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