WiFi Client Service
This API provides WiFi Client setup. Please note that the WiFi Client cannot be used at the same time as the WiFi Access Points service, due to the sharing of same wifi hardware.
IPC interfaces binding
Here's a code sample binding to WiFi service:
bindings: { clientExe.clientComponent.le_wifiClient -> wifiService.le_wifiClient }
Starting the WiFi Client
First of all the function le_wifiClient_Start() must be called to start the WiFi Service.
- le_wifiClient_Start(): returns LE_OK if the call went ok. If WiFi Access Point is active, this will fail.
To subscribe to wifi events le_wifiClient_AddNewEventHandler() is to be called.
- le_wifiClient_AddNewEventHandler(): returns the handler reference if the call went ok.
static void EventHandler(le_wifiClient_Event_t clientEvent,void *contextPtr){switch( clientEvent ){{LE_INFO("WiFi Client Connected.");}break;{LE_INFO("WiFi Client Disconnected.");}break;{LE_INFO("WiFi Client Scan is done.");MyHandleScanResult();}break;}}le_wifiClient_NewEventHandler WiFiEventHandlerRef = NULL;static void MyInit(void){le_result_t result = le_wifiClient_start();if ( LE_OK == result ){LE_INFO("WiFi Client started.");WiFiEventHandlerRef = le_wifiClient_AddNewEventHandler( EventHandler, NULL );}{LE_INFO("ERROR: WiFi Client already started.");}else{LE_INFO("ERROR: WiFi Client not started.");}}
Scanning Access Points with WiFi Client
To start a scan for Access Points, the le_wifiClient_Scan() should be called.
- le_wifiClient_Scan(): returns the LE_OK if the call went ok.
Processing the WiFi scan results
Once the scan results are available, the event LE_WIFICLIENT_EVENT_SCAN_DONE is received. The found Access Points can then be gotten with
- le_wifiClient_GetFirstAccessPoint(): returns the Access Point if found. Else NULL.
- le_wifiClient_GetNextAccessPoint(): returns the next Access Point if found. Else NULL.
The Access Points SSID, Service Set Identifier, is not a string. It does however often contain human readable ASCII values. It can be read with the following function:
- le_wifiClient_GetSsid() : returns the LE_OK if the SSID was read ok.
The Access Points signal strength can be read with the following function:
- le_wifiClient_GetSignalStrength() : returns the signal strength in dBm of the AccessPoint
static void MyHandleScanResult(void){uint8 ssid[MAX_SSID_BYTES];le_wifiClient_AccessPointRef_t accessPointRef = le_wifiClient_GetFirstAccessPoint();while( NULL != accessPointRef ){result = le_wifiClient_GetSsid( accessPointRef, ssid, MAX_SSID_BYTES );{LE_INFO("WiFi Client found.");break;}accessPointRef = le_wifiClient_GetNextAccessPoint();}}
Connecting to Access Point
First of all, an Access Point reference should be created using the SSID of the target Access Point. Use the following function to create a reference:
- le_wifiClient_Create(): returns Access Point reference
To set the pass phrase prior for the Access Point use the function:
- le_wifiClient_SetPassphrase(): returns the function execution status.
WPA-Enterprise requires a username and password to authenticate. To set them use the function:
- le_wifiClient_SetUserCredentials(): returns the function execution status.
If an Access Point is hidden, it does not announce its presence and will not show up in scan. So, the SSID of this Access Point must be known in advance. Then, use the following function to allow connections to hidden Access Points: le_wifiClient_SetHiddenNetworkAttribute(): returns the function execution status.
Finally and when the Access Point parameters have been configured, use the following function to attempt a connection:
- le_wifiClient_Connect(): returns the function execution status.
static void MyConnectTo(le_wifiClient_AccessPointRef_t accessPointRef){le_result_t result;le_wifiClient_SetPassphrase ( accessPointRef, "Secret1" );result = le_wifiClient_Connect( accessPointRef );if (result == LE_OK){LE_INFO("Connecting to AP.");}}
Configure Wifi client with an SSID
While the prior section lists out the le_wifiClient APIs that can be used together to configure the Wifi client to connect to an Access Point over a given SSID, the le_wifiClient_LoadSsid() API seeks to simplify these multiple steps, getting:
- the necessary Access Point reference created for the given SSID which is considered selected for establishing a Wifi connection,
- the necessary Wifi configurations loaded which include the security protocol (i.e. via le_wifiClient_SecurityProtocol()), passphrase (i.e. via le_wifiClient_SetPassphrase()), and the hidden attribute when necessary (i.e. via le_wifiClient_SetHiddenNetworkAttribute()),
- the created reference returned to the API caller in its output argument.
In just this one API call, all these steps would be done for the client application. If any failure has occurred, subsequent steps in the sequence would be skipped and the failing cause will be returned back to the API caller as the API's return value.
This API also achieves the need to keep Wifi configurations back within wifiService instead of elsewhere, like "dataConnectionService:/wifi/".
With the use of this API, Wifi configurations need to be stored in the Legato config tree on the path "wifiService:/wifi/channel/", under which configurations of multiple SSIDs can be stored at the same time. This is done by having an SSID name string as a sub-path under this path and then its Wifi configurations go under this sub-path. This is the path for any given SSID from which this API will access to retrieve corresponding Wifi configurations and install into the wifiClient. Here is an example with 2 SSIDs configured:
root-mdm9x28:~# config get wifiService:/wifi/ wifi/ channel/ MY-MOBILE/ secProtocol<string> == 3 passphrase<string> == MY-WLAN/ secProtocol<string> == 3 passphrase<string> == hidden<bool> == true
The following is a sample code to illustrate how this API can be used:
le_result_t ret = le_wifiClient_LoadSsid(ssid, 0, &apRef);if (ret == LE_OK){LE_DEBUG("Wifi configs installed to connect over SSID %s with AP reference %p",ssid, apRef);}else{LE_ERROR("Failed to install wifi configs to connect over SSID %s", ssid);}
Get the currently selected connection
A selected SSID via its AP reference is set for use in Wifi connection establishment since the API call to le_wifiClient_Connect(). Note that while the input argument is actually an Access Point reference, this reference specifically refers to a given SSID on the device. This is considered the selected connection for use until le_wifiClient_Disconnect() is called to deselect it.
During the time when this AP reference is set for use, there comes the need to be able to query le_wifiClient for it back. This is what this le_wifiClient_GetCurrentConnection() API seeks to return. The following is a sample code to illustrate how it can be used. The retrieved AP reference is returned in the output argument.
le_wifiClient_GetCurrentConnection(&apRef);if (!apRef){return;}ret = le_wifiClient_GetSsid(apRef, &ssid[0], &ssidSize);if (LE_OK != ret){LE_ERROR("Failed to find SSID of AP reference %p", apRef);return;}ssid[ssidSize] = '\0';LE_DEBUG("Found currently selected Wifi connection to get established: %s, reference %p",ssid, apRef);
Copyright (C) Sierra Wireless Inc.