SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
Wi-Fi Direct mode is not the initialization mode by default, therefore it must be set by the application. The following API should be called to set the device in Wi-Fi Direct mode. Wi-Fi Direct configuration is not effective until the device enters Wi-Fi Direct mode. This configuration requires a reset and is persistent with no dependency on the system-persistent configuration.
Example:
_i16 Role;
_i16 Status;
Status = sl_WlanSetMode(ROLE_P2P);
if( Status )
{
/* error */
}
Status = sl_Stop(0);
Role = sl_Start(NULL,NULL,NULL);
if (ROLE_P2P != Role)
{
/* error */
}
The network configuration for Wi-Fi Direct mode is similar to the STA and AP modes. For CLIENT use STA network configuration parameters, and for GO use AP network configuration parameters. Persistent:
To change the default configuration, the following settings are available:
An example of setting CLIENT static IPv4 address:
SlNetCfgIpV4Args_t ipV4;
_i16 Status;
ipV4.Ip = (_u32)SL_IPV4_VAL(192,168,0,108); /* IP address */
ipV4.IpMask = (_u32)SL_IPV4_VAL(255,255,255,0); /* Subnet mask for this STA/P2P */
ipV4.IpGateway = (_u32)SL_IPV4_VAL(192,168,0,1); /* Default gateway address */
ipV4.IpDnsServer = (_u32)SL_IPV4_VAL(192,168,0,1); /* DNS server address */
Status = sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_STATIC,sizeof(SlNetCfgIpV4Args_t) ,(_u8 *)&ipV4);
if( Status )
{
/* error */
}
The device name must be unique because the Wi-Fi Direct connection is device-name based. The device name is compound of the URN and two random characters. Users can set only the URN; the random characters are internally generated. Default = mysimplelink_XX (xx = random two characters). This configuration is persistent according to the system-persistent configuration.
Example:
_u8 device_name[] = "Simple_WiFi_Direct";
_i16 Status;
Status = sl_NetAppSet (SL_NETAPP_DEVICE_ID,SL_NETAPP_DEVICE_URN, strlen(device_name), (_u8 *) device_name);
if( Status )
{
/* error */
}
The following macro is used to set the Wi-Fi Direct device type. The device type is published under P2P I.E. The device type is part of the Wi-Fi Direct discovery parameters, and is used to better recognize the device. The maximum length is 17 characters. Default = 1-0050F204-1. This configuration is persistent according to the system-persistent configuration.
Example:
_i16 Status;
_u8 str[17];
_u16 len = strlen(device_type);
memset(str, 0, 17);
memcpy(str, device_type, len);
Status = sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, SL_WLAN_P2P_OPT_DEV_TYPE, len, str);
if( Status )
{
/* error */
}
The listen channel is used for the discovery state and the value can be 1, 6, or 11. The device stays in this channel when waiting for Wi-Fi Direct probes requests. The operation channel is only used by the GO device. The GO device moves to this channel after the negotiation phase. The default listen channel is randomly assigned between channels 1, 6, or 11. This configuration is persistent according to the system-persistent configuration. The regulatory domain class should be 81 in 2.4 G.
An example for setting the listen channel to 11 and the operational channel to 6 follows:
_u8 channels [4];
_i16 Status;
channels [0] = (unsigned char)11; /* listen channel */
channels [1] = (unsigned char)81; /* listen regulatory class */
channels [2] = (unsigned char)6; /* operational channel */
channels [3] = (unsigned char)81; /* operational regulatory class */
Status = sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, SL_WLAN_P2P_OPT_CHANNEL_N_REGS,4,channels);
if( Status )
{
/* error */
}