RDK Documentation (Open Sourced RDK Components)
testwifi.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 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <malloc.h>
24 #include <unistd.h>
25 #include <getopt.h>
26 #include <time.h>
27 #include <sys/time.h>
28 #include <pthread.h>
29 #include <errno.h>
30 #include "wifi_client_hal.h"
31 #include <ctype.h>
32 
33 #ifndef BOOL
34 #define BOOL unsigned char
35 #endif
36 #ifndef TRUE
37 #define TRUE 1
38 #endif
39 #ifndef FALSE
40 #define FALSE 0
41 #endif
42 #define SIZE 64
43 #define TIME_WAIT 40
44 #define MAX_FILE_PATH_LEN 4096
45 
46 #define CLR_RED "\x1B[31m"
47 #define CLR_GRN "\x1B[32m"
48 #define CLR_YEL "\x1B[33m"
49 #define CLR_BLU "\x1B[34m"
50 #define CLR_RESET "\x1b[0m"
51 
52 void* mallocAlloc(int typeData,int size);
53 void test_wifi_getStats(void);
54 
55 typedef INT (*radioFunc)(INT radioIndex, CHAR *output_string);
56 void radioFunction(char *str,int value,BOOL dispAllValues );
57 void getallSSID(int radioIndex);
58 void getTrafficStats(int radioIndex);
59 void usage();
60 void wpsPushFunc(int waitTime);
61 INT test_wifi_connect_callback(INT ssidIndex, CHAR *AP_SSID, wifiStatusCode_t *error);
62 INT test_wifi_disconnect_callback(INT ssidIndex, CHAR *AP_SSID, wifiStatusCode_t *error);
63 int testWifiConnect(INT ssidIndex, CHAR *AP_SSID,CHAR *AP_security_KeyPassphrase,wifiSecurityMode_t AP_security_mode,CHAR *eapIdentity,CHAR *carootcert,CHAR *clientcert,CHAR *privatekey);
64 void ssidDisconnect(char *,int );
65 pthread_mutex_t connMutex = PTHREAD_MUTEX_INITIALIZER;
66 pthread_cond_t connCond = PTHREAD_COND_INITIALIZER;
67 pthread_mutex_t disconMutex = PTHREAD_MUTEX_INITIALIZER;
68 pthread_cond_t disconCond = PTHREAD_COND_INITIALIZER;
69 int wpsWaitTime;
70 int disconnectWaitTime;
71 int wifiIntialized;
72 void test_wifi_init(void);
73 int check;
74 int connectFlag;
75 int disconnectFlag;
76 pthread_t connectThread;
77 int connectThreadRunning = 0;
78 /*
79 static struct RadioStruct
80 {
81  char* inputStr;
82  radioFunc radioDetails;
83 } radioStruct[] =
84 {
85  {"radioEnable", wifi_getRadioEnable},
86  {"radioStatus", wifi_getRadioStatus},
87  {"MaxBitRate", wifi_getRadioMaxBitRate},
88  {"IfName", wifi_getRadioIfName},
89  {"SuppFreqBands", wifi_getRadioSupportedFrequencyBands},
90  {"OpFreqBands", wifi_getRadioOperatingFrequencyBand},
91  {"SupportedStandards", wifi_getRadioSupportedStandards},
92  {"possChannels", wifi_getRadioPossibleChannels},
93  {"OpChannelBwidth", wifi_getRadioOperatingChannelBandwidth},
94  {"ExtChannel", wifi_getRadioExtChannel},
95  {"transmitPwrSupp", wifi_getRadioTransmitPowerSupported},
96  {"basicDataTransRates", wifi_getRadioBasicDataTransmitRates},
97  {"IEEE80211hSupported", wifi_getRadioIEEE80211hSupported},
98  {"IEEE80211hEnabled", wifi_getRadioIEEE80211hEnabled},
99  {"autoChannelSupported", wifi_getRadioAutoChannelSupported},
100  {"autoChannelEnable", wifi_getRadioAutoChannelEnable},
101  {"getRadioGuardInterval", wifi_getRadioGuardInterval}
102 };
103 */
104 
105 #ifndef RDKC
106 int main(int argc, char * argv[])
107 {
108  char value;
109  int timeoutWps;
110  int num;
111  char ssid[72];
112  wifiSecurityMode_t securityMode;
113  char keyPassphrase[72];
114  char eapIdentity[72];
115  char carootcert[MAX_FILE_PATH_LEN];
116  char clientcert[MAX_FILE_PATH_LEN];
117  char privatekey[MAX_FILE_PATH_LEN];
118  int timeout;
119  char initStatus=0;
120  wifi_connectEndpoint_callback_register(test_wifi_connect_callback);
121  wifi_disconnectEndpoint_callback_register(test_wifi_disconnect_callback);
122  usage();
123  while(1)
124  {
125  printf("-------------------------------------------------------------------------------------------\n");
126  printf("Enter your choice\n");
127  printf("-------------------------------------------------------------------------------------------\n");
128  scanf(" %c",&value);
129 // printf("\n value is %c \n",value);
130  if(value == 'a')
131  {
132  usage();
133  printf("-------------------------------------------------------------------------------------------\n");
134  printf("Enter your choice\n");
135  printf("-------------------------------------------------------------------------------------------\n");
136  scanf(" %c",&value);
137 
138  }
139  else if (value == 'q')
140  {
141  printf("Quitting Test App press y to continue n to cancel it \n");
142  scanf(" %c",&value);
143  if (value == 'y')
144  {
145  exit(0);
146  }
147  else
148  {
149  printf("continuing test app\n");
150  continue;
151  }
152  }
153  if(!isdigit(value))
154  {
155  printf("entered charcter %c is not numeric or the option number is wrong\n",value);
156  continue;
157 
158  }
159  num=value - '0';
160  if (num > 8)
161  {
162  printf("entered number %d not supported \n",num);
163  continue;
164  }
165  if ((num != 1) && (initStatus != 1))
166  {
167  printf(CLR_RED"!!! WIFI INIT NOT DONE.PLEASE SELECT 1 BEFORE USING WIFI OPTIONS !!!" CLR_RESET "\n");
168  continue;
169  }
170 
171  switch(num)
172  {
173  case 1:
174  test_wifi_init();
175  initStatus=1;
176  printf("wifi intialization done \n");
177  break;
178  case 2:
179  printf("-------------------------------------------------------------------------------------------\n");
180  printf("please specify the timeout for wps\n");
181  printf("-------------------------------------------------------------------------------------------\n");
182  scanf(" %d",&timeoutWps);
183  wpsPushFunc(timeoutWps);
184  break;
185  case 4:
186  //getallSSID(1);
187  break;
188  case 5:
189  printf("-------------------------------------------------------------------------------------------\n");
190  printf("please specify the SSID\n");
191  printf("-------------------------------------------------------------------------------------------\n");
192  scanf(" %s",ssid);
193  printf("-------------------------------------------------------------------------------------------\n");
194  printf("please specify the security mode %s \n",ssid);
195  printf("-------------------------------------------------------------------------------------------\n");
196  printf ("WIFI_SECURITY_WEP_64 0 \t WIFI_SECURITY_WEP_128 1 \t WIFI_SECURITY_WPA_PSK_TKIP 2 \t WIFI_SECURITY_WPA_PSK_AES 3 \t WIFI_SECURITY_WPA2_PSK_TKIP 4 \t WIFI_SECURITY_WPA2_PSK_AES 5 \t WIFI_SECURITY_WPA_ENTERPRISE_TKIP 6 \t WIFI_SECURITY_WPA_ENTERPRISE_AES 7 \t WIFI_SECURITY_WPA2_ENTERPRISE_TKIP 8 \t WIFI_SECURITY_WPA2_ENTERPRISE_AES 9 \n");
197  scanf(" %u",&securityMode);
198  if((securityMode >= WIFI_SECURITY_NONE ) && (securityMode < WIFI_SECURITY_WPA_PSK_TKIP ))
199  {
200  printf("-------------------------------------------------------------------------------------------\n");
201  printf("please specify the passphrase for ssid %s \n",ssid);
202  printf("-------------------------------------------------------------------------------------------\n");
203  scanf(" %s",keyPassphrase);
204  testWifiConnect(1,ssid,keyPassphrase,securityMode,NULL,NULL,NULL,NULL);
205  }
206  else if((securityMode >= WIFI_SECURITY_WPA_PSK_TKIP ) && (securityMode < WIFI_SECURITY_WPA_ENTERPRISE_TKIP ))
207  {
208  printf("-------------------------------------------------------------------------------------------\n");
209  printf("please specify the PSK for ssid %s \n",ssid);
210  printf("-------------------------------------------------------------------------------------------\n");
211  scanf(" %s",keyPassphrase);
212  testWifiConnect(1,ssid,keyPassphrase,securityMode,NULL,NULL,NULL,NULL);
213 
214  }
215  else if((securityMode >= WIFI_SECURITY_WPA_ENTERPRISE_TKIP ) && (securityMode < WIFI_SECURITY_NOT_SUPPORTED))
216  {
217  printf("-------------------------------------------------------------------------------------------\n");
218  printf("please specify the pass key for ssid %s \n",ssid);
219  printf("-------------------------------------------------------------------------------------------\n");
220  scanf(" %s",keyPassphrase);
221  printf("-------------------------------------------------------------------------------------------\n");
222  printf("please specify the EAP Identity for ssid %s \n",ssid);
223  printf("-------------------------------------------------------------------------------------------\n");
224  scanf(" %s",eapIdentity);
225  printf("-------------------------------------------------------------------------------------------\n");
226  printf("please specify the carootcert for ssid %s \n",ssid);
227  printf("-------------------------------------------------------------------------------------------\n");
228  scanf(" %s",carootcert);
229  printf("-------------------------------------------------------------------------------------------\n");
230  printf("please specify the clientcert for ssid %s \n",ssid);
231  printf("-------------------------------------------------------------------------------------------\n");
232  scanf(" %s",clientcert);
233  printf("-------------------------------------------------------------------------------------------\n");
234  printf("please specify the privatekey for ssid %s \n",ssid);
235  printf("-------------------------------------------------------------------------------------------\n");
236  scanf(" %s",privatekey);
237  testWifiConnect(1,ssid,keyPassphrase,securityMode,eapIdentity,carootcert,clientcert,privatekey);
238 
239  }
240  else
241  {
242  printf("Security Mode %d Not Supported",securityMode);
243  securityMode=WIFI_SECURITY_NONE;
244  }
245  break;
246  break;
247  case 6:
248  printf("-------------------------------------------------------------------------------------------\n");
249  printf("please specify the SSID\n");
250  printf("-------------------------------------------------------------------------------------------\n");
251  scanf(" %s",ssid);
252  printf("-------------------------------------------------------------------------------------------\n");
253  printf("please specify the timeout for disconnect\n");
254  printf("-------------------------------------------------------------------------------------------\n");
255  scanf(" %d",&timeout);
256  ssidDisconnect(ssid,timeout);
257  break;
258 
259  case 7:
260  printf("printing the current ssid info \n");
261  test_wifi_getStats();
262  break;
263  case 8:
264  printf("scan all ssid \n");
265  getallSSID(1);
266  break;
267  case 9:
268  exit(0);
269  default:
270  printf("options not supported \n ");
271  continue;
272 
273  }
274  printf("-------------------------------------------------------------------------------------------\n");
275  printf(" press a for list of options \n ");
276  printf("-------------------------------------------------------------------------------------------\n");
277  }
278 
279 }
280 #else
281 int main(int argc, char * argv[])
282 {
283  char ssid[72];
284  wifiSecurityMode_t securityMode;
285  char keyPassphrase[72];
286 
287  wifi_connectEndpoint_callback_register(test_wifi_connect_callback);
288  wifi_disconnectEndpoint_callback_register(test_wifi_disconnect_callback);
289 
290  if (argc < 2)
291  {
292  printf("\n Please enter ssid and password to connect. Eg testwifi testssid testpwd");
293  exit(0);
294  }
295 
296  securityMode = 4;
297  strcpy(ssid, argv[1]);
298  strcpy(keyPassphrase, argv[2]);
299  test_wifi_init();
300  printf("wifi intialization done \n");
301 
302  testWifiConnect(1,ssid,keyPassphrase,securityMode,NULL,NULL,NULL,NULL);
303  exit(0);
304 }
305 #endif
306 
307 #if 0
308 int main(int argc, char * argv[])
309 {
310  int c;
311  int longOptPtr=0;
312  const char *short_opt = "r:w::a:s:t:h::";
313  char commands[SIZE];
314  struct option long_opt[] =
315  {
316  {"radio", required_argument,0, 'r'},
317  {"wps", required_argument,0, 'w'},
318  {"ap", required_argument,0, 'a'},
319  {"ssid", required_argument,0, 's'},
320  {"traffic", required_argument,0, 't'},
321  {"help", optional_argument,0, 'h'}
322  };
323  printf("* argc = %d argv = %s \n",argc,argv[0]);
324 
325  while((c = getopt_long(argc, argv, short_opt, long_opt, &longOptPtr)) != -1)
326  {
327  printf("Come here %d \n",longOptPtr);
328  switch(c)
329  {
330  case -1: /* no more arguments */
331  case 0: /* long options toggles */
332  break;
333 
334  case 'r':
335  if(argc == 3)
336  {
337  printf("bdchbcjshb");
338  radioFunction(argv[1],atoi(argv[2]),TRUE);
339  }
340  else if(argc == 4)
341  {
342  radioFunction(argv[3],atoi(argv[2]),FALSE);
343  }
344  else
345  {
346  printf("\noptions are not right %s %d \n", optarg, argc);
347  printf("./wifi -r <radio index> get all radio parameters based on radio index \n");
348  printf("./wifi -r <radio index> <parameter> to get individual radio parameter \n");
349  printf("./wifi --radio <radio index> get all radio parameters based on radio index \n");
350  printf("./wifi --radio <radio index> <parameter> to get individual radio parameter \n");
351  }
352  // snprintf(commands,SIZE,"%s",optarg);
353  break;
354 
355  case 'w':
356  if(argc==3)
357  wpsPushFunc(atoi(argv[2]));
358  else
359  wpsPushFunc(TIME_WAIT);
360 // printf("you entered \"%s\"\n", optarg);
361  /* printf("short option - %c long option - %s\n",c, long_opt[longOptPtr].name);
362  snprintf(commands,SIZE,"%s",optarg);*/
363  break;
364 
365  case 'a':
366  /* printf("short option - %c long option - %s\n",c, long_opt[longOptPtr].name);
367  snprintf(commands,SIZE,"%s",optarg);*/
368  break;
369 
370  case 's':
371  if(argc == 3)
372  {
373  getallSSID(atoi(argv[2]));
374  }
375  else
376  {
377  printf("\noptions are not right %s %d \n", optarg, argc);
378  printf("./wifi -s <radio index> get all ssid information based on radio index\n");
379  printf("./wifi --ssid <radio index> get all ssid information based on radio index\n");
380  }
381  break;
382 
383  case 't':
384  if(argc == 3)
385  {
386  getTrafficStats(atoi(argv[2]));
387  }
388  else
389  {
390  printf("\noptions are not right %s %d \n", optarg, argc);
391  printf("./wifi -t <radio index> get traffic data between radio and connected SSID\n");
392  printf("./wifi --traffic <radio index> get traffic data between radio and connected SSID\n");
393  }
394  break;
395 
396 
397  case 'h':
398  usage();
399  printf("\n");
400  return(0);
401 
402  case ':':
403  case '?':
404  fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
405  return(-2);
406 
407  default:
408  fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);
409  fprintf(stderr, "Try `%s --help' for more information.\n", argv[0]);
410  return(-2);
411  };
412  };
413 
414  return(0);
415 }
416 void radioFunction(char *str,int value,BOOL dispAllValues)
417 {
418  int i = 0;
419  char output_string[64];
420  printf(" inside radio function");
421  int len = sizeof(radioStruct)/sizeof( struct RadioStruct );
422  for (; i < len; i++ )
423  {
424  if(dispAllValues)
425  {
426  if(i == 0)
427  printf("\n paramters \t----------\t value \n");
428 
429  radioStruct[i].radioDetails(value,output_string);
430  printf("%s \t %s \n",radioStruct[i].inputStr,output_string);
431  }
432  else
433  {
434  if (strcmp(radioStruct[i].inputStr,str) == 0)
435  {
436  radioStruct[i].radioDetails(value,output_string);
437  printf("\nradio index %d output string %s\n",value,output_string);
438  }
439  }
440  }
441 }
442 
443 #endif
444 
445 void usage()
446 {
447 
448  printf("\n------------------------------------ Usage ----------------------------------------------\n");
449  printf(" 1 ----- wifi init \n");
450  printf(" 2 ----- press wps button \n");
451  printf(" 3 ----- get STA radio details \n");
452  printf(" 4 ----- SSID details \n");
453  printf(" 5 ----- connect to ssid \n");
454  printf(" 6 ----- disconnect from ssid \n");
455  printf(" 7 ----- ssid stat \n");
456  printf(" 8 ----- scan ssid \n");
457  printf(" q ----- Quit \n");
458  printf("-------------------------------------------------------------------------------------------\n");
459 }
460 #if 0
461 void usage()
462 {
463  printf("\n------------------------------------ Usage ----------------------------------------------\n");
464  printf("./wifi -r <radio index> get all radio parameters based on radio index \n");
465  printf("./wifi --radio <radio index> get all radio parameters based on radio index \n");
466  printf("./wifi -r <radio index> <parameter> to get individual radio parameter\n");
467  printf("./wifi --radio <radio index> <parameter> to get individual radio parameter\n");
468  printf("./wifi -s <radio index> get all ssid information based on radio index\n");
469  printf("./wifi --ssid <radio index> get all ssid information based on radio index\n");
470  printf("./wifi -t <radio index> get traffic data between radio and connected SSID\n");
471  printf("./wifi --traffic <radio index> get traffic data between radio and connected SSID\n");
472  printf("\n-------------------------------------------- ----------------------------------------------\n");
473 }
474 #endif
475 void getallSSID(int radioIndex)
476 {
477  wifi_neighbor_ap_t *neighborAPlist;
478  UINT outputSize;
479  UINT size;
480  wifi_getNeighboringWiFiDiagnosticResult(1,&neighborAPlist,&outputSize);
481  printf("\nradio no %d \n ",radioIndex);
482  printf("\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
483  for(size=0; size < outputSize; size++)
484  {
485 
486  printf("\nap_SSID is %s \t",neighborAPlist[size].ap_SSID);
487  printf("ap_BSSID is %s \t",neighborAPlist[size].ap_BSSID);
488  printf("ap_EncryptionMode is %s \t ",neighborAPlist[size].ap_EncryptionMode);
489  printf("\nap_OperatingFrequencyBand is %s \t ",neighborAPlist[size].ap_OperatingFrequencyBand);
490  if( neighborAPlist[size].ap_SignalStrength > -50)
491  printf(CLR_BLU"ap_SignalStrength is %+d EXCELLENT" CLR_RESET "\n",neighborAPlist[size].ap_SignalStrength);
492  else if(( neighborAPlist[size].ap_SignalStrength < -50) && ( neighborAPlist[size].ap_SignalStrength > -60) )
493  printf(CLR_GRN"ap_SignalStrength is %+d GOOD" CLR_RESET "\n",neighborAPlist[size].ap_SignalStrength);
494  else if(( neighborAPlist[size].ap_SignalStrength < -60) && ( neighborAPlist[size].ap_SignalStrength > -70) )
495  printf(CLR_YEL"ap_SignalStrength is %+d FAIR" CLR_RESET "\n",neighborAPlist[size].ap_SignalStrength);
496  if( neighborAPlist[size].ap_SignalStrength < -70)
497  printf(CLR_RED"ap_SignalStrength is %+d POOR" CLR_RESET "\n",neighborAPlist[size].ap_SignalStrength);
498  /* printf(" ap_Mode is %s \t",neighborAPlist[size].ap_Mode);
499  printf(" ap_Channel is %d \t ",neighborAPlist[size].ap_Channel);
500  printf("\nap_SecurityModeEnabled is %s \t ",neighborAPlist[size].ap_SecurityModeEnabled);
501  printf("\nap_SupportedStandards is %s \t ",neighborAPlist[size].ap_SupportedStandards);
502  printf(" ap_OperatingStandards is %s \t ",neighborAPlist[size].ap_OperatingStandards);
503  printf("\nap_OperatingChannelBandwidth is %s \t ",neighborAPlist[size].ap_OperatingChannelBandwidth);
504  printf(" ap_BeaconPeriod is %d \t ",neighborAPlist[size].ap_BeaconPeriod);
505  printf(" ap_Noise is %+d \t ",neighborAPlist[size].ap_Noise);
506  printf(" ap_BasicDataTransferRates is %s \t ",neighborAPlist[size].ap_BasicDataTransferRates);
507  printf("\nap_SupportedDataTransferRates is %s \t ",neighborAPlist[size].ap_SupportedDataTransferRates);
508  printf(" ap_DTIMPeriod is %d \t ",neighborAPlist[size].ap_DTIMPeriod);*/
509  }
510  printf("\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
511  printf("malloc freed = %lu ", malloc_usable_size(neighborAPlist));
512  free(neighborAPlist);
513 
514 }
515 #if 0
516 void getTrafficStats(int radioIndex)
517 {
518  wifi_radioTrafficStats_t *trafficStats;
519  trafficStats = (wifi_radioTrafficStats_t *)malloc(sizeof(wifi_radioTrafficStats_t));
520  if(trafficStats == NULL)
521  {
522  printf("Malloc Memory allocation failure\n");
523  return;
524  }
525  printf("malloc allocated = %d ", malloc_usable_size(trafficStats));
526  wifi_getRadioTrafficStats(radioIndex, trafficStats);
527  printf("\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
528  printf(" BytesSent = %lu ",trafficStats->radio_BytesSent);
529  printf(" BytesReceived = %lu ",trafficStats->radio_BytesReceived);
530  printf(" PacketsSent = %lu ",trafficStats->radio_PacketsSent);
531  printf(" PacketsReceived = %lu ",trafficStats->radio_PacketsReceived);
532  printf(" ErrorsSent = %lu ",trafficStats->radio_ErrorsSent);
533  printf(" ErrorsReceived = %lu ",trafficStats->radio_ErrorsReceived);
534  printf(" DiscardPacketsSent = %lu ",trafficStats->radio_DiscardPacketsSent);
535  printf(" \nDiscardPacketsReceived = %lu ",trafficStats->radio_DiscardPacketsReceived);
536  printf(" PLCPErrorCount = %lu ",trafficStats->radio_PLCPErrorCount);
537  printf(" FCSErrorCount = %lu ",trafficStats->radio_FCSErrorCount);
538  printf(" InvalidMACCount = %lu ",trafficStats->radio_InvalidMACCount);
539  printf(" PacketsOtherReceived = %lu ",trafficStats->radio_PacketsOtherReceived);
540  printf(" NoiseFloor = %d ",trafficStats->radio_NoiseFloor);
541  printf("\n ChannelUtilization = %lu ",trafficStats->radio_ChannelUtilization);
542  printf(" ActivityFactor = %d ",trafficStats->radio_ActivityFactor);
543  printf(" CarrierSenseThreshold_Exceeded = %d ", trafficStats->radio_CarrierSenseThreshold_Exceeded);
544  printf(" RetransmissionMetirc = %d ",trafficStats->radio_RetransmissionMetirc);
545  printf(" MaximumNoiseFloorOnChannel = %d ",trafficStats->radio_MaximumNoiseFloorOnChannel);
546  printf("\n MinimumNoiseFloorOnChannel = %d ",trafficStats->radio_MinimumNoiseFloorOnChannel);
547  printf(" MedianNoiseFloorOnChannel = %d ",trafficStats->radio_MedianNoiseFloorOnChannel);
548  printf(" StatisticsStartTime = %lu ",trafficStats->radio_StatisticsStartTime);
549  printf("\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
550  free(trafficStats);
551 }
552 
553 #endif
554 
555 void *connThreadFunc(void* arg)
556 {
557  struct timespec waitTime;
558  struct timeval now;
559  int ret;
560 
561  ret = gettimeofday(&now, NULL);
562 
563  waitTime.tv_sec = now.tv_sec;
564  waitTime.tv_nsec = now.tv_usec * 1000;
565  waitTime.tv_sec += wpsWaitTime;
566 
567  pthread_mutex_lock(&connMutex);
568  ret=0;
569  while (!connectFlag && ret != ETIMEDOUT)
570  {
571  ret = pthread_cond_timedwait(&connCond, &connMutex, &waitTime);
572  }
573  if (ret == ETIMEDOUT)
574  {
575  check=1;
576  printf("timed out connecting to AP \n");
577  }
578  connectFlag=0;
579  ret = pthread_mutex_unlock(&connMutex);
580  pthread_exit(NULL);
581 }
582 
583 void *disconnectThreadFunc(void* arg)
584 {
585  struct timespec waitTime;
586  struct timeval now;
587  int ret;
588 
589  ret = gettimeofday(&now, NULL);
590 
591  waitTime.tv_sec = now.tv_sec;
592  waitTime.tv_nsec = now.tv_usec * 1000;
593  waitTime.tv_sec += disconnectWaitTime;
594 
595  pthread_mutex_lock(&disconMutex);
596  ret=0;
597  while (!disconnectFlag && ret != ETIMEDOUT)
598  {
599  ret = pthread_cond_timedwait(&disconCond, &disconMutex, &waitTime);
600  }
601  if (ret == ETIMEDOUT)
602  {
603  check=1;
604  printf("timed out connecting to AP \n");
605  }
606  disconnectFlag=0;
607  ret = pthread_mutex_unlock(&disconMutex);
608 
609  pthread_exit(NULL);
610 }
611 
612 INT test_wifi_disconnect_callback(INT ssidIndex, CHAR *AP_SSID, wifiStatusCode_t *error)
613 {
614  pthread_mutex_lock(&disconMutex);
615  disconnectFlag=1;
616  pthread_cond_broadcast(&disconCond);
617  pthread_mutex_unlock(&disconMutex);
618  if(*error == WIFI_HAL_SUCCESS)
619  {
620  printf("disconnected from %s \n ", AP_SSID);
621  return RETURN_OK;
622  }
623  printf("disonnection error %d to ssid %s \n ",*error,AP_SSID);
624  return RETURN_ERR;
625 // pthread_exit(NULL);
626 }
627 
628 
629 INT test_wifi_connect_callback(INT ssidIndex, CHAR *AP_SSID, wifiStatusCode_t *error)
630 {
631  pthread_mutex_lock(&connMutex);
632  connectFlag=1;
633  pthread_cond_broadcast(&connCond);
634  pthread_mutex_unlock(&connMutex);
635  if(*error == WIFI_HAL_SUCCESS)
636  {
637  printf("Connected to %s \n ", AP_SSID);
638  return RETURN_OK;
639  }
640  printf("Connection error %d to %s \n ",*error,AP_SSID);
641  return RETURN_ERR;
642 // pthread_exit(NULL);
643 }
644 
645 void wpsPushFunc(int waitTime)
646 {
647  void *ret;
648 
649  wpsWaitTime=waitTime;
650 // pthread_join(wpsThread,&ret);
652  {
653  printf("\n WPS push button press success \n ");
654  }
655  else
656  {
657  printf("\n WPS button press failed \n ");
658  return;
659  }
660  if(!connectThreadRunning)
661  {
662  connectThreadRunning = 1;
663  pthread_create(&connectThread, NULL,connThreadFunc, NULL);
664  pthread_join(connectThread,&ret);
665  connectThreadRunning = 0;
666  }
667  else
668  printf("connecting to AP is going on please try after sometime \n");
669 // pthread_join(wpsThread,&ret);
670 // pthread_cond_destroy(&connCond);
671 // pthread_mutex_destroy(&connMutex);
672 
673 }
674 void ssidDisconnect(char* ssid,int waitTime)
675 {
676  pthread_t disconnectThread;
677 
678  disconnectWaitTime=waitTime;
679  pthread_create(&disconnectThread, NULL,disconnectThreadFunc, NULL);
680  // pthread_join(wpsThread,&ret);
681  wifi_disconnectEndpoint(1, ssid);
682 }
683 
684 void test_wifi_init()
685 {
686  if(wifi_init() == RETURN_OK)
687  {
688  wifiIntialized=1;
689  printf("\n WiFi intialize success \n ");
690  }
691  else
692  {
693  printf("\n WiFi Intialization failure \n ");
694  }
695 }
696 
697 int testWifiConnect(INT ssidIndex, CHAR *AP_SSID,CHAR *AP_security_KeyPassphrase,wifiSecurityMode_t AP_security_mode,CHAR *eapIdentity,CHAR *carootcert,CHAR *clientcert,CHAR *privatekey)
698 {
699  int ret;
700  int saveSSID=1;
701  wpsWaitTime=TIME_WAIT;
702 #ifndef RDKC
703  ret=wifi_connectEndpoint(ssidIndex,AP_SSID,AP_security_mode,NULL,NULL,AP_security_KeyPassphrase,saveSSID,eapIdentity,carootcert,clientcert,privatekey);
704 #else
705  ret=wifi_connectEndpoint(ssidIndex,AP_SSID,AP_security_mode,NULL,AP_security_KeyPassphrase,AP_security_KeyPassphrase,saveSSID,eapIdentity,carootcert,clientcert,privatekey);
706 #endif
707 
708  if(ret)
709  {
710  printf("Error in connecting to ssid %s with passphrase %s \n",AP_SSID,AP_security_KeyPassphrase);
711  }
712  else
713  {
714  printf("connecting to ssid %s with passphrase %s \n",AP_SSID,AP_security_KeyPassphrase);
715  }
716  if(!connectThreadRunning)
717  {
718  connectThreadRunning = 1;
719  pthread_create(&connectThread, NULL,connThreadFunc, NULL);
720  pthread_join(connectThread,(void*)&ret);
721  connectThreadRunning = 0;
722  }
723  else
724  printf("connecting to AP is going on please try after sometime \n");
725  return ret;
726 }
727 
728 void test_wifi_getStats()
729 {
730  wifi_getStats(1, NULL);
731 }
WIFI_SECURITY_WPA_ENTERPRISE_TKIP
@ WIFI_SECURITY_WPA_ENTERPRISE_TKIP
WPA Enterprise with TKIP (Temporal Key Integrity Protocol) encryption.
Definition: wifi_common_hal.h:329
_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_SECURITY_NOT_SUPPORTED
@ WIFI_SECURITY_NOT_SUPPORTED
Security mode not supported.
Definition: wifi_common_hal.h:338
_wifi_radioTrafficStats::radio_PacketsOtherReceived
unsigned long radio_PacketsOtherReceived
The number of packets that were received, but which were destined for a MAC address that is not assoc...
Definition: wifi_common_hal.h:361
_wifi_radioTrafficStats::radio_InvalidMACCount
unsigned long radio_InvalidMACCount
The number of packets that were received with a detected invalid MAC header error.
Definition: wifi_common_hal.h:360
RETURN_OK
#define RETURN_OK
Defines for function returns.
Definition: wifi_common_hal.h:218
_wifi_radioTrafficStats::radio_StatisticsStartTime
unsigned long radio_StatisticsStartTime
The date and time at which the collection of the current set of statistics started....
Definition: wifi_common_hal.h:370
_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_radioTrafficStats::radio_CarrierSenseThreshold_Exceeded
int radio_CarrierSenseThreshold_Exceeded
Percentage of time that the radio was unable to transmit or receive Wi-Fi packets to/from associated ...
Definition: wifi_common_hal.h:365
_wifi_radioTrafficStats
Definition: wifi_common_hal.h:345
wifiSecurityMode_t
wifiSecurityMode_t
Wifi Security modes.
Definition: wifi_common_hal.h:320
_wifi_radioTrafficStats::radio_PacketsReceived
unsigned long radio_PacketsReceived
The total number of packets received on the interface.
Definition: wifi_common_hal.h:352
_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_radioTrafficStats::radio_RetransmissionMetirc
int radio_RetransmissionMetirc
Percentage of packets that had to be re-transmitted. Multiple re-transmissions of the same packet cou...
Definition: wifi_common_hal.h:366
_wifi_radioTrafficStats::radio_PLCPErrorCount
unsigned long radio_PLCPErrorCount
The number of packets that were received with a detected Physical Layer Convergence Protocol (PLCP) h...
Definition: wifi_common_hal.h:358
_wifi_radioTrafficStats::radio_BytesSent
unsigned long radio_BytesSent
The total number of bytes transmitted out of the interface, including framing characters.
Definition: wifi_common_hal.h:349
wifi_connectEndpoint
INT wifi_connectEndpoint(INT ssidIndex, CHAR *AP_SSID, wifiSecurityMode_t AP_security_mode, CHAR *AP_security_WEPKey, CHAR *AP_security_PreSharedKey, CHAR *AP_security_KeyPassphrase, int saveSSID, CHAR *eapIdentity, CHAR *carootcert, CHAR *clientcert, CHAR *privatekey)
This API starts the connection process from client with an AP.
Definition: wifi_client_hal.c:1348
_wifi_radioTrafficStats::radio_ActivityFactor
int radio_ActivityFactor
Percentage of time that the radio was transmitting or receiving Wi-Fi packets to/from associated clie...
Definition: wifi_common_hal.h:364
WIFI_HAL_SUCCESS
@ WIFI_HAL_SUCCESS
Definition: wifi_common_hal.h:291
wifi_getRadioTrafficStats
int wifi_getRadioTrafficStats(int radioIndex, wifi_radioTrafficStats_t *output_struct)
Get detail radio traffic statistics information.
WIFI_SECURITY_WPA_PSK_TKIP
@ WIFI_SECURITY_WPA_PSK_TKIP
WPA(Pre-Shared Key) with TKIP (Temporal Key Integrity Protocol) encryption.
Definition: wifi_common_hal.h:325
wifi_setCliWpsButtonPush
INT wifi_setCliWpsButtonPush(INT ssidIndex)
Start the Push button pairing.
Definition: wifi_client_hal.c:1295
_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_disconnectEndpoint
INT wifi_disconnectEndpoint(INT ssidIndex, CHAR *AP_SSID)
This API disconnects the access point specified.
Definition: wifi_client_hal.c:1666
WIFI_SECURITY_NONE
@ WIFI_SECURITY_NONE
No Security.
Definition: wifi_common_hal.h:322
_wifi_radioTrafficStats::radio_PacketsSent
unsigned long radio_PacketsSent
The total number of packets transmitted out of the interface.
Definition: wifi_common_hal.h:351
_wifi_radioTrafficStats::radio_FCSErrorCount
unsigned long radio_FCSErrorCount
The number of packets that were received with a detected FCS error. This parameter is based on dot11F...
Definition: wifi_common_hal.h:359
_wifi_neighbor_ap
Definition: wifi_common_hal.h:409
_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_radioTrafficStats::radio_MaximumNoiseFloorOnChannel
int radio_MaximumNoiseFloorOnChannel
Maximum Noise on the channel during the measuring interval. The metric is updated in this parameter a...
Definition: wifi_common_hal.h:367
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_init
int wifi_init()
Initializes the wifi subsystem.
Definition: wifi_common_hal.c:383
wifi_connectEndpoint_callback_register
void wifi_connectEndpoint_callback_register(wifi_connectEndpoint_callback callback_proc)
Callback registration function.
Definition: wifi_client_hal.c:238
_wifi_radioTrafficStats::radio_MinimumNoiseFloorOnChannel
int radio_MinimumNoiseFloorOnChannel
Minimum Noise on the channel. The metric is updated in this Parameter at the end of the interval defi...
Definition: wifi_common_hal.h:368
wifi_disconnectEndpoint_callback_register
void wifi_disconnectEndpoint_callback_register(wifi_disconnectEndpoint_callback callback_proc)
Callback registration function.
Definition: wifi_client_hal.c:244
_wifi_radioTrafficStats::radio_ChannelUtilization
unsigned long radio_ChannelUtilization
Percentage of time the channel was occupied by the radio’s own activity (Activity Factor) or the acti...
Definition: wifi_common_hal.h:363
wifi_getNeighboringWiFiDiagnosticResult
int wifi_getNeighboringWiFiDiagnosticResult(int radioIndex, wifi_neighbor_ap_t **neighbor_ap_array, unsigned int *output_array_size)
Get neighbor wifi diagnostics.
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199
wifiStatusCode_t
wifiStatusCode_t
Enumerators for Wi-Fi connection status.
Definition: wifi_common_hal.h:290
_wifi_radioTrafficStats::radio_MedianNoiseFloorOnChannel
int radio_MedianNoiseFloorOnChannel
Median Noise on the channel during the measuring interval. The metric is updated in this parameter at...
Definition: wifi_common_hal.h:369