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>
33 #define LOG_RED "\033[0;31m"
34 #define LOG_GREEN "\033[0;32m"
35 #define LOG_BROWN "\033[0;33m"
36 #define LOG_BLUE "\033[0;34m"
37 #define LOG_END "\033[0;m"
39 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
41 static const char *__test_convert_error_to_string(wifi_error_e err_type)
46 case WIFI_ERROR_INVALID_PARAMETER:
47 return "INVALID_PARAMETER";
48 case WIFI_ERROR_OUT_OF_MEMORY:
49 return "OUT_OF_MEMORY";
50 case WIFI_ERROR_INVALID_OPERATION:
51 return "INVALID_OPERATION";
52 case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
53 return "ADDRESS_FAMILY_NOT_SUPPORTED";
54 case WIFI_ERROR_OPERATION_FAILED:
55 return "OPERATION_FAILED";
56 case WIFI_ERROR_NO_CONNECTION:
57 return "NO_CONNECTION";
58 case WIFI_ERROR_NOW_IN_PROGRESS:
59 return "NOW_IN_PROGRESS";
60 case WIFI_ERROR_ALREADY_EXISTS:
61 return "ALREADY_EXISTS";
62 case WIFI_ERROR_OPERATION_ABORTED:
63 return "OPERATION_ABORTED";
64 case WIFI_ERROR_DHCP_FAILED:
66 case WIFI_ERROR_INVALID_KEY:
68 case WIFI_ERROR_NO_REPLY:
70 case WIFI_ERROR_SECURITY_RESTRICTED:
71 return "SECURITY_RESTRICTED";
72 case WIFI_ERROR_PERMISSION_DENIED:
73 return "PERMISSION_DENIED";
74 case WIFI_ERROR_NOT_SUPPORTED:
75 return "NOT_SUPPORTED";
81 static void __test_device_state_callback(wifi_device_state_e state, void* user_data)
83 printf("Device state changed callback");
85 if (state == WIFI_DEVICE_STATE_ACTIVATED)
86 printf(", state : Activated\n");
88 printf(", state : Deactivated\n");
91 static void __test_bg_scan_completed_callback(wifi_error_e error_code, void* user_data)
93 printf("Background Scan Completed, error code : %s\n",
94 __test_convert_error_to_string(error_code));
97 static void __test_scan_request_callback(wifi_error_e error_code, void* user_data)
99 if (user_data != NULL)
100 printf("user_data : %s\n", (char *)user_data);
102 printf("Scan Completed from scan request, error code : %s\n",
103 __test_convert_error_to_string(error_code));
106 static void __test_connection_state_callback(wifi_connection_state_e state, wifi_ap_h ap, void* user_data)
109 char *ap_name = NULL;
111 printf("Connection state changed callback");
114 case WIFI_CONNECTION_STATE_CONNECTED:
115 printf(", state : Connected");
117 case WIFI_CONNECTION_STATE_ASSOCIATION:
118 printf(", state : Association");
120 case WIFI_CONNECTION_STATE_CONFIGURATION:
121 printf(", state : Configuration");
123 case WIFI_CONNECTION_STATE_DISCONNECTED:
124 printf(", state : Disconnected");
127 printf(", state : Unknown");
130 rv = wifi_ap_get_essid(ap, &ap_name);
131 if (rv != WIFI_ERROR_NONE)
132 printf(", Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
134 printf(", AP name : %s\n", ap_name);
139 static void __test_activated_callback(wifi_error_e result, void* user_data)
141 if (result == WIFI_ERROR_NONE)
142 printf("Wi-Fi Activation Succeeded\n");
144 printf("Wi-Fi Activation Failed! error : %s\n", __test_convert_error_to_string(result));
147 static void __test_deactivated_callback(wifi_error_e result, void* user_data)
149 if (result == WIFI_ERROR_NONE)
150 printf("Wi-Fi Deactivation Succeeded\n");
152 printf("Wi-Fi Deactivation Failed! error : %s\n", __test_convert_error_to_string(result));
155 static void __test_connected_callback(wifi_error_e result, void* user_data)
157 if (result == WIFI_ERROR_NONE)
158 printf("Wi-Fi Connection Succeeded\n");
160 printf("Wi-Fi Connection Failed! error : %s\n", __test_convert_error_to_string(result));
163 static void __test_disconnected_callback(wifi_error_e result, void* user_data)
165 if (result == WIFI_ERROR_NONE)
166 printf("Wi-Fi Disconnection Succeeded\n");
168 printf("Wi-Fi Disconnection Failed! error : %s\n", __test_convert_error_to_string(result));
171 static void __test_rssi_level_callback(wifi_rssi_level_e rssi_level, void* user_data)
173 printf("RSSI level changed callback, level = %d\n", rssi_level);
176 static const char* __test_print_state(wifi_connection_state_e state)
179 case WIFI_CONNECTION_STATE_FAILURE:
181 case WIFI_CONNECTION_STATE_DISCONNECTED:
182 return "Disconnected";
183 case WIFI_CONNECTION_STATE_ASSOCIATION:
184 return "Association";
185 case WIFI_CONNECTION_STATE_CONNECTED:
187 case WIFI_CONNECTION_STATE_CONFIGURATION:
188 return "Configuration";
194 static bool __test_found_ap_callback(wifi_ap_h ap, void *user_data)
197 char *ap_name = NULL;
198 wifi_connection_state_e state;
200 rv = wifi_ap_get_essid(ap, &ap_name);
201 if (rv != WIFI_ERROR_NONE) {
202 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
206 rv = wifi_ap_get_connection_state(ap, &state);
207 if (rv != WIFI_ERROR_NONE) {
208 printf("Fail to get State [%s]\n", __test_convert_error_to_string(rv));
213 printf("AP name : %s, state : %s\n", ap_name, __test_print_state(state));
219 static bool __test_found_connect_ap_callback(wifi_ap_h ap, void *user_data)
222 char *ap_name = NULL;
223 char *ap_name_part = (char*)user_data;
225 rv = wifi_ap_get_essid(ap, &ap_name);
226 if (rv != WIFI_ERROR_NONE) {
227 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
231 if (strstr(ap_name, ap_name_part) != NULL) {
232 bool required = false;
234 if (wifi_ap_is_passphrase_required(ap, &required) == WIFI_ERROR_NONE)
235 printf("Passphrase required : %s\n", required ? "TRUE" : "FALSE");
237 printf("Fail to get Passphrase required\n");
240 char passphrase[100];
241 printf("Input passphrase for %s : ", ap_name);
242 rv = scanf("%99s", passphrase);
244 rv = wifi_ap_set_passphrase(ap, passphrase);
245 if (rv != WIFI_ERROR_NONE) {
246 printf("Fail to set passphrase : %s\n", __test_convert_error_to_string(rv));
252 rv = wifi_connect(ap, __test_connected_callback, NULL);
253 if (rv != WIFI_ERROR_NONE)
254 printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
256 printf("Success to connection request [%s]\n", ap_name);
266 static bool __test_found_connect_wps_callback(wifi_ap_h ap, void *user_data)
269 char *ap_name = NULL;
270 char *ap_name_part = (char*)user_data;
272 rv = wifi_ap_get_essid(ap, &ap_name);
273 if (rv != WIFI_ERROR_NONE) {
274 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
278 if (strstr(ap_name, ap_name_part) != NULL) {
282 printf("%s - Input WPS method (1:PBC, 2:PIN) :\n", ap_name);
283 rv = scanf("%9d", &user_sel);
287 rv = wifi_connect_by_wps_pbc(ap, __test_connected_callback, NULL);
290 printf("Input PIN code :\n");
291 rv = scanf("%31s", pin);
292 rv = wifi_connect_by_wps_pin(ap, pin, __test_connected_callback, NULL);
295 printf("Invalid input!\n");
300 if (rv != WIFI_ERROR_NONE)
301 printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
303 printf("Success to connection request [%s]\n", ap_name);
313 static bool __test_found_disconnect_ap_callback(wifi_ap_h ap, void *user_data)
316 char *ap_name = NULL;
317 char *ap_name_part = (char*)user_data;
319 rv = wifi_ap_get_essid(ap, &ap_name);
320 if (rv != WIFI_ERROR_NONE) {
321 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
325 if (strstr(ap_name, ap_name_part) != NULL) {
326 rv = wifi_disconnect(ap, __test_disconnected_callback, NULL);
327 if (rv != WIFI_ERROR_NONE)
328 printf("Fail to disconnection reqeust %s : [%s]\n", ap_name, __test_convert_error_to_string(rv));
330 printf("Success to disconnection request %s\n", ap_name);
340 static bool __test_found_forget_ap_callback(wifi_ap_h ap, void *user_data)
343 char *ap_name = NULL;
344 char *ap_name_part = (char*)user_data;
346 rv = wifi_ap_get_essid(ap, &ap_name);
347 if (rv != WIFI_ERROR_NONE) {
348 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
352 if (strstr(ap_name, ap_name_part) != NULL) {
353 rv = wifi_forget_ap(ap);
354 if (rv != WIFI_ERROR_NONE)
355 printf("Fail to forget [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
357 printf("Success to forget [%s]\n", ap_name);
367 static bool __test_found_eap_ap_callback(wifi_ap_h ap, void *user_data)
370 char *ap_name = NULL;
371 char *ap_name_part = (char*)user_data;
373 rv = wifi_ap_get_essid(ap, &ap_name);
374 if (rv != WIFI_ERROR_NONE) {
375 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
379 if (strstr(ap_name, ap_name_part) != NULL) {
380 wifi_security_type_e type;
382 if (wifi_ap_get_security_type(ap, &type) == WIFI_ERROR_NONE)
383 printf("Security type : %d\n", type);
385 printf("Fail to get Security type\n");
387 if (type != WIFI_SECURITY_TYPE_EAP) {
392 char input_str1[100];
393 printf("Input user name for %s : ", ap_name);
394 rv = scanf("%99s", input_str1);
396 char input_str2[100];
397 printf("Input password for %s : ", ap_name);
398 rv = scanf("%99s", input_str2);
400 rv = wifi_ap_set_eap_passphrase(ap, input_str1, input_str2);
401 if (rv != WIFI_ERROR_NONE) {
402 printf("Fail to set eap passphrase : %s\n", __test_convert_error_to_string(rv));
407 char *inputed_name = NULL;
409 rv = wifi_ap_get_eap_passphrase(ap, &inputed_name, &is_pass_set);
410 if (rv != WIFI_ERROR_NONE) {
411 printf("Fail to get eap passphrase : %s\n", __test_convert_error_to_string(rv));
416 printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE");
418 rv = wifi_connect(ap, __test_connected_callback, NULL);
419 if (rv != WIFI_ERROR_NONE)
420 printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
422 printf("Success to connection request [%s]\n", ap_name);
425 g_free(inputed_name);
433 static bool test_get_user_int(const char *msg, int *num)
435 if (msg == NULL || num == NULL)
441 rv = read(0, buf, 32);
443 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
450 static bool __test_found_change_ip_method_callback(wifi_ap_h ap, void *user_data)
454 char *ap_name_part = (char*)user_data;
456 rv = wifi_ap_get_essid(ap, &ap_name);
457 if (rv != WIFI_ERROR_NONE) {
458 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
462 if (strstr(ap_name, ap_name_part) != NULL) {
463 wifi_ip_config_type_e type;
467 printf("Input new method type (1:dhcp, 2:manual, 3:auto) :\n");
468 rv = scanf("%9d", &method);
474 rv = test_get_user_int("Input Address type to get"
475 "(0:IPV4, 1:IPV6):", &address_type);
477 if (rv == false || (address_type != 0 && address_type != 1)) {
478 printf("Invalid input!!\n");
484 type = WIFI_IP_CONFIG_TYPE_DYNAMIC;
487 type = WIFI_IP_CONFIG_TYPE_STATIC;
490 type = WIFI_IP_CONFIG_TYPE_AUTO;
493 printf("Invalid input!\n");
498 rv = wifi_ap_set_ip_config_type(ap, address_type, type);
499 if (rv != WIFI_ERROR_NONE)
500 printf("Fail to set ip method type[%s]\n", __test_convert_error_to_string(rv));
502 if (type == WIFI_IP_CONFIG_TYPE_STATIC) {
505 printf("Input new ip address (x:skip, 0:clear) :\n");
506 rv = scanf("%15s", ip_addr);
508 switch (ip_addr[0]) {
510 rv = WIFI_ERROR_NONE;
513 rv = wifi_ap_set_ip_address(ap, address_type, NULL);
516 rv = wifi_ap_set_ip_address(ap, address_type, ip_addr);
519 if (rv != WIFI_ERROR_NONE)
520 printf("Fail to set ip address[%s]\n",
521 __test_convert_error_to_string(rv));
524 printf("Input new subnet mask (x:skip, 0:clear) :\n");
525 rv = scanf("%15s", ip_addr);
527 switch (ip_addr[0]) {
529 rv = WIFI_ERROR_NONE;
532 rv = wifi_ap_set_subnet_mask(ap, address_type, NULL);
535 rv = wifi_ap_set_subnet_mask(ap, address_type, ip_addr);
538 if (rv != WIFI_ERROR_NONE)
539 printf("Fail to set subnet mask[%s]\n",
540 __test_convert_error_to_string(rv));
543 printf("Input new gateway address (x:skip, 0:clear) :\n");
544 rv = scanf("%15s", ip_addr);
546 switch (ip_addr[0]) {
548 rv = WIFI_ERROR_NONE;
551 rv = wifi_ap_set_gateway_address(ap, address_type, NULL);
554 rv = wifi_ap_set_gateway_address(ap, address_type, ip_addr);
557 if (rv != WIFI_ERROR_NONE)
558 printf("Fail to set gateway address[%s]\n",
559 __test_convert_error_to_string(rv));
571 static bool __test_found_change_proxy_method_callback(wifi_ap_h ap, void *user_data)
573 int rv, address_type;
575 char *ap_name_part = (char*)user_data;
577 rv = wifi_ap_get_essid(ap, &ap_name);
578 if (rv != WIFI_ERROR_NONE) {
579 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
583 printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
584 if (strstr(ap_name, ap_name_part) != NULL) {
585 wifi_proxy_type_e type;
589 printf("Input new method type (1:direct, 2:manual, 3:auto) :\n");
590 rv = scanf("%9d", &method);
596 rv = test_get_user_int("Input Address type to get"
597 "(0:IPV4, 1:IPV6):", &address_type);
599 if (rv == false || (address_type != 0 && address_type != 1)) {
600 printf("Invalid input!!\n");
606 type = WIFI_PROXY_TYPE_DIRECT;
609 type = WIFI_PROXY_TYPE_MANUAL;
612 type = WIFI_PROXY_TYPE_AUTO;
615 printf("Invalid input!\n");
620 rv = wifi_ap_set_proxy_type(ap, type);
621 if (rv != WIFI_ERROR_NONE)
622 printf("Fail to set proxy method type[%s]\n", __test_convert_error_to_string(rv));
624 printf("Input new proxy address (x:skip, 0:clear) :\n");
625 rv = scanf("%64s", proxy_addr);
628 switch (proxy_addr[0]) {
630 rv = WIFI_ERROR_NONE;
633 rv = wifi_ap_set_proxy_address(ap, address_type, NULL);
636 rv = wifi_ap_set_proxy_address(ap, address_type, proxy_addr);
639 if (rv != WIFI_ERROR_NONE)
640 printf("Fail to set proxy address[%s]\n", __test_convert_error_to_string(rv));
651 static bool __test_found_print_ap_info_callback(wifi_ap_h ap, void *user_data)
653 int rv, address_type = 0;
657 wifi_connection_state_e conn_state;
658 wifi_ip_config_type_e ip_type;
659 wifi_proxy_type_e proxy_type;
660 wifi_security_type_e sec_type;
661 wifi_encryption_type_e enc_type;
662 wifi_eap_type_e eap_type;
663 wifi_eap_auth_type_e eap_auth_type;
665 char *ap_name_part = (char*)user_data;
667 rv = wifi_ap_get_essid(ap, &ap_name);
668 if (rv != WIFI_ERROR_NONE) {
669 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
673 printf("ap_name %s, user input name %s\n", ap_name, ap_name_part);
674 if (strstr(ap_name, ap_name_part) != NULL) {
677 printf("ESSID : %s\n", ap_name);
679 if (wifi_ap_get_bssid(ap, &str_value) == WIFI_ERROR_NONE) {
680 printf("BSSID : %s\n", str_value);
683 printf("Fail to get BSSID\n");
685 if (wifi_ap_get_rssi(ap, &int_value) == WIFI_ERROR_NONE)
686 printf("RSSI : %d\n", int_value);
688 printf("Fail to get RSSI\n");
690 if (wifi_ap_get_frequency(ap, &int_value) == WIFI_ERROR_NONE)
691 printf("Frequency : %d\n", int_value);
693 printf("Fail to get Frequency\n");
695 if (wifi_ap_get_max_speed(ap, &int_value) == WIFI_ERROR_NONE)
696 printf("Max speed : %d\n", int_value);
698 printf("Fail to get Max speed\n");
700 if (wifi_ap_is_favorite(ap, &bool_value) == WIFI_ERROR_NONE)
701 printf("Favorite : %s\n", bool_value ? "TRUE" : "FALSE");
703 printf("Fail to get Favorite\n");
706 if (wifi_ap_get_connection_state(ap, &conn_state) == WIFI_ERROR_NONE)
707 printf("Connection State : %d\n", conn_state);
709 printf("Fail to get Connection State\n");
711 rv = test_get_user_int("Input Address type to get"
712 "(0:IPV4, 1:IPV6):", &address_type);
714 if (rv == false || (address_type != 0 && address_type != 1)) {
715 printf("Invalid input!!\n");
719 if (wifi_ap_get_ip_config_type(ap, address_type, &ip_type) == WIFI_ERROR_NONE)
720 printf("IP config type : %d\n", ip_type);
722 printf("Fail to get IP config type\n");
724 if (wifi_ap_get_ip_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
725 printf("IP : %s\n", str_value);
728 printf("Fail to get IP\n");
730 if (wifi_ap_get_subnet_mask(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
731 printf("Subnet mask : %s\n", str_value);
734 printf("Fail to get Subnet mask\n");
736 if (wifi_ap_get_gateway_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
737 printf("Gateway : %s\n", str_value);
740 printf("Fail to get Gateway\n");
742 if (wifi_ap_get_proxy_type(ap, &proxy_type) == WIFI_ERROR_NONE)
743 printf("Proxy type : %d\n", proxy_type);
745 printf("Fail to get Proxy type\n");
747 if (wifi_ap_get_proxy_address(ap, address_type, &str_value) == WIFI_ERROR_NONE) {
748 printf("Proxy : %s\n", str_value);
751 printf("Fail to get Proxy\n");
753 if (wifi_ap_get_dns_address(ap, 1, address_type, &str_value) == WIFI_ERROR_NONE) {
754 printf("DNS1 : %s\n", str_value);
757 printf("Fail to get DNS1\n");
759 if (wifi_ap_get_dns_address(ap, 2, address_type, &str_value) == WIFI_ERROR_NONE) {
760 printf("DNS2 : %s\n", str_value);
763 printf("Fail to get DNS2\n");
766 if (wifi_ap_get_security_type(ap, &sec_type) == WIFI_ERROR_NONE)
767 printf("Security type : %d\n", sec_type);
769 printf("Fail to get Security type\n");
771 if (wifi_ap_get_encryption_type(ap, &enc_type) == WIFI_ERROR_NONE)
772 printf("Encryption type : %d\n", enc_type);
774 printf("Fail to get Encryption type\n");
776 if (wifi_ap_is_passphrase_required(ap, &bool_value) == WIFI_ERROR_NONE)
777 printf("Passphrase required : %s\n", bool_value ? "TRUE" : "FALSE");
779 printf("Fail to get Passphrase required\n");
781 if (wifi_ap_is_wps_supported(ap, &bool_value) == WIFI_ERROR_NONE)
782 printf("WPS supported : %s\n", bool_value ? "TRUE" : "FALSE");
784 printf("Fail to get WPS supported\n");
786 if (sec_type != WIFI_SECURITY_TYPE_EAP) {
792 if (wifi_ap_get_eap_type(ap, &eap_type) == WIFI_ERROR_NONE)
793 printf("EAP type : %d\n", eap_type);
795 printf("Fail to get EAP type\n");
797 if (wifi_ap_get_eap_auth_type(ap, &eap_auth_type) == WIFI_ERROR_NONE)
798 printf("EAP auth type : %d\n", eap_auth_type);
800 printf("Fail to get EAP auth type\n");
802 if (wifi_ap_get_eap_passphrase(ap, &str_value, &bool_value) == WIFI_ERROR_NONE) {
803 printf("EAP user name : %s\n", str_value);
804 printf("EAP is password setted : %s\n", bool_value ? "TRUE" : "FALSE");
807 printf("Fail to get EAP passphrase(user name/password)\n");
809 if (wifi_ap_get_eap_ca_cert_file(ap, &str_value) == WIFI_ERROR_NONE) {
810 printf("EAP ca cert file : %s\n", str_value);
813 printf("Fail to get EAP ca cert file\n");
815 if (wifi_ap_get_eap_client_cert_file(ap, &str_value) == WIFI_ERROR_NONE) {
816 printf("EAP client cert file : %s\n", str_value);
819 printf("Fail to get EAP client cert file\n");
821 if (wifi_ap_get_eap_private_key_file(ap, &str_value) == WIFI_ERROR_NONE) {
822 printf("EAP private key file : %s\n", str_value);
825 printf("Fail to get EAP private key file\n");
835 static bool _test_config_list_cb(const wifi_config_h config, void *user_data)
838 wifi_security_type_e security_type;
840 wifi_config_get_name(config, &name);
841 wifi_config_get_security_type(config, &security_type);
843 printf("Name[%s] ", name);
844 printf("Security type[%d] ", security_type);
845 if (security_type == WIFI_SECURITY_TYPE_EAP) {
846 wifi_eap_type_e eap_type;
847 wifi_eap_auth_type_e eap_auth_type;
848 wifi_config_get_eap_type(config, &eap_type);
849 printf("Eap type[%d] ", eap_type);
850 wifi_config_get_eap_auth_type(config, &eap_auth_type);
851 printf("Eap auth type[%d]", eap_auth_type);
860 static bool __test_found_specific_aps_callback(wifi_ap_h ap, void *user_data)
862 printf("Found specific ap Completed\n");
865 char *ap_name = NULL;
866 wifi_security_type_e security_type = WIFI_SECURITY_TYPE_NONE;
868 rv = wifi_ap_get_essid(ap, &ap_name);
869 if (rv != WIFI_ERROR_NONE) {
870 printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv));
873 printf("[AP name] : %s\n", ap_name);
875 rv = wifi_ap_get_security_type(ap, &security_type);
876 if (rv == WIFI_ERROR_NONE)
877 printf("[Security type] : %d\n", security_type);
879 printf("Fail to get Security type\n");
884 switch (security_type) {
885 case WIFI_SECURITY_TYPE_WEP:
886 case WIFI_SECURITY_TYPE_WPA_PSK:
887 case WIFI_SECURITY_TYPE_WPA2_PSK:
889 char passphrase[100];
890 printf("Input passphrase for %s : ", ap_name);
891 rv = scanf("%99s", passphrase);
893 rv = wifi_ap_set_passphrase(ap, passphrase);
894 if (rv != WIFI_ERROR_NONE) {
895 printf("Fail to set passphrase : %s\n", __test_convert_error_to_string(rv));
901 case WIFI_SECURITY_TYPE_EAP:
903 char input_str1[100];
904 printf("Input user name for %s : ", ap_name);
905 rv = scanf("%99s", input_str1);
907 char input_str2[100];
908 printf("Input password for %s : ", ap_name);
909 rv = scanf("%99s", input_str2);
911 rv = wifi_ap_set_eap_passphrase(ap, input_str1, input_str2);
912 if (rv != WIFI_ERROR_NONE) {
913 printf("Fail to set eap passphrase : %s\n", __test_convert_error_to_string(rv));
918 char *inputed_name = NULL;
920 rv = wifi_ap_get_eap_passphrase(ap, &inputed_name, &is_pass_set);
921 if (rv != WIFI_ERROR_NONE) {
922 printf("Fail to get eap passphrase : %s\n", __test_convert_error_to_string(rv));
927 printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE");
928 g_free(inputed_name);
931 case WIFI_SECURITY_TYPE_NONE:
936 rv = wifi_connect(ap, __test_connected_callback, NULL);
937 if (rv != WIFI_ERROR_NONE)
938 printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv));
940 printf("Success to connection request [%s]\n", ap_name);
946 static void __test_scan_specific_ap_callback(wifi_error_e error_code, void* user_data)
950 printf("Specific scan Completed from scan request, error code : %s\n",
951 __test_convert_error_to_string(error_code));
953 if (error_code != WIFI_ERROR_NONE)
956 rv = wifi_foreach_found_specific_aps(__test_found_specific_aps_callback, user_data);
957 if (rv != WIFI_ERROR_NONE) {
958 printf("Fail to get specific AP(can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
963 int test_wifi_init(void)
965 int rv = wifi_initialize();
967 if (rv == WIFI_ERROR_NONE) {
968 wifi_set_device_state_changed_cb(__test_device_state_callback, NULL);
969 wifi_set_background_scan_cb(__test_bg_scan_completed_callback, NULL);
970 wifi_set_connection_state_changed_cb(__test_connection_state_callback, NULL);
971 wifi_set_rssi_level_changed_cb(__test_rssi_level_callback, NULL);
973 printf("Wifi init failed [%s]\n", __test_convert_error_to_string(rv));
977 printf("Wifi init succeeded\n");
981 int test_wifi_deinit(void)
985 rv = wifi_deinitialize();
987 if (rv != WIFI_ERROR_NONE) {
988 printf("Wifi deinit failed [%s]\n", __test_convert_error_to_string(rv));
992 printf("Wifi deinit succeeded\n");
996 int test_wifi_activate(void)
1000 rv = wifi_activate(__test_activated_callback, NULL);
1002 if (rv != WIFI_ERROR_NONE) {
1003 printf("Fail to activate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
1007 printf("Success to activate Wi-Fi device\n");
1012 int test_wifi_deactivate(void)
1016 rv = wifi_deactivate(__test_deactivated_callback, NULL);
1018 if (rv != WIFI_ERROR_NONE) {
1019 printf("Fail to deactivate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv));
1023 printf("Success to deactivate Wi-Fi device\n");
1028 int test_is_activated(void)
1033 rv = wifi_is_activated(&state);
1035 if (rv != WIFI_ERROR_NONE) {
1036 printf("Fail to get Wi-Fi device state [%s]\n", __test_convert_error_to_string(rv));
1040 printf("Success to get Wi-Fi device state : %s\n", (state) ? "TRUE" : "FALSE");
1045 int test_get_connection_state(void)
1048 wifi_connection_state_e connection_state;
1050 rv = wifi_get_connection_state(&connection_state);
1052 if (rv != WIFI_ERROR_NONE) {
1053 printf("Fail to get connection state [%s]\n", __test_convert_error_to_string(rv));
1057 printf("Success to get connection state : ");
1058 switch (connection_state) {
1059 case WIFI_CONNECTION_STATE_ASSOCIATION:
1060 printf("Association\n");
1062 case WIFI_CONNECTION_STATE_CONNECTED:
1063 printf("Connected\n");
1065 case WIFI_CONNECTION_STATE_CONFIGURATION:
1066 printf("Configuration\n");
1068 case WIFI_CONNECTION_STATE_DISCONNECTED:
1069 printf("Disconnected\n");
1072 printf("Unknown\n");
1078 int test_get_mac_address(void)
1081 char *mac_addr = NULL;
1083 rv = wifi_get_mac_address(&mac_addr);
1085 if (rv != WIFI_ERROR_NONE) {
1086 printf("Fail to get MAC address [%s]\n", __test_convert_error_to_string(rv));
1090 printf("MAC address : %s\n", mac_addr);
1096 int test_get_interface_name(void)
1099 char *if_name = NULL;
1101 rv = wifi_get_network_interface_name(&if_name);
1103 if (rv != WIFI_ERROR_NONE) {
1104 printf("Fail to get Interface name [%s]\n", __test_convert_error_to_string(rv));
1108 printf("Interface name : %s\n", if_name);
1114 int test_scan_request(void)
1118 rv = wifi_scan(__test_scan_request_callback, NULL);
1120 if (rv != WIFI_ERROR_NONE) {
1121 printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv));
1125 printf("Scan request succeeded\n");
1130 int test_get_connected_ap(void)
1133 char *ap_name = NULL;
1136 rv = wifi_get_connected_ap(&ap_h);
1137 if (rv != WIFI_ERROR_NONE) {
1138 printf("Fail to get connected AP [%s]\n", __test_convert_error_to_string(rv));
1142 rv = wifi_ap_get_essid(ap_h, &ap_name);
1143 if (rv != WIFI_ERROR_NONE) {
1144 printf("Fail to get essid [%s]\n", __test_convert_error_to_string(rv));
1145 wifi_ap_destroy(ap_h);
1149 printf("Connected AP : %s\n", ap_name);
1151 wifi_ap_destroy(ap_h);
1156 int test_foreach_found_aps(void)
1160 rv = wifi_foreach_found_aps(__test_found_ap_callback, NULL);
1161 if (rv != WIFI_ERROR_NONE) {
1162 printf("Fail to get AP list [%s]\n", __test_convert_error_to_string(rv));
1166 printf("Get AP list finished\n");
1171 int test_connect_ap(void)
1177 wifi_is_activated(&state);
1181 printf("Input a part of AP name to connect : ");
1182 rv = scanf("%32s", ap_name);
1184 rv = wifi_foreach_found_aps(__test_found_connect_ap_callback, ap_name);
1185 if (rv != WIFI_ERROR_NONE) {
1186 printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1190 printf("Connection step finished\n");
1194 int test_connect_specific_ap(void)
1199 printf("Input a part of specific AP name to connect : ");
1200 rv = scanf("%32s", ap_name);
1204 rv = wifi_scan_specific_ap(ap_name, __test_scan_specific_ap_callback, NULL);
1206 if (rv != WIFI_ERROR_NONE) {
1207 printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv));
1211 printf("Scan specific AP request succeeded\n");
1215 int test_disconnect_ap(void)
1221 wifi_is_activated(&state);
1225 printf("Input a part of AP name to disconnect : ");
1226 rv = scanf("%32s", ap_name);
1228 rv = wifi_foreach_found_aps(__test_found_disconnect_ap_callback, ap_name);
1229 if (rv != WIFI_ERROR_NONE) {
1230 printf("Fail to disconnect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1234 printf("Disconnection step finished\n");
1238 int test_connect_wps(void)
1244 wifi_is_activated(&state);
1248 printf("Input a part of AP name to connect by wps : ");
1249 rv = scanf("%32s", ap_name);
1251 rv = wifi_foreach_found_aps(__test_found_connect_wps_callback, ap_name);
1252 if (rv != WIFI_ERROR_NONE) {
1253 printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1257 printf("Connection step finished\n");
1261 int test_forget_ap(void)
1267 wifi_is_activated(&state);
1271 printf("Input a part of AP name to forget : ");
1272 rv = scanf("%32s", ap_name);
1274 rv = wifi_foreach_found_aps(__test_found_forget_ap_callback, ap_name);
1275 if (rv != WIFI_ERROR_NONE) {
1276 printf("Fail to forget (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1280 printf("Forget AP finished\n");
1284 int test_connect_eap_ap(void)
1290 wifi_is_activated(&state);
1294 printf("Input a part of AP name to connect : ");
1295 rv = scanf("%32s", ap_name);
1297 rv = wifi_foreach_found_aps(__test_found_eap_ap_callback, ap_name);
1298 if (rv != WIFI_ERROR_NONE) {
1299 printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1303 printf("Connection step finished\n");
1307 int test_set_ip_method(void)
1313 rv = wifi_is_activated(&state);
1314 if (rv != WIFI_ERROR_NONE || state == false)
1317 printf("Input a part of AP name to change IP method : ");
1318 rv = scanf("%32s", ap_name);
1322 rv = wifi_foreach_found_aps(__test_found_change_ip_method_callback, ap_name);
1323 if (rv != WIFI_ERROR_NONE) {
1324 printf("Fail to change (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1328 printf("IP method changing finished\n");
1332 int test_set_proxy_method(void)
1338 rv = wifi_is_activated(&state);
1339 if (rv != WIFI_ERROR_NONE || state == false)
1342 printf("Input a part of AP name to change Proxy method : ");
1343 rv = scanf("%32s", ap_name);
1347 rv = wifi_foreach_found_aps(__test_found_change_proxy_method_callback, ap_name);
1348 if (rv != WIFI_ERROR_NONE) {
1349 printf("Fail to change (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1353 printf("Proxy method changing finished\n");
1357 int test_get_ap_info(void)
1363 rv = wifi_is_activated(&state);
1364 if (rv != WIFI_ERROR_NONE || state == false)
1367 printf("Input a part of AP name to get detailed info : ");
1368 rv = scanf("%32s", ap_name);
1372 rv = wifi_foreach_found_aps(__test_found_print_ap_info_callback, ap_name);
1373 if (rv != WIFI_ERROR_NONE) {
1374 printf("Fail to get AP info (can't get AP list) [%s]\n", __test_convert_error_to_string(rv));
1378 printf("AP info printing finished\n");
1382 int test_load_configuration(void)
1386 rv = wifi_config_foreach_configuration(_test_config_list_cb, NULL);
1387 if (rv != WIFI_ERROR_NONE)
1393 int test_save_configuration(void)
1396 char name[33] = { 0, };
1397 char passphrase[100] = { 0, };
1399 wifi_config_h config;
1401 printf("Input AP configuration\n");
1403 rv = scanf("%32s", name);
1407 printf("Passphrase : ");
1408 rv = scanf("%99s", passphrase);
1412 printf("Security type(None(0), WEP(1), WPA-PSK(2), EAP(4) : ");
1413 rv = scanf("%d", &type);
1417 rv = wifi_config_create(name, passphrase, type, &config);
1418 if (rv != WIFI_ERROR_NONE)
1421 rv = wifi_config_save_configuration(config);
1422 if (rv != WIFI_ERROR_NONE)
1425 rv = wifi_config_destroy(config);
1426 if (rv != WIFI_ERROR_NONE)
1432 int test_set_configuration_proxy_and_hidden(void)
1435 char name[33] = { 0, };
1436 char passphrase[100] = { 0, };
1438 char proxy[100] = { 0, };
1440 wifi_config_h config;
1442 printf("Input AP configuration\n");
1444 rv = scanf("%32s", name);
1448 printf("Passphrase : ");
1449 rv = scanf("%99s", passphrase);
1453 printf("Security type(None(0), WEP(1), WPA-PSK(2), EAP(4) : ");
1454 rv = scanf("%d", &type);
1458 printf("Proxy(server:port) : ");
1459 rv = scanf("%99s", proxy);
1463 printf("Hidden(1:Hidden) : ");
1464 rv = scanf("%d", &hidden);
1468 rv = wifi_config_create(name, passphrase, type, &config);
1469 if (rv != WIFI_ERROR_NONE)
1472 rv = wifi_config_save_configuration(config);
1473 if (rv != WIFI_ERROR_NONE)
1476 rv = wifi_config_set_proxy_address(config, WIFI_ADDRESS_FAMILY_IPV4, proxy);
1477 if (rv != WIFI_ERROR_NONE)
1481 rv = wifi_config_set_hidden_ap_property(config, TRUE);
1483 rv = wifi_config_set_hidden_ap_property(config, FALSE);
1484 if (rv != WIFI_ERROR_NONE)
1487 rv = wifi_config_destroy(config);
1488 if (rv != WIFI_ERROR_NONE)
1494 int test_set_eap_configuration(void)
1497 char name[33] = { 0, };
1498 char passphrase[100] = { 0, };
1499 int type = WIFI_SECURITY_TYPE_EAP;
1500 wifi_config_h config;
1502 printf("Input EAP configuration\n");
1504 rv = scanf("%32s", name);
1508 printf("Passphrase : ");
1509 rv = scanf("%99s", passphrase);
1513 rv = wifi_config_create(name, passphrase, type, &config);
1514 if (rv != WIFI_ERROR_NONE)
1517 rv = wifi_config_save_configuration(config);
1518 if (rv != WIFI_ERROR_NONE)
1521 rv = wifi_config_set_eap_type(config, WIFI_EAP_TYPE_TLS);
1522 if (rv != WIFI_ERROR_NONE)
1525 rv = wifi_config_set_eap_auth_type(config, WIFI_EAP_AUTH_TYPE_MD5);
1526 if (rv != WIFI_ERROR_NONE)
1529 rv = wifi_config_destroy(config);
1530 if (rv != WIFI_ERROR_NONE)
1536 int test_wifi_tdls_disconnect(void)
1541 printf("Enter Mac_address: ");
1542 if (scanf(" %17s", peer_mac) < 1)
1545 if (strlen(peer_mac) > 17) {
1546 printf("Wrong Mac_address\n");
1550 rv = wifi_tdls_disconnect(peer_mac);
1551 if (rv != WIFI_ERROR_NONE) {
1552 printf("test_wifi_tdls_disconnect() is failed [%s]\n", __test_convert_error_to_string(rv));
1558 int test_wifi_tdls_get_connected_peer(void)
1561 char *mac_addr = NULL;
1563 rv = wifi_tdls_get_connected_peer(&mac_addr);
1564 if (rv != WIFI_ERROR_NONE) {
1565 printf("wifi_tdls_get_connected_peer() is failed [%s]\n", __test_convert_error_to_string(rv));
1568 printf("Peer Mac address is [%s]\n", mac_addr);
1573 int main(int argc, char **argv)
1575 GMainLoop *mainloop;
1577 mainloop = g_main_loop_new(NULL, FALSE);
1579 GIOChannel *channel = g_io_channel_unix_new(0);
1580 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1582 printf("Test Thread created...\n");
1584 g_main_loop_run(mainloop);
1589 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1594 printf("Event received from stdin\n");
1596 rv = read(0, a, 10);
1598 if (rv <= 0 || a[0] == '0') {
1599 rv = wifi_deinitialize();
1601 if (rv != WIFI_ERROR_NONE)
1602 printf("Fail to deinitialize.\n");
1607 if (a[0] == '\n' || a[0] == '\r') {
1608 printf("\n\n Network Connection API Test App\n\n");
1609 printf("Options..\n");
1610 printf(LOG_GREEN "1 - Wi-Fi init and set callbacks\n" LOG_END);
1611 printf("2 - Wi-Fi deinit(unset callbacks automatically)\n");
1612 printf(LOG_GREEN "3 - Activate Wi-Fi device\n" LOG_END);
1613 printf("4 - Deactivate Wi-Fi device\n");
1614 printf("5 - Is Wi-Fi activated?\n");
1615 printf("6 - Get connection state\n");
1616 printf("7 - Get MAC address\n");
1617 printf("8 - Get Wi-Fi interface name\n");
1618 printf(LOG_GREEN "9 - Scan request\n" LOG_END);
1619 printf("a - Get Connected AP\n");
1620 printf("b - Get AP list\n");
1621 printf(LOG_GREEN "c - Connect\n" LOG_END);
1622 printf("d - Disconnect\n");
1623 printf("e - Connect by wps pbc\n");
1624 printf("f - Forget an AP\n");
1625 printf("g - Set & connect EAP\n");
1626 printf("h - Set IP method type\n");
1627 printf("i - Set Proxy method type\n");
1628 printf("j - Get Ap info\n");
1629 printf("k - Connect Specific AP\n");
1630 printf("l - Load configuration\n");
1631 printf("m - Save configuration\n");
1632 printf("n - Set configuration proxy and hidden\n");
1633 printf("o - Set EAP configuration\n");
1634 printf("p - TDLS TearDown\n");
1635 printf("q - TDLS Get Connected Peer\n");
1636 printf(LOG_RED "0 - Exit \n" LOG_END);
1638 printf("ENTER - Show options menu.......\n");
1643 rv = test_wifi_init();
1646 rv = test_wifi_deinit();
1649 rv = test_wifi_activate();
1652 rv = test_wifi_deactivate();
1655 rv = test_is_activated();
1658 rv = test_get_connection_state();
1661 rv = test_get_mac_address();
1664 rv = test_get_interface_name();
1667 rv = test_scan_request();
1670 rv = test_get_connected_ap();
1673 rv = test_foreach_found_aps();
1676 rv = test_connect_ap();
1679 rv = test_disconnect_ap();
1682 rv = test_connect_wps();
1685 rv = test_forget_ap();
1688 rv = test_connect_eap_ap();
1691 rv = test_set_ip_method();
1694 rv = test_set_proxy_method();
1697 rv = test_get_ap_info();
1700 rv = test_connect_specific_ap();
1703 rv = test_load_configuration();
1706 rv = test_save_configuration();
1709 rv = test_set_configuration_proxy_and_hidden();
1712 rv = test_set_eap_configuration();
1715 rv = test_wifi_tdls_disconnect();
1718 rv = test_wifi_tdls_get_connected_peer();
1726 printf("Operation succeeded!\n");
1728 printf("Operation failed!\n");