Microchip® Advanced Software Framework

winc1500/host_drv/driver/source/m2m_wifi.c File Reference

This module contains M2M Wi-Fi APIs implementation.

Copyright (c) 2016-2021 Microchip Technology Inc. and its subsidiaries.

#include "driver/include/m2m_wifi.h"
#include "driver/source/m2m_hif.h"
#include "driver/source/nmasic.h"
#include <string.h>

Macros

#define WIFI_1X_TLS_HS_FLAGS_DEFAULT
 
#define WIFI_1X_TLS_HS_FLAGS_PEER_AUTH   NBIT1
 
#define WIFI_1X_TLS_HS_FLAGS_PEER_CERTTIMECHECK   NBIT2
 
#define WIFI_1X_TLS_HS_FLAGS_REQUIRE_TIME   NBIT3
 
#define WIFI_1X_TLS_HS_FLAGS_RSV5   NBIT5
 
#define WIFI_1X_TLS_HS_FLAGS_RSV7   NBIT7
 
#define WIFI_1X_TLS_HS_FLAGS_SESSION_CACHING   NBIT4
 
#define WIFI_1X_TLS_HS_FLAGS_SPECIFY_ROOTCERT   NBIT6
 

Functions

static sint8 m2m_validate_ap_parameters (CONST tstrM2MAPModeConfig *pstrM2MAPModeConfig)
 
static sint8 m2m_validate_scan_options (tstrM2MScanOption *ptstrM2MScanOption)
 
sint8 m2m_wifi_1x_get_option (tenu1xOption enuOptionName, void *pOptionValue, size_t *pOptionLen)
 API to get (read) options relating to Wi-Fi connection using WPA(2) Enterprise authentication. More...
 
sint8 m2m_wifi_1x_set_option (tenu1xOption enuOptionName, const void *pOptionValue, size_t OptionLen)
 API to set (write) options relating to Wi-Fi connection using WPA(2) Enterprise authentication. More...
 
static void m2m_wifi_cb (uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
 
NMI_API sint8 m2m_wifi_conf_auto_rate (tstrConfAutoRate *pstrConfAutoRate)
 Allow the host MCU app to configure auto TX rate selection algorithm. The application can use this API to tweak the algorithm performance. Moreover, it allows the application to force a specific WLAN PHY rate for transmitted data packets to favor range vs. throughput needs. More...
 
sint8 m2m_wifi_configure_sntp (uint8 *pu8NTPServerName, uint8 u8NTPServerNameLength, tenuSNTPUseDHCP useDHCP)
 Configures what NTP server the SNTP client should use. More...
 
sint8 m2m_wifi_connect (char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch)
 Legacy asynchronous API to request connection to a specified access point. More...
 
sint8 m2m_wifi_connect_1x_mschap2 (tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuth1xMschap2 *pstrAuth1xMschap2)
 Asynchronous API to connect to an access point using WPA(2) Enterprise authentication with MS-CHAP-V2 credentials. More...
 
sint8 m2m_wifi_connect_1x_tls (tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuth1xTls *pstrAuth1xTls)
 Asynchronous API to connect to an access point using WPA(2) Enterprise authentication with MS-CHAP-V2 credentials. More...
 
sint8 m2m_wifi_connect_open (tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId)
 Asynchronous API to connect to an access point using open authentication. More...
 
static sint8 m2m_wifi_connect_prepare_msg (tenuCredStoreOption enuCredStoreOption, tenuM2mSecType enuAuthType, uint16 u16AuthSize, tstrNetworkId *pstrNetworkId, tstrM2mWifiConnHdr *pstrWifiConn)
 
sint8 m2m_wifi_connect_psk (tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuthPsk *pstrAuthPsk)
 Asynchronous API to connect to an access point using WPA(2) PSK authentication. More...
 
sint8 m2m_wifi_connect_sc (char *pcSsid, uint8 u8SsidLen, uint8 u8SecType, void *pvAuthInfo, uint16 u16Ch, uint8 u8NoSaveCred)
 Legacy asynchronous API to request connection to a specific AP with the option to save credentials in Flash. More...
 
sint8 m2m_wifi_connect_wep (tenuCredStoreOption enuCredStoreOption, tstrNetworkId *pstrNetworkId, tstrAuthWep *pstrAuthWep)
 Asynchronous API to connect to an access point using WEP authentication. More...
 
sint8 m2m_wifi_default_connect (void)
 Asynchronous API that attempts to reconnect to the last-associated access point. More...
 
sint8 m2m_wifi_deinit (void *arg)
 Synchronous API to de-initialize the WINC driver and host interface. More...
 
sint8 m2m_wifi_delete_sc (char *pcSsid, uint8 u8SsidLen)
 Asynchronous API that deletes connection credentials (PSK, WEP key, 802.1X password) from WINC flash. Either deletes all credentials, or for a specific SSID. More...
 
sint8 m2m_wifi_disable_ap (void)
 Synchronous API to disable access point mode on the WINC. More...
 
sint8 m2m_wifi_disable_roaming (void)
 Disable WiFi STA roaming. More...
 
sint8 m2m_wifi_disconnect (void)
 Synchronous API to request disconnection from a network. More...
 
sint8 m2m_wifi_download_mode ()
 Prepares the WINC before downloading any data (Firmware, Certificates, etc). More...
 
sint8 m2m_wifi_enable_ap (CONST tstrM2MAPConfig *pstrM2MAPConfig)
 Asynchronous API to enable access point (AKA "hot-spot") mode on the WINC. More...
 
sint8 m2m_wifi_enable_ap_ext (CONST tstrM2MAPModeConfig *pstrM2MAPModeConfig)
 Asynchronous API to enable access point (AKA "hot-spot") mode on the WINC with extended options. More...
 
sint8 m2m_wifi_enable_dhcp (uint8 u8DhcpEn)
 Asynchronous function to control the DHCP client functionality within the WINC. More...
 
sint8 m2m_wifi_enable_firmware_logs (uint8 u8Enable)
 Enable or Disable logs in run time (Disable Firmware logs will enhance the firmware start-up time and performance) More...
 
sint8 m2m_wifi_enable_roaming (uint8 bEnableDhcp)
 Enable WiFi STA roaming. More...
 
sint8 m2m_wifi_enable_sntp (uint8 bEnable)
 Asynchronous API to enable or disable the native Simple Network Time Protocol(SNTP) client running on the WINC. More...
 
sint8 m2m_wifi_enable_XO_during_sleep (uint8 bXOSleepEnable)
 Specifies whether the crystal oscillator is left on or off during deep sleep (defaults to off). More...
 
sint8 m2m_wifi_get_connection_info (void)
 Asynchronous API for retrieving the WINC connection status. More...
 
sint8 m2m_wifi_get_firmware_version (tstrM2mRev *pstrRev)
 Synchronous API to obtain the firmware version currently running on the WINC IC. More...
 
sint8 m2m_wifi_get_mac_address (uint8 *pu8MacAddr)
 Request the current MAC address of the device (the working mac address). (the function is Blocking until response received) More...
 
uint8 m2m_wifi_get_num_ap_found (void)
 Reads the number of AP's found in the last Scan Request, The function read the number of AP's from global variable which updated in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE. More...
 
sint8 m2m_wifi_get_otp_mac_address (uint8 *pu8MacAddr, uint8 *pu8IsValid)
 Request the MAC address stored on the OTP (one time programmable) memory of the device. (the function is Blocking until response received) More...
 
uint8 m2m_wifi_get_sleep_mode (void)
 Get the current Power save mode. More...
 
uint8 m2m_wifi_get_state (void)
 Get the wifi state. More...
 
sint8 m2m_wifi_get_system_time (void)
 Asynchronous API to obtain the system time in use by the WINC. More...
 
sint8 m2m_wifi_handle_events (void *arg)
 Synchronous M2M event handler function. More...
 
sint8 m2m_wifi_init (tstrWifiInitParam *pWifiInitParam)
 Synchronous API to initialize the WINC driver. More...
 
sint8 m2m_wifi_init_hold ()
 First part of m2m_wifi_init, up to the point of initializing SPI for flash access. More...
 
sint8 m2m_wifi_init_start (tstrWifiInitParam *pWifiInitParam)
 Second part of m2m_wifi_init, continuing from where m2m_wifi_init_hold left off. More...
 
sint8 m2m_wifi_p2p (uint8 u8Channel)
 
sint8 m2m_wifi_p2p_disconnect (void)
 
sint8 m2m_wifi_prng_get_random_bytes (uint8 *pu8PrngBuff, uint16 u16PrngSize)
 Get random bytes using the PRNG bytes. More...
 
sint8 m2m_wifi_reinit (tstrWifiInitParam *pWifiInitParam)
 De-initialize and then initialize wifi. Resets the WINC. More...
 
sint8 m2m_wifi_reinit_hold (void)
 First part of m2m_wifi_reinit, up to the point of initializing SPI for flash access. More...
 
sint8 m2m_wifi_reinit_start (tstrWifiInitParam *pWifiInitParam)
 Second part of m2m_wifi_reinit, continuing from where m2m_wifi_reinit_hold left off. More...
 
sint8 m2m_wifi_req_client_ctrl (uint8 u8Cmd)
 Send a command to the PS Client (An WINC board running the ps_firmware), if the PS client send any commands it will be received in wifi_cb M2M_WIFI_RESP_CLIENT_INFO. More...
 
sint8 m2m_wifi_req_curr_rssi (void)
 Request the current RSSI for the current connected AP, the response received in wifi_cb M2M_WIFI_RESP_CURRENT_RSSI. More...
 
sint8 m2m_wifi_req_scan_result (uint8 index)
 Reads the AP information from the Scan Result list with the given index, the response received in wifi_cb M2M_WIFI_RESP_SCAN_RESULT, the response pointer should be casted with tstrM2mWifiscanResult structure. More...
 
sint8 m2m_wifi_req_server_init (uint8 ch)
 Initialize the PS Server, The WINC support non secure communication with another WINC, (SERVER/CLIENT) through one byte command (probe request and probe response) without any connection setup. More...
 
sint8 m2m_wifi_request_dhcp_client (void)
 Legacy (deprecated) Asynchronous API for starting a DHCP client on the WINC. More...
 
sint8 m2m_wifi_request_dhcp_server (uint8 *addr)
 Legacy (deprecated) asynchronous function to start a DHCP client on the WINC. More...
 
sint8 m2m_wifi_request_scan (uint8 ch)
 Asynchronous API to request the WINC to scan for networks. More...
 
sint8 m2m_wifi_request_scan_passive (uint8 ch, uint16 scan_time)
 Similar to m2m_wifi_request_scan but performs passive scanning instead of active scanning. More...
 
sint8 m2m_wifi_request_scan_ssid_list (uint8 ch, uint8 *u8Ssidlist)
 Asynchronous wi-fi scan request on the given channel and the hidden scan list. More...
 
sint8 m2m_wifi_request_sleep (uint32 u32SlpReqTime)
 Asynchronous API to place the WINC into sleep mode for a specified period of time. More...
 
sint8 m2m_wifi_send_crl (tstrTlsCrlInfo *pCRL)
 Asynchronous API that notifies the WINC with the Certificate Revocation List. More...
 
sint8 m2m_wifi_send_ethernet_pkt (uint8 *pu8Packet, uint16 u16PacketSize)
 Asynchronous API to queue an Ethernet packet for transmission by the WINC. More...
 
sint8 m2m_wifi_set_battery_voltage (uint16 u16BattVoltx100)
 Set the battery voltage to update the firmware calculations.
Not implemented in WINC3400 firmware. More...
 
sint8 m2m_wifi_set_cust_InfoElement (uint8 *pau8M2mCustInfoElement)
 Asynchronous API to add or remove a user-defined Information Element. More...
 
sint8 m2m_wifi_set_device_name (uint8 *pu8DeviceName, uint8 u8DeviceNameLength)
 Set the WINC3400 device name which is used as P2P device name. More...
 
sint8 m2m_wifi_set_gain_table_idx (uint8 u8GainTableIdx)
 set the gain table index corresponding to a specific WiFi region More...
 
sint8 m2m_wifi_set_gains (tstrM2mWifiGainsParams *pstrM2mGain)
 Set the chip PPA gain for 11b/11gn. More...
 
sint8 m2m_wifi_set_lsn_int (tstrM2mLsnInt *pstrM2mLsnInt)
 Set the Wi-Fi listen interval for power save operation. It is represented in units of AP Beacon periods. More...
 
sint8 m2m_wifi_set_mac_address (uint8 au8MacAddress[6])
 Asynchronous API for assigning a MAC address to the WINC. More...
 
sint8 m2m_wifi_set_power_profile (uint8 u8PwrMode)
 Change the power profile mode
Not implemented in WINC3400 firmware. More...
 
sint8 m2m_wifi_set_scan_options (tstrM2MScanOption *ptstrM2MScanOption)
 Synchronous API for configuring the behaviour of the WINC network scanning functions. More...
 
sint8 m2m_wifi_set_scan_region (uint16 ScanRegion)
 Synchronous API for configuring the regulatory restrictions that may affect the WINC scanning behaviour. More...
 
sint8 m2m_wifi_set_sleep_mode (uint8 PsTyp, uint8 BcastEn)
 Set the power saving mode for the WINC3400. More...
 
sint8 m2m_wifi_set_static_ip (tstrM2MIPConfig *pstrStaticIPConf)
 Asynchronous API to manually assign a (static) IP address to the WINC. More...
 
sint8 m2m_wifi_set_stop_scan_on_first (uint8 u8StopScanOption)
 Synchronous API for enabling/disabling the stop scan on first result of the WINC IC's network scanning functions. More...
 
sint8 m2m_wifi_set_system_time (uint32 u32UTCSeconds)
 Asynchronous function for setting the system time within the WINC. More...
 
sint8 m2m_wifi_set_tx_power (uint8 u8TxPwrLevel)
 set the TX power tenuM2mTxPwrLevel More...
 
sint8 m2m_wifi_start_provision_mode (tstrM2MAPConfig *pstrM2MAPConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect)
 Asynchronous API for control of Wi-Fi provisioning functionality. More...
 
sint8 m2m_wifi_start_provision_mode_ext (tstrM2MAPModeConfig *pstrAPModeConfig, char *pcHttpServerDomainName, uint8 bEnableHttpRedirect)
 Asynchronous API for control of Wi-Fi provisioning functionality with extended options. More...
 
sint8 m2m_wifi_stop_provision_mode (void)
 Synchronous API for terminating provisioning mode on the WINC. More...
 
sint8 m2m_wifi_wps (uint8 u8TriggerType, const char *pcPinNumber)
 Asynchronous API to engage the WINC Wi-Fi Protected Setup (enrollee) function. More...
 
sint8 m2m_wifi_wps_disable (void)
 Asynchronous API that disables Wi-Fi Protected Setup mode in the WINC. More...
 
void m2m_wifi_yield (void)
 Yield from processing more synchronous M2M events. More...
 

Variables

static uint8 gau81xRootSha1 [20] = {0}
 
static tpfAppWifiCb gpfAppWifiCb = NULL
 
static uint32 gu321xTlsHsFlags = WIFI_1X_TLS_HS_FLAGS_DEFAULT
 
static volatile uint8 gu8ChNum
 
static volatile uint8 gu8scanInProgress = 0
 
static volatile uint8 gu8WifiState = WIFI_STATE_DEINIT