SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
This section describes how to start a Wi-Fi Direct search or discovery, and how to view the discovered remote Wi-Fi Direct devices. The scan policy must be set to start the Wi-Fi Direct find process, and to discover remote Wi-Fi Direct peers. This process is done by setting a scan policy for Wi-Fi Direct mode.
Example:
_u32 intervalInSeconds = 20;
_i16 Status;
Status = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1,1), (_u8*)&intervalInSeconds,sizeof(intervalInSeconds));
if( Status )
{
/* error */
}
There are two ways to see and get Wi-Fi Direct remote devices that were discovered during the Wi-Fi Direct find and search operation:
This event is sent asynchronously to the host when a remote Wi-Fi Direct is found, and contains the MAC address, device name, and length of the device name. By listening to this event, the user can immediately find each remote Wi-Fi Direct device that exists in their neighborhood, and issue a connect or add profile command.
By calling this API, the user receives a list of remote peers that were found during the scan and saved in the device cache memory. By receiving the network list, the user can immediately find any remote Wi-Fi Direct device and issue a manual connection or add profile command.
Example:
SlWlanNetworkEntry_t netEntries[30];
_i16 resultsCount = sl_WlanGetNetworkList(0,30,&netEntries[0]);
Enabling the scan policy sets the device to be discoverable for other devices. The two following options are available to complete the connection:
The following are two different Wi-Fi Direct negotiation methods which indicate the WPS phase that follows to the negotiation:
Both sides negotiate with PBC method. Define: SL_WLAN_SEC_TYPE_P2P_PBC.
Divided to two options:
These parameters influence the negotiation method and are supplied during the manual connection API command that comes from the host or by setting the profile for automatic connection. The negotiation method is performed by the device without a user interference.
If no pin code is entered in the display side, the NWP auto-generates the pin code from the device MAC using the following method:
For example, if the MAC address is 03:4A:22:3B:FA:42, convert to it decimals (059:250:066); 7 LSB decimal digits are: 9250066, and the WPS pin checksum digit is 2. The default pin code for this MAC is 92500662.
Configure the negotiation method by setting the security type in the security structure when issuing a connect or add profile command.
After finding a remote Wi-Fi Direct device, the host can instruct the device to connect to it by issuing a simple connect command. This command performs immediate Wi-Fi Direct discovery, and once the remote device is found, the negotiation phase is started according to the negotiation initiator policy, method, and intent selected.
Example:
_i16 Status;
SlWlanSecParams_t SecParams;
Status = sl_WlanConnect("my-tv-p2p-device", 16, NULL, &SecParams ,0);
if( Status )
{
/* error */
}
The manual disconnect option lets the user disconnect from the remote peer by a host command. This command performs Wi-Fi Direct group.
Example:
_i16 Status;
Status = sl_WlanDisconnect();
if( Status )
{
/* error */
}
The purpose of profile configuration is to make an automatic Wi-Fi Direct connection after reset, or after disconnection from the remote peer device. The add profile command stores the Wi-Fi Direct remote device parameters in flash as a new profile, along with profile priority. These profiles are similar to the STA mode profiles and have the same automatic connection behavior. The connection is dependent on the profile policy configuration (see the connection policy section). If the Auto policy is on, a Wi-Fi Direct discovery is performed, and if one or more of the found remote devices matches one of the profiles, a negotiation phase is started according to the negotiation initiator policy, method, and intent selected. The chosen profile is the one with the highest-priority profile.
If a manual connection is sent during a profile connection, the profile connection is stopped, and the manual connection is started.
Example:
_u8 val = 1;
_u8 policyVal;
_i16 Role, Status;
_u8 my_p2p_device[33];
_u8 remote_p2p_device[33];
_u8 bssidEmpty[6] = {0,0,0,0,0,0};
SlWlanSecParams_t SecParams;
Role = sl_Start(NULL, NULL, NULL);
if( Role != ROLE_P2P)
{
/* Set P2P as active mode */
Status = sl_WlanSetMode(ROLE_P2P);
}
/* Set Wi-Fi Direct client dhcp enable (assuming remote GO running DHCP server) */
Status = sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_DHCP,0,0);
if( Status )
{
/* error */
}
/* Set Device Name */
strcpy(my_p2p_device,"sl_p2p_device");
Status = sl_NetAppSet (SL_NETAPP_DEVICE_ID, SL_NETAPP_DEVICE_URN, strlen(my_p2p_device), (_u8 *) my_p2p_device);
if( Status )
{
/* error */
}
/* set connection policy Auto-Connect and Fast*/
Status = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY (1/*Auto*/,1/*Fast*/, 0/*OpenAP*/,0/*AnyP2P*/,0/*auto provisioning*/), NULL, 0 );
/* set P2P Policy - intent 0, random backoff */
Status = sl_WlanPolicySet( SL_WLAN_POLICY_P2P, SL_WLAN_P2P_POLICY(SL_WLAN_P2P_ROLE_CLIENT/*Intent 0 - Client*/,
SL_WLAN_P2P_NEG_INITIATOR_RAND_BACKOFF/*Negotiation initiator – random backoff*/),NULL,0);
SecParams.Type = SL_WLAN_SEC_TYPE_P2P_PBC;
SecParams.Key = "";
SecParams.KeyLen = 0;
strcpy(remote_p2p_device,"Remote_GO_Device_XX");
Status = sl_WlanProfileAdd(remote_p2p_device, strlen(remote_p2p_device),bssidEmpty,&SecParams ,NULL ,7,0);
if( Status )
{
/* error */
}
//restart the device
Status = sl_Stop(100);
if( Status )
{
/* error */
}
Role = sl_Start(NULL, NULL, NULL);