9.3.4 WPS Code Example

void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
	if(u8WiFiEvent == M2M_WIFI_REQ_WPS)
	{
		tstrM2MWPSInfo	*pstrWPS = (tstrM2MWPSInfo*)pvMsg;
		if(pstrWPS->u8AuthType != 0)
		{
			printf("WPS SSID           : %s\n",pstrWPS->au8SSID);
			printf("WPS PSK            : %s\n",pstrWPS->au8PSK);
			printf("WPS SSID Auth Type : %s\n",
			pstrWPS->u8AuthType == M2M_WIFI_SEC_OPEN ? "OPEN" : "WPA/WPA2");
			printf("WPS Channel        : %d\n",pstrWPS->u8Ch + 1);
					
			// Establish Wi-Fi connection
			m2m_wifi_connect((char*)pstrWPS->au8SSID, (uint8)m2m_strlen(pstrWPS->au8SSID),
				pstrWPS->u8AuthType, pstrWPS->au8PSK, pstrWPS->u8Ch);
		}
		else
		{
			printf("(ERR) WPS Is not enabled OR Timedout\n");
		}
	}
}

int main()
{
	tstrWifiInitParam 	param;

	// Platform specific initializations.

	// Driver initialization.
	param.pfAppWifiCb	= wifi_event_cb;
	if(!m2m_wifi_init(&param))
	{
		// Trigger WPS in Push button mode.
		m2m_wifi_wps(WPS_PBC_TRIGGER, NULL);
			
		while(1)	
		{
			m2m_wifi_handle_events(NULL);
		}
	}
}