30 #include "wifi_client_hal.h"
34 #define BOOL unsigned char
44 #define MAX_FILE_PATH_LEN 4096
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"
52 void* mallocAlloc(
int typeData,
int size);
53 void test_wifi_getStats(
void);
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);
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;
70 int disconnectWaitTime;
72 void test_wifi_init(
void);
76 pthread_t connectThread;
77 int connectThreadRunning = 0;
106 int main(
int argc,
char * argv[])
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];
125 printf(
"-------------------------------------------------------------------------------------------\n");
126 printf(
"Enter your choice\n");
127 printf(
"-------------------------------------------------------------------------------------------\n");
133 printf(
"-------------------------------------------------------------------------------------------\n");
134 printf(
"Enter your choice\n");
135 printf(
"-------------------------------------------------------------------------------------------\n");
139 else if (value ==
'q')
141 printf(
"Quitting Test App press y to continue n to cancel it \n");
149 printf(
"continuing test app\n");
155 printf(
"entered charcter %c is not numeric or the option number is wrong\n",value);
162 printf(
"entered number %d not supported \n",num);
165 if ((num != 1) && (initStatus != 1))
167 printf(CLR_RED
"!!! WIFI INIT NOT DONE.PLEASE SELECT 1 BEFORE USING WIFI OPTIONS !!!" CLR_RESET
"\n");
176 printf(
"wifi intialization done \n");
179 printf(
"-------------------------------------------------------------------------------------------\n");
180 printf(
"please specify the timeout for wps\n");
181 printf(
"-------------------------------------------------------------------------------------------\n");
182 scanf(
" %d",&timeoutWps);
183 wpsPushFunc(timeoutWps);
189 printf(
"-------------------------------------------------------------------------------------------\n");
190 printf(
"please specify the SSID\n");
191 printf(
"-------------------------------------------------------------------------------------------\n");
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);
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);
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);
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);
242 printf(
"Security Mode %d Not Supported",securityMode);
248 printf(
"-------------------------------------------------------------------------------------------\n");
249 printf(
"please specify the SSID\n");
250 printf(
"-------------------------------------------------------------------------------------------\n");
252 printf(
"-------------------------------------------------------------------------------------------\n");
253 printf(
"please specify the timeout for disconnect\n");
254 printf(
"-------------------------------------------------------------------------------------------\n");
255 scanf(
" %d",&timeout);
256 ssidDisconnect(ssid,timeout);
260 printf(
"printing the current ssid info \n");
261 test_wifi_getStats();
264 printf(
"scan all ssid \n");
270 printf(
"options not supported \n ");
274 printf(
"-------------------------------------------------------------------------------------------\n");
275 printf(
" press a for list of options \n ");
276 printf(
"-------------------------------------------------------------------------------------------\n");
281 int main(
int argc,
char * argv[])
285 char keyPassphrase[72];
292 printf(
"\n Please enter ssid and password to connect. Eg testwifi testssid testpwd");
297 strcpy(ssid, argv[1]);
298 strcpy(keyPassphrase, argv[2]);
300 printf(
"wifi intialization done \n");
302 testWifiConnect(1,ssid,keyPassphrase,securityMode,NULL,NULL,NULL,NULL);
308 int main(
int argc,
char * argv[])
312 const char *short_opt =
"r:w::a:s:t:h::";
314 struct option long_opt[] =
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'}
323 printf(
"* argc = %d argv = %s \n",argc,argv[0]);
325 while((c = getopt_long(argc, argv, short_opt, long_opt, &longOptPtr)) != -1)
327 printf(
"Come here %d \n",longOptPtr);
337 printf(
"bdchbcjshb");
338 radioFunction(argv[1],atoi(argv[2]),
TRUE);
342 radioFunction(argv[3],atoi(argv[2]),FALSE);
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");
357 wpsPushFunc(atoi(argv[2]));
359 wpsPushFunc(TIME_WAIT);
373 getallSSID(atoi(argv[2]));
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");
386 getTrafficStats(atoi(argv[2]));
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");
404 fprintf(stderr,
"Try `%s --help' for more information.\n", argv[0]);
408 fprintf(stderr,
"%s: invalid option -- %c\n", argv[0], c);
409 fprintf(stderr,
"Try `%s --help' for more information.\n", argv[0]);
416 void radioFunction(
char *str,
int value,BOOL dispAllValues)
419 char output_string[64];
420 printf(
" inside radio function");
421 int len =
sizeof(radioStruct)/
sizeof(
struct RadioStruct );
422 for (; i < len; i++ )
427 printf(
"\n paramters \t----------\t value \n");
429 radioStruct[i].radioDetails(value,output_string);
430 printf(
"%s \t %s \n",radioStruct[i].inputStr,output_string);
434 if (strcmp(radioStruct[i].inputStr,str) == 0)
436 radioStruct[i].radioDetails(value,output_string);
437 printf(
"\nradio index %d output string %s\n",value,output_string);
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");
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");
475 void getallSSID(
int radioIndex)
481 printf(
"\nradio no %d \n ",radioIndex);
482 printf(
"\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
483 for(size=0; size < outputSize; size++)
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);
510 printf(
"\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
511 printf(
"malloc freed = %lu ", malloc_usable_size(neighborAPlist));
512 free(neighborAPlist);
516 void getTrafficStats(
int radioIndex)
520 if(trafficStats == NULL)
522 printf(
"Malloc Memory allocation failure\n");
525 printf(
"malloc allocated = %d ", malloc_usable_size(trafficStats));
527 printf(
"\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
549 printf(
"\n -----------------------------------------------------------------------------------------------------------------------------------------------\n");
555 void *connThreadFunc(
void* arg)
557 struct timespec waitTime;
561 ret = gettimeofday(&now, NULL);
563 waitTime.tv_sec = now.tv_sec;
564 waitTime.tv_nsec = now.tv_usec * 1000;
565 waitTime.tv_sec += wpsWaitTime;
567 pthread_mutex_lock(&connMutex);
569 while (!connectFlag && ret != ETIMEDOUT)
571 ret = pthread_cond_timedwait(&connCond, &connMutex, &waitTime);
573 if (ret == ETIMEDOUT)
576 printf(
"timed out connecting to AP \n");
579 ret = pthread_mutex_unlock(&connMutex);
583 void *disconnectThreadFunc(
void* arg)
585 struct timespec waitTime;
589 ret = gettimeofday(&now, NULL);
591 waitTime.tv_sec = now.tv_sec;
592 waitTime.tv_nsec = now.tv_usec * 1000;
593 waitTime.tv_sec += disconnectWaitTime;
595 pthread_mutex_lock(&disconMutex);
597 while (!disconnectFlag && ret != ETIMEDOUT)
599 ret = pthread_cond_timedwait(&disconCond, &disconMutex, &waitTime);
601 if (ret == ETIMEDOUT)
604 printf(
"timed out connecting to AP \n");
607 ret = pthread_mutex_unlock(&disconMutex);
612 INT test_wifi_disconnect_callback(INT ssidIndex, CHAR *AP_SSID,
wifiStatusCode_t *error)
614 pthread_mutex_lock(&disconMutex);
616 pthread_cond_broadcast(&disconCond);
617 pthread_mutex_unlock(&disconMutex);
620 printf(
"disconnected from %s \n ", AP_SSID);
623 printf(
"disonnection error %d to ssid %s \n ",*error,AP_SSID);
629 INT test_wifi_connect_callback(INT ssidIndex, CHAR *AP_SSID,
wifiStatusCode_t *error)
631 pthread_mutex_lock(&connMutex);
633 pthread_cond_broadcast(&connCond);
634 pthread_mutex_unlock(&connMutex);
637 printf(
"Connected to %s \n ", AP_SSID);
640 printf(
"Connection error %d to %s \n ",*error,AP_SSID);
645 void wpsPushFunc(
int waitTime)
649 wpsWaitTime=waitTime;
653 printf(
"\n WPS push button press success \n ");
657 printf(
"\n WPS button press failed \n ");
660 if(!connectThreadRunning)
662 connectThreadRunning = 1;
663 pthread_create(&connectThread, NULL,connThreadFunc, NULL);
664 pthread_join(connectThread,&ret);
665 connectThreadRunning = 0;
668 printf(
"connecting to AP is going on please try after sometime \n");
674 void ssidDisconnect(
char* ssid,
int waitTime)
676 pthread_t disconnectThread;
678 disconnectWaitTime=waitTime;
679 pthread_create(&disconnectThread, NULL,disconnectThreadFunc, NULL);
684 void test_wifi_init()
689 printf(
"\n WiFi intialize success \n ");
693 printf(
"\n WiFi Intialization failure \n ");
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)
701 wpsWaitTime=TIME_WAIT;
703 ret=
wifi_connectEndpoint(ssidIndex,AP_SSID,AP_security_mode,NULL,NULL,AP_security_KeyPassphrase,saveSSID,eapIdentity,carootcert,clientcert,privatekey);
705 ret=
wifi_connectEndpoint(ssidIndex,AP_SSID,AP_security_mode,NULL,AP_security_KeyPassphrase,AP_security_KeyPassphrase,saveSSID,eapIdentity,carootcert,clientcert,privatekey);
710 printf(
"Error in connecting to ssid %s with passphrase %s \n",AP_SSID,AP_security_KeyPassphrase);
714 printf(
"connecting to ssid %s with passphrase %s \n",AP_SSID,AP_security_KeyPassphrase);
716 if(!connectThreadRunning)
718 connectThreadRunning = 1;
719 pthread_create(&connectThread, NULL,connThreadFunc, NULL);
720 pthread_join(connectThread,(
void*)&ret);
721 connectThreadRunning = 0;
724 printf(
"connecting to AP is going on please try after sometime \n");
728 void test_wifi_getStats()