RDK Documentation (Open Sourced RDK Components)
wifiHalUtiles.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #ifndef WIFIHALUTILES_H_
21 #define WIFIHALUTILES_H_
22 
23 #include "wifiSrvMgr.h"
24 #include "NetworkMgrMain.h"
25 #include "wifiSrvMgrIarmIf.h"
26 
27 #ifdef ENABLE_IARM
28 #include "hostIf_tr69ReqHandler.h"
29 #endif
30 
31 #ifdef ENABLE_XCAM_SUPPORT
32 extern "C" {
33 #include "rdkc_api.h"
34 #include "sysUtils.h"
35 }
36 #endif
37 
38 #if defined(XHB1) || defined(XHC3)
39 extern "C" {
40 #include "mfrApi.h"
41 #include "sysUtils.h"
42 }
43 #endif
44 
45 #ifdef ENABLE_LOST_FOUND
46 #ifdef ENABLE_IARM
47 #include "authserviceIARM.h"
48 #endif
49 #endif
50 
51 #ifdef USE_RDK_WIFI_HAL
52 extern "C" {
53 #include "wifi_client_hal.h"
54 }
55 #endif
56 #ifdef ENABLE_LOST_FOUND
57 #include "netSrvCurl.h"
58 extern "C" {
59 #include "lost_and_found.h"
60 }
61 #include <ifaddrs.h>
62 #include <netinet/in.h>
63 #include <sys/ioctl.h>
64 #ifndef ENABLE_NLMONITOR
65 #include <net/if.h>
66 #endif
67 //}
68 
69 #define WIFI_DEFAULT_INTERFACE "wlan0"
70 
71 #endif
72 
73 #ifdef ENABLE_IARM
74 #include "mfrMgr.h"
75 #include "sysMgr.h"
76 #include "libIBusDaemon.h"
77 #endif
78 
79 #ifdef ENABLE_RTMESSAGE
80 /* RtMessage */
81 #include "rtLog.h"
82 #include "rtConnection.h"
83 #include "rtMessage.h"
84 #define SOCKET_ADDRESS "tcp://127.0.0.1:10001"
85 #endif
86 
87 /**
88  * @addtogroup NETSRVMGR_TYPES
89  * @{
90  */
91 #define ACTION_ON_CONNECT 1
92 #define ACTION_ON_DISCONNECT 0
93 #define RETRY_TIME_INTERVAL 3
94 #define DEVICE_ACTIVATED 1
95 #define DEFAULT_TR69_INSTANCE 0
96 #define XRE_REFRESH_SESSION "Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreRefreshXreSession"
97 #define XRE_REFRESH_SESSION_WITH_RR "Device.X_COMCAST-COM_Xcalibur.Client.XRE.xreRefreshXreSessionWithRR"
98 
99 #define WIFI_ADAPTER_STATUS_PARAM "Device.WiFi.Radio.1.Status"
100 #define WIFI_ADAPTER_ENABLE_PARAM "Device.WiFi.Radio.1.Enable"
101 #define WIFI_SSID_ENABLE_PARAM "Device.WiFi.SSID.1.Enable"
102 #define WIFI_SSID_STATUS_PARAM "Device.WiFi.SSID.1.Status"
103 #define WIFI_SSID_NAME_PARAM "Device.WiFi.SSID.1.SSID"
104 #define WIFI_SSID_BSSID_PARAM "Device.WiFi.SSID.1.BSSID"
105 #define WIFI_SSID_MACADDR_PARAM "Device.WiFi.SSID.1.MACAddress"
106 
107 #define SERIALNUMBER_SIZE 15
108 #define MODELNAME_SIZE 10
109 #define MANUFACTURER_SIZE 40
110 #define WIFIMAC_SIZE 20
111 #define DEVICEID_SIZE 512
112 #define PARTNERID_SIZE 128
113 #define TIME_FORMAT "%Y-%m-%d %H:%M:%S"
114 /** @} */ //END OF GROUP NETSRVMGR_TYPES
115 
116 /**
117  * @addtogroup NETSRVMGR_APIS
118  * @{
119  */
120 #ifdef ENABLE_RTMESSAGE
121 void rtConnection_init();
122 void* rtMessage_Receive(void* arg);
123 void rtConnection_destroy();
124 void onMessage(rtMessageHeader const* hdr, uint8_t const* buff, uint32_t n, void* closure);
125 void onConnectWifi(rtMessageHeader const* hdr, uint8_t const* buff, uint32_t n, void* closure);
126 #endif
127 
128 #ifdef ENABLE_IARM
129 /**
130  * @brief This function is used to get host interface parameters through IARM TR69 bus calls.
131  *
132  * @param[out] param Host Interface message data.
133  *
134  * @return Returns true if successfully gets the interface parameters, Otherwise false.
135  */
136 bool gpvFromTR069hostif( HOSTIF_MsgData_t *param);
137 #endif
138 /**
139  * @brief This function is used to get WIFI connectivity status.
140  *
141  * @return Returns WIFI connectivity status(whether uninstalled/disabled/disconnected/pairing/connecting/connected/failed).
142  */
144 
145 /**
146  * @brief This function is used to get WIFI connection type.
147  *
148  * @return Returns WIFI connection type(whether WPS/mannual/LNF/private).
149  */
150 WiFiConnectionTypeCode_t get_WifiConnectionType();
151 
152 /**
153  * @brief This function is used to get the ethernet connection ON/OFF status in order to proceed with IARM bus calls.
154  *
155  * @return Returns true if connection status OK, Otherwise false.
156  */
157 bool ethernet_on();
158 
159 /**
160  * @brief This function gets the host interface parameters through IARM TR69 calls and update BSS identifier list data.
161  *
162  * @return Returns false in case of WIFI disabled or any other error, Otherwise true in success case.
163  */
164 extern bool updateWiFiList();
165 extern ssidList gSsidList;
166 #ifdef ENABLE_IARM
167 extern IARM_Bus_Daemon_SysMode_t sysModeParam;
168 #endif
169 
170 /**
171  * @brief This function is used to cancel all the WIFI related threads and un initialize the WIFI module.
172  *
173  * @return Returns true if successfully terminated all operations, Otherwise false.
174  */
175 bool shutdownWifi();
176 #ifdef USE_RDK_WIFI_HAL
177 
178 /**
179  * @brief This function will check the current WIFI connection status and,
180  * 1. If status not connected, then it connects with WIFI type WPS.
181  * 2. If connected, then it Disconnect first, then again re-connect to same or different AP.
182  * This function waits for certain timeout period during the disconnection period to check the status.
183  *
184  * @return Returns true if successfully WPS connection made, Otherwise false.
185  */
186 bool connect_WpsPush();
187 
188 /**
189  * @brief This function will attempt to start WPS based on the supplied PIN.
190  * If currently connected to WiFi, this will disconnect before attempting WPS.
191  *
192  * @return Returns true on successful call to trigger WPS PIN, false otherwise.
193  */
194 bool connect_WpsPin(char* wps_pin);
195 
196 /**
197  * @brief This callback function received to handle WIFI connect action.
198  *
199  * @param[in] ssidIndex Service Set Identifier.
200  * @param[in] AP_SSID Access Point SSID.
201  * @param[in] connStatus WIFI connection status.
202  *
203  */
204 INT wifi_connect_callback(INT , CHAR *ap, wifiStatusCode_t *err);
205 
206 /**
207  * @brief This callback function received to handle WIFI disconnect action.
208  *
209  * @param[in] ssidIndex Service Set Identifier.
210  * @param[in] AP_SSID Access Point SSID.
211  * @param[in] connStatus WIFI connection status.
212  *
213  * @return Returns ok, after handled the required WIFI connectivity action.
214  */
215 INT wifi_disconnect_callback(INT , CHAR *ap, wifiStatusCode_t *err);
216 
217 /**
218  * @brief This function is used to connect WIFI from client with an AP using SSID selection.
219  * It uses the input parameters to connect using a supported security method and encryption standard.
220  * The security methods can make use of passphrase, public/private key pairs etc.
221  *
222  * @param[in] ssidIndex Service Set Identifier Index value.
223  * @param[in] ap_SSID Access Point SSID.
224  * @param[in] ap_security_mode AP security mode.
225  * @param[in] ap_security_WEPKey Security pass code of WIFI device.
226  * @param[in] ap_security_PreSharedKey The pre shared key.
227  * @param[in] ap_security_KeyPassphrase The key passphrase.
228  * @param[in] saveSSID Option to save profile in wpa supplicant.
229  * @param[in] eapIdentity Extensible Authentication Protocol Identity.
230  * @param[in] carootcert Network CA Root certificate.
231  * @param[in] clientcert Client certificate.
232  * @param[in] privatekey Private Key password.
233  * @param[in] conType WIFI connection type(WPS/MANNUAL/LNF/PRIVATE).
234  *
235  * @return Returns true if connection made successfully, Otherwise false in failure case.
236  */
237 bool connect_withSSID(int, char *, SsidSecurity, char *, char *, char *,int,char *,char *,char *,char *,int conType = 0);
238 
239 /**
240  * @brief This function is used to Start Wi-Fi scan & get the result to parser. This is used to manage endpoint list .
241  *
242  * @param[in] buffer Buffer to store Neighboring WIFI AP information(eg. ssid, security, signal strength, frequency,etc).
243  *
244  * @return Returns false in case of any failure to scan, Otherwise returns true in success case.
245  */
246 bool scan_Neighboring_WifiAP(char *);
247 
248 /**
249  * @brief This function is used to Start Wi-Fi scan with specified SSID details & get the result to parser.
250  * This is used to manage endpoint list.
251  *
252  * @param[in] buffer Buffer to store Specified SSID WIFI AP information(eg. ssid, security, signal strength, frequency,etc).
253  * @param[in] SSID SSID
254  * @param[in] freq_in Frequency
255  *
256  * @return Returns false in case of any failure to scan, Otherwise returns true in success case.
257  */
258 bool scan_SpecificSSID_WifiAP(char *buffer, const char* SSID, double freq_in);
259 
260 /**
261  * @brief This function is used to get previously connected SSID params(SSID, passphrase, bssid, security, etc.,).
262  *
263  * @param[out] ConnParams Connection param structure to store SSID parameters.
264  *
265  * @return Returns true if successfully gets all the details, Otherwise false.
266  */
267 bool lastConnectedSSID(WiFiConnectionStatus *ConnParams);
268 
269 /**
270  * @brief This function creates a thread to monitor wifi status events.
271  */
272 void monitor_WiFiStatus();
273 
274 /**
275  * @brief This function clears all previously configured SSID and password details and Disconnect to AP.
276  *
277  * @return Returns true if successfully disconnect all SSID, Otherwise false.
278  */
279 bool clearSSID_On_Disconnect_AP();
280 bool disconnectFromCurrentSSID();
281 
282 /**
283  * @brief This function gets WIFI hal version.
284  */
285 bool getHALVersion();
286 #ifdef WIFI_CLIENT_ROAMING
287 /**
288  * @brief This function is used to get WIFI roaming configurations details using SSID index.
289  *
290  * @param[out] param Roaming Control structure to store all configurations.
291  *
292  * @return Returns true if successfully gets all roaming configurations, Otherwise false.
293  */
294 bool getRoamingConfigInfo(WiFi_RoamingCtrl_t *param);
295 
296 /**
297  * @brief This function is used to set WIFI roaming configurations(roamingenabled, threshold, delta value etc.,).
298  *
299  * @param[in] param Roaming Control structure to store all configurations.
300  *
301  * @return Returns true if successfully set the roaming configurations, Otherwise false.
302  */
303 bool setRoamingConfigInfo(WiFi_RoamingCtrl_t *param);
304 #endif
305 #endif
306 
307 #ifdef ENABLE_LOST_FOUND
308 /**
309  * @brief This function returns the WIFI connection status(uninstalled/disabled/disconnected/pairing/connecting/connected/failed).
310  */
311 bool isWifiConnected();
312 
313 /**
314  * @brief This function ensures the device is not connected to LF SSID, so that it trigger the thread to connect to
315  * Lost and Found Wireless SSID.
316  */
317 void connectToLAF();
318 
319 /**
320  * @brief This function trigger the thread to connect to private connection.
321  */
322 void lafConnectToPrivate();
323 
324 /**
325  * @brief This function is used to get LAF Wireless SSID.
326  *
327  * @return Returns true if successfully gets the LAF SSID Otherwise false.
328  */
329 bool getLAFssid();
330 //bool isLAFCurrConnectedssid();
331 
332 /**
333  * @brief This function returns the WIFI LNF status(uninitialized/in progress/connected to LNF network/not connected to LNF network/
334  * unable to connect to LNF network/ etc.,).
335  */
336 WiFiLNFStatusCode_t get_WiFiLNFStatusCode();
337 void doLnFBackoff();
338 
339 /**
340  * @brief This function is used to loads application configuration and initializes client.
341  * Establish WIFI connection depends on input LAF request type(LNF SSID/PRIVATE WIFI).
342  *
343  * @param[in] lafRequestType Lost and Found Request Type(SSID,private WIFI).
344  */
345 bool triggerLostFound(LAF_REQUEST_TYPE lafRequestType);
346 
347 /**
348  * @brief This function is used to get the mac address from interface name.
349  *
350  * @param[in] ifname Interface Name.
351  * @param[out] data Buffer to return mac address.
352  *
353  * @return Returns true if successfully returns the mac address, Otherwise false.
354  */
355 bool getmacaddress(gchar* ifname,GString *data);
356 
357 #if defined(XHB1) || defined(XHC3)
358 /**
359  * @brief This function is used to get basic device info from camera.
360  *
361  * @param[in] stdatatype Device parameter to get value
362  * @param[out] data Buffer to return value.
363  *
364  * @return Returns true if successfully returns the parameter value, Otherwise false.
365  */
366 int getMfrDeviceInfo(mfrSerializedType_t stdatatype, char* data);
367 #endif
368 
369 /**
370  * @brief This function is used to get LAF device info details such as serial number, mac address, model name.
371  *
372  * @param[out] dev_info Buffer to return device info.
373  *
374  * @return Returns true if successfully gets all informations, Otherwise false.
375  */
376 bool getDeviceInfo(laf_device_info_t *dev_info);
377 
378 /**
379  * @brief This function is used to store the results which is from switch to private connection with current time.
380  *
381  * @param[in] lnfError Error code result.
382  * @param[in] currTime Current time.
383  */
384 bool addSwitchToPrivateResults(int lnfError,char *currTime);
385 
386 /**
387  * @brief This function is used to convert the results list maintained which is from switch to private connection to JSON format.
388  *
389  * @param[out] buffer Result Buffer in JSON format.
390  */
391 bool convertSwitchToPrivateResultsToJson(char *buffer);
392 
393 /**
394  * @brief This function clears the switch to private results list.
395  */
396 bool clearSwitchToPrivateResults();
397 #ifdef ENABLE_IARM
398 
399 /**
400  * @brief This function retrieves manufacturer specific data from the box.
401  *
402  * @param[in] mfrDataStr Structure to store manufacturer data.
403  * @param[in] mfrType Manufacturer data request type(model name, serial number, device mac, etc).
404  *
405  * @return Returns true if successfully gets the manufacturer data from IARM bus call, Otherwise false.
406  */
407 bool getMfrData(GString* mfrDataStr,mfrSerializedType_t mfrType);
408 #endif
409 
410 /**
411  * @brief Callback function to connect to WIFI using LF SSID.
412  *
413  * @param[in] wificred WIFI credentials(SSID, security mode, passphrase, private key, etc).
414  *
415  * @return Returns 0 once successfully established the connection, Otherwise return appropriate error code.
416  */
417 int laf_wifi_connect(laf_wifi_ssid_t* const wificred);
418 
419 /**
420  * @brief Callback function to disconnect to WIFI.
421  *
422  * @return Returns 0 once successfully disconnected the connection.
423  */
424 int laf_wifi_disconnect(void);
425 int laf_get_lfat(laf_lfat_t *lfat);
426 int laf_set_lfat(laf_lfat_t* const lfat);
427 
428 /**
429  * @brief Callback function to log messages from lost and found.
430  *
431  * @param[in] level Log level.
432  * @param[in] function Function name.
433  * @param[in] line Line number.
434  * @param[in] msg Log message.
435  */
436 void log_message(laf_loglevel_t level, char const* function, int line, char const* msg);
437 #ifdef ENABLE_IARM
438 static void _eventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
439 #endif
440 
441 /**
442  * @brief This Function is used to get the device activation state.
443  *
444  * @return Returns true if device is activated, false if not activated.
445  */
446 bool getDeviceActivationState();
447 
448 /**
449  * @brief This function is used to start LAF private SSID connection.
450  */
451 void lnfConnectPrivCredentials();
452 #endif
453 
454 /**
455  * @brief This function is used to check whether the device supports wireless communication or not.
456  *
457  * @return Returns true if the device supports wireless connections,Otherwise false.
458  */
459 bool isWiFiCapable();
460 
461 /**
462  * @brief This function is used to get current SSID and connection status from persistent memory.
463  *
464  * @param[out] currSsidConnInfo SSID connection details structure.
465  */
466 void get_CurrentSsidInfo(WiFiConnectionStatus *currSsidConnInfo);
467 #ifdef ENABLE_IARM
468 
469 /**
470  * @brief This function is used to sent iarm message to set hostif parameter.
471  *
472  * @param[in] name Parameter name.
473  * @param[in] type Parameter type(string/date and time/boolean).
474  * @param[in] value Parameter value.
475  *
476  * @return Returns true if successfully sent the iarm message, Otherwise false.
477  */
478 bool setHostifParam (const char *name, HostIf_ParamType_t type, void *value);
479 #endif
480 
481 /**
482  * @brief This function converts the input data to Boolean type.
483  *
484  * @param[in] ptr Address to store the boolean value.
485  * @param[in] val Boolean value.
486  */
487 void put_boolean(char *ptr, bool val);
488 
489 /**
490  * @brief This function converts the input data to integer type.
491  *
492  * @param[in] ptr Address to store the integer value.
493  * @param[in] val Integer value.
494  */
495 void put_int(char *ptr, int val);
496 
497 /**
498  * @brief This function retrieve and store the WIFI credentials(SSID, password).
499  *
500  * @return Returns true if successfully stored the MFR WIFI credentials, Otherwise false.
501  */
502 bool storeMfrWifiCredentials(void);
503 
504 /**
505  * @brief This function erase the stored MFR WIFI credentials.
506  *
507  * @return Returns true if successfully erased the MFR WIFI credentials, Otherwise false.
508  */
509 bool eraseMfrWifiCredentials(void);
510 
511 #ifdef ENABLE_IARM
512 /**
513  * @brief This function connects to the ssid details stored by MFR
514  *
515  * @return Returns true if successfully connects to MFR WIFI credentials, Otherwise false.
516  */
517 bool connectToMfrWifiCredentials(void);
518 #endif
519 
520 /**
521  * @brief This function is used to get detail radio traffic statistics information.
522  *
523  * @param[out] params Structure that saves the traffic statistics.
524  *
525  * @return Returns true if successfully gets all traffic statistics informations, Otherwise false.
526  */
528 
529 /**
530  * @brief This function is used to get the connected SSID informations such as SSID, BSSID, signal strength etc,.
531  *
532  * @param[out] WiFiConnectedSSIDInfo_t Structure that saves the connected SSID details.
533  */
535 
536 /**
537  * @brief This function checks for WIFI connection enable status,
538  * If connection enabled, then it provide WIFI statistics information such as enable status, SSID, signal strength,
539  * data transmission rate etc.,
540  *
541  * @param[out] WiFi_EndPoint_Diag_Params WIFI end point diagnostic parameter.
542  */
544 bool cancelWPSPairingOperation();
545 
546 /** @} */ //END OF GROUP NETSRVMGR_APIS
547 #endif /* WIFIHALUTILES_H_ */
storeMfrWifiCredentials
bool storeMfrWifiCredentials(void)
This function retrieve and store the WIFI credentials(SSID, password).
Definition: wifiHalUtiles.cpp:3264
_WiFi_Radio_Stats_Diag_Params
Definition: wifiSrvMgrIarmIf.h:352
shutdownWifi
bool shutdownWifi()
This function is used to cancel all the WIFI related threads and un initialize the WIFI module.
Definition: wifiHalUtiles.cpp:3955
WiFiStatusCode_t
enum _WiFiStatusCode_t WiFiStatusCode_t
isWiFiCapable
bool isWiFiCapable()
This function is used to check whether the device supports wireless communication or not.
Definition: wifiHalUtiles.cpp:1922
sysMgr.h
IARM-Bus Sys Manager Public API.
_WiFiConnectedSSIDInfo
Definition: wifiSrvMgrIarmIf.h:211
_ssidList
Definition: wifiSrvMgrIarmIf.h:164
getEndPointInfo
void getEndPointInfo(WiFi_EndPoint_Diag_Params *)
This function checks for WIFI connection enable status, If connection enabled, then it provide WIFI s...
Definition: wifiHalUtiles.cpp:3364
get_WifiConnectionType
WiFiConnectionTypeCode_t get_WifiConnectionType()
This function is used to get WIFI connection type.
Definition: wifiHalUtiles.cpp:541
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
getConnectedSSIDInfo
void getConnectedSSIDInfo(WiFiConnectedSSIDInfo_t *)
This function is used to get the connected SSID informations such as SSID, BSSID, signal strength etc...
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: hostIf_utils.cpp:191
getRadioStats
bool getRadioStats(WiFi_Radio_Stats_Diag_Params *params)
This function is used to get detail radio traffic statistics information.
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
ethernet_on
bool ethernet_on()
This function is used to get the ethernet connection ON/OFF status in order to proceed with IARM bus ...
Definition: wifiHalUtiles.cpp:387
eraseMfrWifiCredentials
bool eraseMfrWifiCredentials(void)
This function erase the stored MFR WIFI credentials.
Definition: wifiHalUtiles.cpp:3342
_WiFiConnectionStatus
Definition: wifiSrvMgrIarmIf.h:204
getmacaddress
gchar * getmacaddress(const gchar *ifname)
This function is used to get the mac address of the target device.
Definition: xcal-device.c:2253
HostIf_ParamType_t
enum _HostIf_ParamType HostIf_ParamType_t
updateWiFiList
bool updateWiFiList()
This function gets the host interface parameters through IARM TR69 calls and update BSS identifier li...
_WiFi_EndPoint_Diag_Params
Definition: wifiSrvMgrIarmIf.h:385
get_WifiRadioStatus
WiFiStatusCode_t get_WifiRadioStatus()
This function is used to get WIFI connectivity status.
Definition: wifiHalUtiles.cpp:518
get_CurrentSsidInfo
void get_CurrentSsidInfo(WiFiConnectionStatus *currSsidConnInfo)
This function is used to get current SSID and connection status from persistent memory.
Definition: wifiHalUtiles.cpp:512
WiFiLNFStatusCode_t
enum _WiFiLNFStatusCode_t WiFiLNFStatusCode_t
wifiStatusCode_t
wifiStatusCode_t
Enumerators for Wi-Fi connection status.
Definition: wifi_common_hal.h:290