sl_WlanSetMode – The WLAN device has several WLAN modes of operation. By default, the device acts as a WLAN station, but it can also act in other WLAN roles. The different options are:
- ROLE_STA – For WLAN station mode
- ROLE_AP – For WLAN AP mode
- ROLE_P2P – For WLAN P2P mode
Note: The set mode functionality only takes effect in the next device boot.
An example of switching from any role to WLAN AP roles:
sl_WlanSetMode(ROLE_AP);
/* Turning the device off and on in order for the roles change to take effect */
sl_Stop(0);
sl_Start(NULL,NULL,NULL);
sl_WlanSet – Lets the user configure different WLAN-related parameters. The main parameters used are ConfigID and ConfigOpt.
The possible ConfigID and ConfigOpt combinations are:
- SL_WLAN_CFG_GENERAL_PARAM_ID – The different general WLAN parameters are:
- WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE
- WLAN_GENERAL_PARAM_OPT_STA_TX_POWER – Sets STA mode Tx power level, a number from 0 to 15, as the dB offset from max power (0 will set maximum power).
- WLAN_GENERAL_PARAM_OPT_AP_TX_POWER – Sets AP mode Tx power level, a number from 0 to 15, as the dB offset from max power (0 will set maximum power).
- SL_WLAN_CFG_AP_ID – The different AP configuration options are:
- WLAN_AP_OPT_SSID
- WLAN_AP_OPT_CHANNEL
- WLAN_AP_OPT_HIDDEN_SSID – Sets the AP to be hidden or not hidden
- WLAN_AP_OPT_SECURITY_TYPE – Possible options are:
- Open security: SL_SEC_TYPE_OPEN
- WEP security: SL_SEC_TYPE_WEP
- WPA security: SL_SEC_TYPE_WPA
- WLAN_AP_OPT_PASSWORD – Sets the security password for AP mode:
- For WPA: 8 to 63 characters
- For WEP: 5 to 13 characters (ASCII)
- SL_WLAN_CFG_P2P_PARAM_ID
- WLAN_P2P_OPT_DEV_NAME
- WLAN_P2P_OPT_DEV_TYPE
- WLAN_P2P_OPT_CHANNEL_N_REGS – The listen channel and regulatory class determine the device listen channel during the P2P find and listen phase. The operational channel and regulatory class determines the operating channel preferred by the device (if the device is the group owner, this is the operating channel). Channels should be one of the social channels (1, 6, or 11). If no listen or operational channel is selected, a random 1, 6, or 11 will be selected.
- WLAN_GENERAL_PARAM_OPT_INFO_ELEMENT – The application sets up to MAX_PRIVATE_INFO_ELEMENTS_SUPPORTED information elements per role (AP / P2P GO). To delete an information element, use the relevant index and length = 0. The application sets up to MAX_PRIVATE_INFO_ELEMENTS_SUPPORTED to the same role. However, for AP no more than INFO_ELEMENT_MAX_TOTAL_LENGTH_AP bytes are stored for all information elements. For P2P GO no more than INFO_ELEMENT_MAX_TOTAL_LENGTH_P2P_GO bytes are stored for all information elements.
- WLAN_GENERAL_PARAM_OPT_SCAN_PARAMS – Changes the scan channels and RSSI threshold
An example of setting SSID for AP mode:
unsigned char str[33];
memset(str, 0, 33);
memcpy(str, ssid, len); // ssid string of 32 characters
sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(ssid), str);
sl_WlanGet – Enables the user to configure different WLAN-related parameters. The main parameters used are ConfigID and ConfigOpt. The usage of sl_WlanGet is similar to sl_WlanSet.
sl_WlanConnect – Manually connects to a WLAN network
sl_WlanDisconnect – Disconnects WLAN connection
sl_WlanProfileAdd – When auto-start connection policy is enabled, the device connects to an AP from the profiles table. Up to seven profiles are supported. If several profiles are configured, the device selects the highest priority profile. Within each priority group, the device choses the profile based on the following parameters in descending priority: security policy, signal strength.
sl_WlanProfileGet – Reads a WLAN profile from the device
sl_WlanProfileDel – Deletes an existing profile
sl_WlanPolicySet – Manages the configuration of the following WLAN functionalities:
- SL_POLICY_CONNECTION – SL_POLICY_CONNECTION type defines three options available to connect the CC31xx device to the AP:
- Auto Connect – The CC31xx device tries to automatically reconnect to one of its stored profiles each time the connection fails or the device is rebooted. To set this option, use:
sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0)
- Fast Connect – The CC31xx device tries to establish a fast connection to AP. To set this option, use:
sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(0,1,0,0,0),NULL,0)
- P2P Connect – If Any P2P mode is set, the CC31xx device tries to automatically connect to the first P2P device available, supporting push-button only. To set this option, use:
sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(0,0,0,1,0),NULL,0)
- Auto SmartConfig upon restart – The device wakes up in SmartConfig mode. Any command from the host ends this state. To set this option use:
sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(0,0,0,0,1),NULL,0)
- SL_POLICY_SCAN – Defines the system scan time interval if there is no connection. The default interval is 10 minutes. After the settings scan interval, an immediate scan is activated. The next scan is based on the interval settings. To set the scan interval to a 1-minute interval, use the following example:
unsigned long intervalInSeconds = 60;
#define SL_SCAN_ENABLE 1
sl_WlanPolicySet(SL_POLICY_SCAN,SL_SCAN_ENABLE, (unsigned char *)
&intervalInSeconds,sizeof(intervalInSeconds));
To disable the scan, use:
#define SL_SCAN_DISABLE 0
sl_WlanPolicySet(SL_POLICY_SCAN,SL_SCAN_DISABLE,0,0);
- SL_POLICY_PM – Defines a power-management policy for station mode only. Four power policies are available:
- SL_NORMAL_POLICY (default) – For setting normal power-management policy use:
- SL_ALWAYS_ON_POLICY – For setting always-on power-management policy use:
- SL_LONG_SLEEP_INTERVAL_POLICY – For setting long-sleep interval policy use:
unsigned short PolicyBuff[4] = {0,0,800,0}; // 800 is max sleep time in mSec
sl_WlanPolicySet(SL_POLICY_PM , SL_LONG_SLEEP_INTERVAL_POLICY, PolicyBuff,sizeof(PolicyBuff));
- SL_POLICY_P2P – Defines P2P negotiation policy parameters for a P2P role. To set the intent negotiation value, set one of the following:
- SL_P2P_ROLE_NEGOTIATE – intent 3
- SL_P2P_ROLE_GROUP_OWNER – intent 15
- SL_P2P_ROLE_CLIENT – intent 0
- To set the negotiation initiator value (the initiator policy of the first negotiation action frame), set one of the following:
- SL_P2P_NEG_INITIATOR_ACTIVE
- SL_P2P_NEG_INITIATOR_PASSIVE
- SL_P2P_NEG_INITIATOR_RAND_BACKOFF
For example:
set sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE,SL_P2P_NEG_INITIATOR_RAND_BACKOFF),NULL,0);
sl_WlanPolicyGet – Reads the different WLAN policy settings. The possible options are:
- SL_POLICY_CONNECTION
- SL_POLICY_SCAN
- SL_POLICY_PM
- SL_POLICY_P2P
sl_WlanGetNetworkList – Gets the latest WLAN scan results
sl_WlanSmartConfigStart – Puts the device into SmartConfig state. Once SmartConfig has ended successfully, an asynchronous event will be received: SL_OPCODE_WLAN_SMART_CONFIG_START_ASYNC_RESPONSE. The event holds the SSID and an extra field that might also have been delivered (for example, device name).
sl_WlanSmartConfigStop – Stops the SmartConfig procedure. Once SmartConfig is stopped, an asynchronous event is received: SL_OPCODE_WLAN_SMART_CONFIG_STOP_ASYNC_RESPONSE
sl_WlanRxStatStart – Starts collecting WLAN Rx statistics (unlimited time)
sl_WlanRxStatStop – Stops collecting WLAN Rx statistics
sl_WlanRxStatGet – Gets WLAN Rx statistics. Upon calling this command, the statistics counters are cleared. The statistics returned are:
- Received valid packets – Sum of the packets received correctly (including filtered packets)
- Received FCS error packets – Sum of the packets dropped due to FCS error
- Received PLCP error packets – Sum of the packets dropped due to PLCP error
- Average data RSSI – Average RSSI for all valid data packets received
- Average management RSSI – Average RSSI for all valid management packets received
- Rate histogram – Rate histogram for all valid packets received
- RSSI histogram – RSSI histogram from -40 until -87 (all values below and above RSSI appear in the first and last cells)
- Start time stamp – The timestamp of starting to collect the statistics in µSec
- Get time stamp – The timestamp of reading the statistics in µSec