Microchip® Advanced Software Framework

winc3400/host_app/provisioning/wifi_prov.c File Reference

This module contains WINC3400 Host MCU Provisioning implementation.

Copyright (c) 2019 Microchip Technology Inc. and its subsidiaries.

#include "asf.h"
#include "wifi_prov.h"
#include "http_content.h"
#include "socket/include/socket.h"
#include "driver/include/m2m_wifi.h"
#include <string.h>

Enumerations

enum  prov_app_status {
  APP_PROV_INIT,
  APP_PROV_WINC_CONNECTED,
  APP_PROV_START,
  APP_PROV_END,
  APP_PROV_AP_DISABLE,
  APP_PROV_DEINIT,
  APP_PROV_IDLE,
  APP_PROV_INIT,
  APP_PROV_WINC_CONNECTED,
  APP_PROV_START,
  APP_PROV_END,
  APP_PROV_AP_DISABLE,
  APP_PROV_DEINIT,
  APP_PROV_IDLE
}
 Main app status. More...
 

Functions

static void html_handler (SOCKET sock, uint8_t *p, int16_t p_sz, wifiProvisionParams *provInfo)
 
static void prov_socket_cb (SOCKET sock, uint8_t u8Msg, void *pvMsg)
 Callback to get the Data from socket. More...
 
static void prov_wifi_cb (uint8_t u8MsgType, void *pvMsg)
 Callback to get the Wi-Fi status update. More...
 
void wifi_ap_connect (wifiProvisionParams *provParams)
 Wi-Fi Provisioning ap connect function. More...
 
void wifi_ap_provision (wifiProvisionParams *provParams)
 Wi-Fi Provisioning main application function. More...
 

Variables

static volatile prov_app_status gu8AppStatus = APP_PROV_INIT
 
static SOCKET http_server_socket = -1
 Socket for TCP communication. More...
 
wifiProvisionParamshttpProvInfo
 
static uint8_t rx_buf [RX_BUF_SZ]
 HTTP server globals. More...
 
static SOCKET tcp_client_socket = -1
 
tstr1xAuthTLSCredentials tlsCredentials
 

Main app status.

Enumerator
APP_PROV_INIT 
APP_PROV_WINC_CONNECTED 
APP_PROV_START 
APP_PROV_END 
APP_PROV_AP_DISABLE 
APP_PROV_DEINIT 
APP_PROV_IDLE 
APP_PROV_INIT 
APP_PROV_WINC_CONNECTED 
APP_PROV_START 
APP_PROV_END 
APP_PROV_AP_DISABLE 
APP_PROV_DEINIT 
APP_PROV_IDLE 

static void html_handler ( SOCKET  sock,
uint8_t *  p,
int16_t  p_sz,
wifiProvisionParams provInfo 
)
static
static void prov_socket_cb ( SOCKET  sock,
uint8_t  u8Msg,
void *  pvMsg 
)
static

Callback to get the Data from socket.

Parameters
[in]socksocket handler.
[in]u8Msgsocket event type. Possible values are:
  • SOCKET_MSG_BIND
  • SOCKET_MSG_LISTEN
  • SOCKET_MSG_ACCEPT
  • SOCKET_MSG_CONNECT
  • SOCKET_MSG_RECV
  • SOCKET_MSG_SEND
  • SOCKET_MSG_SENDTO
  • SOCKET_MSG_RECVFROM
[in]pvMsgis a pointer to message structure. Existing types are:

References accept(), html_handler(), http_server_socket, listen(), NULL, printf, tstrSocketRecvMsg::pu8Buffer, recv(), rx_buf, tstrSocketRecvMsg::s16BufferSize, tstrSocketAcceptMsg::sock, SOCKET_MSG_ACCEPT, SOCKET_MSG_BIND, SOCKET_MSG_LISTEN, SOCKET_MSG_RECV, SOCKET_MSG_SEND, tstrSocketBindMsg::status, tstrSocketListenMsg::status, and tcp_client_socket.

Referenced by wifi_ap_provision().

static void prov_wifi_cb ( uint8_t  u8MsgType,
void *  pvMsg 
)
static

Callback to get the Wi-Fi status update.

Parameters
[in]u8MsgTypetype of Wi-Fi notification. Possible types are:
[in]pvMsgA pointer to a buffer containing the notification parameters (if any). It should be casted to the correct data type corresponding to the notification type. Existing types are:

References APP_PROV_AP_DISABLE, APP_PROV_DEINIT, APP_PROV_WINC_CONNECTED, gu8AppStatus, M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, M2M_WIFI_REQ_DHCP_CONF, M2M_WIFI_RESP_CON_STATE_CHANGED, printf, and tstrM2mWifiStateChanged::u8CurrState.

Referenced by wifi_ap_provision().

void wifi_ap_connect ( wifiProvisionParams provParams)

Wi-Fi Provisioning ap connect function.

This will connect to the AP with the credentials received in wifiProvisionParams The user is expected to perform m2m_wifi_init() before calling this api.

Referenced by main().

void wifi_ap_provision ( wifiProvisionParams provParams)

Wi-Fi Provisioning main application function.

This is a blocking function that wait for the user to connect to the PROV_WLAN_SOFTAP_SSID and provide the credentials in web page http://192.168.1.1/provisioning.html. The user is expected to close all the open socket and perform socketDeinit() and m2m_wifi_deinit before this function is called

Referenced by main().

volatile prov_app_status gu8AppStatus = APP_PROV_INIT
static
SOCKET http_server_socket = -1
static

Socket for TCP communication.

Referenced by prov_socket_cb(), and wifi_ap_provision().

wifiProvisionParams* httpProvInfo
uint8_t rx_buf[RX_BUF_SZ]
static

HTTP server globals.

SOCKET tcp_client_socket = -1
static
tstr1xAuthTLSCredentials tlsCredentials

Referenced by post_main_page().