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)
463 if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
466 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
469 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
472 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
476 if (rv != CONNECTION_ERROR_NONE)
480 if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
483 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
486 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
489 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
493 if (rv != CONNECTION_ERROR_NONE)
500 static int test_update_wifi_info(connection_profile_h profile)
503 char input_str[100] = {0,};
505 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
506 rv = connection_profile_set_wifi_passphrase(profile, input_str);
507 if (rv != CONNECTION_ERROR_NONE)
514 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
517 char input_str[100] = {0,};
519 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
520 rv = connection_profile_set_ip_address(profile,
523 if (rv != CONNECTION_ERROR_NONE)
527 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
528 rv = connection_profile_set_subnet_mask(profile,
531 if (rv != CONNECTION_ERROR_NONE)
535 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
536 rv = connection_profile_set_gateway_address(profile,
539 if (rv != CONNECTION_ERROR_NONE)
543 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
544 rv = connection_profile_set_dns_address(profile,
548 if (rv != CONNECTION_ERROR_NONE)
551 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
552 rv = connection_profile_set_dns_address(profile,
556 if (rv != CONNECTION_ERROR_NONE)
564 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
568 char input_str[100] = {0,};
570 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
571 " - (Enter for skip) :", &input_int)) {
574 rv = connection_profile_set_proxy_type(profile,
575 CONNECTION_PROXY_TYPE_DIRECT);
577 if (rv != CONNECTION_ERROR_NONE)
582 rv = connection_profile_set_proxy_type(profile,
583 CONNECTION_PROXY_TYPE_AUTO);
586 rv = connection_profile_set_proxy_type(profile,
587 CONNECTION_PROXY_TYPE_MANUAL);
593 if (rv != CONNECTION_ERROR_NONE)
596 if (test_get_user_string("Input auto Proxy URL or Proxy address"
597 " - (Enter for skip) :", input_str, 100)) {
598 rv = connection_profile_set_proxy_address(profile,
601 if (rv != CONNECTION_ERROR_NONE)
611 static int test_update_network_info(connection_profile_h profile)
615 int address_family = 0;
617 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
619 if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
620 " - (Enter for skip) :", &input_int)) {
623 rv = connection_profile_set_ip_config_type(profile,
625 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
628 rv = connection_profile_set_ip_config_type(profile,
630 CONNECTION_IP_CONFIG_TYPE_STATIC);
631 if (rv != CONNECTION_ERROR_NONE)
634 if (test_update_ip_info(profile, address_family) == -1)
637 if (test_update_proxy_info(profile, address_family) == -1)
644 if (rv != CONNECTION_ERROR_NONE)
652 static void test_print_cellular_info(connection_profile_h profile)
654 connection_cellular_service_type_e service_type;
655 connection_cellular_pdn_type_e pdn_type;
656 connection_cellular_pdn_type_e roam_pdn_type;
658 connection_cellular_auth_type_e auth_type;
659 char *user_name = NULL;
660 char *password = NULL;
661 char *home_url = NULL;
662 bool roaming = false;
664 bool editable = false;
666 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
667 printf("Fail to get cellular service type!\n");
669 printf("Cellular service type : %d\n", service_type);
671 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
672 printf("Fail to get cellular pdn type!\n");
674 printf("Cellular pdn type : %d\n", pdn_type);
676 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
677 printf("Fail to get cellular roam pdn type!\n");
679 printf("Cellular roam pdn type : %d\n", roam_pdn_type);
681 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
682 printf("Fail to get cellular APN!\n");
684 printf("Cellular APN : %s\n", apn);
688 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
689 printf("Fail to get auth info!\n");
691 printf("Cellular auth type : %d\n", auth_type);
692 printf("Cellular user_name : %s\n", user_name);
693 printf("Cellular password : %s\n", password);
698 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
699 printf("Fail to get cellular home url!\n");
701 printf("Cellular home url : %s\n", home_url);
705 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
706 printf("Fail to get cellular roaming state!\n");
708 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
710 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
711 printf("Fail to get cellular hidden state!\n");
713 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
715 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
716 printf("Fail to get cellular editing state!\n");
718 printf("Cellular editable : %s\n", editable ? "true" : "false");
721 static void test_print_wifi_info(connection_profile_h profile)
728 connection_wifi_security_type_e security_type;
729 connection_wifi_encryption_type_e encryption_type;
730 bool pass_required = false;
731 bool wps_supported = false;
733 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
734 printf("Fail to get Wi-Fi essid!\n");
736 printf("Wi-Fi essid : %s\n", essid);
740 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
741 printf("Fail to get Wi-Fi bssid!\n");
743 printf("Wi-Fi bssid : %s\n", bssid);
747 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
748 printf("Fail to get Wi-Fi rssi!\n");
750 printf("Wi-Fi rssi : %d\n", rssi);
752 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
753 printf("Fail to get Wi-Fi frequency!\n");
755 printf("Wi-Fi frequency : %d\n", frequency);
757 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
758 printf("Fail to get Wi-Fi max speed!\n");
760 printf("Wi-Fi max speed : %d\n", max_speed);
762 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
763 printf("Fail to get Wi-Fi security type!\n");
765 printf("Wi-Fi security type : %d\n", security_type);
767 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
768 printf("Fail to get Wi-Fi encryption type!\n");
770 printf("Wi-Fi encryption type : %d\n", encryption_type);
772 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
773 printf("Fail to get Wi-Fi passphrase required!\n");
775 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
777 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
778 printf("Fail to get Wi-Fi wps info\n");
780 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
783 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
785 char *interface_name = NULL;
786 connection_ip_config_type_e ip_type;
789 char *gateway = NULL;
792 connection_proxy_type_e proxy_type;
795 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
796 printf("Fail to get interface name!\n");
798 printf("Interface name : %s\n", interface_name);
799 g_free(interface_name);
802 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
803 printf("Fail to get ipconfig type!\n");
805 printf("Ipconfig type : %d\n", ip_type);
807 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
808 printf("Fail to get IP address!\n");
810 printf("IP address : %s\n", ip);
814 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
815 printf("Fail to get subnet mask!\n");
817 printf("Subnet mask : %s\n", subnet);
821 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
822 printf("Fail to get gateway!\n");
824 printf("Gateway : %s\n", gateway);
828 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
829 printf("Fail to get DNS1!\n");
831 printf("DNS1 : %s\n", dns1);
835 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
836 printf("Fail to get DNS2!\n");
838 printf("DNS2 : %s\n", dns2);
842 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
843 printf("Fail to get proxy type!\n");
845 printf("Proxy type : %d\n", proxy_type);
847 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
848 printf("Fail to get proxy!\n");
850 printf("Proxy : %s\n", proxy);
855 int test_register_client(void)
858 int err = connection_create(&connection);
860 if (CONNECTION_ERROR_NONE == err) {
861 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
862 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
863 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
864 connection_set_ethernet_cable_state_chaged_cb(connection,
865 test_get_ethernet_cable_state_callback, NULL);
867 printf("Client registration failed [%s]\n", test_print_error(err));
871 printf("Client registration success\n");
875 int test_deregister_client(void)
879 connection_profile_h profile;
881 if (connection != NULL)
882 rv = connection_destroy(connection);
884 printf("Cannot deregister : Handle is NULL\n");
885 rv = CONNECTION_ERROR_INVALID_OPERATION;
888 if (rv != CONNECTION_ERROR_NONE) {
889 printf("Client deregistration fail [%s]\n", test_print_error(rv));
894 for (list = state_cb_list; list; list = list->next) {
895 profile = list->data;
896 connection_profile_destroy(profile);
899 g_slist_free(state_cb_list);
900 state_cb_list = NULL;
904 printf("Client deregistration success\n");
909 int test_get_network_state(void)
912 connection_type_e net_state;
914 rv = connection_get_type(connection, &net_state);
916 if (rv != CONNECTION_ERROR_NONE) {
917 printf("Fail to get network state [%s]\n", test_print_error(rv));
921 printf("Retval = [%s] network connection state [%s]\n",
922 test_print_error(rv), test_print_connection_type(net_state));
927 int test_get_cellular_state(void)
930 connection_cellular_state_e cellular_state;
932 rv = connection_get_cellular_state(connection, &cellular_state);
934 if (rv != CONNECTION_ERROR_NONE) {
935 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
939 printf("Retval = [%s] Cellular state [%s]\n",
940 test_print_error(rv), test_print_cellular_state(cellular_state));
945 int test_get_wifi_state(void)
948 connection_wifi_state_e wifi_state;
950 rv = connection_get_wifi_state(connection, &wifi_state);
952 if (rv != CONNECTION_ERROR_NONE) {
953 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
957 printf("Retval = [%s] WiFi state [%s]\n",
958 test_print_error(rv), test_print_wifi_state(wifi_state));
963 int test_get_current_proxy(void)
965 char *proxy_addr = NULL;
967 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
969 if (proxy_addr == NULL) {
970 printf("Proxy address does not exist\n");
974 printf("Current Proxy [%s]\n", proxy_addr);
980 int test_get_current_ip(void)
982 char *ip_addr = NULL;
986 rv = test_get_user_int("Input Address type to get"
987 "(1:IPV4, 2:IPV6):", &input);
990 printf("Invalid input!!\n");
996 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
997 if (ip_addr == NULL) {
998 printf("IPv4 address does not exist\n");
1001 printf("IPv4 address : %s\n", ip_addr);
1005 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1006 if (ip_addr == NULL) {
1007 printf("IPv6 address does not exist\n");
1010 printf("IPv6 address : %s\n", ip_addr);
1013 printf("Wrong IP address family!!\n");
1021 int test_get_call_statistics_info(void)
1025 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1026 printf("last recv data size [%lld]\n", rv);
1027 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1028 printf("last sent data size [%lld]\n", rv);
1029 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1030 printf("total received data size [%lld]\n", rv);
1031 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1032 printf("total sent data size [%lld]\n", rv);
1037 int test_get_wifi_call_statistics_info(void)
1041 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1042 printf("WiFi last recv data size [%lld]\n", rv);
1043 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1044 printf("WiFi last sent data size [%lld]\n", rv);
1045 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1046 printf("WiFi total received data size [%lld]\n", rv);
1047 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1048 printf("WiFi total sent data size [%lld]\n", rv);
1053 int test_get_profile_list(void)
1055 if (test_get_user_selected_profile(NULL, false) == false)
1061 int test_get_default_profile_list(void)
1064 char *profile_name = NULL;
1065 connection_profile_iterator_h profile_iter;
1066 connection_profile_h profile_h;
1067 connection_cellular_service_type_e service_type;
1068 bool is_default = false;
1070 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1071 if (rv != CONNECTION_ERROR_NONE) {
1072 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1076 while (connection_profile_iterator_has_next(profile_iter)) {
1077 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1078 printf("Fail to get profile handle\n");
1082 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1083 printf("Fail to get profile name\n");
1086 printf("profile name : %s\n", profile_name);
1087 g_free(profile_name);
1089 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1090 printf("Fail to get profile service type\n");
1093 printf("service type : %d\n", service_type);
1095 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1096 printf("Fail to get profile subscriber id\n");
1099 printf("Default : %d\n", is_default);
1105 int test_get_connected_profile_list(void)
1108 char *profile_name = NULL;
1109 connection_profile_iterator_h profile_iter;
1110 connection_profile_h profile_h;
1111 bool is_default = false;
1112 connection_profile_type_e type;
1114 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1115 if (rv != CONNECTION_ERROR_NONE) {
1116 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1120 while (connection_profile_iterator_has_next(profile_iter)) {
1121 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1122 printf("Fail to get profile handle\n");
1126 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1127 printf("Fail to get profile name\n");
1130 printf("profile name is %s\n", profile_name);
1131 g_free(profile_name);
1133 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1134 printf("Fail to get profile type\n");
1137 printf("profile type is %d\n", type);
1139 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1140 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1141 printf("Fail to get profile is default\n");
1144 printf("[%s]\n", is_default ? "default" : "not default");
1151 int test_get_current_profile(void)
1154 char *profile_name = NULL;
1155 connection_profile_h profile_h;
1157 rv = connection_get_current_profile(connection, &profile_h);
1158 if (rv != CONNECTION_ERROR_NONE) {
1159 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1163 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1164 printf("Fail to get profile name\n");
1167 printf("profile name : %s\n", profile_name);
1168 g_free(profile_name);
1170 connection_profile_destroy(profile_h);
1175 int test_open_profile(void)
1177 connection_profile_h profile;
1179 printf("\n** Choose a profile to open. **\n");
1181 if (test_get_user_selected_profile(&profile, true) == false)
1184 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1185 printf("Connection open Failed!!\n");
1192 int test_get_default_cellular_service_type(void)
1197 connection_profile_h profile;
1198 char *profile_name = NULL;
1200 rv = test_get_user_int("Input profile type to get"
1201 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1204 printf("Invalid input!!\n");
1210 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1213 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1216 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1219 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1222 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1225 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1228 printf("Wrong number!!\n");
1232 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1235 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1236 printf("Fail to get profile name\n");
1237 connection_profile_destroy(profile);
1240 printf("Default profile name : %s\n", profile_name);
1241 g_free(profile_name);
1243 connection_profile_destroy(profile);
1248 int test_set_default_cellular_service_type(void)
1250 connection_profile_h profile;
1251 connection_cellular_service_type_e type;
1254 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1256 if (rv == false || (input != 1 && input != 2)) {
1257 printf("Invalid input!!\n");
1261 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1263 if (test_get_user_selected_profile(&profile, true) == false)
1266 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1267 printf("Fail to get cellular service type\n");
1272 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1275 if (connection_set_default_cellular_service_profile_async(connection,
1276 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1283 int test_close_profile(void)
1285 connection_profile_h profile;
1287 printf("\n** Choose a profile to close. **\n");
1289 if (test_get_user_selected_profile(&profile, true) == false)
1292 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1293 printf("Connection close Failed!!\n");
1300 int test_add_profile(void)
1303 connection_profile_h profile;
1304 char input_str[100] = {0,};
1306 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1309 g_strstrip(input_str);
1310 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1311 if (rv != CONNECTION_ERROR_NONE)
1312 RETURN_FAIL_DESTROY(profile);
1314 if (test_update_cellular_info(profile) == -1)
1315 RETURN_FAIL_DESTROY(profile);
1317 rv = connection_add_profile(connection, profile);
1318 if (rv != CONNECTION_ERROR_NONE)
1319 RETURN_FAIL_DESTROY(profile);
1321 connection_profile_destroy(profile);
1325 int test_remove_profile(void)
1327 connection_profile_h profile;
1329 printf("\n** Choose a profile to remove. **\n");
1330 if (test_get_user_selected_profile(&profile, true) == false)
1333 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1334 printf("Remove profile Failed!!\n");
1341 int test_update_profile(void)
1345 connection_profile_type_e prof_type;
1346 connection_profile_h profile;
1348 printf("\n** Choose a profile to update. **\n");
1349 if (test_get_user_selected_profile(&profile, true) == false)
1352 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1355 switch (prof_type) {
1356 case CONNECTION_PROFILE_TYPE_CELLULAR:
1357 if (test_update_cellular_info(profile) == -1)
1361 case CONNECTION_PROFILE_TYPE_WIFI:
1362 if (test_update_wifi_info(profile) == -1)
1365 if (test_update_network_info(profile) == -1)
1369 case CONNECTION_PROFILE_TYPE_ETHERNET:
1370 if (test_update_network_info(profile) == -1)
1374 case CONNECTION_PROFILE_TYPE_BT:
1375 printf("Not supported!\n");
1381 rv = connection_update_profile(connection, profile);
1382 if (rv != CONNECTION_ERROR_NONE)
1388 int test_get_profile_info(void)
1390 connection_profile_type_e prof_type;
1391 connection_profile_state_e profile_state;
1392 connection_profile_h profile;
1393 char *profile_name = NULL;
1394 int address_family = 0;
1396 printf("\n** Choose a profile to print. **\n");
1397 if (test_get_user_selected_profile(&profile, true) == false)
1400 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1401 printf("Fail to get profile name\n");
1404 printf("Profile Name : %s\n", profile_name);
1405 g_free(profile_name);
1408 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1409 printf("Fail to get profile state\n");
1412 printf("Profile State : %s\n", test_print_state(profile_state));
1414 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1417 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1419 switch (prof_type) {
1420 case CONNECTION_PROFILE_TYPE_CELLULAR:
1421 printf("Profile Type : Cellular\n");
1422 test_print_cellular_info(profile);
1424 case CONNECTION_PROFILE_TYPE_WIFI:
1425 printf("Profile Type : Wi-Fi\n");
1426 test_print_wifi_info(profile);
1428 case CONNECTION_PROFILE_TYPE_ETHERNET:
1429 printf("Profile Type : Ethernet\n");
1431 case CONNECTION_PROFILE_TYPE_BT:
1432 printf("Profile Type : Bluetooth\n");
1438 test_print_network_info(profile, address_family);
1443 int test_refresh_profile_info(void)
1445 connection_profile_type_e prof_type;
1446 connection_profile_state_e profile_state;
1447 connection_profile_h profile;
1448 char *profile_name = NULL;
1449 int address_family = 0;
1451 printf("\n** Choose a profile to refresh. **\n");
1452 if (test_get_user_selected_profile(&profile, true) == false)
1455 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1458 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1459 printf("Fail to get profile name\n");
1462 printf("Profile Name : %s\n", profile_name);
1463 g_free(profile_name);
1466 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1467 printf("Fail to get profile state\n");
1470 printf("Profile State : %s\n", test_print_state(profile_state));
1473 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1476 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1478 switch (prof_type) {
1479 case CONNECTION_PROFILE_TYPE_CELLULAR:
1480 printf("Profile Type : Cellular\n");
1481 test_print_cellular_info(profile);
1483 case CONNECTION_PROFILE_TYPE_WIFI:
1484 printf("Profile Type : Wi-Fi\n");
1485 test_print_wifi_info(profile);
1487 case CONNECTION_PROFILE_TYPE_ETHERNET:
1488 printf("Profile Type : Ethernet\n");
1490 case CONNECTION_PROFILE_TYPE_BT:
1491 printf("Profile Type : Bluetooth\n");
1497 test_print_network_info(profile, address_family);
1502 int test_set_state_changed_callback()
1504 connection_profile_h profile;
1505 connection_profile_h profile_clone;
1507 printf("\n** Choose a profile to set callback. **\n");
1508 if (test_get_user_selected_profile(&profile, true) == false)
1511 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1514 if (connection_profile_set_state_changed_cb(profile,
1515 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1516 connection_profile_destroy(profile_clone);
1520 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1525 int test_unset_state_changed_callback()
1527 connection_profile_h profile;
1529 char *profile_name = NULL;
1533 printf("\n** Choose a profile to unset callback. **\n");
1534 for (list = state_cb_list; list; list = list->next) {
1535 profile = list->data;
1536 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1537 printf("Fail to get profile name!\n");
1540 printf("%d. %s\n", count, profile_name);
1541 g_free(profile_name);
1547 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1550 printf("Wrong number!!\n");
1555 for (list = state_cb_list; list; list = list->next) {
1556 if (count == input) {
1557 profile = list->data;
1567 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1570 state_cb_list = g_slist_remove(state_cb_list, profile);
1571 connection_profile_destroy(profile);
1576 int test_reset_call_statistics_info(void)
1578 int ret = CONNECTION_ERROR_NONE;
1580 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1581 printf("reset last recv data size [%d]\n", ret);
1582 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1583 printf("last sent data size [%d]\n", ret);
1584 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1585 printf("total received data size [%d]\n", ret);
1586 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1587 printf("total sent data size [%d]\n", ret);
1592 int test_reset_wifi_call_statistics_info(void)
1594 int ret = CONNECTION_ERROR_NONE;
1596 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1597 printf("WiFi last sent data size [%d]\n", ret);
1598 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1599 printf("WiFi last recv data size [%d]\n", ret);
1600 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1601 printf("WiFi total sent data size [%d]\n", ret);
1602 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1603 printf("WiFi total received data size [%d]\n", ret);
1608 int test_add_route(void)
1611 char ip_addr[100] = {0};
1612 char if_name[40] = {0};
1614 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1617 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1620 g_strstrip(ip_addr);
1621 g_strstrip(if_name);
1622 rv = connection_add_route(connection, if_name, ip_addr);
1623 if (rv != CONNECTION_ERROR_NONE) {
1624 printf("Fail to get add new route [%d]\n", rv);
1627 printf("Add Route successfully\n");
1632 int test_remove_route(void)
1635 char ip_addr[100] = {0};
1636 char if_name[40] = {0};
1638 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1641 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1644 g_strstrip(ip_addr);
1645 g_strstrip(if_name);
1646 rv = connection_remove_route(connection, if_name, ip_addr);
1647 if (rv != CONNECTION_ERROR_NONE) {
1648 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1651 printf("Remove Route successfully\n");
1656 int test_add_route_ipv6(void)
1659 char ip_addr[100] = {0};
1660 char gateway[100] = {0};
1661 char if_name[40] = {0};
1663 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1666 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1669 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1672 g_strstrip(ip_addr);
1673 g_strstrip(gateway);
1674 g_strstrip(if_name);
1675 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1676 if (rv != CONNECTION_ERROR_NONE) {
1677 printf("Fail to get add new route [%d]\n", rv);
1680 printf("Add Route successfully\n");
1685 int test_remove_route_ipv6(void)
1688 char ip_addr[100] = {0};
1689 char gateway[100] = {0};
1690 char if_name[40] = {0};
1692 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1695 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1698 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1701 g_strstrip(ip_addr);
1702 g_strstrip(gateway);
1703 g_strstrip(if_name);
1704 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1705 if (rv != CONNECTION_ERROR_NONE) {
1706 printf("Fail to remove the route [%d]\n", rv);
1709 printf("Remove Route successfully\n");
1714 int test_get_bt_state(void)
1717 connection_bt_state_e bt_state;
1719 rv = connection_get_bt_state(connection, &bt_state);
1721 if (rv != CONNECTION_ERROR_NONE) {
1722 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1726 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
1731 int test_get_profile_id(void)
1733 connection_profile_h profile;
1736 printf("\n** Choose a profile to see profile id. **\n");
1737 if (test_get_user_selected_profile(&profile, true) == false)
1740 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1741 printf("Fail to get profile name\n");
1744 printf("Profile id : %s\n", profile_id);
1751 int test_get_mac_address(void)
1753 int rv = 0, type = 0;
1754 connection_type_e conn_type;
1755 char *mac_addr = NULL;
1757 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
1761 conn_type = CONNECTION_TYPE_WIFI;
1764 conn_type = CONNECTION_TYPE_ETHERNET;
1767 printf("Wrong number!!\n");
1771 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
1773 if (rv != CONNECTION_ERROR_NONE) {
1774 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
1778 printf("mac address is %s\n", mac_addr);
1785 int test_get_ethernet_cable_state(void)
1788 connection_ethernet_cable_state_e cable_state;
1790 rv = connection_get_ethernet_cable_state(connection, &cable_state);
1792 if (rv != CONNECTION_ERROR_NONE) {
1793 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
1797 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
1802 int test_reset_profile(void)
1804 int type, sim_id, rv;
1806 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
1808 if (rv == false || (type != 0 && type != 1)) {
1809 printf("Invalid input!!\n");
1813 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
1815 if (rv == false || (sim_id != 0 && sim_id != 1)) {
1816 printf("Invalid input!!\n");
1820 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
1826 int main(int argc, char **argv)
1828 GMainLoop *mainloop;
1829 mainloop = g_main_loop_new(NULL, FALSE);
1831 GIOChannel *channel = g_io_channel_unix_new(0);
1832 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1834 printf("Test Thread created...\n");
1836 g_main_loop_run(mainloop);
1841 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1846 memset(a, '\0', 100);
1847 printf("Event received from stdin\n");
1849 rv = read(0, a, 100);
1851 if (rv < 0 || a[0] == '0') {
1852 if (connection != NULL)
1853 test_deregister_client();
1858 if (*a == '\n' || *a == '\r') {
1859 printf("\n\n Network Connection API Test App\n\n");
1860 printf("Options..\n");
1861 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
1862 printf("2 - Destroy Handle(unset callbacks automatically)\n");
1863 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
1864 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
1865 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
1866 printf("6 - Get current proxy address \n");
1867 printf("7 - Get current Ip address\n");
1868 printf("8 - Get cellular data call statistics\n");
1869 printf("9 - Get WiFi data call statistics\n");
1870 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
1871 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
1872 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
1873 printf("d - Open connection with profile\n");
1874 printf("e - Get default cellular service by type\n");
1875 printf("f - Set default cellular service by type\n");
1876 printf("g - Close connection with profile\n");
1877 printf("h - Add profile(Cellular and Wifi only)\n");
1878 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
1879 printf("j - Update profile\n");
1880 printf("k - Get profile info\n");
1881 printf("l - Refresh profile info\n");
1882 printf("m - Set state changed callback\n");
1883 printf("n - Unset state changed callback\n");
1884 printf("o - Reset cellular data call statistics\n");
1885 printf("p - Reset WiFi data call statistics\n");
1886 printf("q - Add new route\n");
1887 printf("r - Remove a route\n");
1888 printf("s - Get Bluetooth state\n");
1889 printf("t - Get profile id\n");
1890 printf("u - Reset profile\n");
1891 printf("v - Get all cellular default profiles\n");
1892 printf("w - Get mac address\n");
1893 printf("x - Get ethernet cable state\n");
1894 printf("B - Add IPv6 new route\n");
1895 printf("C - Remove IPv6 route\n");
1896 printf(LOG_RED "0 - Exit \n" LOG_END);
1897 printf("ENTER - Show options menu.......\n");
1902 rv = test_register_client();
1905 rv = test_deregister_client();
1908 rv = test_get_network_state();
1911 rv = test_get_cellular_state();
1914 rv = test_get_wifi_state();
1917 rv = test_get_current_proxy();
1920 rv = test_get_current_ip();
1923 rv = test_get_call_statistics_info();
1926 rv = test_get_wifi_call_statistics_info();
1929 rv = test_get_profile_list();
1932 rv = test_get_connected_profile_list();
1935 rv = test_get_current_profile();
1938 rv = test_open_profile();
1941 rv = test_get_default_cellular_service_type();
1944 rv = test_set_default_cellular_service_type();
1947 rv = test_close_profile();
1950 rv = test_add_profile();
1953 rv = test_remove_profile();
1956 rv = test_update_profile();
1959 rv = test_get_profile_info();
1962 rv = test_refresh_profile_info();
1965 rv = test_set_state_changed_callback();
1968 rv = test_unset_state_changed_callback();
1971 rv = test_reset_call_statistics_info();
1974 rv = test_reset_wifi_call_statistics_info();
1977 rv = test_add_route();
1980 rv = test_remove_route();
1983 rv = test_get_bt_state();
1986 rv = test_get_profile_id();
1989 rv = test_reset_profile();
1992 rv = test_get_default_profile_list();
1995 rv = test_get_mac_address();
1998 rv = test_get_ethernet_cable_state();
2001 rv = test_add_route_ipv6();
2004 rv = test_remove_route_ipv6();
2009 printf("Operation succeeded!\n");
2011 printf("Operation failed!\n");