20 #include "wifiHalUtiles.h"
24 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
29 #include <libIARMCore.h>
36 #ifdef ENABLE_LOST_FOUND
38 #endif // ENABLE_LOST_FOUND
40 #ifdef ENABLE_RTMESSAGE
41 rtConnection con_recv = NULL;
46 #include "secure_wrapper.h"
50 #include "safec_lib.h"
52 #define STRCPY_S(dest,size,source) \
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
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;
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
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};
103 bool bShutdownWifi=
false;
104 pthread_t wifiStatusMonitorThread;
108 static eConnMethodType wifi_conn_type;
110 pthread_mutex_t wifiStatusLock = PTHREAD_MUTEX_INITIALIZER;
111 pthread_cond_t condGo = PTHREAD_COND_INITIALIZER;
112 pthread_mutex_t mutexGo = PTHREAD_MUTEX_INITIALIZER;
118 void set_WiFiConnectionType( WiFiConnectionTypeCode_t value);
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 );
129 static void logs_Period1_Params();
130 static void logs_Period2_Params();
133 #ifdef ENABLE_NLMONITOR
134 #include "netlinkifc.h"
135 #endif //ENABLE_NLMONITOR
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"
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
151 SsidSecurity securityMode;
152 const char *modeString;
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" },
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" },
193 #ifdef ENABLE_RTMESSAGE
194 void rtConnection_init()
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);
206 void rtConnection_destroy()
208 rtConnection_Destroy(con_recv);
211 void onMessage(rtMessageHeader
const* hdr, uint8_t
const* buff, uint32_t n,
void* closure)
213 rtConnection con_recv = (rtConnection) closure;
216 rtMessage_FromBytes(&req, buff, n);
218 if (rtMessageHeader_IsRequest(hdr))
221 uint32_t buff_length = 0;
223 rtMessage_ToString(req, &buff, &buff_length);
224 rtLog_Info(
"Req : %.*s", buff_length, buff);
229 rtMessage_Create(&res);
230 rtMessage_SetString(res,
"reply",
"Success");
231 rtConnection_SendResponse(con_recv, hdr, res, 1000);
232 rtMessage_Release(res);
234 rtMessage_Release(req);
237 void onConnectWifi(rtMessageHeader
const* hdr, uint8_t
const* buff, uint32_t n,
void* closure)
241 rtConnection con_recv = (rtConnection) closure;
244 char const* ap_SSID = NULL;
245 int32_t securityMode = 0;
246 char const* ap_security_PreSharedKey = NULL;
251 rtMessage_FromBytes(&req, buff, n);
253 if (rtMessageHeader_IsRequest(hdr))
256 uint32_t buff_length = 0;
257 char jbuff[MAX_SSIDLIST_BUF] = {
'\0'};
260 rtMessage_ToString(req, &buff, &buff_length);
261 rtLog_Info(
"Req : %.*s", buff_length, buff);
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);
269 #ifdef USE_RDK_WIFI_HAL
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);
281 while (
false == isWifiConnected() && retry <= WIFI_CONNECT_TIME)
283 LOG_INFO(
"Waiting for wifi connection");
288 if (
true == isWifiConnected())
290 LOG_INFO(
"Wifi connection success");
293 else if (retry >= WIFI_CONNECT_TIME)
295 LOG_INFO(
"Wifi connection time out");
301 rtMessage_Create(&res);
302 rtMessage_SetInt32(res,
"reply", retVal);
303 rtConnection_SendResponse(con_recv, hdr, res, 1000);
304 rtMessage_Release(res);
306 rtMessage_Release(req);
309 void* rtMessage_Receive(
void*)
314 rtError err = rtConnection_Dispatch(con_recv);
317 LOG_DBG(
"Dispatch Error: %s", rtStrError(err));
326 #ifdef USE_RDK_WIFI_HAL
329 if(wifiHALVer[0] == 0)
331 wifi_getHalVersion(wifiHALVer);
332 LOG_INFO(
"[%s] WiFi HAL Version is %s",MODULE_NAME, wifiHALVer);
338 SsidSecurity get_wifiSecurityModeFromString(
char *secModeString,
char *encryptionType)
340 if (!secModeString || !encryptionType)
342 LOG_ERR(
"[%s] Failed due to NULL.", MODULE_NAME);
343 return NET_WIFI_SECURITY_NONE;
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))
352 for (
int i = 0; i < len; i++)
354 if (strcasestr(secModeString, wifi_securityModesMap_Netapp[i].modeString))
355 return wifi_securityModesMap_Netapp[i].securityMode;
361 for (
int i = len-1; i >= 0; i--)
363 if (strcasestr(secModeString, wifi_securityModesMap[i].modeString))
365 if (strcasestr(encryptionType,
"AES") || strcasestr(secModeString,
"WEP"))
366 return wifi_securityModesMap[i].securityMode;
368 return wifi_securityModesMap[i-1].securityMode;
372 return NET_WIFI_SECURITY_NOT_SUPPORTED;
375 int get_int(
const char* ptr)
377 int *ret = (
int *)ptr;
381 bool get_boolean(
const char *ptr)
383 bool *ret = (
bool *)ptr;
389 if(access(
"/tmp/wifi-on", F_OK ) != -1 )
395 unsigned long getUptimeMS(
void)
397 std::ifstream file(
"/proc/uptime");
401 file.getline(buffer,
sizeof buffer - 1);
403 double uptime = atof(buffer);
409 void logMilestone(
const char *msg_code)
412 fp = fopen(
"/opt/logs/rdk_milestones.log",
"a+");
415 fprintf(fp,
"%s:%ld\n", msg_code, getUptimeMS());
421 static IARM_Result_t WiFi_IARM_Bus_BroadcastEvent(
const char *ownerName, IARM_EventId_t eventId,
void *data,
size_t len)
425 return IARM_RESULT_SUCCESS;
428 bool getMfrData(GString* mfrDataStr,mfrSerializedType_t mfrType)
432 IARM_Result_t iarmRet = IARM_RESULT_IPCCORE_FAIL;
434 memset(¶m, 0,
sizeof(param));
435 param.
type = mfrType;
437 if(iarmRet == IARM_RESULT_SUCCESS)
441 LOG_TRACE(
"[%s] serialized data %s for mfrtype %d", MODULE_NAME, param.
buffer,mfrType );
442 g_string_assign(mfrDataStr,param.
buffer);
447 LOG_ERR(
"[%s] serialized data is empty for mfrtype %d ",MODULE_NAME, mfrType );
454 LOG_ERR(
"[%s] IARM CALL failed for mfrtype %d",MODULE_NAME, mfrType );
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);
472 return gWifiAdopterStatus;
475 static bool get_WiFiStatusCodeAsString (
WiFiStatusCode_t code,
char*
string)
480 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"UNINSTALLED");
483 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"DISABLED");
486 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"DISCONNECTED");
489 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"PAIRING");
492 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"CONNECTING");
495 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"CONNECTED");
498 STRCPY_S (
string, MAX_WIFI_STATUS_STRING,
"FAILED");
506 #ifdef ENABLE_LOST_FOUND
509 return gWifiLNFStatus;
514 strncpy(curSSIDConnInfo->ssidSession.ssid, wifiConnData.ssid, SSID_SIZE);
515 curSSIDConnInfo->isConnected = (
WIFI_CONNECTED == get_WiFiStatusCode())?
true:
false;
522 status = get_WiFiStatusCode();
523 LOG_TRACE(
"[%s] Exit with state %d", MODULE_NAME, status );
527 void set_WiFiConnectionType( WiFiConnectionTypeCode_t value)
529 if(value < 0 || value > WIFI_CON_MAX)
531 LOG_ERR(
"[%s] Trying to set invalid Wifi Connection Type %d ", MODULE_NAME, value );
535 if(gWifiConnectionType != value)
536 LOG_ERR(
"[%s] Wifi Connection Type changed to %d ..", MODULE_NAME, value );
538 gWifiConnectionType = value;
543 return gWifiConnectionType;
546 #ifdef USE_HOSTIF_WIFI_HAL
556 strncpy(wifiParam.
paramName, WIFI_SSID_ENABLE_PARAM, strlen(WIFI_SSID_ENABLE_PARAM) +1);
558 wifiParam.
paramtype = hostIf_BooleanType;
560 memset(&gSsidList,
'\0',
sizeof(
ssidList));
561 ret = gpvFromTR069hostif(&wifiParam);
565 bool ssidStatus = get_boolean(wifiParam.
paramValue);
567 LOG_DBG(
"[%s] Retrieved values from tr69hostif as \'%s\':\'%d\'.", MODULE_NAME, WIFI_SSID_ENABLE_PARAM, ssidStatus);
573 strncpy(wifiParam.
paramName, WIFI_SSID_NAME_PARAM, strlen(WIFI_SSID_NAME_PARAM) +1);
576 ret = gpvFromTR069hostif(&wifiParam);
580 strncpy(gSsidList.ssid, wifiParam.
paramValue,
sizeof(gSsidList.ssid));
585 strncpy(wifiParam.
paramName, WIFI_SSID_BSSID_PARAM, strlen(WIFI_SSID_BSSID_PARAM) +1);
588 ret = gpvFromTR069hostif(&wifiParam);
592 strncpy(gSsidList.bssid, wifiParam.
paramValue,
sizeof(gSsidList.bssid));
596 gSsidList.frequency = -1;
597 gSsidList.signalstrength = -1;
603 LOG_INFO(
"[%s] WiFi is disabled. [\'%s\':%d] ", MODULE_NAME, WIFI_SSID_ENABLE_PARAM, ssidStatus);
622 IARM_Result_t ret = IARM_RESULT_IPCCORE_FAIL;
632 if(ret != IARM_RESULT_SUCCESS)
634 LOG_FATAL(
"[%s] Failed with returned \'%d\' for '\%s\''.", MODULE_NAME, ret, param->paramName);
640 ret = IARM_RESULT_SUCCESS;
641 LOG_DBG(
"[%s] Successfully returned the value of \'%s\'.", MODULE_NAME, param->paramName);
651 char buff[512] = {
'\0'};
657 if(!(in = popen(
"wpa_cli status | grep -i '^ssid' | cut -d = -f 2",
"r")))
659 LOG_FATAL(
"[%s] Failed to read wpa_cli status.", MODULE_NAME);
663 if(fgets(buff,
sizeof(buff), in)!=NULL)
665 LOG_DBG(
"[%s] SSID: %s", MODULE_NAME, buff);
666 size_t len = strlen(buff);
667 if (len > 0 && buff[len-1] ==
'\n') {
670 strncpy(curSSIDConnInfo->ssidSession.ssid, buff, SSID_SIZE);
671 curSSIDConnInfo->isConnected =
true;
674 LOG_FATAL(
"[%s] Failed to get SSID.", MODULE_NAME);
680 curSSIDConnInfo->isConnected =
false;
688 char buff[512] = {
'\0'};
692 if(!(in = popen(
"wpa_cli status | grep -i wpa_state | cut -d = -f 2",
"r")))
694 LOG_ERR(
"[%s] Failed to read wpa_cli status.", MODULE_NAME);
698 char* c = fgets(buff,
sizeof(buff), in);
704 LOG_ERR(
"[%s] Failed to get State.", MODULE_NAME);
708 LOG_INFO(
"[%s] State: %s", MODULE_NAME, buff);
714 if (0 == strncasecmp(buff,
"SCANNING", strlen(
"SCANNING")))
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")))
726 else if (0 == strncasecmp(buff,
"COMPLETED", strlen(
"COMPLETED")))
730 else if (0 == strncasecmp(buff,
"INTERFACE_DISABLED", strlen(
"INTERFACE_DISABLED")))
739 #ifdef USE_RDK_WIFI_HAL
742 bool connect_WpsPush()
754 memset(&eventData, 0,
sizeof(eventData));
776 set_WiFiConnectionType(WIFI_CON_WPS);
782 LOG_INFO(
"[%s] Successfully called \"wifi_setCliWpsButtonPush(%d)\"; WPS Push button Success with status code (%d) ", MODULE_NAME, ssidIndex, wpsStatus);
792 LOG_ERR(
"[%s] Failed in \"wifi_setCliWpsButtonPush(%d)\", WPS Push button press failed with status code (%d) ", MODULE_NAME, ssidIndex, wpsStatus);
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));
805 time_t start_time = time(NULL);
806 time_t timeout_period = start_time + confProp.wifiProps.max_timeout;
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);
811 while (start_time < timeout_period)
814 LOG_INFO(
"[%s] Successfully received Disconnect state \"%d\". ", MODULE_NAME, gWifiAdopterStatus);
815 set_WiFiConnectionType(WIFI_CON_WPS);
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);
823 remove(WIFI_BCK_FILENAME);
824 wifi_conn_type = WPS_PUSH_CONNECT;
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);
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);
842 LOG_INFO(
"[%s] Since failed to disconnect, so reconnecintg again. \"%d\". ", MODULE_NAME);
843 set_WiFiConnectionType(WIFI_CON_WPS);
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));
849 wifi_conn_type = WPS_PUSH_CONNECT;
860 static bool get_WpsPIN(
char *wps_pin)
866 GString *mfrSerialPin = g_string_new(NULL);
867 if (getMfrData(mfrSerialPin, mfrSERIALIZED_TYPE_WPSPIN))
869 snprintf(wps_pin, 8+1,
"%s", mfrSerialPin->str);
874 LOG_ERR(
"getting serialized pin from mfr failed.");
876 g_string_free(mfrSerialPin,
TRUE);
890 bool connect_WpsPin(
char *wps_pin)
897 LOG_DBG(
"wps_pin = %s", wps_pin);
899 if (0 == strcmp(wps_pin,
"xxxxxxxx") &&
false == get_WpsPIN(wps_pin))
906 for (
int i = 1; i <= 30 &&
WIFI_CONNECTED == get_WiFiStatusCode(); i++)
910 set_WiFiConnectionType(WIFI_CON_WPS);
915 LOG_INFO(
"wifi_setCliWpsEnrolleePin called successfully");
920 LOG_ERR(
"wifi_setCliWpsEnrolleePin returned %d", wpsStatus);
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));
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)
944 pthread_mutex_lock(&mutexAPDetails);
945 bsignalAPDetailsReady =
true;
946 if(0 == pthread_cond_signal(&condAPDetails))
948 apDetailsBuffLength = eventData->data.xupnpData.deviceInfoLength;
949 LOG_INFO(
"[%s] Signal to fetch the data from upnp %ld", MODULE_NAME, eventData->data.xupnpData.deviceInfoLength );
951 pthread_mutex_unlock(&mutexAPDetails);
959 void initializeDiscovery(
void)
964 void shutdownDiscovery(
void)
970 INT wifi_connect_callback(INT ssidIndex, CHAR *AP_SSID,
wifiStatusCode_t *connStatus)
975 wifi_status_action (connCode, AP_SSID, (
unsigned short) ACTION_ON_CONNECT);
980 INT wifi_disconnect_callback(INT ssidIndex, CHAR *AP_SSID,
wifiStatusCode_t *connStatus)
985 wifi_status_action (connCode, AP_SSID, (
unsigned short)ACTION_ON_DISCONNECT);
990 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
991 bool parseAPDetails(
char *array)
999 cJSON *rootJson = cJSON_Parse(array);
1002 cJSON *deviceFullData = cJSON_GetObjectItem(rootJson,
"xmediagateways");
1006 guint deviceCount = cJSON_GetArraySize(deviceFullData);
1007 LOG_INFO(
"gateway count in json %d", deviceCount);
1008 char *devType, *devModel, *devMake, *devMACAddr;
1010 for (counter = 0; counter < deviceCount; counter++)
1012 cJSON *deviceData = cJSON_GetArrayItem(deviceFullData, counter);
1013 devType = devModel = devMake = devMACAddr = NULL;
1016 if(cJSON_GetObjectItem(deviceData,
"DevType"))
1017 devType = cJSON_GetObjectItem(deviceData,
"DevType")->valuestring;
1019 if(g_strrstr(g_strstrip(devType),
"XB"))
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;
1031 STRCPY_S(deviceModel,
sizeof(deviceModel), devModel);
1036 STRCPY_S(deviceMake,
sizeof(deviceMake), devMake);
1041 STRCPY_S(deviceMACAddr,
sizeof(deviceMACAddr), devMACAddr);
1044 LOG_INFO(
"[%s] Device Model: %s Device Make: %s MAC Addr: %s", MODULE_NAME, deviceModel, deviceMake, deviceMACAddr);
1049 LOG_ERR(
"[%s] not a valid XB device %s", MODULE_NAME, devType);
1052 LOG_ERR(
"[%s] Failed to get XB details", MODULE_NAME);
1059 LOG_INFO(
"[%s] No AP Details to parse gwcount", MODULE_NAME);
1061 cJSON_Delete(rootJson);
1071 LOG_ERR(
"[%s] Device list is empty", MODULE_NAME);
1079 bool getAPDetails(
unsigned int msgLength)
1082 IARM_Result_t ret = IARM_RESULT_SUCCESS;
1083 bool returnStatus = FALSE;
1085 char apDetails[msgLength + 1];
1086 memset(&apDetails, 0,
sizeof(apDetails));
1091 if(ret == IARM_RESULT_SUCCESS)
1098 if(ret == IARM_RESULT_SUCCESS)
1101 apDetails[param->bufLength] =
'\0';
1102 returnStatus =
TRUE;
1106 LOG_ERR(
"[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo IARM failed in the fetch ", MODULE_NAME);
1109 LOG_TRACE(
"[%s] apDetails %s", MODULE_NAME, apDetails);
1110 IARM_Free(IARM_MEMTYPE_PROCESSLOCAL, param);
1113 returnStatus = parseAPDetails(apDetails);
1117 LOG_ERR(
"[%s] IARM_BUS_XUPNP_API_GetXUPNPDeviceInfo , IARM_Malloc Failed ", MODULE_NAME);
1121 return returnStatus;
1124 void* getAPMakeAndModel(
void *arg)
1131 while (!bShutdownWifi) {
1132 pthread_mutex_lock(&mutexAPDetails);
1133 while(bsignalAPDetailsReady ==
false) {
1134 pthread_cond_wait(&condAPDetails, &mutexAPDetails);
1137 LOG_DBG(
"[%s] ***** Started fetching device data from upnp msg len = %d ***** ", MODULE_NAME, apDetailsBuffLength);
1139 msgLength = apDetailsBuffLength;
1140 bsignalAPDetailsReady =
false;
1141 ret = getAPDetails(msgLength);
1142 pthread_mutex_unlock(&mutexAPDetails);
1144 if(ret && strlen(deviceModel) > 0 && strlen(deviceMake) > 0)
1146 shutdownDiscovery();
1155 void collectAPDetails(
void)
1157 pthread_attr_t attr;
1159 pthread_attr_init(&attr);
1160 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1161 pthread_create(&apDetailsCollectionThread, &attr, getAPMakeAndModel, NULL);
1165 void wifi_status_action (
wifiStatusCode_t connCode,
char *ap_SSID,
unsigned short action)
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;
1177 bool notify =
false;
1178 int xreReconnectReason=0;
1179 memset(&eventData, 0,
sizeof(eventData));
1184 if ((strcmp(savedWiFiConnList.ssidSession.ssid,
"") != 0) && (strcmp(savedWiFiConnList.ssidSession.ssid, ap_SSID) != 0))
1190 LOG_INFO(
"[%s] Successfully %s to AP %s.", MODULE_NAME, connStr, ap_SSID);
1191 if (ACTION_ON_CONNECT == action) {
1196 #ifdef ENABLE_LOST_FOUND
1197 if (! laf_is_lnfssid(ap_SSID))
1198 #endif //ENABLE_LOST_FOUND
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)
1204 #ifdef ENABLE_LOST_FOUND
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;
1209 if(
false == setHostifParam(XRE_REFRESH_SESSION_WITH_RR ,hostIf_IntegerType ,(
void *)&xreReconnectReason))
1211 LOG_ERR(
"refresh xre session failed .");
1213 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 not enabled
1214 #ifdef ENABLE_NLMONITOR
1215 char const* intface=getenv(
"WIFI_INTERFACE");
1218 std::string ifcStr(intface);
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)
1227 v_secure_system(
"/lib/rdk/enableIpv6Autoconf.sh %s &", ifcStr.c_str());
1229 std::string enableV6 =
"/lib/rdk/enableIpv6Autoconf.sh ";
1232 system(enableV6.c_str());
1237 LOG_ERR(
"No WiFi interface .");
1239 #endif //ENABLE_LOST_FOUND
1245 if(
false == setHostifParam(XRE_REFRESH_SESSION ,hostIf_BooleanType ,(
void *)¬ify))
1247 LOG_ERR(
"[%s] refresh xre session failed .", MODULE_NAME);
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)
1256 #if !defined(XHB1) && !defined(XHC3)
1259 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:wifi_addr_reset.sh");
1261 v_secure_system(
"/bin/sh /lib/rdk/wifi_addr_reset.sh");
1263 system(
"/bin/sh /lib/rdk/wifi_addr_reset.sh");
1269 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:triggerDhcpReleaseAndRenew");
1270 netSrvMgrUtiles::triggerDhcpReleaseAndRenew(getenv(
"WIFI_INTERFACE"));
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))
1280 logMilestone(
"PWIFI_CONNECTED");
1281 isLAFCurrConnectedssid=
false;
1282 gWifiLNFStatus=CONNECTED_PRIVATE;
1283 if(bStopLNFWhileDisconnected)
1286 bStopLNFWhileDisconnected=
false;
1288 retVal = lastConnectedSSID(&savedWiFiConnList);
1290 LOG_ERR(
"[%s] Last connected ssid fetch failure ", MODULE_NAME);
1291 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
1296 LOG_INFO(
"[%s] Connecting private ssid. Bouncing xre connection.", MODULE_NAME);
1297 xreReconnectReason = 21;
1298 if(
false == setHostifParam(XRE_REFRESH_SESSION_WITH_RR ,hostIf_IntegerType ,(
void *)&xreReconnectReason))
1300 LOG_ERR(
"refresh xre session failed .");
1304 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:CONNECTED,%s", ap_SSID);
1310 memset(&deviceModel, 0,
sizeof(deviceModel));
1311 memset(&deviceMake, 0,
sizeof(deviceMake));
1312 memset(&deviceMACAddr, 0,
sizeof(deviceMACAddr));
1314 initializeDiscovery();
1317 if(!strlen(deviceModel) && !strlen(deviceMake))
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);
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);
1325 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 not enabled
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)
1337 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 not enabled
1341 #endif // ENABLE_LOST_FOUND
1347 eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1349 LOG_DBG(
"[%s] Notification on 'onWIFIStateChanged' with state as \'CONNECTED\'(%d).", MODULE_NAME,
WIFI_CONNECTED);
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 );
1357 pthread_mutex_unlock(&mutexGo);
1364 }
else if (ACTION_ON_DISCONNECT == action) {
1366 memset(&wifiConnData,
'\0',
sizeof(wifiConnData));
1367 strncpy(wifiConnData.ssid, ap_SSID,
sizeof(wifiConnData.ssid));
1368 wifiConnData.ssid[SSID_SIZE-1] =
'\0';
1372 eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1374 LOG_DBG(
"[%s] Notification on 'onWIFIStateChanged' with state as \'DISCONNECTED\'(%d).", MODULE_NAME,
WIFI_DISCONNECTED);
1376 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_DISCONNECTED");
1380 LOG_INFO(
"[%s] Connecting to AP in Progress...", MODULE_NAME);
1384 eventId = IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged;
1386 LOG_DBG(
"[%s] Notification on 'onWIFIStateChanged' with state as \'CONNECTING\'(%d).", MODULE_NAME,
WIFI_CONNECTING);
1391 if(connCode_prev_state != connCode) {
1394 LOG_INFO(
"[%s] Disconnecting from AP in Progress...", MODULE_NAME);
1399 if(connCode_prev_state != connCode) {
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;
1405 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'NO_SSID\'(%d), CurrentState set as %d (DISCONNECTED)", \
1409 #ifdef ENABLE_LOST_FOUND
1411 if(confProp.wifiProps.bEnableLostFound)
1413 bPrivConnectionLost=
true;
1414 lnfConnectPrivCredentials();
1416 #endif // ENABLE_LOST_FOUND
1421 LOG_ERR(
"[%s] Failed in %s with wifiStatusCode %d (i.e., Timeout expired). ", MODULE_NAME, connStr, connCode);
1423 if(connCode_prev_state != connCode) {
1426 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1428 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'FAILED\'(%d).", \
1429 MODULE_NAME,eventId, eventData.data.wifiError.code);
1436 if(connCode_prev_state != connCode) {
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;
1442 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'CONNECTION_LOST\'(%d).", \
1443 MODULE_NAME, eventId, eventData.data.wifiError.code);
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
1457 #ifdef ENABLE_LOST_FOUND
1458 if(confProp.wifiProps.bEnableLostFound)
1460 bPrivConnectionLost=
true;
1461 lnfConnectPrivCredentials();
1463 #endif //ENABLE_LOST_FOUND
1466 eventId = IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged;
1467 LOG_INFO(
"[%s] Notification on 'onSSIDsChanged (%d)'.", MODULE_NAME, eventId);
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);
1473 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1475 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'SSID_CHANGED\'(%d).", \
1476 MODULE_NAME, eventId, eventData.data.wifiError.code);
1478 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_SSID_CHANGED");
1483 if(connCode_prev_state != connCode) {
1484 LOG_ERR(
"[%s] Failed due to CONNECTION LOST (%d) from %s.", MODULE_NAME, connCode, ap_SSID);
1488 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1490 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'CONNECTION_LOST\'(%d).", \
1491 MODULE_NAME,eventId, eventData.data.wifiError.code);
1493 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_CONNECTION_LOST");
1498 if(connCode_prev_state != connCode)
1500 LOG_ERR(
"[%s] Connection Failed (%d) due to unknown reason.. ", MODULE_NAME, connCode );
1504 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1506 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'CONNECTION_FAILED\'(%d).", \
1507 MODULE_NAME,eventId, eventData.data.wifiError.code);
1509 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_CONNECTION_FAILED");
1514 if(connCode_prev_state != connCode) {
1515 LOG_ERR(
"[%s] Failed due to Connection Interrupted (%d).", MODULE_NAME, connCode );
1519 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1521 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'CONNECTION_INTERRUPTED\'(%d).", \
1522 MODULE_NAME,eventId, eventData.data.wifiError.code);
1524 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_CONNECTION_INTERRUPTED");
1529 LOG_ERR(
"[%s] Failed due to Invalid Credentials. (%d). ", MODULE_NAME, connCode );
1531 #ifdef ENABLE_LOST_FOUND
1532 if(confProp.wifiProps.bEnableLostFound)
1534 bPrivConnectionLost=
true;
1535 lnfConnectPrivCredentials();
1537 #endif //ENABLE_LOST_FOUND
1540 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1542 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'INVALID_CREDENTIALS\'(%d)", \
1543 MODULE_NAME,eventId, eventData.data.wifiError.code);
1545 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_INVALID_CREDENTIALS");
1549 LOG_ERR(
"[%s] Failed due to Auth Failure (%d)", MODULE_NAME, connCode);
1551 #ifdef ENABLE_LOST_FOUND
1552 if (confProp.wifiProps.bEnableLostFound)
1554 bPrivConnectionLost =
true;
1555 lnfConnectPrivCredentials ();
1560 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1562 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'AUTH_FAILED\'(%d).",
1563 MODULE_NAME, eventId, eventData.data.wifiError.code);
1565 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_AUTH_FAILED");
1568 if(connCode_prev_state != connCode) {
1569 LOG_ERR(
"[%s] Failed due to UNRECOVERABLE ERROR. (%d).", MODULE_NAME, connCode );
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);
1578 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_UNRECOVERABLE_ERROR");
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 );
1588 eventId = IARM_BUS_WIFI_MGR_EVENT_onError;
1590 LOG_ERR(
"[%s] Notification on 'onError (%d)' with state as \'UNKNOWN\'(%d).", \
1591 MODULE_NAME, eventId, eventData.data.wifiError.code);
1593 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:DISCONNECTED,WIFI_HAL_ERROR_UNKNOWN");
1598 connCode_prev_state = connCode;
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);
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)
1622 set_WiFiConnectionType((WiFiConnectionTypeCode_t)conType);
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 );
1631 WiFi_IARM_Bus_BroadcastEvent(IARM_BUS_NM_SRV_MGR_NAME, (IARM_EventId_t) eventId, (
void *)&eventData,
sizeof(eventData));
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);
1639 LOG_ERR(
"[%s] Error in connecting to ssid %s",
1640 MODULE_NAME, ap_SSID);
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));
1655 bool scan_SpecificSSID_WifiAP(
char *buffer,
const char* SSID,
double freq_in)
1658 #ifndef ENABLE_XCAM_SUPPORT
1660 UINT ssid_ap_array_size = 0;
1661 WIFI_HAL_FREQ_BAND band = WIFI_HAL_FREQ_BAN_NONE;
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;
1671 bool ret = wifi_getSpecificSSIDInfo (SSID, band, &ssid_ap_array, &ssid_ap_array_size);
1673 LOG_INFO(
"[%s] wifi_get wifi_getSpecificSSIDInfo returned %d, neighbor_ap_array_size %d",
1674 MODULE_NAME, ret, ssid_ap_array_size);
1676 if ((
RETURN_OK != ret ) && ((NULL == ssid_ap_array) || (0 == ssid_ap_array_size)))
1679 cJSON *rootObj = cJSON_CreateObject();
1680 if (NULL == rootObj) {
1681 LOG_ERR(
"[%s] \'Failed to create root json object.", MODULE_NAME);
1685 cJSON *array_obj = NULL, *array_element = NULL;
1687 int signalStrength = 0;
1688 double frequency = 0;
1689 SsidSecurity encrptType = NET_WIFI_SECURITY_NONE;
1691 cJSON_AddItemToObject(rootObj,
"getAvailableSSIDsWithName", array_obj=cJSON_CreateArray());
1693 LOG_DBG(
"\n*********** Start: SSID Scan List **************** \n");
1694 for (
int index = 0; index < ssid_ap_array_size; index++ )
1696 ssid = ssid_ap_array[index].
ap_SSID;
1697 if (*ssid && (0 != strcmp (ssid, LNF_NON_SECURE_SSID)) && (0 != strcmp (ssid, LNF_SECURE_SSID)))
1700 frequency = strtod(ssid_ap_array[index].ap_OperatingFrequencyBand, NULL);
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 );
1705 if(0 == strcmp(wifiHALVer,WIFI_HAL_VERSION))
1708 encrptType = get_wifiSecurityModeFromString((
char *)ssid_ap_array[index].ap_EncryptionMode,NULL);
1712 encrptType = get_wifiSecurityModeFromString((
char *)ssid_ap_array[index].ap_SecurityModeEnabled,(
char *)ssid_ap_array[index].ap_EncryptionMode);
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);
1721 LOG_DBG(
"\n***********End: SSID Scan List **************** \n\n");
1723 bool result =
false;
1724 cJSON *ret_json = NULL;
1725 char *out = cJSON_PrintUnformatted(rootObj);
1729 if (NULL == (ret_json = cJSON_Parse (out)))
1731 LOG_ERR(
"scan_SpecificSSID_WifiAP query returned non-JSON value after cJSON_parse = [%s]. Error = [%s]",out, cJSON_GetErrorPtr());
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);
1740 cJSON_Delete(ret_json);
1746 LOG_ERR(
"scan_SpecificSSID_WifiAP query return SSID List is NULL");
1750 if(rootObj) cJSON_Delete(rootObj);
1754 LOG_DBG(
"[%s] malloc allocated = %d ", MODULE_NAME, malloc_usable_size(ssid_ap_array));
1755 free(ssid_ap_array);
1759 #else // ENABLE_XCAM_SUPPORT
1762 #endif // ENABLE_XCAM_SUPPORT
1765 bool scan_Neighboring_WifiAP(
char *buffer)
1768 #ifdef ENABLE_LOST_FOUND
1772 LOG_ERR(
"Failed to Disconnect in wifi_disconnectEndpoint()");
1774 #endif //ENABLE_LOST_FOUND
1776 UINT neighbor_ap_array_size = 0;
1779 LOG_INFO(
"[%s] wifi_getNeighboringWiFiDiagnosticResult returned %d, neighbor_ap_array_size %d",
1780 MODULE_NAME, ret, neighbor_ap_array_size);
1782 if ((
RETURN_OK != ret ) && ((NULL == neighbor_ap_array) || (0 == neighbor_ap_array_size)))
1785 cJSON *rootObj = cJSON_CreateObject();
1786 if (NULL == rootObj) {
1787 LOG_ERR(
"[%s] \'Failed to create root json object.", MODULE_NAME);
1791 cJSON *array_obj = NULL, *array_element = NULL;
1793 int signalStrength = 0;
1794 double frequency = 0;
1795 SsidSecurity encrptType = NET_WIFI_SECURITY_NONE;
1797 cJSON_AddItemToObject(rootObj,
"getAvailableSSIDs", array_obj=cJSON_CreateArray());
1799 LOG_DBG(
"\n*********** Start: SSID Scan List **************** \n");
1800 for (
int index = 0; index < neighbor_ap_array_size; index++ )
1802 ssid = neighbor_ap_array[index].
ap_SSID;
1803 if (*ssid && (0 != strcmp (ssid, LNF_NON_SECURE_SSID)) && (0 != strcmp (ssid, LNF_SECURE_SSID)))
1806 frequency = strtod(neighbor_ap_array[index].ap_OperatingFrequencyBand, NULL);
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 );
1811 if(0 == strcmp(wifiHALVer,WIFI_HAL_VERSION))
1814 encrptType = get_wifiSecurityModeFromString((
char *)neighbor_ap_array[index].ap_EncryptionMode,NULL);
1818 encrptType = get_wifiSecurityModeFromString((
char *)neighbor_ap_array[index].ap_SecurityModeEnabled,(
char *)neighbor_ap_array[index].ap_EncryptionMode);
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);
1827 LOG_DBG(
"\n***********End: SSID Scan List **************** \n\n");
1829 bool result =
false;
1830 cJSON *ret_json = NULL;
1831 char *out = cJSON_PrintUnformatted(rootObj);
1836 if (NULL == (ret_json = cJSON_Parse (out)))
1838 LOG_ERR(
"scan_Neighboring_WifiAP query returned non-JSON value after cJSON_parse = [%s]. Error = [%s]",out, cJSON_GetErrorPtr());
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);
1847 cJSON_Delete(ret_json);
1853 LOG_ERR(
"scan_Neighboring_WifiAP query return SSID List is NULL");
1858 cJSON_Delete(rootObj);
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);
1877 LOG_ERR(
"[%s] Error in getting last connected SSID ", MODULE_NAME);
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 ))
1889 LOG_TRACE(
"[%s] SECURITY_MODE_SAE", MODULE_NAME);
1890 ConnParams->ssidSession.security_mode=NET_WIFI_SECURITY_WPA3_SAE;
1892 else if (strcmp (ConnParams->ssidSession.security, SECURITY_MODE_WPA_EAP) == 0)
1894 LOG_TRACE(
"[%s] SECURITY_MODE_WPA_EAP", MODULE_NAME);
1895 ConnParams->ssidSession.security_mode=NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES;
1897 else if (ConnParams->ssidSession.security_WEPKey != NULL)
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;
1904 ConnParams->ssidSession.security_mode = NET_WIFI_SECURITY_WEP_64;
1909 LOG_TRACE(
"[%s] SECURITY_MODE_WPA_NONE", MODULE_NAME);
1910 ConnParams->ssidSession.security_mode=NET_WIFI_SECURITY_NONE;
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);
1924 bool isCapable =
false;
1925 unsigned long numRadioEntries = 0;
1926 #ifdef USE_RDK_WIFI_HAL
1929 numRadioEntries = 1;
1932 if(numRadioEntries) {
1939 #ifdef USE_RDK_WIFI_HAL
1941 unsigned int getWifiStatsLogInterval()
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, ¶meter))
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;
1955 LOG_ERR(
"getRFCParameter(%s) failed", parameter_name);
1957 LOG_INFO(
"Returning %u", wifi_stats_log_interval);
1958 return wifi_stats_log_interval;
1961 void *wifiConnStatusThread(
void* arg)
1968 char wifiStatusAsString[MAX_WIFI_STATUS_STRING];
1970 struct timespec condGoTimeout;
1972 pthread_mutex_lock(&mutexGo);
1973 pthread_cond_wait(&condGo, &mutexGo);
1974 pthread_mutex_unlock(&mutexGo);
1976 LOG_DBG(
"[%s] ***** Monitor activated by signal ***** ", MODULE_NAME);
1977 const int WIFI_STATS_LOG_INTERVAL = getWifiStatsLogInterval();
1979 while (!bShutdownWifi) {
1980 wifiStatusCode = get_WiFiStatusCode();
1982 if (get_WiFiStatusCodeAsString (wifiStatusCode, wifiStatusAsString)) {
1983 LOG_INFO(
"TELEMETRY_WIFI_CONNECTION_STATUS:%s", wifiStatusAsString);
1986 LOG_ERR(
"TELEMETRY_WIFI_CONNECTION_STATUS:Unmappable WiFi status code %d", wifiStatusCode);
1991 #if !defined (XHB1) && !defined (XHC3)
1995 #if !defined(ENABLE_XCAM_SUPPORT)
1996 if((strlen(deviceModel) > 0) && (strlen(deviceMake) > 0))
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);
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);
2009 logs_Period1_Params();
2010 logs_Period2_Params();
2013 pthread_mutex_lock(&mutexGo);
2014 clock_gettime(CLOCK_REALTIME, &condGoTimeout);
2015 condGoTimeout.tv_sec += WIFI_STATS_LOG_INTERVAL;
2017 while (!bShutdownWifi && ret != ETIMEDOUT) {
2018 ret = pthread_cond_timedwait(&condGo, &mutexGo, &condGoTimeout);
2020 pthread_mutex_unlock(&mutexGo);
2026 void monitor_WiFiStatus()
2028 bShutdownWifi =
false;
2029 pthread_attr_t attr;
2030 pthread_attr_init(&attr);
2031 pthread_create(&wifiStatusMonitorThread, &attr, wifiConnStatusThread, NULL);
2035 bool clearSSID_On_Disconnect_AP()
2039 char *ap_ssid = savedWiFiConnList.ssidSession.ssid;
2042 LOG_ERR(
"[%s] Failed to Disconnect in wifi_disconnectEndpoint() for AP : \"%s\".",\
2043 MODULE_NAME, ap_ssid);
2048 LOG_INFO(
"[%s] Successfully called \"wifi_disconnectEndpointd()\" for AP: \'%s\'. ",\
2049 MODULE_NAME, ap_ssid);
2050 #ifndef ENABLE_XCAM_SUPPORT
2052 if(wifi_clearSSIDInfo(radioIndex) ==
RETURN_OK) {
2053 LOG_INFO(
"[%s] Successfully cleared SSID info", MODULE_NAME);
2055 #endif // ENABLE_XCAM_SUPPORT
2058 #ifdef ENABLE_LOST_FOUND
2059 if (
false == isLAFCurrConnectedssid )
2060 #endif //ENABLE_LOST_FOUND
2062 memset(&savedWiFiConnList, 0 ,
sizeof(savedWiFiConnList));
2069 bool disconnectFromCurrentSSID()
2073 char *ap_ssid = savedWiFiConnList.ssidSession.ssid;
2077 LOG_ERR(
"[%s] Failed to Disconnect in wifi_disconnectEndpoint() for AP : \"%s\".",\
2078 MODULE_NAME, ap_ssid);
2083 LOG_INFO(
"[%s] Successfully called \"wifi_disconnectEndpointd()\" for AP: \'%s\'. ",\
2084 MODULE_NAME, ap_ssid);
2089 bool cancelWPSPairingOperation()
2092 #if !defined (ENABLE_XCAM_SUPPORT) && !defined (XHB1) && !defined(XHC3)
2093 if(wifi_cancelWpsPairing() ==
RETURN_OK)
2095 LOG_INFO(
"[%s] Successfully Cancelled WPS operation.", MODULE_NAME);
2099 LOG_ERR(
"[%s] Failed to Cancel WPS operation, Looks like no in-progress wps operation.", MODULE_NAME);
2102 #endif //ENABLE_LOST_FOUND
2113 memset(&stats,
'\0',
sizeof(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);
2122 strncpy((
char *)conSSIDInfo->
band,(
const char *)stats.
sta_BAND,(
size_t)BUFF_MIN);
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",
2134 #ifdef ENABLE_LOST_FOUND
2138 if (last_laf_status.backoff > 0.0f)
2140 struct timespec current_time;
2141 clock_gettime (CLOCK_MONOTONIC, ¤t_time);
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);
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;
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);
2154 usleep (seconds_remaining_to_wait * 1000000);
2158 LOG_INFO(
"[%s] backoff = 0s", MODULE_NAME);
2161 LOG_INFO(
"[%s] backoff wait done.", MODULE_NAME);
2164 bool triggerLostFound(LAF_REQUEST_TYPE lafRequestType)
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;
2179 ops = (laf_ops_t*) malloc(
sizeof(laf_ops_t));
2182 LOG_ERR(
"[%s] laf_ops malloc failed ", MODULE_NAME);
2185 dev_info = (laf_device_info_t*) malloc(
sizeof(laf_device_info_t));
2188 LOG_ERR(
"[%s] laf_device_info malloc failed ", MODULE_NAME);
2193 memset(dev_info,0,
sizeof(laf_device_info_t));
2194 memset(ops,0,
sizeof(laf_ops_t));
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;
2202 bRet = getDeviceInfo(dev_info);
2203 if (bRet ==
false) {
2204 LOG_ERR(
"[%s] getDeviceInfo failed", MODULE_NAME);
2207 err = laf_config_new(&conf, ops, dev_info);
2209 LOG_ERR(
"[%s] Lost and found client configurtion failed with error code %d ", MODULE_NAME, err );
2215 err = laf_client_new(&clnt, conf);
2217 LOG_ERR(
"[%s] Lost and found client initialization failed with error code %d", MODULE_NAME, err );
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)
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);
2234 LOG_ERR(
"[%s] Error in lost and found client, error code %d", MODULE_NAME, err );
2237 if(!bAutoSwitchToPrivateEnabled)
2239 if((!bRet) && (bLastLnfSuccess))
2241 LOG_INFO(
"[%s] !AutoSwitchToPrivateEnabled + lastLnfSuccessful + currLnfFailure = clr switch2prv Results ", MODULE_NAME);
2242 clearSwitchToPrivateResults();
2243 bLastLnfSuccess=
false;
2246 bLastLnfSuccess=
true;
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));
2258 laf_config_destroy(conf);
2261 laf_client_destroy(clnt);
2273 fd = socket(AF_INET, SOCK_DGRAM, 0);
2276 LOG_ERR(
"[%s] ERROR opening socket %d ", MODULE_NAME,fd );
2279 ifr.ifr_addr.sa_family = AF_INET;
2280 strncpy(ifr.ifr_name , ifname , IFNAMSIZ-1);
2281 ioRet=ioctl(fd, SIOCGIFHWADDR, &ifr);
2285 LOG_ERR(
"[%s] ERROR in ioctl function to retrieve mac address %d", MODULE_NAME, 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]);
2296 bool getDeviceInfo(laf_device_info_t *dev_info)
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;
2305 mfrType = mfrSERIALIZED_TYPE_SERIALNUMBER;
2306 if(partnerID && !partnerID[0])
2308 if(getDeviceActivationState() ==
false)
2310 LOG_ERR(
"[%s] Partner ID Missing in url May be not activated ", MODULE_NAME);
2314 g_stpcpy(dev_info->partnerId,partnerID);
2319 g_stpcpy(dev_info->partnerId,partnerID);
2321 if(getMfrData(mfrSerialNum,mfrType))
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);
2328 LOG_ERR(
"[%s] getting serial num from mfr failed ", MODULE_NAME);
2332 mfrType = mfrSERIALIZED_TYPE_DEVICEMAC;
2333 if(getMfrData(deviceMacAddr,mfrType))
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);
2341 LOG_ERR(
"[%s] getting device mac addr from mfr failed ", MODULE_NAME);
2345 mfrType = mfrSERIALIZED_TYPE_MODELNAME;
2346 if(getMfrData(mfrModelName,mfrType))
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);
2353 LOG_ERR(
"[%s] getting model name from mfr failed ", MODULE_NAME);
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");
2363 g_string_free(mfrSerialNum,
TRUE);
2364 g_string_free(mfrMake,
TRUE);
2365 g_string_free(mfrModelName,
TRUE);
2366 g_string_free(deviceMacAddr,
TRUE);
2371 #else // ENABLE_IARM
2373 #if defined (ENABLE_XCAM_SUPPORT) || defined (XHB1) || defined(XHC3)
2374 char* getlfatfilename()
2376 static char *lfat_file = NULL;
2377 lfat_file = getenv(
"LFAT_TOKEN_FILE");
2378 LOG_INFO(
"lfat file name=%s", lfat_file);
2382 int get_token_length(
unsigned int &tokenlength)
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");
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){
2406 int get_laf_token(
char* token,
unsigned int tokenlength)
2409 char* tokenfilename = getlfatfilename();
2411 fp_token = fopen(tokenfilename,
"rb");
2412 if(NULL == fp_token) {
2413 LOG_ERR(
"get_laf_token - Error in opening lfat token file");
2418 fread(token,tokenlength,1,fp_token);
2420 LOG_ERR(
"get_laf_token - Token NULL");
2422 if(NULL != fp_token){
2429 #endif // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
2431 #if defined(XHB1) || defined(XHC3)
2432 int getMfrDeviceInfo(mfrSerializedType_t stdatatype,
char* data)
2438 LOG_ERR(
"[%s] Accessing ivalid memory locatio", MODULE_NAME);
2444 strncpy(data,stdata.buf,stdata.bufLen);
2445 if (stdata.freeBuf != NULL)
2447 stdata.freeBuf(stdata.buf);
2453 LOG_ERR(
"[%s] Error retriving required device info.", MODULE_NAME);
2460 bool getDeviceInfo( laf_device_info_t *dev_info )
2463 unsigned int tokenlength=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))
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);
2478 LOG_ERR(
"[%s] rdkc_get_device_basic_info failed", MODULE_NAME);
2481 #elif defined(XHB1) || defined(XHC3)
2482 if(1 == getMfrDeviceInfo(mfrSERIALIZED_TYPE_SERIALNUMBER, dev_info->serial_num))
2484 LOG_ERR(
"[%s] Error reteiving device serial number.", MODULE_NAME);
2486 if(1 == getMfrDeviceInfo(mfrSERIALIZED_TYPE_MODELNAME, dev_info->model))
2488 LOG_ERR(
"[%s] Error reteiving device model", MODULE_NAME);
2491 if(1 == getMfrDeviceInfo(mfrSERIALIZED_TYPE_DEVICEMAC, dev_info->mac))
2493 LOG_ERR(
"[%s] Error reteiving device MAC.", MODULE_NAME);
2496 #if defined(ENABLE_XCAM_SUPPORT) || defined(XHB1) || defined(XHC3)
2497 int get_result = getSetFileContent(partnerIdFile,
"get", dev_info->partnerId);
2499 LOG_ERR(
"[%s] Error reteiving partnerId", MODULE_NAME);
2502 dev_info->partnerId[strcspn(dev_info->partnerId,
"\n")] = 0;
2503 LOG_DBG(
"[%s] PartnerID obtained is : %s", MODULE_NAME, dev_info->partnerId);
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 ");
2512 readtoken = get_laf_token(dev_info->auth_token,tokenlength);
2513 if(readtoken != 0 ) {
2514 LOG_ERR(
"[%s] getDeviceInfo - Token read error", MODULE_NAME);
2517 LOG_DBG(
"[%s] getDeviceInfo - token is : %s", MODULE_NAME, dev_info->auth_token);
2519 #endif // ENABLE_XCAM_SUPPORT, XHC3 and XHB1 defined
2523 #endif // ENABLE_IARM
2526 int laf_wifi_connect(laf_wifi_ssid_t*
const wificred)
2537 LOG_INFO(
"[%s] Already connected to LF ssid Ignoring the request", MODULE_NAME);
2540 if(bStopLNFWhileDisconnected)
2542 LOG_INFO(
"[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2545 if (laf_is_lnfssid(wificred->ssid))
2552 retVal=lastConnectedSSID(&savedWiFiConnList);
2553 if (retVal && savedWiFiConnList.ssidSession.ssid[0] !=
'\0')
2555 if((strcmp(wificred->ssid, savedWiFiConnList.ssidSession.ssid) != 0) && (strcmp(wificred->passphrase, savedWiFiConnList.ssidSession.passphrase) != 0))
2557 LOG_INFO(
"[%s] Lnf response status Credentials changed : BOTH", MODULE_NAME);
2559 else if(strcmp(wificred->ssid, savedWiFiConnList.ssidSession.ssid) != 0)
2561 LOG_INFO(
"[%s] Lnf response status Credentials changed : SSID", MODULE_NAME);
2563 else if(strcmp(wificred->passphrase, savedWiFiConnList.ssidSession.passphrase) != 0)
2565 LOG_INFO(
"[%s] Lnf response status Credentials changed : KeyPassphrase", MODULE_NAME);
2569 #ifdef USE_RDK_WIFI_HAL
2570 if(gWifiLNFStatus != CONNECTED_PRIVATE)
2575 LOG_ERR(
"Failed to Disconnect in wifi_disconnectEndpoint()");
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);
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 );
2590 if(bStopLNFWhileDisconnected)
2592 LOG_INFO(
"[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2596 LOG_TRACE(
"[%s] Device not connected to wifi. waiting to connect...", MODULE_NAME);
2598 if(retry > confProp.wifiProps.lnfRetryCount) {
2599 LOG_ERR(
"[%s] Waited for %d seconds. Failed to connect. Abort ", MODULE_NAME, confProp.wifiProps.lnfRetryCount);
2604 if(! laf_is_lnfssid(wificred->ssid))
2606 setLNFState(CONNECTED_PRIVATE);
2622 int laf_wifi_disconnect(
void)
2629 if (
false == isLAFCurrConnectedssid )
2631 LOG_INFO(
"[%s] Connected to private ssid Ignoring the request ", MODULE_NAME);
2634 if(bStopLNFWhileDisconnected)
2636 LOG_INFO(
"[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2639 #ifdef USE_RDK_WIFI_HAL
2640 char *ap_ssid = savedWiFiConnList.ssidSession.ssid;
2644 if(retVal ==
false) {
2645 LOG_ERR(
"[%s] Tried to disconnect before connect and it failed ", MODULE_NAME);
2650 if(bStopLNFWhileDisconnected)
2652 LOG_INFO(
"[%s] Already WPS flow has intiated so skipping the request the request", MODULE_NAME);
2655 LOG_TRACE(
"[%s] Device is connected to wifi. waiting to disconnect...", MODULE_NAME);
2660 LOG_ERR(
"[%s] Waited for 30seconds. Failed to disconnect. Abort", MODULE_NAME);
2676 rdklevel = RDK_LOG_DEBUG;
2679 rdklevel = RDK_LOG_INFO;
2681 case LAF_LOG_WARNING:
2682 rdklevel = RDK_LOG_WARN;
2685 rdklevel = RDK_LOG_ERROR;
2688 rdklevel = RDK_LOG_INFO;
2694 void log_message(laf_loglevel_t level,
char const*
function,
int line,
char const* msg)
2696 RDK_LOG( map_to_rdkloglevel(level), LOG_NMGR,
"[%s:%s:%s:%d] %s\n",MODULE_NAME,SUB_MODULE_NAME,
function, line, msg );
2701 if(gWifiLNFStatus != status)
2702 LOG_TRACE(
"[%s] LNF Status changed to %d", MODULE_NAME, status );
2704 gWifiLNFStatus = status;
2707 static void signalStartLAF()
2709 pthread_mutex_lock(&mutexLAF);
2711 LOG_DBG(
"[%s] Signal to start LAF private SSID ", MODULE_NAME);
2712 pthread_cond_signal(&condLAF);
2713 pthread_mutex_unlock(&mutexLAF);
2716 void *lafConnPrivThread(
void* arg)
2721 LAF_REQUEST_TYPE reqType;
2722 bool lnfReturnStatus=
false;
2727 pthread_mutex_lock(&mutexLAF);
2729 if (gWifiLNFStatus == CONNECTED_PRIVATE && gWifiAdopterStatus ==
WIFI_CONNECTED)
2731 while (
false == startLAF)
2732 pthread_cond_wait(&condLAF, &mutexLAF);
2734 pthread_mutex_unlock(&mutexLAF);
2736 LOG_DBG(
"[%s] Starting the LAF Connect private SSID",MODULE_NAME);
2739 LOG_INFO(
"[%s] WifiLNFStatus = %d .Setting LNF state as in progress.",MODULE_NAME, gWifiLNFStatus );
2742 if(bPrivConnectionLost)
2744 bPrivConnectionLost=
false;
2745 LOG_INFO(
"[%s] Wait for 10 sec before starting lost and found ", MODULE_NAME );
2750 #ifdef ENABLE_XCAM_SUPPORT
2751 if(rdkc_get_wifi_interface_status() == 3)
2753 LOG_INFO(
"Camera is connected to Y-CABLE. Aborting LNF ");
2758 if((bAutoSwitchToPrivateEnabled) || (bSwitch2Private))
2760 if(bSwitch2Private ==
true)
2762 reqType = LAF_REQUEST_SWITCH_TO_PRIVATE;
2763 bSwitch2Private=
false;
2767 reqType = LAF_REQUEST_CONNECT_TO_PRIV_WIFI;
2772 reqType = LAF_REQUEST_CONNECT_TO_LFSSID;
2775 if (
true == bStopLNFWhileDisconnected)
2777 LOG_INFO(
"stopLNFWhileDisconnected pressed coming out of LNF");
2782 if((gWifiAdopterStatus ==
WIFI_CONNECTED) && (
false == isLAFCurrConnectedssid))
2784 LOG_INFO(
"connection status %d is LAF current ssid %d ", gWifiAdopterStatus, isLAFCurrConnectedssid );
2785 setLNFState(CONNECTED_PRIVATE);
2789 bIsStopLNFWhileDisconnected=
false;
2790 pthread_mutex_lock(&mutexTriggerLAF);
2792 if ((gWifiLNFStatus == CONNECTED_PRIVATE) && (gWifiAdopterStatus ==
WIFI_CONNECTED))
2794 LOG_INFO(
"[%s] Connected to Private SSID already. Aborting requested LNF.", MODULE_NAME);
2795 pthread_mutex_unlock(&mutexTriggerLAF);
2802 lnfReturnStatus = triggerLostFound(reqType);
2804 pthread_mutex_unlock(&mutexTriggerLAF);
2805 if (
false == lnfReturnStatus)
2808 if (
true == bStopLNFWhileDisconnected)
2810 LOG_INFO(
"stopLNFWhileDisconnected pressed coming out of LNF" );
2816 retVal=lastConnectedSSID(&savedWiFiConnList);
2817 if (retVal && savedWiFiConnList.ssidSession.ssid[0] !=
'\0')
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);
2823 LOG_ERR(
"[%s] connect with ssid %s failed ", MODULE_NAME, savedWiFiConnList.ssidSession.ssid );
2828 LOG_ERR(
"[%s] Failed to get previous SSID, Manual connect failed. ", MODULE_NAME);
2830 if (last_laf_status.backoff == 0.0f)
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 );
2838 if (LAF_REQUEST_CONNECT_TO_LFSSID == reqType)
2841 LOG_TRACE(
"[%s] Connected to LNF",MODULE_NAME);
2845 if (gWifiLNFStatus == CONNECTED_PRIVATE)
2847 setLNFState(CONNECTED_PRIVATE);
2848 LOG_INFO(
"pressed coming out of LNF since box is connected to private ");
2854 }
while ((gWifiLNFStatus != CONNECTED_PRIVATE) && (bAutoSwitchToPrivateEnabled));
2855 bIsStopLNFWhileDisconnected=
true;
2860 void *lafConnThread(
void* arg)
2862 bool lnfReturnStatus=
false;
2865 while (
false == bDeviceActivated) {
2866 bLnfActivationLoop=
true;
2869 bIsStopLNFWhileDisconnected=
false;
2872 if (
false == isLAFCurrConnectedssid)
2874 setLNFState(CONNECTED_PRIVATE);
2875 LOG_INFO(
"[%s] Connected through non LAF path", MODULE_NAME);
2876 bIsStopLNFWhileDisconnected=
true;
2877 bLnfActivationLoop=
false;
2882 if (
true == bStopLNFWhileDisconnected)
2884 LOG_INFO(
"[%s] stopLNFWhileDisconnected pressed coming out of LNF", MODULE_NAME);
2885 bIsStopLNFWhileDisconnected=
true;
2886 bLnfActivationLoop=
false;
2890 #if defined(ENABLE_XCAM_SUPPORT) || defined(XHB1) || defined(XHC3)
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);
2900 pthread_mutex_lock(&mutexTriggerLAF);
2902 if (gWifiLNFStatus == CONNECTED_PRIVATE)
2904 LOG_INFO(
"[%s] Connected to Private SSID already. Aborting requested LNF.", MODULE_NAME);
2905 pthread_mutex_unlock(&mutexTriggerLAF);
2910 lnfReturnStatus = triggerLostFound(LAF_REQUEST_CONNECT_TO_LFSSID);
2912 pthread_mutex_unlock(&mutexTriggerLAF);
2913 if (
false == lnfReturnStatus)
2916 if (
true == bStopLNFWhileDisconnected)
2918 LOG_INFO(
"[%s] stopLNFWhileDisconnected pressed coming out of LNF ", MODULE_NAME);
2919 bIsStopLNFWhileDisconnected=
true;
2920 bLnfActivationLoop=
false;
2923 sleep(confProp.wifiProps.lnfRetryInSecs);
2929 LOG_DBG(
"[%s] Connection to LAF success", MODULE_NAME);
2933 bIsStopLNFWhileDisconnected=
false;
2935 if((gWifiLNFStatus != CONNECTED_PRIVATE) && (
false == isLAFCurrConnectedssid) && (gWifiAdopterStatus ==
WIFI_CONNECTED))
2937 LOG_INFO(
"[%s] isLAFCurrConnectedssid = %d gWifiAdopterStatus = %d", MODULE_NAME,isLAFCurrConnectedssid,gWifiAdopterStatus );
2938 gWifiLNFStatus=CONNECTED_PRIVATE;
2940 if (
true == bStopLNFWhileDisconnected)
2942 LOG_INFO(
"[%s] stopLNFWhileDisconnected pressed coming out of LNF ", MODULE_NAME);
2943 bLnfActivationLoop=
false;
2948 bLnfActivationLoop=
false;
2951 bPrivConnectionLost=
false;
2952 lnfConnectPrivCredentials();
2958 static void* startLAFIfNecessary(
void* arg)
2960 lastConnectedSSID(&savedWiFiConnList);
2961 if (savedWiFiConnList.ssidSession.ssid[0] !=
'\0')
2963 sleep(confProp.wifiProps.lnfStartInSecs);
2964 lastConnectedSSID(&savedWiFiConnList);
2970 LOG_DBG(
"[%s] Now connected to Private SSID %s", MODULE_NAME, savedWiFiConnList.ssidSession.ssid);
2974 if(IARM_BUS_SYS_MODE_WAREHOUSE != sysModeParam)
2978 bPrivConnectionLost=
true;
2986 LOG_DBG(
"[%s] Enter", MODULE_NAME );
2987 pthread_attr_t attr;
2988 if((getDeviceActivationState() ==
false)
2990 && (IARM_BUS_SYS_MODE_WAREHOUSE != sysModeParam)
2994 pthread_attr_init(&attr);
2995 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
2996 pthread_create(&lafConnectThread, &attr, lafConnThread, NULL);
3001 #ifdef ENABLE_XCAM_SUPPORT
3003 WiFiHalStatus_t wifistatus = getwifiStatusCode();
3004 if( WIFISTATUS_HAL_COMPLETED == wifistatus ) {
3007 pthread_mutex_lock(&mutexGo);
3008 if(0 == pthread_cond_signal(&condGo)) {
3009 LOG_INFO(
"[%s] Broadcast to monitor.", MODULE_NAME);
3011 pthread_mutex_unlock(&mutexGo);
3015 #elif defined(XHB1) || defined(XHC3)
3018 pthread_mutex_lock(&mutexGo);
3019 if(0 == pthread_cond_signal(&condGo)) {
3020 LOG_INFO(
"[%s] Broadcast to monitor.", MODULE_NAME);
3022 pthread_mutex_unlock(&mutexGo);
3025 pthread_attr_init(&attr);
3026 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
3027 pthread_create(&t, &attr, startLAFIfNecessary, NULL);
3031 void lafConnectToPrivate()
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);
3042 char lafSsid[SSID_SIZE];
3044 memset(lafSsid, 0, SSID_SIZE);
3045 laf_get_lfssid(lafSsid);
3048 LOG_TRACE(
"[%s] lfssid is %s", MODULE_NAME, lafSsid);
3053 LOG_ERR(
"[%s] lfssid is empty ", MODULE_NAME);
3058 bool isLAFCurrConnectedssid()
3062 if(laf_is_lnfssid(savedWiFiConnList.ssidSession.ssid))
3064 LOG_TRACE(
"[%s] LAF is the current connected ssid ", MODULE_NAME);
3076 bool getDeviceActivationState()
3078 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3079 char scriptOutput[BUFFER_SIZE_SCRIPT_OUTPUT] = {
'\0'};
3080 unsigned int count=0;
3083 while(deviceID && !deviceID[0])
3085 if (access(SCRIPT_FILE_TO_GET_DEVICE_ID, F_OK ) != -1)
3089 LOG_ERR(
"[%s] Error in running device id script.", MODULE_NAME);
3090 return bDeviceActivated;
3092 g_stpcpy(deviceID,scriptOutput);
3096 if(! confProp.wifiProps.authServerURL)
3098 LOG_ERR(
"[%s] Authserver URL is NULL", MODULE_NAME);
3099 return bDeviceActivated;
3101 str.assign(confProp.wifiProps.authServerURL,strlen(confProp.wifiProps.authServerURL));
3103 g_stpcpy(deviceID,authServiceURL.getCurlData());
3105 if ((!deviceID && deviceID[0]) || (count >= 3))
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);
3114 for (loopvar=0; loopvar<tokLength; loopvar++)
3116 if (g_strrstr(g_strstrip(tokens[loopvar]),
"deviceId"))
3119 if ((loopvar+3) < tokLength )
3121 g_stpcpy(deviceID, g_strstrip(tokens[loopvar+3]));
3122 if(deviceID[0] !=
'\0')
3124 bDeviceActivated =
true;
3129 for (loopvar=0; loopvar<tokLength; loopvar++)
3131 if (g_strrstr(g_strstrip(tokens[loopvar]),
"partnerId"))
3134 if ((loopvar+3) < tokLength )
3136 g_stpcpy(partnerID, g_strstrip(tokens[loopvar+3]));
3137 if(partnerID[0] !=
'\0')
3139 LOG_INFO(
"[%s] partner id is %s", MODULE_NAME, partnerID);
3147 return bDeviceActivated;
3150 #endif // ENABLE_XCAM_SUPPORT and XHB1 and XHC3
3152 bool isWifiConnected()
3157 void lnfConnectPrivCredentials()
3160 if(bLnfActivationLoop)
3162 LOG_DBG(
"[%s] Still in LnF Activation Loop so discarding getting private credentials",MODULE_NAME);
3168 #endif // ENABLE_LOST_FOUND
3173 IARM_Result_t ret = IARM_RESULT_IPCCORE_FAIL;
3174 bool retValue=
false;
3178 if(NULL == name || value == NULL) {
3179 LOG_ERR(
"[%s] Null pointer caught for Name/Value", MODULE_NAME );
3184 strncpy(param.
paramName, name, strlen(name)+1);
3188 case hostIf_StringType:
3189 case hostIf_DateTimeType:
3195 case hostIf_IntegerType:
3196 case hostIf_UnsignedIntType:
3199 case hostIf_BooleanType:
3211 if(ret != IARM_RESULT_SUCCESS) {
3212 LOG_ERR(
"[%s] Error executing Set parameter call from tr69Client, error code",MODULE_NAME);
3216 LOG_DBG(
"[%s] sent iarm message to set hostif parameter",MODULE_NAME);
3222 #endif // ENABLE_IARM
3226 bool *tmp = (
bool *)ptr;
3232 int *tmp = (
int *)ptr;
3237 bool connectToMfrWifiCredentials()
3244 param.requestType=WIFI_GET_CREDENTIALS;
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);
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);
3258 LOG_INFO(
"[%s] IARM failure in retrieving the stored wifi credentials", MODULE_NAME);
3267 #ifdef USE_RDK_WIFI_HAL
3271 retVal=lastConnectedSSID(&savedWiFiConnList);
3274 LOG_ERR(
"[%s] Last connected ssid fetch failure", MODULE_NAME);
3280 LOG_TRACE(
"[%s] fetched ssid details %s ",MODULE_NAME,savedWiFiConnList.ssidSession.ssid);
3282 param.requestType=WIFI_GET_CREDENTIALS;
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) )
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);
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);
3300 memset(¶m,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;
3307 LOG_TRACE(
"[%s] IARM success in storing wifi credentials",MODULE_NAME);
3308 memset(¶m,0,
sizeof(param));
3309 param.requestType=WIFI_GET_CREDENTIALS;
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) )
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);
3322 LOG_ERR(
"[%s] failure in storing wifi credentials",MODULE_NAME);
3328 LOG_ERR(
"[%s] IARM error in retrieving stored wifi credentials mfr error code %d ",MODULE_NAME,param.returnVal );
3333 LOG_ERR(
"[%s] IARM error in storing wifi credentials mfr error code %d", MODULE_NAME, param.returnVal);
3335 #endif // ENABLE_IARM
3336 #endif // USE_RDK_WIFI_HAL
3345 #ifdef USE_RDK_WIFI_HAL
3350 LOG_TRACE(
"[%s] IARM success in erasing wifi credentials ",MODULE_NAME);
3355 LOG_ERR(
"[%s] failure in erasing wifi credentials ",MODULE_NAME);
3368 #ifdef USE_RDK_WIFI_HAL
3370 memset(&stats,
'\0',
sizeof(stats));
3374 bool enable = (
WIFI_CONNECTED == get_WiFiStatusCode())?
true:
false;
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);
3381 endPointInfo->stats.signalStrength = stats.
sta_RSSI;
3389 strncpy((
char *)endPointInfo->status,
"Disabled", (
size_t)BUFF_LENGTH_64);
3390 endPointInfo->enable = enable;
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);
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
3406 #ifdef USE_RDK_WIFI_HAL
3407 #ifdef WIFI_CLIENT_ROAMING
3408 bool getRoamingConfigInfo(WiFi_RoamingCtrl_t *param)
3411 bool retStatus =
false;
3413 memset(&out_param,0,
sizeof(out_param));
3414 int status = wifi_getRoamingControl(ssidIndex,&out_param);
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;
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);
3432 }
else if(status == -1) {
3433 param->status = ROAM_PARAM_FAILURE;
3434 }
else if(status == -2) {
3435 param->status = ROAM_PARAM_DISABLED;
3437 param->status = ROAM_PARAM_FAILURE;
3442 bool setRoamingConfigInfo(WiFi_RoamingCtrl_t *param)
3445 bool retStatus =
false;
3447 memset(&in_param,0,
sizeof(in_param));
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;
3459 in_param.postAssnAPctrlThreshold = param->postAssnAPcontrolThresholdLevel;
3460 in_param.postAssnAPctrlTimeframe = param->postAssnAPcontrolTimeframe;
3461 in_param.roam80211kvrEnable = param->roaming80211kvrEnable;
3463 int status = wifi_setRoamingControl(ssidIndex,&in_param);
3465 param->status = ROAM_PARAM_SUCCESS;
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;
3473 param->status = ROAM_PARAM_FAILURE;
3484 if(trafficStats == NULL)
3486 LOG_TRACE(
"[%s]Malloc Memory allocation failure", MODULE_NAME);
3489 printf(
"malloc allocated = %d ", malloc_usable_size(trafficStats));
3508 LOG_ERR(
"[%s] HAL wifi_getRadioTrafficStats FAILURE", MODULE_NAME);
3516 void logs_Period1_Params()
3519 if(NULL != wifiParams_Tele_Period1.paramlist)
3526 GList *iter = g_list_first(wifiParams_Tele_Period1.paramlist);
3531 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"LastDataDownlinkRate")) {
3532 LOG_INFO(
"%s:%lu ", (
char *)iter->data, endPointInfo.stats.lastDataDownlinkRate);
3535 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"LastDataUplinkRate ")) {
3536 LOG_INFO(
"%s:%lu ", (
char *)iter->data, endPointInfo.stats.lastDataUplinkRate);
3540 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Retransmissions")) {
3541 LOG_INFO(
"%s:%lu ", (
char *)iter->data, endPointInfo.stats.retransmissions);
3545 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"SignalStrength")) {
3546 LOG_INFO(
"%s:%d ", (
char *)iter->data, endPointInfo.stats.signalStrength);
3549 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Channel")) {
3550 unsigned long output_ulong = 0;
3553 LOG_INFO(
"%s:%lu ", (
char *)iter->data , output_ulong);
3557 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Stats.FCSErrorCount")) {
3558 LOG_INFO(
"%s:%u ", (
char *)iter->data, params.fcsErrorCount);
3561 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Stats.Noise")) {
3562 LOG_INFO(
"%s:%u ", (
char *)iter->data, params.noiseFloor);
3565 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"TransmitPower"))
3570 LOG_INFO(
"%s:%d ", (
char *)iter->data , output_INT);
3574 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Stats.ErrorsReceived")) {
3575 LOG_INFO(
"%s:%u ", (
char *)iter->data, params.errorsReceived);
3578 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Stats.ErrorsSent")) {
3579 LOG_INFO(
"%s:%u ", (
char *)iter->data, params.errorsSent);
3582 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Stats.PacketsReceived")) {
3583 LOG_INFO(
"%s:%lu ", (
char *)iter->data, params.packetsReceived);
3586 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Stats.PacketsSent")) {
3587 LOG_INFO(
"%s:%lu ", (
char *)iter->data, params.packetsSent);
3590 iter = g_list_next(iter);
3599 void logs_Period2_Params()
3601 static bool print_flag =
true;
3603 static time_t lastExec_t;
3609 LOG_TRACE(
"print_flag : %d", print_flag);
3612 if(NULL != wifiParams_Tele_Period2.paramlist)
3614 char bssid_string[BUFF_MAX];
3616 memset(bssid_string,0, BUFF_MAX);
3617 char output_string[BUFF_MAX];
3621 memset(&currSsidInfo,
'\0',
sizeof(currSsidInfo));
3624 GList *iter = g_list_first(wifiParams_Tele_Period2.paramlist);
3629 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"NumberOfEntries")) {
3630 int noOfEndpoint = 1;
3631 LOG_INFO(
"%s:%d", (
char *)iter->data, noOfEndpoint);
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")))
3638 LOG_INFO(
"%s:%s", (
char *)iter->data, currSsidInfo.ssidSession.ssid);
3641 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"BSSID")) {
3642 LOG_INFO(
"%s:%s", (
char *)iter->data, bssid_string);
3646 if(g_strrstr ((
const gchar *)iter->data, (
const gchar *)
"Name")) {
3647 memset(output_string,0, BUFF_MAX);
3649 LOG_INFO(
"%s:%s", (
char *)iter->data, output_string);
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);
3659 iter = g_list_next(iter);
3663 diff_t = difftime(start_t, lastExec_t);
3665 if (diff_t >= wifiParams_Tele_Period2.timePeriod) {
3677 void readValue(FILE *pFile,
char *pToken,
char *data)
3679 char buffer[DATA_LEN];
3684 fseek(pFile, 0, SEEK_SET);
3685 while (fgets(buffer,
sizeof (buffer), pFile) != NULL)
3687 keyValue = strtok( buffer,
"=" );
3688 if(!(strcmp(keyValue, pToken)))
3690 keyValue = strtok(NULL,
"\n" );
3691 if(keyValue != NULL)
3693 strncpy(data, keyValue,strlen(keyValue));
3694 data[strlen(keyValue)] =
'\0';
3701 #ifdef ENABLE_LOST_FOUND
3702 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3704 int laf_get_lfat(laf_lfat_t *lfat)
3711 str.assign(confProp.wifiProps.getLfatUrl,strlen(confProp.wifiProps.getLfatUrl));
3714 retStr = getLfatUrl.getCurlData();
3715 http_err_code = getLfatUrl.gethttpcode();
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;
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)
3737 STRCPY_S(lfat->token, lfat->len+1, cJSON_GetObjectItem(response,
"LFAT")->valuestring);
3738 lfat->token[lfat->len] =
'\0';
3739 cJSON_Delete(response);
3742 #else // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
3743 int laf_get_lfat(laf_lfat_t *lfat)
3747 unsigned int tokenlength=0;
3749 char version[MAX_VERSION_LEN];
3750 char ttl[MAX_VERSION_LEN];
3754 ret = get_token_length(tokenlength);
3756 LOG_ERR(
"laf_get_lfat - Error in token read");
3759 lfat->token = (
char *) malloc(tokenlength+1);
3760 if(lfat->token == NULL)
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);
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");
3774 readValue(fd, LFAT_VERSION, version);
3775 if(version != NULL){
3776 STRCPY_S(lfat->version,
sizeof(lfat->version), version);
3778 STRCPY_S(lfat->version,
sizeof(lfat->version),
"1.1");
3781 readValue(fd, LFAT_TTL, ttl);
3783 value = strtol(ttl, &eptr, 10);
3786 lfat->ttl = 31536000;
3788 LOG_INFO(
"lfat_version : %s, lfat_ttl : %s",version, ttl);
3789 LOG_INFO(
"lfat_version : %s, lfat_ttl : %ld",lfat->version, lfat->ttl);
3792 LOG_INFO(
"Unable to open lfat_conf file");
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);
3804 #endif // ENABLE_XCAM_SUPPORT
3806 #if !defined (ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3808 int laf_set_lfat(laf_lfat_t*
const lfat)
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);
3823 data = cJSON_Print(req_payload);
3824 RDK_ASSERT_NOT_NULL(data);
3826 retStr = setLfatUrl.getCurlData();
3827 http_err_code = setLfatUrl.gethttpcode();
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);
3834 if(http_err_code == 0)
3835 http_err_code = 404;
3836 return http_err_code;
3839 cJSON_Delete(req_payload);
3845 #else // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
3846 int laf_set_lfat(laf_lfat_t*
const lfat)
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);
3856 LOG_ERR(
"Error setting lfat token");
3860 LOG_ERR(
"LFAT Token is Null");
3865 #endif // ENABLE_XCAM_SUPPORT or XHB1 or XHC3
3867 bool addSwitchToPrivateResults(
int lnfError,
char *currTime)
3870 guint lstLnfPvtResultsLength=0;
3874 if(NULL == WiFiLnfSwitchPrivateResultsData) {
3875 LOG_ERR(
"[%s] \'Failed to allocate memory", MODULE_NAME);
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));
3887 LOG_ERR(
"[%s] Error in added Time and lnf error to list, error code %d", MODULE_NAME, ret );
3894 bool convertSwitchToPrivateResultsToJson(
char *buffer)
3896 cJSON *rootObj = NULL, *array_element = NULL, *array_obj = NULL;
3897 UINT output_array_size = 0;
3900 char privateResultsLength=0;
3903 rootObj = cJSON_CreateObject();
3904 if(NULL == rootObj) {
3905 LOG_ERR(
"[%s] Failed to create root json object.", MODULE_NAME);
3908 cJSON_AddItemToObject(rootObj,
"results", array_obj=cJSON_CreateArray());
3909 GList *element = g_list_first(lstLnfPvtResults);
3910 privateResultsLength=g_list_length(lstLnfPvtResults);
3912 while ((element != NULL)&&(privateResultsLength > 0))
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--;
3922 out = cJSON_PrintUnformatted(rootObj);
3925 strncpy(buffer, out, strlen(out)+1);
3926 LOG_TRACE(
"[%s] Buffer = %s", MODULE_NAME,buffer );
3929 cJSON_Delete(rootObj);
3935 bool clearSwitchToPrivateResults()
3938 if((lstLnfPvtResults) && (g_list_length(lstLnfPvtResults) != 0))
3940 #if !defined(ENABLE_XCAM_SUPPORT) && !defined(XHB1) && !defined(XHC3)
3941 g_list_free_full((GList *)g_steal_pointer(&lstLnfPvtResults),g_free);
3943 g_list_free_full(lstLnfPvtResults,g_free);
3948 LOG_INFO(
"[%s] switch to private results list is empty ", MODULE_NAME);
3953 #endif // ENABLE_LOST_FOUND
3954 #endif // USE_RDK_WIFI_HAL
3958 bShutdownWifi=
true;
3961 pthread_mutex_lock(&mutexGo);
3962 if(0 == pthread_cond_signal(&condGo)) {
3963 LOG_INFO(
"[%s] Signalling wifiStatusMonitorThread to exit cond wait", MODULE_NAME);
3965 pthread_mutex_unlock(&mutexGo);
3967 LOG_INFO(
"[%s] calling pthread_join wifiStatusMonitorThread", MODULE_NAME);
3968 pthread_join (wifiStatusMonitorThread, NULL);
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);
3976 pthread_mutex_unlock(&mutexAPDetails);
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);
3985 #ifdef ENABLE_LOST_FOUND
3986 if ((lafConnectThread) && (pthread_cancel(lafConnectThread) == -1 )) {
3987 LOG_ERR(
"[%s] lafConnectThread cancel failed!", MODULE_NAME);
3990 if ((lafConnectToPrivateThread) && (pthread_cancel(lafConnectToPrivateThread) == -1 )) {
3991 LOG_ERR(
"[%s] lafConnectToPrivateThread failed!", MODULE_NAME);
3995 LOG_INFO(
"[%s] Start WiFi Uninitialization", MODULE_NAME);
3996 #ifdef USE_RDK_WIFI_HAL
3999 LOG_INFO(
"[%s] WiFi Uninitialization done", MODULE_NAME);
4001 #ifdef ENABLE_LOST_FOUND
4002 condLAF = PTHREAD_COND_INITIALIZER;
4003 mutexLAF = PTHREAD_MUTEX_INITIALIZER;
4006 isLAFCurrConnectedssid=
false;
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;
4015 memset(&gSsidList,0,
sizeof gSsidList);
4016 memset(&savedWiFiConnList,0,
sizeof savedWiFiConnList);
4017 memset(&wifiConnData,0,
sizeof wifiConnData);