6b3a2be96cbafb6019ffa7aa49b53541ef47f61b
[platform/core/api/wifi.git] / test / wifi_test.c
1 /*
2  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <glib.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <netdb.h>
21 #include <sys/socket.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/un.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <sys/ioctl.h>
28 #include <signal.h>
29 #include <assert.h>
30 #include <wifi.h>
31 #include <tizen_error.h>
32
33 #define LOG_RED "\033[0;31m"
34 #define LOG_GREEN "\033[0;32m"
35 #define LOG_BROWN "\033[0;33m"
36 #define LOG_BLUE "\033[0;34m"
37 #define LOG_END "\033[0;m"
38
39 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
40
41 static const char *__test_convert_error_to_string(wifi_error_e err_type)
42 {
43         switch (err_type) {
44         case WIFI_ERROR_NONE:
45                 return "NONE";
46         case WIFI_ERROR_INVALID_PARAMETER:
47                 return "INVALID_PARAMETER";
48         case WIFI_ERROR_OUT_OF_MEMORY:
49                 return "OUT_OF_MEMORY";
50         case WIFI_ERROR_INVALID_OPERATION:
51                 return "INVALID_OPERATION";
52         case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
53                 return "ADDRESS_FAMILY_NOT_SUPPORTED";
54         case WIFI_ERROR_OPERATION_FAILED:
55                 return "OPERATION_FAILED";
56         case WIFI_ERROR_NO_CONNECTION:
57                 return "NO_CONNECTION";
58         case WIFI_ERROR_NOW_IN_PROGRESS:
59                 return "NOW_IN_PROGRESS";
60         case WIFI_ERROR_ALREADY_EXISTS:
61                 return "ALREADY_EXISTS";
62         case WIFI_ERROR_OPERATION_ABORTED:
63                 return "OPERATION_ABORTED";
64         case WIFI_ERROR_DHCP_FAILED:
65                 return "DHCP_FAILED";
66         case WIFI_ERROR_INVALID_KEY:
67                 return "INVALID_KEY";
68         case WIFI_ERROR_NO_REPLY:
69                 return "NO_REPLY";
70         case WIFI_ERROR_SECURITY_RESTRICTED:
71                 return "SECURITY_RESTRICTED";
72         case WIFI_ERROR_PERMISSION_DENIED:
73                 return "PERMISSION_DENIED";
74         case WIFI_ERROR_NOT_SUPPORTED:
75                 return "NOT_SUPPORTED";
76         }
77
78         return "UNKNOWN";
79 }
80
81 static void __test_device_state_callback(wifi_device_state_e state, void* user_data)
82 {
83         printf("Device state changed callback");
84
85         if (state == WIFI_DEVICE_STATE_ACTIVATED)
86                 printf(", state : Activated\n");
87         else
88                 printf(", state : Deactivated\n");
89 }
90
91 static void __test_bg_scan_completed_callback(wifi_error_e error_code, void* user_data)
92 {
93         printf("Background Scan Completed, error code : %s\n",
94                         __test_convert_error_to_string(error_code));
95 }
96
97 static void __test_scan_request_callback(wifi_error_e error_code, void* user_data)
98 {
99         if (user_data != NULL)
100                 printf("user_data : %s\n", (char *)user_data);
101
102         printf("Scan Completed from scan request, error code : %s\n",
103                         __test_convert_error_to_string(error_code));
104 }
105
106 static void __test_connection_state_callback(wifi_connection_state_e state, wifi_ap_h ap, void* user_data)
107 {
108         int rv = 0;
109         char *ap_name = NULL;
110
111         printf("Connection state changed callback");
112
113         switch (state) {
114         case WIFI_CONNECTION_STATE_CONNECTED:
115                 printf(", state : Connected");
116                 break;
117         case WIFI_CONNECTION_STATE_ASSOCIATION:
118                 printf(", state : Association");
119                 break;
120         case WIFI_CONNECTION_STATE_CONFIGURATION:
121                 printf(", state : Configuration");
122                 break;
123         case WIFI_CONNECTION_STATE_DISCONNECTED:
124                 printf(", state : Disconnected");
125                 break;
126         default:
127                 printf(", state : Unknown");
128         }
129
130         rv = wifi_ap_get_essid(ap, &ap_name);
131         if (rv != WIFI_ERROR_NONE)
132                 printf(", Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
133         else {
134                 printf(", AP name : %s\n", ap_name);
135                 g_free(ap_name);
136         }
137 }
138
139 static void __test_activated_callback(wifi_error_e result, void* user_data)
140 {
141         if (result == WIFI_ERROR_NONE)
142                 printf("Wi-Fi Activation Succeeded\n");
143         else
144                 printf("Wi-Fi Activation Failed! error : %s\n", __test_convert_error_to_string(result));
145 }
146
147 static void __test_deactivated_callback(wifi_error_e result, void* user_data)
148 {
149         if (result == WIFI_ERROR_NONE)
150                 printf("Wi-Fi Deactivation Succeeded\n");
151         else
152                 printf("Wi-Fi Deactivation Failed! error : %s\n", __test_convert_error_to_string(result));
153 }
154
155 static void __test_connected_callback(wifi_error_e result, void* user_data)
156 {
157         if (result == WIFI_ERROR_NONE)
158                 printf("Wi-Fi Connection Succeeded\n");
159         else
160                 printf("Wi-Fi Connection Failed! error : %s\n", __test_convert_error_to_string(result));
161 }
162
163 static void __test_disconnected_callback(wifi_error_e result, void* user_data)
164 {
165         if (result == WIFI_ERROR_NONE)
166                 printf("Wi-Fi Disconnection Succeeded\n");
167         else
168                 printf("Wi-Fi Disconnection Failed! error : %s\n", __test_convert_error_to_string(result));
169 }
170
171 static void __test_rssi_level_callback(wifi_rssi_level_e rssi_level, void* user_data)
172 {
173         printf("RSSI level changed callback, level = %d\n", rssi_level);
174 }
175
176 static const char* __test_print_state(wifi_connection_state_e state)
177 {
178         switch (state) {
179         case WIFI_CONNECTION_STATE_FAILURE:
180                 return "Failure";
181         case WIFI_CONNECTION_STATE_DISCONNECTED:
182                 return "Disconnected";
183         case WIFI_CONNECTION_STATE_ASSOCIATION:
184                 return "Association";
185         case WIFI_CONNECTION_STATE_CONNECTED:
186                 return "Connected";
187         case WIFI_CONNECTION_STATE_CONFIGURATION:
188                 return "Configuration";
189         }
190
191         return "Unknown";
192 }
193
194 static bool __test_found_ap_callback(wifi_ap_h ap, void *user_data)
195 {
196         int rv = 0;
197         char *ap_name = NULL;
198         wifi_connection_state_e state;
199
200         rv = wifi_ap_get_essid(ap, &ap_name);
201         if (rv != WIFI_ERROR_NONE) {
202                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
203                 return false;
204         }
205
206         rv = wifi_ap_get_connection_state(ap, &state);
207         if (rv != WIFI_ERROR_NONE) {
208                 printf("Fail to get State [%s]\n", __test_convert_error_to_string(rv));
209                 g_free(ap_name);
210                 return false;
211         }
212
213         printf("AP name : %s, state : %s\n", ap_name, __test_print_state(state));
214         g_free(ap_name);
215
216         return true;
217 }
218
219 static bool __test_found_connect_ap_callback(wifi_ap_h ap, void *user_data)
220 {
221         int rv = 0;
222         char *ap_name = NULL;
223         char *ap_name_part = (char*)user_data;
224
225         rv = wifi_ap_get_essid(ap, &ap_name);
226         if (rv != WIFI_ERROR_NONE) {
227                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
228                 return false;
229         }
230
231         if (strstr(ap_name, ap_name_part) != NULL) {
232                 bool required = false;
233
234                 if (wifi_ap_is_passphrase_required(ap, &required) == WIFI_ERROR_NONE)
235                         printf("Passphrase required : %s\n", required ? "TRUE" : "FALSE");
236                 else
237                         printf("Fail to get Passphrase required\n");
238
239                 if (required) {
240                         char passphrase[100];
241                         printf("Input passphrase for %s : ", ap_name);
242                         rv = scanf("%99s", passphrase);
243
244                         rv = wifi_ap_set_passphrase(ap, passphrase);
245                         if (rv != WIFI_ERROR_NONE) {
246                                 printf("Fail to set passphrase : %s\n", __test_convert_error_to_string(rv));
247                                 g_free(ap_name);
248                                 return false;
249                         }
250                 }
251
252                 rv = wifi_connect(ap, __test_connected_callback, NULL);
253                 if (rv != WIFI_ERROR_NONE)
254                         printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
255                 else
256                         printf("Success to connection request [%s]\n", ap_name);
257
258                 g_free(ap_name);
259                 return false;
260         }
261
262         g_free(ap_name);
263         return true;
264 }
265
266 static bool __test_found_connect_wps_callback(wifi_ap_h ap, void *user_data)
267 {
268         int rv = 0;
269         char *ap_name = NULL;
270         char *ap_name_part = (char*)user_data;
271
272         rv = wifi_ap_get_essid(ap, &ap_name);
273         if (rv != WIFI_ERROR_NONE) {
274                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
275                 return false;
276         }
277
278         if (strstr(ap_name, ap_name_part) != NULL) {
279                 int user_sel;
280                 char pin[32] = {0,};
281
282                 printf("%s - Input WPS method (1:PBC, 2:PIN) :\n", ap_name);
283                 rv = scanf("%9d", &user_sel);
284
285                 switch (user_sel) {
286                 case 1:
287                         rv = wifi_connect_by_wps_pbc(ap, __test_connected_callback, NULL);
288                         break;
289                 case 2:
290                         printf("Input PIN code :\n");
291                         rv = scanf("%31s", pin);
292                         rv = wifi_connect_by_wps_pin(ap, pin, __test_connected_callback, NULL);
293                         break;
294                 default:
295                         printf("Invalid input!\n");
296                         g_free(ap_name);
297                         return false;
298                 }
299
300                 if (rv != WIFI_ERROR_NONE)
301                         printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
302                 else
303                         printf("Success to connection request [%s]\n", ap_name);
304
305                 g_free(ap_name);
306                 return false;
307         }
308
309         g_free(ap_name);
310         return true;
311 }
312
313 static bool __test_found_disconnect_ap_callback(wifi_ap_h ap, void *user_data)
314 {
315         int rv = 0;
316         char *ap_name = NULL;
317         char *ap_name_part = (char*)user_data;
318
319         rv = wifi_ap_get_essid(ap, &ap_name);
320         if (rv != WIFI_ERROR_NONE) {
321                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
322                 return false;
323         }
324
325         if (strstr(ap_name, ap_name_part) != NULL) {
326                 rv = wifi_disconnect(ap, __test_disconnected_callback, NULL);
327                 if (rv != WIFI_ERROR_NONE)
328                         printf("Fail to disconnection reqeust %s : [%s]\n", ap_name, __test_convert_error_to_string(rv));
329                 else
330                         printf("Success to disconnection request %s\n", ap_name);
331
332                 g_free(ap_name);
333                 return false;
334         }
335
336         g_free(ap_name);
337         return true;
338 }
339
340 static bool __test_found_forget_ap_callback(wifi_ap_h ap, void *user_data)
341 {
342         int rv = 0;
343         char *ap_name = NULL;
344         char *ap_name_part = (char*)user_data;
345
346         rv = wifi_ap_get_essid(ap, &ap_name);
347         if (rv != WIFI_ERROR_NONE) {
348                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
349                 return false;
350         }
351
352         if (strstr(ap_name, ap_name_part) != NULL) {
353                 rv = wifi_forget_ap(ap);
354                 if (rv != WIFI_ERROR_NONE)
355                         printf("Fail to forget [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
356                 else
357                         printf("Success to forget [%s]\n", ap_name);
358
359                 g_free(ap_name);
360                 return false;
361         }
362
363         g_free(ap_name);
364         return true;
365 }
366
367 static bool __test_found_eap_ap_callback(wifi_ap_h ap, void *user_data)
368 {
369         int rv = 0;
370         char *ap_name = NULL;
371         char *ap_name_part = (char*)user_data;
372
373         rv = wifi_ap_get_essid(ap, &ap_name);
374         if (rv != WIFI_ERROR_NONE) {
375                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
376                 return false;
377         }
378
379         if (strstr(ap_name, ap_name_part) != NULL) {
380                 wifi_security_type_e type;
381
382                 if (wifi_ap_get_security_type(ap, &type) == WIFI_ERROR_NONE)
383                         printf("Security type : %d\n", type);
384                 else
385                         printf("Fail to get Security type\n");
386
387                 if (type != WIFI_SECURITY_TYPE_EAP) {
388                         g_free(ap_name);
389                         return false;
390                 }
391
392                 char input_str1[100];
393                 printf("Input user name for %s : ", ap_name);
394                 rv = scanf("%99s", input_str1);
395
396                 char input_str2[100];
397                 printf("Input password for %s : ", ap_name);
398                 rv = scanf("%99s", input_str2);
399
400                 rv = wifi_ap_set_eap_passphrase(ap, input_str1, input_str2);
401                 if (rv != WIFI_ERROR_NONE) {
402                         printf("Fail to set eap passphrase : %s\n", __test_convert_error_to_string(rv));
403                         g_free(ap_name);
404                         return false;
405                 }
406
407                 char *inputed_name = NULL;
408                 bool is_pass_set;
409                 rv = wifi_ap_get_eap_passphrase(ap, &inputed_name, &is_pass_set);
410                 if (rv != WIFI_ERROR_NONE) {
411                         printf("Fail to get eap passphrase : %s\n", __test_convert_error_to_string(rv));
412                         g_free(ap_name);
413                         return false;
414                 }
415
416                 printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE");
417
418                 rv = wifi_connect(ap, __test_connected_callback, NULL);
419                 if (rv != WIFI_ERROR_NONE)
420                         printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
421                 else
422                         printf("Success to connection request [%s]\n", ap_name);
423
424                 g_free(ap_name);
425                 g_free(inputed_name);
426                 return false;
427         }
428
429         g_free(ap_name);
430         return true;
431 }
432
433 static bool test_get_user_int(const char *msg, int *num)
434 {
435         if (msg == NULL || num == NULL)
436                 return false;
437
438         int rv;
439         char buf[32] = {0,};
440         printf("%s\n", msg);
441         rv = read(0, buf, 32);
442
443         if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
444                 return false;
445
446         *num = atoi(buf);
447         return true;
448 }
449
450 static bool __test_found_change_ip_method_callback(wifi_ap_h ap, void *user_data)
451 {
452         int rv;
453         char *ap_name;
454         char *ap_name_part = (char*)user_data;
455
456         rv = wifi_ap_get_essid(ap, &ap_name);
457         if (rv != WIFI_ERROR_NONE) {
458                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
459                 return false;
460         }
461
462         if (strstr(ap_name, ap_name_part) != NULL) {
463                 wifi_ip_config_type_e type;
464                 int method;
465                 int address_type;
466
467                 printf("Input new method type (1:dhcp, 2:manual, 3:auto) :\n");
468                 rv = scanf("%9d", &method);
469                 if (rv <= 0) {
470                         g_free(ap_name);
471                         return false;
472                 }
473
474                 rv = test_get_user_int("Input Address type to get"
475                                                         "(0:IPV4, 1:IPV6):", &address_type);
476
477                 if (rv == false || (address_type != 0 && address_type != 1)) {
478                         printf("Invalid input!!\n");
479                         return false;
480                 }
481
482                 switch (method) {
483                 case 1:
484                         type = WIFI_IP_CONFIG_TYPE_DYNAMIC;
485                         break;
486                 case 2:
487                         type = WIFI_IP_CONFIG_TYPE_STATIC;
488                         break;
489                 case 3:
490                         type = WIFI_IP_CONFIG_TYPE_AUTO;
491                         break;
492                 default:
493                         printf("Invalid input!\n");
494                         g_free(ap_name);
495                         return false;
496                 }
497
498                 rv = wifi_ap_set_ip_config_type(ap, address_type, type);
499                 if (rv != WIFI_ERROR_NONE)
500                         printf("Fail to set ip method type[%s]\n", __test_convert_error_to_string(rv));
501
502                 if (type == WIFI_IP_CONFIG_TYPE_STATIC) {
503                         char ip_addr[16];
504
505                         printf("Input new ip address (x:skip, 0:clear) :\n");
506                         rv = scanf("%15s", ip_addr);
507                         if (rv > 0) {
508                                 switch (ip_addr[0]) {
509                                 case 'x':
510                                         rv = WIFI_ERROR_NONE;
511                                         break;
512                                 case '0':
513                                         rv = wifi_ap_set_ip_address(ap, address_type, NULL);
514                                         break;
515                                 default:
516                                         rv = wifi_ap_set_ip_address(ap, address_type, ip_addr);
517                                 }
518
519                                 if (rv != WIFI_ERROR_NONE)
520                                         printf("Fail to set ip address[%s]\n",
521                                                         __test_convert_error_to_string(rv));
522                         }
523
524                         printf("Input new subnet mask (x:skip, 0:clear) :\n");
525                         rv = scanf("%15s", ip_addr);
526                         if (rv > 0) {
527                                 switch (ip_addr[0]) {
528                                 case 'x':
529                                         rv = WIFI_ERROR_NONE;
530                                         break;
531                                 case '0':
532                                         rv = wifi_ap_set_subnet_mask(ap, address_type, NULL);
533                                         break;
534                                 default:
535                                         rv = wifi_ap_set_subnet_mask(ap, address_type, ip_addr);
536                                 }
537
538                                 if (rv != WIFI_ERROR_NONE)
539                                         printf("Fail to set subnet mask[%s]\n",
540                                                         __test_convert_error_to_string(rv));
541                         }
542
543                         printf("Input new gateway address (x:skip, 0:clear) :\n");
544                         rv = scanf("%15s", ip_addr);
545                         if (rv > 0) {
546                                 switch (ip_addr[0]) {
547                                 case 'x':
548                                         rv = WIFI_ERROR_NONE;
549                                         break;
550                                 case '0':
551                                         rv = wifi_ap_set_gateway_address(ap, address_type, NULL);
552                                         break;
553                                 default:
554                                         rv = wifi_ap_set_gateway_address(ap, address_type, ip_addr);
555                                 }
556
557                                 if (rv != WIFI_ERROR_NONE)
558                                         printf("Fail to set gateway address[%s]\n",
559                                                         __test_convert_error_to_string(rv));
560                         }
561                 }
562
563                 g_free(ap_name);
564                 return false;
565         }
566
567         g_free(ap_name);
568         return true;
569 }
570
571 static bool __test_found_change_proxy_method_callback(wifi_ap_h ap, void *user_data)
572 {
573         int rv, address_type;
574         char *ap_name;
575         char *ap_name_part = (char*)user_data;
576
577         rv = wifi_ap_get_essid(ap, &ap_name);
578         if (rv != WIFI_ERROR_NONE) {
579                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
580                 return false;
581         }
582
583         printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
584         if (strstr(ap_name, ap_name_part) != NULL) {
585                 wifi_proxy_type_e type;
586                 char proxy_addr[65];
587                 int method;
588
589                 printf("Input new method type (1:direct, 2:manual, 3:auto) :\n");
590                 rv = scanf("%9d", &method);
591                 if (rv <= 0) {
592                         g_free(ap_name);
593                         return false;
594                 }
595
596                 rv = test_get_user_int("Input Address type to get"
597                                                         "(0:IPV4, 1:IPV6):", &address_type);
598
599                 if (rv == false || (address_type != 0 && address_type != 1)) {
600                         printf("Invalid input!!\n");
601                         return false;
602                 }
603
604                 switch (method) {
605                 case 1:
606                         type = WIFI_PROXY_TYPE_DIRECT;
607                         break;
608                 case 2:
609                         type = WIFI_PROXY_TYPE_MANUAL;
610                         break;
611                 case 3:
612                         type = WIFI_PROXY_TYPE_AUTO;
613                         break;
614                 default:
615                         printf("Invalid input!\n");
616                         g_free(ap_name);
617                         return false;
618                 }
619
620                 rv = wifi_ap_set_proxy_type(ap, type);
621                 if (rv != WIFI_ERROR_NONE)
622                         printf("Fail to set proxy method type[%s]\n", __test_convert_error_to_string(rv));
623
624                 printf("Input new proxy address (x:skip, 0:clear) :\n");
625                 rv = scanf("%64s", proxy_addr);
626
627                 if (rv > 0) {
628                         switch (proxy_addr[0]) {
629                         case 'x':
630                                 rv = WIFI_ERROR_NONE;
631                                 break;
632                         case '0':
633                                 rv = wifi_ap_set_proxy_address(ap, address_type, NULL);
634                                 break;
635                         default:
636                                 rv = wifi_ap_set_proxy_address(ap, address_type, proxy_addr);
637                         }
638
639                         if (rv != WIFI_ERROR_NONE)
640                                 printf("Fail to set proxy address[%s]\n", __test_convert_error_to_string(rv));
641                 }
642
643                 g_free(ap_name);
644                 return false;
645         }
646
647         g_free(ap_name);
648         return true;
649 }
650
651 static bool __test_found_print_ap_info_callback(wifi_ap_h ap, void *user_data)
652 {
653         int rv, address_type = 0;
654         char *ap_name;
655         char *str_value;
656         int int_value;
657         wifi_connection_state_e conn_state;
658         wifi_ip_config_type_e ip_type;
659         wifi_proxy_type_e proxy_type;
660         wifi_security_type_e sec_type;
661         wifi_encryption_type_e enc_type;
662         wifi_eap_type_e eap_type;
663         wifi_eap_auth_type_e eap_auth_type;
664         bool bool_value;
665         char *ap_name_part = (char*)user_data;
666
667         rv = wifi_ap_get_essid(ap, &ap_name);
668         if (rv != WIFI_ERROR_NONE) {
669                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
670                 return false;
671         }
672
673         printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
674         if (strstr(ap_name, ap_name_part) != NULL) {
675
676                 /* Basic info */
677                 printf("ESSID : %s\n", ap_name);
678
679                 if (wifi_ap_get_bssid(ap, &str_value) == WIFI_ERROR_NONE) {
680                         printf("BSSID : %s\n", str_value);
681                         g_free(str_value);
682                 } else
683                         printf("Fail to get BSSID\n");
684
685                 if (wifi_ap_get_rssi(ap, &int_value) == WIFI_ERROR_NONE)
686                         printf("RSSI : %d\n", int_value);
687                 else
688                         printf("Fail to get RSSI\n");
689
690                 if (wifi_ap_get_frequency(ap, &int_value) == WIFI_ERROR_NONE)
691                         printf("Frequency : %d\n", int_value);
692                 else
693                         printf("Fail to get Frequency\n");
694
695                 if (wifi_ap_get_max_speed(ap, &int_value) == WIFI_ERROR_NONE)
696                         printf("Max speed : %d\n", int_value);
697                 else
698                         printf("Fail to get Max speed\n");
699
700                 if (wifi_ap_is_favorite(ap, &bool_value) == WIFI_ERROR_NONE)
701                         printf("Favorite : %s\n", bool_value ? "TRUE" : "FALSE");
702                 else
703                         printf("Fail to get Favorite\n");
704
705                 /* Network info */
706                 if (wifi_ap_get_connection_state(ap, &conn_state) == WIFI_ERROR_NONE)
707                         printf("Connection State : %d\n", conn_state);
708                 else
709                         printf("Fail to get Connection State\n");
710
711                 rv = test_get_user_int("Input Address type to get"
712                                                         "(0:IPV4, 1:IPV6):", &address_type);
713
714                 if (rv == false || (address_type != 0 && address_type != 1)) {
715                         printf("Invalid input!!\n");
716                         return false;
717                 }
718
719                 if (wifi_ap_get_ip_config_type(ap, address_type, &ip_type) == WIFI_ERROR_NONE)
720                         printf("IP config type : %d\n", ip_type);
721                 else
722                         printf("Fail to get IP config type\n");
723
724                 if (wifi_ap_get_ip_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
725                         printf("IP : %s\n", str_value);
726                         g_free(str_value);
727                 } else
728                         printf("Fail to get IP\n");
729
730                 if (wifi_ap_get_subnet_mask(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
731                         printf("Subnet mask : %s\n", str_value);
732                         g_free(str_value);
733                 } else
734                         printf("Fail to get Subnet mask\n");
735
736                 if (wifi_ap_get_gateway_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
737                         printf("Gateway : %s\n", str_value);
738                         g_free(str_value);
739                 } else
740                         printf("Fail to get Gateway\n");
741
742                 if (wifi_ap_get_proxy_type(ap, &proxy_type) == WIFI_ERROR_NONE)
743                         printf("Proxy type : %d\n", proxy_type);
744                 else
745                         printf("Fail to get Proxy type\n");
746
747                 if (wifi_ap_get_proxy_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
748                         printf("Proxy : %s\n", str_value);
749                         g_free(str_value);
750                 } else
751                         printf("Fail to get Proxy\n");
752
753                 if (wifi_ap_get_dns_address(ap, 1, address_type, &str_value) == WIFI_ERROR_NONE) {
754                         printf("DNS1 : %s\n", str_value);
755                         g_free(str_value);
756                 } else
757                         printf("Fail to get DNS1\n");
758
759                 if (wifi_ap_get_dns_address(ap, 2, address_type, &str_value) == WIFI_ERROR_NONE) {
760                         printf("DNS2 : %s\n", str_value);
761                         g_free(str_value);
762                 } else
763                         printf("Fail to get DNS2\n");
764
765                 /* Security info */
766                 if (wifi_ap_get_security_type(ap, &sec_type) == WIFI_ERROR_NONE)
767                         printf("Security type : %d\n", sec_type);
768                 else
769                         printf("Fail to get Security type\n");
770
771                 if (wifi_ap_get_encryption_type(ap, &enc_type) == WIFI_ERROR_NONE)
772                         printf("Encryption type : %d\n", enc_type);
773                 else
774                         printf("Fail to get Encryption type\n");
775
776                 if (wifi_ap_is_passphrase_required(ap, &bool_value) == WIFI_ERROR_NONE)
777                         printf("Passphrase required : %s\n", bool_value ? "TRUE" : "FALSE");
778                 else
779                         printf("Fail to get Passphrase required\n");
780
781                 if (wifi_ap_is_wps_supported(ap, &bool_value) == WIFI_ERROR_NONE)
782                         printf("WPS supported : %s\n", bool_value ? "TRUE" : "FALSE");
783                 else
784                         printf("Fail to get WPS supported\n");
785
786                 if (sec_type != WIFI_SECURITY_TYPE_EAP) {
787                         g_free(ap_name);
788                         return false;
789                 }
790
791                 /* EAP info */
792                 if (wifi_ap_get_eap_type(ap, &eap_type) == WIFI_ERROR_NONE)
793                         printf("EAP type : %d\n", eap_type);
794                 else
795                         printf("Fail to get EAP type\n");
796
797                 if (wifi_ap_get_eap_auth_type(ap, &eap_auth_type) == WIFI_ERROR_NONE)
798                         printf("EAP auth type : %d\n", eap_auth_type);
799                 else
800                         printf("Fail to get EAP auth type\n");
801
802                 if (wifi_ap_get_eap_passphrase(ap, &str_value, &bool_value) == WIFI_ERROR_NONE) {
803                         printf("EAP user name : %s\n", str_value);
804                         printf("EAP is password setted : %s\n", bool_value ? "TRUE" : "FALSE");
805                         g_free(str_value);
806                 } else
807                         printf("Fail to get EAP passphrase(user name/password)\n");
808
809                 if (wifi_ap_get_eap_ca_cert_file(ap, &str_value) == WIFI_ERROR_NONE) {
810                         printf("EAP ca cert file : %s\n", str_value);
811                         g_free(str_value);
812                 } else
813                         printf("Fail to get EAP ca cert file\n");
814
815                 if (wifi_ap_get_eap_client_cert_file(ap, &str_value) == WIFI_ERROR_NONE) {
816                         printf("EAP client cert file : %s\n", str_value);
817                         g_free(str_value);
818                 } else
819                         printf("Fail to get EAP client cert file\n");
820
821                 if (wifi_ap_get_eap_private_key_file(ap, &str_value) == WIFI_ERROR_NONE) {
822                         printf("EAP private key file : %s\n", str_value);
823                         g_free(str_value);
824                 } else
825                         printf("Fail to get EAP private key file\n");
826
827                 g_free(ap_name);
828                 return false;
829         }
830
831         g_free(ap_name);
832         return true;
833 }
834
835 static bool _test_config_list_cb(const wifi_config_h config, void *user_data)
836 {
837         gchar *name = NULL;
838         wifi_security_type_e security_type;
839
840         wifi_config_get_name(config, &name);
841         wifi_config_get_security_type(config, &security_type);
842
843         printf("Name[%s] ", name);
844         printf("Security type[%d] ", security_type);
845         if (security_type == WIFI_SECURITY_TYPE_EAP) {
846                 wifi_eap_type_e eap_type;
847                 wifi_eap_auth_type_e eap_auth_type;
848                 wifi_config_get_eap_type(config, &eap_type);
849                 printf("Eap type[%d] ", eap_type);
850                 wifi_config_get_eap_auth_type(config, &eap_auth_type);
851                 printf("Eap auth type[%d]", eap_auth_type);
852         }
853         printf("\n");
854
855         g_free(name);
856
857         return true;
858 }
859
860 static bool __test_found_specific_aps_callback(wifi_ap_h ap, void *user_data)
861 {
862         printf("Found specific ap Completed\n");
863
864         int rv;
865         char *ap_name = NULL;
866         wifi_security_type_e security_type = WIFI_SECURITY_TYPE_NONE;
867
868         rv = wifi_ap_get_essid(ap, &ap_name);
869         if (rv != WIFI_ERROR_NONE) {
870                 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
871                 return -1;
872         }
873         printf("[AP name] : %s\n", ap_name);
874
875         rv = wifi_ap_get_security_type(ap, &security_type);
876         if (rv == WIFI_ERROR_NONE)
877                 printf("[Security type] : %d\n", security_type);
878         else {
879                 printf("Fail to get Security type\n");
880                 g_free(ap_name);
881                 return false;
882         }
883
884         switch (security_type) {
885         case WIFI_SECURITY_TYPE_WEP:
886         case WIFI_SECURITY_TYPE_WPA_PSK:
887         case WIFI_SECURITY_TYPE_WPA2_PSK:
888                 {
889                         char passphrase[100];
890                         printf("Input passphrase for %s : ", ap_name);
891                         rv = scanf("%99s", passphrase);
892
893                         rv = wifi_ap_set_passphrase(ap, passphrase);
894                         if (rv != WIFI_ERROR_NONE) {
895                                 printf("Fail to set passphrase : %s\n", __test_convert_error_to_string(rv));
896                                 g_free(ap_name);
897                                 return false;
898                         }
899                 }
900                 break;
901         case WIFI_SECURITY_TYPE_EAP:
902                 {
903                         char input_str1[100];
904                         printf("Input user name for %s : ", ap_name);
905                         rv = scanf("%99s", input_str1);
906
907                         char input_str2[100];
908                         printf("Input password for %s : ", ap_name);
909                         rv = scanf("%99s", input_str2);
910
911                         rv = wifi_ap_set_eap_passphrase(ap, input_str1, input_str2);
912                         if (rv != WIFI_ERROR_NONE) {
913                                 printf("Fail to set eap passphrase : %s\n", __test_convert_error_to_string(rv));
914                                 g_free(ap_name);
915                                 return false;
916                         }
917
918                         char *inputed_name = NULL;
919                         bool is_pass_set;
920                         rv = wifi_ap_get_eap_passphrase(ap, &inputed_name, &is_pass_set);
921                         if (rv != WIFI_ERROR_NONE) {
922                                 printf("Fail to get eap passphrase : %s\n", __test_convert_error_to_string(rv));
923                                 g_free(ap_name);
924                                 return false;
925                         }
926
927                         printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE");
928                         g_free(inputed_name);
929                 }
930                 break;
931         case WIFI_SECURITY_TYPE_NONE:
932         default:
933                 break;
934         }
935
936         rv = wifi_connect(ap, __test_connected_callback, NULL);
937         if (rv != WIFI_ERROR_NONE)
938                 printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
939         else
940                 printf("Success to connection request [%s]\n", ap_name);
941
942         g_free(ap_name);
943         return true;
944 }
945
946 static void __test_scan_specific_ap_callback(wifi_error_e error_code, void* user_data)
947 {
948         int rv;
949
950         printf("Specific scan Completed from scan request, error code : %s\n",
951                         __test_convert_error_to_string(error_code));
952
953         if (error_code != WIFI_ERROR_NONE)
954                 return;
955
956         rv = wifi_foreach_found_specific_aps(__test_found_specific_aps_callback, user_data);
957         if (rv != WIFI_ERROR_NONE) {
958                 printf("Fail to get specific AP(can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
959                 return;
960         }
961 }
962
963 int test_wifi_init(void)
964 {
965         int rv = wifi_initialize();
966
967         if (rv == WIFI_ERROR_NONE) {
968                 wifi_set_device_state_changed_cb(__test_device_state_callback, NULL);
969                 wifi_set_background_scan_cb(__test_bg_scan_completed_callback, NULL);
970                 wifi_set_connection_state_changed_cb(__test_connection_state_callback, NULL);
971                 wifi_set_rssi_level_changed_cb(__test_rssi_level_callback, NULL);
972         } else {
973                 printf("Wifi init failed [%s]\n", __test_convert_error_to_string(rv));
974                 return -1;
975         }
976
977         printf("Wifi init succeeded\n");
978         return 1;
979 }
980
981 int  test_wifi_deinit(void)
982 {
983         int rv = 0;
984
985         rv = wifi_deinitialize();
986
987         if (rv != WIFI_ERROR_NONE) {
988                 printf("Wifi deinit failed [%s]\n", __test_convert_error_to_string(rv));
989                 return -1;
990         }
991
992         printf("Wifi deinit succeeded\n");
993         return 1;
994 }
995
996 int test_wifi_activate(void)
997 {
998         int rv = 0;
999
1000         rv = wifi_activate(__test_activated_callback, NULL);
1001
1002         if (rv != WIFI_ERROR_NONE) {
1003                 printf("Fail to activate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
1004                 return -1;
1005         }
1006
1007         printf("Success to activate Wi-Fi device\n");
1008
1009         return 1;
1010 }
1011
1012 int test_wifi_deactivate(void)
1013 {
1014         int rv = 0;
1015
1016         rv = wifi_deactivate(__test_deactivated_callback, NULL);
1017
1018         if (rv != WIFI_ERROR_NONE) {
1019                 printf("Fail to deactivate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
1020                 return -1;
1021         }
1022
1023         printf("Success to deactivate Wi-Fi device\n");
1024
1025         return 1;
1026 }
1027
1028 int test_is_activated(void)
1029 {
1030         int rv = 0;
1031         bool state = false;
1032
1033         rv = wifi_is_activated(&state);
1034
1035         if (rv != WIFI_ERROR_NONE) {
1036                 printf("Fail to get Wi-Fi device state [%s]\n", __test_convert_error_to_string(rv));
1037                 return -1;
1038         }
1039
1040         printf("Success to get Wi-Fi device state : %s\n", (state) ? "TRUE" : "FALSE");
1041
1042         return 1;
1043 }
1044
1045 int test_get_connection_state(void)
1046 {
1047         int rv = 0;
1048         wifi_connection_state_e connection_state;
1049
1050         rv = wifi_get_connection_state(&connection_state);
1051
1052         if (rv != WIFI_ERROR_NONE) {
1053                 printf("Fail to get connection state [%s]\n", __test_convert_error_to_string(rv));
1054                 return -1;
1055         }
1056
1057         printf("Success to get connection state : ");
1058         switch (connection_state) {
1059         case WIFI_CONNECTION_STATE_ASSOCIATION:
1060                 printf("Association\n");
1061                 break;
1062         case WIFI_CONNECTION_STATE_CONNECTED:
1063                 printf("Connected\n");
1064                 break;
1065         case WIFI_CONNECTION_STATE_CONFIGURATION:
1066                 printf("Configuration\n");
1067                 break;
1068         case WIFI_CONNECTION_STATE_DISCONNECTED:
1069                 printf("Disconnected\n");
1070                 break;
1071         default:
1072                 printf("Unknown\n");
1073         }
1074
1075         return 1;
1076 }
1077
1078 int test_get_mac_address(void)
1079 {
1080         int rv = 0;
1081         char *mac_addr = NULL;
1082
1083         rv = wifi_get_mac_address(&mac_addr);
1084
1085         if (rv != WIFI_ERROR_NONE) {
1086                 printf("Fail to get MAC address [%s]\n", __test_convert_error_to_string(rv));
1087                 return -1;
1088         }
1089
1090         printf("MAC address : %s\n", mac_addr);
1091         g_free(mac_addr);
1092
1093         return 1;
1094 }
1095
1096 int test_get_interface_name(void)
1097 {
1098         int rv = 0;
1099         char *if_name = NULL;
1100
1101         rv = wifi_get_network_interface_name(&if_name);
1102
1103         if (rv != WIFI_ERROR_NONE) {
1104                 printf("Fail to get Interface name [%s]\n", __test_convert_error_to_string(rv));
1105                 return -1;
1106         }
1107
1108         printf("Interface name : %s\n", if_name);
1109         g_free(if_name);
1110
1111         return 1;
1112 }
1113
1114 int test_scan_request(void)
1115 {
1116         int rv = 0;
1117
1118         rv = wifi_scan(__test_scan_request_callback, NULL);
1119
1120         if (rv != WIFI_ERROR_NONE) {
1121                 printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv));
1122                 return -1;
1123         }
1124
1125         printf("Scan request succeeded\n");
1126
1127         return 1;
1128 }
1129
1130 int test_get_connected_ap(void)
1131 {
1132         int rv = 0;
1133         char *ap_name = NULL;
1134         wifi_ap_h ap_h;
1135
1136         rv = wifi_get_connected_ap(&ap_h);
1137         if (rv != WIFI_ERROR_NONE) {
1138                 printf("Fail to get connected AP [%s]\n", __test_convert_error_to_string(rv));
1139                 return -1;
1140         }
1141
1142         rv = wifi_ap_get_essid(ap_h, &ap_name);
1143         if (rv != WIFI_ERROR_NONE) {
1144                 printf("Fail to get essid [%s]\n", __test_convert_error_to_string(rv));
1145                 wifi_ap_destroy(ap_h);
1146                 return -1;
1147         }
1148
1149         printf("Connected AP : %s\n", ap_name);
1150         g_free(ap_name);
1151         wifi_ap_destroy(ap_h);
1152
1153         return 1;
1154 }
1155
1156 int test_foreach_found_aps(void)
1157 {
1158         int rv = 0;
1159
1160         rv = wifi_foreach_found_aps(__test_found_ap_callback, NULL);
1161         if (rv != WIFI_ERROR_NONE) {
1162                 printf("Fail to get AP list [%s]\n", __test_convert_error_to_string(rv));
1163                 return -1;
1164         }
1165
1166         printf("Get AP list finished\n");
1167
1168         return 1;
1169 }
1170
1171 int test_connect_ap(void)
1172 {
1173         int rv = 0;
1174         char ap_name[33];
1175         bool state = false;
1176
1177         wifi_is_activated(&state);
1178         if (state == false)
1179                 return -1;
1180
1181         printf("Input a part of AP name to connect : ");
1182         rv = scanf("%32s", ap_name);
1183
1184         rv = wifi_foreach_found_aps(__test_found_connect_ap_callback, ap_name);
1185         if (rv != WIFI_ERROR_NONE) {
1186                 printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1187                 return -1;
1188         }
1189
1190         printf("Connection step finished\n");
1191         return 1;
1192 }
1193
1194 int test_connect_specific_ap(void)
1195 {
1196         int rv;
1197         char ap_name[33];
1198
1199         printf("Input a part of specific AP name to connect : ");
1200         rv = scanf("%32s", ap_name);
1201         if (rv <= 0)
1202                 return -1;
1203
1204         rv = wifi_scan_specific_ap(ap_name, __test_scan_specific_ap_callback, NULL);
1205
1206         if (rv != WIFI_ERROR_NONE) {
1207                 printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv));
1208                 return -1;
1209         }
1210
1211         printf("Scan specific AP request succeeded\n");
1212         return 1;
1213 }
1214
1215 int test_disconnect_ap(void)
1216 {
1217         int rv = 0;
1218         char ap_name[33];
1219         bool state = false;
1220
1221         wifi_is_activated(&state);
1222         if (state == false)
1223                 return -1;
1224
1225         printf("Input a part of AP name to disconnect : ");
1226         rv = scanf("%32s", ap_name);
1227
1228         rv = wifi_foreach_found_aps(__test_found_disconnect_ap_callback, ap_name);
1229         if (rv != WIFI_ERROR_NONE) {
1230                 printf("Fail to disconnect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1231                 return -1;
1232         }
1233
1234         printf("Disconnection step finished\n");
1235         return 1;
1236 }
1237
1238 int test_connect_wps(void)
1239 {
1240         int rv = 0;
1241         char ap_name[33];
1242         bool state = false;
1243
1244         wifi_is_activated(&state);
1245         if (state == false)
1246                 return -1;
1247
1248         printf("Input a part of AP name to connect by wps : ");
1249         rv = scanf("%32s", ap_name);
1250
1251         rv = wifi_foreach_found_aps(__test_found_connect_wps_callback, ap_name);
1252         if (rv != WIFI_ERROR_NONE) {
1253                 printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1254                 return -1;
1255         }
1256
1257         printf("Connection step finished\n");
1258         return 1;
1259 }
1260
1261 int test_forget_ap(void)
1262 {
1263         int rv = 0;
1264         char ap_name[33];
1265         bool state = false;
1266
1267         wifi_is_activated(&state);
1268         if (state == false)
1269                 return -1;
1270
1271         printf("Input a part of AP name to forget : ");
1272         rv = scanf("%32s", ap_name);
1273
1274         rv = wifi_foreach_found_aps(__test_found_forget_ap_callback, ap_name);
1275         if (rv != WIFI_ERROR_NONE) {
1276                 printf("Fail to forget (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1277                 return -1;
1278         }
1279
1280         printf("Forget AP finished\n");
1281         return 1;
1282 }
1283
1284 int test_connect_eap_ap(void)
1285 {
1286         int rv = 0;
1287         char ap_name[33];
1288         bool state = false;
1289
1290         wifi_is_activated(&state);
1291         if (state == false)
1292                 return -1;
1293
1294         printf("Input a part of AP name to connect : ");
1295         rv = scanf("%32s", ap_name);
1296
1297         rv = wifi_foreach_found_aps(__test_found_eap_ap_callback, ap_name);
1298         if (rv != WIFI_ERROR_NONE) {
1299                 printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1300                 return -1;
1301         }
1302
1303         printf("Connection step finished\n");
1304         return 1;
1305 }
1306
1307 int test_set_ip_method(void)
1308 {
1309         int rv;
1310         char ap_name[33];
1311         bool state;
1312
1313         rv = wifi_is_activated(&state);
1314         if (rv != WIFI_ERROR_NONE || state == false)
1315                 return -1;
1316
1317         printf("Input a part of AP name to change IP method : ");
1318         rv = scanf("%32s", ap_name);
1319         if (rv <= 0)
1320                 return -1;
1321
1322         rv = wifi_foreach_found_aps(__test_found_change_ip_method_callback, ap_name);
1323         if (rv != WIFI_ERROR_NONE) {
1324                 printf("Fail to change (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1325                 return -1;
1326         }
1327
1328         printf("IP method changing finished\n");
1329         return 1;
1330 }
1331
1332 int test_set_proxy_method(void)
1333 {
1334         int rv;
1335         char ap_name[33];
1336         bool state;
1337
1338         rv = wifi_is_activated(&state);
1339         if (rv != WIFI_ERROR_NONE || state == false)
1340                 return -1;
1341
1342         printf("Input a part of AP name to change Proxy method : ");
1343         rv = scanf("%32s", ap_name);
1344         if (rv <= 0)
1345                 return -1;
1346
1347         rv = wifi_foreach_found_aps(__test_found_change_proxy_method_callback, ap_name);
1348         if (rv != WIFI_ERROR_NONE) {
1349                 printf("Fail to change (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1350                 return -1;
1351         }
1352
1353         printf("Proxy method changing finished\n");
1354         return 1;
1355 }
1356
1357 int test_get_ap_info(void)
1358 {
1359         int rv;
1360         char ap_name[33];
1361         bool state;
1362
1363         rv = wifi_is_activated(&state);
1364         if (rv != WIFI_ERROR_NONE || state == false)
1365                 return -1;
1366
1367         printf("Input a part of AP name to get detailed info : ");
1368         rv = scanf("%32s", ap_name);
1369         if (rv <= 0)
1370                 return -1;
1371
1372         rv = wifi_foreach_found_aps(__test_found_print_ap_info_callback, ap_name);
1373         if (rv != WIFI_ERROR_NONE) {
1374                 printf("Fail to get AP info (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1375                 return -1;
1376         }
1377
1378         printf("AP info printing finished\n");
1379         return 1;
1380 }
1381
1382 int test_load_configuration(void)
1383 {
1384         int rv;
1385
1386         rv = wifi_config_foreach_configuration(_test_config_list_cb, NULL);
1387         if (rv != WIFI_ERROR_NONE)
1388                 return -1;
1389
1390         return 1;
1391 }
1392
1393 int test_save_configuration(void)
1394 {
1395         int rv;
1396         char name[33] = { 0, };
1397         char passphrase[100] = { 0, };
1398         int type = 0;
1399         wifi_config_h config;
1400
1401         printf("Input AP configuration\n");
1402         printf("Name : ");
1403         rv = scanf("%32s", name);
1404         if (rv <= 0)
1405                 return -1;
1406
1407         printf("Passphrase : ");
1408         rv = scanf("%99s", passphrase);
1409         if (rv <= 0)
1410                 return -1;
1411
1412         printf("Security type(None(0), WEP(1), WPA-PSK(2), EAP(4) : ");
1413         rv = scanf("%d", &type);
1414         if (rv <= 0)
1415                 return -1;
1416
1417         rv = wifi_config_create(name, passphrase, type, &config);
1418         if (rv != WIFI_ERROR_NONE)
1419                 return -1;
1420
1421         rv = wifi_config_save_configuration(config);
1422         if (rv != WIFI_ERROR_NONE)
1423                 return -1;
1424
1425         rv = wifi_config_destroy(config);
1426         if (rv != WIFI_ERROR_NONE)
1427                 return -1;
1428
1429         return 1;
1430 }
1431
1432 int test_set_configuration_proxy_and_hidden(void)
1433 {
1434         int rv;
1435         char name[33] = { 0, };
1436         char passphrase[100] = { 0, };
1437         int type = 0;
1438         char proxy[100] = { 0, };
1439         int hidden = 0;
1440         wifi_config_h config;
1441
1442         printf("Input AP configuration\n");
1443         printf("Name : ");
1444         rv = scanf("%32s", name);
1445         if (rv <= 0)
1446                 return -1;
1447
1448         printf("Passphrase : ");
1449         rv = scanf("%99s", passphrase);
1450         if (rv <= 0)
1451                 return -1;
1452
1453         printf("Security type(None(0), WEP(1), WPA-PSK(2), EAP(4) : ");
1454         rv = scanf("%d", &type);
1455         if (rv <= 0)
1456                 return -1;
1457
1458         printf("Proxy(server:port) : ");
1459         rv = scanf("%99s", proxy);
1460         if (rv <= 0)
1461                 return -1;
1462
1463         printf("Hidden(1:Hidden) : ");
1464         rv = scanf("%d", &hidden);
1465         if (rv <= 0)
1466                 return -1;
1467
1468         rv = wifi_config_create(name, passphrase, type, &config);
1469         if (rv != WIFI_ERROR_NONE)
1470                 return -1;
1471
1472         rv = wifi_config_save_configuration(config);
1473         if (rv != WIFI_ERROR_NONE)
1474                 return -1;
1475
1476         rv = wifi_config_set_proxy_address(config, WIFI_ADDRESS_FAMILY_IPV4, proxy);
1477         if (rv != WIFI_ERROR_NONE)
1478                 return -1;
1479
1480         if (hidden == 1)
1481                 rv = wifi_config_set_hidden_ap_property(config, TRUE);
1482         else
1483                 rv = wifi_config_set_hidden_ap_property(config, FALSE);
1484         if (rv != WIFI_ERROR_NONE)
1485                 return -1;
1486
1487         rv = wifi_config_destroy(config);
1488         if (rv != WIFI_ERROR_NONE)
1489                 return -1;
1490
1491         return 1;
1492 }
1493
1494 int test_set_eap_configuration(void)
1495 {
1496         int rv;
1497         char name[33] = { 0, };
1498         char passphrase[100] = { 0, };
1499         int type = WIFI_SECURITY_TYPE_EAP;
1500         wifi_config_h config;
1501
1502         printf("Input EAP configuration\n");
1503         printf("Name : ");
1504         rv = scanf("%32s", name);
1505         if (rv <= 0)
1506                 return -1;
1507
1508         printf("Passphrase : ");
1509         rv = scanf("%99s", passphrase);
1510         if (rv <= 0)
1511                 return -1;
1512
1513         rv = wifi_config_create(name, passphrase, type, &config);
1514         if (rv != WIFI_ERROR_NONE)
1515                 return -1;
1516
1517         rv = wifi_config_save_configuration(config);
1518         if (rv != WIFI_ERROR_NONE)
1519                 return -1;
1520
1521         rv = wifi_config_set_eap_type(config, WIFI_EAP_TYPE_TLS);
1522         if (rv != WIFI_ERROR_NONE)
1523                 return -1;
1524
1525         rv = wifi_config_set_eap_auth_type(config, WIFI_EAP_AUTH_TYPE_MD5);
1526         if (rv != WIFI_ERROR_NONE)
1527                 return -1;
1528
1529         rv = wifi_config_destroy(config);
1530         if (rv != WIFI_ERROR_NONE)
1531                 return -1;
1532
1533         return 1;
1534 }
1535
1536 int test_wifi_tdls_disconnect(void)
1537 {
1538         int rv = 0;
1539
1540         char peer_mac[18];
1541         printf("Enter Mac_address: ");
1542         if (scanf(" %17s", peer_mac) < 1)
1543                 return -1;
1544
1545         if (strlen(peer_mac) > 17) {
1546                 printf("Wrong Mac_address\n");
1547                 return -1;
1548         }
1549
1550         rv = wifi_tdls_disconnect(peer_mac);
1551         if (rv != WIFI_ERROR_NONE) {
1552                 printf("test_wifi_tdls_disconnect() is failed [%s]\n", __test_convert_error_to_string(rv));
1553                 return -1;
1554         }
1555         return 1;
1556 }
1557
1558 int test_wifi_tdls_get_connected_peer(void)
1559 {
1560         int rv = 0;
1561         char *mac_addr = NULL;
1562
1563         rv = wifi_tdls_get_connected_peer(&mac_addr);
1564         if (rv != WIFI_ERROR_NONE) {
1565                 printf("wifi_tdls_get_connected_peer() is failed [%s]\n", __test_convert_error_to_string(rv));
1566                 return -1;
1567         }
1568         printf("Peer Mac address is [%s]\n", mac_addr);
1569         g_free(mac_addr);
1570         return 1;
1571 }
1572
1573 int main(int argc, char **argv)
1574 {
1575         GMainLoop *mainloop;
1576         g_type_init();
1577         mainloop = g_main_loop_new(NULL, FALSE);
1578
1579         GIOChannel *channel = g_io_channel_unix_new(0);
1580         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1581
1582         printf("Test Thread created...\n");
1583
1584         g_main_loop_run(mainloop);
1585
1586         return 0;
1587 }
1588
1589 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1590 {
1591         int rv;
1592         char a[10];
1593
1594         printf("Event received from stdin\n");
1595
1596         rv = read(0, a, 10);
1597
1598         if (rv <= 0 || a[0] == '0') {
1599                 rv = wifi_deinitialize();
1600
1601                 if (rv != WIFI_ERROR_NONE)
1602                         printf("Fail to deinitialize.\n");
1603
1604                 exit(1);
1605         }
1606
1607         if (a[0] == '\n' || a[0] == '\r') {
1608                 printf("\n\n Network Connection API Test App\n\n");
1609                 printf("Options..\n");
1610                 printf(LOG_GREEN "1   - Wi-Fi init and set callbacks\n" LOG_END);
1611                 printf("2   - Wi-Fi deinit(unset callbacks automatically)\n");
1612                 printf(LOG_GREEN "3   - Activate Wi-Fi device\n" LOG_END);
1613                 printf("4   - Deactivate Wi-Fi device\n");
1614                 printf("5   - Is Wi-Fi activated?\n");
1615                 printf("6   - Get connection state\n");
1616                 printf("7   - Get MAC address\n");
1617                 printf("8   - Get Wi-Fi interface name\n");
1618                 printf(LOG_GREEN "9   - Scan request\n" LOG_END);
1619                 printf("a   - Get Connected AP\n");
1620                 printf("b   - Get AP list\n");
1621                 printf(LOG_GREEN "c   - Connect\n" LOG_END);
1622                 printf("d   - Disconnect\n");
1623                 printf("e   - Connect by wps pbc\n");
1624                 printf("f   - Forget an AP\n");
1625                 printf("g   - Set & connect EAP\n");
1626                 printf("h   - Set IP method type\n");
1627                 printf("i   - Set Proxy method type\n");
1628                 printf("j   - Get Ap info\n");
1629                 printf("k   - Connect Specific AP\n");
1630                 printf("l   - Load configuration\n");
1631                 printf("m   - Save configuration\n");
1632                 printf("n   - Set configuration proxy and hidden\n");
1633                 printf("o   - Set EAP configuration\n");
1634                 printf("p   - TDLS TearDown\n");
1635                 printf("q   - TDLS Get Connected Peer\n");
1636                 printf(LOG_RED "0   - Exit \n" LOG_END);
1637
1638                 printf("ENTER  - Show options menu.......\n");
1639         }
1640
1641         switch (a[0]) {
1642         case '1':
1643                 rv = test_wifi_init();
1644                 break;
1645         case '2':
1646                 rv = test_wifi_deinit();
1647                 break;
1648         case '3':
1649                 rv = test_wifi_activate();
1650                 break;
1651         case '4':
1652                 rv = test_wifi_deactivate();
1653                 break;
1654         case '5':
1655                 rv = test_is_activated();
1656                 break;
1657         case '6':
1658                 rv = test_get_connection_state();
1659                 break;
1660         case '7':
1661                 rv = test_get_mac_address();
1662                 break;
1663         case '8':
1664                 rv = test_get_interface_name();
1665                 break;
1666         case '9':
1667                 rv = test_scan_request();
1668                 break;
1669         case 'a':
1670                 rv = test_get_connected_ap();
1671                 break;
1672         case 'b':
1673                 rv = test_foreach_found_aps();
1674                 break;
1675         case 'c':
1676                 rv = test_connect_ap();
1677                 break;
1678         case 'd':
1679                 rv = test_disconnect_ap();
1680                 break;
1681         case 'e':
1682                 rv = test_connect_wps();
1683                 break;
1684         case 'f':
1685                 rv = test_forget_ap();
1686                 break;
1687         case 'g':
1688                 rv = test_connect_eap_ap();
1689                 break;
1690         case 'h':
1691                 rv = test_set_ip_method();
1692                 break;
1693         case 'i':
1694                 rv = test_set_proxy_method();
1695                 break;
1696         case 'j':
1697                 rv = test_get_ap_info();
1698                 break;
1699         case 'k':
1700                 rv = test_connect_specific_ap();
1701                 break;
1702         case 'l':
1703                 rv = test_load_configuration();
1704                 break;
1705         case 'm':
1706                 rv = test_save_configuration();
1707                 break;
1708         case 'n':
1709                 rv = test_set_configuration_proxy_and_hidden();
1710                 break;
1711         case 'o':
1712                 rv = test_set_eap_configuration();
1713                 break;
1714         case 'p':
1715                 rv = test_wifi_tdls_disconnect();
1716                 break;
1717         case 'q':
1718                 rv = test_wifi_tdls_get_connected_peer();
1719                 break;
1720
1721         default:
1722                 break;
1723         }
1724
1725         if (rv == 1)
1726                 printf("Operation succeeded!\n");
1727         else
1728                 printf("Operation failed!\n");
1729
1730         return TRUE;
1731 }
1732