RDK Documentation (Open Sourced RDK Components)
wifiHalUtiles.cpp
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 #include "wifiHalUtiles.h"
21 #include "netsrvmgrUtiles.h"
22 
23 #include <fstream>
24 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
25 #include <cJSON.h>
26 
27 #include "sysMgr.h"
28 #include <libIBus.h>
29 #include <libIARMCore.h>
30 
31 #include "xdiscovery.h"
32 
33 #include "rfcapi.h" // for RFC queries
34 #endif
35 
36 #ifdef ENABLE_LOST_FOUND
37 #include <time.h>
38 #endif // ENABLE_LOST_FOUND
39 
40 #ifdef ENABLE_RTMESSAGE
41 rtConnection con_recv = NULL;
42 #endif
43 
44 #ifdef YOCTO_BUILD
45 extern "C" {
46 #include "secure_wrapper.h"
47 }
48 #endif
49 #ifdef SAFEC_RDKV
50 #include "safec_lib.h"
51 #else
52 #define STRCPY_S(dest,size,source) \
53  strcpy(dest, source);
54 #endif
55 
56 #include <sys/stat.h>
57 #include <stdlib.h>
58 
59 #define WIFI_HAL_VERSION_SIZE 6
60 #define MAX_WIFI_STATUS_STRING 32
61 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
62 #define MAX_DEVICE_INFO_STRING_LENGTH 32
63 #endif
64 
65 static WiFiStatusCode_t gWifiAdopterStatus = WIFI_UNINSTALLED;
66 static WiFiConnectionTypeCode_t gWifiConnectionType = WIFI_CON_UNKNOWN;
67 gchar deviceID[DEVICEID_SIZE];
68 gchar partnerID[PARTNERID_SIZE];
69 static char wifiHALVer[WIFI_HAL_VERSION_SIZE]={0};
70 #ifdef ENABLE_LOST_FOUND
71 GList *lstLnfPvtResults=NULL;
72 #define WAIT_TIME_FOR_PRIVATE_CONNECTION 2
73 bool startLAF = false;
74 pthread_mutex_t mutexLAF = PTHREAD_MUTEX_INITIALIZER;
75 pthread_cond_t condLAF = PTHREAD_COND_INITIALIZER;
76 static pthread_mutex_t mutexTriggerLAF = PTHREAD_MUTEX_INITIALIZER;
77 static laf_status_t last_laf_status = {.errcode = 0, .backoff = 0.0f};
78 static struct timespec last_lnf_server_contact_time;
79 pthread_t lafConnectThread;
80 pthread_t lafConnectToPrivateThread;
81 WiFiLNFStatusCode_t gWifiLNFStatus = LNF_UNITIALIZED;
82 bool bDeviceActivated=false;
83 bool bLnfActivationLoop=false;
84 bool bLNFConnect=false;
85 bool bStopLNFWhileDisconnected=false;
86 bool isLAFCurrConnectedssid=false;
87 bool bIsStopLNFWhileDisconnected=false;
88 bool bAutoSwitchToPrivateEnabled=true;
89 bool bSwitch2Private=false;
90 bool bPrivConnectionLost=false;
91 #define TOTAL_NO_OF_RETRY 5
92 #endif
93 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
94 int apDetailsBuffLength;
95 bool bsignalAPDetailsReady = true;
96 pthread_cond_t condAPDetails = PTHREAD_COND_INITIALIZER;
97 pthread_mutex_t mutexAPDetails = PTHREAD_MUTEX_INITIALIZER;
98 pthread_t apDetailsCollectionThread;
99 char deviceModel[MAX_DEVICE_INFO_STRING_LENGTH] = {0};
100 char deviceMake[MAX_DEVICE_INFO_STRING_LENGTH] = {0};
101 char deviceMACAddr[MAX_DEVICE_INFO_STRING_LENGTH] = {0};
102 #endif
103 bool bShutdownWifi=false;
104 pthread_t wifiStatusMonitorThread;
105 WiFiStatusCode_t getWpaStatus();
106 static WiFiConnection wifiConnData;
107 
108 static eConnMethodType wifi_conn_type;
109 
110 pthread_mutex_t wifiStatusLock = PTHREAD_MUTEX_INITIALIZER;
111 pthread_cond_t condGo = PTHREAD_COND_INITIALIZER;
112 pthread_mutex_t mutexGo = PTHREAD_MUTEX_INITIALIZER;
113 extern netMgrConfigProps confProp;
114 
116 void setLNFState(WiFiLNFStatusCode_t status);
117 
118 void set_WiFiConnectionType( WiFiConnectionTypeCode_t value);
119 WiFiConnectionTypeCode_t get_WifiConnectionType();
120 
121 extern WiFiConnectionStatus savedWiFiConnList;
122 extern char gWifiMacAddress[MAC_ADDR_BUFF_LEN];
123 #ifdef USE_RDK_WIFI_HAL
124 static void wifi_status_action (wifiStatusCode_t , char *, unsigned short );
125 static wifiStatusCode_t connCode_prev_state;
126 
127 extern telemetryParams wifiParams_Tele_Period1;
128 extern telemetryParams wifiParams_Tele_Period2;
129 static void logs_Period1_Params();
130 static void logs_Period2_Params();
131 #endif
132 
133 #ifdef ENABLE_NLMONITOR
134 #include "netlinkifc.h"
135 #endif //ENABLE_NLMONITOR
136 
137 #define RDK_ASSERT_NOT_NULL(P) if ((P) == NULL) return EINVAL
138 #define SECURITY_MODE_WPA_EAP "WPA-EAP"
139 #define SECURITY_MODE_WPA_PSK "WPA-PSK"
140 #define SECURITY_MODE_SAE "SAE"
141 #define WIFI_HAL_VERSION "1.0.0"
142 //#define LFAT_VERSION "lfat_version"
143 //#define LFAT_TTL "lfat_ttl"
144 #define LFAT_CONF_FILE "/mnt/ramdisk/env/.lnf_conf"
145 #define DATA_LEN 4096
146 #define SCRIPT_FILE_TO_GET_DEVICE_ID "/lib/rdk/getDeviceId.sh"
147 #define WIFI_CONNECT_TIME 30
148 
149 typedef struct _wifi_securityModes
150 {
151  SsidSecurity securityMode;
152  const char *modeString;
154 
155 wifi_securityModes wifi_securityModesMap_Netapp[] =
156 {
157  { NET_WIFI_SECURITY_NONE, "No Security" },
158  { NET_WIFI_SECURITY_WEP_64, "WEP (Open & Shared)" },
159  { NET_WIFI_SECURITY_WPA_PSK_AES, "WPA-Personal, AES encryp." },
160  { NET_WIFI_SECURITY_WPA_PSK_TKIP, "WPA-Personal, TKIP encryp." },
161  { NET_WIFI_SECURITY_WPA2_PSK_AES, "WPA2-Personal, AES encryp." },
162  { NET_WIFI_SECURITY_WPA2_PSK_TKIP, "WPA2-Personal, TKIP encryp." },
163  { NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP, "WPA-ENTERPRISE, TKIP" },
164  { NET_WIFI_SECURITY_WPA_ENTERPRISE_AES, "WPA-ENTERPRISE, AES" },
165  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP, "WPA2-ENTERPRISE, TKIP" },
166  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES, "WPA2-ENTERPRISE, AES" },
167  { NET_WIFI_SECURITY_WPA_WPA2_PSK, "WPA-WPA2-Personal" },
168  { NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE, "WPA-WPA2-ENTERPRISE" },
169  { NET_WIFI_SECURITY_WPA3_SAE, "WPA3" },
170  { NET_WIFI_SECURITY_WPA3_PSK_AES, "WPA2-WPA3" },
171  { NET_WIFI_SECURITY_NOT_SUPPORTED, "Security format not supported" },
172 };
173 
174 wifi_securityModes wifi_securityModesMap[] =
175 {
176  { NET_WIFI_SECURITY_NONE, "None" },
177  { NET_WIFI_SECURITY_WEP_64, "WEP" },
178  { NET_WIFI_SECURITY_WPA_PSK_TKIP, "WPA" },
179  { NET_WIFI_SECURITY_WPA_PSK_AES, "WPA" },
180  { NET_WIFI_SECURITY_WPA2_PSK_TKIP, "WPA2" },
181  { NET_WIFI_SECURITY_WPA2_PSK_AES, "WPA2" },
182  { NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP, "WPA-ENTERPRISE" },
183  { NET_WIFI_SECURITY_WPA_ENTERPRISE_AES, "WPA-ENTERPRISE" },
184  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP, "WPA2-ENTERPRISE" },
185  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES, "WPA2-ENTERPRISE" },
186  { NET_WIFI_SECURITY_WPA_WPA2_PSK, "WPA-WPA2" },
187  { NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE, "WPA-WPA2-ENTERPRISE" },
188  { NET_WIFI_SECURITY_WPA3_SAE, "WPA3" },
189  { NET_WIFI_SECURITY_WPA3_PSK_AES, "WPA2-WPA3" },
190  { NET_WIFI_SECURITY_NOT_SUPPORTED, "Security format not supported" },
191 };
192 
193 #ifdef ENABLE_RTMESSAGE
194 void rtConnection_init()
195 {
196  rtLog_SetLevel(RT_LOG_INFO);
197  rtLog_SetOption(rdkLog);
198  rtConnection_Create(&con_recv, "NETSRVMGR_WIFI", SOCKET_ADDRESS);
199  rtConnection_AddListener(con_recv, "RDKC.WIFI", onMessage, con_recv);
200 #if defined(XHB1) || defined(XHC3)
201  rtConnection_AddListener(con_recv, "RDKC.WIFI.CONNECT", onConnectWifi, con_recv);
202 #endif
203  LOG_INFO("rtConnection_init done");
204 }
205 
206 void rtConnection_destroy()
207 {
208  rtConnection_Destroy(con_recv);
209 }
210 
211 void onMessage(rtMessageHeader const* hdr, uint8_t const* buff, uint32_t n, void* closure)
212 {
213  rtConnection con_recv = (rtConnection) closure;
214 
215  rtMessage req;
216  rtMessage_FromBytes(&req, buff, n);
217 
218  if (rtMessageHeader_IsRequest(hdr))
219  {
220  char* buff = NULL;
221  uint32_t buff_length = 0;
222 
223  rtMessage_ToString(req, &buff, &buff_length);
224  rtLog_Info("Req : %.*s", buff_length, buff);
225  free(buff);
226 
227  // create response
228  rtMessage res;
229  rtMessage_Create(&res);
230  rtMessage_SetString(res, "reply", "Success");
231  rtConnection_SendResponse(con_recv, hdr, res, 1000);
232  rtMessage_Release(res);
233  }
234  rtMessage_Release(req);
235 }
236 
237 void onConnectWifi(rtMessageHeader const* hdr, uint8_t const* buff, uint32_t n, void* closure)
238 {
239  LOG_INFO("Called onConnectWifi");
240 
241  rtConnection con_recv = (rtConnection) closure;
242 
243  int ssidIndex = 1;
244  char const* ap_SSID = NULL;
245  int32_t securityMode = 0;
246  char const* ap_security_PreSharedKey = NULL;
247  int saveSSID = 1;
248  int32_t retVal = 1;
249 
250  rtMessage req;
251  rtMessage_FromBytes(&req, buff, n);
252 
253  if (rtMessageHeader_IsRequest(hdr))
254  {
255  char* buff = NULL;
256  uint32_t buff_length = 0;
257  char jbuff[MAX_SSIDLIST_BUF] = {'\0'};
258  int jBuffLen = 0;
259 
260  rtMessage_ToString(req, &buff, &buff_length);
261  rtLog_Info("Req : %.*s", buff_length, buff);
262  free(buff);
263 
264  rtMessage_GetString(req, "ap_SSID", &ap_SSID);
265  rtMessage_GetInt32(req, "securityMode", &securityMode);
266  rtMessage_GetString(req, "ap_security_PreSharedKey", &ap_security_PreSharedKey);
267  LOG_INFO("Received ap_SSID : %s securityMode : %d ap_security_PreSharedKey : %s", ap_SSID, securityMode, ap_security_PreSharedKey);
268 
269 #ifdef USE_RDK_WIFI_HAL
270 /* int status = scan_Neighboring_WifiAP(jbuff);
271  jBuffLen = strlen(jbuff);
272  LOG_INFO( "[%s] Scan AP's SSID list buffer size : \n\"%d\"", MODULE_NAME, jBuffLen);*/
273 #endif
274 
275  retVal = connect_withSSID(ssidIndex, const_cast<char*>(ap_SSID), (SsidSecurity)6, NULL, const_cast<char*>(ap_security_PreSharedKey), const_cast<char*>(ap_security_PreSharedKey), saveSSID, NULL, NULL, NULL, NULL, WIFI_CON_PRIVATE);
276 
277  if (retVal)
278  {
279  int retry = 0;
280 
281  while (false == isWifiConnected() && retry <= WIFI_CONNECT_TIME)
282  {
283  LOG_INFO("Waiting for wifi connection");
284  sleep(1);
285  retry++;
286  }
287 
288  if (true == isWifiConnected())
289  {
290  LOG_INFO("Wifi connection success");
291  retVal = 0;
292  }
293  else if (retry >= WIFI_CONNECT_TIME)
294  {
295  LOG_INFO("Wifi connection time out");
296  }
297  }
298 
299  // create response
300  rtMessage res;
301  rtMessage_Create(&res);
302  rtMessage_SetInt32(res, "reply", retVal);
303  rtConnection_SendResponse(con_recv, hdr, res, 1000);
304  rtMessage_Release(res);
305  }
306  rtMessage_Release(req);
307 }
308 
309 void* rtMessage_Receive(void*)
310 {
311  LOG_INFO("rtMessage_Receive");
312  while (1)
313  {
314  rtError err = rtConnection_Dispatch(con_recv);
315  if (err != RT_OK)
316  {
317  LOG_DBG("Dispatch Error: %s", rtStrError(err));
318  }
319  //Adding sleep to avoid logs flooding in case of rtrouted bad state
320  usleep(10000);
321  }
322 }
323 #endif
324 
325 
326 #ifdef USE_RDK_WIFI_HAL
327 bool getHALVersion()
328 {
329  if(wifiHALVer[0] == 0)
330  {
331  wifi_getHalVersion(wifiHALVer);
332  LOG_INFO("[%s] WiFi HAL Version is %s",MODULE_NAME, wifiHALVer);
333  }
334  return true;
335 }
336 #endif
337 
338 SsidSecurity get_wifiSecurityModeFromString(char *secModeString, char *encryptionType)
339 {
340  if (!secModeString || !encryptionType)
341  {
342  LOG_ERR("[%s] Failed due to NULL.", MODULE_NAME);
343  return NET_WIFI_SECURITY_NONE;
344  }
345  LOG_TRACE("[%s] securitymode = %s encryption = %s",
346  MODULE_NAME, secModeString, encryptionType);
347  if (strlen(secModeString) == 0 && strlen(encryptionType) == 0)
348  return NET_WIFI_SECURITY_NONE;
349  if (0 == strcmp(wifiHALVer,WIFI_HAL_VERSION))
350  {
351  int len = sizeof(wifi_securityModesMap_Netapp)/sizeof(wifi_securityModes);
352  for (int i = 0; i < len; i++)
353  {
354  if (strcasestr(secModeString, wifi_securityModesMap_Netapp[i].modeString))
355  return wifi_securityModesMap_Netapp[i].securityMode;
356  }
357  }
358  else
359  {
360  int len = sizeof(wifi_securityModesMap)/sizeof(wifi_securityModes);
361  for (int i = len-1; i >= 0; i--)
362  {
363  if (strcasestr(secModeString, wifi_securityModesMap[i].modeString))
364  {
365  if (strcasestr(encryptionType, "AES") || strcasestr(secModeString, "WEP"))
366  return wifi_securityModesMap[i].securityMode;
367  else
368  return wifi_securityModesMap[i-1].securityMode;
369  }
370  }
371  }
372  return NET_WIFI_SECURITY_NOT_SUPPORTED;
373 }
374 
375 int get_int(const char* ptr)
376 {
377  int *ret = (int *)ptr;
378  return *ret;
379 }
380 
381 bool get_boolean(const char *ptr)
382 {
383  bool *ret = (bool *)ptr;
384  return *ret;
385 }
386 
388 {
389  if(access( "/tmp/wifi-on", F_OK ) != -1 )
390  return false;
391  else
392  return true;
393 }
394 
395 unsigned long getUptimeMS(void)
396 {
397  std::ifstream file("/proc/uptime");
398  if (file.is_open())
399  {
400  char buffer[65];
401  file.getline(buffer, sizeof buffer - 1);
402  file.close();
403  double uptime = atof(buffer);
404  return uptime*1000;
405  }
406  return 0;
407 }
408 
409 void logMilestone(const char *msg_code)
410 {
411  FILE *fp = NULL;
412  fp = fopen("/opt/logs/rdk_milestones.log", "a+");
413  if (fp != NULL)
414  {
415  fprintf(fp, "%s:%ld\n", msg_code, getUptimeMS());
416  fclose(fp);
417  }
418 }
419 
420 #ifdef ENABLE_IARM
421 static IARM_Result_t WiFi_IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
422 {
423  // if( !ethernet_on() )
424  IARM_Bus_BroadcastEvent(ownerName, eventId, data, len);
425  return IARM_RESULT_SUCCESS;
426 }
427 
428 bool getMfrData(GString* mfrDataStr,mfrSerializedType_t mfrType)
429 {
430  bool bRet;
432  IARM_Result_t iarmRet = IARM_RESULT_IPCCORE_FAIL;
433  LOG_TRACE("[%s] Enter", MODULE_NAME);
434  memset(&param, 0, sizeof(param));
435  param.type = mfrType;
437  if(iarmRet == IARM_RESULT_SUCCESS)
438  {
439  if(param.buffer && param.bufLen)
440  {
441  LOG_TRACE("[%s] serialized data %s for mfrtype %d", MODULE_NAME, param.buffer,mfrType );
442  g_string_assign(mfrDataStr,param.buffer);
443  bRet = true;
444  }
445  else
446  {
447  LOG_ERR("[%s] serialized data is empty for mfrtype %d ",MODULE_NAME, mfrType );
448  bRet = false;
449  }
450  }
451  else
452  {
453  bRet = false;
454  LOG_ERR("[%s] IARM CALL failed for mfrtype %d",MODULE_NAME, mfrType );
455  }
456  LOG_TRACE("[%s] Exit", MODULE_NAME);
457  return bRet;
458 }
459 #endif
460 
461 static void set_WiFiStatusCode( WiFiStatusCode_t status)
462 {
463  pthread_mutex_lock(&wifiStatusLock);
464  if(gWifiAdopterStatus != status)
465  LOG_TRACE("[%s] Wifi Status changed to %d", MODULE_NAME, status );
466  gWifiAdopterStatus = status;
467  pthread_mutex_unlock(&wifiStatusLock);
468 }
469 
470 static WiFiStatusCode_t get_WiFiStatusCode()
471 {
472  return gWifiAdopterStatus;
473 }
474 
475 static bool get_WiFiStatusCodeAsString (WiFiStatusCode_t code, char* string)
476 {
477  switch (code)
478  {
479  case WIFI_UNINSTALLED:
480  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "UNINSTALLED");
481  break;
482  case WIFI_DISABLED:
483  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "DISABLED");
484  break;
485  case WIFI_DISCONNECTED:
486  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "DISCONNECTED");
487  break;
488  case WIFI_PAIRING:
489  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "PAIRING");
490  break;
491  case WIFI_CONNECTING:
492  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "CONNECTING");
493  break;
494  case WIFI_CONNECTED:
495  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "CONNECTED");
496  break;
497  case WIFI_FAILED:
498  STRCPY_S (string, MAX_WIFI_STATUS_STRING, "FAILED");
499  break;
500  default:
501  return false;
502  }
503  return true;
504 }
505 
506 #ifdef ENABLE_LOST_FOUND
507 WiFiLNFStatusCode_t get_WiFiLNFStatusCode()
508 {
509  return gWifiLNFStatus;
510 }
511 #endif
513 {
514  strncpy(curSSIDConnInfo->ssidSession.ssid, wifiConnData.ssid, SSID_SIZE);
515  curSSIDConnInfo->isConnected = (WIFI_CONNECTED == get_WiFiStatusCode())? true: false;
516 }
517 
519 {
521  LOG_TRACE("[%s] Enter", MODULE_NAME);
522  status = get_WiFiStatusCode();
523  LOG_TRACE("[%s] Exit with state %d", MODULE_NAME, status );
524  return status;
525 }
526 
527 void set_WiFiConnectionType( WiFiConnectionTypeCode_t value)
528 {
529  if(value < 0 || value > WIFI_CON_MAX)
530  {
531  LOG_ERR("[%s] Trying to set invalid Wifi Connection Type %d ", MODULE_NAME, value );
532  return;
533  }
534 
535  if(gWifiConnectionType != value)
536  LOG_ERR("[%s] Wifi Connection Type changed to %d ..", MODULE_NAME, value );
537 
538  gWifiConnectionType = value;
539 }
540 
541 WiFiConnectionTypeCode_t get_WifiConnectionType()
542 {
543  return gWifiConnectionType;
544 }
545 
546 #ifdef USE_HOSTIF_WIFI_HAL
547 bool updateWiFiList()
548 {
549  bool ret = false;
550 #ifdef ENABLE_IARM
551  HOSTIF_MsgData_t wifiParam = {0};
552 
553  LOG_TRACE("[%s] Enter", MODULE_NAME);
554 
555  memset(&wifiParam, '\0', sizeof(HOSTIF_MsgData_t));
556  strncpy(wifiParam.paramName, WIFI_SSID_ENABLE_PARAM, strlen(WIFI_SSID_ENABLE_PARAM) +1);
557  wifiParam.instanceNum = 0;
558  wifiParam.paramtype = hostIf_BooleanType;
559 
560  memset(&gSsidList, '\0', sizeof(ssidList));
561  ret = gpvFromTR069hostif(&wifiParam);
562 
563  if(ret)
564  {
565  bool ssidStatus = get_boolean(wifiParam.paramValue);
566 
567  LOG_DBG("[%s] Retrieved values from tr69hostif as \'%s\':\'%d\'.", MODULE_NAME, WIFI_SSID_ENABLE_PARAM, ssidStatus);
568 
569  if(ssidStatus)
570  {
571  // Get SSID
572  memset(&wifiParam, '\0', sizeof(HOSTIF_MsgData_t));
573  strncpy(wifiParam.paramName, WIFI_SSID_NAME_PARAM, strlen(WIFI_SSID_NAME_PARAM) +1);
574  wifiParam.paramtype = hostIf_StringType;
575  wifiParam.instanceNum = 0;
576  ret = gpvFromTR069hostif(&wifiParam);
577 
578  if(ret)
579  {
580  strncpy(gSsidList.ssid, wifiParam.paramValue, sizeof(gSsidList.ssid));
581  }
582 
583  // Get SSID
584  memset(&wifiParam, '\0', sizeof(HOSTIF_MsgData_t));
585  strncpy(wifiParam.paramName, WIFI_SSID_BSSID_PARAM, strlen(WIFI_SSID_BSSID_PARAM) +1);
586  wifiParam.paramtype = hostIf_StringType;
587  wifiParam.instanceNum = 0;
588  ret = gpvFromTR069hostif(&wifiParam);
589 
590  if(ret)
591  {
592  strncpy(gSsidList.bssid, wifiParam.paramValue, sizeof(gSsidList.bssid));
593  }
594 
595  /* Not Implemented in tr69 Hal.*/
596  gSsidList.frequency = -1;
597  gSsidList.signalstrength = -1;
598 
599 
600  }
601  else
602  {
603  LOG_INFO("[%s] WiFi is disabled. [\'%s\':%d] ", MODULE_NAME, WIFI_SSID_ENABLE_PARAM, ssidStatus);
604  ret = false;
605  }
606  }
607 
608  LOG_TRACE("[%s] Exit", MODULE_NAME );
609 #endif
610  return ret;
611 }
612 
613 
614 
615 
616 //---------------------------------------------------------
617 // generic Api for get HostIf parameters through IARM_TR69Bus
618 // --------------------------------------------------------
619 #ifdef ENABLE_IARM
620 bool gpvFromTR069hostif( HOSTIF_MsgData_t *param)
621 {
622  IARM_Result_t ret = IARM_RESULT_IPCCORE_FAIL;
623 
624  param->reqType = HOSTIF_GET;
625 // HOSTIF_MsgData_t param = &wifiParam;
626 
627  LOG_TRACE("[%s] Enter", MODULE_NAME);
628 
629  /* IARM get Call*/
631 
632  if(ret != IARM_RESULT_SUCCESS)
633  {
634  LOG_FATAL("[%s] Failed with returned \'%d\' for '\%s\''.", MODULE_NAME, ret, param->paramName);
635  //ret = ERR_REQUEST_DENIED;
636  return false;
637  }
638  else
639  {
640  ret = IARM_RESULT_SUCCESS;
641  LOG_DBG("[%s] Successfully returned the value of \'%s\'.", MODULE_NAME, param->paramName);
642  }
643  LOG_TRACE("[%s] Exit", MODULE_NAME );
644  return true;
645 }
646 #endif
647 #endif /* #ifdef USE_HOSTIF_WIFI_HAL */
648 
649 void getWpaSsid(WiFiConnectionStatus *curSSIDConnInfo) {
650  FILE *in = NULL;
651  char buff[512] = {'\0'};
652 
653  LOG_TRACE("[%s] Enter", MODULE_NAME);
654 
655  if ( WIFI_CONNECTED == getWpaStatus())
656  {
657  if(!(in = popen("wpa_cli status | grep -i '^ssid' | cut -d = -f 2", "r")))
658  {
659  LOG_FATAL("[%s] Failed to read wpa_cli status.", MODULE_NAME);
660  return;
661  }
662 
663  if(fgets(buff, sizeof(buff), in)!=NULL)
664  {
665  LOG_DBG("[%s] SSID: %s", MODULE_NAME, buff);
666  size_t len = strlen(buff);
667  if (len > 0 && buff[len-1] == '\n') {
668  buff[len-1] = '\0';
669  }
670  strncpy(curSSIDConnInfo->ssidSession.ssid, buff, SSID_SIZE);
671  curSSIDConnInfo->isConnected = true;
672  }
673  else {
674  LOG_FATAL("[%s] Failed to get SSID.", MODULE_NAME);
675  }
676  pclose(in);
677 
678  }
679  else {
680  curSSIDConnInfo->isConnected = false;
681  }
682 }
683 
684 WiFiStatusCode_t getWpaStatus()
685 {
686  WiFiStatusCode_t wpa_state = WIFI_DISCONNECTED; // default to this state
687  FILE *in = NULL;
688  char buff[512] = {'\0'};
689 
690  LOG_TRACE("[%s] Enter", MODULE_NAME);
691 
692  if(!(in = popen("wpa_cli status | grep -i wpa_state | cut -d = -f 2", "r")))
693  {
694  LOG_ERR("[%s] Failed to read wpa_cli status.", MODULE_NAME);
695  return wpa_state;
696  }
697 
698  char* c = fgets(buff, sizeof(buff), in);
699 
700  pclose(in);
701 
702  if (c == NULL)
703  {
704  LOG_ERR("[%s] Failed to get State.", MODULE_NAME);
705  return wpa_state;
706  }
707 
708  LOG_INFO("[%s] State: %s", MODULE_NAME, buff);
709 
710  // possible wpa_state values (as seen in wpa_supplicant_state_txt() function of wpa_supplicant) are:
711  // DISCONNECTED, INACTIVE, INTERFACE_DISABLED, SCANNING,
712  // AUTHENTICATING, ASSOCIATING, ASSOCIATED, 4WAY_HANDSHAKE, GROUP_HANDSHAKE,
713  // COMPLETED, UNKNOWN
714  if (0 == strncasecmp(buff, "SCANNING", strlen("SCANNING")))
715  {
716  wpa_state = WIFI_PAIRING;
717  }
718  else if (0 == strncasecmp(buff, "AUTHENTICATING", strlen("AUTHENTICATING")) ||
719  0 == strncasecmp(buff, "ASSOCIATING", strlen("ASSOCIATING")) ||
720  0 == strncasecmp(buff, "ASSOCIATED", strlen("ASSOCIATED")) ||
721  0 == strncasecmp(buff, "4WAY_HANDSHAKE", strlen("4WAY_HANDSHAKE")) ||
722  0 == strncasecmp(buff, "GROUP_HANDSHAKE", strlen("GROUP_HANDSHAKE")))
723  {
724  wpa_state = WIFI_CONNECTING;
725  }
726  else if (0 == strncasecmp(buff, "COMPLETED", strlen("COMPLETED")))
727  {
728  wpa_state = WIFI_CONNECTED;
729  }
730  else if (0 == strncasecmp(buff, "INTERFACE_DISABLED", strlen("INTERFACE_DISABLED")))
731  {
732  wpa_state = WIFI_DISABLED;
733  }
734 
735  LOG_TRACE("[%s] Exit", MODULE_NAME );
736  return wpa_state;
737 }
738 
739 #ifdef USE_RDK_WIFI_HAL
740 
741 /*Connect using WPS Push */
742 bool connect_WpsPush()
743 {
744  bool ret = false;
745  INT ssidIndex = 1;
746  INT wpsStatus = RETURN_OK;
747  INT count=1;
748 #ifdef ENABLE_IARM
750  IARM_Bus_NMgr_WiFi_EventId_t eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
751 
752  LOG_TRACE("[%s] Enter", MODULE_NAME);
753 
754  memset(&eventData, 0, sizeof(eventData));
755 
756 /* if(WIFI_CONNECTING == get_WiFiStatusCode()) {
757  LOG_ERR("[%s] Connecting to AP is in Progress..., please try after 120 seconds.", MODULE_NAME);
758  return ret;
759  }*/
760 
761 // if (WIFI_CONNECTED != get_WiFiStatusCode()) {
762 
763 // we have an issue in states where disconnect state is coming after connecting state so application
764 // screens are getting messed up so to fix it we want make sure that disconnect is done before sending connecting state.
765  if (WIFI_CONNECTED == get_WiFiStatusCode())
766  {
767  wifi_disconnectEndpoint(1, wifiConnData.ssid);
768  usleep(100000);
769  while((WIFI_CONNECTED == get_WiFiStatusCode()) && count <= 30)
770  {
771  usleep(100000);
772  count++;
773  }
774  }
775 
776  set_WiFiConnectionType(WIFI_CON_WPS);
777 
778  wpsStatus = wifi_setCliWpsButtonPush(ssidIndex);
779 
780  if(RETURN_OK == wpsStatus)
781  {
782  LOG_INFO("[%s] Successfully called \"wifi_setCliWpsButtonPush(%d)\"; WPS Push button Success with status code (%d) ", MODULE_NAME, ssidIndex, wpsStatus);
783  ret = true;
784 
785  /*Generate Event for Connect State
786  eventData.data.wifiStateChange.state = WIFI_CONNECTING;
787  set_WiFiStatusCode(WIFI_CONNECTING);
788  wifi_conn_type = WPS_PUSH_CONNECT;*/
789  }
790  else
791  {
792  LOG_ERR("[%s] Failed in \"wifi_setCliWpsButtonPush(%d)\", WPS Push button press failed with status code (%d) ", MODULE_NAME, ssidIndex, wpsStatus);
793 
794  eventData.data.wifiStateChange.state = WIFI_FAILED;
795  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) eventId, (void *)&eventData, sizeof(eventData));
796  }
797 #if 0
798  else if (WIFI_CONNECTED == get_WiFiStatusCode())
799  {
800  /*If connected, do Disconnect first, the again re-connect to same or different AP.
801  * Wait for 60 Sec timeout period if fails to disconnect, then show error.
802  * If successfully disconncted, then go ahead and so call connect WpsPush. */
803  if(RETURN_OK == wifi_disconnectEndpoint(1, wifiConnData.ssid))
804  {
805  time_t start_time = time(NULL);
806  time_t timeout_period = start_time + confProp.wifiProps.max_timeout/*MAX_TIME_OUT_PERIOD */;
807 
808  LOG_INFO("[%s] Received WPS KeyCode \"%d\"; Already Connected to \"%s\" AP. \"wifi_disconnectEndpointd)\" Successfully on WPS Push. ",\
809  MODULE_NAME, ssidIndex, wifiConnData.ssid, wpsStatus);
810  /* Check for status change from Callback function */
811  while (start_time < timeout_period)
812  {
813  if(WIFI_DISCONNECTED == gWifiAdopterStatus) {
814  LOG_INFO("[%s] Successfully received Disconnect state \"%d\". ", MODULE_NAME, gWifiAdopterStatus);
815  set_WiFiConnectionType(WIFI_CON_WPS);
816  ret = (RETURN_OK == wifi_setCliWpsButtonPush(ssidIndex))?true:false;
817  eventData.data.wifiStateChange.state = (ret)? WIFI_CONNECTING: WIFI_FAILED;
818  set_WiFiStatusCode(eventData.data.wifiStateChange.state);
819  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) eventId, (void *)&eventData, sizeof(eventData));
820  LOG_ERR("[%s] Notification on 'onWIFIStateChanged' with state as \'%s\'(%d).", MODULE_NAME,
821  (ret?"CONNECTING": "FAILED"), eventData.data.wifiStateChange.state);
822  if(ret) {
823  remove(WIFI_BCK_FILENAME);
824  wifi_conn_type = WPS_PUSH_CONNECT;
825  }
826  break;
827  }
828  else {
829  LOG_ERR("[%s] Failed to Disconnect \"%s\"; wait for %d sec (i.e., loop time : %s) to update disconnect state by wifi_disconnect_callback. (%d)",
830  MODULE_NAME, wifiConnData.ssid, MAX_TIME_OUT_PERIOD, ctime(&start_time), gWifiAdopterStatus);
831  sleep(RETRY_TIME_INTERVAL);
832  start_time = time(NULL);
833  }
834  }
835  } else {
836  LOG_ERR("[%s] Received WPS KeyCode \"%d\"; Failed in \"wifi_disconnectEndpointd(%d)\", WPS Push button press failed with status code (%d)",
837  MODULE_NAME, ssidIndex, wpsStatus);
838  }
839 
840  if(false == ret)
841  {
842  LOG_INFO("[%s] Since failed to disconnect, so reconnecintg again. \"%d\". ", MODULE_NAME);
843  set_WiFiConnectionType(WIFI_CON_WPS);
844  ret = (RETURN_OK == wifi_setCliWpsButtonPush(ssidIndex))?true:false;
845  eventData.data.wifiStateChange.state = (ret)? WIFI_CONNECTING: WIFI_FAILED;
846  set_WiFiStatusCode(eventData.data.wifiStateChange.state);
847  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) eventId, (void *)&eventData, sizeof(eventData));
848  if(ret) {
849  wifi_conn_type = WPS_PUSH_CONNECT;
850  }
851  }
852  }
853 #endif
854 #endif
855 
856  LOG_TRACE("[%s] Exit", MODULE_NAME );
857  return ret;
858 }
859 
860 static bool get_WpsPIN(char *wps_pin)
861 {
862  LOG_ENTRY_EXIT;
863 
864  bool result = false;
865 #ifdef ENABLE_IARM
866  GString *mfrSerialPin = g_string_new(NULL);
867  if (getMfrData(mfrSerialPin, mfrSERIALIZED_TYPE_WPSPIN))
868  {
869  snprintf(wps_pin, 8+1, "%s", mfrSerialPin->str);
870  result = true;
871  }
872  else
873  {
874  LOG_ERR("getting serialized pin from mfr failed.");
875  }
876  g_string_free(mfrSerialPin, TRUE);
877 #endif
878  return result;
879 }
880 
881 //Connect using WPS pin
882 // if wps_pin = “xxxxxxxx" (or some other condition like "wps_pin not 8 digits")
883 // get PIN by making a call to Mfr (or some function that gets a PIN)
884 // else
885 // pass wps_pin to wifihal
886 // if wps_pin = “” (this check happens in wifihal)
887 // have wpa_supplicant auto-generate PIN
888 // else
889 // have wpa_supplicant use the passed wps_pin
890 bool connect_WpsPin(char *wps_pin)
891 {
892  LOG_ENTRY_EXIT;
893 
894  if (!wps_pin)
895  return false;
896 
897  LOG_DBG("wps_pin = %s", wps_pin);
898 
899  if (0 == strcmp(wps_pin, "xxxxxxxx") && false == get_WpsPIN(wps_pin))
900  return false;
901 
902  if (WIFI_CONNECTED == get_WiFiStatusCode())
903  {
904  wifi_disconnectEndpoint(1, wifiConnData.ssid);
905  usleep(100000);
906  for (int i = 1; i <= 30 && WIFI_CONNECTED == get_WiFiStatusCode(); i++)
907  usleep(100000);
908  }
909 
910  set_WiFiConnectionType(WIFI_CON_WPS);
911 
912  INT wpsStatus = wifi_setCliWpsEnrolleePin(1, wps_pin);
913  if (RETURN_OK == wpsStatus)
914  {
915  LOG_INFO("wifi_setCliWpsEnrolleePin called successfully");
916  return true;
917  }
918  else
919  {
920  LOG_ERR("wifi_setCliWpsEnrolleePin returned %d", wpsStatus);
921 #ifdef ENABLE_IARM
923  memset(&eventData, 0, sizeof(eventData));
924  eventData.data.wifiStateChange.state = WIFI_FAILED;
925  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME,
926  IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged,
927  (void*) &eventData, sizeof(eventData));
928 #endif
929  return false;
930  }
931 }
932 
933 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
934 void _evtHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
935 {
936  LOG_TRACE("[%s] Enter..", MODULE_NAME);
937  if (strcmp(owner, IARM_BUS_SYSMGR_NAME) == 0)
938  {
939  switch(eventId)
940  {
942  {
944  pthread_mutex_lock(&mutexAPDetails);
945  bsignalAPDetailsReady = true;
946  if(0 == pthread_cond_signal(&condAPDetails))
947  {
948  apDetailsBuffLength = eventData->data.xupnpData.deviceInfoLength;
949  LOG_INFO("[%s] Signal to fetch the data from upnp %ld", MODULE_NAME, eventData->data.xupnpData.deviceInfoLength );
950  }
951  pthread_mutex_unlock(&mutexAPDetails);
952  break;
953  }
954  }
955  LOG_TRACE("[%s] Exit...", MODULE_NAME);
956  }
957 }
958 
959 void initializeDiscovery(void)
960 {
962 }
963 
964 void shutdownDiscovery(void)
965 {
967 }
968 #endif
969 
970 INT wifi_connect_callback(INT ssidIndex, CHAR *AP_SSID, wifiStatusCode_t *connStatus)
971 {
972  int ret = RETURN_OK;
973  LOG_TRACE("[%s] Enter", MODULE_NAME);
974  wifiStatusCode_t connCode = *connStatus;
975  wifi_status_action (connCode, AP_SSID, (unsigned short) ACTION_ON_CONNECT);
976  LOG_TRACE("[%s] Exit", MODULE_NAME);
977  return ret;
978 }
979 
980 INT wifi_disconnect_callback(INT ssidIndex, CHAR *AP_SSID, wifiStatusCode_t *connStatus)
981 {
982  int ret = RETURN_OK;
983  LOG_TRACE("[%s] Enter", MODULE_NAME);
984  wifiStatusCode_t connCode = *connStatus;
985  wifi_status_action (connCode, AP_SSID, (unsigned short)ACTION_ON_DISCONNECT);
986  LOG_TRACE("[%s] Exit", MODULE_NAME);
987  return ret;
988 }
989 
990 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
991 bool parseAPDetails(char *array)
992 {
993  guint counter = 0;
994  bool retVal = TRUE;
995  LOG_TRACE("[%s] Enter..", MODULE_NAME);
996 
997  if(array)
998  {
999  cJSON *rootJson = cJSON_Parse(array);
1000  if(rootJson)
1001  {
1002  cJSON *deviceFullData = cJSON_GetObjectItem(rootJson, "xmediagateways");
1003 
1004  if(deviceFullData)
1005  {
1006  guint deviceCount = cJSON_GetArraySize(deviceFullData);
1007  LOG_INFO("gateway count in json %d", deviceCount);
1008  char *devType, *devModel, *devMake, *devMACAddr;
1009 
1010  for (counter = 0; counter < deviceCount; counter++)
1011  {
1012  cJSON *deviceData = cJSON_GetArrayItem(deviceFullData, counter);
1013  devType = devModel = devMake = devMACAddr = NULL;
1014 
1015  if(deviceData) {
1016  if(cJSON_GetObjectItem(deviceData, "DevType"))
1017  devType = cJSON_GetObjectItem(deviceData, "DevType")->valuestring;
1018 
1019  if(g_strrstr(g_strstrip(devType),"XB"))
1020  {
1021  LOG_INFO("[%s] Device type %s Device count %d", MODULE_NAME, devType, counter);
1022  if (cJSON_GetObjectItem(deviceData, "modelClass"))
1023  devModel = cJSON_GetObjectItem(deviceData, "modelClass")->valuestring;
1024  if(cJSON_GetObjectItem(deviceData, "make"))
1025  devMake = cJSON_GetObjectItem(deviceData, "make")->valuestring;
1026  if(cJSON_GetObjectItem(deviceData, "bcastMacAddress"))
1027  devMACAddr = cJSON_GetObjectItem(deviceData, "bcastMacAddress")->valuestring;
1028 
1029  if(devModel)
1030  {
1031  STRCPY_S(deviceModel, sizeof(deviceModel), devModel);
1032  }
1033 
1034  if(devMake)
1035  {
1036  STRCPY_S(deviceMake, sizeof(deviceMake), devMake);
1037  }
1038 
1039  if(devMACAddr)
1040  {
1041  STRCPY_S(deviceMACAddr, sizeof(deviceMACAddr), devMACAddr);
1042  }
1043 
1044  LOG_INFO("[%s] Device Model: %s Device Make: %s MAC Addr: %s", MODULE_NAME, deviceModel, deviceMake, deviceMACAddr);
1045  break;
1046  }
1047  else
1048  {
1049  LOG_ERR("[%s] not a valid XB device %s", MODULE_NAME, devType);
1050  }
1051  } else {
1052  LOG_ERR("[%s] Failed to get XB details", MODULE_NAME);
1053  }
1054  }
1055  }
1056  else
1057  {
1058  retVal = FALSE;
1059  LOG_INFO("[%s] No AP Details to parse gwcount", MODULE_NAME);
1060  }
1061  cJSON_Delete(rootJson);
1062  }
1063  else
1064  {
1065  retVal = FALSE;
1066  LOG_INFO("JSON is empty");
1067  }
1068  }
1069  else
1070  {
1071  LOG_ERR("[%s] Device list is empty", MODULE_NAME);
1072  retVal = FALSE;
1073  }
1074 
1075  LOG_TRACE("[%s] Exit", MODULE_NAME);
1076  return retVal;
1077 }
1078 
1079 bool getAPDetails(unsigned int msgLength)
1080 {
1082  IARM_Result_t ret = IARM_RESULT_SUCCESS;
1083  bool returnStatus = FALSE;
1084 
1085  char apDetails[msgLength + 1];
1086  memset(&apDetails, 0, sizeof(apDetails));
1087 
1088  LOG_TRACE("[%s] Enter", MODULE_NAME);
1089 
1090  ret = IARM_Malloc(IARM_MEMTYPE_PROCESSLOCAL, sizeof(IARM_Bus_SYSMGR_GetXUPNPDeviceInfo_Param_t) + msgLength + 1, (void**)&param);
1091  if(ret == IARM_RESULT_SUCCESS)
1092  {
1093  param->bufLength = msgLength;
1094 
1096  (void *)param, sizeof(IARM_Bus_SYSMGR_GetXUPNPDeviceInfo_Param_t) + msgLength + 1);
1097 
1098  if(ret == IARM_RESULT_SUCCESS)
1099  {
1100  MEMCPY_S(apDetails, msgLength + 1, ((char *)param + sizeof(IARM_Bus_SYSMGR_GetXUPNPDeviceInfo_Param_t)), param->bufLength);
1101  apDetails[param->bufLength] = '\0';
1102  returnStatus = TRUE;
1103  }
1104  else
1105  {
1106  LOG_ERR("[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo IARM failed in the fetch ", MODULE_NAME);
1107  }
1108 
1109  LOG_TRACE("[%s] apDetails %s", MODULE_NAME, apDetails);
1110  IARM_Free(IARM_MEMTYPE_PROCESSLOCAL, param);
1111 
1112  /* Parse the UPnP device information */
1113  returnStatus = parseAPDetails(apDetails);
1114  }
1115  else
1116  {
1117  LOG_ERR("[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo , IARM_Malloc Failed ", MODULE_NAME);
1118  }
1119 
1120  LOG_TRACE("[%s] Exit", MODULE_NAME);
1121  return returnStatus;
1122 }
1123 
1124 void* getAPMakeAndModel(void *arg)
1125 {
1126  bool ret = 0;
1127  int msgLength;
1128 
1129  LOG_TRACE("[%s] Enter", MODULE_NAME);
1130 
1131  while (!bShutdownWifi) {
1132  pthread_mutex_lock(&mutexAPDetails);
1133  while(bsignalAPDetailsReady == false) {
1134  pthread_cond_wait(&condAPDetails, &mutexAPDetails);
1135  }
1136 
1137  LOG_DBG("[%s] ***** Started fetching device data from upnp msg len = %d ***** ", MODULE_NAME, apDetailsBuffLength);
1138 
1139  msgLength = apDetailsBuffLength;
1140  bsignalAPDetailsReady = false;
1141  ret = getAPDetails(msgLength);
1142  pthread_mutex_unlock(&mutexAPDetails);
1143 
1144  if(ret && strlen(deviceModel) > 0 && strlen(deviceMake) > 0)
1145  {
1146  shutdownDiscovery();
1147  break;
1148  }
1149  }
1150 
1151  LOG_TRACE("[%s] Exit", MODULE_NAME);
1152  return NULL;
1153 }
1154 
1155 void collectAPDetails(void)
1156 {
1157  pthread_attr_t attr;
1158 
1159  pthread_attr_init(&attr);
1160  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1161  pthread_create(&apDetailsCollectionThread, &attr, getAPMakeAndModel, NULL);
1162 }
1163 #endif
1164 
1165 void wifi_status_action (wifiStatusCode_t connCode, char *ap_SSID, unsigned short action)
1166 {
1167  const char *connStr = (action == ACTION_ON_CONNECT)?"Connect": "Disconnect";
1168  static unsigned int switchLnf2Priv=0;
1169  static unsigned int switchPriv2Lnf=0;
1170  bool retVal = false;
1171  bool sameSSid = true;
1172  int radioIndex = 0;
1173  wifi_sta_stats_t stats;
1174 #ifdef ENABLE_IARM
1177  bool notify = false;
1178  int xreReconnectReason=0;
1179  memset(&eventData, 0, sizeof(eventData));
1180 #endif
1181 
1182  LOG_TRACE("[%s] Enter", MODULE_NAME);
1183 
1184  if ((strcmp(savedWiFiConnList.ssidSession.ssid, "") != 0) && (strcmp(savedWiFiConnList.ssidSession.ssid, ap_SSID) != 0))
1185  {
1186  sameSSid = false;
1187  }
1188  switch(connCode) {
1189  case WIFI_HAL_SUCCESS:
1190  LOG_INFO("[%s] Successfully %s to AP %s.", MODULE_NAME, connStr, ap_SSID);
1191  if (ACTION_ON_CONNECT == action) {
1192  set_WiFiStatusCode(WIFI_CONNECTED);
1193 #ifdef ENABLE_IARM
1194  notify = true;
1195 #endif
1196 #ifdef ENABLE_LOST_FOUND
1197  if (! laf_is_lnfssid(ap_SSID))
1198 #endif //ENABLE_LOST_FOUND
1199  {
1200  LOG_INFO("[%s] savedWiFiConnList.ssidSession.ssid = %s ap_SSID = %s",MODULE_NAME, savedWiFiConnList.ssidSession.ssid,ap_SSID);
1201  if (strcmp (savedWiFiConnList.ssidSession.ssid, ap_SSID) != 0)
1202  {
1204 #ifdef ENABLE_LOST_FOUND
1205  //bounce xre connection if we move from one private ssid to another ssid
1206  LOG_INFO("[%s] Moving from one SSID = %s to another SSID = %s", MODULE_NAME,savedWiFiConnList.ssidSession.ssid,ap_SSID);
1207 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
1208  xreReconnectReason=20; //RECONNECT_REASON_WIFI_NETWORK_CHANGE
1209  if(false == setHostifParam(XRE_REFRESH_SESSION_WITH_RR ,hostIf_IntegerType ,(void *)&xreReconnectReason))
1210  {
1211  LOG_ERR("refresh xre session failed .");
1212  }
1213 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 not enabled
1214 #ifdef ENABLE_NLMONITOR
1215  char const* intface=getenv("WIFI_INTERFACE");
1216  if(intface != NULL)
1217  {
1218  std::string ifcStr(intface);
1219  //cleanup Global IPv6s assigned.
1220  NetLinkIfc::get_instance()->deleteinterfaceip(ifcStr,AF_INET6);
1221  NetLinkIfc::get_instance()->deleteinterfaceroutes(ifcStr,AF_INET6);
1222  LOG_INFO("Clearing ipv6 ip and routes .");
1223  struct stat stat_buf;
1224  if (stat("/tmp/ani_wifi", &stat_buf) == 0) // if active network interface = WIFI
1225  {
1226 #ifdef YOCTO_BUILD
1227  v_secure_system("/lib/rdk/enableIpv6Autoconf.sh %s &", ifcStr.c_str());
1228 #else
1229  std::string enableV6 = "/lib/rdk/enableIpv6Autoconf.sh ";
1230  enableV6 += ifcStr; //adding interface
1231  enableV6 += " &";
1232  system(enableV6.c_str());
1233 #endif
1234  }
1235  }
1236  else
1237  LOG_ERR("No WiFi interface .");
1238 #endif
1239 #endif //ENABLE_LOST_FOUND
1240  }
1241  }
1242 #ifdef ENABLE_IARM
1243  notify = true;
1244 #if 0 /* Do not bounce for any network switch. Do it only from LF to private. */
1245  if(false == setHostifParam(XRE_REFRESH_SESSION ,hostIf_BooleanType ,(void *)&notify))
1246  {
1247  LOG_ERR("[%s] refresh xre session failed .", MODULE_NAME);
1248  }
1249 #endif
1250 #endif
1251  /* one condition variable is signaled */
1252 #ifndef ENABLE_XCAM_SUPPORT
1253  LOG_INFO("[%s] Trigger DHCP lease for new connection", MODULE_NAME);
1254  if (access("/opt/persistent/ip.wifi.0", F_OK ) != 0)
1255  {
1256 #if !defined(XHB1) && !defined(XHC3)
1257  if (!sameSSid)
1258  {
1259  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:wifi_addr_reset.sh");
1260 #ifdef YOCTO_BUILD
1261  v_secure_system("/bin/sh /lib/rdk/wifi_addr_reset.sh");
1262 #else
1263  system("/bin/sh /lib/rdk/wifi_addr_reset.sh");
1264 #endif
1265  }
1266  else
1267 #endif
1268  {
1269  LOG_INFO( "TELEMETRY_WIFI_CONNECTION_STATUS:triggerDhcpReleaseAndRenew");
1270  netSrvMgrUtiles::triggerDhcpReleaseAndRenew(getenv("WIFI_INTERFACE"));
1271  }
1272  }
1273 #endif
1274 #ifdef ENABLE_LOST_FOUND
1275  memset(&wifiConnData, '\0', sizeof(wifiConnData));
1276  strncpy(wifiConnData.ssid, ap_SSID, sizeof(wifiConnData.ssid));
1277  wifiConnData.ssid[SSID_SIZE-1] = '\0';
1278  if (! laf_is_lnfssid(ap_SSID))
1279  {
1280  logMilestone("PWIFI_CONNECTED");
1281  isLAFCurrConnectedssid=false;
1282  gWifiLNFStatus=CONNECTED_PRIVATE;
1283  if(bStopLNFWhileDisconnected)
1284  {
1285  LOG_INFO("Enable LNF");
1286  bStopLNFWhileDisconnected=false;
1287  }
1288  retVal = lastConnectedSSID(&savedWiFiConnList);
1289  if(!retVal)
1290  LOG_ERR("[%s] Last connected ssid fetch failure ", MODULE_NAME);
1291 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
1292  if(!switchPriv2Lnf)
1293  switchPriv2Lnf=1;
1294  if(switchLnf2Priv)
1295  {
1296  LOG_INFO("[%s] Connecting private ssid. Bouncing xre connection.", MODULE_NAME);
1297  xreReconnectReason = 21; // RECONNECT_REASON_WIFI_NETWORK_CHANGE_LNF_TO_PRIVATE
1298  if(false == setHostifParam(XRE_REFRESH_SESSION_WITH_RR ,hostIf_IntegerType ,(void *)&xreReconnectReason))
1299  {
1300  LOG_ERR("refresh xre session failed .");
1301  }
1302  switchLnf2Priv=0;
1303  }
1304  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:CONNECTED,%s", ap_SSID);
1305  memset(&stats, 0, sizeof(wifi_sta_stats_t));
1306  wifi_getStats(radioIndex, &stats);
1307 
1308  if(!sameSSid)
1309  {
1310  memset(&deviceModel, 0, sizeof(deviceModel));
1311  memset(&deviceMake, 0, sizeof(deviceMake));
1312  memset(&deviceMACAddr, 0, sizeof(deviceMACAddr));
1313  collectAPDetails();
1314  initializeDiscovery();
1315  }
1316 
1317  if(!strlen(deviceModel) && !strlen(deviceMake))
1318  {
1319  LOG_INFO("TELEMETRY_WIFI_STATS:%s,%s,%d,%d,%d,%d,%d,%s", stats.sta_SSID, stats.sta_BSSID, (int)stats.sta_PhyRate, (int)stats.sta_Noise, (int)stats.sta_RSSI, (int)stats.sta_LastDataDownlinkRate, (int)stats.sta_LastDataUplinkRate, stats.sta_BAND);
1320  }
1321  else
1322  {
1323  LOG_INFO("TELEMETRY_WIFI_STATS:%s,%s,%d,%d,%d,%d,%d,%s,%s,%s,%s", stats.sta_SSID, stats.sta_BSSID, (int)stats.sta_PhyRate, (int)stats.sta_Noise, (int)stats.sta_RSSI, (int)stats.sta_LastDataDownlinkRate, (int)stats.sta_LastDataUplinkRate, stats.sta_BAND, deviceMake, deviceModel, deviceMACAddr);
1324  }
1325 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 not enabled
1326  }
1327  else {
1328  LOG_TRACE("[%s] This is a LNF SSID so no storing", MODULE_NAME);
1329  isLAFCurrConnectedssid=true;
1330 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
1331  if(!switchLnf2Priv)
1332  switchLnf2Priv=1;
1333  if(switchPriv2Lnf)
1334  {
1335  switchPriv2Lnf=0;
1336  }
1337 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 not enabled
1338  setLNFState(CONNECTED_LNF);
1339  }
1340 
1341 #endif // ENABLE_LOST_FOUND
1342  /*Write into file*/
1343 // WiFiConnectionStatus wifiParams;
1344 
1345  /*Generate Event for Connect State*/
1346 #ifdef ENABLE_IARM
1347  eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1348  eventData.data.wifiStateChange.state = WIFI_CONNECTED;
1349  LOG_DBG("[%s] Notification on 'onWIFIStateChanged' with state as \'CONNECTED\'(%d).", MODULE_NAME, WIFI_CONNECTED);
1350 #endif
1351  while(bShutdownWifi!=true){
1352  LOG_INFO("[%s] attempting Mutex try Lock ", MODULE_NAME );
1353  if(0== pthread_mutex_trylock(&mutexGo)){
1354  if(0 == pthread_cond_signal(&condGo)) {
1355  LOG_INFO("[%s] Broadcast to monitor.", MODULE_NAME );
1356  }
1357  pthread_mutex_unlock(&mutexGo);
1358  break;
1359  }
1360  else{
1361  sleep(1);/*wait for another thread to release lock also check bShutdownWifi*/
1362  }
1363  }
1364  } else if (ACTION_ON_DISCONNECT == action) {
1365  set_WiFiStatusCode(WIFI_DISCONNECTED);
1366  memset(&wifiConnData, '\0', sizeof(wifiConnData));
1367  strncpy(wifiConnData.ssid, ap_SSID, sizeof(wifiConnData.ssid));
1368  wifiConnData.ssid[SSID_SIZE-1] = '\0';
1369 #ifdef ENABLE_IARM
1370  notify = true;
1371  /*Generate Event for Disconnect State*/
1372  eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1373  eventData.data.wifiStateChange.state = WIFI_DISCONNECTED;
1374  LOG_DBG("[%s] Notification on 'onWIFIStateChanged' with state as \'DISCONNECTED\'(%d).", MODULE_NAME, WIFI_DISCONNECTED);
1375 #endif
1376  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_DISCONNECTED");
1377  }
1378  break;
1379  case WIFI_HAL_CONNECTING:
1380  LOG_INFO("[%s] Connecting to AP in Progress...", MODULE_NAME);
1381  set_WiFiStatusCode(WIFI_CONNECTING);
1382 #ifdef ENABLE_IARM
1383  notify = true;
1384  eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1385  eventData.data.wifiStateChange.state = WIFI_CONNECTING;
1386  LOG_DBG("[%s] Notification on 'onWIFIStateChanged' with state as \'CONNECTING\'(%d).", MODULE_NAME, WIFI_CONNECTING);
1387 #endif
1388  break;
1389 
1391  if(connCode_prev_state != connCode) {
1392 #ifdef ENABLE_IARM
1393  notify = true;
1394  LOG_INFO("[%s] Disconnecting from AP in Progress...", MODULE_NAME);
1395 #endif
1396  }
1397  break;
1399  if(connCode_prev_state != connCode) {
1400 #ifdef ENABLE_IARM
1401  notify = true;
1402  LOG_ERR("[%s] Failed in %s with wifiStatusCode %d (i.e., AP not found). ", MODULE_NAME, connStr, connCode);
1403  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1404  eventData.data.wifiError.code = WIFI_NO_SSID;
1405  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'NO_SSID\'(%d), CurrentState set as %d (DISCONNECTED)", \
1406  MODULE_NAME,eventId, eventData.data.wifiError.code, WIFI_DISCONNECTED);
1407 #endif
1408  set_WiFiStatusCode(WIFI_DISCONNECTED);
1409 #ifdef ENABLE_LOST_FOUND
1410  /* Event Id & Code */
1411  if(confProp.wifiProps.bEnableLostFound)
1412  {
1413  bPrivConnectionLost=true;
1414  lnfConnectPrivCredentials();
1415  }
1416 #endif // ENABLE_LOST_FOUND
1417  }
1418  break;
1419 
1421  LOG_ERR("[%s] Failed in %s with wifiStatusCode %d (i.e., Timeout expired). ", MODULE_NAME, connStr, connCode);
1422  /* Event Id & Code */
1423  if(connCode_prev_state != connCode) {
1424 #ifdef ENABLE_IARM
1425  notify = true;
1426  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1427  eventData.data.wifiError.code = WIFI_UNKNOWN;
1428  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'FAILED\'(%d).", \
1429  MODULE_NAME,eventId, eventData.data.wifiError.code);
1430 #endif
1431  set_WiFiStatusCode(WIFI_DISCONNECTED);
1432  }
1433  break;
1434 
1436  if(connCode_prev_state != connCode) {
1437 #ifdef ENABLE_IARM
1438  notify = true;
1439  LOG_ERR("[%s] Failed in %s with wifiStatusCode %d (i.e., Fail in Device/AP Disconnect).", MODULE_NAME, connStr, connCode);
1440  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1441  eventData.data.wifiError.code = WIFI_CONNECTION_LOST;
1442  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'CONNECTION_LOST\'(%d).", \
1443  MODULE_NAME, eventId, eventData.data.wifiError.code);
1444 #endif
1445  set_WiFiStatusCode(WIFI_DISCONNECTED);
1446  }
1447  break;
1448  /* the SSID of the network changed */
1450  if(connCode_prev_state != connCode) {
1451  LOG_ERR("[%s] Failed due to SSID Change (%d) . ", MODULE_NAME, connCode);
1452 #ifdef USE_TELEMETRY_2_0
1453  telemetry_event_d("WIFIV_ERR_HAL_SSIDChngd", 1);
1454 #endif // #ifdef USE_TELEMETRY_2_0
1455 
1456  set_WiFiStatusCode(WIFI_DISCONNECTED);
1457 #ifdef ENABLE_LOST_FOUND
1458  if(confProp.wifiProps.bEnableLostFound)
1459  {
1460  bPrivConnectionLost=true;
1461  lnfConnectPrivCredentials();
1462  }
1463 #endif //ENABLE_LOST_FOUND
1464 #ifdef ENABLE_IARM
1465  notify = true;
1466  eventId = IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged;
1467  LOG_INFO("[%s] Notification on 'onSSIDsChanged (%d)'.", MODULE_NAME, eventId);
1468 
1469  //Two events need to be generated in this switch case, hence calling WiFi_IARM_Bus_BroadcastEvent() for IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged here itself
1470  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME,(IARM_EventId_t) eventId,(void *)&eventData,sizeof(eventData));
1471  LOG_INFO("[%s] Broadcast Event id \'%d\'.", MODULE_NAME, eventId);
1472 
1473  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1474  eventData.data.wifiError.code = WIFI_SSID_CHANGED;
1475  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'SSID_CHANGED\'(%d).", \
1476  MODULE_NAME, eventId, eventData.data.wifiError.code);
1477 #endif
1478  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_SSID_CHANGED");
1479  }
1480  break;
1481  /* the connection to the network was lost */
1483  if(connCode_prev_state != connCode) {
1484  LOG_ERR("[%s] Failed due to CONNECTION LOST (%d) from %s.", MODULE_NAME, connCode, ap_SSID);
1485  set_WiFiStatusCode(WIFI_DISCONNECTED);
1486 #ifdef ENABLE_IARM
1487  notify = true;
1488  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1489  eventData.data.wifiError.code = WIFI_CONNECTION_LOST;
1490  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'CONNECTION_LOST\'(%d).", \
1491  MODULE_NAME,eventId, eventData.data.wifiError.code);
1492 #endif
1493  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_CONNECTION_LOST");
1494  }
1495  break;
1496  /* the connection failed for an unknown reason */
1498  if(connCode_prev_state != connCode)
1499  {
1500  LOG_ERR("[%s] Connection Failed (%d) due to unknown reason.. ", MODULE_NAME, connCode );
1501  set_WiFiStatusCode(WIFI_DISCONNECTED);
1502 #ifdef ENABLE_IARM
1503  notify = true;
1504  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1505  eventData.data.wifiError.code = WIFI_CONNECTION_FAILED;
1506  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'CONNECTION_FAILED\'(%d).", \
1507  MODULE_NAME,eventId, eventData.data.wifiError.code);
1508 #endif
1509  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_CONNECTION_FAILED");
1510  }
1511  break;
1512  /* the connection was interrupted */
1514  if(connCode_prev_state != connCode) {
1515  LOG_ERR("[%s] Failed due to Connection Interrupted (%d).", MODULE_NAME, connCode );
1516  set_WiFiStatusCode(WIFI_DISCONNECTED);
1517 #ifdef ENABLE_IARM
1518  notify = true;
1519  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1520  eventData.data.wifiError.code = WIFI_CONNECTION_INTERRUPTED;
1521  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'CONNECTION_INTERRUPTED\'(%d).", \
1522  MODULE_NAME,eventId, eventData.data.wifiError.code);
1523 #endif
1524  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_CONNECTION_INTERRUPTED");
1525  }
1526  break;
1527  /* the connection failed due to invalid credentials */
1529  LOG_ERR("[%s] Failed due to Invalid Credentials. (%d). ", MODULE_NAME, connCode );
1530  set_WiFiStatusCode(WIFI_DISCONNECTED);
1531 #ifdef ENABLE_LOST_FOUND
1532  if(confProp.wifiProps.bEnableLostFound)
1533  {
1534  bPrivConnectionLost=true;
1535  lnfConnectPrivCredentials();
1536  }
1537 #endif //ENABLE_LOST_FOUND
1538 #ifdef ENABLE_IARM
1539  notify = true;
1540  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1541  eventData.data.wifiError.code = WIFI_INVALID_CREDENTIALS;
1542  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'INVALID_CREDENTIALS\'(%d)", \
1543  MODULE_NAME,eventId, eventData.data.wifiError.code);
1544 #endif
1545  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_INVALID_CREDENTIALS");
1546  break;
1547  /* the connection failed due to authentication failure */
1549  LOG_ERR("[%s] Failed due to Auth Failure (%d)", MODULE_NAME, connCode);
1550  set_WiFiStatusCode (WIFI_DISCONNECTED);
1551 #ifdef ENABLE_LOST_FOUND
1552  if (confProp.wifiProps.bEnableLostFound)
1553  {
1554  bPrivConnectionLost = true;
1555  lnfConnectPrivCredentials ();
1556  }
1557 #endif
1558 #ifdef ENABLE_IARM
1559  notify = true;
1560  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1561  eventData.data.wifiError.code = WIFI_AUTH_FAILED;
1562  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'AUTH_FAILED\'(%d).",
1563  MODULE_NAME, eventId, eventData.data.wifiError.code);
1564 #endif
1565  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_AUTH_FAILED");
1566  break;
1568  if(connCode_prev_state != connCode) {
1569  LOG_ERR("[%s] Failed due to UNRECOVERABLE ERROR. (%d).", MODULE_NAME, connCode );
1570  set_WiFiStatusCode(WIFI_FAILED);
1571 #ifdef ENABLE_IARM
1572  notify = true;
1573  eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1574  eventData.data.wifiStateChange.state = WIFI_FAILED;
1575  LOG_ERR("[%s] Notification on 'onWIFIStateChanged (%d)' with state as \'FAILED\'(%d).", \
1576  MODULE_NAME, eventId, eventData.data.wifiStateChange.state);
1577 #endif
1578  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_UNRECOVERABLE_ERROR");
1579  }
1580  break;
1582  default:
1583  if(connCode_prev_state != connCode) {
1584  LOG_ERR("[%s] Failed in %s with WiFi Error Code %d (i.e., WIFI_HAL_ERROR_UNKNOWN).", MODULE_NAME, connStr, connCode );
1585 #ifdef ENABLE_IARM
1586  notify = true;
1587  /* Event Id & Code */
1588  eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1589  eventData.data.wifiError.code = WIFI_UNKNOWN;
1590  LOG_ERR("[%s] Notification on 'onError (%d)' with state as \'UNKNOWN\'(%d).", \
1591  MODULE_NAME, eventId, eventData.data.wifiError.code);
1592 #endif
1593  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_UNKNOWN");
1594  }
1595  break;
1596  }
1597 
1598  connCode_prev_state = connCode;
1599 #ifdef ENABLE_IARM
1600  if(notify && ((eventId >= IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged) && (eventId < IARM_BUS_WIFI_MGR_EVENT_MAX)))
1601  {
1602  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME,
1603  (IARM_EventId_t) eventId,
1604  (void *)&eventData, sizeof(eventData));
1605  LOG_INFO("[%s] Broadcast Event id \'%d\'. ", MODULE_NAME, eventId);
1606  }
1607 #endif
1608  LOG_TRACE("[%s] Exit", MODULE_NAME );
1609 }
1610 
1611 /*Connect using SSID Selection */
1612 bool connect_withSSID(int ssidIndex, char *ap_SSID, SsidSecurity ap_security_mode, CHAR *ap_security_WEPKey, CHAR *ap_security_PreSharedKey, CHAR *ap_security_KeyPassphrase,int saveSSID,CHAR * eapIdentity,CHAR * carootcert,CHAR * clientcert,CHAR * privatekey,int conType)
1613 {
1614  int ret = true;
1615  wifiSecurityMode_t securityMode;
1616 #ifdef ENABLE_IARM
1618  IARM_Bus_NMgr_WiFi_EventId_t eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1619 #endif
1620 
1621  LOG_TRACE("[%s] Enter", MODULE_NAME);
1622  set_WiFiConnectionType((WiFiConnectionTypeCode_t)conType);
1623  securityMode=(wifiSecurityMode_t)ap_security_mode;
1624  LOG_INFO("[%s] ssidIndex %d; ap_SSID : %s; ap_security_mode : %d; saveSSID = %d",
1625  MODULE_NAME, ssidIndex, ap_SSID, (int)ap_security_mode, saveSSID );
1626  if(saveSSID)
1627  {
1628  set_WiFiStatusCode(WIFI_CONNECTING);
1629 #ifdef ENABLE_IARM
1630  eventData.data.wifiStateChange.state = WIFI_CONNECTING;
1631  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) eventId, (void *)&eventData, sizeof(eventData));
1632 #endif
1633  }
1634  LOG_DBG("[%s] connecting to ssid %s with passphrase %s ",
1635  MODULE_NAME, ap_SSID, ap_security_KeyPassphrase);
1636  ret=wifi_connectEndpoint(ssidIndex, ap_SSID, securityMode, ap_security_WEPKey, ap_security_PreSharedKey, ap_security_KeyPassphrase, saveSSID,eapIdentity,carootcert,clientcert,privatekey);
1637  if(ret)
1638  {
1639  LOG_ERR("[%s] Error in connecting to ssid %s",
1640  MODULE_NAME, ap_SSID);
1641 #ifdef ENABLE_IARM
1642  eventData.data.wifiStateChange.state = WIFI_FAILED;
1643  WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) eventId, (void *)&eventData, sizeof(eventData));
1644 #endif
1645  ret = false;
1646  }
1647  else
1648  {
1649  ret = true;
1650  }
1651  LOG_TRACE("[%s] Exit", MODULE_NAME );
1652  return ret;
1653 }
1654 
1655 bool scan_SpecificSSID_WifiAP(char *buffer, const char* SSID, double freq_in)
1656 {
1657  LOG_TRACE("[%s] Enter..", MODULE_NAME);
1658 #ifndef ENABLE_XCAM_SUPPORT
1659  wifi_neighbor_ap_t *ssid_ap_array = NULL;
1660  UINT ssid_ap_array_size = 0;
1661  WIFI_HAL_FREQ_BAND band = WIFI_HAL_FREQ_BAN_NONE;
1662  if(freq_in == 2.4)
1663  band = WIFI_HAL_FREQ_BAND_24GHZ;
1664  else if(freq_in == 5)
1665  band = WIFI_HAL_FREQ_BAND_5GHZ;
1666  else if (freq_in == 0 )
1667  band = WIFI_HAL_FREQ_BAN_NONE;
1668  else
1669  return false;
1670 
1671  bool ret = wifi_getSpecificSSIDInfo (SSID, band, &ssid_ap_array, &ssid_ap_array_size);
1672 
1673  LOG_INFO("[%s] wifi_get wifi_getSpecificSSIDInfo returned %d, neighbor_ap_array_size %d",
1674  MODULE_NAME, ret, ssid_ap_array_size);
1675 
1676  if ((RETURN_OK != ret ) && ((NULL == ssid_ap_array) || (0 == ssid_ap_array_size)))
1677  return false;
1678 
1679  cJSON *rootObj = cJSON_CreateObject();
1680  if (NULL == rootObj) {
1681  LOG_ERR("[%s] \'Failed to create root json object.", MODULE_NAME);
1682  return false;
1683  }
1684 
1685  cJSON *array_obj = NULL, *array_element = NULL;
1686  char *ssid = NULL;
1687  int signalStrength = 0;
1688  double frequency = 0;
1689  SsidSecurity encrptType = NET_WIFI_SECURITY_NONE;
1690 
1691  cJSON_AddItemToObject(rootObj, "getAvailableSSIDsWithName", array_obj=cJSON_CreateArray());
1692 
1693  LOG_DBG( "\n*********** Start: SSID Scan List **************** \n");
1694  for (int index = 0; index < ssid_ap_array_size; index++ )
1695  {
1696  ssid = ssid_ap_array[index].ap_SSID;
1697  if (*ssid && (0 != strcmp (ssid, LNF_NON_SECURE_SSID)) && (0 != strcmp (ssid, LNF_SECURE_SSID)))
1698  {
1699  signalStrength = ssid_ap_array[index].ap_SignalStrength;
1700  frequency = strtod(ssid_ap_array[index].ap_OperatingFrequencyBand, NULL);
1701 
1702  LOG_DBG( "[%s] [%d] => SSID: %s | SignalStrength: %d | Frequency: %f | EncryptionMode: %s",
1703  MODULE_NAME, index, ssid, signalStrength, frequency, ssid_ap_array[index].ap_EncryptionMode );
1704 
1705  if(0 == strcmp(wifiHALVer,WIFI_HAL_VERSION))
1706  {
1707  /* The type of encryption the neighboring WiFi SSID advertises.*/
1708  encrptType = get_wifiSecurityModeFromString((char *)ssid_ap_array[index].ap_EncryptionMode,NULL);
1709  }
1710  else
1711  {
1712  encrptType = get_wifiSecurityModeFromString((char *)ssid_ap_array[index].ap_SecurityModeEnabled,(char *)ssid_ap_array[index].ap_EncryptionMode);
1713  }
1714  cJSON_AddItemToArray(array_obj,array_element=cJSON_CreateObject());
1715  cJSON_AddStringToObject(array_element, "ssid", ssid);
1716  cJSON_AddNumberToObject(array_element, "security", encrptType);
1717  cJSON_AddNumberToObject(array_element, "signalStrength", signalStrength);
1718  cJSON_AddNumberToObject(array_element, "frequency", frequency);
1719  }
1720  }
1721  LOG_DBG( "\n***********End: SSID Scan List **************** \n\n");
1722 
1723  bool result = false;
1724  cJSON *ret_json = NULL;
1725  char *out = cJSON_PrintUnformatted(rootObj);
1726  if(out)
1727  {
1728  /* Parse and check the SSID Scan List is valid JSON */
1729  if (NULL == (ret_json = cJSON_Parse (out)))
1730  {
1731  LOG_ERR("scan_SpecificSSID_WifiAP query returned non-JSON value after cJSON_parse = [%s]. Error = [%s]",out, cJSON_GetErrorPtr());
1732  result = false;
1733  }
1734  else
1735  {
1736  strncpy(buffer, out, strlen(out)+1);
1737  LOG_DBG("[%s] Out = %s", MODULE_NAME,out);
1738  LOG_DBG("[%s] Buffer = %s", MODULE_NAME,buffer);
1739  result = true;
1740  cJSON_Delete(ret_json);
1741  }
1742  free(out);
1743  }
1744  else
1745  {
1746  LOG_ERR("scan_SpecificSSID_WifiAP query return SSID List is NULL");
1747  result = false;
1748  }
1749 
1750  if(rootObj) cJSON_Delete(rootObj);
1751 
1752  if(ssid_ap_array)
1753  {
1754  LOG_DBG("[%s] malloc allocated = %d ", MODULE_NAME, malloc_usable_size(ssid_ap_array));
1755  free(ssid_ap_array);
1756  }
1757  LOG_TRACE("[%s] Exit", MODULE_NAME);
1758  return result;
1759 #else // ENABLE_XCAM_SUPPORT
1760  LOG_TRACE("[%s] Exit", MODULE_NAME);
1761  return false;
1762 #endif // ENABLE_XCAM_SUPPORT
1763 }
1764 
1765 bool scan_Neighboring_WifiAP(char *buffer)
1766 {
1767  LOG_TRACE("[%s] Enter..", MODULE_NAME);
1768 #ifdef ENABLE_LOST_FOUND
1769 
1770  if((isWifiConnected()) && (isLAFCurrConnectedssid == true) && (RETURN_OK != wifi_disconnectEndpoint(1, wifiConnData.ssid)))
1771  {
1772  LOG_ERR("Failed to Disconnect in wifi_disconnectEndpoint()");
1773  }
1774 #endif //ENABLE_LOST_FOUND
1775  wifi_neighbor_ap_t *neighbor_ap_array = NULL;
1776  UINT neighbor_ap_array_size = 0;
1777  bool ret = wifi_getNeighboringWiFiDiagnosticResult (0, &neighbor_ap_array, &neighbor_ap_array_size);
1778 
1779  LOG_INFO("[%s] wifi_getNeighboringWiFiDiagnosticResult returned %d, neighbor_ap_array_size %d",
1780  MODULE_NAME, ret, neighbor_ap_array_size);
1781 
1782  if ((RETURN_OK != ret ) && ((NULL == neighbor_ap_array) || (0 == neighbor_ap_array_size)))
1783  return false;
1784 
1785  cJSON *rootObj = cJSON_CreateObject();
1786  if (NULL == rootObj) {
1787  LOG_ERR("[%s] \'Failed to create root json object.", MODULE_NAME);
1788  return false;
1789  }
1790 
1791  cJSON *array_obj = NULL, *array_element = NULL;
1792  char *ssid = NULL;
1793  int signalStrength = 0;
1794  double frequency = 0;
1795  SsidSecurity encrptType = NET_WIFI_SECURITY_NONE;
1796 
1797  cJSON_AddItemToObject(rootObj, "getAvailableSSIDs", array_obj=cJSON_CreateArray());
1798 
1799  LOG_DBG( "\n*********** Start: SSID Scan List **************** \n");
1800  for (int index = 0; index < neighbor_ap_array_size; index++ )
1801  {
1802  ssid = neighbor_ap_array[index].ap_SSID;
1803  if (*ssid && (0 != strcmp (ssid, LNF_NON_SECURE_SSID)) && (0 != strcmp (ssid, LNF_SECURE_SSID)))
1804  {
1805  signalStrength = neighbor_ap_array[index].ap_SignalStrength;
1806  frequency = strtod(neighbor_ap_array[index].ap_OperatingFrequencyBand, NULL);
1807 
1808  LOG_DBG("[%s] [%d] => SSID: %s | SignalStrength: %d | Frequency: %f | EncryptionMode: %s",
1809  MODULE_NAME, index, ssid, signalStrength, frequency, neighbor_ap_array[index].ap_EncryptionMode );
1810 
1811  if(0 == strcmp(wifiHALVer,WIFI_HAL_VERSION))
1812  {
1813  /* The type of encryption the neighboring WiFi SSID advertises.*/
1814  encrptType = get_wifiSecurityModeFromString((char *)neighbor_ap_array[index].ap_EncryptionMode,NULL);
1815  }
1816  else
1817  {
1818  encrptType = get_wifiSecurityModeFromString((char *)neighbor_ap_array[index].ap_SecurityModeEnabled,(char *)neighbor_ap_array[index].ap_EncryptionMode);
1819  }
1820  cJSON_AddItemToArray(array_obj,array_element=cJSON_CreateObject());
1821  cJSON_AddStringToObject(array_element, "ssid", ssid);
1822  cJSON_AddNumberToObject(array_element, "security", encrptType);
1823  cJSON_AddNumberToObject(array_element, "signalStrength", signalStrength);
1824  cJSON_AddNumberToObject(array_element, "frequency", frequency);
1825  }
1826  }
1827  LOG_DBG( "\n***********End: SSID Scan List **************** \n\n");
1828 
1829  bool result = false;
1830  cJSON *ret_json = NULL;
1831  char *out = cJSON_PrintUnformatted(rootObj);
1832 
1833  if(out)
1834  {
1835  /* Parse and check the SSID Scan List is valid JSON */
1836  if (NULL == (ret_json = cJSON_Parse (out)))
1837  {
1838  LOG_ERR("scan_Neighboring_WifiAP query returned non-JSON value after cJSON_parse = [%s]. Error = [%s]",out, cJSON_GetErrorPtr());
1839  result = false;
1840  }
1841  else
1842  {
1843  strncpy(buffer, out, strlen(out)+1);
1844  LOG_DBG("[%s] Out = %s", MODULE_NAME,out);
1845  LOG_DBG("[%s] Buffer = %s", MODULE_NAME,buffer);
1846  result = true;
1847  cJSON_Delete(ret_json);
1848  }
1849  free(out);
1850  }
1851  else
1852  {
1853  LOG_ERR("scan_Neighboring_WifiAP query return SSID List is NULL");
1854  result = false;
1855  }
1856 
1857  if(rootObj) {
1858  cJSON_Delete(rootObj);
1859  }
1860 
1861  if(neighbor_ap_array) {
1862  LOG_DBG( "[%s] malloc allocated = %d ", MODULE_NAME, malloc_usable_size(neighbor_ap_array));
1863  free(neighbor_ap_array);
1864  }
1865  LOG_TRACE("[%s] Exit", MODULE_NAME );
1866  return result;
1867 }
1868 
1869 bool lastConnectedSSID(WiFiConnectionStatus *ConnParams)
1870 {
1871  LOG_TRACE("[%s] Enter", MODULE_NAME);
1872 
1873  bool ret = false;
1874  wifi_pairedSSIDInfo_t pairedSSIDInfo = {0};
1875  if (RETURN_OK != wifi_lastConnected_Endpoint (&pairedSSIDInfo))
1876  {
1877  LOG_ERR("[%s] Error in getting last connected SSID ", MODULE_NAME);
1878  }
1879  else
1880  {
1881  snprintf (ConnParams->ssidSession.ssid, sizeof(ConnParams->ssidSession.ssid), "%s", pairedSSIDInfo.ap_ssid);
1882  snprintf (ConnParams->ssidSession.passphrase, sizeof(ConnParams->ssidSession.passphrase), "%s", pairedSSIDInfo.ap_passphrase);
1883  snprintf (ConnParams->ssidSession.bssid, sizeof(ConnParams->ssidSession.bssid), "%s", pairedSSIDInfo.ap_bssid);
1884  snprintf (ConnParams->ssidSession.security, sizeof(ConnParams->ssidSession.security), "%s", pairedSSIDInfo.ap_security);
1885  snprintf (ConnParams->ssidSession.security_WEPKey, sizeof(ConnParams->ssidSession.security_WEPKey), "%s", pairedSSIDInfo.ap_wep_key);
1886  if ((strstr (ConnParams->ssidSession.security, SECURITY_MODE_WPA_PSK) != NULL ) ||
1887  (strstr (ConnParams->ssidSession.security, SECURITY_MODE_SAE) != NULL ))
1888  {
1889  LOG_TRACE("[%s] SECURITY_MODE_SAE", MODULE_NAME);
1890  ConnParams->ssidSession.security_mode=NET_WIFI_SECURITY_WPA3_SAE;//Same security_mode for both wpa2 and wpa3
1891  }
1892  else if (strcmp (ConnParams->ssidSession.security, SECURITY_MODE_WPA_EAP) == 0)
1893  {
1894  LOG_TRACE("[%s] SECURITY_MODE_WPA_EAP", MODULE_NAME);
1895  ConnParams->ssidSession.security_mode=NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES;
1896  }
1897  else if (ConnParams->ssidSession.security_WEPKey != NULL)
1898  {
1899  LOG_TRACE("[%s] security_WEPKey is %s", MODULE_NAME, ConnParams->ssidSession.security_WEPKey );
1900  if ( strlen(ConnParams->ssidSession.security_WEPKey) == 26 || strlen(ConnParams->ssidSession.security_WEPKey) == 13 ){
1901  ConnParams->ssidSession.security_mode = NET_WIFI_SECURITY_WEP_128;
1902  }
1903  else{
1904  ConnParams->ssidSession.security_mode = NET_WIFI_SECURITY_WEP_64;
1905  }
1906  }
1907  else
1908  {
1909  LOG_TRACE("[%s] SECURITY_MODE_WPA_NONE", MODULE_NAME);
1910  ConnParams->ssidSession.security_mode=NET_WIFI_SECURITY_NONE;
1911  }
1912  LOG_TRACE("[%s] last connected ssid is %s passphrase is %s bssid is %s security is %s security_mode is %d",
1913  MODULE_NAME, ConnParams->ssidSession.ssid, ConnParams->ssidSession.passphrase,
1914  ConnParams->ssidSession.bssid, ConnParams->ssidSession.security,ConnParams->ssidSession.security_mode);
1915  ret = true;
1916  }
1917  LOG_TRACE("[%s] Exit", MODULE_NAME);
1918  return ret;
1919 }
1920 #endif
1921 
1923 {
1924  bool isCapable = false;
1925  unsigned long numRadioEntries = 0;
1926 #ifdef USE_RDK_WIFI_HAL
1927  wifi_getRadioNumberOfEntries(&numRadioEntries);
1928  /* Default set to 1 for Xi5, it will change for other devices.*/
1929  numRadioEntries = 1;
1930 #endif
1931 
1932  if(numRadioEntries) {
1933  set_WiFiStatusCode(WIFI_DISCONNECTED);
1934  isCapable = true;
1935  }
1936  return isCapable;
1937 }
1938 
1939 #ifdef USE_RDK_WIFI_HAL
1940 
1941 unsigned int getWifiStatsLogInterval()
1942 {
1943  unsigned int wifi_stats_log_interval = 300;
1944 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
1945  const char *parameter_name = "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Feature.WiFi.WiFiStatsLogInterval";
1946  RFC_ParamData_t parameter = { 0 };
1947  if (WDMP_SUCCESS == getRFCParameter("netsrvmgr", parameter_name, &parameter))
1948  {
1949  LOG_INFO("getRFCParameter(%s) returned %s", parameter_name, parameter.value);
1950  long parameter_value = strtol(parameter.value, NULL, 10);
1951  if (parameter_value >= 120 && parameter_value <= 3600)
1952  wifi_stats_log_interval = parameter_value;
1953  }
1954  else
1955  LOG_ERR("getRFCParameter(%s) failed", parameter_name);
1956 #endif
1957  LOG_INFO("Returning %u", wifi_stats_log_interval);
1958  return wifi_stats_log_interval;
1959 }
1960 
1961 void *wifiConnStatusThread(void* arg)
1962 {
1963  LOG_ENTRY_EXIT;
1964 
1965  int ret = 0;
1966  wifi_sta_stats_t stats;
1967  WiFiStatusCode_t wifiStatusCode;
1968  char wifiStatusAsString[MAX_WIFI_STATUS_STRING];
1969  int radioIndex = 0;
1970  struct timespec condGoTimeout;
1971 
1972  pthread_mutex_lock(&mutexGo);
1973  pthread_cond_wait(&condGo, &mutexGo);
1974  pthread_mutex_unlock(&mutexGo);
1975 
1976  LOG_DBG("[%s] ***** Monitor activated by signal ***** ", MODULE_NAME);
1977  const int WIFI_STATS_LOG_INTERVAL = getWifiStatsLogInterval();
1978 
1979  while (!bShutdownWifi) {
1980  wifiStatusCode = get_WiFiStatusCode();
1981 
1982  if (get_WiFiStatusCodeAsString (wifiStatusCode, wifiStatusAsString)) {
1983  LOG_INFO("TELEMETRY_WIFI_CONNECTION_STATUS:%s", wifiStatusAsString);
1984  }
1985  else {
1986  LOG_ERR("TELEMETRY_WIFI_CONNECTION_STATUS:Unmappable WiFi status code %d", wifiStatusCode);
1987  }
1988 
1989  if (WIFI_CONNECTED == wifiStatusCode) {
1990  //LOG_INFO( "\n *****Start Monitoring ***** \n");
1991 #if !defined (XHB1) && !defined (XHC3)
1992  memset(&stats, 0, sizeof(wifi_sta_stats_t));
1993  wifi_getStats(radioIndex, &stats);
1994 
1995 #if !defined(ENABLE_XCAM_SUPPORT)
1996  if((strlen(deviceModel) > 0) && (strlen(deviceMake) > 0))
1997  {
1998  LOG_INFO("TELEMETRY_WIFI_STATS:%s,%s,%d,%d,%d,%d,%d,%s,%s,%s,%s", stats.sta_SSID, stats.sta_BSSID, (int)stats.sta_PhyRate, (int)stats.sta_Noise, (int)stats.sta_RSSI, (int)stats.sta_LastDataDownlinkRate, (int)stats.sta_LastDataUplinkRate, stats.sta_BAND, deviceMake, deviceModel, deviceMACAddr);
1999  }
2000  else
2001 #endif
2002  {
2003  LOG_INFO("TELEMETRY_WIFI_STATS:%s,%s,%d,%d,%d,%d,%d,%s", stats.sta_SSID, stats.sta_BSSID, (int)stats.sta_PhyRate, (int)stats.sta_Noise, (int)stats.sta_RSSI, (int)stats.sta_LastDataDownlinkRate, (int)stats.sta_LastDataUplinkRate, stats.sta_BAND);
2004  }
2005 #endif
2006  //LOG_INFO( "\n *****End Monitoring ***** \n");
2007 
2008  /*Telemetry Parameter logging*/
2009  logs_Period1_Params();
2010  logs_Period2_Params();
2011  }
2012 
2013  pthread_mutex_lock(&mutexGo);
2014  clock_gettime(CLOCK_REALTIME, &condGoTimeout);
2015  condGoTimeout.tv_sec += WIFI_STATS_LOG_INTERVAL;
2016  ret = 0;
2017  while (!bShutdownWifi && ret != ETIMEDOUT) {
2018  ret = pthread_cond_timedwait(&condGo, &mutexGo, &condGoTimeout);
2019  }
2020  pthread_mutex_unlock(&mutexGo);
2021  }
2022 
2023  return NULL;
2024 }
2025 
2026 void monitor_WiFiStatus()
2027 {
2028  bShutdownWifi = false;
2029  pthread_attr_t attr;
2030  pthread_attr_init(&attr);
2031  pthread_create(&wifiStatusMonitorThread, &attr, wifiConnStatusThread, NULL);
2032 }
2033 
2034 
2035 bool clearSSID_On_Disconnect_AP()
2036 {
2037  bool ret = true;
2038  int radioIndex = 1;
2039  char *ap_ssid = savedWiFiConnList.ssidSession.ssid;
2040  if(RETURN_OK != wifi_disconnectEndpoint(1, ap_ssid))
2041  {
2042  LOG_ERR("[%s] Failed to Disconnect in wifi_disconnectEndpoint() for AP : \"%s\".",\
2043  MODULE_NAME, ap_ssid);
2044  ret = false;
2045  }
2046  else
2047  {
2048  LOG_INFO("[%s] Successfully called \"wifi_disconnectEndpointd()\" for AP: \'%s\'. ",\
2049  MODULE_NAME, ap_ssid);
2050 #ifndef ENABLE_XCAM_SUPPORT
2051  // Clear wpa_supplicant SSID info
2052  if(wifi_clearSSIDInfo(radioIndex) == RETURN_OK) {
2053  LOG_INFO("[%s] Successfully cleared SSID info", MODULE_NAME);
2054  }
2055 #endif // ENABLE_XCAM_SUPPORT
2056 
2057 
2058 #ifdef ENABLE_LOST_FOUND
2059  if ( false == isLAFCurrConnectedssid )
2060 #endif //ENABLE_LOST_FOUND
2061  {
2062  memset(&savedWiFiConnList, 0 ,sizeof(savedWiFiConnList));
2064  }
2065  }
2066  return ret;
2067 }
2068 
2069 bool disconnectFromCurrentSSID()
2070 {
2071  bool ret = true;
2072  int radioIndex = 1;
2073  char *ap_ssid = savedWiFiConnList.ssidSession.ssid;
2074 
2075  if(RETURN_OK != wifi_disconnectEndpoint(radioIndex, ap_ssid))
2076  {
2077  LOG_ERR("[%s] Failed to Disconnect in wifi_disconnectEndpoint() for AP : \"%s\".",\
2078  MODULE_NAME, ap_ssid);
2079  ret = false;
2080  }
2081  else
2082  {
2083  LOG_INFO("[%s] Successfully called \"wifi_disconnectEndpointd()\" for AP: \'%s\'. ",\
2084  MODULE_NAME, ap_ssid);
2085  }
2086  return ret;
2087 }
2088 
2089 bool cancelWPSPairingOperation()
2090 {
2091  bool ret = true;
2092 #if !defined (ENABLE_XCAM_SUPPORT) && !defined (XHB1) && !defined(XHC3)
2093  if(wifi_cancelWpsPairing() == RETURN_OK)
2094  {
2095  LOG_INFO("[%s] Successfully Cancelled WPS operation.", MODULE_NAME);
2096  }
2097  else
2098  {
2099  LOG_ERR("[%s] Failed to Cancel WPS operation, Looks like no in-progress wps operation.", MODULE_NAME);
2100  ret = false;
2101  }
2102 #endif //ENABLE_LOST_FOUND
2103  return ret;
2104 }
2105 
2107 {
2108  int radioIndex = 0;
2109  wifi_sta_stats_t stats;
2110 
2111  LOG_TRACE("[%s] Enter", MODULE_NAME);
2112 
2113  memset(&stats, '\0', sizeof(stats));
2114 
2115  wifi_getStats(radioIndex, &stats);
2116  strncpy((char *)conSSIDInfo->ssid, (const char *)stats.sta_SSID, (size_t)SSID_SIZE);
2117  strncpy((char *)conSSIDInfo->bssid, (const char *)stats.sta_BSSID, (size_t)BSSID_BUFF);
2118  conSSIDInfo->rate = stats.sta_PhyRate;
2119  conSSIDInfo->noise = stats.sta_Noise;
2120  conSSIDInfo->signalStrength = stats.sta_RSSI;
2121  conSSIDInfo->frequency = stats.sta_Frequency;
2122  strncpy((char *)conSSIDInfo->band,(const char *)stats.sta_BAND,(size_t)BUFF_MIN);
2123  conSSIDInfo->securityMode = get_wifiSecurityModeFromString(stats.sta_SecMode, stats.sta_Encryption);
2124 
2125  LOG_DBG("[%s] Connected SSID info: \n \
2126  [SSID: \"%s\"| BSSID : \"%s\" | PhyRate : \"%f\" | Noise : \"%f\" | SignalStrength(rssi) : \"%f\" | Frequency : \"%d\" Security Mode : \"%d\"] \n",
2127  MODULE_NAME, stats.sta_SSID, stats.sta_BSSID, stats.sta_PhyRate, stats.sta_Noise, stats.sta_RSSI,conSSIDInfo->frequency,conSSIDInfo->securityMode);
2128 
2129  LOG_TRACE("[%s] Exit", MODULE_NAME );
2130 }
2131 
2132 #endif
2133 
2134 #ifdef ENABLE_LOST_FOUND
2135 
2136 void doLnFBackoff()
2137 {
2138  if (last_laf_status.backoff > 0.0f)
2139  {
2140  struct timespec current_time;
2141  clock_gettime (CLOCK_MONOTONIC, &current_time);
2142 
2143  float seconds_elapsed_after_last_lnf_server_contact =
2144  (current_time.tv_sec - last_lnf_server_contact_time.tv_sec)
2145  + (((float) ((current_time.tv_nsec - last_lnf_server_contact_time.tv_nsec))) / 1000000000);
2146 
2147  float seconds_remaining_to_wait = last_laf_status.backoff - seconds_elapsed_after_last_lnf_server_contact;
2148  if (seconds_remaining_to_wait <= 0)
2149  seconds_remaining_to_wait = 0;
2150 
2151  LOG_INFO( "[%s] last requested backoff = %fs, elapsed after last lnf server contact = %fs, waiting for remaining %fs",
2152  MODULE_NAME, last_laf_status.backoff, seconds_elapsed_after_last_lnf_server_contact, seconds_remaining_to_wait);
2153 
2154  usleep (seconds_remaining_to_wait * 1000000); // wait out the remainder of the requested backoff period
2155  }
2156  else
2157  {
2158  LOG_INFO("[%s] backoff = 0s", MODULE_NAME);
2159  }
2160 
2161  LOG_INFO("[%s] backoff wait done.", MODULE_NAME);
2162 }
2163 
2164 bool triggerLostFound(LAF_REQUEST_TYPE lafRequestType)
2165 {
2166  laf_conf_t* conf = NULL;
2167  laf_client_t* clnt = NULL;
2168  laf_ops_t *ops = NULL;
2169  laf_device_info_t *dev_info = NULL;
2170  char currTime[BUFF_LENGTH_32];
2171  static bool bLastLnfSuccess=false;
2172  int err;
2173  bool bRet=true;
2174 
2175  LOG_TRACE("[%s] Enter", MODULE_NAME);
2176 #ifdef ENABLE_IARM
2178 #endif
2179  ops = (laf_ops_t*) malloc(sizeof(laf_ops_t));
2180  if(!ops)
2181  {
2182  LOG_ERR("[%s] laf_ops malloc failed ", MODULE_NAME);
2183  return ENOMEM;
2184  }
2185  dev_info = (laf_device_info_t*) malloc(sizeof(laf_device_info_t));
2186  if(!dev_info)
2187  {
2188  LOG_ERR("[%s] laf_device_info malloc failed ", MODULE_NAME);
2189  free(ops);
2190  return ENOMEM;
2191  }
2192 
2193  memset(dev_info,0,sizeof(laf_device_info_t));
2194  memset(ops,0,sizeof(laf_ops_t));
2195  /* set operation parameters */
2196  ops->laf_log_message = log_message;
2197  ops->laf_wifi_connect = laf_wifi_connect;
2198  ops->laf_wifi_disconnect = laf_wifi_disconnect;
2199  ops->laf_get_lfat = laf_get_lfat;
2200  ops->laf_set_lfat = laf_set_lfat;
2201 
2202  bRet = getDeviceInfo(dev_info);
2203  if (bRet == false) {
2204  LOG_ERR("[%s] getDeviceInfo failed", MODULE_NAME);
2205  }
2206  /* configure laf */
2207  err = laf_config_new(&conf, ops, dev_info);
2208  if(err != 0) {
2209  LOG_ERR("[%s] Lost and found client configurtion failed with error code %d ", MODULE_NAME, err );
2210  bRet=false;
2211  }
2212  else
2213  {
2214  /* initialize laf client */
2215  err = laf_client_new(&clnt, conf);
2216  if(err != 0) {
2217  LOG_ERR("[%s] Lost and found client initialization failed with error code %d", MODULE_NAME, err );
2218  bRet=false;
2219  }
2220  else
2221  {
2222  /* start laf */
2223  clnt->req_type = lafRequestType;
2224  clnt->conf.device.backoff = last_laf_status.backoff;
2225  err = laf_start(clnt, &last_laf_status);
2226  if (err != LAF_NO_RESPONSE_FROM_LNF)
2227  {
2228  LOG_INFO("[%s] lnf server requested backoff = %fs",
2229  MODULE_NAME, last_laf_status.backoff);
2230  clock_gettime(CLOCK_MONOTONIC, &last_lnf_server_contact_time);
2231  }
2232 
2233  if(err != 0) {
2234  LOG_ERR("[%s] Error in lost and found client, error code %d", MODULE_NAME, err );
2235  bRet=false;
2236  }
2237  if(!bAutoSwitchToPrivateEnabled)
2238  {
2239  if((!bRet) && (bLastLnfSuccess))
2240  {
2241  LOG_INFO("[%s] !AutoSwitchToPrivateEnabled + lastLnfSuccessful + currLnfFailure = clr switch2prv Results ", MODULE_NAME);
2242  clearSwitchToPrivateResults();
2243  bLastLnfSuccess=false;
2244  }
2245  if(bRet)
2246  bLastLnfSuccess=true;
2247  netSrvMgrUtiles::getCurrentTime(currTime,(char *)TIME_FORMAT);
2248  if (addSwitchToPrivateResults(err,currTime) != 0) {
2249  LOG_INFO( "[%s] Added Time=%s lnf error=%d to list,length of list = %d", MODULE_NAME,currTime,err,g_list_length(lstLnfPvtResults));
2250  }
2251  }
2252  }
2253  }
2254  free(dev_info);
2255  free(ops);
2256  /* destroy config */
2257  if(conf)
2258  laf_config_destroy(conf);
2259  /* destroy lost and found client */
2260  if(clnt)
2261  laf_client_destroy(clnt);
2262 
2263  LOG_TRACE("[%s] Exit", MODULE_NAME );
2264  return bRet;
2265 }
2266 bool getmacaddress(gchar* ifname,GString *data)
2267 {
2268  int fd;
2269  int ioRet;
2270  struct ifreq ifr;
2271  unsigned char *mac;
2272  LOG_TRACE("[%s] Enter", MODULE_NAME);
2273  fd = socket(AF_INET, SOCK_DGRAM, 0);
2274  if (fd < 0)
2275  {
2276  LOG_ERR("[%s] ERROR opening socket %d ", MODULE_NAME,fd );
2277  return false;
2278  }
2279  ifr.ifr_addr.sa_family = AF_INET;
2280  strncpy(ifr.ifr_name , ifname , IFNAMSIZ-1);
2281  ioRet=ioctl(fd, SIOCGIFHWADDR, &ifr);
2282  if (ioRet < 0)
2283  {
2284  close(fd);
2285  LOG_ERR("[%s] ERROR in ioctl function to retrieve mac address %d", MODULE_NAME, fd );
2286  return false;
2287  }
2288  close(fd);
2289  mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
2290  g_string_printf(data,"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
2291  LOG_TRACE("[%s] Exit", MODULE_NAME );
2292  return true;
2293 }
2294 
2295 #ifdef ENABLE_IARM
2296 bool getDeviceInfo(laf_device_info_t *dev_info)
2297 {
2298  bool bRet = true;
2299  GString* mfrSerialNum = g_string_new(NULL);
2300  GString* mfrMake = g_string_new(NULL);
2301  GString* mfrModelName = g_string_new(NULL);
2302  GString* deviceMacAddr = g_string_new(NULL);
2303  mfrSerializedType_t mfrType;
2304 
2305  mfrType = mfrSERIALIZED_TYPE_SERIALNUMBER;
2306  if(partnerID && !partnerID[0])
2307  {
2308  if(getDeviceActivationState() == false)
2309  {
2310  LOG_ERR("[%s] Partner ID Missing in url May be not activated ", MODULE_NAME);
2311  }
2312  else
2313  {
2314  g_stpcpy(dev_info->partnerId,partnerID);
2315  }
2316  }
2317  else
2318  {
2319  g_stpcpy(dev_info->partnerId,partnerID);
2320  }
2321  if(getMfrData(mfrSerialNum,mfrType))
2322  {
2323  LOG_TRACE("[%s] mfrSerialNum = %s mfrType = %d", MODULE_NAME,mfrSerialNum->str,mfrType );
2324  STRCPY_S(dev_info->serial_num, sizeof(dev_info->serial_num), mfrSerialNum->str);
2325  }
2326  else
2327  {
2328  LOG_ERR("[%s] getting serial num from mfr failed ", MODULE_NAME);
2329  bRet = false;
2330  goto out;
2331  }
2332  mfrType = mfrSERIALIZED_TYPE_DEVICEMAC;
2333  if(getMfrData(deviceMacAddr,mfrType))
2334  {
2335  LOG_TRACE("[%s] deviceMacAddr = %s mfrType = %d ", MODULE_NAME, deviceMacAddr->str,mfrType);
2336  STRCPY_S(dev_info->mac, sizeof(dev_info->mac), deviceMacAddr->str);
2337 
2338  }
2339  else
2340  {
2341  LOG_ERR("[%s] getting device mac addr from mfr failed ", MODULE_NAME);
2342  bRet = false;
2343  goto out;
2344  }
2345  mfrType = mfrSERIALIZED_TYPE_MODELNAME;
2346  if(getMfrData(mfrModelName,mfrType))
2347  {
2348  LOG_TRACE("[%s] mfrModelName = %s mfrType = %d ", MODULE_NAME, mfrModelName->str,mfrType );
2349  STRCPY_S(dev_info->model, sizeof(dev_info->model), mfrModelName->str);
2350  }
2351  else
2352  {
2353  LOG_ERR("[%s] getting model name from mfr failed ", MODULE_NAME);
2354  bRet = false;
2355  goto out;
2356  }
2357 
2358  LOG_TRACE("[%s] dummy auth token update ", MODULE_NAME);
2359  memset(dev_info->auth_token, 0, MAX_AUTH_TOKEN_LEN+1);
2360  STRCPY_S(dev_info->auth_token, sizeof(dev_info->auth_token), "xact_token");
2361 
2362 out:
2363  g_string_free(mfrSerialNum,TRUE);
2364  g_string_free(mfrMake,TRUE);
2365  g_string_free(mfrModelName,TRUE);
2366  g_string_free(deviceMacAddr,TRUE);
2367 
2368  return bRet;
2369 }
2370 
2371 #else // ENABLE_IARM
2372 
2373 #if defined (ENABLE_XCAM_SUPPORT) || defined (XHB1) || defined(XHC3)
2374 char* getlfatfilename()
2375 {
2376  static char *lfat_file = NULL;
2377  lfat_file = getenv("LFAT_TOKEN_FILE");
2378  LOG_INFO("lfat file name=%s", lfat_file);
2379  return lfat_file;
2380 }
2381 
2382 int get_token_length(unsigned int &tokenlength)
2383 {
2384  LOG_ENTRY_EXIT;
2385  FILE* fp_token;
2386  int tokensize;
2387  char* tokenfilename = getlfatfilename();
2388  fp_token = fopen(tokenfilename,"rb");
2389  if(NULL == fp_token) {
2390  LOG_ERR("get_token_length - Error in opening lfat token file");
2391  return EBADF;
2392  }else{
2393  fseek(fp_token, 0L, SEEK_END);
2394  tokensize = ftell(fp_token);
2395  fseek(fp_token, 0, SEEK_SET);
2396  tokenlength = tokensize;
2397  LOG_DBG("get_token_length - token size is - %d",tokenlength);
2398  if(NULL != fp_token){
2399  fclose(fp_token);
2400  fp_token = NULL;
2401  }
2402  }
2403  return 0;
2404 }
2405 
2406 int get_laf_token(char* token,unsigned int tokenlength)
2407 {
2408  LOG_ENTRY_EXIT;
2409  char* tokenfilename = getlfatfilename();
2410  FILE* fp_token;
2411  fp_token = fopen(tokenfilename,"rb");
2412  if(NULL == fp_token) {
2413  LOG_ERR("get_laf_token - Error in opening lfat token file");
2414  return EBADF;
2415  }else{
2416  if(NULL != token)
2417  {
2418  fread(token,tokenlength,1,fp_token);
2419  }else {
2420  LOG_ERR("get_laf_token - Token NULL");
2421  }
2422  if(NULL != fp_token){
2423  fclose(fp_token);
2424  fp_token = NULL;
2425  }
2426  }
2427  return 0;
2428 }
2429 #endif // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
2430 
2431 #if defined(XHB1) || defined(XHC3)
2432 int getMfrDeviceInfo(mfrSerializedType_t stdatatype, char* data)
2433 {
2434  mfrSerializedData_t stdata = {NULL, 0, NULL};
2435 
2436  if(NULL == data)
2437  {
2438  LOG_ERR("[%s] Accessing ivalid memory locatio", MODULE_NAME);
2439  return 1;
2440  }
2441 
2442  if(mfrGetSerializedData(stdatatype, &stdata) == mfrERR_NONE)
2443  {
2444  strncpy(data,stdata.buf,stdata.bufLen);
2445  if (stdata.freeBuf != NULL)
2446  {
2447  stdata.freeBuf(stdata.buf);
2448  stdata.buf = NULL;
2449  }
2450  }
2451  else
2452  {
2453  LOG_ERR("[%s] Error retriving required device info.", MODULE_NAME);
2454  return 1;
2455  }
2456  return 0;
2457 }
2458 #endif
2459 
2460 bool getDeviceInfo( laf_device_info_t *dev_info )
2461 {
2462  bool ret = false;
2463  unsigned int tokenlength=0;
2464  int readtoken=0;
2465  char* partnerIdFile = "/opt/usr_config/partnerid.txt";
2466 #ifdef ENABLE_XCAM_SUPPORT
2467  struct basic_info xcam_dev_info;
2468  memset((void*)&xcam_dev_info, 0, sizeof(struct basic_info));
2469  if (!rdkc_get_device_basic_info(&xcam_dev_info))
2470  {
2471  strncpy(dev_info->serial_num, xcam_dev_info.serial_number, MAX_DEV_SERIAL_LEN-1);
2472  strncpy(dev_info->mac, xcam_dev_info.mac_addr, MAX_DEV_MAC_LEN);
2473  strncpy(dev_info->model, xcam_dev_info.model, MAX_DEV_MODEL_LEN);
2474  LOG_INFO("[%s] serial_no=%s", MODULE_NAME, dev_info->serial_num);
2475  }
2476  else
2477  {
2478  LOG_ERR("[%s] rdkc_get_device_basic_info failed", MODULE_NAME);
2479  return ret;
2480  }
2481 #elif defined(XHB1) || defined(XHC3)
2482  if(1 == getMfrDeviceInfo(mfrSERIALIZED_TYPE_SERIALNUMBER, dev_info->serial_num))
2483  {
2484  LOG_ERR("[%s] Error reteiving device serial number.", MODULE_NAME);
2485  }
2486  if(1 == getMfrDeviceInfo(mfrSERIALIZED_TYPE_MODELNAME, dev_info->model))
2487  {
2488  LOG_ERR("[%s] Error reteiving device model", MODULE_NAME);
2489  }
2490 
2491  if(1 == getMfrDeviceInfo(mfrSERIALIZED_TYPE_DEVICEMAC, dev_info->mac))
2492  {
2493  LOG_ERR("[%s] Error reteiving device MAC.", MODULE_NAME);
2494  }
2495 #endif
2496 #if defined(ENABLE_XCAM_SUPPORT) || defined(XHB1) || defined(XHC3)
2497  int get_result = getSetFileContent(partnerIdFile, "get", dev_info->partnerId);
2498  if (get_result)
2499  LOG_ERR("[%s] Error reteiving partnerId", MODULE_NAME);
2500  else
2501  {
2502  dev_info->partnerId[strcspn(dev_info->partnerId, "\n")] = 0;
2503  LOG_DBG("[%s] PartnerID obtained is : %s", MODULE_NAME, dev_info->partnerId);
2504  }
2505  LOG_TRACE( "[%s] auth token update for xcam", MODULE_NAME);
2506  memset(dev_info->auth_token, 0, MAX_AUTH_TOKEN_LEN+1);
2507  readtoken = get_token_length(tokenlength);
2508  if(readtoken != 0) {
2509  LOG_DBG("getDeviceInfo - Error in token read ");
2510  return false;
2511  }
2512  readtoken = get_laf_token(dev_info->auth_token,tokenlength);
2513  if(readtoken != 0 ) {
2514  LOG_ERR("[%s] getDeviceInfo - Token read error", MODULE_NAME);
2515  return false;
2516  }
2517  LOG_DBG("[%s] getDeviceInfo - token is : %s", MODULE_NAME, dev_info->auth_token);
2518  ret = true;
2519 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 defined
2520  return ret;
2521 }
2522 
2523 #endif // ENABLE_IARM
2524 
2525 /* Callback function to connect to wifi */
2526 int laf_wifi_connect(laf_wifi_ssid_t* const wificred)
2527 {
2528  /* call api to connect to wifi */
2529  int retry = 0;
2530  bool retVal=false;
2531  int ssidIndex=1;
2532  // bool notify = false;
2533 
2534  LOG_TRACE("[%s] Enter", MODULE_NAME);
2535  if (laf_is_lnfssid(wificred->ssid) && (true == isLAFCurrConnectedssid) && (WIFI_CONNECTED == get_WifiRadioStatus()))
2536  {
2537  LOG_INFO("[%s] Already connected to LF ssid Ignoring the request", MODULE_NAME);
2538  return 0;
2539  }
2540  if(bStopLNFWhileDisconnected)
2541  {
2542  LOG_INFO("[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2543  return EPERM;
2544  }
2545  if (laf_is_lnfssid(wificred->ssid))
2546  {
2547  bLNFConnect=true;
2548  }
2549  else
2550  {
2551  bLNFConnect=false;
2552  retVal=lastConnectedSSID(&savedWiFiConnList);
2553  if (retVal && savedWiFiConnList.ssidSession.ssid[0] != '\0')
2554  {
2555  if((strcmp(wificred->ssid, savedWiFiConnList.ssidSession.ssid) != 0) && (strcmp(wificred->passphrase, savedWiFiConnList.ssidSession.passphrase) != 0))
2556  {
2557  LOG_INFO("[%s] Lnf response status Credentials changed : BOTH", MODULE_NAME);
2558  }
2559  else if(strcmp(wificred->ssid, savedWiFiConnList.ssidSession.ssid) != 0)
2560  {
2561  LOG_INFO("[%s] Lnf response status Credentials changed : SSID", MODULE_NAME);
2562  }
2563  else if(strcmp(wificred->passphrase, savedWiFiConnList.ssidSession.passphrase) != 0)
2564  {
2565  LOG_INFO("[%s] Lnf response status Credentials changed : KeyPassphrase", MODULE_NAME);
2566  }
2567  }
2568  }
2569 #ifdef USE_RDK_WIFI_HAL
2570  if(gWifiLNFStatus != CONNECTED_PRIVATE)
2571  {
2572  setLNFState(LNF_IN_PROGRESS);
2573  if((bLNFConnect == true) && (RETURN_OK != wifi_disconnectEndpoint(1, wifiConnData.ssid)))
2574  {
2575  LOG_ERR("Failed to Disconnect in wifi_disconnectEndpoint()");
2576  }
2577  retVal=connect_withSSID(ssidIndex, wificred->ssid, (SsidSecurity)wificred->security_mode, NULL, wificred->psk, wificred->passphrase, (int)(!bLNFConnect),wificred->identity,wificred->carootcert,wificred->clientcert,wificred->privatekey,bLNFConnect ? WIFI_CON_LNF : WIFI_CON_PRIVATE);
2578  }
2579  // retVal=connect_withSSID(ssidIndex, wificred->ssid, NET_WIFI_SECURITY_NONE, NULL, NULL, wificred->psk);
2580 // }
2581 #endif
2582  if(false == retVal)
2583  {
2584  LOG_ERR("[%s] connect with ssid %s failed ", MODULE_NAME, wificred->ssid);
2585  LOG_DBG("[%s] connect with ssid %s failed (passphrase %s)", MODULE_NAME, wificred->ssid, wificred->passphrase );
2586  return EPERM;
2587  }
2588  while(get_WifiRadioStatus() != WIFI_CONNECTED && retry <= confProp.wifiProps.lnfRetryCount) {
2589  retry++; //max wait for 180 seconds
2590  if(bStopLNFWhileDisconnected)
2591  {
2592  LOG_INFO( "[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2593  return EPERM;
2594  }
2595  sleep(1);
2596  LOG_TRACE("[%s] Device not connected to wifi. waiting to connect...", MODULE_NAME);
2597  }
2598  if(retry > confProp.wifiProps.lnfRetryCount) {
2599  LOG_ERR("[%s] Waited for %d seconds. Failed to connect. Abort ", MODULE_NAME, confProp.wifiProps.lnfRetryCount);
2600  return EPERM;
2601  }
2602 
2603  /* Bounce xre session only if switching from LF to private */
2604  if(! laf_is_lnfssid(wificred->ssid))
2605  {
2606  setLNFState(CONNECTED_PRIVATE);
2607 // notify = true;
2608 // sleep(10); //waiting for default route before bouncing the xre connection
2609 // LOG_INFO( "[%s] Connecting private ssid. Bouncing xre connection.", MODULE_NAME);
2610 //#ifdef ENABLE_IARM
2611 // if(false == setHostifParam(XRE_REFRESH_SESSION ,hostIf_BooleanType ,(void *)&notify))
2612 // {
2613 // LOG_ERR("[%s] refresh xre session failed ", MODULE_NAME);
2614 // }
2615 //#endif
2616  }
2617  LOG_TRACE("[%s] Exit", MODULE_NAME );
2618  return 0;
2619 }
2620 
2621 /* Callback function to disconenct wifi */
2622 int laf_wifi_disconnect(void)
2623 {
2624  int retry = 0;
2625  bool retVal=false;
2626  int radioIndex = 1;
2627 
2628  LOG_TRACE("[%s] Enter", MODULE_NAME);
2629  if ( false == isLAFCurrConnectedssid )
2630  {
2631  LOG_INFO("[%s] Connected to private ssid Ignoring the request ", MODULE_NAME);
2632  return 0;
2633  }
2634  if(bStopLNFWhileDisconnected)
2635  {
2636  LOG_INFO("[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2637  return EPERM;
2638  }
2639 #ifdef USE_RDK_WIFI_HAL
2640  char *ap_ssid = savedWiFiConnList.ssidSession.ssid;
2641  retVal = wifi_disconnectEndpoint(radioIndex, ap_ssid);
2642 #endif
2643  setLNFState(LNF_IN_PROGRESS);
2644  if(retVal == false) {
2645  LOG_ERR("[%s] Tried to disconnect before connect and it failed ", MODULE_NAME);
2646  return EPERM;
2647  }
2648 
2649  while(get_WifiRadioStatus() != WIFI_DISCONNECTED && retry <= 30) {
2650  if(bStopLNFWhileDisconnected)
2651  {
2652  LOG_INFO("[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2653  return EPERM;
2654  }
2655  LOG_TRACE("[%s] Device is connected to wifi. waiting to disconnect...", MODULE_NAME);
2656  retry++; //max wait for 180 seconds
2657  sleep(1);
2658  }
2659  if(retry > 30) {
2660  LOG_ERR("[%s] Waited for 30seconds. Failed to disconnect. Abort", MODULE_NAME);
2661  return EPERM;
2662  }
2663 
2664  LOG_TRACE("[%s] Exit", MODULE_NAME );
2665  return 0;
2666 }
2667 
2668 /* log level to display */
2669 static rdk_LogLevel map_to_rdkloglevel(int level)
2670 {
2671  rdk_LogLevel rdklevel;
2672 
2673  switch(level)
2674  {
2675  case LAF_LOG_DEBUG:
2676  rdklevel = RDK_LOG_DEBUG;
2677  break;
2678  case LAF_LOG_INFO:
2679  rdklevel = RDK_LOG_INFO;
2680  break;
2681  case LAF_LOG_WARNING:
2682  rdklevel = RDK_LOG_WARN;
2683  break;
2684  case LAF_LOG_ERROR:
2685  rdklevel = RDK_LOG_ERROR;
2686  break;
2687  default:
2688  rdklevel = RDK_LOG_INFO;
2689  break;
2690  }
2691  return rdklevel;
2692 }
2693 /* callback function to log messages from lost and found */
2694 void log_message(laf_loglevel_t level, char const* function, int line, char const* msg)
2695 {
2696  RDK_LOG( map_to_rdkloglevel(level), LOG_NMGR, "[%s:%s:%s:%d] %s\n",MODULE_NAME,SUB_MODULE_NAME, function, line, msg );
2697 }
2698 
2699 void setLNFState(WiFiLNFStatusCode_t status)
2700 {
2701  if(gWifiLNFStatus != status)
2702  LOG_TRACE("[%s] LNF Status changed to %d", MODULE_NAME, status );
2703 
2704  gWifiLNFStatus = status;
2705 }
2706 
2707 static void signalStartLAF()
2708 {
2709  pthread_mutex_lock(&mutexLAF);
2710  startLAF = true;
2711  LOG_DBG("[%s] Signal to start LAF private SSID ", MODULE_NAME);
2712  pthread_cond_signal(&condLAF);
2713  pthread_mutex_unlock(&mutexLAF);
2714 }
2715 
2716 void *lafConnPrivThread(void* arg)
2717 {
2718  int counter=0;
2719  bool retVal;
2720  int ssidIndex=1;
2721  LAF_REQUEST_TYPE reqType;
2722  bool lnfReturnStatus=false;
2723 
2724  LOG_TRACE("[%s] Enter",MODULE_NAME);
2725 
2726  while (true) {
2727  pthread_mutex_lock(&mutexLAF);
2728  // if already connected to private wifi, suppress any start LAF signal that was previously issued
2729  if (gWifiLNFStatus == CONNECTED_PRIVATE && gWifiAdopterStatus == WIFI_CONNECTED)
2730  startLAF = false;
2731  while (false == startLAF)
2732  pthread_cond_wait(&condLAF, &mutexLAF);
2733  startLAF = false;
2734  pthread_mutex_unlock(&mutexLAF);
2735  {
2736  LOG_DBG("[%s] Starting the LAF Connect private SSID",MODULE_NAME);
2737  if(gWifiLNFStatus != CONNECTED_LNF)
2738  {
2739  LOG_INFO("[%s] WifiLNFStatus = %d .Setting LNF state as in progress.",MODULE_NAME, gWifiLNFStatus );
2740  setLNFState(LNF_IN_PROGRESS);
2741  }
2742  if(bPrivConnectionLost)
2743  {
2744  bPrivConnectionLost=false;
2745  LOG_INFO("[%s] Wait for 10 sec before starting lost and found ", MODULE_NAME );
2746  sleep(10);
2747  }
2748  do
2749  {
2750 #ifdef ENABLE_XCAM_SUPPORT
2751  if(rdkc_get_wifi_interface_status() == 3)
2752  {
2753  LOG_INFO("Camera is connected to Y-CABLE. Aborting LNF ");
2754  setLNFState(LNF_UNITIALIZED);
2755  break;
2756  }
2757 #endif
2758  if((bAutoSwitchToPrivateEnabled) || (bSwitch2Private))
2759  {
2760  if(bSwitch2Private == true)
2761  {
2762  reqType = LAF_REQUEST_SWITCH_TO_PRIVATE;
2763  bSwitch2Private=false;
2764  }
2765  else
2766  {
2767  reqType = LAF_REQUEST_CONNECT_TO_PRIV_WIFI;
2768  }
2769  }
2770  else
2771  {
2772  reqType = LAF_REQUEST_CONNECT_TO_LFSSID;
2773  setLNFState(LNF_IN_PROGRESS);
2774  }
2775  if (true == bStopLNFWhileDisconnected)
2776  {
2777  LOG_INFO("stopLNFWhileDisconnected pressed coming out of LNF");
2778  setLNFState(LNF_UNITIALIZED);
2779  break;
2780  }
2781 
2782  if((gWifiAdopterStatus == WIFI_CONNECTED) && (false == isLAFCurrConnectedssid))
2783  {
2784  LOG_INFO("connection status %d is LAF current ssid %d ", gWifiAdopterStatus, isLAFCurrConnectedssid );
2785  setLNFState(CONNECTED_PRIVATE);
2786  break;
2787  }
2788 
2789  bIsStopLNFWhileDisconnected=false;
2790  pthread_mutex_lock(&mutexTriggerLAF);
2791  doLnFBackoff();
2792  if ((gWifiLNFStatus == CONNECTED_PRIVATE) && (gWifiAdopterStatus == WIFI_CONNECTED))
2793  {
2794  LOG_INFO("[%s] Connected to Private SSID already. Aborting requested LNF.", MODULE_NAME);
2795  pthread_mutex_unlock(&mutexTriggerLAF);
2796  break;
2797  }
2798  else
2799  {
2800  if (gWifiLNFStatus == LNF_UNITIALIZED)
2801  setLNFState(LNF_IN_PROGRESS);
2802  lnfReturnStatus = triggerLostFound(reqType);
2803  }
2804  pthread_mutex_unlock(&mutexTriggerLAF);
2805  if (false == lnfReturnStatus)
2806 // else if (!triggerLostFound(LAF_REQUEST_CONNECT_TO_PRIV_WIFI) && counter < TOTAL_NO_OF_RETRY)
2807  {
2808  if (true == bStopLNFWhileDisconnected)
2809  {
2810  LOG_INFO("stopLNFWhileDisconnected pressed coming out of LNF" );
2811  setLNFState(LNF_UNITIALIZED);
2812  break;
2813  }
2814 // counter++;
2815  retVal=false;
2816  retVal=lastConnectedSSID(&savedWiFiConnList);
2817  if (retVal && savedWiFiConnList.ssidSession.ssid[0] != '\0')
2818  {
2819  LOG_INFO("[%s] Trying Manual Connect with ssid %s security %d since not able to connect through LNF",MODULE_NAME, savedWiFiConnList.ssidSession.ssid,savedWiFiConnList.ssidSession.security_mode);
2820  retVal=connect_withSSID(ssidIndex, savedWiFiConnList.ssidSession.ssid,savedWiFiConnList.ssidSession.security_mode, NULL, savedWiFiConnList.ssidSession.passphrase, savedWiFiConnList.ssidSession.passphrase,true,NULL,NULL,NULL,NULL,WIFI_CON_PRIVATE);
2821  if(false == retVal)
2822  {
2823  LOG_ERR("[%s] connect with ssid %s failed ", MODULE_NAME, savedWiFiConnList.ssidSession.ssid );
2824  }
2825  }
2826  else
2827  {
2828  LOG_ERR("[%s] Failed to get previous SSID, Manual connect failed. ", MODULE_NAME);
2829  }
2830  if (last_laf_status.backoff == 0.0f)
2831  {
2832  last_laf_status.backoff = (float)confProp.wifiProps.lnfRetryInSecs;
2833  LOG_INFO( "[%s] Added default lnf back off time %fs ",MODULE_NAME,last_laf_status.backoff );
2834  }
2835  }
2836  else
2837  {
2838  if (LAF_REQUEST_CONNECT_TO_LFSSID == reqType)
2839  {
2840  setLNFState(CONNECTED_LNF);
2841  LOG_TRACE("[%s] Connected to LNF",MODULE_NAME);
2842  }
2843  else
2844  {
2845  if (gWifiLNFStatus == CONNECTED_PRIVATE)
2846  {
2847  setLNFState(CONNECTED_PRIVATE);
2848  LOG_INFO("pressed coming out of LNF since box is connected to private ");
2849  }
2850  }
2851  break;
2852  }
2853  sleep(1);
2854  }while ((gWifiLNFStatus != CONNECTED_PRIVATE) && (bAutoSwitchToPrivateEnabled));
2855  bIsStopLNFWhileDisconnected=true;
2856  }
2857  }
2858  LOG_TRACE("[%s] Exit", MODULE_NAME );
2859 }
2860 void *lafConnThread(void* arg)
2861 {
2862  bool lnfReturnStatus=false;
2863  LOG_TRACE("[%s] Enter", MODULE_NAME);
2864  setLNFState(LNF_IN_PROGRESS);
2865  while (false == bDeviceActivated) {
2866  bLnfActivationLoop=true;
2867  while(gWifiLNFStatus != CONNECTED_LNF)
2868  {
2869  bIsStopLNFWhileDisconnected=false;
2870  if (gWifiAdopterStatus == WIFI_CONNECTED)
2871  {
2872  if (false == isLAFCurrConnectedssid)
2873  {
2874  setLNFState(CONNECTED_PRIVATE);
2875  LOG_INFO("[%s] Connected through non LAF path", MODULE_NAME);
2876  bIsStopLNFWhileDisconnected=true;
2877  bLnfActivationLoop=false;
2878  return NULL;
2879  }
2880  break;
2881  }
2882  if (true == bStopLNFWhileDisconnected)
2883  {
2884  LOG_INFO("[%s] stopLNFWhileDisconnected pressed coming out of LNF", MODULE_NAME);
2885  bIsStopLNFWhileDisconnected=true;
2886  bLnfActivationLoop=false;
2887  setLNFState(LNF_UNITIALIZED);
2888  return NULL;
2889  }
2890 #if defined(ENABLE_XCAM_SUPPORT) || defined(XHB1) || defined(XHC3)
2891  int readtoken=0;
2892  unsigned int tokenlength=0;
2893  readtoken = get_token_length(tokenlength);
2894  if(readtoken != 0) {
2895  LOG_ERR("[%s] LNF TOKEN ERROR", MODULE_NAME);
2896  setLNFState(CONNECTED_PRIVATE);
2897  break;
2898  }
2899 #endif
2900  pthread_mutex_lock(&mutexTriggerLAF);
2901  doLnFBackoff();
2902  if (gWifiLNFStatus == CONNECTED_PRIVATE)
2903  {
2904  LOG_INFO("[%s] Connected to Private SSID already. Aborting requested LNF.", MODULE_NAME);
2905  pthread_mutex_unlock(&mutexTriggerLAF);
2906  break;
2907  }
2908  else
2909  {
2910  lnfReturnStatus = triggerLostFound(LAF_REQUEST_CONNECT_TO_LFSSID);
2911  }
2912  pthread_mutex_unlock(&mutexTriggerLAF);
2913  if (false == lnfReturnStatus)
2914  {
2915 
2916  if (true == bStopLNFWhileDisconnected)
2917  {
2918  LOG_INFO("[%s] stopLNFWhileDisconnected pressed coming out of LNF ", MODULE_NAME);
2919  bIsStopLNFWhileDisconnected=true;
2920  bLnfActivationLoop=false;
2921  return NULL;
2922  }
2923  sleep(confProp.wifiProps.lnfRetryInSecs);
2924  continue;
2925  }
2926  else
2927  {
2928  setLNFState(CONNECTED_LNF);
2929  LOG_DBG("[%s] Connection to LAF success", MODULE_NAME);
2930  break;
2931  }
2932  }
2933  bIsStopLNFWhileDisconnected=false;
2934  sleep(1);
2935  if((gWifiLNFStatus != CONNECTED_PRIVATE) && (false == isLAFCurrConnectedssid) && (gWifiAdopterStatus == WIFI_CONNECTED))
2936  {
2937  LOG_INFO("[%s] isLAFCurrConnectedssid = %d gWifiAdopterStatus = %d", MODULE_NAME,isLAFCurrConnectedssid,gWifiAdopterStatus );
2938  gWifiLNFStatus=CONNECTED_PRIVATE;
2939  }
2940  if (true == bStopLNFWhileDisconnected)
2941  {
2942  LOG_INFO("[%s] stopLNFWhileDisconnected pressed coming out of LNF ", MODULE_NAME);
2943  bLnfActivationLoop=false;
2944  return NULL;
2945  }
2946 // getDeviceActivationState();
2947  }
2948  bLnfActivationLoop=false;
2949  if(gWifiLNFStatus == CONNECTED_LNF)
2950  {
2951  bPrivConnectionLost=false;
2952  lnfConnectPrivCredentials();
2953  }
2954  LOG_TRACE( "[%s] Exit",MODULE_NAME);
2955  pthread_exit(NULL);
2956 }
2957 
2958 static void* startLAFIfNecessary(void* arg)
2959 {
2960  lastConnectedSSID(&savedWiFiConnList);
2961  if (savedWiFiConnList.ssidSession.ssid[0] != '\0')
2962  {
2963  sleep(confProp.wifiProps.lnfStartInSecs);
2964  lastConnectedSSID(&savedWiFiConnList);
2965  }
2966  /* If Device is activated and already connected to Private or any network,
2967  but defineltly not LF SSID. - No need to trigger LNF*/
2968  /* Here, 'getDeviceActivationState == true'*/
2969  if((! laf_is_lnfssid(savedWiFiConnList.ssidSession.ssid)) && (WIFI_CONNECTED == get_WifiRadioStatus())) {
2970  LOG_DBG("[%s] Now connected to Private SSID %s", MODULE_NAME, savedWiFiConnList.ssidSession.ssid);
2971  }
2972  else {
2973 #ifdef ENABLE_IARM
2974  if(IARM_BUS_SYS_MODE_WAREHOUSE != sysModeParam)
2975 #endif
2976  {
2977  signalStartLAF();
2978  bPrivConnectionLost=true;
2979  }
2980  }
2981  pthread_exit(NULL);
2982 }
2983 
2984 void connectToLAF()
2985 {
2986  LOG_DBG("[%s] Enter", MODULE_NAME );
2987  pthread_attr_t attr;
2988  if((getDeviceActivationState() == false)
2989 #ifdef ENABLE_IARM
2990  && (IARM_BUS_SYS_MODE_WAREHOUSE != sysModeParam)
2991 #endif
2992 )
2993  {
2994  pthread_attr_init(&attr);
2995  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2996  pthread_create(&lafConnectThread, &attr, lafConnThread, NULL);
2997  }
2998  else
2999  {
3000 
3001 #ifdef ENABLE_XCAM_SUPPORT
3002  //check wifi status
3003  WiFiHalStatus_t wifistatus = getwifiStatusCode();
3004  if( WIFISTATUS_HAL_COMPLETED == wifistatus ) {
3005  set_WiFiStatusCode(WIFI_CONNECTED);
3006  //signal to monitor wifi status
3007  pthread_mutex_lock(&mutexGo);
3008  if(0 == pthread_cond_signal(&condGo)) {
3009  LOG_INFO("[%s] Broadcast to monitor.", MODULE_NAME);
3010  }
3011  pthread_mutex_unlock(&mutexGo);
3012  } else {
3013  set_WiFiStatusCode(WIFI_DISCONNECTED);
3014  }
3015 #elif defined(XHB1) || defined(XHC3)
3016  set_WiFiStatusCode(WIFI_CONNECTED);
3017  //signal to monitor wifi status
3018  pthread_mutex_lock(&mutexGo);
3019  if(0 == pthread_cond_signal(&condGo)) {
3020  LOG_INFO("[%s] Broadcast to monitor.", MODULE_NAME);
3021  }
3022  pthread_mutex_unlock(&mutexGo);
3023 #endif
3024  pthread_t t;
3025  pthread_attr_init(&attr);
3026  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3027  pthread_create(&t, &attr, startLAFIfNecessary, NULL);
3028  }
3029 }
3030 
3031 void lafConnectToPrivate()
3032 {
3033  pthread_attr_t attr;
3034  pthread_attr_init(&attr);
3035  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3036  pthread_create(&lafConnectToPrivateThread, &attr, lafConnPrivThread, NULL);
3037 }
3038 
3039 
3040 bool getLAFssid()
3041 {
3042  char lafSsid[SSID_SIZE];
3043  LOG_TRACE("[%s] Enter", MODULE_NAME);
3044  memset(lafSsid, 0, SSID_SIZE);
3045  laf_get_lfssid(lafSsid);
3046  if(lafSsid)
3047  {
3048  LOG_TRACE("[%s] lfssid is %s", MODULE_NAME, lafSsid);
3049  return true;
3050  }
3051  else
3052  {
3053  LOG_ERR("[%s] lfssid is empty ", MODULE_NAME);
3054  return false;
3055  }
3056 }
3057 #if 0
3058 bool isLAFCurrConnectedssid()
3059 {
3060  bool retVal=false;
3061  LOG_TRACE("[%s] Enter", MODULE_NAME);
3062  if(laf_is_lnfssid(savedWiFiConnList.ssidSession.ssid))
3063  {
3064  LOG_TRACE("[%s] LAF is the current connected ssid ", MODULE_NAME);
3065  retVal=true;
3066  }
3067  else
3068  {
3069  retVal=false;
3070  }
3071  LOG_TRACE("[%s] Exit", MODULE_NAME );
3072  return retVal;
3073 
3074 }
3075 #endif
3076 bool getDeviceActivationState()
3077 {
3078 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3079  char scriptOutput[BUFFER_SIZE_SCRIPT_OUTPUT] = {'\0'};
3080  unsigned int count=0;
3081  std::string str;
3082  LOG_TRACE("[%s] Enter", MODULE_NAME);
3083  while(deviceID && !deviceID[0])
3084  {
3085  if (access(SCRIPT_FILE_TO_GET_DEVICE_ID, F_OK ) != -1)
3086  {
3087  if (!netSrvMgrUtiles::getCommandOutput(SCRIPT_FILE_TO_GET_DEVICE_ID, scriptOutput, sizeof (scriptOutput)))
3088  {
3089  LOG_ERR("[%s] Error in running device id script.", MODULE_NAME);
3090  return bDeviceActivated;
3091  }
3092  g_stpcpy(deviceID,scriptOutput);
3093  }
3094  else
3095  {
3096  if(! confProp.wifiProps.authServerURL)
3097  {
3098  LOG_ERR("[%s] Authserver URL is NULL", MODULE_NAME);
3099  return bDeviceActivated;
3100  }
3101  str.assign(confProp.wifiProps.authServerURL,strlen(confProp.wifiProps.authServerURL));
3102  CurlObject authServiceURL(str);
3103  g_stpcpy(deviceID,authServiceURL.getCurlData());
3104  }
3105  if ((!deviceID && deviceID[0]) || (count >= 3))
3106  break;
3107  sleep(5);
3108  count++;
3109  }
3110  LOG_INFO( "[%s] device id string is %s", MODULE_NAME,deviceID);
3111  gchar **tokens = g_strsplit_set(deviceID,"{}:,\"", -1);
3112  guint tokLength = g_strv_length(tokens);
3113  guint loopvar=0;
3114  for (loopvar=0; loopvar<tokLength; loopvar++)
3115  {
3116  if (g_strrstr(g_strstrip(tokens[loopvar]), "deviceId"))
3117  {
3118  //"deviceId": "T00xxxxxxx" so omit 3 tokens ":" fromDeviceId
3119  if ((loopvar+3) < tokLength )
3120  {
3121  g_stpcpy(deviceID, g_strstrip(tokens[loopvar+3]));
3122  if(deviceID[0] != '\0')
3123  {
3124  bDeviceActivated = true;
3125  }
3126  }
3127  }
3128  }
3129  for (loopvar=0; loopvar<tokLength; loopvar++)
3130  {
3131  if (g_strrstr(g_strstrip(tokens[loopvar]), "partnerId"))
3132  {
3133  //"deviceId": "T00xxxxxxx" so omit 3 tokens ":" fromDeviceId
3134  if ((loopvar+3) < tokLength )
3135  {
3136  g_stpcpy(partnerID, g_strstrip(tokens[loopvar+3]));
3137  if(partnerID[0] != '\0')
3138  {
3139  LOG_INFO("[%s] partner id is %s", MODULE_NAME, partnerID);
3140  }
3141  }
3142  }
3143  }
3144  if(tokens)
3145  g_strfreev(tokens);
3146  LOG_TRACE("[%s] Exit", MODULE_NAME );
3147  return bDeviceActivated;
3148 #else
3149  return true;
3150 #endif // ENABLE_XCAM_SUPPORT and XHB1 and XHC3
3151 }
3152 bool isWifiConnected()
3153 {
3154  return (get_WiFiStatusCode() == WIFI_CONNECTED);
3155 }
3156 
3157 void lnfConnectPrivCredentials()
3158 {
3159  LOG_TRACE("[%s] Enter", MODULE_NAME);
3160  if(bLnfActivationLoop)
3161  {
3162  LOG_DBG( "[%s] Still in LnF Activation Loop so discarding getting private credentials",MODULE_NAME);
3163  return;
3164  }
3165  signalStartLAF();
3166  LOG_TRACE("[%s] Exit", MODULE_NAME);
3167 }
3168 #endif // ENABLE_LOST_FOUND
3169 
3170 #ifdef ENABLE_IARM
3171 bool setHostifParam (const char *name, HostIf_ParamType_t type, void *value)
3172 {
3173  IARM_Result_t ret = IARM_RESULT_IPCCORE_FAIL;
3174  bool retValue=false;
3175  LOG_TRACE("[%s] Enter", MODULE_NAME);
3176  HOSTIF_MsgData_t param = {0};
3177 
3178  if(NULL == name || value == NULL) {
3179  LOG_ERR("[%s] Null pointer caught for Name/Value", MODULE_NAME );
3180  return retValue;
3181  }
3182 
3183  /* Initialize hostIf Set structure */
3184  strncpy(param.paramName, name, strlen(name)+1);
3185  param.reqType = HOSTIF_SET;
3186 
3187  switch (type) {
3188  case hostIf_StringType:
3189  case hostIf_DateTimeType:
3190  {
3191  param.paramtype = hostIf_StringType;
3192  STRCPY_S(param.paramValue, sizeof(param.paramValue), (char *) value);
3193  break;
3194  }
3195  case hostIf_IntegerType:
3196  case hostIf_UnsignedIntType:
3197  put_int(param.paramValue, *(int*)value);
3198  param.paramtype = hostIf_IntegerType;
3199  case hostIf_BooleanType:
3200  put_boolean(param.paramValue,*(bool*)value);
3201  param.paramtype = hostIf_BooleanType;
3202  break;
3203  default:
3204  break;
3205  }
3206 
3209  (void *)&param,
3210  sizeof(param));
3211  if(ret != IARM_RESULT_SUCCESS) {
3212  LOG_ERR("[%s] Error executing Set parameter call from tr69Client, error code",MODULE_NAME);
3213  }
3214  else
3215  {
3216  LOG_DBG("[%s] sent iarm message to set hostif parameter",MODULE_NAME);
3217  retValue=true;
3218  }
3219  LOG_TRACE("[%s] Exit", MODULE_NAME );
3220  return retValue;
3221 }
3222 #endif // ENABLE_IARM
3223 
3224 void put_boolean(char *ptr, bool val)
3225 {
3226  bool *tmp = (bool *)ptr;
3227  *tmp = val;
3228 }
3229 
3230 void put_int(char *ptr, int val)
3231 {
3232  int *tmp = (int *)ptr;
3233  *tmp = val;
3234 }
3235 
3236 #ifdef ENABLE_IARM
3237 bool connectToMfrWifiCredentials()
3238 {
3239  int ssidIndex=1;
3240  bool retVal=false;
3242 
3243  LOG_TRACE("[%s] Enter", MODULE_NAME);
3244  param.requestType=WIFI_GET_CREDENTIALS;
3245  if(IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_MFRLIB_NAME,IARM_BUS_MFRLIB_API_WIFI_Credentials,(void *)&param,sizeof(param)))
3246  {
3247  if (param.wifiCredentials.iSecurityMode == -1){
3248  LOG_INFO("[%s] IARM success in retrieving the stored wifi credentials having no security mode ",MODULE_NAME);
3249  retVal = connect_withSSID(ssidIndex, param.wifiCredentials.cSSID, NET_WIFI_SECURITY_WPA_PSK_AES, NULL, param.wifiCredentials.cPassword, param.wifiCredentials.cPassword, true, NULL, NULL, NULL, NULL, WIFI_CON_PRIVATE);
3250  }
3251  else{
3252  LOG_INFO("[%s] IARM success in retrieving the stored wifi credentials having the security mode %d",MODULE_NAME,param.wifiCredentials.iSecurityMode );
3253  retVal = connect_withSSID(ssidIndex, param.wifiCredentials.cSSID, (SsidSecurity)param.wifiCredentials.iSecurityMode, NULL, param.wifiCredentials.cPassword, param.wifiCredentials.cPassword, true, NULL, NULL, NULL, NULL, WIFI_CON_PRIVATE);
3254  }
3255  }
3256  else
3257  {
3258  LOG_INFO("[%s] IARM failure in retrieving the stored wifi credentials", MODULE_NAME);
3259  }
3260  return retVal;
3261 }
3262 #endif
3263 
3265 {
3266  bool retVal=false;
3267 #ifdef USE_RDK_WIFI_HAL
3268 #ifdef ENABLE_IARM
3270  LOG_TRACE("[%s] Enter", MODULE_NAME);
3271  retVal=lastConnectedSSID(&savedWiFiConnList);
3272  if(retVal == false)
3273  {
3274  LOG_ERR("[%s] Last connected ssid fetch failure", MODULE_NAME);
3275  return retVal;
3276  }
3277  else
3278  {
3279  retVal=false;
3280  LOG_TRACE("[%s] fetched ssid details %s ",MODULE_NAME,savedWiFiConnList.ssidSession.ssid);
3281  }
3282  param.requestType=WIFI_GET_CREDENTIALS;
3283  if(IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_MFRLIB_NAME,IARM_BUS_MFRLIB_API_WIFI_Credentials,(void *)&param,sizeof(param)))
3284  {
3285  LOG_TRACE("[%s] IARM success in retrieving the stored wifi credentials ",MODULE_NAME);
3286  if ((strcmp (param.wifiCredentials.cSSID, savedWiFiConnList.ssidSession.ssid) == 0) &&
3287  (strcmp (param.wifiCredentials.cPassword, savedWiFiConnList.ssidSession.passphrase) == 0) &&
3288  (param.wifiCredentials.iSecurityMode == savedWiFiConnList.ssidSession.security_mode || param.wifiCredentials.iSecurityMode == -1) )
3289  {
3290  LOG_INFO("[%s] Same ssid info not storing it stored ssid %s new ssid %s",
3291  MODULE_NAME, param.wifiCredentials.cSSID, savedWiFiConnList.ssidSession.ssid);
3292  return true;
3293  }
3294  else
3295  {
3296  LOG_INFO("[%s] ssid info is different continue to store ssid %s new ssid %s",
3297  MODULE_NAME, param.wifiCredentials.cSSID, savedWiFiConnList.ssidSession.ssid);
3298  }
3299  }
3300  memset(&param,0,sizeof(param));
3301  param.requestType=WIFI_SET_CREDENTIALS;
3302  STRCPY_S(param.wifiCredentials.cSSID, sizeof(param.wifiCredentials.cSSID), savedWiFiConnList.ssidSession.ssid);
3303  STRCPY_S(param.wifiCredentials.cPassword, sizeof(param.wifiCredentials.cPassword), savedWiFiConnList.ssidSession.passphrase);
3304  param.wifiCredentials.iSecurityMode = savedWiFiConnList.ssidSession.security_mode;
3305  if(IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_MFRLIB_NAME,IARM_BUS_MFRLIB_API_WIFI_Credentials,(void *)&param,sizeof(param)))
3306  {
3307  LOG_TRACE("[%s] IARM success in storing wifi credentials",MODULE_NAME);
3308  memset(&param,0,sizeof(param));
3309  param.requestType=WIFI_GET_CREDENTIALS;
3310  if(IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_MFRLIB_NAME,IARM_BUS_MFRLIB_API_WIFI_Credentials,(void *)&param,sizeof(param)))
3311  {
3312  LOG_TRACE("[%s] IARM success in retrieving the stored wifi credentials ",MODULE_NAME);
3313  if ((strcmp (param.wifiCredentials.cSSID, savedWiFiConnList.ssidSession.ssid) == 0) &&
3314  (strcmp (param.wifiCredentials.cPassword, savedWiFiConnList.ssidSession.passphrase) == 0) &&
3315  (param.wifiCredentials.iSecurityMode == savedWiFiConnList.ssidSession.security_mode || param.wifiCredentials.iSecurityMode == -1) )
3316  {
3317  retVal=true;
3318  LOG_INFO("[%s] Successfully stored the credentails and verified stored ssid %s current ssid %s and security_mode %d",MODULE_NAME,param.wifiCredentials.cSSID,savedWiFiConnList.ssidSession.ssid,param.wifiCredentials.iSecurityMode);
3319  }
3320  else
3321  {
3322  LOG_ERR("[%s] failure in storing wifi credentials",MODULE_NAME);
3323  }
3324 
3325  }
3326  else
3327  {
3328  LOG_ERR("[%s] IARM error in retrieving stored wifi credentials mfr error code %d ",MODULE_NAME,param.returnVal );
3329  }
3330  }
3331  else
3332  {
3333  LOG_ERR("[%s] IARM error in storing wifi credentials mfr error code %d", MODULE_NAME, param.returnVal);
3334  }
3335 #endif // ENABLE_IARM
3336 #endif // USE_RDK_WIFI_HAL
3337  LOG_TRACE("[%s] Exit", MODULE_NAME);
3338  return retVal;
3339 }
3340 
3341 
3343 {
3344  bool retVal=false;
3345 #ifdef USE_RDK_WIFI_HAL
3346  LOG_TRACE("[%s] Enter", MODULE_NAME);
3347 #ifdef ENABLE_IARM
3348  if(IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_MFRLIB_NAME,IARM_BUS_MFRLIB_API_WIFI_EraseAllData,0,0))
3349  {
3350  LOG_TRACE("[%s] IARM success in erasing wifi credentials ",MODULE_NAME);
3351  retVal=true;
3352  }
3353  else
3354  {
3355  LOG_ERR("[%s] failure in erasing wifi credentials ",MODULE_NAME);
3356  }
3357  LOG_TRACE("[%s] Exit", MODULE_NAME);
3358 #endif
3359 #endif
3360  return retVal;
3361 }
3362 
3363 
3365 {
3366  int radioIndex = 0;
3367  LOG_TRACE("[%s] Enter", MODULE_NAME);
3368 #ifdef USE_RDK_WIFI_HAL
3369  wifi_sta_stats_t stats;
3370  memset(&stats, '\0', sizeof(stats));
3371 
3372  wifi_getStats(radioIndex, &stats);
3373 
3374  bool enable = (WIFI_CONNECTED == get_WiFiStatusCode())? true: false;
3375  if (enable)
3376  {
3377  strncpy((char *)endPointInfo->status, "Enabled", (size_t)BUFF_LENGTH_64);
3378  endPointInfo->enable = enable;
3379  strncpy((char *)endPointInfo->SSIDReference, (const char *)stats.sta_SSID, (size_t)BUFF_LENGTH_64);
3380 
3381  endPointInfo->stats.signalStrength = stats.sta_RSSI;
3382  endPointInfo->stats.retransmissions = stats.sta_Retransmissions;
3383  endPointInfo->stats.lastDataDownlinkRate = stats.sta_LastDataDownlinkRate;
3384  endPointInfo->stats.lastDataUplinkRate = stats.sta_LastDataUplinkRate;
3385  /*endPointInfo->security.modesSupported = ;*/
3386  }
3387  else
3388  {
3389  strncpy((char *)endPointInfo->status, "Disabled", (size_t)BUFF_LENGTH_64);
3390  endPointInfo->enable = enable;
3391  }
3392 
3393  LOG_DBG("[%s] \n Profile : \"EndPoint.1.\": \n \
3394  [Enable : \"%d\"| Status : \"%s\" | SSIDReference : \"%s\" ]",
3395  MODULE_NAME, endPointInfo->enable, endPointInfo->status, endPointInfo->SSIDReference);
3396 
3397  LOG_DBG("[%s] \n Profile : \"EndPoint.1.Stats.\": \n \
3398  [SignalStrength : \"%d\"| Retransmissions : \"%ld\" | LastDataUplinkRate : \"%ld\" | LastDataDownlinkRate : \" %ld\" ]",
3399  MODULE_NAME,endPointInfo->stats.signalStrength, endPointInfo->stats.retransmissions,
3400  endPointInfo->stats.lastDataDownlinkRate, endPointInfo->stats.lastDataUplinkRate);
3401 #endif // USE_RDK_WIFI_HAL
3402  LOG_TRACE("[%s] Exit", MODULE_NAME );
3403 }
3404 
3405 
3406 #ifdef USE_RDK_WIFI_HAL
3407 #ifdef WIFI_CLIENT_ROAMING
3408 bool getRoamingConfigInfo(WiFi_RoamingCtrl_t *param)
3409 {
3410  int ssidIndex = 0;
3411  bool retStatus = false;
3412  wifi_roamingCtrl_t out_param;
3413  memset(&out_param,0,sizeof(out_param));
3414  int status = wifi_getRoamingControl(ssidIndex,&out_param);
3415  if(status == 0) {
3416  param->roamingEnable = (out_param.roamingEnable==1?true:false);
3417  param->preassnBestThreshold = out_param.preassnBestThreshold;
3418  param->preassnBestDelta = out_param.preassnBestDelta;
3419  param->status = ROAM_PARAM_SUCCESS;
3420  param->selfSteerOverride = (out_param.selfSteerOverride==1?true:false);
3421  param->postAssnLevelDeltaConnected = out_param.postAssnLevelDeltaConnected;
3422  param->postAssnLevelDeltaDisconnected = out_param.postAssnLevelDeltaDisconnected;
3423  param->postAssnSelfSteerThreshold = out_param.postAssnSelfSteerThreshold;
3424  param->postAssnSelfSteerTimeframe = out_param.postAssnSelfSteerTimeframe;
3425  param->postAssnBackOffTime = out_param.postAssnBackOffTime;
3426  //param->postAssnSelfSteerBeaconsMissedTime = out_param.postAssnSelfSteerBeaconsMissedTime;
3427  param->postAssnAPcontrolThresholdLevel = out_param.postAssnAPctrlThreshold;
3428  param->postAssnAPcontrolTimeframe = out_param.postAssnAPctrlTimeframe;
3429  param->roaming80211kvrEnable = out_param.roam80211kvrEnable;
3430  LOG_DBG("[%s] Successfully set Roaming param- [roamingEnable=%d,preassnBestThreshold=%d,preassnBestDelta=%d]", MODULE_NAME,param->roamingEnable,param->preassnBestThreshold,param->preassnBestDelta);
3431  retStatus = true;
3432  } else if(status == -1) {
3433  param->status = ROAM_PARAM_FAILURE;
3434  } else if(status == -2) {
3435  param->status = ROAM_PARAM_DISABLED;
3436  } else
3437  param->status = ROAM_PARAM_FAILURE;
3438 
3439  return retStatus;
3440 }
3441 
3442 bool setRoamingConfigInfo(WiFi_RoamingCtrl_t *param)
3443 {
3444  int ssidIndex = 0;
3445  bool retStatus = false;
3446  wifi_roamingCtrl_t in_param;
3447  memset(&in_param,0,sizeof(in_param));
3448 
3449  in_param.roamingEnable = (param->roamingEnable==true?1:0);
3450  in_param.preassnBestThreshold = param->preassnBestThreshold;
3451  in_param.preassnBestDelta = param->preassnBestDelta;
3452  in_param.selfSteerOverride = (param->selfSteerOverride==true?1:0);
3453  in_param.postAssnLevelDeltaConnected = param->postAssnLevelDeltaConnected;
3454  in_param.postAssnLevelDeltaDisconnected = param->postAssnLevelDeltaDisconnected;
3455  in_param.postAssnSelfSteerThreshold = param->postAssnSelfSteerThreshold;
3456  in_param.postAssnSelfSteerTimeframe = param->postAssnSelfSteerTimeframe;
3457  in_param.postAssnBackOffTime = param->postAssnBackOffTime;
3458  //in_param.postAssnSelfSteerBeaconsMissedTime = param->postAssnSelfSteerBeaconsMissedTime;
3459  in_param.postAssnAPctrlThreshold = param->postAssnAPcontrolThresholdLevel;
3460  in_param.postAssnAPctrlTimeframe = param->postAssnAPcontrolTimeframe;
3461  in_param.roam80211kvrEnable = param->roaming80211kvrEnable;
3462 
3463  int status = wifi_setRoamingControl(ssidIndex,&in_param);
3464  if(status == 0) {
3465  param->status = ROAM_PARAM_SUCCESS;
3466  retStatus = true;
3467  LOG_DBG("[%s] Successfully set Roaming param- [roamingEnable=%d,preassnBestThreshold=%d,preassnBestDelta=%d]", MODULE_NAME,in_param.roamingEnable,in_param.preassnBestThreshold,in_param.preassnBestDelta);
3468  } else if(status == -1)
3469  param->status = ROAM_PARAM_FAILURE;
3470  else if(status == -2)
3471  param->status = ROAM_PARAM_DISABLED;
3472  else
3473  param->status = ROAM_PARAM_FAILURE;
3474 
3475  return retStatus;
3476 }
3477 #endif
3479 {
3480  int radioIndex=0;
3481  LOG_TRACE("[%s] Enter", MODULE_NAME);
3482 
3484  if(trafficStats == NULL)
3485  {
3486  LOG_TRACE( "[%s]Malloc Memory allocation failure", MODULE_NAME);
3487  return false;
3488  }
3489  printf("malloc allocated = %d ", malloc_usable_size(trafficStats));
3490  if (wifi_getRadioTrafficStats(radioIndex, trafficStats) == RETURN_OK) {
3491  params->bytesSent = trafficStats->radio_BytesSent;
3492  params->bytesReceived = trafficStats->radio_BytesReceived;
3493  params->packetsSent = trafficStats->radio_PacketsSent;
3494  params->packetsReceived = trafficStats->radio_PacketsReceived;
3495  params->errorsSent = trafficStats->radio_ErrorsSent;
3496  params->errorsReceived = trafficStats->radio_ErrorsReceived;
3497  params->discardPacketsSent = trafficStats->radio_DiscardPacketsSent;
3498  params->discardPacketsReceived = trafficStats->radio_DiscardPacketsReceived;
3499  params->plcErrorCount = trafficStats->radio_DiscardPacketsReceived;
3500  params->fcsErrorCount = trafficStats->radio_FCSErrorCount;
3501  params->invalidMACCount = trafficStats->radio_InvalidMACCount;
3502  params->packetsOtherReceived = trafficStats->radio_PacketsOtherReceived;
3503  params->noiseFloor = trafficStats->radio_NoiseFloor;
3504 
3505  }
3506  else
3507  {
3508  LOG_ERR("[%s] HAL wifi_getRadioTrafficStats FAILURE", MODULE_NAME);
3509  }
3510  free(trafficStats);
3511 
3512  LOG_TRACE("[%s] Exit", MODULE_NAME );
3513  return true;
3514 }
3515 
3516 void logs_Period1_Params()
3517 {
3518  LOG_TRACE("[%s] Enter", MODULE_NAME);
3519  if(NULL != wifiParams_Tele_Period1.paramlist)
3520  {
3521  WiFi_EndPoint_Diag_Params endPointInfo;
3522  getEndPointInfo(&endPointInfo);
3524  getRadioStats(&params);
3525 
3526  GList *iter = g_list_first(wifiParams_Tele_Period1.paramlist);
3527 
3528  while(iter)
3529  {
3530  /* Device.WiFi.EndPoint.{i}.Stats.LastDataDownlinkRate*/
3531  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "LastDataDownlinkRate")) {
3532  LOG_INFO("%s:%lu ", (char *)iter->data, endPointInfo.stats.lastDataDownlinkRate);
3533  }
3534  /* Device.WiFi.EndPoint.{i}.Stats.LastDataUplinkRate */
3535  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "LastDataUplinkRate ")) {
3536  LOG_INFO("%s:%lu ", (char *)iter->data, endPointInfo.stats.lastDataUplinkRate);
3537  }
3538 
3539  /* Device.WiFi.EndPoint.{i}.Stats.Retransmissions*/
3540  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Retransmissions")) {
3541  LOG_INFO("%s:%lu ", (char *)iter->data, endPointInfo.stats.retransmissions);
3542  }
3543 
3544  /*Device.WiFi.Endpoint.{i}.Stats.SignalStrength*/
3545  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "SignalStrength")) {
3546  LOG_INFO("%s:%d ", (char *)iter->data, endPointInfo.stats.signalStrength);
3547  }
3548 
3549  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Channel")) {
3550  unsigned long output_ulong = 0;
3551  int radioIndex = 0;
3552  if (wifi_getRadioChannel(radioIndex, &output_ulong) == RETURN_OK) {
3553  LOG_INFO("%s:%lu ", (char *)iter->data , output_ulong);
3554  }
3555  }
3556 
3557  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Stats.FCSErrorCount")) {
3558  LOG_INFO("%s:%u ", (char *)iter->data, params.fcsErrorCount);
3559  }
3560 
3561  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Stats.Noise")) {
3562  LOG_INFO("%s:%u ", (char *)iter->data, params.noiseFloor);
3563  }
3564 
3565  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "TransmitPower"))
3566  {
3567  INT output_INT = 0;
3568  int radioIndex = 0;
3569  if (wifi_getRadioTransmitPower( radioIndex, &output_INT) == RETURN_OK) {
3570  LOG_INFO("%s:%d ", (char *)iter->data , output_INT);
3571  }
3572  }
3573 
3574  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Stats.ErrorsReceived")) {
3575  LOG_INFO( "%s:%u ", (char *)iter->data, params.errorsReceived);
3576  }
3577 
3578  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Stats.ErrorsSent")) {
3579  LOG_INFO("%s:%u ", (char *)iter->data, params.errorsSent);
3580  }
3581 
3582  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Stats.PacketsReceived")) {
3583  LOG_INFO( "%s:%lu ", (char *)iter->data, params.packetsReceived);
3584  }
3585 
3586  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Stats.PacketsSent")) {
3587  LOG_INFO("%s:%lu ", (char *)iter->data, params.packetsSent);
3588  }
3589 
3590  iter = g_list_next(iter);
3591  }
3592 
3593  }
3594 
3595  LOG_TRACE("Exit");
3596 }
3597 
3598 
3599 void logs_Period2_Params()
3600 {
3601  static bool print_flag = true;
3602  time_t start_t;
3603  static time_t lastExec_t;
3604  double diff_t;
3605 
3606  LOG_ENTRY_EXIT;
3607 
3608  time(&start_t);
3609  LOG_TRACE("print_flag : %d", print_flag);
3610  if(print_flag)
3611  {
3612  if(NULL != wifiParams_Tele_Period2.paramlist)
3613  {
3614  char bssid_string[BUFF_MAX];
3615  int ssidIndex = 0;
3616  memset(bssid_string,0, BUFF_MAX);
3617  char output_string[BUFF_MAX];
3618  wifi_getBaseBSSID(ssidIndex, bssid_string);
3619 
3620  WiFiConnectionStatus currSsidInfo;
3621  memset(&currSsidInfo, '\0', sizeof(currSsidInfo));
3622  get_CurrentSsidInfo(&currSsidInfo);
3623 
3624  GList *iter = g_list_first(wifiParams_Tele_Period2.paramlist);
3625  while(iter)
3626  {
3627  LOG_TRACE("%s", (char *)iter->data);
3628  /* Device.WiFi.Endpoint.{i}.NumberOfEntries*/
3629  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "NumberOfEntries")) {
3630  int noOfEndpoint = 1;
3631  LOG_INFO( "%s:%d", (char *)iter->data, noOfEndpoint);
3632  }
3633 
3634  if((g_strrstr ((const gchar *)iter->data, (const gchar *) "Device.WiFi.EndPoint.1.Profile.1.SSID"))
3635  || (g_strrstr ((const gchar *)iter->data, (const gchar *) "Device.WiFi.SSID.1.SSID"))
3636  || (g_strrstr ((const gchar *)iter->data, (const gchar *) "Device.WiFi.EndPoint.1.SSIDReference")))
3637  {
3638  LOG_INFO("%s:%s", (char *)iter->data, currSsidInfo.ssidSession.ssid);
3639  }
3640 
3641  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "BSSID")) {
3642  LOG_INFO("%s:%s", (char *)iter->data, bssid_string);
3643  }
3644 
3645  /* Device.WiFi.EndPoint.{i}.Profile.{i}.SSID*/
3646  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Name")) {
3647  memset(output_string,0, BUFF_MAX);
3648  if(wifi_getSSIDName(ssidIndex, output_string) == RETURN_OK) {
3649  LOG_INFO("%s:%s", (char *)iter->data, output_string);
3650  }
3651  }
3652 
3653  if(g_strrstr ((const gchar *)iter->data, (const gchar *) "Device.WiFi.SSID.1.MACAddress")) {
3654  if(gWifiMacAddress[0] != '\0') {
3655  LOG_INFO("%s:%s", (char *)iter->data, gWifiMacAddress);
3656  }
3657  }
3658 
3659  iter = g_list_next(iter);
3660  }
3661  }
3662  }
3663  diff_t = difftime(start_t, lastExec_t);
3664 
3665  if (diff_t >= wifiParams_Tele_Period2.timePeriod) {
3666  time(&lastExec_t);
3667  print_flag = true;
3668  }
3669  else
3670  {
3671  print_flag = false;
3672  }
3673 
3674 }
3675 
3676 
3677 void readValue(FILE *pFile, char *pToken, char *data)
3678 {
3679  char buffer[DATA_LEN];
3680  char *keyValue;
3681  if(pFile == NULL)
3682  return;
3683  /* Search the token in the config txt file and copy the value */
3684  fseek(pFile, 0, SEEK_SET);
3685  while (fgets(buffer, sizeof (buffer), pFile) != NULL)
3686  {
3687  keyValue = strtok( buffer, "=" );
3688  if(!(strcmp(keyValue, pToken)))
3689  {
3690  keyValue = strtok(NULL, "\n" );
3691  if(keyValue != NULL)
3692  {
3693  strncpy(data, keyValue,strlen(keyValue));
3694  data[strlen(keyValue)] = '\0'; // Adding '\0' is required if strncpy is used
3695  }
3696  break;
3697  }
3698  }
3699 }
3700 
3701 #ifdef ENABLE_LOST_FOUND
3702 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3703 /* get lfat from auth service */
3704 int laf_get_lfat(laf_lfat_t *lfat)
3705 {
3706  long http_err_code;
3707  cJSON *response;
3708  std::string str;
3709  gchar *retStr;
3710 
3711  str.assign(confProp.wifiProps.getLfatUrl,strlen(confProp.wifiProps.getLfatUrl));
3712 
3713  CurlObject getLfatUrl(str);
3714  retStr = getLfatUrl.getCurlData();
3715  http_err_code = getLfatUrl.gethttpcode();
3716 
3717  if((http_err_code != 200) || (strlen(retStr ) <= 1)) {
3718  LOG_ERR("get lfat from auth service failed with error code %ld", http_err_code);
3719  if(http_err_code == 0)
3720  http_err_code = 404;
3721  return http_err_code;
3722  }
3723 
3724  /* parse json response */
3725  LOG_DBG("Response from authservice to get lfat %s", retStr);
3726  response = cJSON_Parse(retStr);
3727  RDK_ASSERT_NOT_NULL(response);
3728  RDK_ASSERT_NOT_NULL(cJSON_GetObjectItem(response, "version"));
3729  STRCPY_S(lfat->version, sizeof(lfat->version), cJSON_GetObjectItem(response, "version")->valuestring);
3730  RDK_ASSERT_NOT_NULL(cJSON_GetObjectItem(response, "expires"));
3731  lfat->ttl = cJSON_GetObjectItem(response, "expires")->valueint;
3732  RDK_ASSERT_NOT_NULL(cJSON_GetObjectItem(response, "LFAT"));
3733  lfat->len = strlen(cJSON_GetObjectItem(response, "LFAT")->valuestring);
3734  lfat->token = (char *) malloc(lfat->len+1);
3735  if(lfat->token == NULL)
3736  return ENOMEM;
3737  STRCPY_S(lfat->token, lfat->len+1, cJSON_GetObjectItem(response, "LFAT")->valuestring);
3738  lfat->token[lfat->len] = '\0';
3739  cJSON_Delete(response);
3740  return 0;
3741 }
3742 #else // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
3743 int laf_get_lfat(laf_lfat_t *lfat)
3744 {
3745  LOG_ENTRY_EXIT;
3746  int ret=0;
3747  unsigned int tokenlength=0;
3748  FILE *fd = NULL;
3749  char version[MAX_VERSION_LEN];
3750  char ttl[MAX_VERSION_LEN];
3751  long value = 0;
3752  char *eptr;
3753 
3754  ret = get_token_length(tokenlength);
3755  if(ret != 0) {
3756  LOG_ERR("laf_get_lfat - Error in token read");
3757  return ret;
3758  }
3759  lfat->token = (char *) malloc(tokenlength+1);
3760  if(lfat->token == NULL)
3761  return ENOMEM;
3762  ret = get_laf_token(lfat->token,tokenlength);
3763  lfat->len = tokenlength;
3764  lfat->token[tokenlength] = '\0';
3765  LOG_DBG("laf_get_lfat - token size is - %d", lfat->len);
3766  LOG_DBG("laf_get_lfat - token is - %s", lfat->token);
3767 
3768  //Read lfat version and ttl from /mnt/ramdisk/env/.lnf_conf
3769  if (0 == access(LFAT_CONF_FILE, F_OK)) {
3770  memset(version,'\0', MAX_VERSION_LEN);
3771  memset(ttl, '\0', MAX_VERSION_LEN);
3772  fd = fopen(LFAT_CONF_FILE, "r");
3773  if (fd != NULL) {
3774  readValue(fd, LFAT_VERSION, version);
3775  if(version != NULL){
3776  STRCPY_S(lfat->version, sizeof(lfat->version), version);
3777  }else{
3778  STRCPY_S(lfat->version, sizeof(lfat->version), "1.1");
3779  }
3780 
3781  readValue(fd, LFAT_TTL, ttl);
3782  if(ttl != NULL){
3783  value = strtol(ttl, &eptr, 10);
3784  lfat->ttl = value;
3785  }else{
3786  lfat->ttl = 31536000;
3787  }
3788  LOG_INFO("lfat_version : %s, lfat_ttl : %s",version, ttl);
3789  LOG_INFO("lfat_version : %s, lfat_ttl : %ld",lfat->version, lfat->ttl);
3790  fclose(fd);
3791  }else{
3792  LOG_INFO("Unable to open lfat_conf file");
3793  }
3794  }
3795  else //If .lnf_conf file is not present
3796  {
3797  // Read from netsrvmgr.conf
3798  STRCPY_S(lfat->version, sizeof(lfat->version), confProp.wifiProps.lfatVersion);
3799  lfat->ttl = confProp.wifiProps.lfatTTL;
3800  LOG_INFO("lfat_version : %s, lfat_ttl : %ld",lfat->version, lfat->ttl);
3801  }
3802  return ret;
3803 }
3804 #endif // ENABLE_XCAM_SUPPORT
3805 
3806 #if !defined (ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3807 /* store lfat with auth service */
3808 int laf_set_lfat(laf_lfat_t* const lfat)
3809 {
3810  cJSON *req_payload;
3811  char *data;
3812  long http_err_code;
3813  std::string str;
3814  gchar *retStr;
3815 
3816  str.assign(confProp.wifiProps.setLfatUrl,strlen(confProp.wifiProps.setLfatUrl));
3817  req_payload = cJSON_CreateObject();
3818  RDK_ASSERT_NOT_NULL(req_payload);
3819  cJSON_AddStringToObject(req_payload, "version", lfat->version);
3820  cJSON_AddNumberToObject(req_payload, "expires", lfat->ttl);
3821  cJSON_AddStringToObject(req_payload, "lfat", lfat->token);
3822 
3823  data = cJSON_Print(req_payload);
3824  RDK_ASSERT_NOT_NULL(data);
3825  CurlObject setLfatUrl(str,data);
3826  retStr = setLfatUrl.getCurlData();
3827  http_err_code = setLfatUrl.gethttpcode();
3828 
3829  if(http_err_code != 200) {
3830  LOG_ERR("set lfat to auth service failed with error code %ld message", http_err_code);
3831  cJSON_Delete(req_payload);
3832  if(data)
3833  free(data);
3834  if(http_err_code == 0)
3835  http_err_code = 404;
3836  return http_err_code;
3837  }
3838 
3839  cJSON_Delete(req_payload);
3840  if(data)
3841  free(data);
3842 
3843  return 0;
3844 }
3845 #else // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
3846 int laf_set_lfat(laf_lfat_t* const lfat)
3847 {
3848  LOG_ENTRY_EXIT;
3849  char* tokenfilename = getlfatfilename();
3850  if(NULL != lfat->token){
3851  LOG_INFO("Updating lfat token after token expiry/recovery");
3852  int result = getSetFileContent(tokenfilename, "set", lfat->token);
3853  LOG_DBG("tokenfilename : %s lfat->token : %s", tokenfilename, lfat->token);
3854  if (result)
3855  {
3856  LOG_ERR("Error setting lfat token");
3857  return -1;
3858  }
3859  }else {
3860  LOG_ERR( "LFAT Token is Null");
3861  return -1;
3862  }
3863  return 0;
3864 }
3865 #endif // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
3866 
3867 bool addSwitchToPrivateResults(int lnfError,char *currTime)
3868 {
3869  bool ret = false;
3870  guint lstLnfPvtResultsLength=0;
3871  WiFiLnfSwitchPrivateResults_t *WiFiLnfSwitchPrivateResultsData=NULL;
3872  LOG_TRACE("[%s] Enter", MODULE_NAME);
3873  WiFiLnfSwitchPrivateResultsData = g_new0(WiFiLnfSwitchPrivateResults_t,1);
3874  if(NULL == WiFiLnfSwitchPrivateResultsData) {
3875  LOG_ERR("[%s] \'Failed to allocate memory", MODULE_NAME);
3876  }
3877  else {
3878  WiFiLnfSwitchPrivateResultsData->lnfError = (unsigned char)lnfError;
3879  g_stpcpy((gchar*)WiFiLnfSwitchPrivateResultsData->currTime,currTime);
3880  lstLnfPvtResults=g_list_append(lstLnfPvtResults,WiFiLnfSwitchPrivateResultsData);
3881  lstLnfPvtResultsLength=g_list_length(lstLnfPvtResults);
3882  if ((lstLnfPvtResults != NULL)&&(lstLnfPvtResultsLength > 0)) {
3883  LOG_INFO("[%s] Time = %s lnf error = %d length of list = %d ", MODULE_NAME,WiFiLnfSwitchPrivateResultsData->currTime,WiFiLnfSwitchPrivateResultsData->lnfError,g_list_length(lstLnfPvtResults));
3884  ret = true;
3885  }
3886  else {
3887  LOG_ERR("[%s] Error in added Time and lnf error to list, error code %d", MODULE_NAME, ret );
3888  }
3889  }
3890  LOG_TRACE("[%s] Exit", MODULE_NAME );
3891  return ret;
3892 }
3893 
3894 bool convertSwitchToPrivateResultsToJson(char *buffer)
3895 {
3896  cJSON *rootObj = NULL, *array_element = NULL, *array_obj = NULL;
3897  UINT output_array_size = 0;
3898  INT index;
3899  char *out = NULL;
3900  char privateResultsLength=0;
3901  WiFiLnfSwitchPrivateResults_t *WiFiLnfSwitchPrivateResultsData=NULL;
3902  LOG_TRACE("[%s] Enter", MODULE_NAME);
3903  rootObj = cJSON_CreateObject();
3904  if(NULL == rootObj) {
3905  LOG_ERR("[%s] Failed to create root json object.", MODULE_NAME);
3906  return false;
3907  }
3908  cJSON_AddItemToObject(rootObj, "results", array_obj=cJSON_CreateArray());
3909  GList *element = g_list_first(lstLnfPvtResults);
3910  privateResultsLength=g_list_length(lstLnfPvtResults);
3911 
3912  while ((element != NULL)&&(privateResultsLength > 0))
3913  {
3914  WiFiLnfSwitchPrivateResultsData = (WiFiLnfSwitchPrivateResults_t*)element->data;
3915  cJSON_AddItemToArray(array_obj,array_element=cJSON_CreateObject());
3916  cJSON_AddStringToObject(array_element, "timestamp",(const char*)WiFiLnfSwitchPrivateResultsData->currTime);
3917  cJSON_AddNumberToObject(array_element, "result", WiFiLnfSwitchPrivateResultsData->lnfError);
3918  LOG_TRACE("[%s] Time = %s lnf error = %d ", MODULE_NAME, WiFiLnfSwitchPrivateResultsData->currTime,WiFiLnfSwitchPrivateResultsData->lnfError );
3919  element = g_list_next(element);
3920  privateResultsLength--;
3921  }
3922  out = cJSON_PrintUnformatted(rootObj);
3923 
3924  if(out) {
3925  strncpy(buffer, out, strlen(out)+1);
3926  LOG_TRACE("[%s] Buffer = %s", MODULE_NAME,buffer );
3927  }
3928  if(rootObj) {
3929  cJSON_Delete(rootObj);
3930  }
3931  if(out) free(out);
3932  LOG_TRACE("[%s] Exit", MODULE_NAME );
3933  return true;
3934 }
3935 bool clearSwitchToPrivateResults()
3936 {
3937  LOG_TRACE("[%s] Enter", MODULE_NAME);
3938  if((lstLnfPvtResults) && (g_list_length(lstLnfPvtResults) != 0))
3939  {
3940 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3941  g_list_free_full((GList *)g_steal_pointer(&lstLnfPvtResults),g_free);
3942 #else
3943  g_list_free_full(lstLnfPvtResults,g_free);
3944 #endif
3945  }
3946  else
3947  {
3948  LOG_INFO("[%s] switch to private results list is empty ", MODULE_NAME);
3949  }
3950  LOG_TRACE("[%s] Exit", MODULE_NAME );
3951  return true;
3952 }
3953 #endif // ENABLE_LOST_FOUND
3954 #endif // USE_RDK_WIFI_HAL
3956 {
3957  bool result=true;
3958  bShutdownWifi= true;
3959  LOG_TRACE("[%s] Enter", MODULE_NAME);
3960 
3961  pthread_mutex_lock(&mutexGo);
3962  if(0 == pthread_cond_signal(&condGo)) {
3963  LOG_INFO("[%s] Signalling wifiStatusMonitorThread to exit cond wait", MODULE_NAME);
3964  }
3965  pthread_mutex_unlock(&mutexGo);
3966 
3967  LOG_INFO("[%s] calling pthread_join wifiStatusMonitorThread", MODULE_NAME);
3968  pthread_join (wifiStatusMonitorThread, NULL);
3969 
3970 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3971  pthread_mutex_lock(&mutexAPDetails);
3972  bsignalAPDetailsReady = true;
3973  if(0 == pthread_cond_signal(&condAPDetails)) {
3974  LOG_INFO("[%s] Signalling apDetailsCollectionThread to exit cond wait", MODULE_NAME);
3975  }
3976  pthread_mutex_unlock(&mutexAPDetails);
3977 
3978  LOG_INFO("[%s] calling pthread_cancel apDetailsCollectionThread", MODULE_NAME);
3979  if ((apDetailsCollectionThread) && (pthread_cancel(apDetailsCollectionThread) == -1 )) {
3980  LOG_ERR("[%s] apDetailsCollectionThread cancel failed!", MODULE_NAME);
3981  result = false;
3982  }
3983 #endif
3984 
3985 #ifdef ENABLE_LOST_FOUND
3986  if ((lafConnectThread) && (pthread_cancel(lafConnectThread) == -1 )) {
3987  LOG_ERR("[%s] lafConnectThread cancel failed!", MODULE_NAME);
3988  result=false;
3989  }
3990  if ((lafConnectToPrivateThread) && (pthread_cancel(lafConnectToPrivateThread) == -1 )) {
3991  LOG_ERR("[%s] lafConnectToPrivateThread failed!", MODULE_NAME);
3992  result=false;
3993  }
3994 #endif
3995  LOG_INFO("[%s] Start WiFi Uninitialization", MODULE_NAME);
3996 #ifdef USE_RDK_WIFI_HAL
3997  wifi_uninit();
3998 #endif
3999  LOG_INFO("[%s] WiFi Uninitialization done", MODULE_NAME);
4000  gWifiAdopterStatus = WIFI_UNINSTALLED;
4001 #ifdef ENABLE_LOST_FOUND
4002  condLAF = PTHREAD_COND_INITIALIZER;
4003  mutexLAF = PTHREAD_MUTEX_INITIALIZER;
4004  gWifiLNFStatus = LNF_UNITIALIZED;
4005  bLNFConnect=false;
4006  isLAFCurrConnectedssid=false;
4007 #endif
4008  wifiStatusLock = PTHREAD_MUTEX_INITIALIZER;
4009  condGo = PTHREAD_COND_INITIALIZER;
4010  mutexGo = PTHREAD_MUTEX_INITIALIZER;
4011 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
4012  condAPDetails = PTHREAD_COND_INITIALIZER;
4013  mutexAPDetails = PTHREAD_MUTEX_INITIALIZER;
4014 #endif
4015  memset(&gSsidList,0,sizeof gSsidList);
4016  memset(&savedWiFiConnList,0,sizeof savedWiFiConnList);
4017  memset(&wifiConnData,0,sizeof wifiConnData);
4018  LOG_TRACE("[%s] Exit", MODULE_NAME );
4019  return result;
4020 }
4021 
4022 
LNF_IN_PROGRESS
@ LNF_IN_PROGRESS
Definition: wifiSrvMgrIarmIf.h:106
_wifi_sta_stats::sta_Encryption
char sta_Encryption[64]
WiFi Encryption Type AES, TKIP, etc.
Definition: wifi_common_hal.h:461
_HostIf_MsgData_t::reqType
HostIf_ReqType_t reqType
Definition: hostIf_tr69ReqHandler.h:178
WIFI_CONNECTING
@ WIFI_CONNECTING
Definition: wifiSrvMgrIarmIf.h:98
WIFI_AUTH_FAILED
@ WIFI_AUTH_FAILED
Definition: wifiSrvMgrIarmIf.h:134
getCurrentTime
void getCurrentTime(struct timespec *timer)
Get Current time.
Definition: hostIf_utils.cpp:466
storeMfrWifiCredentials
bool storeMfrWifiCredentials(void)
This function retrieve and store the WIFI credentials(SSID, password).
Definition: wifiHalUtiles.cpp:3264
_wifi_radioTrafficStats::radio_DiscardPacketsReceived
unsigned long radio_DiscardPacketsReceived
The total number of inbound packets which were chosen to be discarded even though no errors had been ...
Definition: wifi_common_hal.h:357
WIFI_HAL_ERROR_SSID_CHANGED
@ WIFI_HAL_ERROR_SSID_CHANGED
Definition: wifi_common_hal.h:299
_HostIf_MsgData_t::instanceNum
short instanceNum
Definition: hostIf_tr69ReqHandler.h:176
WIFI_HAL_DISCONNECTING
@ WIFI_HAL_DISCONNECTING
Definition: wifi_common_hal.h:293
_WiFi_Radio_Stats_Diag_Params
Definition: wifiSrvMgrIarmIf.h:352
_WiFiConnection
Definition: wifiSrvMgrIarmIf.h:189
_wifi_sta_stats::sta_PhyRate
float sta_PhyRate
Indicates the Physical rate (Mbps)
Definition: wifi_common_hal.h:462
wifi_setCliWpsEnrolleePin
INT wifi_setCliWpsEnrolleePin(INT ssidIndex, CHAR *EnrolleePin)
This API sets the PIN to connect. User get the EnrolleePin (device pin from AP device) give to hostap...
Definition: wifi_client_hal.c:937
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
_wifi_radioTrafficStats::radio_PacketsOtherReceived
unsigned long radio_PacketsOtherReceived
The number of packets that were received, but which were destined for a MAC address that is not assoc...
Definition: wifi_common_hal.h:361
wifi_lastConnected_Endpoint
INT wifi_lastConnected_Endpoint(wifi_pairedSSIDInfo_t *pairedSSIDInfo)
This call will give the last saved AP's ssid.
Definition: wifi_client_hal.c:1555
sysMgr.h
IARM-Bus Sys Manager Public API.
_wifi_sta_stats::sta_SSID
char sta_SSID[64]
The current connected SSID name.
Definition: wifi_common_hal.h:457
WIFI_SSID_CHANGED
@ WIFI_SSID_CHANGED
Definition: wifiSrvMgrIarmIf.h:127
_wifi_radioTrafficStats::radio_InvalidMACCount
unsigned long radio_InvalidMACCount
The number of packets that were received with a detected invalid MAC header error.
Definition: wifi_common_hal.h:360
_WiFiConnectedSSIDInfo
Definition: wifiSrvMgrIarmIf.h:211
_ssidList
Definition: wifiSrvMgrIarmIf.h:164
RETURN_OK
#define RETURN_OK
Defines for function returns.
Definition: wifi_common_hal.h:218
getEndPointInfo
void getEndPointInfo(WiFi_EndPoint_Diag_Params *endPointInfo)
This function checks for WIFI connection enable status, If connection enabled, then it provide WIFI s...
Definition: wifiHalUtiles.cpp:3364
mfrGetSerializedData
mfrError_t mfrGetSerializedData(mfrSerializedType_t type, mfrSerializedData_t *data, mfrEncryptFunction_t crypto)
Retrieve Serialized Read-Only data from device. The serialized data is returned as a byte stream....
Definition: mfrCli.c:98
IARM_BUS_SYSMGR_NAME
#define IARM_BUS_SYSMGR_NAME
Definition: sysMgr.h:110
_WiFiConnectedSSIDInfo::signalStrength
float signalStrength
Definition: wifiSrvMgrIarmIf.h:220
WIFI_HAL_ERROR_CONNECTION_LOST
@ WIFI_HAL_ERROR_CONNECTION_LOST
Definition: wifi_common_hal.h:300
_wifi_radioTrafficStats::radio_ErrorsReceived
unsigned long radio_ErrorsReceived
The total number of inbound packets that contained errors preventing them from being delivered to a h...
Definition: wifi_common_hal.h:355
WIFI_INVALID_CREDENTIALS
@ WIFI_INVALID_CREDENTIALS
Definition: wifiSrvMgrIarmIf.h:131
_IARM_Bus_MFRLib_GetSerializedData_Param_t::buffer
char buffer[(1280)]
Definition: mfrMgr.h:120
_wifi_sta_stats::sta_LastDataUplinkRate
unsigned int sta_LastDataUplinkRate
Definition: wifi_common_hal.h:467
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
_wifi_sta_stats::sta_LastDataDownlinkRate
unsigned int sta_LastDataDownlinkRate
Definition: wifi_common_hal.h:466
get_WifiConnectionType
WiFiConnectionTypeCode_t get_WifiConnectionType()
This function is used to get WIFI connection type.
Definition: wifiHalUtiles.cpp:541
WIFI_HAL_ERROR_CONNECTION_FAILED
@ WIFI_HAL_ERROR_CONNECTION_FAILED
Definition: wifi_common_hal.h:301
_wifi_radioTrafficStats
Definition: wifi_common_hal.h:345
WIFI_HAL_CONNECTING
@ WIFI_HAL_CONNECTING
Definition: wifi_common_hal.h:292
WIFI_CONNECTED
@ WIFI_CONNECTED
Definition: wifiSrvMgrIarmIf.h:99
WIFI_DISCONNECTED
@ WIFI_DISCONNECTED
Definition: wifiSrvMgrIarmIf.h:96
_wifi_sta_stats::sta_BSSID
char sta_BSSID[64]
The BSSID used for connected SSID.
Definition: wifi_common_hal.h:458
wifiSecurityMode_t
wifiSecurityMode_t
Wifi Security modes.
Definition: wifi_common_hal.h:320
_wifi_radioTrafficStats::radio_PacketsReceived
unsigned long radio_PacketsReceived
The total number of packets received on the interface.
Definition: wifi_common_hal.h:352
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
_netMgrConfigProps
Definition: NetworkMgrMain.h:141
_wifi_radioTrafficStats::radio_ErrorsSent
unsigned long radio_ErrorsSent
The total number of outbound packets that could not be transmitted because of errors.
Definition: wifi_common_hal.h:354
_wifi_sta_stats::sta_Frequency
unsigned int sta_Frequency
Current Operating Frequency.
Definition: wifi_common_hal.h:465
_wifi_pairedSSIDInfo::ap_wep_key
CHAR ap_wep_key[128]
wep_key of AP incase of WEP security
Definition: wifi_client_hal.h:125
_IARM_Bus_MFRLib_GetSerializedData_Param_t::bufLen
int bufLen
Definition: mfrMgr.h:121
IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_UPDATE
@ IARM_BUS_SYSMGR_EVENT_XUPNP_DATA_UPDATE
Definition: sysMgr.h:131
_wifi_pairedSSIDInfo::ap_bssid
CHAR ap_bssid[64]
[MACAddress] The BSSID (Basic Service Set ID) used for the neighboring WiFi SSID.
Definition: wifi_client_hal.h:122
_wifi_pairedSSIDInfo::ap_security
CHAR ap_security[64]
Security of AP.
Definition: wifi_client_hal.h:123
_IARM_BUS_SYSMGR_GetXUPNPDeviceInfo_Param_t::bufLength
int bufLength
Definition: sysMgr.h:115
_WiFiLnfSwitchPrivateResults
Definition: wifiSrvMgrIarmIf.h:232
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
CurlObject
Definition: netSrvCurl.h:28
_IARM_XUPNP_NAME
#define _IARM_XUPNP_NAME
Definition: xdiscovery.h:125
getConnectedSSIDInfo
void getConnectedSSIDInfo(WiFiConnectedSSIDInfo_t *)
This function is used to get the connected SSID informations such as SSID, BSSID, signal strength etc...
netsrvmgrUtiles.h
The header file provides components netSrvMgrUtiles information APIs.
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: wifiHalUtiles.cpp:3224
getRadioStats
bool getRadioStats(WiFi_Radio_Stats_Diag_Params *params)
This function is used to get detail radio traffic statistics information.
IARM_BUS_WIFI_MGR_EVENT_MAX
@ IARM_BUS_WIFI_MGR_EVENT_MAX
Definition: wifiSrvMgrIarmIf.h:307
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: wifiHalUtiles.cpp:3230
_wifi_radioTrafficStats::radio_BytesSent
unsigned long radio_BytesSent
The total number of bytes transmitted out of the interface, including framing characters.
Definition: wifi_common_hal.h:349
wifi_connectEndpoint
INT wifi_connectEndpoint(INT ssidIndex, CHAR *AP_SSID, wifiSecurityMode_t AP_security_mode, CHAR *AP_security_WEPKey, CHAR *AP_security_PreSharedKey, CHAR *AP_security_KeyPassphrase, int saveSSID, CHAR *eapIdentity, CHAR *carootcert, CHAR *clientcert, CHAR *privatekey)
This API starts the connection process from client with an AP.
Definition: wifi_client_hal.c:1348
_WiFiConnectedSSIDInfo::band
char band[17]
Definition: wifiSrvMgrIarmIf.h:215
wifi_getBaseBSSID
int wifi_getBaseBSSID(int ssidIndex, char *output_string)
Get the BSSID. Basic Service Set Identifier (BSSID) is the mac addresss of the wireless access point.
_wifi_pairedSSIDInfo::ap_ssid
CHAR ap_ssid[64]
The current service set identifier in use by the neighboring WiFi SSID. The value MAY be empty for hi...
Definition: wifi_client_hal.h:121
_wifi_sta_stats::sta_BAND
char sta_BAND[16]
The BAND used for connected SSID.
Definition: wifi_common_hal.h:459
WIFI_UNKNOWN
@ WIFI_UNKNOWN
Definition: wifiSrvMgrIarmIf.h:133
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
wifi_getRadioTransmitPower
int wifi_getRadioTransmitPower(int radioIndex, int *output_INT)
Get the current transmit Power.
WIFI_CONNECTION_LOST
@ WIFI_CONNECTION_LOST
Definition: wifiSrvMgrIarmIf.h:128
wifi_getSSIDName
int wifi_getSSIDName(int apIndex, char *output_string)
Get SSID name.
_wifi_pairedSSIDInfo::ap_passphrase
CHAR ap_passphrase[128]
Passphrase of AP.
Definition: wifi_client_hal.h:124
eraseMfrWifiCredentials
bool eraseMfrWifiCredentials(void)
This function erase the stored MFR WIFI credentials.
Definition: wifiHalUtiles.cpp:3342
IARM_BUS_TR69HOSTIFMGR_API_SetParams
#define IARM_BUS_TR69HOSTIFMGR_API_SetParams
Definition: hostIf_tr69ReqHandler.h:92
_WiFiConnectionStatus
Definition: wifiSrvMgrIarmIf.h:204
_wifi_roamingCtrl_t
Roaming Control information (pre assoc data structure}.
Definition: wifi_client_hal.h:135
WIFI_DISABLED
@ WIFI_DISABLED
Definition: wifiSrvMgrIarmIf.h:95
_IARM_BUS_SYSMgr_EventData_t
Definition: sysMgr.h:229
WIFI_HAL_SUCCESS
@ WIFI_HAL_SUCCESS
Definition: wifi_common_hal.h:291
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
wifi_getRadioTrafficStats
int wifi_getRadioTrafficStats(int radioIndex, wifi_radioTrafficStats_t *output_struct)
Get detail radio traffic statistics information.
xdiscovery.h
The header file provides xdiscovery APIs.
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
IARM_Bus_BroadcastEvent
IARM_Result_t IARM_Bus_BroadcastEvent(const char *ownerName, IARM_EventId_t eventId, void *data, size_t len)
This API is used to publish an Asynchronous event to all IARM client registered for this perticular e...
getmacaddress
gchar * getmacaddress(const gchar *ifname)
This function is used to get the mac address of the target device.
Definition: xcal-device.c:2253
wifi_getRadioNumberOfEntries
int wifi_getRadioNumberOfEntries(unsigned long *output)
Get total number of radios in the wifi subsystem.
HostIf_ParamType_t
enum _HostIf_ParamType HostIf_ParamType_t
WIFI_FAILED
@ WIFI_FAILED
Definition: wifiSrvMgrIarmIf.h:100
libIBus.h
RDK IARM-Bus API Declarations.
WIFI_NO_SSID
@ WIFI_NO_SSID
Definition: wifiSrvMgrIarmIf.h:132
_IARM_BUS_SYSMGR_GetXUPNPDeviceInfo_Param_t
Definition: sysMgr.h:113
wifi_setCliWpsButtonPush
INT wifi_setCliWpsButtonPush(INT ssidIndex)
Start the Push button pairing.
Definition: wifi_client_hal.c:1295
netSrvMgrUtiles::getCommandOutput
bool getCommandOutput(const char *command, char *output_buffer, size_t output_buffer_size)
This function is used to get the output of running the specified command.
Definition: netsrvmgrUtiles.cpp:737
IARM_Bus_NMgr_WiFi_EventId_t
enum _IARM_Bus_NMgr_WiFi_EventId_t IARM_Bus_NMgr_WiFi_EventId_t
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
_IARM_BUS_MFRLIB_API_WIFI_Credentials_Param_t
Definition: mfrMgr.h:144
updateWiFiList
bool updateWiFiList()
This function gets the host interface parameters through IARM TR69 calls and update BSS identifier li...
_wifi_radioTrafficStats::radio_BytesReceived
unsigned long radio_BytesReceived
The total number of bytes received on the interface, including framing characters.
Definition: wifi_common_hal.h:350
_WiFiConnectedSSIDInfo::noise
float noise
Definition: wifiSrvMgrIarmIf.h:219
_WiFiConnectedSSIDInfo::bssid
char bssid[20]
Definition: wifiSrvMgrIarmIf.h:214
wifi_disconnectEndpoint
INT wifi_disconnectEndpoint(INT ssidIndex, CHAR *AP_SSID)
This API disconnects the access point specified.
Definition: wifi_client_hal.c:1666
WIFI_HAL_ERROR_INVALID_CREDENTIALS
@ WIFI_HAL_ERROR_INVALID_CREDENTIALS
Definition: wifi_common_hal.h:303
_wifi_radioTrafficStats::radio_PacketsSent
unsigned long radio_PacketsSent
The total number of packets transmitted out of the interface.
Definition: wifi_common_hal.h:351
_wifi_radioTrafficStats::radio_FCSErrorCount
unsigned long radio_FCSErrorCount
The number of packets that were received with a detected FCS error. This parameter is based on dot11F...
Definition: wifi_common_hal.h:359
LNF_UNITIALIZED
@ LNF_UNITIALIZED
Definition: wifiSrvMgrIarmIf.h:105
WIFI_CONNECTION_FAILED
@ WIFI_CONNECTION_FAILED
Definition: wifiSrvMgrIarmIf.h:129
rdk_LogLevel
rdk_LogLevel
These values represent the logging 'levels' or 'types', they are each independent.
Definition: rdk_debug.h:157
_wifi_neighbor_ap
Definition: wifi_common_hal.h:409
_wifi_sta_stats::sta_SecMode
char sta_SecMode[64]
WiFi Security Mode WPA2-PSK , WPA2-EAP etc..
Definition: wifi_common_hal.h:460
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
_WiFi_EndPoint_Diag_Params
Definition: wifiSrvMgrIarmIf.h:385
_wifi_radioTrafficStats::radio_NoiseFloor
int radio_NoiseFloor
The noise floor for this radio channel where a recoverable signal can be obtained....
Definition: wifi_common_hal.h:362
WIFI_HAL_ERROR_UNKNOWN
@ WIFI_HAL_ERROR_UNKNOWN
Definition: wifi_common_hal.h:306
wifi_uninit
int wifi_uninit()
Uninitilizes wifi module.
Definition: wifi_common_hal.c:482
_WiFiConnectedSSIDInfo::securityMode
int securityMode
Definition: wifiSrvMgrIarmIf.h:216
IARM_BUS_TR69HOSTIFMGR_NAME
#define IARM_BUS_TR69HOSTIFMGR_NAME
Definition: hostIf_tr69ReqHandler.h:85
IARM_BUS_MFRLIB_API_GetSerializedData
#define IARM_BUS_MFRLIB_API_GetSerializedData
Definition: mfrMgr.h:100
wifi_getRadioChannel
int wifi_getRadioChannel(int radioIndex, unsigned long *output_ulong)
Get the running channel number.
wifi_getStats
void wifi_getStats(int radioIndex, wifi_sta_stats_t *wifi_sta_stats)
Returns current station connection status.
_wifi_radioTrafficStats::radio_DiscardPacketsSent
unsigned long radio_DiscardPacketsSent
The total number of outbound packets which were chosen to be discarded even though no errors had been...
Definition: wifi_common_hal.h:356
_wifi_pairedSSIDInfo
SSID information.
Definition: wifi_client_hal.h:119
_IARM_BUS_WiFiSrvMgr_EventData_t
Definition: wifiSrvMgrIarmIf.h:285
IARM_BUS_MFRLIB_NAME
#define IARM_BUS_MFRLIB_NAME
Definition: mfrMgr.h:98
_wifi_sta_stats::sta_RSSI
float sta_RSSI
RSSI value in dBm.
Definition: wifi_common_hal.h:464
_WiFiConnectedSSIDInfo::frequency
int frequency
Definition: wifiSrvMgrIarmIf.h:217
LOG_INFO
#define LOG_INFO(AAMP_JS_OBJECT, FORMAT,...)
Definition: jsutils.h:39
WIFI_PAIRING
@ WIFI_PAIRING
Definition: wifiSrvMgrIarmIf.h:97
WIFI_HAL_ERROR_AUTH_FAILED
@ WIFI_HAL_ERROR_AUTH_FAILED
Definition: wifi_common_hal.h:305
WIFI_HAL_ERROR_CONNECTION_INTERRUPTED
@ WIFI_HAL_ERROR_CONNECTION_INTERRUPTED
Definition: wifi_common_hal.h:302
_wifi_sta_stats::sta_Retransmissions
unsigned int sta_Retransmissions
Definition: wifi_common_hal.h:468
get_WifiRadioStatus
WiFiStatusCode_t get_WifiRadioStatus()
This function is used to get WIFI connectivity status.
Definition: wifiHalUtiles.cpp:518
_IARM_Bus_MFRLib_GetSerializedData_Param_t
Definition: mfrMgr.h:118
WIFI_HAL_ERROR_DEV_DISCONNECT
@ WIFI_HAL_ERROR_DEV_DISCONNECT
Definition: wifi_common_hal.h:298
_IARM_Bus_MFRLib_GetSerializedData_Param_t::type
mfrSerializedType_t type
Definition: mfrMgr.h:119
_mfrSerializedData_t
Definition: mfrTypes.h:50
_wifi_securityModes
Definition: wifiHalUtiles.cpp:149
WIFI_CONNECTION_INTERRUPTED
@ WIFI_CONNECTION_INTERRUPTED
Definition: wifiSrvMgrIarmIf.h:130
_wifi_neighbor_ap::ap_SSID
char ap_SSID[64]
The current service set identifier in use by the neighboring WiFi SSID. The value MAY be empty for hi...
Definition: wifi_common_hal.h:412
IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo
#define IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo
Definition: xdiscovery.h:126
_wifi_sta_stats
Definition: wifi_common_hal.h:455
IARM_Bus_UnRegisterEventHandler
IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char *ownerName, IARM_EventId_t eventId)
This API is used to Remove ALL handlers registered for the given event. This API remove the all the e...
_WiFiConnectedSSIDInfo::ssid
char ssid[33]
Definition: wifiSrvMgrIarmIf.h:213
IARM_BUS_TR69HOSTIFMGR_API_GetParams
#define IARM_BUS_TR69HOSTIFMGR_API_GetParams
Definition: hostIf_tr69ReqHandler.h:94
telemetryParams
Definition: NetworkMgrMain.h:98
_wifi_neighbor_ap::ap_SignalStrength
int ap_SignalStrength
An indicator of radio signal strength (RSSI) of the neighboring WiFi radio measured in&#160;dBm,...
Definition: wifi_common_hal.h:416
_wifi_sta_stats::sta_Noise
float sta_Noise
Indicator of average noise strength (in dBm) received from the connected WiFi radio.
Definition: wifi_common_hal.h:463
get_CurrentSsidInfo
void get_CurrentSsidInfo(WiFiConnectionStatus *curSSIDConnInfo)
This function is used to get current SSID and connection status from persistent memory.
Definition: wifiHalUtiles.cpp:512
wifi_getNeighboringWiFiDiagnosticResult
int wifi_getNeighboringWiFiDiagnosticResult(int radioIndex, wifi_neighbor_ap_t **neighbor_ap_array, unsigned int *output_array_size)
Get neighbor wifi diagnostics.
_WiFiConnectedSSIDInfo::rate
float rate
Definition: wifiSrvMgrIarmIf.h:218
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
CONNECTED_LNF
@ CONNECTED_LNF
Definition: wifiSrvMgrIarmIf.h:107
LOG_TRACE
#define LOG_TRACE
Definition: rdk_debug_priv.c:83
WIFI_HAL_UNRECOVERABLE_ERROR
@ WIFI_HAL_UNRECOVERABLE_ERROR
Definition: wifi_common_hal.h:304
WIFI_HAL_ERROR_NOT_FOUND
@ WIFI_HAL_ERROR_NOT_FOUND
Definition: wifi_common_hal.h:296
WiFiLNFStatusCode_t
enum _WiFiLNFStatusCode_t WiFiLNFStatusCode_t
wifiStatusCode_t
wifiStatusCode_t
Enumerators for Wi-Fi connection status.
Definition: wifi_common_hal.h:290
WIFI_HAL_ERROR_TIMEOUT_EXPIRED
@ WIFI_HAL_ERROR_TIMEOUT_EXPIRED
Definition: wifi_common_hal.h:297
WIFI_UNINSTALLED
@ WIFI_UNINSTALLED
Definition: wifiSrvMgrIarmIf.h:94