RDK Documentation (Open Sourced RDK Components)
wifi_common_hal.c
1 /*
2 * If not stated otherwise in this file or this component's Licenses.txt file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2018 RDK Management
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 #define _GNU_SOURCE
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <limits.h>
25 #include <net/if.h>
26 #include <signal.h>
27 #include <unistd.h>
28 #include <wifi_common_hal.h>
29 #include <stdbool.h>
30 #include <pthread.h>
31 #include <ifaddrs.h>
32 
33 #include <sys/ioctl.h>
34 #include <netinet/in.h>
35 
36 #include "wifi_log.h"
37 
38 #define MAX_SSID_LEN 32 /* Maximum SSID name */
39 #define MAX_VERSION_LEN 16 /* Maximum Version Len */
40 #define BUFF_LEN_1024 1024
41 #define BUFF_LEN_64 64
42 extern BOOL bNoAutoScan;
43 
44 ULONG ssid_number_of_entries = 0;
45 
46 /*! Supported values are NONE - 0, WPA - 1, WEP - 2*/
47 typedef enum _SsidSecurity
48 {
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,
65 } SsidSecurity;
66 
67 /*static struct _wifi_securityModes
68 {
69  SsidSecurity securityMode;
70  const char *modeString;
71 } wifi_securityModes[] =
72 {
73  { NET_WIFI_SECURITY_NONE, "No Security" },
74  { NET_WIFI_SECURITY_WEP_64, "WEP (Open & Shared)" },
75  { NET_WIFI_SECURITY_WEP_128, "WEP (Open & Shared)" },
76  { NET_WIFI_SECURITY_WPA_PSK_TKIP, "WPA-Personal, TKIP encryp." },
77  { NET_WIFI_SECURITY_WPA_PSK_AES, "WPA-Personal, AES encryp." },
78  { NET_WIFI_SECURITY_WPA2_PSK_TKIP, "WPA2-Personal, TKIP encryp." },
79  { NET_WIFI_SECURITY_WPA2_PSK_AES, "WPA2-Personal, AES encryp." },
80  { NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP, "WPA-ENTERPRISE, TKIP" },
81  { NET_WIFI_SECURITY_WPA_ENTERPRISE_AES, "WPA-ENTERPRISE, AES" },
82  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP, "WPA2-ENTERPRISE, TKIP" },
83  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES, "WPA2-ENTERPRISE, AES" },
84  { NET_WIFI_SECURITY_NOT_SUPPORTED, "Security format not supported" },
85 };
86 */
87 /*
88 static struct _wifi_securityModes
89 {
90  const char *modeString;
91  const char *encryptionString;
92  const char *apSecurityEncryptionString;
93 } wifi_securityModes[] =
94 {
95  { "WPA3","AES","[WPA2-SAE-CCMP]" },
96  { "WPA3","AES","[WPA2-SAE-CCMP-preauth]" },
97  { "WPA2-WPA3","AES","[WPA2-PSK+SAE-CCMP]" },
98  { "WPA2-WPA3","AES","[WPA2-PSK+SAE-CCMP-preauth]" },
99  { "WPA-WPA2","TKIP","[WPA-PSK-TKIP][WPA2-PSK-TKIP]"},
100  { "WPA-WPA2","TKIP","[WPA-PSK-TKIP][WPA2-PSK-TKIP-preauth]"},
101  { "WPA-WPA2","AES","[WPA-PSK-TKIP][WPA2-PSK-CCMP-preauth]"},
102  { "WPA-WPA2","AES","[WPA-PSK-CCMP][WPA2-PSK-CCMP]"},
103  { "WPA-WPA2","AES","[WPA-PSK-CCMP][WPA2-PSK-CCMP-preauth]"},
104  { "WPA-WPA2","AES","[WPA-PSK-TKIP+CCMP][WPA2-PSK-CCMP-preauth]"},
105  { "WPA-WPA2","TKIP,AES","[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP]"},
106  { "WPA-WPA2","TKIP,AES","[WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP-preauth]"},
107 
108  { "WPA-WPA2-Enterprise","TKIP","[WPA-EAP-TKIP][WPA2-EAP-TKIP]"},
109  { "WPA-WPA2-Enterprise","AES","[WPA-EAP-CCMP][WPA2-EAP-CCMP]"},
110  { "WPA-WPA2-Enterprise","TKIP,AES","[WPA-EAP-CCMP+TKIP][WPA2-EAP-CCMP+TKIP]"},
111  { "WPA-Enterprise","TKIP,AES","[WPA-EAP-CCMP+TKIP]"},
112  { "WPA2-Enterprise","TKIP,AES","[WPA2-EAP-CCMP+TKIP]"},
113  { "WPA-Enterprise","TKIP","[WPA-EAP-TKIP]"},
114  { "WPA-Enterprise","AES","[WPA-EAP-CCMP]"},
115  { "WPA2-Enterprise","TKIP","[WPA2-EAP-TKIP]"},
116  { "WPA2-Enterprise","AES","[WPA2-EAP-CCMP]"},
117 
118  { "WPA","TKIP","[WPA-PSK-TKIP]"},
119  { "WPA2","TKIP","[WPA2-PSK-TKIP]"},
120  { "WPA2","TKIP","[WPA2-PSK-TKIP-preauth]"},
121  { "WPA","AES","[WPA-PSK-CCMP]"},
122  { "WPA2","AES","[WPA2-PSK-CCMP]"},
123  { "WPA2","AES","[WPA2-PSK-CCMP-preauth]"},
124  { "WPA","TKIP,AES","[WPA-PSK-CCMP+TKIP]"},
125  { "WPA2","TKIP,AES","[WPA2-PSK-CCMP+TKIP]"},
126  { "WPA2","TKIP,AES","[WPA2-PSK-CCMP+TKIP-preauth]"},
127  { "WEP","","WEP"},
128  { "WPA2","AES","[WPA2-PSK+FT/PSK-CCMP][WPS][ESS]"},
129  { "WPA2-Enterprise","AES","[WPA2-EAP+FT/EAP-CCMP][ESS]"},
130  { "None","","None"},
131 };
132 */
133 /*{
134  { NET_WIFI_SECURITY_NONE, "No Security" },
135  { NET_WIFI_SECURITY_WEP_64, "WEP (Open & Shared)" },
136  { NET_WIFI_SECURITY_WEP_128, "WEP (Open & Shared)" },
137  { NET_WIFI_SECURITY_WPA_PSK_TKIP, "WPA-Personal, TKIP encryp." },
138  { NET_WIFI_SECURITY_WPA_PSK_AES, "WPA-Personal, AES encryp." },
139  { NET_WIFI_SECURITY_WPA2_PSK_TKIP, "WPA2-Personal, TKIP encryp." },
140  { NET_WIFI_SECURITY_WPA2_PSK_AES, "WPA2-Personal, AES encryp." },
141  { NET_WIFI_SECURITY_WPA_ENTERPRISE_TKIP, "WPA-ENTERPRISE, TKIP" },
142  { NET_WIFI_SECURITY_WPA_ENTERPRISE_AES, "WPA-ENTERPRISE, AES" },
143  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_TKIP, "WPA2-ENTERPRISE, TKIP" },
144  { NET_WIFI_SECURITY_WPA2_ENTERPRISE_AES, "WPA2-ENTERPRISE, AES" },
145  { NET_WIFI_SECURITY_NOT_SUPPORTED, "Security format not supported" },
146 };*/
147 
148 void wifi_usleep(useconds_t usec)
149 {
150  // WIFI_LOG_INFO("wifi hal calling sleep:%uus\n", (uint32_t) usec);
151  if (usec >= 1000000) {
152  (void) sleep((unsigned int) (usec / 1000000));
153  }
154  else {
155  (void) usleep(usec);
156  }
157 }
158 
159 INT is_null_pointer(char* str) { //Check if passed string is a null pointer and empty string or not
160  if ((str !=NULL) && (str[0]=='\0')) {
161  return 0;
162  }
163  return 1;
164 }
165 
166 #include <wpa_ctrl.h>
167 
168 #include <stdint.h>
169 typedef uint8_t u8;
170 // added to be able to use wpa_supplicant's 'printf_decode' utility function to decode the SSIDs encoded by wpa_supplicant
171 extern size_t printf_decode(u8 *buf, size_t maxlen, const char *str);
172 
173 #define BUF_SIZE 256
174 
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"
179 
180 #define WPA_SUP_TIMEOUT 7000 /* 7 msec */
181 #define WPA_SUP_PING_INTERVAL 60 /* 1 min */
182 
183 typedef enum {
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;
189 
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();
197 #endif
198 
199 bool init_done=false; /* Flag to check if WiFi init was already done or not */
200 extern bool stop_monitor; /* Flag to stop the monitor thread */
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];
207 wifi_neighbor_ap_t ap_list[512];
208 
209 
210 static wifi_context_t g_ctx;
211 static void wifi_initContext(wifi_context_t * ctx, wifi_halConfig_t *conf);
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);
215 
216 static char * wifi_readFile(const char * fname, bool sysfs);
217 
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);
225 
226 
227 INT wifi_getHalVersion(CHAR *output_string)
228 {
229  int retStatus = RETURN_OK;
230  int ret = 0;
231  if(output_string) {
232  ret = sprintf(output_string,"%d.%d.%d",WIFI_HAL_MAJOR_VERSION,WIFI_HAL_MINOR_VERSION,WIFI_HAL_MAINTENANCE_VERSION);
233  if(ret <= 0 || ret > MAX_VERSION_LEN) {
234  WIFI_LOG_ERROR("Failed generate HAL Version, ret = %d.\n",ret );
235  retStatus = RETURN_ERR;
236  }
237  } else {
238  WIFI_LOG_ERROR("Failed to get HAL Version - Input String is NULL.\n" );
239  retStatus = RETURN_ERR;
240  }
241  return retStatus;
242 }
243 static INT getFrequencyListFor_Band(WIFI_HAL_FREQ_BAND band, char *output_string)
244 {
245  if(output_string == NULL)
246  {
247  WIFI_LOG_ERROR("[%s] Memory not allocated for output_string \n",__FUNCTION__);
248  return RETURN_ERR;
249  }
250  char *s = NULL;
251  char *t = NULL;
252  char *r = NULL;
253  char *saveptr = NULL;
254  char lines[32][64];
255  int i;
256  INT ret = RETURN_ERR;
257 
258  WIFI_LOG_INFO("in getFrequencyListFor_Band ..\n");
259  pthread_mutex_lock(&wpa_sup_lock);
260  int ret_status = wpaCtrlSendCmd("GET_CAPABILITY freq");
261  if(ret_status == RETURN_OK)
262  {
263  if( band == WIFI_HAL_FREQ_BAND_5GHZ)
264  {
265  s = strstr(return_buf, "Mode[A] Channels:");
266  t = strstr(return_buf, "Mode[B] Channels:");
267  if(t) *t = 0;
268  }
269  else if (band == WIFI_HAL_FREQ_BAND_24GHZ)
270  {
271  s = strstr(return_buf, "Mode[G] Channels:");
272  t = strstr(return_buf, "Mode[A] Channels:");
273  if(t) *t = 0;
274  }
275  if (s == NULL)
276  {
277  WIFI_LOG_INFO("[%s] Error in selecting the frequencies\n",__FUNCTION__);
278  ret = RETURN_ERR;
279  }
280  else
281  {
282  s = s+18;
283  r = strtok_r(s,"\n", &saveptr);
284  i=0;
285  while(r != NULL)
286  {
287  strcpy(lines[i],r);
288  r = strtok_r(NULL,"\n", &saveptr);
289  i++;
290  }
291 
292  saveptr = NULL;
293  for(int k=0;k<i;k++)
294  {
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, " ");
301  }
302  WIFI_LOG_DEBUG("frequencies selected : [%s] \n",output_string);
303  ret = RETURN_OK;
304  }
305  }
306  else
307  {
308  WIFI_LOG_ERROR("[%s] Error in getting supported bands- Unable to get Channel Capability\n",__FUNCTION__);
309  ret = RETURN_ERR;
310  }
311  pthread_mutex_unlock(&wpa_sup_lock);
312  return ret;
313  //wpa_cli get_capability freq
314 }
315 
316 char * wifi_readFile(const char * fname, bool sysfs)
317 {
318  FILE *fp = NULL;
319  char *buf = NULL;
320  long fBytes = 0;
321  long freadBytes = 0;
322 
323  fp=fopen(fname,"r");
324  if(fp==NULL)
325  {
326  WIFI_LOG_INFO("readFile(): File Open Error \n" );
327  return NULL;
328  }
329  fseek(fp,0L,SEEK_END);
330  fBytes=ftell(fp);
331  fseek(fp,0L,SEEK_SET);
332  if(fBytes > 0)
333  {
334  buf=(char *)calloc(fBytes+1,sizeof(char));
335  if(buf == NULL)
336  {
337  WIFI_LOG_INFO("readFile(): Memory Allocation Error \n" );
338  fclose(fp);
339  return NULL;
340  }
341  freadBytes = fread(buf,sizeof(char),fBytes,fp);
342  if (!sysfs && (freadBytes != fBytes)) // Do we need to proceed on partial read.. ? Blocking for now.
343  {
344  WIFI_LOG_ERROR(" readFile(): Error occured during fread(), freadBytes= %ld \n" ,freadBytes);
345  fclose(fp);
346  free(buf);
347  return NULL;
348  }
349  }
350  else
351  {
352  WIFI_LOG_ERROR("readFile(): File is empty \n" );
353  }
354  fclose(fp);
355  return buf;
356 }
357 
358 bool wifi_interfaceExists(const char * ifname)
359 {
360  bool found = false;
361  struct if_nameindex *ifp, *ifpsave;
362 
363  ifpsave = ifp = if_nameindex();
364 
365  if(!ifp){
366  WIFI_LOG_DEBUG("if_nameindex call failed: %s\n", strerror(errno));
367  return false;
368  }
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) {
373  found = true;
374  break;
375  }
376  ifp++;
377  }
378  if_freenameindex(ifpsave);
379  return found;
380 }
381 
382 // Initializes the wifi subsystem (all radios)
384 {
385  return wifi_initWithConfig(NULL);
386 }
387 
388 INT wifi_initWithConfig(wifi_halConfig_t *conf)
389 {
390  int retry = 0;
391  stop_monitor=false;
392  pthread_attr_t thread_attr;
393  int ret;
394 
395  wifi_initContext(&g_ctx, conf);
396 
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");
400  return RETURN_OK;
401  }
402 
403  WIFI_LOG_INFO("TELEMETRY_WIFI_WPA_SUPPLICANT:ENABLED \n");
404  // Starting wpa_supplicant service if it is not already started
405  WIFI_LOG_INFO("Starting wpa_supplicant service \n");
406 
407  #ifndef RDKC
408  system("systemctl start wpa_supplicant");
409  #else
410  system("/etc/init.d/wpa_supplicant.service restart");
411  #endif
412 
413  bool interfaceExists = wifi_interfaceExists(g_ctx.conf.wlan_Interface);
414  if(interfaceExists)
415  {
416 
417  /* Starting wpa_supplicant may take some time, try 75 times before giving up */
418  retry = 0;
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);
425  }
426 
427  if (g_wpa_ctrl == NULL) {
428  WIFI_LOG_INFO("wpa_ctrl_open failed for control interface \n");
429  return RETURN_ERR;
430  }
431 
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");
435  return RETURN_ERR;
436  }
437 
438  if ( wpa_ctrl_attach(g_wpa_monitor) != 0) {
439  WIFI_LOG_INFO("wpa_ctrl_attach failed \n");
440  return RETURN_ERR;
441  }
442  if (pthread_mutex_init(&wpa_sup_lock, NULL) != 0)
443  {
444  WIFI_LOG_INFO("mutex init failed\n");
445  return RETURN_ERR;
446  }
447  /* Create thread to monitor events from wpa supplicant */
448  pthread_attr_init(&thread_attr);
449  pthread_attr_setstacksize(&thread_attr, 256*1024);
450 
451  ret = pthread_create(&monitor_thread, &thread_attr, monitor_thread_task, NULL);
452 
453 
454  if (ret != 0) {
455  WIFI_LOG_INFO("Monitor thread creation failed \n");
456  return RETURN_ERR;
457  }
458  // Start wpa_supplicant health monitor thread
459  WIFI_LOG_INFO("Starting wpa_supplicant health monitor thread \n");
460  ret = pthread_create(&wpa_health_mon_thread, NULL, monitor_wpa_health, NULL);
461  if (ret != 0) {
462  WIFI_LOG_INFO("WPA health monitor thread creation failed \n");
463  return RETURN_ERR;
464  }
465 #ifdef WIFI_CLIENT_ROAMING
466  // Initialize and set Roaming config params
467  initialize_roaming_config();
468 #endif
469 
470  init_done=true;
471 
472  return RETURN_OK;
473  }
474  else {
475  WIFI_LOG_WARN("wireless interface %s doesn't exist\n",
476  g_ctx.conf.wlan_Interface);
477  return RETURN_ERR;
478  }
479 }
480 
481 // Uninitializes wifi
482 INT wifi_uninit() {
483 
484  WIFI_LOG_INFO("Stopping monitor thread\n");
485 
486  WIFI_LOG_INFO("Disconnecting from the network\n");
487 
488  //check if "init_done" is not true (if previous init is not successful)
489  //This helps to find if "wpa_health_mon_thread" created with a "pthread_create" during init or not.
490  if(init_done == false) {
491  WIFI_LOG_INFO("Previous wifi init is not successful\n");
492  return RETURN_OK;
493  }
494 
495 
496  wpaCtrlSendCmd("DISCONNECT");
497  wpaCtrlSendCmd("DISABLE_NETWORK 0");
498 
499  // adding a small sleep just to receive WPA_EVENT_DISCONNECTED
500  // so that netsrvmgr can log a disconnected telemetry event
501  wifi_usleep(1000000);
502 
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__);
505  }
506 
507  stop_monitor = true;
508  pthread_join (wpa_health_mon_thread, NULL);
509  pthread_join (monitor_thread, NULL);
510 
511  WIFI_LOG_INFO("Stopping wpa_supplicant service\n");
512 #ifndef RDKC
513  system("systemctl stop wpa_supplicant");
514 #else
515  system("/etc/init.d/wpa_supplicant.service stop");
516 #endif
517 
518  if (g_wpa_ctrl) {
519  wpa_ctrl_close(g_wpa_ctrl);
520  g_wpa_ctrl = NULL;
521  }
522 
523  if (g_wpa_monitor) {
524  wpa_ctrl_close(g_wpa_monitor);
525  g_wpa_monitor = NULL;
526  }
527 
528  init_done=false;
529  return RETURN_OK;
530 }
531 
532 //clears internal variables to implement a factory reset of the Wi-Fi subsystem
534 
535  return RETURN_OK;
536 }
537 
538 //Restore all radio parameters without touch access point parameters
540  return RETURN_OK;
541 }
542 
543 //Restore selected radio parameters without touch access point parameters
544 INT wifi_factoryResetRadio(int radioIndex) {
545 
546  return RETURN_OK;
547 }
548 
549 // resets the wifi subsystem, deletes all APs
550 INT wifi_reset() {
551  return RETURN_OK;
552 }
553 
554 // turns off transmit power for the entire Wifi subsystem, for all radios
556 {
557  struct ifaddrs * addrs;
558  WIFI_LOG_INFO("bringing down all wireless interfaces\n");
559 
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)
564  continue;
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);
568  }
569  }
570  freeifaddrs(addrs);
571  }
572  else {
573  WIFI_LOG_WARN("error trying to disable wireless interfaces. getifaddrs failed. %d", errno);
574  }
575 
576  return RETURN_OK;
577 }
578 
579 #if 1
580 static void get_security_mode_and_encryption_type(const char* flags, char* auth, char* encrypt)
581 {
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;
590 
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");
599 
600  auth[0] = 0;
601  encrypt[0] = 0;
602 
603  if(wpa)
604  strcat(auth, "WPA-");
605  if(wpa2)
606  strcat(auth, "WPA2-");
607  if(sae)
608  strcat(auth, "WPA3-");
609  if(eap)
610  strcat(auth, "Enterprise-");
611  if(wep)
612  strcat(auth, "WEP-");
613  if(none)
614  strcat(auth, "None-");
615 
616  if(auth[0])
617  auth[strlen(auth) - 1] = 0;
618  else
619  {
620  WIFI_LOG_WARN("no auth flags recognized: %s\n", flags);
621  return;
622  }
623 
624  if(tkip)
625  strcat(encrypt, "TKIP,");
626  if(ccmp)
627  strcat(encrypt, "AES,");
628 
629  if(encrypt[0])
630  encrypt[strlen(encrypt) - 1] = 0;
631  else if(wpa || wpa2)
632  WIFI_LOG_WARN("no wpa encrypt flags recognized: %s\n", flags);
633 }
634 #else
635 static void get_security_mode_and_encryption_type(const char* wpa_supplicant_ap_flags, char* security_mode, char* encryption_type)
636 {
637  int len = sizeof ( wifi_securityModes ) / sizeof ( wifi_securityModes[0] );
638  for (int i = 0; i < len; i++)
639  {
640  if (NULL != strcasestr(wpa_supplicant_ap_flags, wifi_securityModes[i].apSecurityEncryptionString))
641  {
642  strcpy(security_mode, wifi_securityModes[i].modeString);
643  strcpy(encryption_type, wifi_securityModes[i].encryptionString);
644  return;
645  }
646  }
647  WIFI_LOG_WARN("Unknown flag: %s\n", wpa_supplicant_ap_flags);
648  security_mode[0] = '\0';
649  encryption_type[0] = '\0';
650 }
651 #endif
652 
653 static int is_zero_bssid(char* bssid) {
654  if(bssid == NULL)
655  return RETURN_ERR;
656  else
657  return strncmp(bssid,"00:00:00:00:00:00",17);
658 }
659 
660 void wifi_getStats(INT radioIndex, wifi_sta_stats_t *stats)
661 {
662  char *ptr = NULL;
663  char *saveptr = NULL;
664  char *bssid, *ssid;
665  int phyrate, noise, rssi,freq,avgRssi;
666  int retStatus = -1;
667 
668  if(NULL == stats)
669  {
670  WIFI_LOG_ERROR("Input Stats is NULL \n");
671  return;
672  }
673 
674  bssid = NULL; ssid = NULL;
675 
676  /* Find the currently connected BSSID and run signal_poll command to get the stats */
677  pthread_mutex_lock(&wpa_sup_lock);
678  retStatus = wpaCtrlSendCmd("STATUS");
679  if(retStatus == 0)
680  {
681  bssid = getValue(return_buf, "bssid");
682  if (bssid == NULL)
683  {
684  WIFI_LOG_DEBUG("BSSID is NULL in Status output\n");
685  goto exit;
686  }
687  else
688  strcpy(stats->sta_BSSID, bssid);
689  ptr = bssid + strlen(bssid) + 1;
690  ssid = getValue(ptr, "ssid");
691  if (ssid == NULL)
692  {
693  WIFI_LOG_DEBUG("SSID is NULL in Status output\n");
694  goto exit;
695  }
696  printf_decode ((u8*)stats->sta_SSID, sizeof(stats->sta_SSID), ssid);
697 
698 
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) {
703  // Check if we get proper BSSID from status no need to copy it
704  if(is_zero_bssid(stats->sta_BSSID) == RETURN_OK) {
705  sscanf(token,"bssid=%18s",stats->sta_BSSID);
706  }
707  }
708  // Get Security Mode from curent BSSID
709  else if(strncmp(token,"flags=",6) == 0) {
710  char flags[64];
711  sscanf(token,"flags=%64s",flags);
712  get_security_mode_and_encryption_type(flags, stats->sta_SecMode, stats->sta_Encryption);
713  break;
714  }
715  token = strtok_r(NULL, "\n", &saveptr);
716  }
717  } else {
718  WIFI_LOG_ERROR("Failed to get BSSID from BSS current\n");
719  }
720 
721  } else {
722  if (retStatus == -2)
723  telemetry_event_d("WIFIV_WARN_hal_timeout", 1);
724  WIFI_LOG_ERROR("wpaCtrlSendCmd(STATUS) failed - Ret = %d \n",retStatus);
725  goto exit;
726  }
727 
728  retStatus = wpaCtrlSendCmd("SIGNAL_POLL");
729  if(retStatus == 0)
730  {
731  ptr = getValue(return_buf, "RSSI");
732 
733  if (ptr == NULL)
734  {
735  WIFI_LOG_ERROR("RSSI not in signal poll \n");
736  goto exit;
737  }
738  else {
739  rssi = atoi(ptr);
740  stats->sta_RSSI = rssi;
741  }
742  ptr = ptr + strlen(ptr) + 1;
743  ptr = getValue(ptr, "LINKSPEED");
744  if (ptr == NULL)
745  {
746  WIFI_LOG_ERROR("LINKSPEED not in signal poll \n");
747  goto exit;
748  }
749  else {
750  phyrate = atoi(ptr);
751  stats->sta_PhyRate = phyrate;
752  }
753 
754  ptr = ptr + strlen(ptr) + 1;
755  ptr = getValue(ptr, "NOISE");
756  if (ptr == NULL)
757  {
758  WIFI_LOG_ERROR("NOISE not in signal poll \n");
759  goto exit;
760  }
761  else {
762  noise = atoi(ptr);
763  stats->sta_Noise = noise;
764  }
765 
766  ptr = ptr + strlen(ptr) + 1;
767  ptr = getValue(ptr, "FREQUENCY");
768  if(ptr == NULL)
769  {
770  WIFI_LOG_ERROR("FREQUENCY not in signal poll \n");
771  goto exit;
772  } else {
773  freq = atoi(ptr);
774  WIFI_LOG_DEBUG("FREQUENCY=%d \t",freq);
775  stats->sta_Frequency = freq;
776  if((freq / 1000) == 2)
777  strcpy(stats->sta_BAND,"2.4GHz");
778  else if((freq / 1000) == 5)
779  strcpy(stats->sta_BAND,"5GHz");
780  else
781  WIFI_LOG_ERROR("Unknown freq band.\n");
782  }
783  // Read Average RSSI
784  ptr = ptr + strlen(ptr) + 1;
785  ptr = getValue(ptr, "AVG_RSSI");
786  if(ptr != NULL)
787  {
788  avgRssi = atoi(ptr);
789  stats->sta_RSSI = avgRssi;
790  WIFI_LOG_DEBUG("AVG_RSSI=%d \n",avgRssi);
791  }
792  }
793  else
794  {
795  if (retStatus == -2)
796  telemetry_event_d("WIFIV_ERR_hal_signalpolltimeout", 1);
797  WIFI_LOG_ERROR("wpaCtrlSendCmd(SIGNAL_POLL) failed ret = %d\n",retStatus);
798  goto exit;
799  }
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",
802  stats->sta_BSSID, stats->sta_SSID, (int)stats->sta_RSSI, (int)stats->sta_PhyRate, (int)stats->sta_Noise, stats->sta_BAND);
803  WIFI_LOG_INFO("%s\n", wifi_stats_buffer);
804  telemetry_event_s("ap_info_split", wifi_stats_buffer);
805 exit:
806  pthread_mutex_unlock(&wpa_sup_lock);
807  return;
808 }
809 
810 INT parse_scan_results(char *buf, size_t len)
811 {
812  uint32_t count = 0;
813  char tmp_str[100];
814  char flags[256];
815  char *delim_ptr, *ptr, *encrypt_ptr,*security_ptr;
816 
817  if ((len == 0) || (buf == NULL)) return count;
818 
819  /* example output:
820  * bssid / frequency / signal level / flags / ssid
821  * b8:62:1f:e5:dd:5b 5200 -55 [WPA2-EAP-CCMP][ESS] BCLMT-Wifi
822  */
823 
824  /* skip heading */
825  ptr = strstr(buf,"/ ssid");
826  if (ptr == NULL) return count;
827  ptr += strlen("/ ssid") + 1;
828 
829  // Memset ap_list before filling the list
830  memset(&ap_list,0,sizeof(ap_list));
831 
832  /* Parse scan results */
833  while (((delim_ptr=strchr(ptr, '\t')) != NULL) && (count < sizeof(ap_list)/sizeof(wifi_neighbor_ap_t))) {
834 
835  /* Parse bssid */
836  memcpy(ap_list[count].ap_BSSID, ptr, (delim_ptr-ptr));
837  ap_list[count].ap_BSSID[delim_ptr-ptr] = '\0';
838 /* WIFI_LOG_INFO("bssid=%s \n",ap_list[count].ap_BSSID); */
839 
840  /* Parse frequency band */
841  ptr = delim_ptr + 1;
842  delim_ptr=strchr(ptr, '\t');
843  if(ptr) {
844  char freq[10];
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");
848  }
849  //memcpy(ap_list[count].ap_OperatingFrequencyBand, ptr, (delim_ptr-ptr));
850  //ap_list[count].ap_OperatingFrequencyBand[delim_ptr-ptr] = '\0';
851 /* WIFI_LOG_INFO("freq=%s \n",ap_list[count].ap_OperatingFrequencyBand); */
852 
853  /* parse signal level */
854  ptr = delim_ptr + 1;
855  delim_ptr=strchr(ptr, '\t');
856  memcpy(tmp_str, ptr, (delim_ptr-ptr));
857  tmp_str[delim_ptr-ptr] = '\0';
858  ap_list[count].ap_SignalStrength = atoi(tmp_str);
859 /* WIFI_LOG_INFO("signal strength=%d \n",ap_list[count].ap_SignalStrength); */
860 
861  /* parse flags */
862  ptr = delim_ptr + 1;
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));
868  encrypt_ptr=ap_list[count].ap_EncryptionMode;
869  security_ptr=ap_list[count].ap_SecurityModeEnabled;
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';
873  }
874  if (security_ptr > ap_list[count].ap_SecurityModeEnabled) {
875  *(security_ptr-1)='\0';
876  }
877 
878  /* parse SSID */
879  ptr = delim_ptr + 1;
880  delim_ptr=strchr(ptr, '\n');
881  *delim_ptr = '\0'; // alters the buffer passed in; put back the '\n' after printf_decode, if this is a problem
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);
885  // *delim_ptr='\n'; // put back the '\n' after printf_decode
886 
887  ptr = delim_ptr + 1;
888  // increment ap_count only if bssid is filled properly
889  // increment ap_count for non-empty SSIDs.
890  if(ap_list[count].ap_BSSID[0] != '\0' && ap_list[count].ap_SSID[0] != '\0')
891  count++;
892  }
893 
894  return count;
895 }
896 
897 /* example scan_results_buffer:
898  * bssid / frequency / signal level / flags / ssid
899  * b8:62:1f:e5:dd:5b 5200 -55 [WPA2-EAP-CCMP][ESS] BCLMT-Wifi
900  */
901 void log_top5_bssids(const char *scan_results_buffer)
902 {
903  static const int BSSID_LEN = 17; // aa:bb:cc:dd:ee:ff = 17 characters
904  char *ptr, *delim_ptr, bssid[BSSID_LEN+1], bssid_split[128] = {0}, *str = bssid_split;
905 
906  if (scan_results_buffer == NULL) return;
907 
908  /* skip heading */
909  ptr = strstr(scan_results_buffer,"/ ssid");
910  if (ptr == NULL) return;
911  ptr += strlen("/ ssid");
912 
913  for (int i = 0; i < 5 && ptr && ((delim_ptr = strchr(++ptr, '\t')) != NULL); ptr = strchr(ptr, '\n'))
914  {
915  if (delim_ptr - ptr != BSSID_LEN)
916  continue; // as we don't know exactly what we have here on this line
917 
918  memcpy(bssid, ptr, BSSID_LEN);
919  bssid[BSSID_LEN] = '\0';
920 
921  // strip ':' characters from bssid
922  char *pw = bssid; // write pointer
923  for (char *pr = bssid; *pr; pr++) // read pointer
924  if (*pr != ':')
925  *pw++ = *pr;
926  *pw = '\0';
927 
928  if (strlen(bssid) == 12) // aabbccddeeff = 12 characters
929  {
930  if (i > 0) *str++ = ',';
931  *str++ = '0' + i;
932  *str++ = ':';
933  strcpy(str, bssid);
934  str += 12;
935  i++;
936  }
937  }
938 
939  WIFI_LOG_INFO("bssid_split = %s\n", bssid_split);
940  telemetry_event_s("bssid_split", bssid_split);
941 }
942 
943 INT wifi_getNeighboringWiFiDiagnosticResult(INT radioIndex, wifi_neighbor_ap_t **neighbor_ap_array, UINT *output_array_size)
944 {
945  size_t return_len=sizeof(return_buf)-1;
946  int retry = 0;
947 
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");
952  } else {
953  WIFI_LOG_INFO("No in progress scanning, Starting a fresh scan.\n");
954  bNoAutoScan=TRUE;
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);
964  goto exit_err;
965  }
966  }
967  WIFI_LOG_INFO("Scan command returned %s \n", return_buf);
968  cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_STARTED;
969  }
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);
973  }
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);
977  //*output_array_size=0;
978  // goto exit_err;
979  } //else {
980  WIFI_LOG_INFO("Trying to read Scan results \n"); // Lets read scan_results even if it is timed out FIX:- Xi-6 Scan timeout
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);
985  if (ap_count > 0) {
986  int i;
987  *output_array_size = ap_count;
988  *neighbor_ap_array = (wifi_neighbor_ap_t *)malloc(ap_count*sizeof(wifi_neighbor_ap_t));
989 
990  if(*neighbor_ap_array == NULL) {
991  WIFI_LOG_INFO("Malloc Memory allocation failure\n");
992  goto exit_err;
993  }
994  for (i=0; i<*output_array_size; i++)
995  (*neighbor_ap_array)[i] = ap_list[i];
996  }
997  // }
998  cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
999  bNoAutoScan=FALSE;
1000  pthread_mutex_unlock(&wpa_sup_lock);
1001  return RETURN_OK;
1002 
1003  exit_err:
1004  cur_scan_state = WIFI_HAL_WPA_SUP_SCAN_STATE_IDLE;
1005  bNoAutoScan=FALSE;
1006  pthread_mutex_unlock(&wpa_sup_lock);
1007  return RETURN_ERR;
1008 }
1009 
1010 INT wifi_getSpecificSSIDInfo(const char* SSID, WIFI_HAL_FREQ_BAND band, wifi_neighbor_ap_t **filtered_ap_array, UINT *output_array_size) // ssid, band , output_array
1011 {
1012  char freq_list_string[BUF_SIZE];
1013  char cmd[BUF_SIZE];
1014  wifi_neighbor_ap_t filtered_APList[32];
1015  int bssCount = 0;
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)
1020  {
1021  if( RETURN_OK == getFrequencyListFor_Band(band,freq_list_string) && freq_list_string != NULL)
1022  {
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)
1025  return RETURN_ERR;
1026  pthread_mutex_lock(&wpa_sup_lock);
1027  wpaCtrlSendCmd(cmd); //wpa_cli freq_list + bands returned from the above static function parsed results
1028  pthread_mutex_unlock(&wpa_sup_lock);
1029  }
1030  else
1031  {
1032  WIFI_LOG_INFO("Error in getting the Frequency list for specified Band, NOT SCANNING . \n");
1033  return RETURN_ERR;
1034  }
1035  }
1036 
1037  int timeout = 8;
1038  bssCount = get_wifi_self_steer_matching_bss_list(SSID,filtered_APList,timeout); //setting time limit as 8 (to make scan complete)
1039  *output_array_size = bssCount;
1040  if(bssCount == 0)
1041  {
1042  WIFI_LOG_ERROR("No BSS found with given band and frequency \n");
1043  ret = RETURN_ERR;
1044  }
1045  else
1046  {
1047  WIFI_LOG_DEBUG("Found %d BSS ids' for SSID %s \n",bssCount,SSID);
1048  *filtered_ap_array = (wifi_neighbor_ap_t *)malloc(bssCount*sizeof(wifi_neighbor_ap_t));
1049  if(*filtered_ap_array == NULL)
1050  {
1051  WIFI_LOG_INFO("Memory allocation failure\n");
1052  ret = RETURN_ERR;
1053  }
1054  else
1055  {
1056  int i;
1057  for (i=0; i<*output_array_size; i++)
1058  (*filtered_ap_array)[i] = filtered_APList[i];
1059  ret = RETURN_OK;
1060  }
1061  }
1062  pthread_mutex_lock(&wpa_sup_lock);
1063  wpaCtrlSendCmd("SET freq_list 0"); //reset the freq_list wpa_cli freq_list 0
1064  pthread_mutex_unlock(&wpa_sup_lock);
1065  return ret;
1066 }
1067 
1068 /**************WiFi Diagnostics********************/
1069 
1070 INT wifi_getRadioSupportedFrequencyBands(INT radioIndex, CHAR *output_string) {
1071 
1072  int retStatus = RETURN_ERR;
1073  if(!output_string) {
1074  WIFI_LOG_ERROR("Error in getting supported bands.. Null string\n");
1075  return RETURN_ERR;
1076  }
1077  // Check if the client is Dual band supported
1078  if(isDualBandSupported() == true) {
1079  snprintf(output_string, 64, "2.4GHz,5GHz");
1080  } else {
1081  // Get Supported Modes and decide band based on that
1082  pthread_mutex_lock(&wpa_sup_lock);
1083  retStatus = wpaCtrlSendCmd("GET_CAPABILITY channels");
1084  if(retStatus == RETURN_OK) {
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");
1089  } else {
1090  WIFI_LOG_ERROR("Error in getting supported bands- Unable to get Freq Modes\n");
1091  }
1092  } else {
1093  WIFI_LOG_ERROR("Error in getting supported bands- Unable to Channel Capability\n");
1094  }
1095  pthread_mutex_unlock(&wpa_sup_lock);
1096  }
1097  WIFI_LOG_DEBUG("[%s:%d] SupportedFrequencyBands - %s\n",__FUNCTION__,__LINE__,output_string);
1098  return RETURN_OK;
1099 }
1100 
1101 INT wifi_getRadioOperatingFrequencyBand(INT radioIndex, CHAR *output_string) {
1102 
1103  int retStatus = RETURN_OK;
1104  CHAR frequency_string[8] = "";
1105  int frequency = 0;
1106 
1107  if(!output_string) {
1108  WIFI_LOG_ERROR("Error in getting supported bands.. Null string\n");
1109  return RETURN_ERR;
1110  }
1111  if (RETURN_OK == wifi_getRadioSignalParameter ("FREQUENCY", frequency_string) &&
1112  1 == sscanf (frequency_string, "%d", &frequency) &&
1113  0 != frequency ) {
1114  int band = frequency/1000;
1115  if(band == 5) {
1116  snprintf(output_string, 64, "5GHz");
1117  } else if (band == 2) {
1118  snprintf(output_string, 64, "2.4GHz");
1119  } else {
1120  WIFI_LOG_ERROR("[%s:%d] Failure in getting OperatingFrequencyBand \n",__FUNCTION__,__LINE__);
1121  retStatus = RETURN_ERR;
1122  }
1123  } else {
1124  WIFI_LOG_ERROR("[%s:%d] Failure in getting OperatingFrequencyBand - Failed to get Frequency\n",__FUNCTION__,__LINE__);
1125  retStatus = RETURN_ERR;
1126  }
1127  return retStatus;
1128 }
1129 
1130 INT wifi_getRadioSupportedStandards(INT radioIndex, CHAR *output_string) {
1131 
1132  FILE *fp = NULL;
1133  char cmd[BUFF_LEN_64];
1134  char result[BUFF_LEN_64];
1135 
1136  if (!output_string) {
1137  return RETURN_ERR;
1138  }
1139 
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));
1143 
1144  // TODO: this isn't going to work with multiple wlan interfaces
1145  snprintf(cmd,sizeof(cmd),"iw phy | grep 'HE Iftypes'| tr '\n' ' '");
1146  fp = popen(cmd,"r");
1147 
1148  if (fp != NULL)
1149  {
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");
1153  }
1154  pclose(fp);
1155  }
1156 
1157  return RETURN_OK;
1158 
1159 }
1160 
1161 INT wifi_getRadioStandard(INT radioIndex, CHAR *output_string, BOOL *gOnly, BOOL *nOnly, BOOL *acOnly) {
1162 
1163  CHAR frequency_string[8] = "";
1164  int frequency = 0;
1165  int ret = RETURN_ERR;
1166  int freqBand = 0;
1167 
1168  if(!output_string) {
1169  return RETURN_ERR;
1170  }
1171  if (RETURN_OK == wifi_getRadioSignalParameter ("FREQUENCY", frequency_string) &&
1172  1 == sscanf (frequency_string, "%d", &frequency) &&
1173  0 != frequency)
1174  {
1175  freqBand = frequency/1000;
1176  if(freqBand == 2 && radioIndex == 0) {
1177  snprintf(output_string, 64,"b,g,n");
1178  ret = RETURN_OK;
1179  } else if(freqBand == 5 && radioIndex == 1) {
1180  snprintf(output_string, 64,"a,n,ac");
1181  ret = RETURN_OK;
1182  } else {
1183  WIFI_LOG_ERROR("Invalid frequency band, Failure in getting Operating standard.\n");
1184  }
1185  }
1186  if(gOnly != NULL) *gOnly = false;
1187  if(nOnly != NULL) *nOnly = false;
1188  if(acOnly != NULL) *acOnly = false;
1189  return ret;
1190 }
1191 
1192 static void getPossibleChannelsFromCapability(char* channelCap,char *modeStr,char* output_string)
1193 {
1194  char *pch=NULL,*final=NULL;
1195  char *saveptr = NULL;
1196 
1197  pch = strtok_r(channelCap,"\n", &saveptr);
1198  while (pch != NULL)
1199  {
1200  if(strstr(pch,modeStr))
1201  {
1202  pch=strchr(pch,':');
1203  pch=pch+2;
1204  final = pch;
1205  while(*final != '\0')
1206  {
1207  if(*final == ' ')
1208  {
1209  *final= ',';
1210  }
1211  final++;
1212  }
1213  break;
1214  }
1215  pch = strtok_r (NULL, "\n", &saveptr);
1216  }
1217  if(pch !=NULL)
1218  strcpy(output_string,pch);
1219 }
1220 
1221 INT wifi_getRadioPossibleChannels(INT radioIndex, CHAR *output_string) {
1222 
1223  int ret;
1224  char tmp_buff[BUFF_LEN_1024];
1225  if(!output_string) {
1226  return RETURN_ERR;
1227  }
1228  memset(tmp_buff,0,BUFF_LEN_1024);
1229  pthread_mutex_lock (&wpa_sup_lock);
1230  ret = wpaCtrlSendCmd ("GET_CAPABILITY channels");
1231  if(ret == RETURN_OK)
1232  {
1233  strncpy(tmp_buff,return_buf,BUFF_LEN_1024);
1234  pthread_mutex_unlock (&wpa_sup_lock);
1235  }
1236  else
1237  {
1238  WIFI_LOG_ERROR("Error in getting channel capability.\n");
1239  pthread_mutex_unlock (&wpa_sup_lock);
1240  return RETURN_ERR;
1241  }
1242  if(radioIndex == 1)
1243  {
1244  getPossibleChannelsFromCapability(tmp_buff,"Mode[A]",output_string);
1245  }
1246  else
1247  {
1248  getPossibleChannelsFromCapability(tmp_buff,"Mode[G]",output_string);
1249  }
1250  return RETURN_OK;
1251 }
1252 
1253 INT wifi_getRadioOperatingChannelBandwidth(INT radioIndex, CHAR *output_string) {
1254 
1255  char resultBuff[64];
1256  char cmd[64];
1257  char interfaceName[10];
1258  int bandWidth = 0;
1259  FILE *fp = NULL;
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;
1265 
1266  if(!output_string) {
1267  return ret;
1268  }
1269 
1270  memset(interfaceName,0,sizeof(interfaceName));
1271  memset(cmd,0,sizeof(cmd));
1272  memset(resultBuff,0,sizeof(resultBuff));
1273 
1274  wifi_getRadioIfName(radioIndex, interfaceName);
1275  if(interfaceName[0] == '\0')
1276  {
1277  WIFI_LOG_ERROR("Unable to get wireless interface name, Get bandwidth failed \n");
1278  return ret;
1279  }
1280  snprintf(cmd,sizeof(cmd),"iw dev %s info | grep channel | cut -f 2 -d ','",interfaceName);
1281  fp = popen(cmd,"r");
1282  if (fp != NULL)
1283  {
1284  if ((fgets(resultBuff, sizeof (resultBuff), fp) != NULL) && (resultBuff[0] != '\0'))
1285  {
1286  sscanf(resultBuff,"%*s%d%*s",&bandWidth); /* Expected output :- " width: 80 MHz" */
1287  if(bandWidth != 0) {
1288  snprintf(output_string, 64, "%dMHz",bandWidth);
1289  WIFI_LOG_INFO("OperatingChannelBandwidth = %s\n",output_string);
1290  ret = RETURN_OK;
1291  } else {
1292  WIFI_LOG_ERROR("Failure in getting bandwidth \n");
1293  }
1294  }
1295  else
1296  {
1297  WIFI_LOG_ERROR("Unable to read Channel width from iw \n");
1298  iw_info_failed=true;
1299  }
1300  pclose(fp);
1301  }
1302  else
1303  {
1304  WIFI_LOG_ERROR("popen() failed. failure in getting Channel Bandwidth\n");
1305  iw_info_failed=true;
1306  }
1307 
1308  if(true == iw_info_failed) //iw info fallback
1309  {
1310  WIFI_LOG_INFO("iw info command failed, fall back to iw link command\n");
1311 
1312  memset(cmd,0,sizeof(cmd));
1313  memset(resultBuff,0,sizeof(resultBuff));
1314 
1315  snprintf(cmd,sizeof(cmd),"iw dev %s link | grep tx",interfaceName);
1316  fp = popen(cmd,"r");
1317  if (fp != NULL)
1318  {
1319  if ((fgets(resultBuff, sizeof (resultBuff), fp) != NULL) && (resultBuff[0] != '\0'))
1320  {
1321  char* resultBuff_P=resultBuff;
1322  while ((bandwidth_string = strtok_r(resultBuff_P, " ", &resultBuff_P)))
1323  {
1324  bandwidth_token = strcasestr(bandwidth_string, "MHz");
1325  if(NULL != bandwidth_token )
1326  {
1327  strcpy(output_string,bandwidth_string); //copy bandwidth string to o/p string
1328  bandwidth_found=true;
1329  break;
1330  }
1331  }
1332  if (true == bandwidth_found)
1333  {
1334  WIFI_LOG_INFO("OperatingChannelBandwidth = %s\n",output_string);
1335  ret = RETURN_OK;
1336  }
1337  else
1338  {
1339  WIFI_LOG_ERROR("MHz information missing in iw link o/p \n");
1340  }
1341  }
1342  else
1343  {
1344  WIFI_LOG_ERROR("Failure in getting bandwidth \n");
1345  }
1346  }
1347  else
1348  {
1349  WIFI_LOG_ERROR("popen() failed. failure in getting Channel Bandwidth\n");
1350  }
1351 
1352  }
1353  return ret;
1354 }
1355 
1356 INT wifi_getSSIDName(INT apIndex, CHAR *output_string) {
1357 
1358  int ret = RETURN_ERR;
1359  if (output_string != NULL)
1360  {
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"); // include '\n' to avoid a match with "bssid"
1366  if (ssid == NULL)
1367  {
1368  WIFI_LOG_ERROR( "%s: ssid not found in STATUS output\n", __FUNCTION__);
1369  }
1370  else
1371  {
1372  // TODO: assumes 'output_string' is at least MAX_SSID_LEN+1 big. wifi_getSSIDName needs 'max_len' 3rd arg to avoid assumption.
1373  printf_decode ((u8*)output_string, MAX_SSID_LEN+1, ssid);
1374  ret = RETURN_OK;
1375  }
1376  pthread_mutex_unlock(&wpa_sup_lock);
1377  }
1378  return ret;
1379 }
1380 
1381 INT wifi_setSSIDName(INT apIndex, CHAR *ssid_string) {
1382 
1383  return RETURN_OK;
1384 }
1385 
1386 INT wifi_getBaseBSSID(INT ssidIndex, CHAR *output_string) {
1387 
1388  char *bssid = NULL;
1389  int maxBssidLen = 18;
1390 
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");
1396  if (bssid == NULL)
1397  goto exit_err;
1398  else
1399  if (output_string != NULL) strncpy(output_string, bssid,maxBssidLen);
1400 
1401  pthread_mutex_unlock(&wpa_sup_lock);
1402  return RETURN_OK;
1403 
1404 
1405 exit_err:
1406  pthread_mutex_unlock(&wpa_sup_lock);
1407  return RETURN_ERR;
1408 }
1409 
1410 INT wifi_getSSIDMACAddress(INT ssidIndex, CHAR *output_string) {
1411 
1412  char *bssid;
1413 
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");
1419  if (bssid == NULL)
1420  goto exit_err;
1421  else
1422  if (output_string != NULL) strcpy(output_string, bssid);
1423 
1424  pthread_mutex_unlock(&wpa_sup_lock);
1425  return RETURN_OK;
1426 
1427 
1428 exit_err:
1429  pthread_mutex_unlock(&wpa_sup_lock);
1430  return RETURN_ERR;
1431 }
1432 
1433 static INT wifi_getRadioSignalParameter (const CHAR* parameter, CHAR *output_string) {
1434 
1435  if (!parameter || !output_string) {
1436  return RETURN_ERR;
1437  }
1438 
1439  char *parameter_value= NULL;
1440  int ret = RETURN_ERR;
1441 
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)))
1447  {
1448  strcpy (output_string, parameter_value);
1449  ret = RETURN_OK;
1450  }
1451  pthread_mutex_unlock (&wpa_sup_lock);
1452 
1453  WIFI_LOG_DEBUG( "[%s] return code = [%d], parameter = [%s], parameter_value = [%s]\n",
1454  __FUNCTION__, ret, parameter, parameter_value ? parameter_value : "NULL");
1455  return ret;
1456 }
1457 
1458 static int wifi_getRadioChannelFromFrequency(int frequency)
1459 {
1460  if (frequency == 2484)
1461  return 14;
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;
1470  else
1471  return 0;
1472 }
1473 // Ping to wpa_supplicant and get connection Status, Ret = 0-> success, -1-> Response failure ,-2-> Command failure
1474 static int wifi_getWpaSupplicantStatus()
1475 {
1476  int retStatus = -1;
1477  char temp_buff[50];
1478  int pingStatus = -1;
1479 
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);
1487 
1488  if(temp_buff[0] != '\0' && retStatus == 0 )
1489  {
1490  if(strncmp(temp_buff,"PONG",4) == 0)
1491  {
1492  pingStatus = 0;
1493  }
1494  else
1495  {
1496  pingStatus = -1; // Response failure
1497  }
1498  }
1499  else
1500  {
1501  pingStatus = -2; // Command Failure
1502  }
1503  return pingStatus;
1504 }
1505 
1506 // Open wpa_supplicant Control and Monitor Connection, Ret = 0-> Success , -1 -> failure
1507 static int wifi_openWpaSupConnection()
1508 {
1509  int retStatus = -1;
1510 
1511  // Open Control connection
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");
1517  } else{
1518  WIFI_LOG_ERROR("Failure in opening wpa_supplicant control connection.\n");
1519  pthread_mutex_unlock(&wpa_sup_lock);
1520  return retStatus;
1521  }
1522  pthread_mutex_unlock(&wpa_sup_lock);
1523 
1524  // Open Monitor Connection
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");
1532  } else {
1533  WIFI_LOG_INFO("Monitor connection Attached Successfully. \n");
1534  retStatus = 0;
1535  }
1536  } else{
1537  WIFI_LOG_ERROR("Failure in opening wpa_supplicant monitor connection.\n");
1538  }
1539  pthread_mutex_unlock(&wpa_sup_lock);
1540  return retStatus;
1541 }
1542 void* monitor_wpa_health(void* param)
1543 {
1544  int retStatus = -1;
1545  int printInterval = 0;
1546  int pingCount = 0;
1547  int pingRecoveryCount = 0;
1548  (void)param;
1549 
1550  while(true)
1551  {
1552  retStatus = wifi_getWpaSupplicantStatus();
1553  if(retStatus == 0)
1554  {
1555  if(printInterval >= 4)
1556  {
1557  WIFI_LOG_INFO("wpa_supplicant heartbeat success. \n");
1558  printInterval = 0;
1559  }
1560  else
1561  printInterval++;
1562  }
1563  else
1564  {
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);
1567  pingCount = 0;
1568  WIFI_LOG_INFO("Trying for 5 continues pings...\n");
1569  while(pingCount < 5)
1570  {
1571  retStatus = wifi_getWpaSupplicantStatus();
1572  if(!retStatus) {
1573  WIFI_LOG_INFO("wpa_supplicant heartbeat success. , Breaking Ping attempts\n");
1574  // If the connection is alternatively failing for 3 times, Then it seems like an inconsistent connection, Lets reopen a new control connection.
1575  if(pingRecoveryCount >= 2) {
1576  WIFI_LOG_INFO("wpa_supplicant heartbeat - inconsistent control connection: Reopen new one.\n");
1577  wifi_openWpaSupConnection();
1578  pingRecoveryCount = 0;
1579  } else {
1580  pingRecoveryCount++;
1581  }
1582  break; // Got one Success lets break
1583  }
1584  else
1585  {
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);
1588  }
1589  pingCount++;
1590  wifi_usleep(1000000 * 3);
1591  }
1592  if(pingCount >= 5) {
1593  WIFI_LOG_INFO("Heartbeat failed for all attempts, Trying to reopen Connection.\n");
1594  wifi_openWpaSupConnection();
1595  }
1596  }
1597  wifi_usleep(WPA_SUP_PING_INTERVAL * 1000000);
1598  }
1599 }
1600 
1601 INT wifi_getRadioChannel(INT radioIndex,ULONG *output_ulong) {
1602 
1603  if(!output_ulong) {
1604  return RETURN_ERR;
1605  }
1606 
1607  CHAR frequency_string[8] = "";
1608  int frequency = 0;
1609  int channel = 0;
1610  int ret = RETURN_ERR;
1611  if (RETURN_OK == wifi_getRadioSignalParameter ("FREQUENCY", frequency_string) &&
1612  1 == sscanf (frequency_string, "%d", &frequency) &&
1613  0 != frequency &&
1614  0 != (channel = wifi_getRadioChannelFromFrequency (frequency)))
1615  {
1616  *output_ulong = channel;
1617  ret = RETURN_OK;
1618  }
1619 
1620  WIFI_LOG_DEBUG( "[%s] return code = [%d], Channel Spec: %lu\n", __FUNCTION__, ret, *output_ulong);
1621  return ret;
1622 }
1623 
1624 INT wifi_getRadioChannelsInUse(INT radioIndex, CHAR *output_string) {
1625  if (!output_string)
1626  return RETURN_ERR;
1627  snprintf(output_string, 256, (radioIndex==0)?"1,6,11":"36,40");
1628  return RETURN_OK;
1629 }
1630 
1631 INT wifi_getSSIDNumberOfEntries(ULONG *output) {
1632 
1633  if(!output) {
1634  return RETURN_ERR;
1635  }
1636 
1637  *output = 1;
1638  WIFI_LOG_INFO("SSID entries:1\n");
1639  return RETURN_OK;
1640 
1641 }
1642 
1643 INT wifi_getRadioTrafficStats(INT radioIndex, wifi_radioTrafficStats_t *output_struct) {
1644 
1645  FILE *fp = NULL;
1646  char resultBuff[BUF_SIZE];
1647  char cmd[50];
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;
1651  int numParams = 0;
1652  int noise = 0;
1653  char* ptr = NULL;
1654 
1655  if(!output_struct) {
1656  WIFI_LOG_INFO("output struct is null");
1657  return 0;
1658  }
1659 
1660  // memset arrays
1661  memset(resultBuff,0,sizeof(resultBuff));
1662  memset(cmd,0,sizeof(cmd));
1663  memset(interfaceName,0,sizeof(interfaceName));
1664 
1665  wifi_getRadioIfName(0,interfaceName);
1666  snprintf(cmd,sizeof(cmd),"cat /proc/net/dev | grep %s",interfaceName);
1667  fp = popen(cmd,"r");
1668  if (fp != NULL)
1669  {
1670  if (fgets(resultBuff, sizeof (resultBuff), fp) != NULL)
1671  {
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 );
1673  if(numParams != 9)
1674  {
1675  WIFI_LOG_ERROR("Error in parsing Radio Stats params \n");
1676  }
1677  output_struct->radio_PacketsSent = tx_packets;
1678  output_struct->radio_PacketsReceived = rx_packets;
1679  output_struct->radio_BytesSent = tx_bytes;
1680  output_struct->radio_BytesReceived = rx_bytes;
1681  output_struct->radio_ErrorsReceived = rx_err;
1682  output_struct->radio_ErrorsSent = tx_err;
1683  output_struct->radio_DiscardPacketsSent = tx_drop;
1684  output_struct->radio_DiscardPacketsReceived = rx_drop;
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);
1686  }
1687  else
1688  {
1689  WIFI_LOG_ERROR("Error in reading /proc/net/dev file \n");
1690  }
1691  pclose(fp);
1692  }
1693  else
1694  {
1695  WIFI_LOG_ERROR("Error in popen() : Opening /proc/net/dev failed \n");
1696  }
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");
1702  if(NULL != ptr)
1703  {
1704  noise = atoi(ptr);
1705  output_struct->radio_NoiseFloor = noise;
1706  WIFI_LOG_INFO("\n noise = %d ",noise);
1707  }
1708  else
1709  {
1710  WIFI_LOG_INFO("Noise is not available in siganl poll \n");
1711  }
1712  pthread_mutex_unlock(&wpa_sup_lock);
1713  return RETURN_OK;
1714 }
1715 
1716 INT wifi_getRadioEnable(INT radioIndex, BOOL *output_bool) {
1717  *output_bool = (g_wpa_monitor != NULL);
1718  WIFI_LOG_INFO("The radio is %s\n", g_wpa_monitor ? "enabled" : "not enabled");
1719  return RETURN_OK;
1720 }
1721 
1722 INT wifi_getRadioStatus(INT radioIndex, CHAR *output_string) {
1723  int ret = RETURN_ERR;
1724  char radio_status[20];
1725  char cli_buff[512];
1726  char *ptr = NULL;
1727 
1728  if(!output_string){
1729  WIFI_LOG_ERROR("Output_string is null\n");
1730  return ret;
1731  }
1732 
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));
1738  if (status == 0)
1739  {
1740  ptr = getValue(cli_buff, "wpa_state");
1741  if(NULL != ptr)
1742  {
1743  strcpy(radio_status,ptr);
1744  if(strcmp(radio_status,"INTERFACE_DISABLED") == 0)
1745  {
1746  strcpy(output_string,"DOWN");
1747  }
1748  else
1749  {
1750  strcpy(output_string,"UP");
1751  }
1752  ret = RETURN_OK;
1753  WIFI_LOG_INFO("\n WPA State : %s, Radio State :%s ",radio_status,output_string);
1754  }
1755  else
1756  {
1757  ret = RETURN_ERR;
1758  WIFI_LOG_INFO("Radio State is not available in wpa_cli STATUS \n");
1759  }
1760  }
1761  else
1762  {
1763  char path[PATH_MAX];
1764  snprintf(path, PATH_MAX, "/sys/class/net/%s/operstate", g_ctx.conf.wlan_Interface);
1765 
1766  char *operstate = wifi_readFile(path, true);
1767  if (operstate) {
1768  if (!strncasecmp(operstate, "up", 2)) {
1769  strcpy(output_string, "UP");
1770  ret = RETURN_OK;
1771  }
1772  else if (!strncasecmp(operstate, "down", 4)) {
1773  strcpy(output_string, "DOWN");
1774  ret = RETURN_OK;
1775  }
1776  else {
1777  WIFI_LOG_ERROR("failed to parse the operstate from %s. '%s'\n",
1778  path, operstate);
1779  ret = RETURN_ERR;
1780  }
1781  WIFI_LOG_INFO("The radio is %s (operstate=%s)\n", output_string, operstate);
1782  free(operstate);
1783  }
1784  else {
1785  ret = RETURN_ERR;
1786  }
1787  }
1788  return ret;
1789 }
1790 
1791 INT wifi_getRegulatoryDomain(INT radioIndex, CHAR* output_string){
1792  int ret = RETURN_ERR;
1793  if(!output_string){
1794  WIFI_LOG_INFO("Output_string is null\n");
1795  return ret;
1796  }
1797  pthread_mutex_lock(&wpa_sup_lock);
1798  int status = wpaCtrlSendCmd("GET COUNTRY");
1799 
1800  if(status == 0 && return_buf[0] != '\0'){
1801  if(snprintf(output_string, 4, "%s", return_buf) >= 0)
1802  ret = RETURN_OK;
1803  }
1804  else{
1805  ret = RETURN_ERR;
1806  }
1807  pthread_mutex_unlock(&wpa_sup_lock);
1808  return ret;
1809 }
1810 
1811 INT wifi_getRadioMaxBitRate(INT radioIndex, CHAR *output_string) {
1812 
1813  WIFI_LOG_INFO("MaxBitRate information will be implemented\n");
1814  return RETURN_ERR;
1815 }
1816 
1817 INT wifi_getRadioMCS(INT radioIndex, INT *output_INT){
1818 
1819  WIFI_LOG_INFO("MCS could not be determined\n");
1820  return RETURN_ERR;
1821 }
1822 
1823 INT wifi_getSSIDTrafficStats(INT ssidIndex, wifi_ssidTrafficStats_t *output_struct) {
1824 
1825  char filename[]="/tmp/wlparam.txt";
1826  char *bufPtr=NULL;
1827  char *saveptr = NULL;
1828  char *ptrToken;
1829 
1830  if(!output_struct) {
1831  WIFI_LOG_INFO("output struct is null");
1832  return 0;
1833  }
1834  system("wl counter > /tmp/wlparam.txt");
1835  bufPtr=wifi_readFile(filename, false);
1836  if(bufPtr)
1837  {
1838  ptrToken = strtok_r (bufPtr," \t\n", &saveptr);
1839  while (ptrToken != NULL)
1840  {
1841  if (strcmp(ptrToken, "txdatamcast") == 0)
1842  {
1843  ptrToken = strtok_r (NULL, " \t\n", &saveptr);
1844  output_struct->ssid_MulticastPacketsSent=strtoull(ptrToken, NULL, 10);
1845  WIFI_LOG_INFO("\n txdatamcast = %llu ",strtoull(ptrToken, NULL, 10));
1846  }
1847  else if (strcmp(ptrToken, "txdatabcast") == 0)
1848  {
1849  ptrToken = strtok_r (NULL, " \t\n", &saveptr);
1850  output_struct->ssid_BroadcastPacketsSent=strtoull(ptrToken, NULL, 10);
1851  WIFI_LOG_INFO("\n txdatabcast = %llu ",strtoull(ptrToken, NULL, 10));
1852  }
1853  else if (strcmp(ptrToken, "txnoack") == 0)
1854  {
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));
1858  }
1859  else
1860  {
1861  ptrToken = strtok_r (NULL, " \t\n", &saveptr);
1862  }
1863  }
1864  free(bufPtr);
1865  }
1866 
1867  //TODO: Get the following stats in. Commenting it out to unblock basic testing
1868  /*NETAPP_WIFI_STATS tTestInfo;
1869  memset(&tTestInfo, 0, sizeof(tTestInfo));
1870  NetAppWiFiTestGetStats(hNetApp, &tTestInfo);
1871  output_struct->ssid_MulticastPacketsSent = tTestInfo.txdatamcast;
1872  output_struct->ssid_BroadcastPacketsSent = tTestInfo.txdatabcast;
1873  output_struct->ssid_ACKFailureCount = tTestInfo.txnoack;*/
1874  return RETURN_OK;
1875 }
1876 
1877 INT wifi_getRadioExtChannel(INT radioIndex, CHAR *output_string) {
1878 
1879  WIFI_LOG_INFO("Extension channel is Auto\n");
1880  strcpy(output_string, "Auto");
1881  return RETURN_OK;
1882 }
1883 
1884 /***************Stubbed out functions**********************/
1885 INT wifi_getRadioNumberOfEntries(ULONG *output) {
1886  WIFI_LOG_INFO("The radio number of entries is always 1\n");
1887  *output = 1;
1888  return RETURN_OK;
1889 }
1890 
1891 INT wifi_setRadioEnable(INT radioIndex, BOOL enable) {
1892  return RETURN_OK;
1893 }
1894 
1895 INT wifi_getRadioIfName(INT radioIndex, CHAR *output_string) {
1896  strcpy(output_string, g_ctx.conf.wlan_Interface);
1897  return RETURN_OK;
1898 }
1899 INT wifi_setRadioScanningFreqList(INT radioIndex, const CHAR *freqList)
1900 {
1901  int result = RETURN_OK;
1902  char cmd[BUF_SIZE];
1903 
1904  memset(cmd,0,BUF_SIZE);
1905  snprintf(cmd,BUF_SIZE,"SET freq_list %s",freqList);
1906  pthread_mutex_lock(&wpa_sup_lock);
1907  if(wpaCtrlSendCmd(cmd) != RETURN_OK)
1908  {
1909  result = RETURN_ERR;
1910  }
1911  pthread_mutex_unlock(&wpa_sup_lock);
1912  return result;
1913 }
1914 INT wifi_getDualBandSupport()
1915 {
1916  if(isDualBandSupported() == true)
1917  return 1;
1918  else
1919  return 0;
1920 }
1921 
1922 
1923 INT wifi_setRadioChannelMode(INT radioIndex, CHAR *channelMode, BOOL gOnlyFlag, BOOL nOnlyFlag, BOOL acOnlyFlag) {
1924  return RETURN_OK;
1925 }
1926 
1927 INT wifi_setRadioChannel(INT radioIndex, ULONG channel) {
1928  return RETURN_OK;
1929 }
1930 
1931 INT wifi_getRadioAutoChannelSupported(INT radioIndex, BOOL *output_bool) {
1932  return RETURN_OK;
1933 }
1934 
1935 INT wifi_getRadioAutoChannelEnable(INT radioIndex, BOOL *output_bool) {
1936  return RETURN_OK;
1937 }
1938 
1939 INT wifi_setRadioAutoChannelEnable(INT radioIndex, BOOL enable) {
1940  return RETURN_OK;
1941 }
1942 
1943 INT wifi_getRadioAutoChannelRefreshPeriod(INT radioIndex, ULONG *output_ulong) {
1944  return RETURN_OK;
1945 }
1946 
1947 INT wifi_setRadioAutoChannelRefreshPeriod(INT radioIndex, ULONG seconds) {
1948  return RETURN_OK;
1949 }
1950 
1951 INT wifi_setRadioOperatingChannelBandwidth(INT radioIndex, CHAR *bandwidth) {
1952  return RETURN_OK;
1953 }
1954 
1955 INT wifi_setRadioExtChannel(INT radioIndex, CHAR *string) {
1956  return RETURN_OK;
1957 }
1958 
1959 INT wifi_getRadioGuardInterval(INT radioIndex, CHAR *output_string) {
1960  return RETURN_OK;
1961 }
1962 
1963 INT wifi_setRadioGuardInterval(INT radioIndex, CHAR *string) {
1964  return RETURN_OK;
1965 }
1966 
1967 INT wifi_setRadioMCS(INT radioIndex, INT MCS) {
1968  return RETURN_OK;
1969 }
1970 
1971 INT wifi_getRadioTransmitPowerSupported(INT radioIndex, CHAR *output_list) {
1972  return RETURN_OK;
1973 }
1974 
1975 INT wifi_getRadioTransmitPower(INT radioIndex, INT *output_INT) {
1976  return RETURN_OK;
1977 }
1978 
1979 INT wifi_setRadioTransmitPower(INT radioIndex, ULONG TransmitPower) {
1980  return RETURN_OK;
1981 }
1982 
1983 INT wifi_getRadioIEEE80211hSupported(INT radioIndex, BOOL *Supported) {
1984  return RETURN_OK;
1985 }
1986 
1987 INT wifi_getRadioIEEE80211hEnabled(INT radioIndex, BOOL *enable) {
1988  return RETURN_OK;
1989 }
1990 
1991 INT wifi_setRadioIEEE80211hEnabled(INT radioIndex, BOOL enable) {
1992  return RETURN_OK;
1993 }
1994 
1995 INT wifi_getRadioCarrierSenseThresholdRange(INT radioIndex, INT *output) {
1996  return RETURN_OK;
1997 }
1998 
1999 INT wifi_getRadioCarrierSenseThresholdInUse(INT radioIndex, INT *output) {
2000  return RETURN_OK;
2001 }
2002 INT wifi_setRadioCarrierSenseThresholdInUse(INT radioIndex, INT threshold) {
2003  return RETURN_OK;
2004 }
2005 
2006 INT wifi_getRadioChannelSwitchingCount(INT radioIndex, INT *output) {
2007  return RETURN_OK;
2008 }
2009 
2010 INT wifi_getRadioBeaconPeriod(INT radioIndex, UINT *output) {
2011  return RETURN_OK;
2012 }
2013 
2014 INT wifi_setRadioBeaconPeriod(INT radioIndex, UINT BeaconPeriod) {
2015  return RETURN_OK;
2016 }
2017 
2018 INT wifi_getRadioBasicDataTransmitRates(INT radioIndex, CHAR *output) {
2019  return RETURN_OK;
2020 }
2021 
2022 INT wifi_setRadioBasicDataTransmitRates(INT radioIndex, CHAR *TransmitRates) {
2023  return RETURN_OK;
2024 }
2025 
2026 INT wifi_setRadioTrafficStatsMeasure(INT radioIndex, wifi_radioTrafficStatsMeasure_t *input_struct) {
2027  return RETURN_OK;
2028 }
2029 
2030 INT wifi_getRadioStatsReceivedSignalLevel(INT radioIndex, INT signalIndex, INT *SignalLevel) {
2031  return RETURN_OK;
2032 }
2033 
2034 INT wifi_applyRadioSettings(INT radioIndex) {
2035  return RETURN_OK;
2036 }
2037 
2038 INT wifi_getSSIDRadioIndex(INT ssidIndex, INT *radioIndex) {
2039  return RETURN_OK;
2040 }
2041 
2042 INT wifi_getSSIDEnable(INT ssidIndex, BOOL *output_bool) {
2043  return RETURN_OK;
2044 }
2045 
2046 INT wifi_setSSIDEnable(INT ssidIndex, BOOL enable) {
2047  return RETURN_OK;
2048 }
2049 
2050 INT wifi_getSSIDStatus(INT ssidIndex, CHAR *output_string) {
2051  return RETURN_OK;
2052 }
2053 
2054 INT wifi_applySSIDSettings(INT ssidIndex) {
2055  return RETURN_OK;
2056 }
2057 
2058 void wifi_initContext(wifi_context_t * ctx, wifi_halConfig_t *conf)
2059 {
2060  memset(ctx, 0, sizeof(*ctx));
2061  if (!conf) {
2062  strcpy(ctx->conf.wlan_Interface, "wlan0");
2063  }
2064  else {
2065  strncpy(ctx->conf.wlan_Interface, conf->wlan_Interface, WLAN_IFNAMSIZ -1);
2066  }
2067 
2068  snprintf(ctx->ctrl_path, WLAN_PATHMAX, "/var/run/wpa_supplicant/%s", ctx->conf.wlan_Interface);
2069 }
2070 
2071 void wifi_interfaceSetEnabled(const char * ifname, bool enable)
2072 {
2073  int ret;
2074  bool do_set;
2075  struct ifreq req;
2076 
2077  int soc = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
2078  if (soc == -1) {
2079  WIFI_LOG_ERROR("error checking interface status, socket error. %s\n",
2080  strerror(errno));
2081  return;
2082  }
2083 
2084  do_set = false;
2085  memset(&req, 0, sizeof(req));
2086  strncpy(req.ifr_ifrn.ifrn_name, ifname, IFNAMSIZ);
2087 
2088  // read the current interface status.
2089  ret = ioctl(soc, SIOCGIFFLAGS, &req);
2090  if (ret == -1) {
2091  WIFI_LOG_ERROR("failed to get current state of interface %s. %s",
2092  ifname, strerror(errno));
2093  return;
2094  }
2095 
2096  if ((req.ifr_flags & IFF_UP) == IFF_UP) {
2097  if (!enable) {
2098  req.ifr_flags &= ~IFF_UP;
2099  do_set = true;
2100  }
2101  }
2102  else {
2103  if (enable) {
2104  req.ifr_flags |= IFF_UP;
2105  do_set = true;
2106  }
2107  }
2108 
2109  if (do_set) {
2110  ret = ioctl(soc, SIOCSIFFLAGS, &req);
2111  if (ret == -1) {
2112  WIFI_LOG_ERROR("failed to disable interface. %s\n", strerror(errno));
2113  }
2114  }
2115 }
2116 
_wifi_sta_stats::sta_Encryption
char sta_Encryption[64]
WiFi Encryption Type AES, TKIP, etc.
Definition: wifi_common_hal.h:461
wifi_setRadioExtChannel
int wifi_setRadioExtChannel(int radioIndex, char *string)
Set the extension channel.
_wifi_radioTrafficStats::radio_DiscardPacketsReceived
unsigned long radio_DiscardPacketsReceived
The total number of inbound packets which were chosen to be discarded even though no errors had been ...
Definition: wifi_common_hal.h:357
wifi_setRadioBasicDataTransmitRates
int wifi_setRadioBasicDataTransmitRates(int radioIndex, char *TransmitRates)
The basic data transmit rate.
wifi_getRadioIfName
int wifi_getRadioIfName(int radioIndex, char *output_string)
Get the Radio Interface name from platform.
wifi_setRadioIEEE80211hEnabled
int wifi_setRadioIEEE80211hEnabled(int radioIndex, unsigned char enable)
Set 80211h feature enable.
wifi_getRadioCarrierSenseThresholdRange
int wifi_getRadioCarrierSenseThresholdRange(int radioIndex, int *output)
Gets the carrier sense ranges supported by the radio, measured in dBm.
wifi_getRadioGuardInterval
int wifi_getRadioGuardInterval(int radioIndex, char *output_string)
Get the guard interval value. eg "400nsec" or "800nsec".
_wifi_sta_stats::sta_PhyRate
float sta_PhyRate
Indicates the Physical rate (Mbps)
Definition: wifi_common_hal.h:462
wifi_getRadioStatsReceivedSignalLevel
int wifi_getRadioStatsReceivedSignalLevel(int radioIndex, int signalIndex, int *SignalLevel)
Set radio traffic static Measuring rules.
wifi_setSSIDEnable
int wifi_setSSIDEnable(int ssidIndex, unsigned char enable)
Set SSID enable configuration parameters.
wifi_getRadioIEEE80211hEnabled
int wifi_getRadioIEEE80211hEnabled(int radioIndex, unsigned char *enable)
Get the 80211h feature enable.
wifi_setRadioAutoChannelEnable
int wifi_setRadioAutoChannelEnable(int radioIndex, unsigned char enable)
Set the Auto Channel Selection / Dynamic channel selection enable status.
wifi_getRadioChannelsInUse
int wifi_getRadioChannelsInUse(int radioIndex, char *output_string)
Gets the list of channels currently in use.
wifi_getSSIDEnable
int wifi_getSSIDEnable(int ssidIndex, unsigned char *output_bool)
Get SSID enable configuration parameters.
wifi_setRadioTrafficStatsMeasure
int wifi_setRadioTrafficStatsMeasure(int radioIndex, wifi_radioTrafficStatsMeasure_t *input_struct)
Set radio traffic static Measuring rules.
_wifi_sta_stats::sta_SSID
char sta_SSID[64]
The current connected SSID name.
Definition: wifi_common_hal.h:457
wifi_getSSIDRadioIndex
int wifi_getSSIDRadioIndex(int ssidIndex, int *radioIndex)
Get the radio index assocated with the SSID entry.
RETURN_OK
#define RETURN_OK
Defines for function returns.
Definition: wifi_common_hal.h:218
_wifi_radioTrafficStats::radio_ErrorsReceived
unsigned long radio_ErrorsReceived
The total number of inbound packets that contained errors preventing them from being delivered to a h...
Definition: wifi_common_hal.h:355
wifi_getRadioExtChannel
int wifi_getRadioExtChannel(int radioIndex, char *output_string)
Get the secondary extension channel position.
wifi_getRadioIEEE80211hSupported
int wifi_getRadioIEEE80211hSupported(int radioIndex, unsigned char *Supported)
Function to check 80211h is supported or not.
_wifi_halSettings
Definition: wifi_common_hal.h:559
wifi_getRadioOperatingFrequencyBand
int wifi_getRadioOperatingFrequencyBand(int radioIndex, char *output_string)
Get the frequency band at which the radio is operating.
_wifi_radioTrafficStats
Definition: wifi_common_hal.h:345
_wifi_sta_stats::sta_BSSID
char sta_BSSID[64]
The BSSID used for connected SSID.
Definition: wifi_common_hal.h:458
wifi_setRadioChannel
int wifi_setRadioChannel(int radioIndex, unsigned long channel)
Set the running channel number.
_wifi_radioTrafficStats::radio_PacketsReceived
unsigned long radio_PacketsReceived
The total number of packets received on the interface.
Definition: wifi_common_hal.h:352
wifi_getRadioSupportedFrequencyBands
int wifi_getRadioSupportedFrequencyBands(int radioIndex, char *output_string)
Get Supported frequency bands at which the radio can operate.
_wifi_radioTrafficStats::radio_ErrorsSent
unsigned long radio_ErrorsSent
The total number of outbound packets that could not be transmitted because of errors.
Definition: wifi_common_hal.h:354
_wifi_sta_stats::sta_Frequency
unsigned int sta_Frequency
Current Operating Frequency.
Definition: wifi_common_hal.h:465
wifi_setRadioChannelMode
int wifi_setRadioChannelMode(int radioIndex, char *channelMode, unsigned char gOnlyFlag, unsigned char nOnlyFlag, unsigned char acOnlyFlag)
Set the radio operating mode and pure mode flag.
wifi_getRadioAutoChannelRefreshPeriod
int wifi_getRadioAutoChannelRefreshPeriod(int radioIndex, unsigned long *output_ulong)
Get the Auto Channel Selection / Dynamic channel selection refresh period in seconds.
_wifi_ssidTrafficStats::ssid_MulticastPacketsSent
unsigned long ssid_MulticastPacketsSent
The total number of packets that higher-level protocols requested for transmission and which were add...
Definition: wifi_common_hal.h:399
_wifi_ssidTrafficStats::ssid_BroadcastPacketsSent
unsigned long ssid_BroadcastPacketsSent
The total number of packets that higher-level protocols requested for transmission and which were add...
Definition: wifi_common_hal.h:401
_wifi_radioTrafficStatsMeasure
Definition: wifi_common_hal.h:372
wifi_setRadioOperatingChannelBandwidth
int wifi_setRadioOperatingChannelBandwidth(int radioIndex, char *bandwidth)
Set the Operating Channel Bandwidth.
wifi_setSSIDName
int wifi_setSSIDName(int apIndex, char *ssid_string)
Set SSID name.
_wifi_radioTrafficStats::radio_BytesSent
unsigned long radio_BytesSent
The total number of bytes transmitted out of the interface, including framing characters.
Definition: wifi_common_hal.h:349
wifi_getRadioAutoChannelSupported
int wifi_getRadioAutoChannelSupported(int radioIndex, unsigned char *output_bool)
Check if the driver support the Auto Channel Selection / Dynamic channel selection.
wifi_getBaseBSSID
int wifi_getBaseBSSID(int ssidIndex, char *output_string)
Get the BSSID. Basic Service Set Identifier (BSSID) is the mac addresss of the wireless access point.
_wifi_sta_stats::sta_BAND
char sta_BAND[16]
The BAND used for connected SSID.
Definition: wifi_common_hal.h:459
wifi_applyRadioSettings
int wifi_applyRadioSettings(int radioIndex)
This API is used to apply (push) all previously set radio level variables and make these settings act...
wifi_getRadioTransmitPower
int wifi_getRadioTransmitPower(int radioIndex, int *output_INT)
Get the current transmit Power.
wifi_setRadioGuardInterval
int wifi_setRadioGuardInterval(int radioIndex, char *string)
Set the guard interval value.
wifi_getSSIDStatus
int wifi_getSSIDStatus(int ssidIndex, char *output_string)
Get the SSID enable status.
wifi_getSSIDName
int wifi_getSSIDName(int apIndex, char *output_string)
Get SSID name.
_wifi_neighbor_ap::ap_BSSID
char ap_BSSID[64]
[MACAddress] The BSSID used for the neighboring WiFi SSID.
Definition: wifi_common_hal.h:413
ULONG
#define ULONG
Defines for the basic data types.
Definition: wifi_common_hal.h:168
wifi_getRadioTrafficStats
int wifi_getRadioTrafficStats(int radioIndex, wifi_radioTrafficStats_t *output_struct)
Get detail radio traffic statistics information.
wifi_getRadioMCS
int wifi_getRadioMCS(int radioIndex, int *output_INT)
Get the Modulation Coding Scheme index.
wifi_getRadioBeaconPeriod
int wifi_getRadioBeaconPeriod(int radioIndex, unsigned int *output)
Gets the time interval between transmitting beacons (expressed in milliseconds).
wifi_getRadioNumberOfEntries
int wifi_getRadioNumberOfEntries(unsigned long *output)
Get total number of radios in the wifi subsystem.
wifi_getRadioEnable
int wifi_getRadioEnable(int radioIndex, unsigned char *output_bool)
Get the Radio enable config parameter.
SsidSecurity
enum _SsidSecurity SsidSecurity
wifi_setRadioEnable
int wifi_setRadioEnable(int radioIndex, unsigned char enable)
Set the Radio enable config parameter.
_wifi_neighbor_ap::ap_SecurityModeEnabled
char ap_SecurityModeEnabled[64]
The type of encryption the neighboring WiFi SSID advertises. Enumeration of:None, WPA-WPA2 etc.
Definition: wifi_common_hal.h:417
_wifi_radioTrafficStats::radio_BytesReceived
unsigned long radio_BytesReceived
The total number of bytes received on the interface, including framing characters.
Definition: wifi_common_hal.h:350
wifi_context
Definition: wifi_log.h:6
_wifi_radioTrafficStats::radio_PacketsSent
unsigned long radio_PacketsSent
The total number of packets transmitted out of the interface.
Definition: wifi_common_hal.h:351
wifi_getRadioMaxBitRate
int wifi_getRadioMaxBitRate(int radioIndex, char *output_string)
Get the maximum PHY bit rate supported by the interface.
wifi_getRadioTransmitPowerSupported
int wifi_getRadioTransmitPowerSupported(int radioIndex, char *output_list)
Get supported Transmit Power list.
wifi_getRadioStandard
int wifi_getRadioStandard(int radioIndex, char *output_string, unsigned char *gOnly, unsigned char *nOnly, unsigned char *acOnly)
Get the radio operating mode and pure mode flag. Mode flags are the IEEE 802.11 standards to indicate...
_wifi_neighbor_ap
Definition: wifi_common_hal.h:409
wifi_getSSIDNumberOfEntries
int wifi_getSSIDNumberOfEntries(unsigned long *output)
Get the total number of SSID entries in the wifi subsystem.
_wifi_sta_stats::sta_SecMode
char sta_SecMode[64]
WiFi Security Mode WPA2-PSK , WPA2-EAP etc..
Definition: wifi_common_hal.h:460
wifi_getSSIDMACAddress
int wifi_getSSIDMACAddress(int ssidIndex, char *output_string)
Get the MAC address associated with the Wifi SSID.
wifi_getRadioChannelSwitchingCount
int wifi_getRadioChannelSwitchingCount(int radioIndex, int *output)
Function returns the total number of channel changes.
_wifi_radioTrafficStats::radio_NoiseFloor
int radio_NoiseFloor
The noise floor for this radio channel where a recoverable signal can be obtained....
Definition: wifi_common_hal.h:362
wifi_down
INT wifi_down()
Turns off transmit power for the entire Wifi subsystem, for all radios.
Definition: wifi_common_hal.c:555
wifi_getRegulatoryDomain
int wifi_getRegulatoryDomain(int radioIndex, char *output_string)
Gets the Access Point regulatory domain.
wifi_uninit
INT wifi_uninit()
Uninitilizes wifi module.
Definition: wifi_common_hal.c:482
wifi_getRadioChannel
int wifi_getRadioChannel(int radioIndex, unsigned long *output_ulong)
Get the running channel number.
WIFI_HAL_MINOR_VERSION
#define WIFI_HAL_MINOR_VERSION
This is the minor version of the HAL.
Definition: wifi_common_hal.h:251
wifi_setRadioMCS
int wifi_setRadioMCS(int radioIndex, int MCS)
Set the Modulation Coding Scheme index.
WIFI_HAL_MAJOR_VERSION
#define WIFI_HAL_MAJOR_VERSION
Defines for HAL version 2.0.0.
Definition: wifi_common_hal.h:250
wifi_getStats
void wifi_getStats(int radioIndex, wifi_sta_stats_t *wifi_sta_stats)
Returns current station connection status.
_wifi_radioTrafficStats::radio_DiscardPacketsSent
unsigned long radio_DiscardPacketsSent
The total number of outbound packets which were chosen to be discarded even though no errors had been...
Definition: wifi_common_hal.h:356
wifi_getRadioOperatingChannelBandwidth
int wifi_getRadioOperatingChannelBandwidth(int radioIndex, char *output_string)
Get the Operating Channel Bandwidth.
wifi_init
INT wifi_init()
Initializes the wifi subsystem.
Definition: wifi_common_hal.c:383
wifi_getRadioStatus
int wifi_getRadioStatus(int radioIndex, char *output_string)
Get the Radio enable status.
_wifi_sta_stats::sta_RSSI
float sta_RSSI
RSSI value in dBm.
Definition: wifi_common_hal.h:464
WIFI_HAL_MAINTENANCE_VERSION
#define WIFI_HAL_MAINTENANCE_VERSION
This is the maintenance version of the HAL.
Definition: wifi_common_hal.h:252
wifi_getRadioSupportedStandards
int wifi_getRadioSupportedStandards(int radioIndex, char *output_string)
Get Supported frequency bands at which the radio can operate.
wifi_getRadioPossibleChannels
int wifi_getRadioPossibleChannels(int radioIndex, char *output_string)
Gets the supported channel list.
wifi_setRadioBeaconPeriod
int wifi_setRadioBeaconPeriod(int radioIndex, unsigned int BeaconPeriod)
Sets the BeaconPeriod.
wifi_factoryReset
INT wifi_factoryReset()
Implements factory reset of the Wi-Fi subsystem.
Definition: wifi_common_hal.c:533
wifi_getSSIDTrafficStats
int wifi_getSSIDTrafficStats(int ssidIndex, wifi_ssidTrafficStats_t *output_struct)
Get the basic SSID traffic statistics info.
_wifi_securityModes
Definition: wifiHalUtiles.cpp:149
_wifi_sta_stats
Definition: wifi_common_hal.h:455
wifi_getRadioBasicDataTransmitRates
int wifi_getRadioBasicDataTransmitRates(int radioIndex, char *output)
Gets the basic data transmit rate.
_wifi_neighbor_ap::ap_SignalStrength
int ap_SignalStrength
An indicator of radio signal strength (RSSI) of the neighboring WiFi radio measured in&#160;dBm,...
Definition: wifi_common_hal.h:416
_wifi_sta_stats::sta_Noise
float sta_Noise
Indicator of average noise strength (in dBm) received from the connected WiFi radio.
Definition: wifi_common_hal.h:463
wifi_setRadioCarrierSenseThresholdInUse
int wifi_setRadioCarrierSenseThresholdInUse(int radioIndex, int threshold)
Set carrier sense threshold.
wifi_setRadioTransmitPower
int wifi_setRadioTransmitPower(int radioIndex, unsigned long TransmitPower)
Set the transmit power.
_wifi_neighbor_ap::ap_EncryptionMode
char ap_EncryptionMode[64]
Comma-separated list of strings. The type of encryption the neighboring WiFi SSID advertises....
Definition: wifi_common_hal.h:418
wifi_getNeighboringWiFiDiagnosticResult
int wifi_getNeighboringWiFiDiagnosticResult(int radioIndex, wifi_neighbor_ap_t **neighbor_ap_array, unsigned int *output_array_size)
Get neighbor wifi diagnostics.
wifi_factoryResetRadio
INT wifi_factoryResetRadio(int radioIndex)
Reset specified radio parameter.
Definition: wifi_common_hal.c:544
wifi_setRadioAutoChannelRefreshPeriod
int wifi_setRadioAutoChannelRefreshPeriod(int radioIndex, unsigned long seconds)
Set the Auto Channel Selection / Dynamic channel selection refresh period in seconds.
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
wifi_getRadioCarrierSenseThresholdInUse
int wifi_getRadioCarrierSenseThresholdInUse(int radioIndex, int *output)
Get carrier sense threshold.
wifi_getRadioAutoChannelEnable
int wifi_getRadioAutoChannelEnable(int radioIndex, unsigned char *output_bool)
Get the Auto Channel Selection / Dynamic channel selection enable status.
wifi_factoryResetRadios
INT wifi_factoryResetRadios()
Reset all radio parameters.
Definition: wifi_common_hal.c:539
wifi_applySSIDSettings
int wifi_applySSIDSettings(int ssidIndex)
This API is used to apply SSID settings to the hardware.
_wifi_ssidTrafficStats
Definition: wifi_common_hal.h:379
wifi_reset
INT wifi_reset()
Deletes all the saved access point configuration details.
Definition: wifi_common_hal.c:550