28 #include <wifi_common_hal.h>
33 #include <sys/ioctl.h>
34 #include <netinet/in.h>
38 #define MAX_SSID_LEN 32
39 #define MAX_VERSION_LEN 16
40 #define BUFF_LEN_1024 1024
41 #define BUFF_LEN_64 64
42 extern BOOL bNoAutoScan;
44 ULONG ssid_number_of_entries = 0;
47 typedef enum _SsidSecurity
49 NET_WIFI_SECURITY_NONE = 0,
50 NET_WIFI_SECURITY_WEP_64,
51 NET_WIFI_SECURITY_WEP_128,
52 NET_WIFI_SECURITY_WPA_PSK_TKIP,
53 NET_WIFI_SECURITY_WPA_PSK_AES,
54 NET_WIFI_SECURITY_WPA2_PSK_TKIP,
55 NET_WIFI_SECURITY_WPA2_PSK_AES,
56 NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP,
57 NET_WIFI_SECURITY_WPA_ENTERPRISE_AES,
58 NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP,
59 NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES,
60 NET_WIFI_SECURITY_WPA_WPA2_PSK,
61 NET_WIFI_SECURITY_WPA_WPA2_ENTERPRISE,
62 NET_WIFI_SECURITY_WPA3_PSK_AES,
63 NET_WIFI_SECURITY_WPA3_SAE,
64 NET_WIFI_SECURITY_NOT_SUPPORTED = 99,
148 void wifi_usleep(useconds_t usec)
151 if (usec >= 1000000) {
152 (void) sleep((
unsigned int) (usec / 1000000));
159 INT is_null_pointer(
char* str) {
160 if ((str !=NULL) && (str[0]==
'\0')) {
166 #include <wpa_ctrl.h>
171 extern size_t printf_decode(u8 *buf,
size_t maxlen,
const char *str);
175 #define CA_ROOT_CERT_PATH "/opt/lnf/ca-chain.cert.pem"
176 #define CA_CLIENT_CERT_PATH "/opt/lnf/xi5device.cert.pem"
177 #define CA_PRIVATE_KEY_PATH "/opt/lnf/xi5device.key.pem"
178 #define WPA_SUP_CONFIG "/opt/secure/wifi/wpa_supplicant.conf"
180 #define WPA_SUP_TIMEOUT 7000
181 #define WPA_SUP_PING_INTERVAL 60
184 WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE,
185 WIFI_HAL_WPA_SUP_SCAN_STATE_CMD_SENT,
186 WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED,
187 WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED,
188 } WIFI_HAL_WPA_SUP_SCAN_STATE;
190 char* getValue(
const char *buf,
const char *keyword);
191 int wpaCtrlSendCmd(
char *cmd);
192 int get_wifi_self_steer_matching_bss_list(
const char* ssid_to_find,
wifi_neighbor_ap_t neighborAPList[],
int timeout);
193 static INT getFrequencyListFor_Band(WIFI_HAL_FREQ_BAND band,
char *output_string);
194 BOOL isDualBandSupported();
195 #ifdef WIFI_CLIENT_ROAMING
196 int initialize_roaming_config();
199 bool init_done=
false;
200 extern bool stop_monitor;
201 uint32_t g_wpa_sup_pid=0, ap_count=0;
202 struct wpa_ctrl *g_wpa_ctrl= NULL;
203 struct wpa_ctrl *g_wpa_monitor = NULL;
204 WIFI_HAL_WPA_SUP_SCAN_STATE cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
205 pthread_mutex_t wpa_sup_lock;
206 char cmd_buf[1024], return_buf[96*1024];
212 static bool wifi_interfaceExists(
const char * ifname);
213 bool wifi_interfaceIsWireless(
const char * ifname);
214 static void wifi_interfaceSetEnabled(
const char * ifname,
bool enabled);
216 static char * wifi_readFile(
const char * fname,
bool sysfs);
218 pthread_t monitor_thread;
219 pthread_t wpa_health_mon_thread;
220 void* monitor_thread_task(
void *param);
221 void* monitor_wpa_health(
void* param);
222 static int wifi_getWpaSupplicantStatus();
223 static int wifi_openWpaSupConnection();
224 static INT wifi_getRadioSignalParameter (
const CHAR* parameter, CHAR *output_string);
227 INT wifi_getHalVersion(CHAR *output_string)
233 if(ret <= 0 || ret > MAX_VERSION_LEN) {
234 WIFI_LOG_ERROR(
"Failed generate HAL Version, ret = %d.\n",ret );
235 retStatus = RETURN_ERR;
238 WIFI_LOG_ERROR(
"Failed to get HAL Version - Input String is NULL.\n" );
239 retStatus = RETURN_ERR;
243 static INT getFrequencyListFor_Band(WIFI_HAL_FREQ_BAND band,
char *output_string)
245 if(output_string == NULL)
247 WIFI_LOG_ERROR(
"[%s] Memory not allocated for output_string \n",__FUNCTION__);
253 char *saveptr = NULL;
256 INT ret = RETURN_ERR;
258 WIFI_LOG_INFO(
"in getFrequencyListFor_Band ..\n");
259 pthread_mutex_lock(&wpa_sup_lock);
260 int ret_status = wpaCtrlSendCmd(
"GET_CAPABILITY freq");
263 if( band == WIFI_HAL_FREQ_BAND_5GHZ)
265 s = strstr(return_buf,
"Mode[A] Channels:");
266 t = strstr(return_buf,
"Mode[B] Channels:");
269 else if (band == WIFI_HAL_FREQ_BAND_24GHZ)
271 s = strstr(return_buf,
"Mode[G] Channels:");
272 t = strstr(return_buf,
"Mode[A] Channels:");
277 WIFI_LOG_INFO(
"[%s] Error in selecting the frequencies\n",__FUNCTION__);
283 r = strtok_r(s,
"\n", &saveptr);
288 r = strtok_r(NULL,
"\n", &saveptr);
295 char *ptr = lines[k];
296 strtok_r(ptr,
"=", &ptr);
297 char *tmp = strtok_r(ptr,
" ", &saveptr);
298 strcpy(lines[k],tmp);
299 strcat(output_string,lines[k]);
300 strcat(output_string,
" ");
302 WIFI_LOG_DEBUG(
"frequencies selected : [%s] \n",output_string);
308 WIFI_LOG_ERROR(
"[%s] Error in getting supported bands- Unable to get Channel Capability\n",__FUNCTION__);
311 pthread_mutex_unlock(&wpa_sup_lock);
316 char * wifi_readFile(
const char * fname,
bool sysfs)
326 WIFI_LOG_INFO(
"readFile(): File Open Error \n" );
329 fseek(fp,0L,SEEK_END);
331 fseek(fp,0L,SEEK_SET);
334 buf=(
char *)calloc(fBytes+1,
sizeof(
char));
337 WIFI_LOG_INFO(
"readFile(): Memory Allocation Error \n" );
341 freadBytes = fread(buf,
sizeof(
char),fBytes,fp);
342 if (!sysfs && (freadBytes != fBytes))
344 WIFI_LOG_ERROR(
" readFile(): Error occured during fread(), freadBytes= %ld \n" ,freadBytes);
352 WIFI_LOG_ERROR(
"readFile(): File is empty \n" );
358 bool wifi_interfaceExists(
const char * ifname)
361 struct if_nameindex *ifp, *ifpsave;
363 ifpsave = ifp = if_nameindex();
366 WIFI_LOG_DEBUG(
"if_nameindex call failed: %s\n", strerror(errno));
369 while(ifp->if_index) {
370 WIFI_LOG_DEBUG(
"comparing interface name '%s' with '%s' to check if exists\n",
371 ifp->if_name, ifname);
372 if (strcmp(ifp->if_name, ifname) == 0) {
378 if_freenameindex(ifpsave);
385 return wifi_initWithConfig(NULL);
392 pthread_attr_t thread_attr;
395 wifi_initContext(&g_ctx, conf);
397 WIFI_LOG_INFO(
"Initializing Generic WiFi hal.\n");
398 if(init_done ==
true) {
399 WIFI_LOG_INFO(
"Wifi init has already been done\n");
403 WIFI_LOG_INFO(
"TELEMETRY_WIFI_WPA_SUPPLICANT:ENABLED \n");
405 WIFI_LOG_INFO(
"Starting wpa_supplicant service \n");
408 system(
"systemctl start wpa_supplicant");
410 system(
"/etc/init.d/wpa_supplicant.service restart");
413 bool interfaceExists = wifi_interfaceExists(g_ctx.conf.wlan_Interface);
419 while (retry++ < 75) {
420 WIFI_LOG_INFO(
"opening control path:%s\n", g_ctx.ctrl_path);
421 g_wpa_ctrl = wpa_ctrl_open(g_ctx.ctrl_path);
422 if (g_wpa_ctrl != NULL)
break;
423 WIFI_LOG_INFO(
"ctrl_open returned NULL \n");
424 wifi_usleep(1000000);
427 if (g_wpa_ctrl == NULL) {
428 WIFI_LOG_INFO(
"wpa_ctrl_open failed for control interface \n");
432 g_wpa_monitor = wpa_ctrl_open(g_ctx.ctrl_path);
433 if ( g_wpa_monitor == NULL ) {
434 WIFI_LOG_INFO(
"wpa_ctrl_open failed for monitor interface \n");
438 if ( wpa_ctrl_attach(g_wpa_monitor) != 0) {
439 WIFI_LOG_INFO(
"wpa_ctrl_attach failed \n");
442 if (pthread_mutex_init(&wpa_sup_lock, NULL) != 0)
444 WIFI_LOG_INFO(
"mutex init failed\n");
448 pthread_attr_init(&thread_attr);
449 pthread_attr_setstacksize(&thread_attr, 256*1024);
451 ret = pthread_create(&monitor_thread, &thread_attr, monitor_thread_task, NULL);
455 WIFI_LOG_INFO(
"Monitor thread creation failed \n");
459 WIFI_LOG_INFO(
"Starting wpa_supplicant health monitor thread \n");
460 ret = pthread_create(&wpa_health_mon_thread, NULL, monitor_wpa_health, NULL);
462 WIFI_LOG_INFO(
"WPA health monitor thread creation failed \n");
465 #ifdef WIFI_CLIENT_ROAMING
467 initialize_roaming_config();
475 WIFI_LOG_WARN(
"wireless interface %s doesn't exist\n",
476 g_ctx.conf.wlan_Interface);
484 WIFI_LOG_INFO(
"Stopping monitor thread\n");
486 WIFI_LOG_INFO(
"Disconnecting from the network\n");
490 if(init_done ==
false) {
491 WIFI_LOG_INFO(
"Previous wifi init is not successful\n");
496 wpaCtrlSendCmd(
"DISCONNECT");
497 wpaCtrlSendCmd(
"DISABLE_NETWORK 0");
501 wifi_usleep(1000000);
503 if ((wpa_health_mon_thread) && ( pthread_cancel(wpa_health_mon_thread) == -1 )) {
504 WIFI_LOG_ERROR(
"[%s:%d] wpa health monitor thread cancel failed! \n",__FUNCTION__, __LINE__);
508 pthread_join (wpa_health_mon_thread, NULL);
509 pthread_join (monitor_thread, NULL);
511 WIFI_LOG_INFO(
"Stopping wpa_supplicant service\n");
513 system(
"systemctl stop wpa_supplicant");
515 system(
"/etc/init.d/wpa_supplicant.service stop");
519 wpa_ctrl_close(g_wpa_ctrl);
524 wpa_ctrl_close(g_wpa_monitor);
525 g_wpa_monitor = NULL;
557 struct ifaddrs * addrs;
558 WIFI_LOG_INFO(
"bringing down all wireless interfaces\n");
560 if (getifaddrs(&addrs) == 0) {
561 struct ifaddrs * itr;
562 for (itr = addrs; itr; itr = itr->ifa_next) {
563 if (itr->ifa_addr == NULL || itr->ifa_addr->sa_family != AF_PACKET)
565 if (wifi_interfaceIsWireless(itr->ifa_name)) {
566 WIFI_LOG_INFO(
"bring down wireless interface %s", itr->ifa_name);
567 wifi_interfaceSetEnabled(itr->ifa_name,
false);
573 WIFI_LOG_WARN(
"error trying to disable wireless interfaces. getifaddrs failed. %d", errno);
580 static void get_security_mode_and_encryption_type(
const char* flags,
char* auth,
char* encrypt)
582 const char* wpa2 = NULL;
583 const char* wpa = NULL;
584 const char* eap = NULL;
585 const char* ccmp = NULL;
586 const char* sae = NULL;
587 const char* tkip = NULL;
588 const char* wep = NULL;
589 const char* none = NULL;
591 wpa = strstr(flags,
"WPA-");
592 wpa2 = strstr(flags,
"WPA2-");
593 eap = strstr(flags,
"EAP");
594 ccmp = strstr(flags,
"CCMP");
595 sae = strstr(flags,
"SAE");
596 tkip = strstr(flags,
"TKIP");
597 wep = strstr(flags,
"WEP");
598 none = strstr(flags,
"NONE");
604 strcat(auth,
"WPA-");
606 strcat(auth,
"WPA2-");
608 strcat(auth,
"WPA3-");
610 strcat(auth,
"Enterprise-");
612 strcat(auth,
"WEP-");
614 strcat(auth,
"None-");
617 auth[strlen(auth) - 1] = 0;
620 WIFI_LOG_WARN(
"no auth flags recognized: %s\n", flags);
625 strcat(encrypt,
"TKIP,");
627 strcat(encrypt,
"AES,");
630 encrypt[strlen(encrypt) - 1] = 0;
632 WIFI_LOG_WARN(
"no wpa encrypt flags recognized: %s\n", flags);
635 static void get_security_mode_and_encryption_type(
const char* wpa_supplicant_ap_flags,
char* security_mode,
char* encryption_type)
638 for (
int i = 0; i < len; i++)
640 if (NULL != strcasestr(wpa_supplicant_ap_flags,
wifi_securityModes[i].apSecurityEncryptionString))
647 WIFI_LOG_WARN(
"Unknown flag: %s\n", wpa_supplicant_ap_flags);
648 security_mode[0] =
'\0';
649 encryption_type[0] =
'\0';
653 static int is_zero_bssid(
char* bssid) {
657 return strncmp(bssid,
"00:00:00:00:00:00",17);
663 char *saveptr = NULL;
665 int phyrate, noise, rssi,freq,avgRssi;
670 WIFI_LOG_ERROR(
"Input Stats is NULL \n");
674 bssid = NULL; ssid = NULL;
677 pthread_mutex_lock(&wpa_sup_lock);
678 retStatus = wpaCtrlSendCmd(
"STATUS");
681 bssid = getValue(return_buf,
"bssid");
684 WIFI_LOG_DEBUG(
"BSSID is NULL in Status output\n");
689 ptr = bssid + strlen(bssid) + 1;
690 ssid = getValue(ptr,
"ssid");
693 WIFI_LOG_DEBUG(
"SSID is NULL in Status output\n");
699 if(wpaCtrlSendCmd(
"BSS current") == 0) {
700 char* token = strtok_r(return_buf,
"\n", &saveptr);
701 while(token != NULL) {
702 if(strncmp(token,
"bssid=",6) == 0) {
705 sscanf(token,
"bssid=%18s",stats->
sta_BSSID);
709 else if(strncmp(token,
"flags=",6) == 0) {
711 sscanf(token,
"flags=%64s",flags);
715 token = strtok_r(NULL,
"\n", &saveptr);
718 WIFI_LOG_ERROR(
"Failed to get BSSID from BSS current\n");
723 telemetry_event_d(
"WIFIV_WARN_hal_timeout", 1);
724 WIFI_LOG_ERROR(
"wpaCtrlSendCmd(STATUS) failed - Ret = %d \n",retStatus);
728 retStatus = wpaCtrlSendCmd(
"SIGNAL_POLL");
731 ptr = getValue(return_buf,
"RSSI");
735 WIFI_LOG_ERROR(
"RSSI not in signal poll \n");
742 ptr = ptr + strlen(ptr) + 1;
743 ptr = getValue(ptr,
"LINKSPEED");
746 WIFI_LOG_ERROR(
"LINKSPEED not in signal poll \n");
754 ptr = ptr + strlen(ptr) + 1;
755 ptr = getValue(ptr,
"NOISE");
758 WIFI_LOG_ERROR(
"NOISE not in signal poll \n");
766 ptr = ptr + strlen(ptr) + 1;
767 ptr = getValue(ptr,
"FREQUENCY");
770 WIFI_LOG_ERROR(
"FREQUENCY not in signal poll \n");
774 WIFI_LOG_DEBUG(
"FREQUENCY=%d \t",freq);
776 if((freq / 1000) == 2)
778 else if((freq / 1000) == 5)
781 WIFI_LOG_ERROR(
"Unknown freq band.\n");
784 ptr = ptr + strlen(ptr) + 1;
785 ptr = getValue(ptr,
"AVG_RSSI");
790 WIFI_LOG_DEBUG(
"AVG_RSSI=%d \n",avgRssi);
796 telemetry_event_d(
"WIFIV_ERR_hal_signalpolltimeout", 1);
797 WIFI_LOG_ERROR(
"wpaCtrlSendCmd(SIGNAL_POLL) failed ret = %d\n",retStatus);
800 char wifi_stats_buffer[128];
801 snprintf(wifi_stats_buffer,
sizeof(wifi_stats_buffer),
"bssid=%s,ssid=%s,rssi=%d,phyrate=%d,noise=%d,Band=%s",
803 WIFI_LOG_INFO(
"%s\n", wifi_stats_buffer);
804 telemetry_event_s(
"ap_info_split", wifi_stats_buffer);
806 pthread_mutex_unlock(&wpa_sup_lock);
810 INT parse_scan_results(
char *buf,
size_t len)
815 char *delim_ptr, *ptr, *encrypt_ptr,*security_ptr;
817 if ((len == 0) || (buf == NULL))
return count;
825 ptr = strstr(buf,
"/ ssid");
826 if (ptr == NULL)
return count;
827 ptr += strlen(
"/ ssid") + 1;
830 memset(&ap_list,0,
sizeof(ap_list));
833 while (((delim_ptr=strchr(ptr,
'\t')) != NULL) && (count <
sizeof(ap_list)/
sizeof(
wifi_neighbor_ap_t))) {
836 memcpy(ap_list[count].ap_BSSID, ptr, (delim_ptr-ptr));
837 ap_list[count].
ap_BSSID[delim_ptr-ptr] =
'\0';
842 delim_ptr=strchr(ptr,
'\t');
845 strncpy(freq,ptr,10);
846 int frequency=strtol(freq,NULL,10);
847 ((frequency/1000) == 2)?strcpy(ap_list[count].ap_OperatingFrequencyBand,
"2.4GHz"):strcpy(ap_list[count].ap_OperatingFrequencyBand,
"5GHz");
855 delim_ptr=strchr(ptr,
'\t');
856 memcpy(tmp_str, ptr, (delim_ptr-ptr));
857 tmp_str[delim_ptr-ptr] =
'\0';
863 delim_ptr=strchr(ptr,
'\t');
864 memcpy(flags, ptr, (delim_ptr-ptr));
865 flags[delim_ptr-ptr] =
'\0';
866 memset(ap_list[count].ap_SecurityModeEnabled, 0,
sizeof(ap_list[count].ap_SecurityModeEnabled));
867 memset(ap_list[count].ap_EncryptionMode, 0,
sizeof(ap_list[count].ap_EncryptionMode));
870 get_security_mode_and_encryption_type(flags, security_ptr, encrypt_ptr);
871 if (encrypt_ptr > ap_list[count].ap_EncryptionMode) {
872 *(encrypt_ptr-1)=
'\0';
874 if (security_ptr > ap_list[count].ap_SecurityModeEnabled) {
875 *(security_ptr-1)=
'\0';
880 delim_ptr=strchr(ptr,
'\n');
882 printf_decode ((u8*)ap_list[count].ap_SSID, 64, ptr);
883 WIFI_LOG_INFO(
"decoded SSID=%s (encoded SSID=%s) BSSID=%s flags=%s SecuritymodeEnabled=%s EncryptionMode=%s\n",
884 ap_list[count].ap_SSID, ptr, ap_list[count].ap_BSSID, flags, ap_list[count].ap_SecurityModeEnabled, ap_list[count].ap_EncryptionMode);
890 if(ap_list[count].ap_BSSID[0] !=
'\0' && ap_list[count].ap_SSID[0] !=
'\0')
901 void log_top5_bssids(
const char *scan_results_buffer)
903 static const int BSSID_LEN = 17;
904 char *ptr, *delim_ptr, bssid[BSSID_LEN+1], bssid_split[128] = {0}, *str = bssid_split;
906 if (scan_results_buffer == NULL)
return;
909 ptr = strstr(scan_results_buffer,
"/ ssid");
910 if (ptr == NULL)
return;
911 ptr += strlen(
"/ ssid");
913 for (
int i = 0; i < 5 && ptr && ((delim_ptr = strchr(++ptr,
'\t')) != NULL); ptr = strchr(ptr,
'\n'))
915 if (delim_ptr - ptr != BSSID_LEN)
918 memcpy(bssid, ptr, BSSID_LEN);
919 bssid[BSSID_LEN] =
'\0';
923 for (
char *pr = bssid; *pr; pr++)
928 if (strlen(bssid) == 12)
930 if (i > 0) *str++ =
',';
939 WIFI_LOG_INFO(
"bssid_split = %s\n", bssid_split);
940 telemetry_event_s(
"bssid_split", bssid_split);
945 size_t return_len=
sizeof(return_buf)-1;
948 WIFI_LOG_INFO(
"Starting a single scan..\n");
949 pthread_mutex_lock(&wpa_sup_lock);
950 if (cur_scan_state == WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED) {
951 WIFI_LOG_INFO(
"Scan is already in progress, Waiting for the scan results. \n");
953 WIFI_LOG_INFO(
"No in progress scanning, Starting a fresh scan.\n");
955 wpaCtrlSendCmd(
"BSS_FLUSH 0");
956 wpaCtrlSendCmd(
"SCAN");
957 if (strstr(return_buf,
"FAIL-BUSY") != NULL) {
958 WIFI_LOG_ERROR(
"Scan command returned %s .. waiting \n", return_buf);
959 wpaCtrlSendCmd(
"BSS_FLUSH 0");
960 wifi_usleep(1000000);
961 wpaCtrlSendCmd(
"SCAN");
962 if (strstr(return_buf,
"FAIL-BUSY") != NULL) {
963 WIFI_LOG_ERROR(
"Scan command returned %s FAILED \n", return_buf);
967 WIFI_LOG_INFO(
"Scan command returned %s \n", return_buf);
968 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED;
970 pthread_mutex_unlock(&wpa_sup_lock);
971 while ((cur_scan_state != WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED) &&(retry++ < 1000)) {
972 wifi_usleep(WPA_SUP_TIMEOUT);
974 pthread_mutex_lock(&wpa_sup_lock);
975 if (cur_scan_state != WIFI_HAL_WPA_SUP_SCAN_STATE_RESULTS_RECEIVED) {
976 WIFI_LOG_ERROR(
"Scan timed out retry times = %d \n",retry);
980 WIFI_LOG_INFO(
"Trying to read Scan results \n");
981 wpaCtrlSendCmd(
"SCAN_RESULTS");
982 log_top5_bssids(return_buf);
983 ap_count = parse_scan_results(return_buf, return_len);
984 WIFI_LOG_INFO(
"Scan results contains %d BSSIDs. \n",ap_count);
987 *output_array_size = ap_count;
990 if(*neighbor_ap_array == NULL) {
991 WIFI_LOG_INFO(
"Malloc Memory allocation failure\n");
994 for (i=0; i<*output_array_size; i++)
995 (*neighbor_ap_array)[i] = ap_list[i];
998 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
1000 pthread_mutex_unlock(&wpa_sup_lock);
1004 cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
1006 pthread_mutex_unlock(&wpa_sup_lock);
1010 INT wifi_getSpecificSSIDInfo(
const char* SSID, WIFI_HAL_FREQ_BAND band,
wifi_neighbor_ap_t **filtered_ap_array, UINT *output_array_size)
1012 char freq_list_string[BUF_SIZE];
1016 int ret = RETURN_ERR;
1017 memset(&freq_list_string,0,BUF_SIZE);
1018 memset(&cmd,0,BUF_SIZE);
1019 if(band != WIFI_HAL_FREQ_BAN_NONE)
1021 if(
RETURN_OK == getFrequencyListFor_Band(band,freq_list_string) && freq_list_string != NULL)
1023 WIFI_LOG_INFO(
"Setting scan Freq based on selected Band to - %s \n",freq_list_string);
1024 if(snprintf(cmd,BUF_SIZE,
"SET freq_list %s",freq_list_string) < 0)
1026 pthread_mutex_lock(&wpa_sup_lock);
1027 wpaCtrlSendCmd(cmd);
1028 pthread_mutex_unlock(&wpa_sup_lock);
1032 WIFI_LOG_INFO(
"Error in getting the Frequency list for specified Band, NOT SCANNING . \n");
1038 bssCount = get_wifi_self_steer_matching_bss_list(SSID,filtered_APList,timeout);
1039 *output_array_size = bssCount;
1042 WIFI_LOG_ERROR(
"No BSS found with given band and frequency \n");
1047 WIFI_LOG_DEBUG(
"Found %d BSS ids' for SSID %s \n",bssCount,SSID);
1049 if(*filtered_ap_array == NULL)
1051 WIFI_LOG_INFO(
"Memory allocation failure\n");
1057 for (i=0; i<*output_array_size; i++)
1058 (*filtered_ap_array)[i] = filtered_APList[i];
1062 pthread_mutex_lock(&wpa_sup_lock);
1063 wpaCtrlSendCmd(
"SET freq_list 0");
1064 pthread_mutex_unlock(&wpa_sup_lock);
1072 int retStatus = RETURN_ERR;
1073 if(!output_string) {
1074 WIFI_LOG_ERROR(
"Error in getting supported bands.. Null string\n");
1078 if(isDualBandSupported() ==
true) {
1079 snprintf(output_string, 64,
"2.4GHz,5GHz");
1082 pthread_mutex_lock(&wpa_sup_lock);
1083 retStatus = wpaCtrlSendCmd(
"GET_CAPABILITY channels");
1085 if(strstr(return_buf,
"Mode[A]") != NULL) {
1086 snprintf(output_string, 64,
"5GHz");
1087 }
else if(strstr(return_buf,
"Mode[B]") != NULL || strstr(return_buf,
"Mode[G]") != NULL) {
1088 snprintf(output_string, 64,
"2.4GHz");
1090 WIFI_LOG_ERROR(
"Error in getting supported bands- Unable to get Freq Modes\n");
1093 WIFI_LOG_ERROR(
"Error in getting supported bands- Unable to Channel Capability\n");
1095 pthread_mutex_unlock(&wpa_sup_lock);
1097 WIFI_LOG_DEBUG(
"[%s:%d] SupportedFrequencyBands - %s\n",__FUNCTION__,__LINE__,output_string);
1104 CHAR frequency_string[8] =
"";
1107 if(!output_string) {
1108 WIFI_LOG_ERROR(
"Error in getting supported bands.. Null string\n");
1111 if (
RETURN_OK == wifi_getRadioSignalParameter (
"FREQUENCY", frequency_string) &&
1112 1 == sscanf (frequency_string,
"%d", &frequency) &&
1114 int band = frequency/1000;
1116 snprintf(output_string, 64,
"5GHz");
1117 }
else if (band == 2) {
1118 snprintf(output_string, 64,
"2.4GHz");
1120 WIFI_LOG_ERROR(
"[%s:%d] Failure in getting OperatingFrequencyBand \n",__FUNCTION__,__LINE__);
1121 retStatus = RETURN_ERR;
1124 WIFI_LOG_ERROR(
"[%s:%d] Failure in getting OperatingFrequencyBand - Failed to get Frequency\n",__FUNCTION__,__LINE__);
1125 retStatus = RETURN_ERR;
1133 char cmd[BUFF_LEN_64];
1134 char result[BUFF_LEN_64];
1136 if (!output_string) {
1140 snprintf(output_string, 64, (radioIndex==0)?
"b,g,n":
"a,n,ac");
1141 memset(cmd,0,
sizeof(cmd));
1142 memset(result,0,
sizeof(result));
1145 snprintf(cmd,
sizeof(cmd),
"iw phy | grep 'HE Iftypes'| tr '\n' ' '");
1146 fp = popen(cmd,
"r");
1150 if (fgets(result,
sizeof(result), fp)) {
1151 if (strstr(result,
"HE Iftypes"))
1152 snprintf(output_string, 64, (radioIndex==0)?
"b,g,n,ax":
"a,n,ac,ax");
1161 INT
wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL *nOnly, BOOL *acOnly) {
1163 CHAR frequency_string[8] =
"";
1165 int ret = RETURN_ERR;
1168 if(!output_string) {
1171 if (
RETURN_OK == wifi_getRadioSignalParameter (
"FREQUENCY", frequency_string) &&
1172 1 == sscanf (frequency_string,
"%d", &frequency) &&
1175 freqBand = frequency/1000;
1176 if(freqBand == 2 && radioIndex == 0) {
1177 snprintf(output_string, 64,
"b,g,n");
1179 }
else if(freqBand == 5 && radioIndex == 1) {
1180 snprintf(output_string, 64,
"a,n,ac");
1183 WIFI_LOG_ERROR(
"Invalid frequency band, Failure in getting Operating standard.\n");
1186 if(gOnly != NULL) *gOnly =
false;
1187 if(nOnly != NULL) *nOnly =
false;
1188 if(acOnly != NULL) *acOnly =
false;
1192 static void getPossibleChannelsFromCapability(
char* channelCap,
char *modeStr,
char* output_string)
1194 char *pch=NULL,*
final=NULL;
1195 char *saveptr = NULL;
1197 pch = strtok_r(channelCap,
"\n", &saveptr);
1200 if(strstr(pch,modeStr))
1202 pch=strchr(pch,
':');
1205 while(*
final !=
'\0')
1215 pch = strtok_r (NULL,
"\n", &saveptr);
1218 strcpy(output_string,pch);
1224 char tmp_buff[BUFF_LEN_1024];
1225 if(!output_string) {
1228 memset(tmp_buff,0,BUFF_LEN_1024);
1229 pthread_mutex_lock (&wpa_sup_lock);
1230 ret = wpaCtrlSendCmd (
"GET_CAPABILITY channels");
1233 strncpy(tmp_buff,return_buf,BUFF_LEN_1024);
1234 pthread_mutex_unlock (&wpa_sup_lock);
1238 WIFI_LOG_ERROR(
"Error in getting channel capability.\n");
1239 pthread_mutex_unlock (&wpa_sup_lock);
1244 getPossibleChannelsFromCapability(tmp_buff,
"Mode[A]",output_string);
1248 getPossibleChannelsFromCapability(tmp_buff,
"Mode[G]",output_string);
1255 char resultBuff[64];
1257 char interfaceName[10];
1260 int ret = RETURN_ERR;
1261 bool iw_info_failed=
false;
1262 char* bandwidth_string=NULL;
1263 char* bandwidth_token=NULL;
1264 bool bandwidth_found=
false;
1266 if(!output_string) {
1270 memset(interfaceName,0,
sizeof(interfaceName));
1271 memset(cmd,0,
sizeof(cmd));
1272 memset(resultBuff,0,
sizeof(resultBuff));
1275 if(interfaceName[0] ==
'\0')
1277 WIFI_LOG_ERROR(
"Unable to get wireless interface name, Get bandwidth failed \n");
1280 snprintf(cmd,
sizeof(cmd),
"iw dev %s info | grep channel | cut -f 2 -d ','",interfaceName);
1281 fp = popen(cmd,
"r");
1284 if ((fgets(resultBuff,
sizeof (resultBuff), fp) != NULL) && (resultBuff[0] !=
'\0'))
1286 sscanf(resultBuff,
"%*s%d%*s",&bandWidth);
1287 if(bandWidth != 0) {
1288 snprintf(output_string, 64,
"%dMHz",bandWidth);
1289 WIFI_LOG_INFO(
"OperatingChannelBandwidth = %s\n",output_string);
1292 WIFI_LOG_ERROR(
"Failure in getting bandwidth \n");
1297 WIFI_LOG_ERROR(
"Unable to read Channel width from iw \n");
1298 iw_info_failed=
true;
1304 WIFI_LOG_ERROR(
"popen() failed. failure in getting Channel Bandwidth\n");
1305 iw_info_failed=
true;
1308 if(
true == iw_info_failed)
1310 WIFI_LOG_INFO(
"iw info command failed, fall back to iw link command\n");
1312 memset(cmd,0,
sizeof(cmd));
1313 memset(resultBuff,0,
sizeof(resultBuff));
1315 snprintf(cmd,
sizeof(cmd),
"iw dev %s link | grep tx",interfaceName);
1316 fp = popen(cmd,
"r");
1319 if ((fgets(resultBuff,
sizeof (resultBuff), fp) != NULL) && (resultBuff[0] !=
'\0'))
1321 char* resultBuff_P=resultBuff;
1322 while ((bandwidth_string = strtok_r(resultBuff_P,
" ", &resultBuff_P)))
1324 bandwidth_token = strcasestr(bandwidth_string,
"MHz");
1325 if(NULL != bandwidth_token )
1327 strcpy(output_string,bandwidth_string);
1328 bandwidth_found=
true;
1332 if (
true == bandwidth_found)
1334 WIFI_LOG_INFO(
"OperatingChannelBandwidth = %s\n",output_string);
1339 WIFI_LOG_ERROR(
"MHz information missing in iw link o/p \n");
1344 WIFI_LOG_ERROR(
"Failure in getting bandwidth \n");
1349 WIFI_LOG_ERROR(
"popen() failed. failure in getting Channel Bandwidth\n");
1358 int ret = RETURN_ERR;
1359 if (output_string != NULL)
1361 pthread_mutex_lock(&wpa_sup_lock);
1362 int retStatus = wpaCtrlSendCmd(
"STATUS");
1363 if (retStatus == -2)
1364 telemetry_event_d(
"WIFIV_WARN_hal_timeout", 1);
1365 char *ssid = getValue(return_buf,
"\nssid");
1368 WIFI_LOG_ERROR(
"%s: ssid not found in STATUS output\n", __FUNCTION__);
1373 printf_decode ((u8*)output_string, MAX_SSID_LEN+1, ssid);
1376 pthread_mutex_unlock(&wpa_sup_lock);
1389 int maxBssidLen = 18;
1391 pthread_mutex_lock(&wpa_sup_lock);
1392 int retStatus = wpaCtrlSendCmd(
"STATUS");
1393 if (retStatus == -2)
1394 telemetry_event_d(
"WIFIV_WARN_hal_timeout", 1);
1395 bssid = getValue(return_buf,
"bssid");
1399 if (output_string != NULL) strncpy(output_string, bssid,maxBssidLen);
1401 pthread_mutex_unlock(&wpa_sup_lock);
1406 pthread_mutex_unlock(&wpa_sup_lock);
1414 pthread_mutex_lock(&wpa_sup_lock);
1415 int retStatus = wpaCtrlSendCmd(
"STATUS");
1416 if (retStatus == -2)
1417 telemetry_event_d(
"WIFIV_WARN_hal_timeout", 1);
1418 bssid = getValue(return_buf,
"bssid");
1422 if (output_string != NULL) strcpy(output_string, bssid);
1424 pthread_mutex_unlock(&wpa_sup_lock);
1429 pthread_mutex_unlock(&wpa_sup_lock);
1433 static INT wifi_getRadioSignalParameter (
const CHAR* parameter, CHAR *output_string) {
1435 if (!parameter || !output_string) {
1439 char *parameter_value= NULL;
1440 int ret = RETURN_ERR;
1442 pthread_mutex_lock (&wpa_sup_lock);
1443 int retStatus = wpaCtrlSendCmd (
"SIGNAL_POLL");
1444 if (retStatus == -2)
1445 telemetry_event_d(
"WIFIV_ERR_hal_signalpolltimeout", 1);
1446 if (NULL != (parameter_value = getValue(return_buf, parameter)))
1448 strcpy (output_string, parameter_value);
1451 pthread_mutex_unlock (&wpa_sup_lock);
1453 WIFI_LOG_DEBUG(
"[%s] return code = [%d], parameter = [%s], parameter_value = [%s]\n",
1454 __FUNCTION__, ret, parameter, parameter_value ? parameter_value :
"NULL");
1458 static int wifi_getRadioChannelFromFrequency(
int frequency)
1460 if (frequency == 2484)
1462 else if (frequency < 2484)
1463 return (frequency - 2407) / 5;
1464 else if (frequency >= 4910 && frequency <= 4980)
1465 return (frequency - 4000) / 5;
1466 else if (frequency <= 45000)
1467 return (frequency - 5000) / 5;
1468 else if (frequency >= 58320 && frequency <= 64800)
1469 return (frequency - 56160) / 2160;
1474 static int wifi_getWpaSupplicantStatus()
1478 int pingStatus = -1;
1480 memset(temp_buff,0,
sizeof(temp_buff));
1481 pthread_mutex_lock(&wpa_sup_lock);
1482 retStatus = wpaCtrlSendCmd(
"PING");
1483 if (retStatus == -3)
1484 telemetry_event_d(
"WIFIV_ERR_wpasupplicant_down", 1);
1485 strncpy(temp_buff,return_buf,
sizeof(temp_buff)-1);
1486 pthread_mutex_unlock(&wpa_sup_lock);
1488 if(temp_buff[0] !=
'\0' && retStatus == 0 )
1490 if(strncmp(temp_buff,
"PONG",4) == 0)
1507 static int wifi_openWpaSupConnection()
1512 pthread_mutex_lock(&wpa_sup_lock);
1513 wpa_ctrl_close(g_wpa_ctrl);
1514 g_wpa_ctrl = wpa_ctrl_open(g_ctx.ctrl_path);
1515 if(NULL != g_wpa_ctrl) {
1516 WIFI_LOG_INFO(
"wpa_supplicant control connection opened successfuly. \n");
1518 WIFI_LOG_ERROR(
"Failure in opening wpa_supplicant control connection.\n");
1519 pthread_mutex_unlock(&wpa_sup_lock);
1522 pthread_mutex_unlock(&wpa_sup_lock);
1525 pthread_mutex_lock(&wpa_sup_lock);
1526 wpa_ctrl_close(g_wpa_monitor);
1527 g_wpa_monitor = wpa_ctrl_open(g_ctx.ctrl_path);
1528 if(NULL != g_wpa_monitor) {
1529 WIFI_LOG_INFO(
"wpa_supplicant monitor connection opened successfuly. \n");
1530 if ( wpa_ctrl_attach(g_wpa_monitor) != 0) {
1531 WIFI_LOG_ERROR(
"wpa_ctrl_attach failed \n");
1533 WIFI_LOG_INFO(
"Monitor connection Attached Successfully. \n");
1537 WIFI_LOG_ERROR(
"Failure in opening wpa_supplicant monitor connection.\n");
1539 pthread_mutex_unlock(&wpa_sup_lock);
1542 void* monitor_wpa_health(
void* param)
1545 int printInterval = 0;
1547 int pingRecoveryCount = 0;
1552 retStatus = wifi_getWpaSupplicantStatus();
1555 if(printInterval >= 4)
1557 WIFI_LOG_INFO(
"wpa_supplicant heartbeat success. \n");
1565 WIFI_LOG_ERROR(
"wpa_supplicant heartbeat failed, Reason: %s \n",retStatus==-1?
"No response.":
"Command failure.");
1566 telemetry_event_d(
"WIFIV_ERR_HBFail", 1);
1568 WIFI_LOG_INFO(
"Trying for 5 continues pings...\n");
1569 while(pingCount < 5)
1571 retStatus = wifi_getWpaSupplicantStatus();
1573 WIFI_LOG_INFO(
"wpa_supplicant heartbeat success. , Breaking Ping attempts\n");
1575 if(pingRecoveryCount >= 2) {
1576 WIFI_LOG_INFO(
"wpa_supplicant heartbeat - inconsistent control connection: Reopen new one.\n");
1577 wifi_openWpaSupConnection();
1578 pingRecoveryCount = 0;
1580 pingRecoveryCount++;
1586 WIFI_LOG_ERROR(
"wpa_supplicant heartbeat failed, Reason: %s, Attempt = %d\n",retStatus==-1?
"No response.":
"Command failure.",pingCount+1);
1587 telemetry_event_d(
"WIFIV_ERR_HBFail", 1);
1590 wifi_usleep(1000000 * 3);
1592 if(pingCount >= 5) {
1593 WIFI_LOG_INFO(
"Heartbeat failed for all attempts, Trying to reopen Connection.\n");
1594 wifi_openWpaSupConnection();
1597 wifi_usleep(WPA_SUP_PING_INTERVAL * 1000000);
1607 CHAR frequency_string[8] =
"";
1610 int ret = RETURN_ERR;
1611 if (
RETURN_OK == wifi_getRadioSignalParameter (
"FREQUENCY", frequency_string) &&
1612 1 == sscanf (frequency_string,
"%d", &frequency) &&
1614 0 != (channel = wifi_getRadioChannelFromFrequency (frequency)))
1616 *output_ulong = channel;
1620 WIFI_LOG_DEBUG(
"[%s] return code = [%d], Channel Spec: %lu\n", __FUNCTION__, ret, *output_ulong);
1627 snprintf(output_string, 256, (radioIndex==0)?
"1,6,11":
"36,40");
1638 WIFI_LOG_INFO(
"SSID entries:1\n");
1646 char resultBuff[BUF_SIZE];
1648 char interfaceName[10];
1649 long long int rx_bytes = 0,rx_packets = 0,rx_err = 0,rx_drop = 0;
1650 long long int tx_bytes = 0,tx_packets = 0,tx_err = 0,tx_drop = 0;
1655 if(!output_struct) {
1656 WIFI_LOG_INFO(
"output struct is null");
1661 memset(resultBuff,0,
sizeof(resultBuff));
1662 memset(cmd,0,
sizeof(cmd));
1663 memset(interfaceName,0,
sizeof(interfaceName));
1666 snprintf(cmd,
sizeof(cmd),
"cat /proc/net/dev | grep %s",interfaceName);
1667 fp = popen(cmd,
"r");
1670 if (fgets(resultBuff,
sizeof (resultBuff), fp) != NULL)
1672 numParams = sscanf( resultBuff,
" %[^:]: %lld %lld %lld %lld %*u %*u %*u %*u %lld %lld %lld %lld %*u %*u %*u %*u",interfaceName, &rx_bytes, &rx_packets,&rx_err,&rx_drop,&tx_bytes,&tx_packets,&tx_err,&tx_drop );
1675 WIFI_LOG_ERROR(
"Error in parsing Radio Stats params \n");
1685 WIFI_LOG_INFO(
"[tx_packets = %lld] [rx_packets = %lld] [tx_bytes = %lld] [rx_bytes = %lld] [rx_err = %lld] [tx_err = %lld] [tx_drop = %lld] [rx_drop = %lld] \n",tx_packets,rx_packets,tx_bytes,rx_bytes,rx_err,tx_err,tx_drop,rx_drop);
1689 WIFI_LOG_ERROR(
"Error in reading /proc/net/dev file \n");
1695 WIFI_LOG_ERROR(
"Error in popen() : Opening /proc/net/dev failed \n");
1697 pthread_mutex_lock(&wpa_sup_lock);
1698 int retStatus = wpaCtrlSendCmd(
"SIGNAL_POLL");
1699 if (retStatus == -2)
1700 telemetry_event_d(
"WIFIV_ERR_hal_signalpolltimeout", 1);
1701 ptr = getValue(return_buf,
"NOISE");
1706 WIFI_LOG_INFO(
"\n noise = %d ",noise);
1710 WIFI_LOG_INFO(
"Noise is not available in siganl poll \n");
1712 pthread_mutex_unlock(&wpa_sup_lock);
1717 *output_bool = (g_wpa_monitor != NULL);
1718 WIFI_LOG_INFO(
"The radio is %s\n", g_wpa_monitor ?
"enabled" :
"not enabled");
1723 int ret = RETURN_ERR;
1724 char radio_status[20];
1729 WIFI_LOG_ERROR(
"Output_string is null\n");
1733 pthread_mutex_lock(&wpa_sup_lock);
1734 int status = wpaCtrlSendCmd(
"STATUS");
1735 strncpy(cli_buff,return_buf,512);
1736 pthread_mutex_unlock(&wpa_sup_lock);
1737 memset(radio_status,0,
sizeof(radio_status));
1740 ptr = getValue(cli_buff,
"wpa_state");
1743 strcpy(radio_status,ptr);
1744 if(strcmp(radio_status,
"INTERFACE_DISABLED") == 0)
1746 strcpy(output_string,
"DOWN");
1750 strcpy(output_string,
"UP");
1753 WIFI_LOG_INFO(
"\n WPA State : %s, Radio State :%s ",radio_status,output_string);
1758 WIFI_LOG_INFO(
"Radio State is not available in wpa_cli STATUS \n");
1763 char path[PATH_MAX];
1764 snprintf(path, PATH_MAX,
"/sys/class/net/%s/operstate", g_ctx.conf.wlan_Interface);
1766 char *operstate = wifi_readFile(path,
true);
1768 if (!strncasecmp(operstate,
"up", 2)) {
1769 strcpy(output_string,
"UP");
1772 else if (!strncasecmp(operstate,
"down", 4)) {
1773 strcpy(output_string,
"DOWN");
1777 WIFI_LOG_ERROR(
"failed to parse the operstate from %s. '%s'\n",
1781 WIFI_LOG_INFO(
"The radio is %s (operstate=%s)\n", output_string, operstate);
1792 int ret = RETURN_ERR;
1794 WIFI_LOG_INFO(
"Output_string is null\n");
1797 pthread_mutex_lock(&wpa_sup_lock);
1798 int status = wpaCtrlSendCmd(
"GET COUNTRY");
1800 if(status == 0 && return_buf[0] !=
'\0'){
1801 if(snprintf(output_string, 4,
"%s", return_buf) >= 0)
1807 pthread_mutex_unlock(&wpa_sup_lock);
1813 WIFI_LOG_INFO(
"MaxBitRate information will be implemented\n");
1819 WIFI_LOG_INFO(
"MCS could not be determined\n");
1825 char filename[]=
"/tmp/wlparam.txt";
1827 char *saveptr = NULL;
1830 if(!output_struct) {
1831 WIFI_LOG_INFO(
"output struct is null");
1834 system(
"wl counter > /tmp/wlparam.txt");
1835 bufPtr=wifi_readFile(filename,
false);
1838 ptrToken = strtok_r (bufPtr,
" \t\n", &saveptr);
1839 while (ptrToken != NULL)
1841 if (strcmp(ptrToken,
"txdatamcast") == 0)
1843 ptrToken = strtok_r (NULL,
" \t\n", &saveptr);
1845 WIFI_LOG_INFO(
"\n txdatamcast = %llu ",strtoull(ptrToken, NULL, 10));
1847 else if (strcmp(ptrToken,
"txdatabcast") == 0)
1849 ptrToken = strtok_r (NULL,
" \t\n", &saveptr);
1851 WIFI_LOG_INFO(
"\n txdatabcast = %llu ",strtoull(ptrToken, NULL, 10));
1853 else if (strcmp(ptrToken,
"txnoack") == 0)
1855 ptrToken = strtok_r (NULL,
" \t\n", &saveptr);
1856 output_struct->ssid_ACKFailureCount=strtoull(ptrToken, NULL, 10);
1857 WIFI_LOG_INFO(
"\n txnoack = %llu ",strtoull(ptrToken, NULL, 10));
1861 ptrToken = strtok_r (NULL,
" \t\n", &saveptr);
1879 WIFI_LOG_INFO(
"Extension channel is Auto\n");
1880 strcpy(output_string,
"Auto");
1886 WIFI_LOG_INFO(
"The radio number of entries is always 1\n");
1896 strcpy(output_string, g_ctx.conf.wlan_Interface);
1899 INT wifi_setRadioScanningFreqList(INT radioIndex,
const CHAR *freqList)
1904 memset(cmd,0,BUF_SIZE);
1905 snprintf(cmd,BUF_SIZE,
"SET freq_list %s",freqList);
1906 pthread_mutex_lock(&wpa_sup_lock);
1909 result = RETURN_ERR;
1911 pthread_mutex_unlock(&wpa_sup_lock);
1914 INT wifi_getDualBandSupport()
1916 if(isDualBandSupported() ==
true)
2060 memset(ctx, 0,
sizeof(*ctx));
2062 strcpy(ctx->conf.wlan_Interface,
"wlan0");
2065 strncpy(ctx->conf.wlan_Interface, conf->wlan_Interface, WLAN_IFNAMSIZ -1);
2068 snprintf(ctx->ctrl_path, WLAN_PATHMAX,
"/var/run/wpa_supplicant/%s", ctx->conf.wlan_Interface);
2071 void wifi_interfaceSetEnabled(
const char * ifname,
bool enable)
2077 int soc = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
2079 WIFI_LOG_ERROR(
"error checking interface status, socket error. %s\n",
2085 memset(&req, 0,
sizeof(req));
2086 strncpy(req.ifr_ifrn.ifrn_name, ifname, IFNAMSIZ);
2089 ret = ioctl(soc, SIOCGIFFLAGS, &req);
2091 WIFI_LOG_ERROR(
"failed to get current state of interface %s. %s",
2092 ifname, strerror(errno));
2096 if ((req.ifr_flags & IFF_UP) == IFF_UP) {
2098 req.ifr_flags &= ~IFF_UP;
2104 req.ifr_flags |= IFF_UP;
2110 ret = ioctl(soc, SIOCSIFFLAGS, &req);
2112 WIFI_LOG_ERROR(
"failed to disable interface. %s\n", strerror(errno));