2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/socket.h>
27 #include <sys/ioctl.h>
31 #include <tizen_error.h>
34 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
36 static const char *__test_convert_error_to_string(wifi_error_e err_type)
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:
61 case WIFI_ERROR_INVALID_KEY:
63 case WIFI_ERROR_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";
76 static void __test_device_state_callback(wifi_device_state_e state, void* user_data)
78 printf("Device state changed callback");
80 if (state == WIFI_DEVICE_STATE_ACTIVATED)
81 printf(", state : Activated\n");
83 printf(", state : Deactivated\n");
86 static void __test_bg_scan_completed_callback(wifi_error_e error_code, void* user_data)
88 printf("Background Scan Completed, error code : %s\n",
89 __test_convert_error_to_string(error_code));
92 static void __test_scan_request_callback(wifi_error_e error_code, void* user_data)
94 if (user_data != NULL)
95 printf("user_data : %s\n", (char *)user_data);
97 printf("Scan Completed from scan request, error code : %s\n",
98 __test_convert_error_to_string(error_code));
101 static void __test_connection_state_callback(wifi_connection_state_e state, wifi_ap_h ap, void* user_data)
104 char *ap_name = NULL;
106 printf("Connection state changed callback");
109 case WIFI_CONNECTION_STATE_CONNECTED:
110 printf(", state : Connected");
112 case WIFI_CONNECTION_STATE_ASSOCIATION:
113 printf(", state : Association");
115 case WIFI_CONNECTION_STATE_CONFIGURATION:
116 printf(", state : Configuration");
118 case WIFI_CONNECTION_STATE_DISCONNECTED:
119 printf(", state : Disconnected");
122 printf(", state : Unknown");
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));
129 printf(", AP name : %s\n", ap_name);
134 static void __test_activated_callback(wifi_error_e result, void* user_data)
136 if (result == WIFI_ERROR_NONE)
137 printf("Wi-Fi Activation Succeeded\n");
139 printf("Wi-Fi Activation Failed! error : %s\n", __test_convert_error_to_string(result));
142 static void __test_deactivated_callback(wifi_error_e result, void* user_data)
144 if (result == WIFI_ERROR_NONE)
145 printf("Wi-Fi Deactivation Succeeded\n");
147 printf("Wi-Fi Deactivation Failed! error : %s\n", __test_convert_error_to_string(result));
150 static void __test_connected_callback(wifi_error_e result, void* user_data)
152 if (result == WIFI_ERROR_NONE)
153 printf("Wi-Fi Connection Succeeded\n");
155 printf("Wi-Fi Connection Failed! error : %s\n", __test_convert_error_to_string(result));
158 static void __test_disconnected_callback(wifi_error_e result, void* user_data)
160 if (result == WIFI_ERROR_NONE)
161 printf("Wi-Fi Disconnection Succeeded\n");
163 printf("Wi-Fi Disconnection Failed! error : %s\n", __test_convert_error_to_string(result));
166 static void __test_rssi_level_callback(wifi_rssi_level_e rssi_level, void* user_data)
168 printf("RSSI level changed callback, level = %d\n", rssi_level);
171 static const char* __test_print_state(wifi_connection_state_e state)
174 case WIFI_CONNECTION_STATE_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:
182 case WIFI_CONNECTION_STATE_CONFIGURATION:
183 return "Configuration";
189 static bool __test_found_ap_callback(wifi_ap_h ap, void *user_data)
192 char *ap_name = NULL;
193 wifi_connection_state_e state;
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));
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));
208 printf("AP name : %s, state : %s\n", ap_name, __test_print_state(state));
214 static bool __test_found_connect_ap_callback(wifi_ap_h ap, void *user_data)
217 char *ap_name = NULL;
218 char *ap_name_part = (char*)user_data;
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));
226 if (strstr(ap_name, ap_name_part) != NULL) {
227 bool required = false;
229 if (wifi_ap_is_passphrase_required(ap, &required) == WIFI_ERROR_NONE)
230 printf("Passphrase required : %s\n", required ? "TRUE" : "FALSE");
232 printf("Fail to get Passphrase required\n");
235 char passphrase[100];
236 printf("Input passphrase for %s : ", ap_name);
237 rv = scanf("%99s", passphrase);
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));
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));
251 printf("Success to connection request [%s]\n", ap_name);
261 static bool __test_found_connect_wps_callback(wifi_ap_h ap, void *user_data)
264 char *ap_name = NULL;
265 char *ap_name_part = (char*)user_data;
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));
273 if (strstr(ap_name, ap_name_part) != NULL) {
277 printf("%s - Input WPS method (1:PBC, 2:PIN) :\n", ap_name);
278 rv = scanf("%9d", &user_sel);
282 rv = wifi_connect_by_wps_pbc(ap, __test_connected_callback, NULL);
285 printf("Input PIN code :\n");
286 rv = scanf("%31s", pin);
287 rv = wifi_connect_by_wps_pin(ap, pin, __test_connected_callback, NULL);
290 printf("Invalid input!\n");
295 if (rv != WIFI_ERROR_NONE)
296 printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
298 printf("Success to connection request [%s]\n", ap_name);
308 static bool __test_found_disconnect_ap_callback(wifi_ap_h ap, void *user_data)
311 char *ap_name = NULL;
312 char *ap_name_part = (char*)user_data;
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));
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));
325 printf("Success to disconnection request %s\n", ap_name);
335 static bool __test_found_forget_ap_callback(wifi_ap_h ap, void *user_data)
338 char *ap_name = NULL;
339 char *ap_name_part = (char*)user_data;
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));
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));
352 printf("Success to forget [%s]\n", ap_name);
362 static bool __test_found_eap_ap_callback(wifi_ap_h ap, void *user_data)
365 char *ap_name = NULL;
366 char *ap_name_part = (char*)user_data;
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));
374 if (strstr(ap_name, ap_name_part) != NULL) {
375 wifi_security_type_e type;
377 if (wifi_ap_get_security_type(ap, &type) == WIFI_ERROR_NONE)
378 printf("Security type : %d\n", type);
380 printf("Fail to get Security type\n");
382 if (type != WIFI_SECURITY_TYPE_EAP) {
387 char input_str1[100];
388 printf("Input user name for %s : ", ap_name);
389 rv = scanf("%99s", input_str1);
391 char input_str2[100];
392 printf("Input password for %s : ", ap_name);
393 rv = scanf("%99s", input_str2);
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));
402 char *inputed_name = NULL;
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));
411 printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE");
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));
417 printf("Success to connection request [%s]\n", ap_name);
420 g_free(inputed_name);
428 static bool test_get_user_int(const char *msg, int *num)
430 if (msg == NULL || num == NULL)
436 rv = read(0, buf, 32);
438 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
445 static bool __test_found_change_ip_method_callback(wifi_ap_h ap, void *user_data)
449 char *ap_name_part = (char*)user_data;
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));
457 if (strstr(ap_name, ap_name_part) != NULL) {
458 wifi_ip_config_type_e type;
462 printf("Input new method type (1:dhcp, 2:manual, 3:auto) :\n");
463 rv = scanf("%9d", &method);
469 rv = test_get_user_int("Input Address type to get"
470 "(0:IPV4, 1:IPV6):", &address_type);
472 if (rv == false || (address_type != 0 && address_type != 1)) {
473 printf("Invalid input!!\n");
479 type = WIFI_IP_CONFIG_TYPE_DYNAMIC;
482 type = WIFI_IP_CONFIG_TYPE_STATIC;
485 type = WIFI_IP_CONFIG_TYPE_AUTO;
488 printf("Invalid input!\n");
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));
497 if (type == WIFI_IP_CONFIG_TYPE_STATIC) {
500 printf("Input new ip address (x:skip, 0:clear) :\n");
501 rv = scanf("%15s", ip_addr);
503 switch (ip_addr[0]) {
505 rv = WIFI_ERROR_NONE;
508 rv = wifi_ap_set_ip_address(ap, address_type, NULL);
511 rv = wifi_ap_set_ip_address(ap, address_type, ip_addr);
514 if (rv != WIFI_ERROR_NONE)
515 printf("Fail to set ip address[%s]\n",
516 __test_convert_error_to_string(rv));
519 printf("Input new subnet mask (x:skip, 0:clear) :\n");
520 rv = scanf("%15s", ip_addr);
522 switch (ip_addr[0]) {
524 rv = WIFI_ERROR_NONE;
527 rv = wifi_ap_set_subnet_mask(ap, address_type, NULL);
530 rv = wifi_ap_set_subnet_mask(ap, address_type, ip_addr);
533 if (rv != WIFI_ERROR_NONE)
534 printf("Fail to set subnet mask[%s]\n",
535 __test_convert_error_to_string(rv));
538 printf("Input new gateway address (x:skip, 0:clear) :\n");
539 rv = scanf("%15s", ip_addr);
541 switch (ip_addr[0]) {
543 rv = WIFI_ERROR_NONE;
546 rv = wifi_ap_set_gateway_address(ap, address_type, NULL);
549 rv = wifi_ap_set_gateway_address(ap, address_type, ip_addr);
552 if (rv != WIFI_ERROR_NONE)
553 printf("Fail to set gateway address[%s]\n",
554 __test_convert_error_to_string(rv));
566 static bool __test_found_change_proxy_method_callback(wifi_ap_h ap, void *user_data)
568 int rv, address_type;
570 char *ap_name_part = (char*)user_data;
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));
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;
584 printf("Input new method type (1:direct, 2:manual, 3:auto) :\n");
585 rv = scanf("%9d", &method);
591 rv = test_get_user_int("Input Address type to get"
592 "(0:IPV4, 1:IPV6):", &address_type);
594 if (rv == false || (address_type != 0 && address_type != 1)) {
595 printf("Invalid input!!\n");
601 type = WIFI_PROXY_TYPE_DIRECT;
604 type = WIFI_PROXY_TYPE_MANUAL;
607 type = WIFI_PROXY_TYPE_AUTO;
610 printf("Invalid input!\n");
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));
619 printf("Input new proxy address (x:skip, 0:clear) :\n");
620 rv = scanf("%64s", proxy_addr);
623 switch (proxy_addr[0]) {
625 rv = WIFI_ERROR_NONE;
628 rv = wifi_ap_set_proxy_address(ap, address_type, NULL);
631 rv = wifi_ap_set_proxy_address(ap, address_type, proxy_addr);
634 if (rv != WIFI_ERROR_NONE)
635 printf("Fail to set proxy address[%s]\n", __test_convert_error_to_string(rv));
646 static bool __test_found_print_ap_info_callback(wifi_ap_h ap, void *user_data)
648 int rv, address_type = 0;
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;
660 char *ap_name_part = (char*)user_data;
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));
668 printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
669 if (strstr(ap_name, ap_name_part) != NULL) {
672 printf("ESSID : %s\n", ap_name);
674 if (wifi_ap_get_bssid(ap, &str_value) == WIFI_ERROR_NONE) {
675 printf("BSSID : %s\n", str_value);
678 printf("Fail to get BSSID\n");
680 if (wifi_ap_get_rssi(ap, &int_value) == WIFI_ERROR_NONE)
681 printf("RSSI : %d\n", int_value);
683 printf("Fail to get RSSI\n");
685 if (wifi_ap_get_frequency(ap, &int_value) == WIFI_ERROR_NONE)
686 printf("Frequency : %d\n", int_value);
688 printf("Fail to get Frequency\n");
690 if (wifi_ap_get_max_speed(ap, &int_value) == WIFI_ERROR_NONE)
691 printf("Max speed : %d\n", int_value);
693 printf("Fail to get Max speed\n");
695 if (wifi_ap_is_favorite(ap, &bool_value) == WIFI_ERROR_NONE)
696 printf("Favorite : %s\n", bool_value ? "TRUE" : "FALSE");
698 printf("Fail to get Favorite\n");
701 if (wifi_ap_get_connection_state(ap, &conn_state) == WIFI_ERROR_NONE)
702 printf("Connection State : %d\n", conn_state);
704 printf("Fail to get Connection State\n");
706 rv = test_get_user_int("Input Address type to get"
707 "(0:IPV4, 1:IPV6):", &address_type);
709 if (rv == false || (address_type != 0 && address_type != 1)) {
710 printf("Invalid input!!\n");
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);
717 printf("Fail to get IP config type\n");
719 if (wifi_ap_get_ip_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
720 printf("IP : %s\n", str_value);
723 printf("Fail to get IP\n");
725 if (wifi_ap_get_subnet_mask(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
726 printf("Subnet mask : %s\n", str_value);
729 printf("Fail to get Subnet mask\n");
731 if (wifi_ap_get_gateway_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
732 printf("Gateway : %s\n", str_value);
735 printf("Fail to get Gateway\n");
737 if (wifi_ap_get_proxy_type(ap, &proxy_type) == WIFI_ERROR_NONE)
738 printf("Proxy type : %d\n", proxy_type);
740 printf("Fail to get Proxy type\n");
742 if (wifi_ap_get_proxy_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
743 printf("Proxy : %s\n", str_value);
746 printf("Fail to get Proxy\n");
748 if (wifi_ap_get_dns_address(ap, 1, address_type, &str_value) == WIFI_ERROR_NONE) {
749 printf("DNS1 : %s\n", str_value);
752 printf("Fail to get DNS1\n");
754 if (wifi_ap_get_dns_address(ap, 2, address_type, &str_value) == WIFI_ERROR_NONE) {
755 printf("DNS2 : %s\n", str_value);
758 printf("Fail to get DNS2\n");
761 if (wifi_ap_get_security_type(ap, &sec_type) == WIFI_ERROR_NONE)
762 printf("Security type : %d\n", sec_type);
764 printf("Fail to get Security type\n");
766 if (wifi_ap_get_encryption_type(ap, &enc_type) == WIFI_ERROR_NONE)
767 printf("Encryption type : %d\n", enc_type);
769 printf("Fail to get Encryption type\n");
771 if (wifi_ap_is_passphrase_required(ap, &bool_value) == WIFI_ERROR_NONE)
772 printf("Passphrase required : %s\n", bool_value ? "TRUE" : "FALSE");
774 printf("Fail to get Passphrase required\n");
776 if (wifi_ap_is_wps_supported(ap, &bool_value) == WIFI_ERROR_NONE)
777 printf("WPS supported : %s\n", bool_value ? "TRUE" : "FALSE");
779 printf("Fail to get WPS supported\n");
781 if (sec_type != WIFI_SECURITY_TYPE_EAP) {
787 if (wifi_ap_get_eap_type(ap, &eap_type) == WIFI_ERROR_NONE)
788 printf("EAP type : %d\n", eap_type);
790 printf("Fail to get EAP type\n");
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);
795 printf("Fail to get EAP auth type\n");
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");
802 printf("Fail to get EAP passphrase(user name/password)\n");
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);
808 printf("Fail to get EAP ca cert file\n");
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);
814 printf("Fail to get EAP client cert file\n");
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);
820 printf("Fail to get EAP private key file\n");
830 static bool _test_config_list_cb(const wifi_config_h config, void *user_data)
833 wifi_security_type_e security_type;
835 wifi_config_get_name(config, &name);
836 wifi_config_get_security_type(config, &security_type);
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);
855 static bool __test_found_specific_aps_callback(wifi_ap_h ap, void *user_data)
857 printf("Found specific ap Completed\n");
860 char *ap_name = NULL;
861 wifi_security_type_e security_type = WIFI_SECURITY_TYPE_NONE;
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));
868 printf("[AP name] : %s\n", ap_name);
870 rv = wifi_ap_get_security_type(ap, &security_type);
871 if (rv == WIFI_ERROR_NONE)
872 printf("[Security type] : %d\n", security_type);
874 printf("Fail to get Security type\n");
879 switch (security_type) {
880 case WIFI_SECURITY_TYPE_WEP:
881 case WIFI_SECURITY_TYPE_WPA_PSK:
882 case WIFI_SECURITY_TYPE_WPA2_PSK:
884 char passphrase[100];
885 printf("Input passphrase for %s : ", ap_name);
886 rv = scanf("%99s", passphrase);
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));
896 case WIFI_SECURITY_TYPE_EAP:
898 char input_str1[100];
899 printf("Input user name for %s : ", ap_name);
900 rv = scanf("%99s", input_str1);
902 char input_str2[100];
903 printf("Input password for %s : ", ap_name);
904 rv = scanf("%99s", input_str2);
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));
913 char *inputed_name = NULL;
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));
922 printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE");
923 g_free(inputed_name);
926 case WIFI_SECURITY_TYPE_NONE:
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));
935 printf("Success to connection request [%s]\n", ap_name);
941 static void __test_scan_specific_ap_callback(wifi_error_e error_code, void* user_data)
945 printf("Specific scan Completed from scan request, error code : %s\n",
946 __test_convert_error_to_string(error_code));
948 if (error_code != WIFI_ERROR_NONE)
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));
958 int test_wifi_init(void)
960 int rv = wifi_initialize();
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);
968 printf("Wifi init failed [%s]\n", __test_convert_error_to_string(rv));
972 printf("Wifi init succeeded\n");
976 int test_wifi_deinit(void)
980 rv = wifi_deinitialize();
982 if (rv != WIFI_ERROR_NONE) {
983 printf("Wifi deinit failed [%s]\n", __test_convert_error_to_string(rv));
987 printf("Wifi deinit succeeded\n");
991 int test_wifi_activate(void)
995 rv = wifi_activate(__test_activated_callback, NULL);
997 if (rv != WIFI_ERROR_NONE) {
998 printf("Fail to activate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
1002 printf("Success to activate Wi-Fi device\n");
1007 int test_wifi_deactivate(void)
1011 rv = wifi_deactivate(__test_deactivated_callback, NULL);
1013 if (rv != WIFI_ERROR_NONE) {
1014 printf("Fail to deactivate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
1018 printf("Success to deactivate Wi-Fi device\n");
1023 int test_is_activated(void)
1028 rv = wifi_is_activated(&state);
1030 if (rv != WIFI_ERROR_NONE) {
1031 printf("Fail to get Wi-Fi device state [%s]\n", __test_convert_error_to_string(rv));
1035 printf("Success to get Wi-Fi device state : %s\n", (state) ? "TRUE" : "FALSE");
1040 int test_get_connection_state(void)
1043 wifi_connection_state_e connection_state;
1045 rv = wifi_get_connection_state(&connection_state);
1047 if (rv != WIFI_ERROR_NONE) {
1048 printf("Fail to get connection state [%s]\n", __test_convert_error_to_string(rv));
1052 printf("Success to get connection state : ");
1053 switch (connection_state) {
1054 case WIFI_CONNECTION_STATE_ASSOCIATION:
1055 printf("Association\n");
1057 case WIFI_CONNECTION_STATE_CONNECTED:
1058 printf("Connected\n");
1060 case WIFI_CONNECTION_STATE_CONFIGURATION:
1061 printf("Configuration\n");
1063 case WIFI_CONNECTION_STATE_DISCONNECTED:
1064 printf("Disconnected\n");
1067 printf("Unknown\n");
1073 int test_get_mac_address(void)
1076 char *mac_addr = NULL;
1078 rv = wifi_get_mac_address(&mac_addr);
1080 if (rv != WIFI_ERROR_NONE) {
1081 printf("Fail to get MAC address [%s]\n", __test_convert_error_to_string(rv));
1085 printf("MAC address : %s\n", mac_addr);
1091 int test_get_interface_name(void)
1094 char *if_name = NULL;
1096 rv = wifi_get_network_interface_name(&if_name);
1098 if (rv != WIFI_ERROR_NONE) {
1099 printf("Fail to get Interface name [%s]\n", __test_convert_error_to_string(rv));
1103 printf("Interface name : %s\n", if_name);
1109 int test_scan_request(void)
1113 rv = wifi_scan(__test_scan_request_callback, NULL);
1115 if (rv != WIFI_ERROR_NONE) {
1116 printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv));
1120 printf("Scan request succeeded\n");
1125 int test_get_connected_ap(void)
1128 char *ap_name = NULL;
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));
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);
1144 printf("Connected AP : %s\n", ap_name);
1146 wifi_ap_destroy(ap_h);
1151 int test_foreach_found_aps(void)
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));
1161 printf("Get AP list finished\n");
1166 int test_connect_ap(void)
1172 wifi_is_activated(&state);
1176 printf("Input a part of AP name to connect : ");
1177 rv = scanf("%32s", ap_name);
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));
1185 printf("Connection step finished\n");
1189 int test_connect_specific_ap(void)
1194 printf("Input a part of specific AP name to connect : ");
1195 rv = scanf("%32s", ap_name);
1199 rv = wifi_scan_specific_ap(ap_name, __test_scan_specific_ap_callback, NULL);
1201 if (rv != WIFI_ERROR_NONE) {
1202 printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv));
1206 printf("Scan specific AP request succeeded\n");
1210 int test_disconnect_ap(void)
1216 wifi_is_activated(&state);
1220 printf("Input a part of AP name to disconnect : ");
1221 rv = scanf("%32s", ap_name);
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));
1229 printf("Disconnection step finished\n");
1233 int test_connect_wps(void)
1239 wifi_is_activated(&state);
1243 printf("Input a part of AP name to connect by wps : ");
1244 rv = scanf("%32s", ap_name);
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));
1252 printf("Connection step finished\n");
1256 int test_forget_ap(void)
1262 wifi_is_activated(&state);
1266 printf("Input a part of AP name to forget : ");
1267 rv = scanf("%32s", ap_name);
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));
1275 printf("Forget AP finished\n");
1279 int test_connect_eap_ap(void)
1285 wifi_is_activated(&state);
1289 printf("Input a part of AP name to connect : ");
1290 rv = scanf("%32s", ap_name);
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));
1298 printf("Connection step finished\n");
1302 int test_set_ip_method(void)
1308 rv = wifi_is_activated(&state);
1309 if (rv != WIFI_ERROR_NONE || state == false)
1312 printf("Input a part of AP name to change IP method : ");
1313 rv = scanf("%32s", ap_name);
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));
1323 printf("IP method changing finished\n");
1327 int test_set_proxy_method(void)
1333 rv = wifi_is_activated(&state);
1334 if (rv != WIFI_ERROR_NONE || state == false)
1337 printf("Input a part of AP name to change Proxy method : ");
1338 rv = scanf("%32s", ap_name);
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));
1348 printf("Proxy method changing finished\n");
1352 int test_get_ap_info(void)
1358 rv = wifi_is_activated(&state);
1359 if (rv != WIFI_ERROR_NONE || state == false)
1362 printf("Input a part of AP name to get detailed info : ");
1363 rv = scanf("%32s", ap_name);
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));
1373 printf("AP info printing finished\n");
1377 int test_load_configuration(void)
1381 rv = wifi_config_foreach_configuration(_test_config_list_cb, NULL);
1382 if (rv != WIFI_ERROR_NONE)
1388 int test_save_configuration(void)
1391 char name[33] = { 0, };
1392 char passphrase[100] = { 0, };
1394 wifi_config_h config;
1396 printf("Input AP configuration\n");
1398 rv = scanf("%32s", name);
1402 printf("Passphrase : ");
1403 rv = scanf("%99s", passphrase);
1407 printf("Security type(None(0), WEP(1), WPA-PSK(2), EAP(4) : ");
1408 rv = scanf("%d", &type);
1412 rv = wifi_config_create(name, passphrase, type, &config);
1413 if (rv != WIFI_ERROR_NONE)
1416 rv = wifi_config_save_configuration(config);
1417 if (rv != WIFI_ERROR_NONE)
1420 rv = wifi_config_destroy(config);
1421 if (rv != WIFI_ERROR_NONE)
1427 int test_set_configuration_proxy_and_hidden(void)
1430 char name[33] = { 0, };
1431 char passphrase[100] = { 0, };
1433 char proxy[100] = { 0, };
1435 wifi_config_h config;
1437 printf("Input AP configuration\n");
1439 rv = scanf("%32s", name);
1443 printf("Passphrase : ");
1444 rv = scanf("%99s", passphrase);
1448 printf("Security type(None(0), WEP(1), WPA-PSK(2), EAP(4) : ");
1449 rv = scanf("%d", &type);
1453 printf("Proxy(server:port) : ");
1454 rv = scanf("%99s", proxy);
1458 printf("Hidden(1:Hidden) : ");
1459 rv = scanf("%d", &hidden);
1463 rv = wifi_config_create(name, passphrase, type, &config);
1464 if (rv != WIFI_ERROR_NONE)
1467 rv = wifi_config_save_configuration(config);
1468 if (rv != WIFI_ERROR_NONE)
1471 rv = wifi_config_set_proxy_address(config, WIFI_ADDRESS_FAMILY_IPV4, proxy);
1472 if (rv != WIFI_ERROR_NONE)
1476 rv = wifi_config_set_hidden_ap_property(config, TRUE);
1478 rv = wifi_config_set_hidden_ap_property(config, FALSE);
1479 if (rv != WIFI_ERROR_NONE)
1482 rv = wifi_config_destroy(config);
1483 if (rv != WIFI_ERROR_NONE)
1489 int test_set_eap_configuration(void)
1492 char name[33] = { 0, };
1493 char passphrase[100] = { 0, };
1494 int type = WIFI_SECURITY_TYPE_EAP;
1495 wifi_config_h config;
1497 printf("Input EAP configuration\n");
1499 rv = scanf("%32s", name);
1503 printf("Passphrase : ");
1504 rv = scanf("%99s", passphrase);
1508 rv = wifi_config_create(name, passphrase, type, &config);
1509 if (rv != WIFI_ERROR_NONE)
1512 rv = wifi_config_save_configuration(config);
1513 if (rv != WIFI_ERROR_NONE)
1516 rv = wifi_config_set_eap_type(config, WIFI_EAP_TYPE_TLS);
1517 if (rv != WIFI_ERROR_NONE)
1520 rv = wifi_config_set_eap_auth_type(config, WIFI_EAP_AUTH_TYPE_MD5);
1521 if (rv != WIFI_ERROR_NONE)
1524 rv = wifi_config_destroy(config);
1525 if (rv != WIFI_ERROR_NONE)
1531 int test_wifi_tdls_disconnect(void)
1535 char * peer_mac = NULL;
1536 printf("Enter Mac_address: ");
1537 if(scanf(" %ms", &peer_mac) < 1)
1540 if (strlen(peer_mac) > 17)
1542 printf("Wrong Mac_address\n");
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));
1556 int test_wifi_tdls_get_connected_peer(void)
1559 char *mac_addr = NULL;
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));
1566 printf("Peer Mac address is [%s]\n",mac_addr);
1571 int main(int argc, char **argv)
1573 GMainLoop *mainloop;
1575 mainloop = g_main_loop_new(NULL, FALSE);
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);
1580 printf("Test Thread created...\n");
1582 g_main_loop_run(mainloop);
1587 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1592 printf("Event received from stdin\n");
1594 rv = read(0, a, 10);
1596 if (rv <= 0 || a[0] == '0') {
1597 rv = wifi_deinitialize();
1599 if (rv != WIFI_ERROR_NONE)
1600 printf("Fail to deinitialize.\n");
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");
1636 printf("ENTER - Show options menu.......\n");
1641 rv = test_wifi_init();
1644 rv = test_wifi_deinit();
1647 rv = test_wifi_activate();
1650 rv = test_wifi_deactivate();
1653 rv = test_is_activated();
1656 rv = test_get_connection_state();
1659 rv = test_get_mac_address();
1662 rv = test_get_interface_name();
1665 rv = test_scan_request();
1668 rv = test_get_connected_ap();
1671 rv = test_foreach_found_aps();
1674 rv = test_connect_ap();
1677 rv = test_disconnect_ap();
1680 rv = test_connect_wps();
1683 rv = test_forget_ap();
1686 rv = test_connect_eap_ap();
1689 rv = test_set_ip_method();
1692 rv = test_set_proxy_method();
1695 rv = test_get_ap_info();
1698 rv = test_connect_specific_ap();
1701 rv = test_load_configuration();
1704 rv = test_save_configuration();
1707 rv = test_set_configuration_proxy_and_hidden();
1710 rv = test_set_eap_configuration();
1713 rv = test_wifi_tdls_disconnect();
1716 rv = test_wifi_tdls_get_connected_peer();
1724 printf("Operation succeeded!\n");
1726 printf("Operation failed!\n");