3.1.7.1 Wi-Fi Service

The Wi-Fi service provides API’s to enable the following features:
  1. Station mode
  2. Soft AP mode
The Wi-Fi Service API prototype is as follows:
RNWF_RESULT_t RNWF_WIFI_SrvCtrl( RNWF_WIFI_SERVICE_t request, void *input)
It handles following services and reports the result to application over the return code or through the registered callback.
Table 3-3. Wi-Fi Services
Option/CommandInputDescription
RNWF_SET_WIFI_PARAMSMode, SSID, Passphrase, Security, Auto-connectConfigures the provided Wi-Fi details and Triggers the connection based on auto enable flag
RNWF_STA_CONNECTNoneTriggers the Wi-Fi STA connection
RNWF_STA_DISCONNECTNoneDisconnects the connection
RNWF_AP_DISABLENoneDisables the SoftAP mode
RNWF_SET_WIFI_AP_CHANNELChannel numberConfigure the Wi-Fi channel
RNWF_SET_WIFI_BSSIDBSSID of AP (String)Configure the Access point's BSSID to which RNWF needs to connect

RNWF_SET_WIFI_TIMEOUT

Seconds (int)Configure Wi-Fi connection timeout
RNWF_SET_WIFI_HIDDEN,true or falseConfigure Hidden mode SSID in SoftAP mode
RNWF_WIFI_PASSIVE_SCANNoneRequest/Trigger Wi-Fi passive scan
RNWF_WIFI_ACTIVE_SCANNoneRequest/Trigger Wi-Fi active scan
RNWF_WIFI_SET_CALLBACKCallback Function handlerRegister the call back for async events
RNWF_GET_WIFI_REGDOMString to receive available regulatory domain valuesQuery available Wi-Fi Regulatory Domains
RNWF_SET_WIFI_REGDOMRegulatory domain value to set (String)Configure the Wi-Fi Regulatory Domain
RNWF_WIFI_SET_COEXCo-Ex Enable/disable, Interface type, WLAN RX Priority, WLAN TX Priority, Antenna ModeConfigure Wi-Fi Bluetooth Co-existence (Co-Ex)
RNWF_SET_WIFI_PSMtrue or false (Wi-Fi Power Save Mode - ON/OFF)Wi-Fi Power Save Mode ON
RNWF_WIFI_PING_ENBLPing IP address (String)Enable Wi-Fi Ping support
The following list captures the Wi-Fi callback event codes and their arguments
Table 3-4. Callback Event Codes
EventResponse ComponentsComments
RNWF_DHCP_LINK_LOCAL_IPV6_DONEDHCP IPv6 (Local): StringWi-Fi DHCP IPv6 (Local) address received event code
RNWF_DHCP_GLOBAL_IPV6_DONEDHCP IPv6 (Global): StringWi-Fi DHCP IPv6 (Global) address received event code
RNWF_SET_REGDOMNoneWi-Fi Set regulatory domain event code
RNWF_SNTP_UP

ID : Parameter ID number

VAL: Parameter value

SNTP time synchronization complete event code

RNWF_PING_ERRORPing failure/error code: StringWi-Fi Ping Error event code
RNWF_PING_SUCCESSNoneWi-Fi Ping Success event code
RNWF_CONNECTEDAssociation ID: Integer

Connected State: Integer

Wi-Fi connected event code. Reports the connection's Association ID and connected state
RNWF_DISCONNECTEDAssociation ID: Integer

Connected State: Integer

Wi-Fi disconnected event code
RNWF_CONNECT_FAILEDFail event code: IntegerWi-Fi connection failure event code
RNWF_DHCP_IPV4_DONEDHCP IPv4: StringWi-Fi DHCP IPv4 address received event code
RNWF_SCAN_INDICATIONRSSI: Received signal strength

Sec Type (Int): Recommended security type to use connecting to this AP (10 options)

Channel (Int): Channel # of device
BSSID (String): BSSID of detected device
SSID (String): SSID of detected device

Scan results to report each scan list
RNWF_SCAN_DONENoneScan complete event code
The following figure illustrates the Station mode connection sequence
Figure 3-29. Station Mode Connection Sequence
Figure 3-30. Process Flow for Creating a Soft AP
Figure 3-31. Scan Operation Sequence
Following is the example of establishing connection in the Station mode
#include <stdio.h>
 
/* This section lists other files that are included in this file.*/
#include "rnwf_app.h"
#include "rnwf_wifi_service.h"
#include "rnwf_interface.h"
 
void APP_WIFI_Callback(RNWF_WIFI_EVENT_t event, uint8_t *p_str)
{
    switch(event)
    {
        case RNWF_SNTP_UP:
        {   
            break;
        }
        case RNWF_CONNECTED:
        {
            printf("Wi-Fi Connected\n");
            break;
        }
        case RNWF_DISCONNECTED:
        {
            printf("Wi-Fi Disconnected\nReconnecting... \n");
            RNWF_WIFI_SrvCtrl(RNWF_STA_CONNECT, NULL);
            break;
        }
	case RNWF_DHCP_IPV4_DONE:
        {
            printf("DHCP IPv4: %s\n", &p_str[2]);
            break;       
        }
        case RNWF_DHCP_LINK_LOCAL_IPV6_DONE:
        {
            printf("DHCP link-local IPv6:%s\n", &p_str[2]);
            break;
        }
        case RNWF_DHCP_GLOBAL_IPV6_DONE:
        {
            printf("DHCP global IPv6:%s\n", &p_str[2]);
            break;
        }
        case RNWF_SET_REGDOM:
        {
            RNWF_WIFI_SrvCtrl(RNWF_SET_WIFI_REGDOM, (void *)COUNTRY_CODE);
            break;
        }
        case RNWF_SCAN_INDICATION:
        {
            break;
        }
        case RNWF_SCAN_DONE:
        {
            break;
        }
        case RNWF_CONNECT_FAILED:
        {
            break;
        }
        default:
        {
            break;
        }
    }
}
 
int main(void)
{   
 
   RNWF_WIFI_PARAM_t wifi_sta_cfg = {RNWF_WIFI_MODE_STA, HOME_AP_SSID, HOME_AP_PASSPHRASE, HOME_AP_SECURITY, STA_AUTOCONNECT};    
     
   RNWF_WIFI_SrvCtrl(RNWF_WIFI_SET_CALLBACK, APP_WIFI_Callback);
 
   RNWF_WIFI_SrvCtrl(RNWF_SET_WIFI_PARAMS, &wifi_sta_cfg);
 
    while(1)
    {  
        RNWF_EVENT_Handler();
    }
}