2 * Copyright (c) 2011-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.
24 #include "net_connection.h"
26 #include <tizen_error.h>
28 #define LOG_RED "\033[0;31m"
29 #define LOG_GREEN "\033[0;32m"
30 #define LOG_BROWN "\033[0;33m"
31 #define LOG_BLUE "\033[0;34m"
32 #define LOG_END "\033[0;m"
34 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
36 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
38 connection_h connection = NULL;
39 static GSList *state_cb_list = NULL;
42 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
44 if (msg == NULL || buf == NULL || buf_size < 2)
49 memset(buf, 0, buf_size);
50 rv = read(0, buf, buf_size - 1);
52 if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
61 static bool test_get_user_int(const char *msg, int *num)
63 if (msg == NULL || num == NULL)
69 rv = read(0, buf, 32);
71 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
78 static const char *test_print_state(connection_profile_state_e state)
81 case CONNECTION_PROFILE_STATE_DISCONNECTED:
82 return "Disconnected";
83 case CONNECTION_PROFILE_STATE_ASSOCIATION:
85 case CONNECTION_PROFILE_STATE_CONFIGURATION:
86 return "Configuration";
87 case CONNECTION_PROFILE_STATE_CONNECTED:
94 static const char *test_print_connection_type(connection_type_e type)
97 case CONNECTION_TYPE_DISCONNECTED:
98 return "Disconnected";
99 case CONNECTION_TYPE_WIFI:
101 case CONNECTION_TYPE_CELLULAR:
103 case CONNECTION_TYPE_ETHERNET:
105 case CONNECTION_TYPE_BT:
107 case CONNECTION_TYPE_NET_PROXY:
114 static const char *test_print_cellular_state(connection_cellular_state_e state)
117 case CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE:
118 return "Out of service";
119 case CONNECTION_CELLULAR_STATE_FLIGHT_MODE:
120 return "Flight mode";
121 case CONNECTION_CELLULAR_STATE_ROAMING_OFF:
122 return "Roaming off";
123 case CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE:
124 return "Call only available";
125 case CONNECTION_CELLULAR_STATE_AVAILABLE:
127 case CONNECTION_CELLULAR_STATE_CONNECTED:
134 static const char *test_print_wifi_state(connection_wifi_state_e state)
137 case CONNECTION_WIFI_STATE_DEACTIVATED:
138 return "Deactivated";
139 case CONNECTION_WIFI_STATE_DISCONNECTED:
140 return "Disconnected";
141 case CONNECTION_WIFI_STATE_CONNECTED:
148 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
151 case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
153 case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
155 case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
157 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
158 return "Prepaid internet";
159 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
160 return "Prepaid MMS";
161 case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
163 case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
164 return "Application";
170 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
173 case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
175 case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
177 case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
182 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
185 case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
187 case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
189 case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
191 case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
196 static const char *test_print_error(connection_error_e error)
199 case CONNECTION_ERROR_NONE:
200 return "CONNECTION_ERROR_NONE";
201 case CONNECTION_ERROR_INVALID_PARAMETER:
202 return "CONNECTION_ERROR_INVALID_PARAMETER";
203 case CONNECTION_ERROR_OUT_OF_MEMORY:
204 return "CONNECTION_ERROR_OUT_OF_MEMORY";
205 case CONNECTION_ERROR_INVALID_OPERATION:
206 return "CONNECTION_ERROR_INVALID_OPERATION";
207 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
208 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
209 case CONNECTION_ERROR_OPERATION_FAILED:
210 return "CONNECTION_ERROR_OPERATION_FAILED";
211 case CONNECTION_ERROR_ITERATOR_END:
212 return "CONNECTION_ERROR_ITERATOR_END";
213 case CONNECTION_ERROR_NO_CONNECTION:
214 return "CONNECTION_ERROR_NO_CONNECTION";
215 case CONNECTION_ERROR_NOW_IN_PROGRESS:
216 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
217 case CONNECTION_ERROR_ALREADY_EXISTS:
218 return "CONNECTION_ERROR_ALREADY_EXISTS";
219 case CONNECTION_ERROR_OPERATION_ABORTED:
220 return "CONNECTION_ERROR_OPERATION_ABORTED";
221 case CONNECTION_ERROR_DHCP_FAILED:
222 return "CONNECTION_ERROR_DHCP_FAILED";
223 case CONNECTION_ERROR_INVALID_KEY:
224 return "CONNECTION_ERROR_INVALID_KEY";
225 case CONNECTION_ERROR_NO_REPLY:
226 return "CONNECTION_ERROR_NO_REPLY";
227 case CONNECTION_ERROR_PERMISSION_DENIED:
228 return "CONNECTION_ERROR_PERMISSION_DENIED";
229 case CONNECTION_ERROR_NOT_SUPPORTED:
230 return "CONNECTION_ERROR_NOT_SUPPORTED";
232 return "CONNECTION_ERROR_UNKNOWN";
236 static void test_type_changed_callback(connection_type_e type, void* user_data)
238 printf("Type changed callback, connection type : %d\n", type);
241 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
243 printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
244 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
247 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
249 printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
250 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
253 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
256 connection_profile_h profile = user_data;
261 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
264 printf("[%s] : %s\n", test_print_state(state), profile_name);
265 g_free(profile_name);
268 static void test_connection_opened_callback(connection_error_e result, void* user_data)
270 if (result == CONNECTION_ERROR_NONE)
271 printf("Connection open Succeeded\n");
273 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
276 static void test_connection_closed_callback(connection_error_e result, void* user_data)
278 if (result == CONNECTION_ERROR_NONE)
279 printf("Connection close Succeeded\n");
281 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
284 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
286 if (result == CONNECTION_ERROR_NONE)
287 printf("Reset profile Succeeded\n");
289 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
292 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
294 if (result == CONNECTION_ERROR_NONE)
295 printf("Default profile setting Succeeded\n");
297 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
300 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
303 if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
304 printf("Ethernet Cable Connected\n");
305 else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
306 printf("Ethernet Cable Disconnected\n");
309 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
314 connection_profile_type_e profile_type;
315 connection_profile_state_e profile_state;
316 connection_profile_iterator_h profile_iter;
317 connection_profile_h profile_h;
319 connection_profile_h profile_list[100] = {0,};
320 int profile_count = 0;
322 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
323 if (rv != CONNECTION_ERROR_NONE) {
324 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
328 while (connection_profile_iterator_has_next(profile_iter)) {
329 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
330 printf("Fail to get profile handle\n");
334 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
335 printf("Fail to get profile name\n");
339 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
340 printf("Fail to get profile type\n");
341 g_free(profile_name);
345 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
346 printf("Fail to get profile state\n");
347 g_free(profile_name);
351 if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
353 connection_profile_get_wifi_essid(profile_h, &essid);
354 printf("%d. state:[%s], profile name:%s, essid:%s\n",
355 profile_count, test_print_state(profile_state),
356 profile_name, (essid) ? essid : "");
359 profile_list[profile_count] = profile_h;
362 connection_cellular_service_type_e service_type;
363 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE)
364 printf("Fail to get cellular service type!\n");
366 printf("%d. state:[%s], profile name:%s[%s]\n",
367 profile_count, test_print_state(profile_state),
368 profile_name, test_print_cellular_service_type(service_type));
370 profile_list[profile_count] = profile_h;
374 g_free(profile_name);
375 if (profile_count >= 100)
382 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
383 input >= profile_count ||
385 printf("Wrong number!!\n");
390 *profile = profile_list[input];
395 static int test_update_cellular_info(connection_profile_h profile)
398 char input_str1[100] = {0,};
399 char input_str2[100] = {0,};
403 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
404 "Prepaid MMS:4, Tethering:5, Application:6)"
405 " - (Enter for skip) :", &input_int)) {
408 rv = connection_profile_set_cellular_service_type(profile,
409 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
412 rv = connection_profile_set_cellular_service_type(profile,
413 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
416 rv = connection_profile_set_cellular_service_type(profile,
417 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
420 rv = connection_profile_set_cellular_service_type(profile,
421 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
424 rv = connection_profile_set_cellular_service_type(profile,
425 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
428 rv = connection_profile_set_cellular_service_type(profile,
429 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
435 if (rv != CONNECTION_ERROR_NONE)
440 if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
441 g_strstrip(input_str1);
442 rv = connection_profile_set_cellular_apn(profile, input_str1);
443 if (rv != CONNECTION_ERROR_NONE)
447 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
448 g_strstrip(input_str1);
449 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
450 if (rv != CONNECTION_ERROR_NONE)
454 if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
455 g_strstrip(input_str1);
456 rv = connection_profile_set_cellular_home_url(profile, input_str1);
457 if (rv != CONNECTION_ERROR_NONE)
461 if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
464 rv = connection_profile_set_cellular_auth_info(profile,
465 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
466 if (rv != CONNECTION_ERROR_NONE)
471 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
474 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
476 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
478 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
481 g_strstrip(input_str1);
482 g_strstrip(input_str2);
483 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
484 if (rv != CONNECTION_ERROR_NONE)
489 if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
492 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
495 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
498 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
502 if (rv != CONNECTION_ERROR_NONE)
506 if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
509 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
512 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
515 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
519 if (rv != CONNECTION_ERROR_NONE)
526 static int test_update_wifi_info(connection_profile_h profile)
529 char input_str[100] = {0,};
531 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
532 rv = connection_profile_set_wifi_passphrase(profile, input_str);
533 if (rv != CONNECTION_ERROR_NONE)
540 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
543 char input_str[100] = {0,};
545 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
546 rv = connection_profile_set_ip_address(profile,
549 if (rv != CONNECTION_ERROR_NONE)
553 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
554 rv = connection_profile_set_subnet_mask(profile,
557 if (rv != CONNECTION_ERROR_NONE)
561 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
562 rv = connection_profile_set_gateway_address(profile,
565 if (rv != CONNECTION_ERROR_NONE)
569 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
570 rv = connection_profile_set_dns_address(profile,
574 if (rv != CONNECTION_ERROR_NONE)
577 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
578 rv = connection_profile_set_dns_address(profile,
582 if (rv != CONNECTION_ERROR_NONE)
590 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
594 char input_str[100] = {0,};
596 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
597 " - (Enter for skip) :", &input_int)) {
600 rv = connection_profile_set_proxy_type(profile,
601 CONNECTION_PROXY_TYPE_DIRECT);
603 if (rv != CONNECTION_ERROR_NONE)
608 rv = connection_profile_set_proxy_type(profile,
609 CONNECTION_PROXY_TYPE_AUTO);
612 rv = connection_profile_set_proxy_type(profile,
613 CONNECTION_PROXY_TYPE_MANUAL);
619 if (rv != CONNECTION_ERROR_NONE)
622 if (test_get_user_string("Input auto Proxy URL or Proxy address"
623 " - (Enter for skip) :", input_str, 100)) {
624 rv = connection_profile_set_proxy_address(profile,
627 if (rv != CONNECTION_ERROR_NONE)
637 static int test_update_network_info(connection_profile_h profile)
641 int address_family = 0;
643 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
645 if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
646 " - (Enter for skip) :", &input_int)) {
649 rv = connection_profile_set_ip_config_type(profile,
651 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
654 rv = connection_profile_set_ip_config_type(profile,
656 CONNECTION_IP_CONFIG_TYPE_STATIC);
657 if (rv != CONNECTION_ERROR_NONE)
660 if (test_update_ip_info(profile, address_family) == -1)
663 if (test_update_proxy_info(profile, address_family) == -1)
670 if (rv != CONNECTION_ERROR_NONE)
678 static void test_print_cellular_info(connection_profile_h profile)
680 connection_cellular_service_type_e service_type;
681 connection_cellular_pdn_type_e pdn_type;
682 connection_cellular_pdn_type_e roam_pdn_type;
684 connection_cellular_auth_type_e auth_type;
685 char *user_name = NULL;
686 char *password = NULL;
687 char *home_url = NULL;
688 bool roaming = false;
690 bool editable = false;
692 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
693 printf("Fail to get cellular service type!\n");
695 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
697 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
698 printf("Fail to get cellular pdn type!\n");
700 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
702 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
703 printf("Fail to get cellular roam pdn type!\n");
705 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
707 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
708 printf("Fail to get cellular APN!\n");
710 printf("Cellular APN : %s\n", apn);
714 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
715 printf("Fail to get auth info!\n");
717 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
718 printf("Cellular user_name : %s\n", user_name);
719 printf("Cellular password : %s\n", password);
724 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
725 printf("Fail to get cellular home url!\n");
727 printf("Cellular home url : %s\n", home_url);
731 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
732 printf("Fail to get cellular roaming state!\n");
734 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
736 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
737 printf("Fail to get cellular hidden state!\n");
739 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
741 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
742 printf("Fail to get cellular editing state!\n");
744 printf("Cellular editable : %s\n", editable ? "true" : "false");
747 static void test_print_wifi_info(connection_profile_h profile)
754 connection_wifi_security_type_e security_type;
755 connection_wifi_encryption_type_e encryption_type;
756 bool pass_required = false;
757 bool wps_supported = false;
759 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
760 printf("Fail to get Wi-Fi essid!\n");
762 printf("Wi-Fi essid : %s\n", essid);
766 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
767 printf("Fail to get Wi-Fi bssid!\n");
769 printf("Wi-Fi bssid : %s\n", bssid);
773 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
774 printf("Fail to get Wi-Fi rssi!\n");
776 printf("Wi-Fi rssi : %d\n", rssi);
778 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
779 printf("Fail to get Wi-Fi frequency!\n");
781 printf("Wi-Fi frequency : %d\n", frequency);
783 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
784 printf("Fail to get Wi-Fi max speed!\n");
786 printf("Wi-Fi max speed : %d\n", max_speed);
788 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
789 printf("Fail to get Wi-Fi security type!\n");
791 printf("Wi-Fi security type : %d\n", security_type);
793 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
794 printf("Fail to get Wi-Fi encryption type!\n");
796 printf("Wi-Fi encryption type : %d\n", encryption_type);
798 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
799 printf("Fail to get Wi-Fi passphrase required!\n");
801 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
803 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
804 printf("Fail to get Wi-Fi wps info\n");
806 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
809 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
811 char *interface_name = NULL;
812 connection_ip_config_type_e ip_type;
815 char *gateway = NULL;
818 connection_proxy_type_e proxy_type;
821 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
822 printf("Fail to get interface name!\n");
824 printf("Interface name : %s\n", interface_name);
825 g_free(interface_name);
828 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
829 printf("Fail to get ipconfig type!\n");
831 printf("Ipconfig type : %d\n", ip_type);
833 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
834 printf("Fail to get IP address!\n");
836 printf("IP address : %s\n", ip);
840 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
841 printf("Fail to get subnet mask!\n");
843 printf("Subnet mask : %s\n", subnet);
847 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
848 printf("Fail to get gateway!\n");
850 printf("Gateway : %s\n", gateway);
854 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
855 printf("Fail to get DNS1!\n");
857 printf("DNS1 : %s\n", dns1);
861 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
862 printf("Fail to get DNS2!\n");
864 printf("DNS2 : %s\n", dns2);
868 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
869 printf("Fail to get proxy type!\n");
871 printf("Proxy type : %d\n", proxy_type);
873 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
874 printf("Fail to get proxy!\n");
876 printf("Proxy : %s\n", proxy);
881 int test_register_client(void)
884 int err = connection_create(&connection);
886 if (CONNECTION_ERROR_NONE == err) {
887 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
888 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
889 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
890 connection_set_ethernet_cable_state_chaged_cb(connection,
891 test_get_ethernet_cable_state_callback, NULL);
893 printf("Client registration failed [%s]\n", test_print_error(err));
897 printf("Client registration success\n");
901 int test_deregister_client(void)
905 connection_profile_h profile;
907 if (connection != NULL)
908 rv = connection_destroy(connection);
910 printf("Cannot deregister : Handle is NULL\n");
911 rv = CONNECTION_ERROR_INVALID_OPERATION;
914 if (rv != CONNECTION_ERROR_NONE) {
915 printf("Client deregistration fail [%s]\n", test_print_error(rv));
920 for (list = state_cb_list; list; list = list->next) {
921 profile = list->data;
922 connection_profile_destroy(profile);
925 g_slist_free(state_cb_list);
926 state_cb_list = NULL;
930 printf("Client deregistration success\n");
935 int test_get_network_state(void)
938 connection_type_e net_state;
940 rv = connection_get_type(connection, &net_state);
942 if (rv != CONNECTION_ERROR_NONE) {
943 printf("Fail to get network state [%s]\n", test_print_error(rv));
947 printf("Retval = [%s] network connection state [%s]\n",
948 test_print_error(rv), test_print_connection_type(net_state));
953 int test_get_cellular_state(void)
956 connection_cellular_state_e cellular_state;
958 rv = connection_get_cellular_state(connection, &cellular_state);
960 if (rv != CONNECTION_ERROR_NONE) {
961 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
965 printf("Retval = [%s] Cellular state [%s]\n",
966 test_print_error(rv), test_print_cellular_state(cellular_state));
971 int test_get_wifi_state(void)
974 connection_wifi_state_e wifi_state;
976 rv = connection_get_wifi_state(connection, &wifi_state);
978 if (rv != CONNECTION_ERROR_NONE) {
979 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
983 printf("Retval = [%s] WiFi state [%s]\n",
984 test_print_error(rv), test_print_wifi_state(wifi_state));
989 int test_get_current_proxy(void)
991 char *proxy_addr = NULL;
993 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
995 if (proxy_addr == NULL) {
996 printf("Proxy address does not exist\n");
1000 printf("Current Proxy [%s]\n", proxy_addr);
1006 int test_get_current_ip(void)
1008 char *ip_addr = NULL;
1012 rv = test_get_user_int("Input Address type to get"
1013 "(1:IPV4, 2:IPV6):", &input);
1016 printf("Invalid input!!\n");
1022 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1023 if (ip_addr == NULL) {
1024 printf("IPv4 address does not exist\n");
1027 printf("IPv4 address : %s\n", ip_addr);
1031 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1032 if (ip_addr == NULL) {
1033 printf("IPv6 address does not exist\n");
1036 printf("IPv6 address : %s\n", ip_addr);
1039 printf("Wrong IP address family!!\n");
1047 int test_get_call_statistics_info(void)
1051 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1052 printf("last recv data size [%lld]\n", rv);
1053 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1054 printf("last sent data size [%lld]\n", rv);
1055 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1056 printf("total received data size [%lld]\n", rv);
1057 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1058 printf("total sent data size [%lld]\n", rv);
1063 int test_get_wifi_call_statistics_info(void)
1067 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1068 printf("WiFi last recv data size [%lld]\n", rv);
1069 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1070 printf("WiFi last sent data size [%lld]\n", rv);
1071 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1072 printf("WiFi total received data size [%lld]\n", rv);
1073 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1074 printf("WiFi total sent data size [%lld]\n", rv);
1079 int test_get_profile_list(void)
1081 if (test_get_user_selected_profile(NULL, false) == false)
1087 int test_get_default_profile_list(void)
1090 char *profile_name = NULL;
1091 connection_profile_iterator_h profile_iter;
1092 connection_profile_h profile_h;
1093 connection_cellular_service_type_e service_type;
1094 bool is_default = false;
1096 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1097 if (rv != CONNECTION_ERROR_NONE) {
1098 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1102 while (connection_profile_iterator_has_next(profile_iter)) {
1103 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1104 printf("Fail to get profile handle\n");
1108 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1109 printf("Fail to get profile name\n");
1112 printf("profile name : %s\n", profile_name);
1113 g_free(profile_name);
1115 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1116 printf("Fail to get profile service type\n");
1119 printf("service type : %d\n", service_type);
1121 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1122 printf("Fail to get profile subscriber id\n");
1125 printf("Default : %d\n", is_default);
1131 int test_get_connected_profile_list(void)
1134 char *profile_name = NULL;
1135 connection_profile_iterator_h profile_iter;
1136 connection_profile_h profile_h;
1137 bool is_default = false;
1138 connection_profile_type_e type;
1140 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1141 if (rv != CONNECTION_ERROR_NONE) {
1142 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1146 while (connection_profile_iterator_has_next(profile_iter)) {
1147 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1148 printf("Fail to get profile handle\n");
1152 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1153 printf("Fail to get profile name\n");
1156 printf("profile name is %s\n", profile_name);
1157 g_free(profile_name);
1159 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1160 printf("Fail to get profile type\n");
1163 printf("profile type is %d\n", type);
1165 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1166 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1167 printf("Fail to get profile is default\n");
1170 printf("[%s]\n", is_default ? "default" : "not default");
1177 int test_get_current_profile(void)
1180 char *profile_name = NULL;
1181 connection_profile_h profile_h;
1183 rv = connection_get_current_profile(connection, &profile_h);
1184 if (rv != CONNECTION_ERROR_NONE) {
1185 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1189 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1190 printf("Fail to get profile name\n");
1193 printf("profile name : %s\n", profile_name);
1194 g_free(profile_name);
1196 connection_profile_destroy(profile_h);
1201 int test_open_profile(void)
1203 connection_profile_h profile;
1205 printf("\n** Choose a profile to open. **\n");
1207 if (test_get_user_selected_profile(&profile, true) == false)
1210 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1211 printf("Connection open Failed!!\n");
1218 int test_get_default_cellular_service_type(void)
1223 connection_profile_h profile;
1224 char *profile_name = NULL;
1226 rv = test_get_user_int("Input profile type to get"
1227 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1230 printf("Invalid input!!\n");
1236 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1239 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1242 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1245 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1248 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1251 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1254 printf("Wrong number!!\n");
1258 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1261 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1262 printf("Fail to get profile name\n");
1263 connection_profile_destroy(profile);
1266 printf("Default profile name : %s\n", profile_name);
1267 g_free(profile_name);
1269 connection_profile_destroy(profile);
1274 int test_set_default_cellular_service_type(void)
1276 connection_profile_h profile;
1277 connection_cellular_service_type_e type;
1280 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1282 if (rv == false || (input != 1 && input != 2)) {
1283 printf("Invalid input!!\n");
1287 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1289 if (test_get_user_selected_profile(&profile, true) == false)
1292 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1293 printf("Fail to get cellular service type\n");
1298 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1301 if (connection_set_default_cellular_service_profile_async(connection,
1302 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1309 int test_close_profile(void)
1311 connection_profile_h profile;
1313 printf("\n** Choose a profile to close. **\n");
1315 if (test_get_user_selected_profile(&profile, true) == false)
1318 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1319 printf("Connection close Failed!!\n");
1326 int test_add_profile(void)
1329 connection_profile_h profile;
1330 char input_str[100] = {0,};
1332 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1335 g_strstrip(input_str);
1336 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1337 if (rv != CONNECTION_ERROR_NONE)
1338 RETURN_FAIL_DESTROY(profile);
1340 if (test_update_cellular_info(profile) == -1)
1341 RETURN_FAIL_DESTROY(profile);
1343 rv = connection_add_profile(connection, profile);
1344 if (rv != CONNECTION_ERROR_NONE)
1345 RETURN_FAIL_DESTROY(profile);
1347 connection_profile_destroy(profile);
1351 int test_remove_profile(void)
1353 connection_profile_h profile;
1355 printf("\n** Choose a profile to remove. **\n");
1356 if (test_get_user_selected_profile(&profile, true) == false)
1359 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1360 printf("Remove profile Failed!!\n");
1367 int test_update_profile(void)
1371 connection_profile_type_e prof_type;
1372 connection_profile_h profile;
1374 printf("\n** Choose a profile to update. **\n");
1375 if (test_get_user_selected_profile(&profile, true) == false)
1378 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1381 switch (prof_type) {
1382 case CONNECTION_PROFILE_TYPE_CELLULAR:
1383 if (test_update_cellular_info(profile) == -1)
1387 case CONNECTION_PROFILE_TYPE_WIFI:
1388 if (test_update_wifi_info(profile) == -1)
1391 if (test_update_network_info(profile) == -1)
1395 case CONNECTION_PROFILE_TYPE_ETHERNET:
1396 if (test_update_network_info(profile) == -1)
1400 case CONNECTION_PROFILE_TYPE_BT:
1401 printf("Not supported!\n");
1407 rv = connection_update_profile(connection, profile);
1408 if (rv != CONNECTION_ERROR_NONE)
1414 int test_get_profile_info(void)
1416 connection_profile_type_e prof_type;
1417 connection_profile_state_e profile_state;
1418 connection_profile_h profile;
1419 char *profile_name = NULL;
1420 int address_family = 0;
1422 printf("\n** Choose a profile to print. **\n");
1423 if (test_get_user_selected_profile(&profile, true) == false)
1426 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1427 printf("Fail to get profile name\n");
1430 printf("Profile Name : %s\n", profile_name);
1431 g_free(profile_name);
1434 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1435 printf("Fail to get profile state\n");
1438 printf("Profile State : %s\n", test_print_state(profile_state));
1440 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1443 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1445 switch (prof_type) {
1446 case CONNECTION_PROFILE_TYPE_CELLULAR:
1447 printf("Profile Type : Cellular\n");
1448 test_print_cellular_info(profile);
1450 case CONNECTION_PROFILE_TYPE_WIFI:
1451 printf("Profile Type : Wi-Fi\n");
1452 test_print_wifi_info(profile);
1454 case CONNECTION_PROFILE_TYPE_ETHERNET:
1455 printf("Profile Type : Ethernet\n");
1457 case CONNECTION_PROFILE_TYPE_BT:
1458 printf("Profile Type : Bluetooth\n");
1464 test_print_network_info(profile, address_family);
1469 int test_refresh_profile_info(void)
1471 connection_profile_type_e prof_type;
1472 connection_profile_state_e profile_state;
1473 connection_profile_h profile;
1474 char *profile_name = NULL;
1475 int address_family = 0;
1477 printf("\n** Choose a profile to refresh. **\n");
1478 if (test_get_user_selected_profile(&profile, true) == false)
1481 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1484 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1485 printf("Fail to get profile name\n");
1488 printf("Profile Name : %s\n", profile_name);
1489 g_free(profile_name);
1492 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1493 printf("Fail to get profile state\n");
1496 printf("Profile State : %s\n", test_print_state(profile_state));
1499 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1502 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1504 switch (prof_type) {
1505 case CONNECTION_PROFILE_TYPE_CELLULAR:
1506 printf("Profile Type : Cellular\n");
1507 test_print_cellular_info(profile);
1509 case CONNECTION_PROFILE_TYPE_WIFI:
1510 printf("Profile Type : Wi-Fi\n");
1511 test_print_wifi_info(profile);
1513 case CONNECTION_PROFILE_TYPE_ETHERNET:
1514 printf("Profile Type : Ethernet\n");
1516 case CONNECTION_PROFILE_TYPE_BT:
1517 printf("Profile Type : Bluetooth\n");
1523 test_print_network_info(profile, address_family);
1528 int test_set_state_changed_callback()
1530 connection_profile_h profile;
1531 connection_profile_h profile_clone;
1533 printf("\n** Choose a profile to set callback. **\n");
1534 if (test_get_user_selected_profile(&profile, true) == false)
1537 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1540 if (connection_profile_set_state_changed_cb(profile,
1541 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1542 connection_profile_destroy(profile_clone);
1546 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1551 int test_unset_state_changed_callback()
1553 connection_profile_h profile;
1555 char *profile_name = NULL;
1559 printf("\n** Choose a profile to unset callback. **\n");
1560 for (list = state_cb_list; list; list = list->next) {
1561 profile = list->data;
1562 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1563 printf("Fail to get profile name!\n");
1566 printf("%d. %s\n", count, profile_name);
1567 g_free(profile_name);
1573 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1576 printf("Wrong number!!\n");
1581 for (list = state_cb_list; list; list = list->next) {
1582 if (count == input) {
1583 profile = list->data;
1593 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1596 state_cb_list = g_slist_remove(state_cb_list, profile);
1597 connection_profile_destroy(profile);
1602 int test_reset_call_statistics_info(void)
1604 int ret = CONNECTION_ERROR_NONE;
1606 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1607 printf("reset last recv data size [%d]\n", ret);
1608 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1609 printf("last sent data size [%d]\n", ret);
1610 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1611 printf("total received data size [%d]\n", ret);
1612 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1613 printf("total sent data size [%d]\n", ret);
1618 int test_reset_wifi_call_statistics_info(void)
1620 int ret = CONNECTION_ERROR_NONE;
1622 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1623 printf("WiFi last sent data size [%d]\n", ret);
1624 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1625 printf("WiFi last recv data size [%d]\n", ret);
1626 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1627 printf("WiFi total sent data size [%d]\n", ret);
1628 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1629 printf("WiFi total received data size [%d]\n", ret);
1634 int test_add_route(void)
1637 char ip_addr[100] = {0};
1638 char if_name[40] = {0};
1640 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1643 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1646 g_strstrip(ip_addr);
1647 g_strstrip(if_name);
1648 rv = connection_add_route(connection, if_name, ip_addr);
1649 if (rv != CONNECTION_ERROR_NONE) {
1650 printf("Fail to get add new route [%d]\n", rv);
1653 printf("Add Route successfully\n");
1658 int test_remove_route(void)
1661 char ip_addr[100] = {0};
1662 char if_name[40] = {0};
1664 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1667 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1670 g_strstrip(ip_addr);
1671 g_strstrip(if_name);
1672 rv = connection_remove_route(connection, if_name, ip_addr);
1673 if (rv != CONNECTION_ERROR_NONE) {
1674 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1677 printf("Remove Route successfully\n");
1682 int test_add_route_ipv6(void)
1685 char ip_addr[100] = {0};
1686 char gateway[100] = {0};
1687 char if_name[40] = {0};
1689 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1692 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1695 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1698 g_strstrip(ip_addr);
1699 g_strstrip(gateway);
1700 g_strstrip(if_name);
1701 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1702 if (rv != CONNECTION_ERROR_NONE) {
1703 printf("Fail to get add new route [%d]\n", rv);
1706 printf("Add Route successfully\n");
1711 int test_remove_route_ipv6(void)
1714 char ip_addr[100] = {0};
1715 char gateway[100] = {0};
1716 char if_name[40] = {0};
1718 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1721 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1724 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1727 g_strstrip(ip_addr);
1728 g_strstrip(gateway);
1729 g_strstrip(if_name);
1730 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1731 if (rv != CONNECTION_ERROR_NONE) {
1732 printf("Fail to remove the route [%d]\n", rv);
1735 printf("Remove Route successfully\n");
1740 int test_get_bt_state(void)
1743 connection_bt_state_e bt_state;
1745 rv = connection_get_bt_state(connection, &bt_state);
1747 if (rv != CONNECTION_ERROR_NONE) {
1748 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1752 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
1757 int test_get_profile_id(void)
1759 connection_profile_h profile;
1762 printf("\n** Choose a profile to see profile id. **\n");
1763 if (test_get_user_selected_profile(&profile, true) == false)
1766 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1767 printf("Fail to get profile name\n");
1770 printf("Profile id : %s\n", profile_id);
1777 int test_get_mac_address(void)
1779 int rv = 0, type = 0;
1780 connection_type_e conn_type;
1781 char *mac_addr = NULL;
1783 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
1787 conn_type = CONNECTION_TYPE_WIFI;
1790 conn_type = CONNECTION_TYPE_ETHERNET;
1793 printf("Wrong number!!\n");
1797 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
1799 if (rv != CONNECTION_ERROR_NONE) {
1800 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
1804 printf("mac address is %s\n", mac_addr);
1811 int test_get_ethernet_cable_state(void)
1814 connection_ethernet_cable_state_e cable_state;
1816 rv = connection_get_ethernet_cable_state(connection, &cable_state);
1818 if (rv != CONNECTION_ERROR_NONE) {
1819 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
1823 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
1828 int test_reset_profile(void)
1830 int type, sim_id, rv;
1832 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
1834 if (rv == false || (type != 0 && type != 1)) {
1835 printf("Invalid input!!\n");
1839 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
1841 if (rv == false || (sim_id != 0 && sim_id != 1)) {
1842 printf("Invalid input!!\n");
1846 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
1852 int main(int argc, char **argv)
1854 GMainLoop *mainloop;
1855 mainloop = g_main_loop_new(NULL, FALSE);
1857 GIOChannel *channel = g_io_channel_unix_new(0);
1858 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1860 printf("Test Thread created...\n");
1862 g_main_loop_run(mainloop);
1867 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1872 memset(a, '\0', 100);
1873 printf("Event received from stdin\n");
1875 rv = read(0, a, 100);
1877 if (rv < 0 || a[0] == '0') {
1878 if (connection != NULL)
1879 test_deregister_client();
1884 if (*a == '\n' || *a == '\r') {
1885 printf("\n\n Network Connection API Test App\n\n");
1886 printf("Options..\n");
1887 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
1888 printf("2 - Destroy Handle(unset callbacks automatically)\n");
1889 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
1890 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
1891 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
1892 printf("6 - Get current proxy address \n");
1893 printf("7 - Get current Ip address\n");
1894 printf("8 - Get cellular data call statistics\n");
1895 printf("9 - Get WiFi data call statistics\n");
1896 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
1897 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
1898 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
1899 printf("d - Open connection with profile\n");
1900 printf("e - Get default cellular service by type\n");
1901 printf("f - Set default cellular service by type\n");
1902 printf("g - Close connection with profile\n");
1903 printf("h - Add profile(Cellular and Wifi only)\n");
1904 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
1905 printf("j - Update profile\n");
1906 printf("k - Get profile info\n");
1907 printf("l - Refresh profile info\n");
1908 printf("m - Set state changed callback\n");
1909 printf("n - Unset state changed callback\n");
1910 printf("o - Reset cellular data call statistics\n");
1911 printf("p - Reset WiFi data call statistics\n");
1912 printf("q - Add new route\n");
1913 printf("r - Remove a route\n");
1914 printf("s - Get Bluetooth state\n");
1915 printf("t - Get profile id\n");
1916 printf("u - Reset profile\n");
1917 printf("v - Get all cellular default profiles\n");
1918 printf("w - Get mac address\n");
1919 printf("x - Get ethernet cable state\n");
1920 printf("B - Add IPv6 new route\n");
1921 printf("C - Remove IPv6 route\n");
1922 printf(LOG_RED "0 - Exit \n" LOG_END);
1923 printf("ENTER - Show options menu.......\n");
1928 rv = test_register_client();
1931 rv = test_deregister_client();
1934 rv = test_get_network_state();
1937 rv = test_get_cellular_state();
1940 rv = test_get_wifi_state();
1943 rv = test_get_current_proxy();
1946 rv = test_get_current_ip();
1949 rv = test_get_call_statistics_info();
1952 rv = test_get_wifi_call_statistics_info();
1955 rv = test_get_profile_list();
1958 rv = test_get_connected_profile_list();
1961 rv = test_get_current_profile();
1964 rv = test_open_profile();
1967 rv = test_get_default_cellular_service_type();
1970 rv = test_set_default_cellular_service_type();
1973 rv = test_close_profile();
1976 rv = test_add_profile();
1979 rv = test_remove_profile();
1982 rv = test_update_profile();
1985 rv = test_get_profile_info();
1988 rv = test_refresh_profile_info();
1991 rv = test_set_state_changed_callback();
1994 rv = test_unset_state_changed_callback();
1997 rv = test_reset_call_statistics_info();
2000 rv = test_reset_wifi_call_statistics_info();
2003 rv = test_add_route();
2006 rv = test_remove_route();
2009 rv = test_get_bt_state();
2012 rv = test_get_profile_id();
2015 rv = test_reset_profile();
2018 rv = test_get_default_profile_list();
2021 rv = test_get_mac_address();
2024 rv = test_get_ethernet_cable_state();
2027 rv = test_add_route_ipv6();
2030 rv = test_remove_route_ipv6();
2035 printf("Operation succeeded!\n");
2037 printf("Operation failed!\n");