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_error(connection_error_e error)
173 case CONNECTION_ERROR_NONE:
174 return "CONNECTION_ERROR_NONE";
175 case CONNECTION_ERROR_INVALID_PARAMETER:
176 return "CONNECTION_ERROR_INVALID_PARAMETER";
177 case CONNECTION_ERROR_OUT_OF_MEMORY:
178 return "CONNECTION_ERROR_OUT_OF_MEMORY";
179 case CONNECTION_ERROR_INVALID_OPERATION:
180 return "CONNECTION_ERROR_INVALID_OPERATION";
181 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
182 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
183 case CONNECTION_ERROR_OPERATION_FAILED:
184 return "CONNECTION_ERROR_OPERATION_FAILED";
185 case CONNECTION_ERROR_ITERATOR_END:
186 return "CONNECTION_ERROR_ITERATOR_END";
187 case CONNECTION_ERROR_NO_CONNECTION:
188 return "CONNECTION_ERROR_NO_CONNECTION";
189 case CONNECTION_ERROR_NOW_IN_PROGRESS:
190 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
191 case CONNECTION_ERROR_ALREADY_EXISTS:
192 return "CONNECTION_ERROR_ALREADY_EXISTS";
193 case CONNECTION_ERROR_OPERATION_ABORTED:
194 return "CONNECTION_ERROR_OPERATION_ABORTED";
195 case CONNECTION_ERROR_DHCP_FAILED:
196 return "CONNECTION_ERROR_DHCP_FAILED";
197 case CONNECTION_ERROR_INVALID_KEY:
198 return "CONNECTION_ERROR_INVALID_KEY";
199 case CONNECTION_ERROR_NO_REPLY:
200 return "CONNECTION_ERROR_NO_REPLY";
201 case CONNECTION_ERROR_PERMISSION_DENIED:
202 return "CONNECTION_ERROR_PERMISSION_DENIED";
203 case CONNECTION_ERROR_NOT_SUPPORTED:
204 return "CONNECTION_ERROR_NOT_SUPPORTED";
206 return "CONNECTION_ERROR_UNKNOWN";
210 static void test_type_changed_callback(connection_type_e type, void* user_data)
212 printf("Type changed callback, connection type : %d\n", type);
215 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
217 printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
218 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
221 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
223 printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
224 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
227 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
230 connection_profile_h profile = user_data;
235 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
238 printf("[%s] : %s\n", test_print_state(state), profile_name);
239 g_free(profile_name);
242 static void test_connection_opened_callback(connection_error_e result, void* user_data)
244 if (result == CONNECTION_ERROR_NONE)
245 printf("Connection open Succeeded\n");
247 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
250 static void test_connection_closed_callback(connection_error_e result, void* user_data)
252 if (result == CONNECTION_ERROR_NONE)
253 printf("Connection close Succeeded\n");
255 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
258 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
260 if (result == CONNECTION_ERROR_NONE)
261 printf("Reset profile Succeeded\n");
263 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
266 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
268 if (result == CONNECTION_ERROR_NONE)
269 printf("Default profile setting Succeeded\n");
271 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
274 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
277 if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
278 printf("Ethernet Cable Connected\n");
279 else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
280 printf("Ethernet Cable Disconnected\n");
283 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
288 connection_profile_type_e profile_type;
289 connection_profile_state_e profile_state;
290 connection_profile_iterator_h profile_iter;
291 connection_profile_h profile_h;
293 connection_profile_h profile_list[100] = {0,};
294 int profile_count = 0;
296 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
297 if (rv != CONNECTION_ERROR_NONE) {
298 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
302 while (connection_profile_iterator_has_next(profile_iter)) {
303 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
304 printf("Fail to get profile handle\n");
308 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
309 printf("Fail to get profile name\n");
313 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
314 printf("Fail to get profile type\n");
315 g_free(profile_name);
319 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
320 printf("Fail to get profile state\n");
321 g_free(profile_name);
325 if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
327 connection_profile_get_wifi_essid(profile_h, &essid);
328 printf("%d. state:[%s], profile name:%s, essid:%s\n",
329 profile_count, test_print_state(profile_state),
330 profile_name, (essid) ? essid : "");
333 profile_list[profile_count] = profile_h;
336 connection_cellular_service_type_e service_type;
337 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE)
338 printf("Fail to get cellular service type!\n");
340 printf("%d. state:[%s], profile name:%s[%s]\n",
341 profile_count, test_print_state(profile_state),
342 profile_name, test_print_cellular_service_type(service_type));
344 profile_list[profile_count] = profile_h;
348 g_free(profile_name);
349 if (profile_count >= 100)
356 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
357 input >= profile_count ||
359 printf("Wrong number!!\n");
364 *profile = profile_list[input];
369 static int test_update_cellular_info(connection_profile_h profile)
372 char input_str1[100] = {0,};
373 char input_str2[100] = {0,};
377 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
378 "Prepaid MMS:4, Tethering:5, Application:6)"
379 " - (Enter for skip) :", &input_int)) {
382 rv = connection_profile_set_cellular_service_type(profile,
383 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
386 rv = connection_profile_set_cellular_service_type(profile,
387 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
390 rv = connection_profile_set_cellular_service_type(profile,
391 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
394 rv = connection_profile_set_cellular_service_type(profile,
395 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
398 rv = connection_profile_set_cellular_service_type(profile,
399 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
402 rv = connection_profile_set_cellular_service_type(profile,
403 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
409 if (rv != CONNECTION_ERROR_NONE)
414 if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
415 g_strstrip(input_str1);
416 rv = connection_profile_set_cellular_apn(profile, input_str1);
417 if (rv != CONNECTION_ERROR_NONE)
421 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
422 g_strstrip(input_str1);
423 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
424 if (rv != CONNECTION_ERROR_NONE)
428 if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
429 g_strstrip(input_str1);
430 rv = connection_profile_set_cellular_home_url(profile, input_str1);
431 if (rv != CONNECTION_ERROR_NONE)
435 if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
438 rv = connection_profile_set_cellular_auth_info(profile,
439 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
440 if (rv != CONNECTION_ERROR_NONE)
445 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
448 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
450 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
452 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
455 g_strstrip(input_str1);
456 g_strstrip(input_str2);
457 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
458 if (rv != CONNECTION_ERROR_NONE)
466 static int test_update_wifi_info(connection_profile_h profile)
469 char input_str[100] = {0,};
471 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
472 rv = connection_profile_set_wifi_passphrase(profile, input_str);
473 if (rv != CONNECTION_ERROR_NONE)
480 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
483 char input_str[100] = {0,};
485 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
486 rv = connection_profile_set_ip_address(profile,
489 if (rv != CONNECTION_ERROR_NONE)
493 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
494 rv = connection_profile_set_subnet_mask(profile,
497 if (rv != CONNECTION_ERROR_NONE)
501 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
502 rv = connection_profile_set_gateway_address(profile,
505 if (rv != CONNECTION_ERROR_NONE)
509 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
510 rv = connection_profile_set_dns_address(profile,
514 if (rv != CONNECTION_ERROR_NONE)
517 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
518 rv = connection_profile_set_dns_address(profile,
522 if (rv != CONNECTION_ERROR_NONE)
530 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
534 char input_str[100] = {0,};
536 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
537 " - (Enter for skip) :", &input_int)) {
540 rv = connection_profile_set_proxy_type(profile,
541 CONNECTION_PROXY_TYPE_DIRECT);
543 if (rv != CONNECTION_ERROR_NONE)
548 rv = connection_profile_set_proxy_type(profile,
549 CONNECTION_PROXY_TYPE_AUTO);
552 rv = connection_profile_set_proxy_type(profile,
553 CONNECTION_PROXY_TYPE_MANUAL);
559 if (rv != CONNECTION_ERROR_NONE)
562 if (test_get_user_string("Input auto Proxy URL or Proxy address"
563 " - (Enter for skip) :", input_str, 100)) {
564 rv = connection_profile_set_proxy_address(profile,
567 if (rv != CONNECTION_ERROR_NONE)
577 static int test_update_network_info(connection_profile_h profile)
581 int address_family = 0;
583 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
585 if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
586 " - (Enter for skip) :", &input_int)) {
589 rv = connection_profile_set_ip_config_type(profile,
591 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
594 rv = connection_profile_set_ip_config_type(profile,
596 CONNECTION_IP_CONFIG_TYPE_STATIC);
597 if (rv != CONNECTION_ERROR_NONE)
600 if (test_update_ip_info(profile, address_family) == -1)
603 if (test_update_proxy_info(profile, address_family) == -1)
610 if (rv != CONNECTION_ERROR_NONE)
618 static void test_print_cellular_info(connection_profile_h profile)
620 connection_cellular_service_type_e service_type;
622 connection_cellular_auth_type_e auth_type;
623 char *user_name = NULL;
624 char *password = NULL;
625 char *home_url = NULL;
626 bool roaming = false;
628 bool editable = false;
630 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
631 printf("Fail to get cellular service type!\n");
633 printf("Cellular service type : %d\n", service_type);
635 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
636 printf("Fail to get cellular APN!\n");
638 printf("Cellular APN : %s\n", apn);
642 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
643 printf("Fail to get auth info!\n");
645 printf("Cellular auth type : %d\n", auth_type);
646 printf("Cellular user_name : %s\n", user_name);
647 printf("Cellular password : %s\n", password);
652 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
653 printf("Fail to get cellular home url!\n");
655 printf("Cellular home url : %s\n", home_url);
659 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
660 printf("Fail to get cellular roaming state!\n");
662 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
664 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
665 printf("Fail to get cellular hidden state!\n");
667 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
669 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
670 printf("Fail to get cellular editing state!\n");
672 printf("Cellular editable : %s\n", editable ? "true" : "false");
675 static void test_print_wifi_info(connection_profile_h profile)
682 connection_wifi_security_type_e security_type;
683 connection_wifi_encryption_type_e encryption_type;
684 bool pass_required = false;
685 bool wps_supported = false;
687 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
688 printf("Fail to get Wi-Fi essid!\n");
690 printf("Wi-Fi essid : %s\n", essid);
694 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
695 printf("Fail to get Wi-Fi bssid!\n");
697 printf("Wi-Fi bssid : %s\n", bssid);
701 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
702 printf("Fail to get Wi-Fi rssi!\n");
704 printf("Wi-Fi rssi : %d\n", rssi);
706 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
707 printf("Fail to get Wi-Fi frequency!\n");
709 printf("Wi-Fi frequency : %d\n", frequency);
711 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
712 printf("Fail to get Wi-Fi max speed!\n");
714 printf("Wi-Fi max speed : %d\n", max_speed);
716 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
717 printf("Fail to get Wi-Fi security type!\n");
719 printf("Wi-Fi security type : %d\n", security_type);
721 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
722 printf("Fail to get Wi-Fi encryption type!\n");
724 printf("Wi-Fi encryption type : %d\n", encryption_type);
726 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
727 printf("Fail to get Wi-Fi passphrase required!\n");
729 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
731 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
732 printf("Fail to get Wi-Fi wps info\n");
734 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
737 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
739 char *interface_name = NULL;
740 connection_ip_config_type_e ip_type;
743 char *gateway = NULL;
746 connection_proxy_type_e proxy_type;
749 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
750 printf("Fail to get interface name!\n");
752 printf("Interface name : %s\n", interface_name);
753 g_free(interface_name);
756 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
757 printf("Fail to get ipconfig type!\n");
759 printf("Ipconfig type : %d\n", ip_type);
761 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
762 printf("Fail to get IP address!\n");
764 printf("IP address : %s\n", ip);
768 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
769 printf("Fail to get subnet mask!\n");
771 printf("Subnet mask : %s\n", subnet);
775 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
776 printf("Fail to get gateway!\n");
778 printf("Gateway : %s\n", gateway);
782 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
783 printf("Fail to get DNS1!\n");
785 printf("DNS1 : %s\n", dns1);
789 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
790 printf("Fail to get DNS2!\n");
792 printf("DNS2 : %s\n", dns2);
796 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
797 printf("Fail to get proxy type!\n");
799 printf("Proxy type : %d\n", proxy_type);
801 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
802 printf("Fail to get proxy!\n");
804 printf("Proxy : %s\n", proxy);
809 int test_register_client(void)
812 int err = connection_create(&connection);
814 if (CONNECTION_ERROR_NONE == err) {
815 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
816 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
817 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
818 connection_set_ethernet_cable_state_chaged_cb(connection,
819 test_get_ethernet_cable_state_callback, NULL);
821 printf("Client registration failed [%s]\n", test_print_error(err));
825 printf("Client registration success\n");
829 int test_deregister_client(void)
833 connection_profile_h profile;
835 if (connection != NULL)
836 rv = connection_destroy(connection);
838 printf("Cannot deregister : Handle is NULL\n");
839 rv = CONNECTION_ERROR_INVALID_OPERATION;
842 if (rv != CONNECTION_ERROR_NONE) {
843 printf("Client deregistration fail [%s]\n", test_print_error(rv));
848 for (list = state_cb_list; list; list = list->next) {
849 profile = list->data;
850 connection_profile_destroy(profile);
853 g_slist_free(state_cb_list);
854 state_cb_list = NULL;
858 printf("Client deregistration success\n");
863 int test_get_network_state(void)
866 connection_type_e net_state;
868 rv = connection_get_type(connection, &net_state);
870 if (rv != CONNECTION_ERROR_NONE) {
871 printf("Fail to get network state [%s]\n", test_print_error(rv));
875 printf("Retval = [%s] network connection state [%s]\n",
876 test_print_error(rv), test_print_connection_type(net_state));
881 int test_get_cellular_state(void)
884 connection_cellular_state_e cellular_state;
886 rv = connection_get_cellular_state(connection, &cellular_state);
888 if (rv != CONNECTION_ERROR_NONE) {
889 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
893 printf("Retval = [%s] Cellular state [%s]\n",
894 test_print_error(rv), test_print_cellular_state(cellular_state));
899 int test_get_wifi_state(void)
902 connection_wifi_state_e wifi_state;
904 rv = connection_get_wifi_state(connection, &wifi_state);
906 if (rv != CONNECTION_ERROR_NONE) {
907 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
911 printf("Retval = [%s] WiFi state [%s]\n",
912 test_print_error(rv), test_print_wifi_state(wifi_state));
917 int test_get_current_proxy(void)
919 char *proxy_addr = NULL;
921 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
923 if (proxy_addr == NULL) {
924 printf("Proxy address does not exist\n");
928 printf("Current Proxy [%s]\n", proxy_addr);
934 int test_get_current_ip(void)
936 char *ip_addr = NULL;
940 rv = test_get_user_int("Input Address type to get"
941 "(1:IPV4, 2:IPV6):", &input);
944 printf("Invalid input!!\n");
950 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
951 if (ip_addr == NULL) {
952 printf("IPv4 address does not exist\n");
955 printf("IPv4 address : %s\n", ip_addr);
959 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
960 if (ip_addr == NULL) {
961 printf("IPv6 address does not exist\n");
964 printf("IPv6 address : %s\n", ip_addr);
967 printf("Wrong IP address family!!\n");
975 int test_get_call_statistics_info(void)
979 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
980 printf("last recv data size [%lld]\n", rv);
981 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
982 printf("last sent data size [%lld]\n", rv);
983 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
984 printf("total received data size [%lld]\n", rv);
985 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
986 printf("total sent data size [%lld]\n", rv);
991 int test_get_wifi_call_statistics_info(void)
995 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
996 printf("WiFi last recv data size [%lld]\n", rv);
997 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
998 printf("WiFi last sent data size [%lld]\n", rv);
999 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1000 printf("WiFi total received data size [%lld]\n", rv);
1001 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1002 printf("WiFi total sent data size [%lld]\n", rv);
1007 int test_get_profile_list(void)
1009 if (test_get_user_selected_profile(NULL, false) == false)
1015 int test_get_default_profile_list(void)
1018 char *profile_name = NULL;
1019 connection_profile_iterator_h profile_iter;
1020 connection_profile_h profile_h;
1021 connection_cellular_service_type_e service_type;
1022 bool is_default = false;
1024 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1025 if (rv != CONNECTION_ERROR_NONE) {
1026 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1030 while (connection_profile_iterator_has_next(profile_iter)) {
1031 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1032 printf("Fail to get profile handle\n");
1036 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1037 printf("Fail to get profile name\n");
1040 printf("profile name : %s\n", profile_name);
1041 g_free(profile_name);
1043 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1044 printf("Fail to get profile service type\n");
1047 printf("service type : %d\n", service_type);
1049 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1050 printf("Fail to get profile subscriber id\n");
1053 printf("Default : %d\n", is_default);
1059 int test_get_connected_profile_list(void)
1062 char *profile_name = NULL;
1063 connection_profile_iterator_h profile_iter;
1064 connection_profile_h profile_h;
1065 bool is_default = false;
1066 connection_profile_type_e type;
1068 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1069 if (rv != CONNECTION_ERROR_NONE) {
1070 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1074 while (connection_profile_iterator_has_next(profile_iter)) {
1075 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1076 printf("Fail to get profile handle\n");
1080 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1081 printf("Fail to get profile name\n");
1084 printf("profile name is %s\n", profile_name);
1085 g_free(profile_name);
1087 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1088 printf("Fail to get profile type\n");
1091 printf("profile type is %d\n", type);
1093 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1094 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1095 printf("Fail to get profile is default\n");
1098 printf("[%s]\n", is_default ? "default" : "not default");
1105 int test_get_current_profile(void)
1108 char *profile_name = NULL;
1109 connection_profile_h profile_h;
1111 rv = connection_get_current_profile(connection, &profile_h);
1112 if (rv != CONNECTION_ERROR_NONE) {
1113 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1117 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1118 printf("Fail to get profile name\n");
1121 printf("profile name : %s\n", profile_name);
1122 g_free(profile_name);
1124 connection_profile_destroy(profile_h);
1129 int test_open_profile(void)
1131 connection_profile_h profile;
1133 printf("\n** Choose a profile to open. **\n");
1135 if (test_get_user_selected_profile(&profile, true) == false)
1138 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1139 printf("Connection open Failed!!\n");
1146 int test_get_default_cellular_service_type(void)
1151 connection_profile_h profile;
1152 char *profile_name = NULL;
1154 rv = test_get_user_int("Input profile type to get"
1155 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1158 printf("Invalid input!!\n");
1164 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1167 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1170 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1173 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1176 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1179 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1182 printf("Wrong number!!\n");
1186 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1189 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1190 printf("Fail to get profile name\n");
1191 connection_profile_destroy(profile);
1194 printf("Default profile name : %s\n", profile_name);
1195 g_free(profile_name);
1197 connection_profile_destroy(profile);
1202 int test_set_default_cellular_service_type(void)
1204 connection_profile_h profile;
1205 connection_cellular_service_type_e type;
1208 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1210 if (rv == false || (input != 1 && input != 2)) {
1211 printf("Invalid input!!\n");
1215 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1217 if (test_get_user_selected_profile(&profile, true) == false)
1220 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1221 printf("Fail to get cellular service type\n");
1226 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1229 if (connection_set_default_cellular_service_profile_async(connection,
1230 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1237 int test_close_profile(void)
1239 connection_profile_h profile;
1241 printf("\n** Choose a profile to close. **\n");
1243 if (test_get_user_selected_profile(&profile, true) == false)
1246 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1247 printf("Connection close Failed!!\n");
1254 int test_add_profile(void)
1257 connection_profile_h profile;
1258 char input_str[100] = {0,};
1260 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1263 g_strstrip(input_str);
1264 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1265 if (rv != CONNECTION_ERROR_NONE)
1266 RETURN_FAIL_DESTROY(profile);
1268 if (test_update_cellular_info(profile) == -1)
1269 RETURN_FAIL_DESTROY(profile);
1271 rv = connection_add_profile(connection, profile);
1272 if (rv != CONNECTION_ERROR_NONE)
1273 RETURN_FAIL_DESTROY(profile);
1275 connection_profile_destroy(profile);
1279 int test_remove_profile(void)
1281 connection_profile_h profile;
1283 printf("\n** Choose a profile to remove. **\n");
1284 if (test_get_user_selected_profile(&profile, true) == false)
1287 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1288 printf("Remove profile Failed!!\n");
1295 int test_update_profile(void)
1299 connection_profile_type_e prof_type;
1300 connection_profile_h profile;
1302 printf("\n** Choose a profile to update. **\n");
1303 if (test_get_user_selected_profile(&profile, true) == false)
1306 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1309 switch (prof_type) {
1310 case CONNECTION_PROFILE_TYPE_CELLULAR:
1311 if (test_update_cellular_info(profile) == -1)
1315 case CONNECTION_PROFILE_TYPE_WIFI:
1316 if (test_update_wifi_info(profile) == -1)
1319 if (test_update_network_info(profile) == -1)
1323 case CONNECTION_PROFILE_TYPE_ETHERNET:
1324 if (test_update_network_info(profile) == -1)
1328 case CONNECTION_PROFILE_TYPE_BT:
1329 printf("Not supported!\n");
1335 rv = connection_update_profile(connection, profile);
1336 if (rv != CONNECTION_ERROR_NONE)
1342 int test_get_profile_info(void)
1344 connection_profile_type_e prof_type;
1345 connection_profile_state_e profile_state;
1346 connection_profile_h profile;
1347 char *profile_name = NULL;
1348 int address_family = 0;
1350 printf("\n** Choose a profile to print. **\n");
1351 if (test_get_user_selected_profile(&profile, true) == false)
1354 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1355 printf("Fail to get profile name\n");
1358 printf("Profile Name : %s\n", profile_name);
1359 g_free(profile_name);
1362 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1363 printf("Fail to get profile state\n");
1366 printf("Profile State : %s\n", test_print_state(profile_state));
1368 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1371 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1373 switch (prof_type) {
1374 case CONNECTION_PROFILE_TYPE_CELLULAR:
1375 printf("Profile Type : Cellular\n");
1376 test_print_cellular_info(profile);
1378 case CONNECTION_PROFILE_TYPE_WIFI:
1379 printf("Profile Type : Wi-Fi\n");
1380 test_print_wifi_info(profile);
1382 case CONNECTION_PROFILE_TYPE_ETHERNET:
1383 printf("Profile Type : Ethernet\n");
1385 case CONNECTION_PROFILE_TYPE_BT:
1386 printf("Profile Type : Bluetooth\n");
1392 test_print_network_info(profile, address_family);
1397 int test_refresh_profile_info(void)
1399 connection_profile_type_e prof_type;
1400 connection_profile_state_e profile_state;
1401 connection_profile_h profile;
1402 char *profile_name = NULL;
1403 int address_family = 0;
1405 printf("\n** Choose a profile to refresh. **\n");
1406 if (test_get_user_selected_profile(&profile, true) == false)
1409 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1412 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1413 printf("Fail to get profile name\n");
1416 printf("Profile Name : %s\n", profile_name);
1417 g_free(profile_name);
1420 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1421 printf("Fail to get profile state\n");
1424 printf("Profile State : %s\n", test_print_state(profile_state));
1427 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1430 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1432 switch (prof_type) {
1433 case CONNECTION_PROFILE_TYPE_CELLULAR:
1434 printf("Profile Type : Cellular\n");
1435 test_print_cellular_info(profile);
1437 case CONNECTION_PROFILE_TYPE_WIFI:
1438 printf("Profile Type : Wi-Fi\n");
1439 test_print_wifi_info(profile);
1441 case CONNECTION_PROFILE_TYPE_ETHERNET:
1442 printf("Profile Type : Ethernet\n");
1444 case CONNECTION_PROFILE_TYPE_BT:
1445 printf("Profile Type : Bluetooth\n");
1451 test_print_network_info(profile, address_family);
1456 int test_set_state_changed_callback()
1458 connection_profile_h profile;
1459 connection_profile_h profile_clone;
1461 printf("\n** Choose a profile to set callback. **\n");
1462 if (test_get_user_selected_profile(&profile, true) == false)
1465 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1468 if (connection_profile_set_state_changed_cb(profile,
1469 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1470 connection_profile_destroy(profile_clone);
1474 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1479 int test_unset_state_changed_callback()
1481 connection_profile_h profile;
1483 char *profile_name = NULL;
1487 printf("\n** Choose a profile to unset callback. **\n");
1488 for (list = state_cb_list; list; list = list->next) {
1489 profile = list->data;
1490 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1491 printf("Fail to get profile name!\n");
1494 printf("%d. %s\n", count, profile_name);
1495 g_free(profile_name);
1501 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1504 printf("Wrong number!!\n");
1509 for (list = state_cb_list; list; list = list->next) {
1510 if (count == input) {
1511 profile = list->data;
1521 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1524 state_cb_list = g_slist_remove(state_cb_list, profile);
1525 connection_profile_destroy(profile);
1530 int test_reset_call_statistics_info(void)
1532 int ret = CONNECTION_ERROR_NONE;
1534 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1535 printf("reset last recv data size [%d]\n", ret);
1536 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1537 printf("last sent data size [%d]\n", ret);
1538 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1539 printf("total received data size [%d]\n", ret);
1540 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1541 printf("total sent data size [%d]\n", ret);
1546 int test_reset_wifi_call_statistics_info(void)
1548 int ret = CONNECTION_ERROR_NONE;
1550 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1551 printf("WiFi last sent data size [%d]\n", ret);
1552 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1553 printf("WiFi last recv data size [%d]\n", ret);
1554 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1555 printf("WiFi total sent data size [%d]\n", ret);
1556 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1557 printf("WiFi total received data size [%d]\n", ret);
1562 int test_add_route(void)
1565 char ip_addr[100] = {0};
1566 char if_name[40] = {0};
1568 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1571 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1574 g_strstrip(ip_addr);
1575 g_strstrip(if_name);
1576 rv = connection_add_route(connection, if_name, ip_addr);
1577 if (rv != CONNECTION_ERROR_NONE) {
1578 printf("Fail to get add new route [%d]\n", rv);
1581 printf("Add Route successfully\n");
1586 int test_remove_route(void)
1589 char ip_addr[100] = {0};
1590 char if_name[40] = {0};
1592 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1595 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1598 g_strstrip(ip_addr);
1599 g_strstrip(if_name);
1600 rv = connection_remove_route(connection, if_name, ip_addr);
1601 if (rv != CONNECTION_ERROR_NONE) {
1602 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1605 printf("Remove Route successfully\n");
1610 int test_add_route_ipv6(void)
1613 char ip_addr[100] = {0};
1614 char gateway[100] = {0};
1615 char if_name[40] = {0};
1617 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1620 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1623 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1626 g_strstrip(ip_addr);
1627 g_strstrip(gateway);
1628 g_strstrip(if_name);
1629 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1630 if (rv != CONNECTION_ERROR_NONE) {
1631 printf("Fail to get add new route [%d]\n", rv);
1634 printf("Add Route successfully\n");
1639 int test_remove_route_ipv6(void)
1642 char ip_addr[100] = {0};
1643 char gateway[100] = {0};
1644 char if_name[40] = {0};
1646 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1649 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1652 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1655 g_strstrip(ip_addr);
1656 g_strstrip(gateway);
1657 g_strstrip(if_name);
1658 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1659 if (rv != CONNECTION_ERROR_NONE) {
1660 printf("Fail to remove the route [%d]\n", rv);
1663 printf("Remove Route successfully\n");
1668 int test_get_bt_state(void)
1671 connection_bt_state_e bt_state;
1673 rv = connection_get_bt_state(connection, &bt_state);
1675 if (rv != CONNECTION_ERROR_NONE) {
1676 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1680 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
1685 int test_get_profile_id(void)
1687 connection_profile_h profile;
1690 printf("\n** Choose a profile to see profile id. **\n");
1691 if (test_get_user_selected_profile(&profile, true) == false)
1694 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1695 printf("Fail to get profile name\n");
1698 printf("Profile id : %s\n", profile_id);
1705 int test_get_mac_address(void)
1707 int rv = 0, type = 0;
1708 connection_type_e conn_type;
1709 char *mac_addr = NULL;
1711 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
1715 conn_type = CONNECTION_TYPE_WIFI;
1718 conn_type = CONNECTION_TYPE_ETHERNET;
1721 printf("Wrong number!!\n");
1725 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
1727 if (rv != CONNECTION_ERROR_NONE) {
1728 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
1732 printf("mac address is %s\n", mac_addr);
1739 int test_get_ethernet_cable_state(void)
1742 connection_ethernet_cable_state_e cable_state;
1744 rv = connection_get_ethernet_cable_state(connection, &cable_state);
1746 if (rv != CONNECTION_ERROR_NONE) {
1747 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
1751 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
1756 int test_reset_profile(void)
1758 int type, sim_id, rv;
1760 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
1762 if (rv == false || (type != 0 && type != 1)) {
1763 printf("Invalid input!!\n");
1767 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
1769 if (rv == false || (sim_id != 0 && sim_id != 1)) {
1770 printf("Invalid input!!\n");
1774 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
1780 int main(int argc, char **argv)
1782 GMainLoop *mainloop;
1783 mainloop = g_main_loop_new(NULL, FALSE);
1785 GIOChannel *channel = g_io_channel_unix_new(0);
1786 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1788 printf("Test Thread created...\n");
1790 g_main_loop_run(mainloop);
1795 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1800 memset(a, '\0', 100);
1801 printf("Event received from stdin\n");
1803 rv = read(0, a, 100);
1805 if (rv < 0 || a[0] == '0') {
1806 if (connection != NULL)
1807 test_deregister_client();
1812 if (*a == '\n' || *a == '\r') {
1813 printf("\n\n Network Connection API Test App\n\n");
1814 printf("Options..\n");
1815 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
1816 printf("2 - Destroy Handle(unset callbacks automatically)\n");
1817 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
1818 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
1819 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
1820 printf("6 - Get current proxy address \n");
1821 printf("7 - Get current Ip address\n");
1822 printf("8 - Get cellular data call statistics\n");
1823 printf("9 - Get WiFi data call statistics\n");
1824 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
1825 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
1826 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
1827 printf("d - Open connection with profile\n");
1828 printf("e - Get default cellular service by type\n");
1829 printf("f - Set default cellular service by type\n");
1830 printf("g - Close connection with profile\n");
1831 printf("h - Add profile(Cellular and Wifi only)\n");
1832 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
1833 printf("j - Update profile\n");
1834 printf("k - Get profile info\n");
1835 printf("l - Refresh profile info\n");
1836 printf("m - Set state changed callback\n");
1837 printf("n - Unset state changed callback\n");
1838 printf("o - Reset cellular data call statistics\n");
1839 printf("p - Reset WiFi data call statistics\n");
1840 printf("q - Add new route\n");
1841 printf("r - Remove a route\n");
1842 printf("s - Get Bluetooth state\n");
1843 printf("t - Get profile id\n");
1844 printf("u - Reset profile\n");
1845 printf("v - Get all cellular default profiles\n");
1846 printf("w - Get mac address\n");
1847 printf("x - Get ethernet cable state\n");
1848 printf("B - Add IPv6 new route\n");
1849 printf("C - Remove IPv6 route\n");
1850 printf(LOG_RED "0 - Exit \n" LOG_END);
1851 printf("ENTER - Show options menu.......\n");
1856 rv = test_register_client();
1859 rv = test_deregister_client();
1862 rv = test_get_network_state();
1865 rv = test_get_cellular_state();
1868 rv = test_get_wifi_state();
1871 rv = test_get_current_proxy();
1874 rv = test_get_current_ip();
1877 rv = test_get_call_statistics_info();
1880 rv = test_get_wifi_call_statistics_info();
1883 rv = test_get_profile_list();
1886 rv = test_get_connected_profile_list();
1889 rv = test_get_current_profile();
1892 rv = test_open_profile();
1895 rv = test_get_default_cellular_service_type();
1898 rv = test_set_default_cellular_service_type();
1901 rv = test_close_profile();
1904 rv = test_add_profile();
1907 rv = test_remove_profile();
1910 rv = test_update_profile();
1913 rv = test_get_profile_info();
1916 rv = test_refresh_profile_info();
1919 rv = test_set_state_changed_callback();
1922 rv = test_unset_state_changed_callback();
1925 rv = test_reset_call_statistics_info();
1928 rv = test_reset_wifi_call_statistics_info();
1931 rv = test_add_route();
1934 rv = test_remove_route();
1937 rv = test_get_bt_state();
1940 rv = test_get_profile_id();
1943 rv = test_reset_profile();
1946 rv = test_get_default_profile_list();
1949 rv = test_get_mac_address();
1952 rv = test_get_ethernet_cable_state();
1955 rv = test_add_route_ipv6();
1958 rv = test_remove_route_ipv6();
1963 printf("Operation succeeded!\n");
1965 printf("Operation failed!\n");