Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Asynchronous Wi-Fi direct (P2P) enabling mode function.

The WILC supports P2P in device listening mode ONLY (intent is ZERO). The WILC P2P implementation does not support P2P GO (Group Owner) mode. Active P2P devices (e.g. phones) could find the WILC in the search list. When the P2P GO Peer device place provisional discovery request, a Wi-Fi notification event M2M_WIFI_REQ_P2P_AUTH is triggered with config methods opted by peer device. In response to callback event M2M_WIFI_REQ_P2P_AUTH, the Application should send response back to WILC with either m2m_wifi_allow_p2p_connection() API in case of CONF_METHOD_PBC, or m2m_wifi_set_p2p_pin() for CONF_METHOD_DISPLAY & CONF_METHOD_KEYPAD (pin request) to allow P2P connection. However, the application can ignore the event to reject the p2p connection request. When a device is connected to WILC, a Wi-Fi notification event M2M_WIFI_RESP_CON_STATE_CHANGED is triggered. Refer to the code examples for a more illustrative example.

Functions

NMI_API sint8 m2m_wifi_p2p (uint8 u8Channel, tenuP2PTrigger enuTrigger, uint16 u16WPS_CfgMehods)
 

NMI_API sint8 m2m_wifi_p2p ( uint8  u8Channel,
tenuP2PTrigger  enuTrigger,
uint16  u16WPS_CfgMehods 
)
Parameters
[in]u8ChannelP2P Listen RF channel. According to the P2P standard It must hold only one of the following values 1, 6 or 11.
[in]enuTriggerP2P Trigger method. Could be:
  • [P2P_PIN] Push button method
  • [P2P_PBC] Pin method
[in]u16WPS_CfgMehodsWSC Config methods ["Device configuration methods" in m2m_types.h]
Precondition
Warning
This function is not allowed in AP or STA modes.
See Also
tpfAppWifiCb m2m_wifi_init M2M_WIFI_RESP_CON_STATE_CHANGED tstrM2mWifiStateChanged M2M_WIFI_REQ_P2P_AUTH tstrM2MP2pDevInfo tenuP2PTrigger m2m_wifi_set_p2p_pin m2m_wifi_allow_p2p_connection
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.

Example

The code snippet shown an example of how the p2p mode operates.

#include "m2m_wifi.h"
#include "m2m_types.h"
void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
switch(u8WiFiEvent)
{
{
M2M_INFO("Wifi State :: %s :: ErrCode %d\n", pstrWifiState->u8CurrState? "CONNECTED":"DISCONNECTED",pstrWifiState->u8ErrCode);
// Do something
}
break;
{
tstrM2MP2pDevInfo *pstrP2PDevInfo = (tstrM2MP2pDevInfo *)pvMsg;
if (pstrP2PDevInfo->u16CfgMethods & CONF_METHOD_KEYPAD) {
osprintf("\r\nPlease enter P2P pin\r\n(Usage: P2P_PIN <pin-number displayed on phone>\r\n");
}
else if (pstrP2PDevInfo->u16CfgMethods & CONF_MEHTOD_DISPLAY){
osprintf("\r\nPlease enter P2P pin on phone <12345678>\r\n");
os_m2m_wifi_set_p2p_pin((uint8_t *)"12345678", 8);
}
else {
}
break;
}
default:
break;
}
}
int main()
{
param.pfAppWifiCb = wifi_event_cb;
if(!m2m_wifi_init(&param))
{
// Trigger P2P
while(1)
{
}
}
}

References tstrM2MP2PConnect::enuTrigger, hif_send(), M2M_ERR, M2M_ERR_FAIL, M2M_REQ_GRP_WIFI, M2M_SUCCESS, M2M_WIFI_CH_1, M2M_WIFI_CH_11, M2M_WIFI_CH_6, M2M_WIFI_REQ_ENABLE_P2P, NULL, tstrM2MP2PConnect::u16WPS_CfgMethods, and tstrM2MP2PConnect::u8ListenChannel.

Referenced by os_m2m_wifi_p2p(), and os_m2m_wifi_p2p_imp().