26 #include <wifi_client_hal.h>
30 #ifdef WIFI_CLIENT_ROAMING
48 extern size_t printf_decode(u8 *buf,
size_t maxlen,
const char *str);
50 #define WPA_SUP_TIMEOUT 5000
51 #define MAX_SSID_LEN 32
52 #define MAX_PASSWORD_LEN 64
55 #define RETURN_BUF_LENGTH (96*1024)
56 #define BUFF_LEN_32 MAX_SSID_LEN
57 #define BUFF_LEN_64 64
58 #define MAX_WPS_AP_COUNT 5
59 #define WPS_CON_TIMEOUT 120
61 #define MAX_NEIGHBOR_LIMIT 32
62 #define PREVIOUS_AUTH_INVALID 2
63 #ifdef WIFI_CLIENT_ROAMING
64 #define WIFI_ROAMING_CONFIG_FILE "/opt/secure/wifi/wifi_roamingControl.json"
65 #define WIFI_DEFAULT_ROAMING_ENABLE false
66 #define WIFI_DEFAULT_PRE_ASSN_BEST_THRLD -67
67 #define WIFI_DEFAULT_PRE_ASSN_BEST_DELTA 3
68 #define WIFI_DEFAULT_BEST_DELTA_CONNECTED 12
69 #define WIFI_DEFAULT_POST_ASSN_SELF_STEER_THRESHOLD -75
70 #define WIFI_DEFAULT_POST_ASSN_SELF_STEER_TIMEFRAME 60
71 #define WIFI_DEFAULT_SELF_STEER_OVERRIDE_ENABLE false
72 #define WIFI_DEFAULT_BEST_DELTA_DISCONNECTED 8
73 #define WIFI_DEFAULT_AP_CONTROL_THRESHOLD -75
74 #define WIFI_DEFAULT_AP_CONTROL_TIMEFRAME 60
75 #define WIFI_DEFAULT_POST_ASSN_BACKOFF_TIME 2
76 #define WIFI_DEFAULT_POST_ASSN_DELTA 3
77 #define WPA_EVENT_BEACON_LOSS "CTRL-EVENT-BEACON-LOSS"
78 #define WIFI_MAX_POST_ASSN_BACKOFF_TIME 3600
79 #define WIFI_MAX_POST_ASSN_TIME_FRAME 36000
84 WIFI_HAL_WPA_SUP_STATE_IDLE,
85 WIFI_HAL_WPA_SUP_STATE_CMD_SENT,
86 WIFI_HAL_WPA_SUP_CONNECTING,
87 } WIFI_HAL_WPA_SUP_STATE;
90 WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE,
91 WIFI_HAL_WPA_SUP_SCAN_STATE_CMD_SENT,
92 WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED,
93 WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED,
94 } WIFI_HAL_WPA_SUP_SCAN_STATE;
96 #ifdef WIFI_CLIENT_ROAMING
98 WIFI_HAL_ROAM_STATE_ROAMING_IDLE,
99 WIFI_HAL_ROAM_STATE_SIGNAL_PROCESSING,
100 WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_STARTED,
101 WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_EXPIRED,
102 WIFI_HAL_ROAM_STATE_AP_SELECTION,
103 WIFI_HAL_ROAM_STATE_ROAMING_TRIGGERED,
104 WIFI_HAL_ROAM_STATE_ROAMING_SUCCESS,
105 } WIFI_HAL_ROAM_STATE;
108 WIFI_HAL_RRM_NEIGHBOR_REP_STATE_IDLE,
109 WIFI_HAL_RRM_NEIGHBOR_REP_RECEIVED,
110 WIFI_HAL_RRM_NEIGHBOR_REP_REQUEST_FAILED,
111 WIFI_HAL_RRM_NEIGHBOR_REP_STATE_INTERNAL_ERROR
112 } WIFI_HAL_RRM_NEIGHBOR_REP_STATUS;
115 WIFI_HAL_ROAMING_MODE_NOT_SET,
116 WIFI_HAL_ROAMING_MODE_SELF_STEERING,
117 WIFI_HAL_ROAMING_MODE_AP_STEERING,
118 } WIFI_HAL_ROAMING_MODE;
120 typedef struct _wifi_rrm_neighbor_rep_request_t
122 char ssid[MAX_SSID_LEN + 1];
125 } wifi_rrm_neighbor_rep_request_t;
127 typedef struct _wifi_rrm_neighbor_ap_t
129 char ssid[BUFF_LEN_32];
130 char bssid[BUFF_LEN_32];
131 char bssidInfo[BUFF_LEN_64];
136 } wifi_rrm_neighbor_ap_t;
138 typedef struct _wifi_neighbor_report_t
140 wifi_rrm_neighbor_ap_t neighbor_ap [MAX_NEIGHBOR_LIMIT];
142 } wifi_rrm_neighbor_report_t;
147 CHAR ap_SSID[MAX_SSID_LEN+1];
149 INT ap_SignalStrength;
151 WIFI_HAL_FREQ_BAND ap_FreqBand;
155 extern struct wpa_ctrl *g_wpa_ctrl;
156 extern struct wpa_ctrl *g_wpa_monitor;
159 extern pthread_mutex_t wpa_sup_lock;
162 extern char cmd_buf[1024];
163 extern char return_buf[RETURN_BUF_LENGTH];
166 extern uint32_t ap_count;
167 INT parse_scan_results(
char *buf,
size_t len);
169 BOOL bNoAutoScan=FALSE;
170 char bUpdatedSSIDInfo=1;
171 BOOL bIsWpsCompleted =
TRUE;
172 BOOL bIsPBCOverlapDetected = FALSE;
173 BOOL bWpsPBC = FALSE;
174 struct timespec timespec_wps_cancel;
177 WIFI_HAL_WPA_SUP_STATE cur_sup_state = WIFI_HAL_WPA_SUP_STATE_IDLE;
178 WIFI_HAL_WPA_SUP_SCAN_STATE cur_scan_state_from_supp = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
179 extern WIFI_HAL_WPA_SUP_SCAN_STATE cur_scan_state;
181 static char event_buf[4096];
183 static int isPrivateSSID=1;
184 size_t event_buf_len;
185 pthread_t wps_start_thread;
188 #ifdef WIFI_CLIENT_ROAMING
189 pthread_mutex_t wifi_roam_lock;
191 wifi_rrm_neighbor_report_t stRrmNeighborRpt;
192 pthread_t wifi_signal_mon_thread;
194 int backOffRefreshed = 1;
195 INT postAssocBackOffTime = WIFI_DEFAULT_POST_ASSN_BACKOFF_TIME;
196 WIFI_HAL_RRM_NEIGHBOR_REP_STATUS cur_rrm_nbr_rep_state = WIFI_HAL_RRM_NEIGHBOR_REP_STATE_IDLE;
198 WIFI_HAL_ROAMING_MODE cur_roaming_mode = WIFI_HAL_ROAMING_MODE_AP_STEERING;
199 WIFI_HAL_ROAM_STATE cur_roaming_state = WIFI_HAL_ROAM_STATE_ROAMING_IDLE;
200 #endif // WIFI_CLIENT_ROAMING
202 INT is_null_pointer(
char* str);
207 void* start_wifi_wps_connection(
void *param);
209 void stop_wifi_wps_connection();
211 BOOL isDualBandSupported();
213 int triggerWpsPush(
char *bssid);
215 #ifdef WIFI_CLIENT_ROAMING
217 static char* readPersistentFile(
char *fileName);
219 static int writeToPersistentFile (
char *fileName, cJSON *pRoamingCtrl_data);
223 void start_wifi_signal_monitor_timer(
void *arg);
227 char ssid_to_find[MAX_SSID_LEN+1] = {0};
228 char scanned_ssid[MAX_SSID_LEN+1] = {0};
240 WIFI_LOG_INFO(
"Registering connect callback...\n");
241 callback_connect=callback_proc;
246 WIFI_LOG_INFO(
"Registering disconnect callback...\n");
247 callback_disconnect=callback_proc;
252 WIFI_LOG_INFO(
"Registering telemetry callback...\n");
253 callback_telemetry = telemetry_ops;
256 void telemetry_init(
char* name)
258 if (callback_telemetry) callback_telemetry->init(name);
261 void telemetry_event_s(
char* marker,
char* value)
263 if (callback_telemetry) callback_telemetry->event_s(marker, value);
266 void telemetry_event_d(
char* marker,
int value)
268 if (callback_telemetry) callback_telemetry->event_d(marker, value);
272 char* getValue(
const char *buf,
const char *keyword) {
274 char *saveptr = NULL;
279 ptr = strstr(buf, keyword);
280 if (ptr == NULL)
return NULL;
282 strtok_r(ptr,
"=", &saveptr);
283 return (strtok_r(NULL,
"\n", &saveptr));
286 char trimSpace(
char *srcStr)
290 for(tmpPtr2=tmpPtr1=srcStr;*tmpPtr1;tmpPtr1++)
292 if(!isspace(*tmpPtr1))
293 *tmpPtr2++ = *tmpPtr1;
299 int wpaCtrlSendCmd(
char *cmd) {
300 size_t return_len=
sizeof(return_buf)-1;
303 memset(return_buf, 0, return_len);
304 if(NULL == g_wpa_ctrl) {
305 WIFI_LOG_ERROR(
"Control interface is NULL. \n");
309 ret = wpa_ctrl_request(g_wpa_ctrl, cmd, strlen(cmd), return_buf, &return_len, NULL);
312 WIFI_LOG_INFO(
"cmd=%s timed out \n", cmd);
314 }
else if (ret < 0) {
315 WIFI_LOG_INFO(
"cmd=%s failed \n", cmd);
321 static int find_ssid_in_scan_results(
const char* ssid)
325 if(NULL == ssid || ssid[0] ==
'\0')
327 WIFI_LOG_ERROR(
"SSID to find is null/empty");
330 for (i = 0; i < ap_count; i++)
332 if (strncmp (ap_list[i].ap_SSID, ssid,MAX_SSID_LEN) == 0)
334 WIFI_LOG_INFO(
"Found SSID match - bssid = %s rssi = %d ssid = %s\n",
335 ap_list[i].ap_BSSID, ap_list[i].ap_SignalStrength, ap_list[i].ap_SSID);
340 WIFI_LOG_TRACE(
"No SSID match - bssid = %s rssi = %d ssid = %s\n",
341 ap_list[i].ap_BSSID, ap_list[i].ap_SignalStrength, ap_list[i].ap_SSID);
347 static BOOL wpa_supplicant_conf_reset()
349 WIFI_LOG_INFO(
"Deleting conf file and making a new one\n");
351 if (remove(
"/opt/secure/wifi/wpa_supplicant.conf") == 0)
353 WIFI_LOG_INFO(
"Removed File\n");
356 fp = fopen(
"/opt/secure/wifi/wpa_supplicant.conf",
"w");
359 WIFI_LOG_INFO(
"Error in opening configuration file\n");
362 fprintf(fp,
"ctrl_interface=/var/run/wpa_supplicant\n");
363 fprintf(fp,
"update_config=1\n");
368 static long timespec_diff_ms(
struct timespec* ts1,
struct timespec* ts2)
370 return ((ts2->tv_sec - ts1->tv_sec)*1000L) + ((ts2->tv_nsec - ts1->tv_nsec)/1000000);
376 void* monitor_thread_task(
void *param)
379 char *saveptr = NULL;
381 char current_ssid[MAX_SSID_LEN+1] = {0};
382 char current_bssid[ENET_LEN+1] = {0};
384 char last_disconnected_bssid[ENET_LEN+1] = {0};
385 int last_disconnected_reason_code = 0;
386 char last_disconnected_ssid[MAX_SSID_LEN+1] = {0};
387 char out_of_range_ssid[MAX_SSID_LEN+1] = {0};
389 char tmp_return_buf[8192];
392 #ifdef WIFI_CLIENT_ROAMING
393 pthread_mutex_init(&wifi_roam_lock,NULL);
394 pthread_condattr_t attr;
396 pthread_condattr_init( &attr);
397 pthread_condattr_setclock( &attr, CLOCK_MONOTONIC);
398 pthread_cond_init( &cond, &attr);
401 while ((stop_monitor !=
true) && (g_wpa_monitor != NULL)) {
402 if (wpa_ctrl_pending(g_wpa_monitor) > 0) {
404 memset(event_buf, 0,
sizeof(event_buf));
405 event_buf_len =
sizeof(event_buf) - 1;
407 if (0 == wpa_ctrl_recv(g_wpa_monitor, event_buf, &event_buf_len)) {
409 WIFI_LOG_DEBUG(
"%s: wpa_ctrl_recv got event_buf = [%s]\n", __FUNCTION__, event_buf);
411 start = strchr(event_buf,
'>');
412 if (start == NULL)
continue;
413 if ((strstr(start, WPA_EVENT_SCAN_STARTED) != NULL)&&(!bNoAutoScan)) {
420 WIFI_LOG_INFO(
"Scan started \n");
424 WIFI_LOG_INFO(
"ssid_to_find empty. Issuing 'GET_NETWORK 0 ssid' to get SSID being scanned for\n");
425 pthread_mutex_lock(&wpa_sup_lock);
426 wpaCtrlSendCmd(
"GET_NETWORK 0 ssid");
427 const char* ptr_start_quote = strchr (return_buf,
'"');
428 char* ptr_end_quote = NULL;
429 if (ptr_start_quote && (ptr_end_quote = strrchr (ptr_start_quote,
'"')) > ptr_start_quote)
431 *ptr_end_quote =
'\0';
432 strcpy (ssid_to_find, ptr_start_quote + 1);
434 pthread_mutex_unlock(&wpa_sup_lock);
435 WIFI_LOG_INFO(
"ssid based on network id = [%s] \n", return_buf);
437 WIFI_LOG_INFO(
"SSID to find = [%s] \n", ssid_to_find);
438 strcpy(scanned_ssid, ssid_to_find);
440 pthread_mutex_lock(&wpa_sup_lock);
443 WIFI_LOG_INFO(
"Flushing the BSS now\n");
444 wpaCtrlSendCmd(
"BSS_FLUSH 0");
446 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED;
447 pthread_mutex_unlock(&wpa_sup_lock);
450 else if (strstr(start, WPA_EVENT_SCAN_RESULTS) != NULL) {
451 WIFI_LOG_INFO(
"Scan results received \n");
454 pthread_mutex_lock(&wpa_sup_lock);
455 return_buf[0] =
'\0';
456 wpaCtrlSendCmd(
"SCAN_RESULTS");
457 log_top5_bssids(return_buf);
460 WIFI_LOG_INFO(
"Buffer Length = %lu \n",strlen(return_buf));
461 ap_count = parse_scan_results (return_buf, strlen (return_buf));
462 if (!find_ssid_in_scan_results (ssid_to_find))
463 WIFI_LOG_ERROR(
"SSID [%s] not found in scan results\n", ssid_to_find);
467 WIFI_LOG_ERROR(
"no SSID to find\n");
469 pthread_mutex_unlock(&wpa_sup_lock);
473 WIFI_LOG_INFO(
"Application is running wifi scan so skipping \n");
475 if (cur_scan_state == WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED) {
476 pthread_mutex_lock(&wpa_sup_lock);
477 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED;
478 pthread_mutex_unlock(&wpa_sup_lock);
482 else if((strstr(start, WPS_EVENT_AP_AVAILABLE_PBC) != NULL)) {
483 WIFI_LOG_INFO(
"WPS Connection in progress\n");
486 if (callback_connect) (*callback_connect)(1, current_ssid, &connError);
489 else if(strstr(start, WPS_EVENT_TIMEOUT) != NULL) {
490 WIFI_LOG_INFO(
"WPS Connection timeout\n");
491 bIsWpsCompleted =
TRUE;
493 if (callback_disconnect) (*callback_disconnect)(1,
"", &connError);
497 else if(strstr(start,WPS_EVENT_OVERLAP) != NULL) {
498 WIFI_LOG_ERROR(
"WPS Overlap detected. ! Canceling WPS Operation...\n");
499 bIsPBCOverlapDetected =
TRUE;
501 if(isDualBandSupported())
502 stop_wifi_wps_connection();
504 WIFI_LOG_ERROR(
"TELEMETRY_WPS_CONNECTION_STATUS:DISCONNECTED,WPS_PBC_OVERLAP \n");
506 if (callback_disconnect) (*callback_disconnect)(1,
"", &connError);
508 bIsWpsCompleted =
TRUE;
511 else if(strstr(start, WPS_EVENT_SUCCESS) != NULL) {
512 bIsWpsCompleted =
TRUE;
514 WIFI_LOG_INFO(
"WPS is successful...Associating now\n");
517 else if(strstr(start, WPA_EVENT_CONNECTED) != NULL) {
518 WIFI_LOG_INFO(
"Authentication completed successfully and data connection enabled\n");
520 pthread_mutex_lock(&wpa_sup_lock);
523 wpaCtrlSendCmd(
"SAVE_CONFIG");
525 WIFI_LOG_INFO(
"[%s:%d] Configuration Saved \n",__FUNCTION__,__LINE__);
528 int retStatus = wpaCtrlSendCmd(
"STATUS");
530 telemetry_event_d(
"WIFIV_WARN_hal_timeout", 1);
531 int rc = snprintf (tmp_return_buf,
sizeof(tmp_return_buf),
"%s", return_buf);
533 WIFI_LOG_ERROR(
"snprintf of tmp_return_buf failed\n");
535 const char* bssid_ptr = getValue(return_buf,
"bssid");
539 snprintf (current_bssid,
sizeof(current_bssid),
"%s", bssid_ptr);
540 ptr = bssid_ptr + strlen(bssid_ptr) + 1;
544 WIFI_LOG_ERROR(
"BSSID is NULL. Status output = [%s]\n", tmp_return_buf);
545 current_bssid[0] =
'\0';
548 const char *ssid_ptr = getValue(ptr,
"ssid");
549 printf_decode ((u8*)current_ssid,
sizeof(current_ssid), ssid_ptr ? ssid_ptr :
"");
550 WIFI_LOG_INFO(
"Connected to BSSID [%s], SSID [%s]\n", current_bssid, current_ssid);
551 pthread_mutex_unlock(&wpa_sup_lock);
554 if(*out_of_range_ssid)
556 *out_of_range_ssid = 0;
557 WIFI_LOG_INFO(
"Out of range SSID : %s\n", out_of_range_ssid);
572 if (callback_connect) (*callback_connect)(1, current_ssid, &connError);
575 else if(strstr(start, WPA_EVENT_DISCONNECTED) != NULL) {
580 char* name_value_entry = NULL;
581 strtok_r (start,
" ", &saveptr);
582 while (NULL != (name_value_entry = strtok_r (NULL,
" ", &saveptr)))
584 if (0 == strncmp (name_value_entry,
"bssid=", strlen (
"bssid=")))
585 snprintf (last_disconnected_bssid,
sizeof(last_disconnected_bssid),
"%s", name_value_entry + strlen (
"bssid="));
586 else if (0 == strncmp (name_value_entry,
"reason=", strlen (
"reason=")))
587 last_disconnected_reason_code = atoi (name_value_entry + strlen (
"reason="));
593 if( *out_of_range_ssid && (last_disconnected_reason_code != PREVIOUS_AUTH_INVALID) )
595 *out_of_range_ssid = 0;
596 WIFI_LOG_INFO(
"Out of range SSID : %s\n", out_of_range_ssid);
600 snprintf (last_disconnected_ssid,
sizeof(last_disconnected_ssid),
"%s",
601 0 == strcasecmp (current_bssid, last_disconnected_bssid) ? current_ssid :
"");
604 "Disconnected from BSSID [%s], reason_code [%d] (SSID [%s]), last successfully connected bssid [%s]\n",
605 last_disconnected_bssid, last_disconnected_reason_code, last_disconnected_ssid, current_bssid);
608 current_bssid[0] =
'\0';
609 current_ssid[0] =
'\0';
612 #ifdef WIFI_CLIENT_ROAMING
614 if( cur_roaming_state == WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_STARTED) {
615 pthread_cond_signal(&cond);
617 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
618 backOffRefreshed = 1;
620 if (callback_disconnect) (*callback_disconnect)(1, last_disconnected_ssid, &connError);
623 else if (strstr (start, WPA_EVENT_TEMP_DISABLED) != NULL) {
631 char ssid[MAX_SSID_LEN+1] =
"<UNKNOWN>";
633 int auth_failures = -1;
634 char reason[128] =
"UNKNOWN";
636 const char* ptr_start_quote = strchr (start,
'"');
637 char* ptr_end_quote = NULL;
638 if (ptr_start_quote && (ptr_end_quote = strrchr (ptr_start_quote,
'"')) > ptr_start_quote)
640 *ptr_end_quote =
'\0';
641 printf_decode ((u8*)ssid,
sizeof(ssid), ptr_start_quote + 1);
642 *ptr_end_quote =
'"';
645 char* name_value_entry = NULL;
646 strtok_r (ptr_end_quote,
" ", &saveptr);
647 while (NULL != (name_value_entry = strtok_r (NULL,
" ", &saveptr)))
649 if (0 == strncmp (name_value_entry,
"auth_failures=", strlen (
"auth_failures=")))
650 auth_failures = atoi (name_value_entry + strlen (
"auth_failures="));
651 else if (0 == strncmp (name_value_entry,
"duration=", strlen (
"duration=")))
652 duration = atoi (name_value_entry + strlen (
"duration="));
653 else if (0 == strncmp (name_value_entry,
"reason=", strlen (
"reason=")))
654 snprintf (reason,
sizeof (reason),
"%s", name_value_entry + strlen (
"reason="));
657 if (0 == strcmp (reason,
"WRONG_KEY")) {
659 }
else if (0 == strcmp (reason,
"AUTH_FAILED"))
663 WIFI_LOG_INFO(
"SSID [%s] disabled for %ds (auth_failures=%d), reason=%s, connError [%d]\n",
664 ssid, duration, auth_failures, reason, connError);
672 if(strlen(out_of_range_ssid) > 0)
681 WIFI_LOG_INFO(
"Connection failed due to invalid credential, Disconnecting...\n");
682 pthread_mutex_lock(&wpa_sup_lock);
683 wpaCtrlSendCmd(
"DISCONNECT");
684 pthread_mutex_unlock(&wpa_sup_lock);
688 if (callback_connect)
689 (*callback_connect) (1, ssid, &connError);
692 else if (strstr (start, WPA_EVENT_REENABLED) != NULL) {
698 char ssid[MAX_SSID_LEN+1] =
"<UNKNOWN>";
700 const char* ptr_start_quote = strchr (start,
'"');
701 char* ptr_end_quote = NULL;
702 if (ptr_start_quote && (ptr_end_quote = strrchr (ptr_start_quote,
'"')) > ptr_start_quote)
704 *ptr_end_quote =
'\0';
705 printf_decode ((u8*)ssid,
sizeof(ssid), ptr_start_quote + 1);
706 *ptr_end_quote =
'"';
709 WIFI_LOG_INFO(
"SSID [%s] re-enabled\n", ssid);
712 else if((strstr(start, WPA_EVENT_NETWORK_NOT_FOUND) != NULL)&&(!bNoAutoScan)) {
722 WIFI_LOG_INFO(
"SSID [%s] not found in last scan\n", ssid_to_find);
729 clock_gettime(CLOCK_MONOTONIC, &now);
730 if (timespec_diff_ms(×pec_wps_cancel, &now) < 1000)
732 WIFI_LOG_WARN(
"Ignoring NETWORK_NOT_FOUND event received within 1s of WPS_CANCEL \n");
738 if (!*current_ssid && *last_disconnected_ssid && (0 == strcmp (last_disconnected_ssid, ssid_to_find)))
742 if (*last_disconnected_bssid)
744 pthread_mutex_lock(&wpa_sup_lock);
745 snprintf(cmd_buf,
sizeof(cmd_buf),
"BSS %s", last_disconnected_bssid);
746 wpaCtrlSendCmd(cmd_buf);
747 WIFI_LOG_TRACE(
"cmd_buf = [%s], return_buf = [%s]\n", cmd_buf, return_buf);
749 WIFI_LOG_INFO(
"BSSID [%s] had an SSID change\n", last_disconnected_bssid);
753 WIFI_LOG_INFO(
"BSSID [%s] is down or not within range\n", last_disconnected_bssid);
757 strcpy(out_of_range_ssid, last_disconnected_ssid);
758 WIFI_LOG_INFO(
"Out of range SSID : %s\n", out_of_range_ssid);
760 pthread_mutex_unlock(&wpa_sup_lock);
769 WIFI_LOG_INFO(
"Skipping no ssid found error: Scanned SSID = [%s] SSID to find = [%s]", scanned_ssid, ssid_to_find);
772 if (callback_disconnect) (*callback_disconnect)(1, ssid_to_find, &connError);
774 #ifdef WIFI_CLIENT_ROAMING
775 else if((strstr(start, WPA_EVENT_SIGNAL_CHANGE) != NULL) && isPrivateSSID) {
780 WIFI_LOG_DEBUG(
"RSSI Change event detected, Event = %s \n",start);
782 if(pstRoamingCtrl.roamingEnable ==
true) {
783 int rssi=0,isAbove=0,readCount=0;
785 char *eventData = strstr(start,
" ");
786 readCount = sscanf(eventData,
" above=%d signal=%d",&isAbove,&rssi);
788 WIFI_LOG_DEBUG(
"Signal Change event received with RSSI=[%d] and isAbove=[%d] \n",rssi,isAbove);
789 if(isAbove == 0 && cur_roaming_state == WIFI_HAL_ROAM_STATE_ROAMING_IDLE) {
790 cur_roaming_state = WIFI_HAL_ROAM_STATE_SIGNAL_PROCESSING;
792 if(cur_roaming_mode == WIFI_HAL_ROAMING_MODE_SELF_STEERING)
793 time = pstRoamingCtrl.postAssnSelfSteerTimeframe;
794 else if(cur_roaming_mode == WIFI_HAL_ROAMING_MODE_AP_STEERING)
795 time = pstRoamingCtrl.postAssnAPctrlTimeframe;
796 pthread_create(&wifi_signal_mon_thread,NULL,start_wifi_signal_monitor_timer, (
void*)time);
797 }
else if(isAbove == 1 && cur_roaming_state == WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_STARTED){
798 WIFI_LOG_INFO(
"Signal strength is recovered, Stopping Roaming timer.\n");
799 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
800 backOffRefreshed = 1;
801 pthread_cond_signal(&cond);
802 }
else if(cur_roaming_state != WIFI_HAL_ROAM_STATE_ROAMING_IDLE){
803 WIFI_LOG_DEBUG(
"Roaming is in progres, Skipping signal change event \n");
806 WIFI_LOG_ERROR(
"Failed to parse signal change event. \n");
810 WIFI_LOG_DEBUG(
"Skipping signal change event, Roaming is disabled.\n");
813 else if((strstr(start, RRM_EVENT_NEIGHBOR_REP_RXED) != NULL))
815 WIFI_LOG_INFO(
"RRM Neighbor report received event\n");
816 if(pstRoamingCtrl.roamingEnable && pstRoamingCtrl.roam80211kvrEnable) {
817 cur_roaming_mode = WIFI_HAL_ROAMING_MODE_AP_STEERING;
818 int ret = parse_neighbor_report_response(start,&stRrmNeighborRpt);
820 cur_rrm_nbr_rep_state = WIFI_HAL_RRM_NEIGHBOR_REP_STATE_INTERNAL_ERROR;
822 cur_rrm_nbr_rep_state = WIFI_HAL_RRM_NEIGHBOR_REP_RECEIVED;
824 WIFI_LOG_DEBUG(
"RRM Skipping neighbor report, Roaming/KVR is disabled.\n");
826 }
else if ((strstr(start, RRM_EVENT_NEIGHBOR_REP_FAILED) != NULL)) {
827 WIFI_LOG_INFO(
"RRM Neighbor report failed event. \n");
828 cur_rrm_nbr_rep_state = WIFI_HAL_RRM_NEIGHBOR_REP_REQUEST_FAILED;
830 else if(strstr(start,WPA_EVENT_BEACON_LOSS) != NULL)
832 WIFI_LOG_INFO(
"Beacon Loss event detected. Client may disconnect.\n");
833 telemetry_event_d(
"WIFIV_WARN_BcnLossdisconn", 1);
834 }
else if(strstr(start,
"WNM-BTM-REQ-RECEIVED") != NULL)
836 WIFI_LOG_INFO(
"WNM- BTM Request Received. \n");
837 }
else if(strstr(start,
"WNM-BTM-RES-SENT") != NULL) {
838 WIFI_LOG_INFO(
"WNM- BTM Response Sent. \n");
839 cur_roaming_mode = WIFI_HAL_ROAMING_MODE_AP_STEERING;
840 }
else if(strstr(start, WPA_EVENT_AUTH_REJECT) != NULL ||
841 strstr(start, WPA_EVENT_ASSOC_REJECT) != NULL) {
843 if(*out_of_range_ssid)
845 *out_of_range_ssid = 0;
846 WIFI_LOG_INFO(
"Out of range SSID : %s\n", out_of_range_ssid);
849 #endif // WIFI_CLIENT_ROAMING
856 usleep(WPA_SUP_TIMEOUT);
868 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
873 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
878 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
884 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID:%d\n", ssidIndex);
885 uint32_t wps_pin = 0;
886 if(NetAppWiFiGenerateWPSPin(hNetApp, &wps_pin) == NETAPP_SUCCESS){
890 WIFI_LOG_INFO(
"Error setting the device pin\n");
898 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
901 if (!is_null_pointer(methods)){
902 strcpy(methods,
"Push and Pin");
903 WIFI_LOG_INFO(
"Supported Methods: Push and Pin\n");
911 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
913 if (!is_null_pointer(output_string)){
914 strcpy(output_string,
"Push and Pull");
922 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
923 if (!is_null_pointer(methodString)){
924 strcpy(methodString,
"Push and Pin");
925 WIFI_LOG_INFO(
"Supported Methods: Push and Pin\n");
933 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
939 WIFI_LOG_INFO(
"WPS Pin Call\n");
941 WIFI_LOG_DEBUG(
"wps_pin = %s\n", wps_pin);
945 if (wps_pin == NULL || *wps_pin ==
'\0')
947 WIFI_LOG_ERROR(
"No PIN supplied.\n");
953 pthread_mutex_lock(&wpa_sup_lock);
954 sprintf(cmd_buf,
"WPS_CHECK_PIN %s", wps_pin);
957 command_failed =
true;
958 if (0 == wpaCtrlSendCmd(cmd_buf))
960 if (strncmp(return_buf,
"FAIL", 4) == 0)
961 WIFI_LOG_ERROR(
"command '%s' returned '%s'\n", cmd_buf, return_buf);
963 command_failed =
false;
965 pthread_mutex_unlock(&wpa_sup_lock);
970 pthread_mutex_lock(&wpa_sup_lock);
971 if (cur_sup_state != WIFI_HAL_WPA_SUP_STATE_IDLE)
973 pthread_mutex_unlock(&wpa_sup_lock);
974 WIFI_LOG_INFO(
"Connection is in progress, returning error \n");
979 wpaCtrlSendCmd(
"REMOVE_NETWORK 0");
980 wpaCtrlSendCmd(
"SAVE_CONFIG");
981 bUpdatedSSIDInfo = 1;
984 bIsWpsCompleted = FALSE;
985 sprintf(cmd_buf,
"WPS_PIN any");
988 strcat(cmd_buf,
" ");
989 strcat(cmd_buf, wps_pin);
993 command_failed =
true;
994 if (0 == wpaCtrlSendCmd(cmd_buf))
996 if (strncmp(return_buf,
"FAIL", 4) == 0)
997 WIFI_LOG_ERROR(
"command '%s' returned '%s'\n", cmd_buf, return_buf);
1000 command_failed =
false;
1001 if (*wps_pin ==
'\0')
1002 strncat (wps_pin, return_buf, 8);
1005 pthread_mutex_unlock(&wpa_sup_lock);
1009 WIFI_LOG_INFO(
"Will be timing out if AP is not found after 120 seconds\n");
1011 if (
false == wpa_supplicant_conf_reset())
1015 (*callback_connect)(1,
"", &connError);
1016 WIFI_LOG_INFO(
"Connection in progress..\n");
1020 *pinValue = atoi(EnrolleePin);
1021 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
1022 if(NetAppWiFiConnectByPin(hNetApp, NETAPP_IFACE_WIRELESS, NULL, *pinValue,
true) == NETAPP_SUCCESS){
1025 WIFI_LOG_INFO(
"Error connecting to device with enrollee pin... Check again\n");
1035 char *saveptr = NULL;
1036 char ssid[MAX_SSID_LEN+1];
1044 memset(ssid,0,
sizeof(ssid));
1045 memset(bssid,0,
sizeof(bssid));
1046 memset(rssi,0,
sizeof(rssi));
1047 memset(freq,0,
sizeof(freq));
1050 ptr = strstr(buf,
"/ ssid");
1051 if (ptr == NULL)
return -1;
1052 ptr += strlen(
"/ ssid") + 1;
1054 char* line = strtok_r(ptr,
"\n", &saveptr);
1055 while(line != NULL && apCount < MAX_WPS_AP_COUNT)
1057 if(strstr(line,
"[WPS-PBC]") != NULL)
1063 sscanf(line,
"%32s %5s %7s %*s %32s",bssid,freq,rssi,ssid);
1064 if((ssid[0] !=
'\0') && (bssid[0] !=
'\0') && (rssi[0] !=
'\0') && (freq[0] !=
'\0'))
1066 WIFI_LOG_INFO(
"WPS-PBC AccessPoint[%d] : [SSID = %s , BSSID = %s , FREQ = %s , RSSI = %s ]\n",apCount,ssid,bssid,freq,rssi);
1067 strncpy(ap_list[apCount].ap_BSSID,bssid,
sizeof(ap_list[apCount].ap_BSSID));
1068 strncpy(ap_list[apCount].ap_SSID,ssid,
sizeof(ap_list[apCount].ap_SSID));
1069 ap_list[apCount].ap_Frequency = (int) strtol(freq,&eptr,10);
1070 ap_list[apCount].ap_FreqBand = (((ap_list[apCount].ap_Frequency/1000) == 5)?WIFI_HAL_FREQ_BAND_5GHZ:WIFI_HAL_FREQ_BAND_24GHZ);
1075 line = strtok_r(NULL,
"\n", &saveptr);
1081 INT wifi_cancelWpsPairing ()
1083 int retStatus = RETURN_ERR;
1086 if(bIsWpsCompleted == FALSE)
1088 stop_wifi_wps_connection();
1093 WIFI_LOG_INFO(
"No In-Progress WPS Operation, Skipping WPS_CANCEL. \n");
1100 void stop_wifi_wps_connection()
1102 bNoAutoScan = FALSE;
1103 if(bIsWpsCompleted == FALSE)
1105 WIFI_LOG_INFO(
"Stopping WPS operation.. \n");
1106 if (bWpsPBC && isDualBandSupported())
1107 pthread_cancel(wps_start_thread);
1110 if(pthread_mutex_trylock(&wpa_sup_lock) != 0)
1112 pthread_mutex_unlock(&wpa_sup_lock);
1113 pthread_mutex_lock(&wpa_sup_lock);
1115 clock_gettime(CLOCK_MONOTONIC, ×pec_wps_cancel);
1116 wpaCtrlSendCmd(
"WPS_CANCEL");
1118 if(cur_scan_state != WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE)
1119 wpaCtrlSendCmd(
"ABORT_SCAN");
1120 pthread_mutex_unlock(&wpa_sup_lock);
1125 if (callback_disconnect) (*callback_disconnect)(1,
"", &connError);
1126 if(bIsPBCOverlapDetected ==
TRUE)
1127 WIFI_LOG_INFO(
"TELEMETRY_WPS_CONNECTION_STATUS:DISCONNECTED,WPS_PBC_OVERLAP\n");
1129 WIFI_LOG_INFO(
"TELEMETRY_WPS_CONNECTION_STATUS:DISCONNECTED,WPS_TIME_OUT\n");
1130 bIsWpsCompleted =
TRUE;
1135 BOOL isDualBandSupported()
1138 char cmd[BUFF_LEN_64];
1139 char result[BUFF_LEN_64];
1140 bool retStatus =
false;
1142 memset(cmd,0,
sizeof(cmd));
1143 memset(result,0,BUFF_LEN_64);
1145 snprintf(cmd,
sizeof(cmd),
"iw list | grep 'Band' | tr '\n' ' '");
1146 fp = popen(cmd,
"r");
1149 if ((fgets(result,
sizeof(result), fp) != NULL) && (result[0] !=
'\0'))
1151 if((strstr(result,
"Band 1:") != NULL) && (strstr(result,
"Band 2:") != NULL))
1165 WIFI_LOG_ERROR(
"isDualBandSupported() : popen() failed \n");
1171 int triggerWpsPush(
char *bssid)
1178 memset(cmd,0,
sizeof(cmd));
1179 snprintf(cmd,32,
"WPS_PBC %s",bssid);
1180 WIFI_LOG_INFO(
"Initiating WPS connection to BSSID - %s \n",bssid );
1181 pthread_mutex_lock(&wpa_sup_lock);
1182 retStatus = wpaCtrlSendCmd(cmd);
1183 pthread_mutex_unlock(&wpa_sup_lock);
1187 WIFI_LOG_ERROR(
"triggerWpsPush() failed , BSSID is NULL.! \n");
1193 void* start_wifi_wps_connection(
void *param)
1198 char tmpBuff[RETURN_BUF_LENGTH];
1200 bIsWpsCompleted = FALSE;
1201 bIsPBCOverlapDetected = FALSE;
1204 WIFI_LOG_INFO(
"Scanning for WPS-PBC access points on both 5 & 2.4 GHz Bands.\n");
1205 while(!bIsWpsCompleted)
1207 pthread_mutex_lock(&wpa_sup_lock);
1208 wpaCtrlSendCmd(
"BSS_FLUSH 0");
1210 wpaCtrlSendCmd(
"SCAN");
1213 if (strstr(return_buf,
"FAIL-BUSY") != NULL) {
1214 WIFI_LOG_INFO(
"FAIL-BUSY due to in-progress scanning.. \n");
1215 wpaCtrlSendCmd(
"ABORT_SCAN");
1216 wpaCtrlSendCmd(
"BSS_FLUSH 0");
1217 wpaCtrlSendCmd(
"SCAN");
1220 pthread_mutex_unlock(&wpa_sup_lock);
1221 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED;
1225 while ((cur_scan_state != WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED) &&(retry++ < 1000)) {
1230 memset(tmpBuff,0,RETURN_BUF_LENGTH);
1231 pthread_mutex_lock(&wpa_sup_lock);
1232 wpaCtrlSendCmd(
"SCAN_RESULTS");
1233 log_top5_bssids(return_buf);
1234 strncpy(tmpBuff,return_buf,
sizeof(tmpBuff));
1235 pthread_mutex_unlock(&wpa_sup_lock);
1236 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
1237 apCount = parse_wps_pbc_accesspoints(tmpBuff,ap_list);
1241 WIFI_LOG_INFO(
"Trying to establish WPS connection to 5GHz Accesspoint.\n");
1242 for(i=0; i<apCount; i++)
1244 if(ap_list[i].ap_FreqBand == WIFI_HAL_FREQ_BAND_5GHZ)
1246 triggerWpsPush(ap_list[i].ap_BSSID);
1250 while ((!bIsWpsCompleted) &&(retry++ < 1000)) {
1253 if(!bIsWpsCompleted)
1254 WIFI_LOG_ERROR(
"Failed to connect to 5G AP - %s\n",ap_list[i].ap_SSID);
1257 WIFI_LOG_INFO(
"TELEMETRY_WPS_CONNECTION_STATUS:CONNECTED,%s,%s,5GHz,%d,%d \n",ap_list[i].ap_SSID,ap_list[i].ap_BSSID,ap_list[i].ap_SignalStrength,ap_list[i].ap_Frequency);
1264 WIFI_LOG_INFO(
"Failed to get 5Ghz AP for WPS connection, Trying for 2.4GHz AP. \n");
1265 for(i=0; i<apCount; i++)
1267 if(ap_list[i].ap_FreqBand == WIFI_HAL_FREQ_BAND_24GHZ)
1269 triggerWpsPush(ap_list[i].ap_BSSID);
1273 while ((!bIsWpsCompleted) &&(retry++ < 1000)) {
1276 if(!bIsWpsCompleted)
1277 WIFI_LOG_ERROR(
"Failed to connect to 2.4G AP - %s\n",ap_list[i].ap_SSID);
1280 WIFI_LOG_INFO(
"TELEMETRY_WPS_CONNECTION_STATUS:CONNECTED,%s,%s,2.4GHz,%d,%d \n",ap_list[i].ap_SSID,ap_list[i].ap_BSSID,ap_list[i].ap_SignalStrength,ap_list[i].ap_Frequency);
1288 WIFI_LOG_INFO(
"Missing WPS_PBC AP in Scanned list, Continue Scanning... \n");
1297 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
1299 WIFI_LOG_INFO(
"WPS Push Button Call\n");
1300 telemetry_event_d(
"WIFIV_ERR_WPS_button_pressed", 1);
1303 pthread_mutex_lock(&wpa_sup_lock);
1305 if (cur_sup_state != WIFI_HAL_WPA_SUP_STATE_IDLE) {
1306 pthread_mutex_unlock(&wpa_sup_lock);
1307 WIFI_LOG_INFO(
"Connection is in progress, returning error \n");
1312 wpaCtrlSendCmd(
"REMOVE_NETWORK 0");
1313 wpaCtrlSendCmd(
"SAVE_CONFIG");
1315 pthread_mutex_unlock(&wpa_sup_lock);
1317 if(isDualBandSupported())
1319 WIFI_LOG_INFO(
"STB is Dual-Band supported. Initiating band seletion... \n");
1320 pthread_create(&wps_start_thread, NULL, start_wifi_wps_connection, NULL);
1322 signal(SIGALRM, stop_wifi_wps_connection);
1323 alarm(WPS_CON_TIMEOUT);
1327 WIFI_LOG_INFO(
"No Dual-Band support. Initiate Normal PBC.\n");
1328 bIsWpsCompleted = FALSE;
1329 pthread_mutex_lock(&wpa_sup_lock);
1330 wpaCtrlSendCmd(
"WPS_PBC");
1331 pthread_mutex_unlock(&wpa_sup_lock);
1334 WIFI_LOG_INFO(
"Will be timing out if AP not found after 120 seconds\n");
1336 if (
false == wpa_supplicant_conf_reset())
1341 (*callback_connect)(1,
"", &connError);
1342 WIFI_LOG_INFO(
"Connection in progress..\n");
1344 WIFI_LOG_INFO(
"WIFI HAL: WPS Push sent successfully\n");
1348 INT
wifi_connectEndpoint(INT ssidIndex, CHAR *AP_SSID,
wifiSecurityMode_t AP_security_mode, CHAR *AP_security_WEPKey, CHAR *AP_security_PreSharedKey, CHAR *AP_security_KeyPassphrase,
int saveSSID,CHAR * eapIdentity,CHAR * carootcert,CHAR * clientcert,CHAR * privatekey){
1351 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
1353 WIFI_LOG_INFO(
"Save SSID value:%d\n", saveSSID);
1355 pthread_mutex_lock(&wpa_sup_lock);
1356 isPrivateSSID=saveSSID;
1357 if (isPrivateSSID) {
1358 WIFI_LOG_INFO(
"Will save network to wpa_supplicant.conf if connect is successful\n");
1361 WIFI_LOG_INFO(
"Will not save network to wpa_supplicant.conf\n");
1365 WIFI_LOG_INFO(
"Requesting connection to AP\n");
1367 WIFI_LOG_INFO(
"Security mode:%d\n", AP_security_mode);
1368 retStatus=wpaCtrlSendCmd(
"REMOVE_NETWORK 0");
1369 if ((strstr (return_buf,
"FAIL") != NULL) || (retStatus != 0))
1371 WIFI_LOG_ERROR(
"%s: REMOVE_NETWORK 0 failed error %d \n", __FUNCTION__,retStatus);
1374 wpaCtrlSendCmd(
"ADD_NETWORK");
1377 sprintf(cmd_buf,
"SET_NETWORK 0 ssid \"%s\"", AP_SSID);
1378 wpaCtrlSendCmd(cmd_buf);
1389 WIFI_LOG_INFO(
"Security mode is WPA2/WPA3\n");
1392 WIFI_LOG_INFO(
"Security mode is WPA3\n");
1395 WIFI_LOG_INFO(
"Security mode is PSK\n");
1398 sprintf(cmd_buf,
"SET_NETWORK 0 key_mgmt WPA-PSK SAE");
1399 wpaCtrlSendCmd(cmd_buf);
1403 sprintf(cmd_buf,
"SET_NETWORK 0 sae_password \"%s\"", AP_security_PreSharedKey);
1404 int status = wpaCtrlSendCmd(cmd_buf);
1405 if(strstr(return_buf,
"FAIL") != NULL)
1407 WIFI_LOG_ERROR(
"Failed to set sae_password\n");
1412 sprintf(cmd_buf,
"SET_NETWORK 0 psk \"%s\"", AP_security_PreSharedKey);
1413 wpaCtrlSendCmd(cmd_buf);
1414 if(strstr(return_buf,
"FAIL") != NULL){
1415 WIFI_LOG_INFO(
"Password may not be falling within spec\n");
1418 if (callback_connect)
1419 (*callback_connect)(1, AP_SSID, &connError);
1421 WIFI_LOG_ERROR(
"erorr connecting to BSS (%d), but user didn't supply callback\n",
1424 pthread_mutex_unlock(&wpa_sup_lock);
1438 WIFI_LOG_INFO(
"Security mode is WPA Enterprise\n");
1439 sprintf(cmd_buf,
"SET_NETWORK 0 key_mgmt WPA-EAP");
1440 wpaCtrlSendCmd(cmd_buf);
1445 wpaCtrlSendCmd(
"SET_NETWORK 0 key_mgmt NONE");
1446 wpaCtrlSendCmd(
"SET_NETWORK 0 auth_alg OPEN SHARED");
1453 if (strlen(AP_security_PreSharedKey) == 5 || strlen(AP_security_PreSharedKey) ==13)
1454 sprintf(cmd_buf,
"SET_NETWORK 0 wep_key0 \"%s\"", AP_security_PreSharedKey);
1456 sprintf(cmd_buf,
"SET_NETWORK 0 wep_key0 %s", AP_security_PreSharedKey);
1458 wpaCtrlSendCmd(cmd_buf);
1461 WIFI_LOG_INFO(
"None\n");
1462 sprintf(cmd_buf,
"SET_NETWORK 0 key_mgmt NONE");
1463 wpaCtrlSendCmd(cmd_buf);
1469 wpaCtrlSendCmd(
"SET_NETWORK 0 scan_ssid 1");
1480 WIFI_LOG_INFO(
"Setting TKIP values\n");
1482 wpaCtrlSendCmd(
"SET_NETWORK 0 pairwise CCMP TKIP");
1484 wpaCtrlSendCmd(
"SET_NETWORK 0 group CCMP TKIP");
1486 wpaCtrlSendCmd(
"SET_NETWORK 0 proto WPA RSN");
1495 WIFI_LOG_INFO(
"EAP Identity %s\n", eapIdentity);
1496 sprintf(cmd_buf,
"SET_NETWORK 0 identity \"%s\"", eapIdentity);
1498 wpaCtrlSendCmd(cmd_buf);
1500 wpaCtrlSendCmd(
"SET_NETWORK 0 eap TLS");
1503 WIFI_LOG_INFO(
"The carootcert:%s\n", carootcert);
1504 WIFI_LOG_INFO(
"The clientcert:%s\n", clientcert);
1505 WIFI_LOG_INFO(
"The privatekey:%s\n", privatekey);
1506 WIFI_LOG_DEBUG(
"The PSK key:%s\n", AP_security_PreSharedKey);
1507 WIFI_LOG_DEBUG(
"The KeyP key:%s\n", AP_security_KeyPassphrase);
1510 if (access(carootcert, F_OK) != -1){
1512 WIFI_LOG_INFO(
"CA Root certificate exists\n");
1513 sprintf(cmd_buf,
"SET_NETWORK 0 ca_cert \"%s\"", carootcert);
1514 wpaCtrlSendCmd(cmd_buf);
1517 if (access(clientcert, F_OK) != -1){
1519 WIFI_LOG_INFO(
"Client Certificate exists\n");
1520 sprintf(cmd_buf,
"SET_NETWORK 0 client_cert \"%s\"", clientcert);
1521 wpaCtrlSendCmd(cmd_buf);
1524 if (access(privatekey, F_OK) != -1){
1526 WIFI_LOG_INFO(
"Private Key exists\n");
1527 sprintf(cmd_buf,
"SET_NETWORK 0 private_key \"%s\"", privatekey);
1528 wpaCtrlSendCmd(cmd_buf);
1530 sprintf(cmd_buf,
"SET_NETWORK 0 private_key_passwd \"%s\"", AP_security_KeyPassphrase);
1531 WIFI_LOG_INFO(
"Command is:%s\n", cmd_buf);
1532 wpaCtrlSendCmd(cmd_buf);
1535 wpaCtrlSendCmd(
"SET_NETWORK 0 mode 0");
1537 snprintf (ssid_to_find,
sizeof (ssid_to_find),
"%s", AP_SSID);
1538 WIFI_LOG_INFO(
"Setting ssid_to_find to [%s]\n", ssid_to_find);
1540 wpaCtrlSendCmd(
"ENABLE_NETWORK 0");
1541 wpaCtrlSendCmd(
"REASSOCIATE");
1544 WIFI_LOG_INFO(
"Connecting to the specified access point\n");
1547 if (callback_connect) (*callback_connect)(1, AP_SSID, &connError);
1550 WIFI_LOG_INFO(
"Leaving WiFi Connect Endpoint function\n");
1551 pthread_mutex_unlock(&wpa_sup_lock);
1557 char *saveptr = NULL;
1558 static char ssid[32]={0};
1559 static char bssid[20]={0};
1560 static char security[64]={0};
1561 static char passphrase[64]={0};
1562 static char wep_key[128]={0};
1567 if(!bUpdatedSSIDInfo)
1569 strcpy(pairedSSIDInfo->
ap_ssid, ssid);
1570 strcpy(pairedSSIDInfo->
ap_bssid, bssid);
1576 f = fopen(
"/opt/secure/wifi/wpa_supplicant.conf",
"r");
1579 WIFI_LOG_ERROR(
"Failed to open wpa_supplicant.conf\n");
1582 while (fgets(buf,
sizeof(buf), f) != NULL)
1584 tokenKey=strtok_r(buf,
"\"=", &saveptr);
1585 if (tokenKey == NULL)
1587 tokenValue=strtok_r(NULL,
"\"=\n", &saveptr);
1588 trimSpace(tokenKey);
1589 if((tokenValue != NULL) && (strcasecmp(tokenKey,
"ssid") == 0))
1591 strcpy(pairedSSIDInfo->
ap_ssid,tokenValue);
1592 strcpy(ssid,tokenValue);
1595 else if((tokenValue != NULL) && (strcasecmp(tokenKey,
"psk") == 0))
1598 strcpy(passphrase,tokenValue);
1600 else if((tokenValue != NULL) && (strcasecmp(tokenKey,
"bssid") == 0))
1602 strcpy(pairedSSIDInfo->
ap_bssid,tokenValue);
1603 strcpy(bssid,tokenValue);
1605 else if((tokenValue != NULL) && (strcasecmp(tokenKey,
"key_mgmt") == 0))
1607 trimSpace(tokenValue);
1609 strcpy(security,tokenValue);
1611 else if((tokenValue != NULL) && (strstr(tokenKey,
"wep_key") != 0))
1613 trimSpace(tokenValue);
1614 strcpy(pairedSSIDInfo->
ap_wep_key,tokenValue);
1615 strcpy(wep_key,tokenValue);
1617 strcpy(passphrase,tokenValue);
1622 if(pairedSSIDInfo->
ap_ssid[0] ==
'\0') {
1623 WIFI_LOG_ERROR(
"No SSID in wpa_supplicant.conf\n");
1624 telemetry_event_d(
"WIFIV_ERR_NoSSIDconf", 1);
1628 WIFI_LOG_DEBUG(
"%s: ap_ssid=[%s], ap_bssid=[%s]\n",
1634 if (pairedSSIDInfo->
ap_ssid[0] !=
'\0' && pairedSSIDInfo->
ap_bssid[0] ==
'\0')
1636 pthread_mutex_lock(&wpa_sup_lock);
1637 int retStatus = wpaCtrlSendCmd(
"STATUS");
1638 if (retStatus == -2)
1639 telemetry_event_d(
"WIFIV_WARN_hal_timeout", 1);
1640 const char* current_bssid = getValue(return_buf,
"bssid");
1641 WIFI_LOG_DEBUG(
"%s: current_bssid=[%s]\n", __FUNCTION__, current_bssid);
1644 const char *ssid_ptr = getValue((
char*) (strchr(current_bssid,
'\0') + 1),
"ssid");
1645 WIFI_LOG_DEBUG(
"%s: ssid_ptr=[%s]\n", __FUNCTION__, ssid_ptr);
1648 char current_ssid[MAX_SSID_LEN+1] = {0};
1649 printf_decode ((u8*)current_ssid,
sizeof(current_ssid), ssid_ptr);
1650 WIFI_LOG_DEBUG(
"%s: current_ssid=[%s]\n", __FUNCTION__, current_ssid);
1651 if (strcmp(pairedSSIDInfo->
ap_ssid, current_ssid) == 0)
1653 snprintf (pairedSSIDInfo->
ap_bssid,
sizeof(pairedSSIDInfo->
ap_bssid),
"%s", current_bssid);
1654 snprintf (bssid,
sizeof(bssid),
"%s", current_bssid);
1655 WIFI_LOG_DEBUG(
"%s: current_ssid matches ap_ssid. ap_bssid set to [%s]\n",
1656 __FUNCTION__, pairedSSIDInfo->
ap_bssid);
1660 pthread_mutex_unlock(&wpa_sup_lock);
1668 WIFI_LOG_INFO(
"SSID Index is not applicable here since this is a STA.. Printing SSID Index:%d\n", ssidIndex);
1670 WIFI_LOG_INFO(
"Received request to disconnect from AP\n");
1672 wpaCtrlSendCmd(
"DISCONNECT");
1678 INT wifi_clearSSIDInfo(INT ssidIndex) {
1680 int status = RETURN_ERR;
1682 pthread_mutex_lock(&wpa_sup_lock);
1683 if (wpaCtrlSendCmd(
"REMOVE_NETWORK 0") ==
RETURN_OK) {
1684 if(wpaCtrlSendCmd(
"SAVE_CONFIG") ==
RETURN_OK) {
1685 WIFI_LOG_INFO(
"Cleared ssid info successfully. \n");
1688 WIFI_LOG_ERROR(
"Error in saving configuration. \n ");
1691 WIFI_LOG_ERROR(
"Error in removing network. \n");
1693 pthread_mutex_unlock(&wpa_sup_lock);
1698 #ifdef WIFI_CLIENT_ROAMING
1700 static int wifi_set_signal_monitor(
int rssi_threshold)
1702 int status = RETURN_ERR;
1703 char cmd[BUFF_LEN_64];
1705 memset(cmd,0,
sizeof(cmd));
1706 sprintf(cmd,
"SIGNAL_MONITOR THRESHOLD=%d HYSTERESIS=2",rssi_threshold);
1707 pthread_mutex_lock(&wpa_sup_lock);
1708 wpaCtrlSendCmd(
"SIGNAL_MONITOR");
1709 status = wpaCtrlSendCmd(cmd);
1710 pthread_mutex_unlock(&wpa_sup_lock);
1712 WIFI_LOG_INFO(
"Successfully started RSSI Signal monitor.\n ");
1714 WIFI_LOG_ERROR(
"Failed to start RSSI Signal monitor. !\n ");
1719 static int wifi_is_valid_threshold(
int threshold)
1721 return ((threshold <= 0) && (threshold >= -200));
1729 int refreshNeeded = 0;
1731 if(NULL == pRoamingCtrlCfg) {
1732 WIFI_LOG_ERROR(
"Input pointer is NULL \n");
1735 memset(¤tCfg,0,
sizeof(currentCfg));
1738 status = wifi_getRoamingControl(ssidIndex,¤tCfg);
1740 if(currentCfg.roamingEnable != pRoamingCtrlCfg->roamingEnable) {
1741 snprintf(cmd_buf,
sizeof(cmd_buf),
"SET roaming_enable %d", pRoamingCtrlCfg->roamingEnable);
1742 pthread_mutex_lock(&wpa_sup_lock);
1743 status = wpaCtrlSendCmd(cmd_buf);
1744 pthread_mutex_unlock(&wpa_sup_lock);
1745 refreshNeeded =
true;
1747 WIFI_LOG_ERROR(
"Failed to set roaming enable.! \n");
1750 WIFI_LOG_INFO(
"Successfully set roamingEnable to %d\n", pRoamingCtrlCfg->roamingEnable);
1752 WIFI_LOG_DEBUG(
"Trying to set same value for roamingEnable, Ignoring SET operation.\n");
1754 pstRoamingCtrl.roamingEnable = pRoamingCtrlCfg->roamingEnable;
1762 if(currentCfg.preassnBestThreshold != pRoamingCtrlCfg->preassnBestThreshold && wifi_is_valid_threshold(pRoamingCtrlCfg->preassnBestThreshold)) {
1763 snprintf(cmd_buf,
sizeof(cmd_buf),
"SET pre_assn_best_threshold_level %d", pRoamingCtrlCfg->preassnBestThreshold);
1764 pthread_mutex_lock(&wpa_sup_lock);
1765 status = wpaCtrlSendCmd(cmd_buf);
1766 pthread_mutex_unlock(&wpa_sup_lock);
1768 WIFI_LOG_ERROR(
"Failed to set pre_assn_best_threshold_level.! \n");
1771 WIFI_LOG_INFO(
"Successfully set preassnBestThreshold to %d\n", pRoamingCtrlCfg->preassnBestThreshold);
1772 }
else if(currentCfg.preassnBestThreshold == pRoamingCtrlCfg->preassnBestThreshold)
1773 WIFI_LOG_DEBUG(
"Trying to set same value for preassnBestThreshold, Ignoring SET operation.\n");
1775 WIFI_LOG_ERROR(
"Failed to set pre_assn_best_threshold_level - Invalid value = %d \n",pRoamingCtrlCfg->preassnBestThreshold);
1778 pstRoamingCtrl.preassnBestThreshold = pRoamingCtrlCfg->preassnBestThreshold;
1780 if(currentCfg.preassnBestDelta != pRoamingCtrlCfg->preassnBestDelta) {
1781 snprintf(cmd_buf,
sizeof(cmd_buf),
"SET pre_assn_best_delta_level %d", pRoamingCtrlCfg->preassnBestDelta);
1782 pthread_mutex_lock(&wpa_sup_lock);
1783 status = wpaCtrlSendCmd(cmd_buf);
1784 pthread_mutex_unlock(&wpa_sup_lock);
1786 WIFI_LOG_ERROR(
"Failed to set pre_assn_best_delta_level.! \n");
1789 WIFI_LOG_INFO(
"Successfully set preassnBestDelta to %d\n", pRoamingCtrlCfg->preassnBestDelta);
1791 WIFI_LOG_DEBUG(
"Trying to set same value for preassnBestDelta, Ignoring SET operation.\n");
1793 pstRoamingCtrl.preassnBestDelta = pRoamingCtrlCfg->preassnBestDelta;
1796 if(currentCfg.roam80211kvrEnable != pRoamingCtrlCfg->roam80211kvrEnable) {
1797 snprintf(cmd_buf,
sizeof(cmd_buf),
"SET kvr_enable %d", pRoamingCtrlCfg->roam80211kvrEnable);
1798 pthread_mutex_lock(&wpa_sup_lock);
1799 wpaCtrlSendCmd(cmd_buf);
1800 pthread_mutex_unlock(&wpa_sup_lock);
1801 WIFI_LOG_INFO(
"Successfully set 80211kvrEnable to %d\n", pRoamingCtrlCfg->roam80211kvrEnable);
1803 WIFI_LOG_DEBUG(
"Trying to set same value for 80211kvrEnable,Ignoring SET operation.\n");
1805 pstRoamingCtrl.roam80211kvrEnable = pRoamingCtrlCfg->roam80211kvrEnable;
1808 pthread_mutex_lock(&wpa_sup_lock);
1809 wpaCtrlSendCmd(
"SAVE_CONFIG");
1810 pthread_mutex_unlock(&wpa_sup_lock);
1813 WIFI_LOG_ERROR(
"Failed to get current roaming Config \n");
1817 if(pstRoamingCtrl.selfSteerOverride != pRoamingCtrlCfg->selfSteerOverride) {
1818 pstRoamingCtrl.selfSteerOverride = pRoamingCtrlCfg->selfSteerOverride;
1819 refreshNeeded =
true;
1820 WIFI_LOG_INFO(
"Successfully set selfSteerOverride to %d\n", pstRoamingCtrl.selfSteerOverride);
1822 WIFI_LOG_DEBUG(
"Trying to set same value for selfSteerOverride, Ignoring SET operation.\n");
1825 if((pstRoamingCtrl.roam80211kvrEnable ==
true) && (pstRoamingCtrl.selfSteerOverride ==
false)) {
1826 cur_roaming_mode = WIFI_HAL_ROAMING_MODE_AP_STEERING;
1827 WIFI_LOG_INFO(
"Setting Roaming mode to AP Controlled..\n");
1830 cur_roaming_mode = WIFI_HAL_ROAMING_MODE_SELF_STEERING;
1831 WIFI_LOG_INFO(
"Setting Roaming mode to Self Steering..\n");
1834 if(pstRoamingCtrl.postAssnLevelDeltaConnected != pRoamingCtrlCfg->postAssnLevelDeltaConnected) {
1835 pstRoamingCtrl.postAssnLevelDeltaConnected = pRoamingCtrlCfg->postAssnLevelDeltaConnected;
1836 WIFI_LOG_INFO(
"Successfully set postAssnLevelDeltaConnected to %d\n", pstRoamingCtrl.postAssnLevelDeltaConnected);
1838 WIFI_LOG_DEBUG(
"Trying to set same value for postAssnLevelDeltaConnected,Ignoring SET operation.\n");
1841 if(pstRoamingCtrl.postAssnLevelDeltaDisconnected != pRoamingCtrlCfg->postAssnLevelDeltaDisconnected) {
1842 pstRoamingCtrl.postAssnLevelDeltaDisconnected = pRoamingCtrlCfg->postAssnLevelDeltaDisconnected;
1843 WIFI_LOG_INFO(
"Successfully set postAssnLevelDeltaDisconnected to %d\n", pstRoamingCtrl.postAssnLevelDeltaDisconnected);
1845 WIFI_LOG_DEBUG(
"Trying to set same value for postAssnLevelDeltaDisconnected,Ignoring SET operation.\n");
1848 if(pstRoamingCtrl.postAssnSelfSteerThreshold != pRoamingCtrlCfg->postAssnSelfSteerThreshold && wifi_is_valid_threshold(pRoamingCtrlCfg->postAssnSelfSteerThreshold)) {
1849 pstRoamingCtrl.postAssnSelfSteerThreshold = pRoamingCtrlCfg->postAssnSelfSteerThreshold;
1850 refreshNeeded =
true;
1851 WIFI_LOG_INFO(
"Successfully set postAssnSelfSteerThreshold to %d\n",pstRoamingCtrl.postAssnSelfSteerThreshold);
1852 }
else if(pstRoamingCtrl.postAssnSelfSteerThreshold == pRoamingCtrlCfg->postAssnSelfSteerThreshold) {
1853 WIFI_LOG_DEBUG(
"Trying to set same value for postAssnSelfSteerThreshold,Ignoring SET operation.\n");
1855 WIFI_LOG_ERROR(
"Failed to set postAssnSelfSteerThreshold, Invalid Value = %d.\n",pRoamingCtrlCfg->postAssnSelfSteerThreshold);
1858 if(pstRoamingCtrl.postAssnSelfSteerTimeframe != pRoamingCtrlCfg->postAssnSelfSteerTimeframe && pRoamingCtrlCfg->postAssnSelfSteerTimeframe >= 0) {
1859 pstRoamingCtrl.postAssnSelfSteerTimeframe = pRoamingCtrlCfg->postAssnSelfSteerTimeframe;
1860 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
1861 backOffRefreshed = 1;
1862 WIFI_LOG_INFO(
"Successfully set postAssnSelfSteerTimeframe to %d\n", pstRoamingCtrl.postAssnSelfSteerTimeframe);
1863 }
else if(pRoamingCtrlCfg->postAssnSelfSteerTimeframe < 0 ) {
1864 WIFI_LOG_ERROR(
"Failed to set postAssnSelfSteerTimeframe, Invalid Value = %d.\n",pRoamingCtrlCfg->postAssnSelfSteerTimeframe);
1867 if(pstRoamingCtrl.postAssnBackOffTime != pRoamingCtrlCfg->postAssnBackOffTime) {
1868 pstRoamingCtrl.postAssnBackOffTime = pRoamingCtrlCfg->postAssnBackOffTime;
1869 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
1870 backOffRefreshed = 1;
1871 WIFI_LOG_INFO(
"Successfully set postAssnBackOffTime to %d\n", pstRoamingCtrl.postAssnBackOffTime);
1873 WIFI_LOG_DEBUG(
"Trying to set same value for postAssnBackOffTime,Ignoring SET operation.\n");
1876 if(pstRoamingCtrl.postAssnAPctrlThreshold != pRoamingCtrlCfg->postAssnAPctrlThreshold && wifi_is_valid_threshold(pRoamingCtrlCfg->postAssnAPctrlThreshold)) {
1877 pstRoamingCtrl.postAssnAPctrlThreshold = pRoamingCtrlCfg->postAssnAPctrlThreshold;
1878 refreshNeeded =
true;
1879 WIFI_LOG_INFO(
"Successfully set postAssnAPctrlThreshold to %d\n", pstRoamingCtrl.postAssnAPctrlThreshold);
1880 }
else if(pstRoamingCtrl.postAssnAPctrlThreshold == pRoamingCtrlCfg->postAssnAPctrlThreshold) {
1881 WIFI_LOG_DEBUG(
"Trying to set same value for postAssnAPctrlThreshold,Ignoring SET operation.\n");
1883 WIFI_LOG_ERROR(
"Failed to set postAssnAPctrlThreshold, Invalid Value = %d.\n",pRoamingCtrlCfg->postAssnAPctrlThreshold);
1886 if(pstRoamingCtrl.postAssnAPctrlTimeframe != pRoamingCtrlCfg->postAssnAPctrlTimeframe && pRoamingCtrlCfg->postAssnAPctrlTimeframe >= 0) {
1887 pstRoamingCtrl.postAssnAPctrlTimeframe = pRoamingCtrlCfg->postAssnAPctrlTimeframe;
1888 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
1889 backOffRefreshed = 1;
1890 WIFI_LOG_INFO(
"Successfully set postAssnAPctrlTimeframe to %d\n", pstRoamingCtrl.postAssnAPctrlTimeframe);
1891 }
else if(pstRoamingCtrl.postAssnAPctrlTimeframe == pRoamingCtrlCfg->postAssnAPctrlTimeframe){
1892 WIFI_LOG_DEBUG(
"Trying to set same value for postAssnAPctrlTimeframe,Ignoring SET operation.\n");
1894 WIFI_LOG_ERROR(
"Failed to set postAssnAPctrlTimeframe, Invalid Value = %d.\n",pRoamingCtrlCfg->postAssnAPctrlTimeframe);
1898 if((pstRoamingCtrl.roamingEnable ==
true) && (refreshNeeded ==
true)) {
1899 if(cur_roaming_mode == WIFI_HAL_ROAMING_MODE_SELF_STEERING ) {
1901 wifi_set_signal_monitor(pstRoamingCtrl.postAssnSelfSteerThreshold);
1902 }
else if(cur_roaming_mode == WIFI_HAL_ROAMING_MODE_AP_STEERING) {
1903 wifi_set_signal_monitor(pstRoamingCtrl.postAssnAPctrlThreshold);
1905 }
else if((pstRoamingCtrl.roamingEnable ==
false) && (refreshNeeded ==
true)) {
1907 pthread_mutex_lock(&wpa_sup_lock);
1908 wpaCtrlSendCmd(
"SIGNAL_MONITOR");
1909 pthread_mutex_unlock(&wpa_sup_lock);
1911 if( cur_roaming_state == WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_STARTED) {
1912 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
1913 backOffRefreshed = 1;
1914 pthread_cond_signal(&cond);
1919 status = persist_roaming_config(&pstRoamingCtrl);
1921 WIFI_LOG_ERROR(
"Failed to save roaming Configuration.! \n");
1927 cJSON *pRoamingCtrl_Json_Data = NULL;
1930 if (pRoamingCtrl_data != NULL) {
1931 pRoamingCtrl_Json_Data = cJSON_CreateObject();
1932 if(!pRoamingCtrl_Json_Data) {
1933 WIFI_LOG_ERROR(
"Failed to create JSON object \n");
1937 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"roamingEnable", pRoamingCtrl_data->roamingEnable);
1938 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"preassnBestThreshold", pRoamingCtrl_data->preassnBestThreshold);
1939 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"preassnBestDelta", pRoamingCtrl_data->preassnBestDelta);
1941 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"selfSteerOverride", pRoamingCtrl_data->selfSteerOverride);
1942 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnLevelDeltaConnected", pRoamingCtrl_data->postAssnLevelDeltaConnected);
1943 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnLevelDeltaDisconnected", pRoamingCtrl_data->postAssnLevelDeltaDisconnected);
1944 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnSelfSteerThreshold", pRoamingCtrl_data->postAssnSelfSteerThreshold);
1945 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnSelfSteerTimeframe", pRoamingCtrl_data->postAssnSelfSteerTimeframe);
1946 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnBackOffTime", pRoamingCtrl_data->postAssnBackOffTime);
1948 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnAPctrlThreshold", pRoamingCtrl_data->postAssnAPctrlThreshold);
1949 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"postAssnAPctrlTimeframe", pRoamingCtrl_data->postAssnAPctrlTimeframe);
1950 cJSON_AddNumberToObject(pRoamingCtrl_Json_Data,
"80211kvrEnable", pRoamingCtrl_data->roam80211kvrEnable);
1952 if( writeToPersistentFile(WIFI_ROAMING_CONFIG_FILE , pRoamingCtrl_Json_Data) != 0)
1954 cJSON_Delete(pRoamingCtrl_Json_Data);
1957 WIFI_LOG_ERROR(
"Input config is NULL, failed to save roaming config \n");
1966 WIFI_LOG_DEBUG(
"Entering ... (%s) \n",__FUNCTION__);
1968 if(pRoamingCtrlCfg == NULL) {
1969 WIFI_LOG_ERROR(
"Input Stats is NULL \n");
1974 pthread_mutex_lock(&wpa_sup_lock);
1975 retStatus = wpaCtrlSendCmd(
"GET roaming_controls");
1978 ptr = getValue(return_buf,
"roaming_enable");
1980 WIFI_LOG_ERROR(
"Failure in getting roaming_enable. \n");
1981 retStatus = RETURN_ERR;
1985 pRoamingCtrlCfg->roamingEnable = strtol(ptr,NULL,10);
1986 WIFI_LOG_DEBUG(
"[%s] Roaming Enable = %d\n",__FUNCTION__,pRoamingCtrlCfg->roamingEnable);
1988 ptr = ptr + strlen(ptr) + 1;
1989 ptr = getValue(ptr,
"pre_assn_best_threshold_level");
1991 WIFI_LOG_ERROR(
"Failure in getting pre_assn_best_threshold_level. \n");
1992 retStatus = RETURN_ERR;
1996 pRoamingCtrlCfg->preassnBestThreshold = strtol(ptr,NULL,10);
1997 WIFI_LOG_DEBUG(
"[%s] preassnBestThreshold = %d\n",__FUNCTION__,pRoamingCtrlCfg->preassnBestThreshold);
1999 ptr = ptr + strlen(ptr) + 1;
2000 ptr = getValue(ptr,
"pre_assn_best_delta_level");
2002 WIFI_LOG_ERROR(
"Failure in getting pre_assn_best_delta_level. \n");
2003 retStatus = RETURN_ERR;
2007 pRoamingCtrlCfg->preassnBestDelta = strtol(ptr,NULL,10);
2008 WIFI_LOG_DEBUG(
"[%s] preassnBestDelta = %d\n",__FUNCTION__,pRoamingCtrlCfg->preassnBestDelta);
2010 ptr = ptr + strlen(ptr) + 1;
2011 ptr = getValue(ptr,
"kvr_enable");
2014 WIFI_LOG_ERROR(
"Failure in getting kvr_enable. \n");
2016 pRoamingCtrlCfg->roam80211kvrEnable = strtol(ptr,NULL,10);
2017 WIFI_LOG_DEBUG(
"[%s] roam80211kvrEnable = %d\n",__FUNCTION__,pRoamingCtrlCfg->roam80211kvrEnable);
2021 WIFI_LOG_ERROR(
"GET ROAMING_CONTROLS failed , Status = %d \n",retStatus);
2022 retStatus = RETURN_ERR;
2025 pthread_mutex_unlock(&wpa_sup_lock);
2029 char* readPersistentFile(
char *fileName)
2032 char *fileContent = NULL;
2033 if( 0 == access(fileName, F_OK) )
2035 fp = fopen(fileName,
"r");
2038 WIFI_LOG_ERROR(
"Failed to open persistent file. !\n ");
2043 fseek(fp, 0, SEEK_END);
2044 ch_count = ftell(fp);
2045 fseek(fp, 0, SEEK_SET);
2046 fileContent = (
char *) malloc(
sizeof(
char) * (ch_count + 1));
2047 if(fileContent == NULL) {
2048 WIFI_LOG_ERROR(
"Failed to allocate memory, readPersistentFile failed.\n ");
2052 fread(fileContent, 1, ch_count,fp);
2053 fileContent[ch_count] =
'\0';
2059 WIFI_LOG_ERROR(
"Missing persistent file!\n ");
2063 int writeToPersistentFile (
char* fileName, cJSON* pRoaming_Data)
2066 fp = fopen(fileName,
"w");
2069 WIFI_LOG_ERROR(
"Failed to open persistent file. !\n ");
2074 char* fileContent = cJSON_Print(pRoaming_Data);
2075 if(fileContent != NULL) {
2076 fprintf(fp,
"%s", fileContent);
2078 WIFI_LOG_DEBUG(
"Persistent file saved successfully.\n ");
2080 WIFI_LOG_ERROR(
"Failed to format Json to string. !\n ");
2086 int initialize_roaming_config()
2088 char *pRoamingCtrl_data_file_content = NULL;
2092 cJSON *pRoamingCtrl_json = NULL;
2098 pRoamingCtrl_data.roamingEnable = WIFI_DEFAULT_ROAMING_ENABLE;
2099 pRoamingCtrl_data.preassnBestThreshold = WIFI_DEFAULT_PRE_ASSN_BEST_THRLD;
2100 pRoamingCtrl_data.preassnBestDelta = WIFI_DEFAULT_PRE_ASSN_BEST_DELTA;
2101 pRoamingCtrl_data.selfSteerOverride = WIFI_DEFAULT_SELF_STEER_OVERRIDE_ENABLE;
2102 pRoamingCtrl_data.postAssnLevelDeltaConnected = WIFI_DEFAULT_BEST_DELTA_CONNECTED;
2103 pRoamingCtrl_data.postAssnSelfSteerThreshold = WIFI_DEFAULT_POST_ASSN_SELF_STEER_THRESHOLD;
2104 pRoamingCtrl_data.postAssnSelfSteerTimeframe = WIFI_DEFAULT_POST_ASSN_SELF_STEER_TIMEFRAME;
2105 pRoamingCtrl_data.postAssnBackOffTime = WIFI_DEFAULT_POST_ASSN_BACKOFF_TIME;
2106 pRoamingCtrl_data.postAssnLevelDeltaDisconnected = WIFI_DEFAULT_BEST_DELTA_DISCONNECTED;
2107 pRoamingCtrl_data.postAssnAPctrlThreshold = WIFI_DEFAULT_AP_CONTROL_THRESHOLD;
2108 pRoamingCtrl_data.postAssnAPctrlTimeframe = WIFI_DEFAULT_AP_CONTROL_TIMEFRAME;
2109 pRoamingCtrl_data.roam80211kvrEnable =
false;
2111 pRoamingCtrl_data_file_content = readPersistentFile(WIFI_ROAMING_CONFIG_FILE);
2113 if(NULL == pRoamingCtrl_data_file_content) {
2114 WIFI_LOG_ERROR(
"Failed to read persistent file. !\n ");
2116 if(pRoamingCtrl_data_file_content) {
2117 pRoamingCtrl_json = cJSON_Parse(pRoamingCtrl_data_file_content);
2118 free(pRoamingCtrl_data_file_content);
2121 if(NULL == pRoamingCtrl_json) {
2122 WIFI_LOG_ERROR(
"Failed to parse configuration file !\n ");
2126 if( !(cJSON_GetObjectItem(pRoamingCtrl_json,
"roamingEnable")) || !(cJSON_GetObjectItem(pRoamingCtrl_json,
"preassnBestThreshold") || !(cJSON_GetObjectItem(pRoamingCtrl_json,
"preassnBestDelta")))) {
2127 WIFI_LOG_ERROR(
"Corrupted roaming values, Unable to load intial configs !\n ");
2129 pRoamingCtrl_data.roamingEnable = cJSON_GetObjectItem(pRoamingCtrl_json,
"roamingEnable")->valueint;
2130 pRoamingCtrl_data.preassnBestThreshold = cJSON_GetObjectItem(pRoamingCtrl_json,
"preassnBestThreshold")->valueint;
2131 pRoamingCtrl_data.preassnBestDelta = cJSON_GetObjectItem(pRoamingCtrl_json,
"preassnBestDelta")->valueint;
2133 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"selfSteerOverride")) {
2134 pRoamingCtrl_data.selfSteerOverride = cJSON_GetObjectItem(pRoamingCtrl_json,
"selfSteerOverride")->valueint;
2136 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnLevelDeltaConnected")) {
2137 pRoamingCtrl_data.postAssnLevelDeltaConnected = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnLevelDeltaConnected")->valueint;
2139 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnSelfSteerThreshold")) {
2140 pRoamingCtrl_data.postAssnSelfSteerThreshold = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnSelfSteerThreshold")->valueint;
2142 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnSelfSteerTimeframe")) {
2143 pRoamingCtrl_data.postAssnSelfSteerTimeframe = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnSelfSteerTimeframe")->valueint;
2145 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnBackOffTime")) {
2146 pRoamingCtrl_data.postAssnBackOffTime = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnBackOffTime")->valueint;
2148 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnLevelDeltaDisconnected")) {
2149 pRoamingCtrl_data.postAssnLevelDeltaDisconnected = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnLevelDeltaDisconnected")->valueint;
2151 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnAPctrlThreshold")) {
2152 pRoamingCtrl_data.postAssnAPctrlThreshold = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnAPctrlThreshold")->valueint;
2154 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnAPctrlTimeframe")) {
2155 pRoamingCtrl_data.postAssnAPctrlTimeframe = cJSON_GetObjectItem(pRoamingCtrl_json,
"postAssnAPctrlTimeframe")->valueint;
2157 if(cJSON_GetObjectItem(pRoamingCtrl_json,
"80211kvrEnable")) {
2158 pRoamingCtrl_data.roam80211kvrEnable = cJSON_GetObjectItem(pRoamingCtrl_json,
"80211kvrEnable")->valueint;
2160 cJSON_Delete(pRoamingCtrl_json);
2164 WIFI_LOG_INFO(
"Setting Initial Roaming Configuration :- [roamingEnable=%d,preassnBestThreshold=%d,preassnBestDelta=%d,selfSteerOverride=%d,postAssnLevelDeltaConnected=%d,postAssnSelfSteerThreshold=%d,postAssnSelfSteerTimeframe=%d,postAssnBackOffTime=%d,postAssnLevelDeltaDisconnected=%d,postAssnAPcontrolThresholdLevel=%d,postAssnAPcontrolTimeframe=%d,80211kvrEnable=%d]\n",pRoamingCtrl_data.roamingEnable,pRoamingCtrl_data.preassnBestThreshold,pRoamingCtrl_data.preassnBestDelta,pRoamingCtrl_data.selfSteerOverride,pRoamingCtrl_data.postAssnLevelDeltaConnected,pRoamingCtrl_data.postAssnSelfSteerThreshold,pRoamingCtrl_data.postAssnSelfSteerTimeframe,pRoamingCtrl_data.postAssnBackOffTime,pRoamingCtrl_data.postAssnLevelDeltaDisconnected,pRoamingCtrl_data.postAssnAPctrlThreshold,pRoamingCtrl_data.postAssnAPctrlTimeframe,pRoamingCtrl_data.roam80211kvrEnable);
2166 wifi_setRoamingControl(ssidIndex,&pRoamingCtrl_data);
2170 int get_wifi_self_steer_matching_bss_list(
const char* ssid_to_find,
wifi_neighbor_ap_t neighborAPList[],
int timeout)
2172 char tmpBuff[RETURN_BUF_LENGTH];
2175 int apCnt = 0,matchCount = 0;
2178 WIFI_LOG_INFO(
"Starting scan for best Neighbor SSIDs ... \n");
2180 pthread_mutex_lock(&wpa_sup_lock);
2181 wpaCtrlSendCmd(
"BSS_FLUSH 0");
2182 wpaCtrlSendCmd(
"SCAN");
2183 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED;
2184 pthread_mutex_unlock(&wpa_sup_lock);
2187 while ((cur_scan_state != WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED) &&(retry++ < 10)) {
2188 usleep(timeout*100000);
2191 memset(tmpBuff,0,
sizeof(tmpBuff));
2192 pthread_mutex_lock(&wpa_sup_lock);
2193 wpaCtrlSendCmd(
"SCAN_RESULTS");
2194 log_top5_bssids(return_buf);
2195 strncpy(tmpBuff,return_buf,
sizeof(tmpBuff));
2198 ap_count = parse_scan_results (tmpBuff, strlen (tmpBuff));
2199 for(apCnt = 0;apCnt<ap_count; apCnt++) {
2201 if ((strncmp (ap_list[apCnt].ap_SSID,ssid_to_find,MAX_SSID_LEN) == 0) && (matchCount<MAX_NEIGHBOR_LIMIT)) {
2202 WIFI_LOG_INFO(
"SCAN Results Matching BSS - ssid = [%s] bssid = [%s] rssi = [%d] freq = [%s]\n",
2203 ap_list[apCnt].ap_SSID,ap_list[apCnt].ap_BSSID, ap_list[apCnt].ap_SignalStrength, ap_list[apCnt].ap_OperatingFrequencyBand);
2206 }
else if(matchCount>=MAX_NEIGHBOR_LIMIT) {
2210 pthread_mutex_unlock(&wpa_sup_lock);
2213 #ifdef WIFI_CLIENT_ROAMING
2217 int retStatus = RETURN_ERR;
2221 WIFI_LOG_ERROR(
"BSS count is 0, Failed to get best AP from neighbor list.\n");
2224 if(bestNeighbor == NULL) {
2225 WIFI_LOG_ERROR(
"Input neighbor struct is null, Failed to get best AP from neighbor list.\n");
2229 for(count=0;count<apCount;count++) {
2234 if(bestBss.
ap_SSID[0] !=
'\0') {
2238 WIFI_LOG_INFO(
"Failed to get Best AP. !\n");
2242 static int wifi_getRadioFrequencyFromChannel(
int channel)
2247 else if (channel<14)
2248 return (channel*5)+2407;
2249 else if (channel>=182 && channel<=196)
2250 return (channel*5)+4000;
2251 else if (channel>=36 && channel<=165)
2252 return (channel*5)+5000;
2257 static void incrementBackoff(
int *backOff)
2259 if(*backOff <= WIFI_MAX_POST_ASSN_BACKOFF_TIME) {
2260 *backOff = *backOff*2;
2266 static int isWifiActivelyUsed()
2270 static int start_post_assoc_roaming(WIFI_HAL_ROAMING_MODE roamingMode)
2276 int retStatus = RETURN_ERR;
2278 memset(&neighborAPList,0,
sizeof(neighborAPList));
2283 if(currWifiStats.
sta_SSID[0] ==
'\0') {
2284 WIFI_LOG_ERROR(
"Failed to get current SSID, Skip Roaming. \n");
2288 pthread_mutex_lock(&wifi_roam_lock);
2289 cur_roaming_state = WIFI_HAL_ROAM_STATE_AP_SELECTION;
2290 pthread_mutex_unlock(&wifi_roam_lock);
2291 bssCount = get_wifi_self_steer_matching_bss_list(currWifiStats.
sta_SSID,neighborAPList,timeout);
2293 WIFI_LOG_ERROR(
"No Matching BSS found to Roam. \n");
2294 incrementBackoff(&postAssocBackOffTime);
2297 WIFI_LOG_INFO(
"Got %d matching BSS for SSID %s \n",bssCount,currWifiStats.
sta_SSID);
2305 if(roamingMode == WIFI_HAL_ROAMING_MODE_SELF_STEERING) {
2306 rssiThreshold = pstRoamingCtrl.postAssnSelfSteerThreshold;
2307 }
else if (roamingMode == WIFI_HAL_ROAMING_MODE_AP_STEERING) {
2308 rssiThreshold = pstRoamingCtrl.postAssnAPctrlThreshold;
2311 status = get_best_ap_from_neighbor_list(neighborAPList,bssCount,&bestNeighbor);
2314 WIFI_LOG_ERROR(
"failed to get BSSID from Best BSS.\n");
2315 incrementBackoff(&postAssocBackOffTime);
2317 }
else if(strncmp(currWifiStats.
sta_BSSID,bestNeighbor.
ap_BSSID,MAX_SSID_LEN-1) == 0) {
2318 WIFI_LOG_ERROR(
"Client is already connected to Best BSS, Skipping Roaming operation.\n");
2319 incrementBackoff(&postAssocBackOffTime);
2323 if(isWifiActivelyUsed() ==
true) {
2324 delta = pstRoamingCtrl.postAssnLevelDeltaConnected;
2326 delta = pstRoamingCtrl.postAssnLevelDeltaDisconnected;
2331 WIFI_LOG_ERROR(
"Skipping roam to %s based on RSSI delta,Current RSSI=[%d],Target RSSI=[%d],Delta=[%d] \n",bestNeighbor.
ap_BSSID,(
int)currWifiStats.
sta_RSSI,bestNeighbor.
ap_SignalStrength,delta);
2332 incrementBackoff(&postAssocBackOffTime);
2336 char cmd[BUFF_LEN_64] = {0};
2337 sprintf(cmd,
"ROAM %s",bestNeighbor.
ap_BSSID);
2338 pthread_mutex_lock(&wpa_sup_lock);
2339 int roamStat = wpaCtrlSendCmd(cmd);
2340 pthread_mutex_unlock(&wpa_sup_lock);
2342 WIFI_LOG_INFO(
"WiFi ROAM: Roaming triggered to %s . \n",bestNeighbor.
ap_BSSID);
2343 pthread_mutex_lock(&wifi_roam_lock);
2344 cur_roaming_state = WIFI_HAL_ROAM_STATE_ROAMING_TRIGGERED;
2345 pthread_mutex_unlock(&wifi_roam_lock);
2346 if(bestNeighbor.
ap_SignalStrength >= pstRoamingCtrl.postAssnSelfSteerThreshold) {
2347 postAssocBackOffTime = pstRoamingCtrl.postAssnBackOffTime;
2348 backOffRefreshed = 1;
2349 WIFI_LOG_INFO(
"Successfully roamed to best AP.\n");
2351 WIFI_LOG_INFO(
"Roaming is successful, But RSSI is still low. Increase Backoff\n");
2352 incrementBackoff(&postAssocBackOffTime);
2356 WIFI_LOG_INFO(
"Failed to trigger ROAM operation. \n");
2357 incrementBackoff(&postAssocBackOffTime);
2366 int start_ap_steer_roaming()
2369 char freqList[BUFF_LEN_64];
2370 char cmd[BUFF_LEN_32];
2377 memset(freqList,0,BUFF_LEN_64);
2378 memset(cmd,0,BUFF_LEN_32);
2381 int isRRMSupported = wifi_get_rrm_support();
2382 if(isRRMSupported && (pstRoamingCtrl.roam80211kvrEnable ==
true)) {
2383 WIFI_LOG_INFO(
"RRM is enabled in current connection. trying to get Neighbor report. ! \n");
2384 wifi_rrm_neighbor_rep_request_t nbr_req;
2385 memset(&nbr_req,0,
sizeof(wifi_rrm_neighbor_rep_request_t));
2386 memset(&stRrmNeighborRpt,0,
sizeof(wifi_rrm_neighbor_report_t));
2387 cur_rrm_nbr_rep_state = WIFI_HAL_RRM_NEIGHBOR_REP_STATE_IDLE;
2388 int status = wifi_getRRMNeighborReport(&nbr_req,&stRrmNeighborRpt);
2390 WIFI_LOG_INFO(
"Successfully sent request for RRM Neighbors. \n");
2392 WIFI_LOG_ERROR(
"Failure in getting RRM Neighbor report. \n");
2395 WIFI_LOG_INFO(
"RRM is not supported or Not enabled. \n");
2398 if(stRrmNeighborRpt.neighbor_cnt > 0 && (pstRoamingCtrl.roam80211kvrEnable ==
true)) {
2399 for(apCount=0;apCount<stRrmNeighborRpt.neighbor_cnt;apCount++) {
2401 memset(&freqStr,0,
sizeof(freqStr));
2402 snprintf(freqStr,
sizeof(freqStr),
"%d",stRrmNeighborRpt.neighbor_ap->freq);
2403 if(strstr(freqList,freqStr) == NULL)
2404 pos += snprintf(&freqList[pos],BUFF_LEN_64,
" %s",freqStr);
2406 WIFI_LOG_INFO(
"RRM, Setting scan Freq based on Neighbor report to - %s \n",freqList);
2407 snprintf(cmd,BUFF_LEN_32,
"SET freq_list %s",freqList);
2408 pthread_mutex_lock(&wpa_sup_lock);
2409 wpaCtrlSendCmd(cmd);
2410 pthread_mutex_unlock(&wpa_sup_lock);
2412 WIFI_LOG_INFO(
"802.11K Neighbor report not present, Scanning all channels for Roaming. \n");
2414 start_post_assoc_roaming(WIFI_HAL_ROAMING_MODE_AP_STEERING);
2417 pthread_mutex_lock(&wpa_sup_lock);
2418 wpaCtrlSendCmd(
"SET freq_list 0");
2419 pthread_mutex_unlock(&wpa_sup_lock);
2422 void start_wifi_signal_monitor_timer(
void *arg)
2427 int rssiThreshold = 0;
2428 int timeIncrement = 0;
2429 static int prevTimeFrame = 0;
2430 int nextTimeFrame = 0;
2432 int timeFrame = (
int*) arg;
2433 pthread_mutex_lock(&wifi_roam_lock);
2434 cur_roaming_state = WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_STARTED;
2435 pthread_mutex_unlock(&wifi_roam_lock);
2436 if(!backOffRefreshed) {
2439 if(postAssocBackOffTime > WIFI_MAX_POST_ASSN_BACKOFF_TIME) {
2440 nextTimeFrame = prevTimeFrame + postAssocBackOffTime/2;
2442 nextTimeFrame = timeFrame + postAssocBackOffTime/2;
2445 if(postAssocBackOffTime <= WIFI_MAX_POST_ASSN_BACKOFF_TIME && nextTimeFrame <= WIFI_MAX_POST_ASSN_TIME_FRAME) {
2446 timeFrame = nextTimeFrame;
2447 prevTimeFrame = timeFrame;
2448 }
else if(nextTimeFrame <= WIFI_MAX_POST_ASSN_TIME_FRAME) {
2449 timeFrame = prevTimeFrame + postAssocBackOffTime/2;
2450 prevTimeFrame = timeFrame;
2452 timeFrame = prevTimeFrame;
2454 timeIncrement = postAssocBackOffTime/2;
2457 backOffRefreshed = 0;
2458 prevTimeFrame = timeFrame;
2461 WIFI_LOG_INFO(
"Starting signal monitor thread, TimeFrame = %d with Backoff = %d.\n",timeFrame,timeIncrement);
2462 clock_gettime(CLOCK_MONOTONIC, &to);
2463 to.tv_sec += timeFrame;
2465 pthread_mutex_lock(&wifi_roam_lock);
2466 if((retVal = pthread_cond_timedwait(&cond,&wifi_roam_lock,&to)) == 0) {
2467 WIFI_LOG_INFO(
"Signal strength recovered or connection state changed, lets stop roaming timer. !\n");
2468 cur_roaming_state = WIFI_HAL_ROAM_STATE_ROAMING_IDLE;
2469 pthread_mutex_unlock(&wifi_roam_lock);
2471 else if(retVal == ETIMEDOUT) {
2472 WIFI_LOG_INFO(
"Signal monitor timer expired, RSSI is still lower, trigger roaming operation.\n");
2473 cur_roaming_state = WIFI_HAL_ROAM_STATE_THRESHOLD_TIMER_EXPIRED;
2474 pthread_mutex_unlock(&wifi_roam_lock);
2475 if(cur_roaming_mode == WIFI_HAL_ROAMING_MODE_SELF_STEERING) {
2476 WIFI_LOG_INFO(
"Starting Self steer roaming... \n");
2477 start_post_assoc_roaming(WIFI_HAL_ROAMING_MODE_SELF_STEERING);
2478 rssiThreshold = pstRoamingCtrl.postAssnSelfSteerThreshold;
2479 }
else if(cur_roaming_mode == WIFI_HAL_ROAMING_MODE_AP_STEERING){
2480 WIFI_LOG_INFO(
"Starting AP-Controlled roaming... \n");
2481 start_ap_steer_roaming();
2482 rssiThreshold = pstRoamingCtrl.postAssnAPctrlThreshold;
2484 WIFI_LOG_ERROR(
"Unrecognized roaming mode, skipping Roaming operation.\n");
2487 wifi_set_signal_monitor(rssiThreshold);
2489 WIFI_LOG_ERROR(
"Wifi Roam conditional wait failed.! \n");
2490 pthread_mutex_unlock(&wifi_roam_lock);
2492 pthread_mutex_lock(&wifi_roam_lock);
2493 cur_roaming_state = WIFI_HAL_ROAM_STATE_ROAMING_IDLE;
2494 pthread_mutex_unlock(&wifi_roam_lock);
2497 int wifi_get_rrm_support()
2503 pthread_mutex_lock(&wpa_sup_lock);
2504 retStatus = wpaCtrlSendCmd(
"GET_RRM_SUPPORT");
2505 if(retStatus ==
RETURN_OK && return_buf[0] !=
'\0' ) {
2506 rrmSupport = strtol(return_buf,NULL,10);
2508 WIFI_LOG_ERROR(
"Failed to get RRM support.\n");
2510 pthread_mutex_unlock(&wpa_sup_lock);
2523 INT wifi_getRRMNeighborReport(wifi_rrm_neighbor_rep_request_t* nbr_req, wifi_rrm_neighbor_report_t* nbr_rpt)
2525 int retStatus = RETURN_ERR;
2531 memset(bssid,0,
sizeof(bssid));
2533 WIFI_LOG_ERROR(
"Client is not associated, RRM request failed.\n");
2537 retStatus = wifi_sendNeighborReportRequest(nbr_req);
2538 if(retStatus == 0) {
2541 while (((cur_rrm_nbr_rep_state != WIFI_HAL_RRM_NEIGHBOR_REP_RECEIVED)) &&(retry++ < 10)) {
2545 WIFI_LOG_ERROR(
"Failed to get RRM response, Request timed out.!\n");
2546 }
else if(cur_rrm_nbr_rep_state == WIFI_HAL_RRM_NEIGHBOR_REP_REQUEST_FAILED) {
2547 WIFI_LOG_ERROR(
"RRM neighbor report request failed.\n");
2548 }
else if (cur_rrm_nbr_rep_state == WIFI_HAL_RRM_NEIGHBOR_REP_STATE_INTERNAL_ERROR) {
2549 WIFI_LOG_ERROR(
"RRM neighbor report report received, But failed to parse.\n");
2550 }
else if (cur_rrm_nbr_rep_state == WIFI_HAL_RRM_NEIGHBOR_REP_RECEIVED) {
2551 WIFI_LOG_INFO(
"RRM Neighbor report succesfully received.\n");
2556 WIFI_LOG_ERROR(
"Failed to send RRM Neighbor Request. \n");
2558 cur_rrm_nbr_rep_state = WIFI_HAL_RRM_NEIGHBOR_REP_STATE_IDLE;
2570 INT wifi_sendNeighborReportRequest(wifi_rrm_neighbor_rep_request_t* nbr_req)
2572 char cmd[BUFF_LEN_64];
2573 int retStatus = RETURN_ERR;
2575 memset(cmd,0,BUFF_LEN_64);
2577 if(nbr_req->ssid[0] !=
'\0') {
2578 WIFI_LOG_DEBUG(
"Sending RRM neighbor request with ssid=%s, lci=%d, civic=%d \n",nbr_req->ssid,nbr_req->lci,nbr_req->civic);
2579 snprintf(cmd,
sizeof(cmd),
"NEIGHBOR_REP_REQUEST ssid=\"%s\" lci=%d civic=%d",nbr_req->ssid,nbr_req->lci,nbr_req->civic);
2581 snprintf(cmd,
sizeof(cmd),
"NEIGHBOR_REP_REQUEST");
2583 pthread_mutex_lock(&wpa_sup_lock);
2584 retStatus = wpaCtrlSendCmd(cmd);
2585 pthread_mutex_unlock(&wpa_sup_lock);
2586 if(retStatus == 0) {
2587 WIFI_LOG_INFO(
"RRM Neighbor report request sent successfully \n");
2590 WIFI_LOG_ERROR(
"Failed to send RRM Request, cmd = %s \n",cmd);
2604 int parse_neighbor_report_response(
char *nbr_response,wifi_rrm_neighbor_report_t *nbr_rpt)
2607 char bssid[BUFF_LEN_32];
2608 char info[BUFF_LEN_32];
2609 int op_class,channel,phy_type;
2611 if(!nbr_response || nbr_response[0] ==
'\0') {
2612 WIFI_LOG_ERROR(
"Unable to parse - Neighbor response is NULL. \n");
2614 }
else if(!nbr_rpt) {
2615 WIFI_LOG_ERROR(
"Unable to parse - Input Neighbor report is NULL \n");
2621 if(sscanf(nbr_response,
"%*s bssid=%s info=%s op_class=%d chan=%d phy_type=%d",bssid,info,&op_class,&channel,&phy_type) == 5) {
2625 for(i=0;i<nbr_rpt->neighbor_cnt;i++) {
2626 if(strncmp(nbr_rpt->neighbor_ap[i].bssid,bssid,MAX_SSID_LEN) == 0) {
2631 if(!match && (nbr_rpt->neighbor_cnt < MAX_NEIGHBOR_LIMIT)) {
2632 strncpy(nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssid,bssid,
sizeof(nbr_rpt->neighbor_ap->bssid));
2633 strncpy(nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssidInfo,info,
sizeof(nbr_rpt->neighbor_ap->bssidInfo));
2634 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].channel = channel;
2635 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].op_class = op_class;
2636 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].phy_type = phy_type;
2637 nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].freq = wifi_getRadioFrequencyFromChannel(channel);
2638 WIFI_LOG_INFO(
"RRM Neighbor[%d] - Bssid = %s , Info = %s, op_class=%d, Channel = %d, Phy_Type = %d, Freq=%d\n ",nbr_rpt->neighbor_cnt,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssid,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].bssidInfo,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].op_class,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].channel,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].phy_type,nbr_rpt->neighbor_ap[nbr_rpt->neighbor_cnt].freq);
2639 nbr_rpt->neighbor_cnt+=1;
2641 WIFI_LOG_INFO(
"BSSID already present in neighbor list, Skipping %s \n",bssid);
2643 WIFI_LOG_INFO(
"Maximum neighbors added to list, Skipping.\n");
2646 WIFI_LOG_INFO(
"Failed to Parse Neighbor Report - Skipping entry\n");
2650 #endif // WIFI_CLIENT_ROAMING
2652 WiFiHalStatus_t getwifiStatusCode()
2654 return WIFISTATUS_HAL_COMPLETED;
2657 void wifi_printf(
const char *level,
const char *format, ...)
2662 gettimeofday(&now, NULL);
2663 printf(
"[%6s] %9ld.%06ld - ", level, now.tv_sec, now.tv_usec);
2665 va_start(arg_list, format);
2666 vprintf(format, arg_list);