2 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "net_connection.h"
26 #include <tizen_error.h>
28 #define LOG_RED "\033[0;31m"
29 #define LOG_GREEN "\033[0;32m"
30 #define LOG_BROWN "\033[0;33m"
31 #define LOG_BLUE "\033[0;34m"
32 #define LOG_END "\033[0;m"
34 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
36 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
38 connection_h connection = NULL;
39 static GSList *state_cb_list = NULL;
42 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
44 if (msg == NULL || buf == NULL || buf_size < 2)
49 memset(buf, 0, buf_size);
50 rv = read(0, buf, buf_size - 1);
52 if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
61 static bool test_get_user_int(const char *msg, int *num)
63 if (msg == NULL || num == NULL)
69 rv = read(0, buf, 32);
71 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
78 static const char *test_print_state(connection_profile_state_e state)
81 case CONNECTION_PROFILE_STATE_DISCONNECTED:
82 return "Disconnected";
83 case CONNECTION_PROFILE_STATE_ASSOCIATION:
85 case CONNECTION_PROFILE_STATE_CONFIGURATION:
86 return "Configuration";
87 case CONNECTION_PROFILE_STATE_CONNECTED:
94 static const char *test_print_connection_type(connection_type_e type)
97 case CONNECTION_TYPE_DISCONNECTED:
98 return "Disconnected";
99 case CONNECTION_TYPE_WIFI:
101 case CONNECTION_TYPE_CELLULAR:
103 case CONNECTION_TYPE_ETHERNET:
105 case CONNECTION_TYPE_BT:
107 case CONNECTION_TYPE_NET_PROXY:
114 static const char *test_print_cellular_state(connection_cellular_state_e state)
117 case CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE:
118 return "Out of service";
119 case CONNECTION_CELLULAR_STATE_FLIGHT_MODE:
120 return "Flight mode";
121 case CONNECTION_CELLULAR_STATE_ROAMING_OFF:
122 return "Roaming off";
123 case CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE:
124 return "Call only available";
125 case CONNECTION_CELLULAR_STATE_AVAILABLE:
127 case CONNECTION_CELLULAR_STATE_CONNECTED:
134 static const char *test_print_wifi_state(connection_wifi_state_e state)
137 case CONNECTION_WIFI_STATE_DEACTIVATED:
138 return "Deactivated";
139 case CONNECTION_WIFI_STATE_DISCONNECTED:
140 return "Disconnected";
141 case CONNECTION_WIFI_STATE_CONNECTED:
148 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
151 case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
153 case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
155 case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
157 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
158 return "Prepaid internet";
159 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
160 return "Prepaid MMS";
161 case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
163 case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
164 return "Application";
170 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
173 case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
175 case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
177 case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
183 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
186 case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
188 case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
190 case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
192 case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
198 static const char *test_print_error(connection_error_e error)
201 case CONNECTION_ERROR_NONE:
202 return "CONNECTION_ERROR_NONE";
203 case CONNECTION_ERROR_INVALID_PARAMETER:
204 return "CONNECTION_ERROR_INVALID_PARAMETER";
205 case CONNECTION_ERROR_OUT_OF_MEMORY:
206 return "CONNECTION_ERROR_OUT_OF_MEMORY";
207 case CONNECTION_ERROR_INVALID_OPERATION:
208 return "CONNECTION_ERROR_INVALID_OPERATION";
209 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
210 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
211 case CONNECTION_ERROR_OPERATION_FAILED:
212 return "CONNECTION_ERROR_OPERATION_FAILED";
213 case CONNECTION_ERROR_ITERATOR_END:
214 return "CONNECTION_ERROR_ITERATOR_END";
215 case CONNECTION_ERROR_NO_CONNECTION:
216 return "CONNECTION_ERROR_NO_CONNECTION";
217 case CONNECTION_ERROR_NOW_IN_PROGRESS:
218 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
219 case CONNECTION_ERROR_ALREADY_EXISTS:
220 return "CONNECTION_ERROR_ALREADY_EXISTS";
221 case CONNECTION_ERROR_OPERATION_ABORTED:
222 return "CONNECTION_ERROR_OPERATION_ABORTED";
223 case CONNECTION_ERROR_DHCP_FAILED:
224 return "CONNECTION_ERROR_DHCP_FAILED";
225 case CONNECTION_ERROR_INVALID_KEY:
226 return "CONNECTION_ERROR_INVALID_KEY";
227 case CONNECTION_ERROR_NO_REPLY:
228 return "CONNECTION_ERROR_NO_REPLY";
229 case CONNECTION_ERROR_PERMISSION_DENIED:
230 return "CONNECTION_ERROR_PERMISSION_DENIED";
231 case CONNECTION_ERROR_NOT_SUPPORTED:
232 return "CONNECTION_ERROR_NOT_SUPPORTED";
234 return "CONNECTION_ERROR_UNKNOWN";
238 static void test_type_changed_callback(connection_type_e type, void* user_data)
240 printf("Type changed callback, connection type : %d\n", type);
243 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
245 printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
246 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
249 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
251 printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
252 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
255 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
258 connection_profile_h profile = user_data;
263 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
266 printf("[%s] : %s\n", test_print_state(state), profile_name);
267 g_free(profile_name);
270 static void test_connection_opened_callback(connection_error_e result, void* user_data)
272 if (result == CONNECTION_ERROR_NONE)
273 printf("Connection open Succeeded\n");
275 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
278 static void test_connection_closed_callback(connection_error_e result, void* user_data)
280 if (result == CONNECTION_ERROR_NONE)
281 printf("Connection close Succeeded\n");
283 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
286 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
288 if (result == CONNECTION_ERROR_NONE)
289 printf("Reset profile Succeeded\n");
291 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
294 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
296 if (result == CONNECTION_ERROR_NONE)
297 printf("Default profile setting Succeeded\n");
299 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
302 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
305 if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
306 printf("Ethernet Cable Connected\n");
307 else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
308 printf("Ethernet Cable Disconnected\n");
311 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
316 connection_profile_type_e profile_type;
317 connection_profile_state_e profile_state;
318 connection_profile_iterator_h profile_iter;
319 connection_profile_h profile_h;
321 connection_profile_h profile_list[100] = {0,};
322 int profile_count = 0;
324 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
325 if (rv != CONNECTION_ERROR_NONE) {
326 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
330 while (connection_profile_iterator_has_next(profile_iter)) {
331 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
332 printf("Fail to get profile handle\n");
336 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
337 printf("Fail to get profile name\n");
341 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
342 printf("Fail to get profile type\n");
343 g_free(profile_name);
347 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
348 printf("Fail to get profile state\n");
349 g_free(profile_name);
353 printf("%d. state:[%s], profile name:%s", profile_count,
354 test_print_state(profile_state), profile_name);
355 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
356 connection_cellular_service_type_e service_type;
357 if (connection_profile_get_cellular_service_type(
358 profile_h, &service_type) !=
359 CONNECTION_ERROR_NONE)
360 printf("Fail to get cellular service type!\n");
363 test_print_cellular_service_type(service_type));
367 profile_list[profile_count] = profile_h;
370 g_free(profile_name);
371 if (profile_count >= 100)
378 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
379 input >= profile_count ||
381 printf("Wrong number!!\n");
386 *profile = profile_list[input];
391 static int test_update_cellular_info(connection_profile_h profile)
394 char input_str1[100] = {0,};
395 char input_str2[100] = {0,};
399 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
400 "Prepaid MMS:4, Tethering:5, Application:6)"
401 " - (Enter for skip) :", &input_int)) {
404 rv = connection_profile_set_cellular_service_type(profile,
405 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
408 rv = connection_profile_set_cellular_service_type(profile,
409 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
412 rv = connection_profile_set_cellular_service_type(profile,
413 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
416 rv = connection_profile_set_cellular_service_type(profile,
417 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
420 rv = connection_profile_set_cellular_service_type(profile,
421 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
424 rv = connection_profile_set_cellular_service_type(profile,
425 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
431 if (rv != CONNECTION_ERROR_NONE)
436 if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
437 g_strstrip(input_str1);
438 rv = connection_profile_set_cellular_apn(profile, input_str1);
439 if (rv != CONNECTION_ERROR_NONE)
443 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
444 g_strstrip(input_str1);
445 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
446 if (rv != CONNECTION_ERROR_NONE)
450 if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
451 g_strstrip(input_str1);
452 rv = connection_profile_set_cellular_home_url(profile, input_str1);
453 if (rv != CONNECTION_ERROR_NONE)
457 if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
460 rv = connection_profile_set_cellular_auth_info(profile,
461 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
462 if (rv != CONNECTION_ERROR_NONE)
467 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
470 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
472 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
474 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
477 g_strstrip(input_str1);
478 g_strstrip(input_str2);
479 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
480 if (rv != CONNECTION_ERROR_NONE)
485 if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
488 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
491 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
494 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
498 if (rv != CONNECTION_ERROR_NONE)
502 if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
505 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
508 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
511 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
515 if (rv != CONNECTION_ERROR_NONE)
522 static int test_update_wifi_info(connection_profile_h profile)
525 char input_str[100] = {0,};
527 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
528 rv = connection_profile_set_wifi_passphrase(profile, input_str);
529 if (rv != CONNECTION_ERROR_NONE)
536 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
539 char input_str[100] = {0,};
541 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
542 rv = connection_profile_set_ip_address(profile,
545 if (rv != CONNECTION_ERROR_NONE)
549 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
550 rv = connection_profile_set_subnet_mask(profile,
553 if (rv != CONNECTION_ERROR_NONE)
557 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
558 rv = connection_profile_set_gateway_address(profile,
561 if (rv != CONNECTION_ERROR_NONE)
565 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
566 rv = connection_profile_set_dns_address(profile,
570 if (rv != CONNECTION_ERROR_NONE)
573 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
574 rv = connection_profile_set_dns_address(profile,
578 if (rv != CONNECTION_ERROR_NONE)
586 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
590 char input_str[100] = {0,};
592 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
593 " - (Enter for skip) :", &input_int)) {
596 rv = connection_profile_set_proxy_type(profile,
597 CONNECTION_PROXY_TYPE_DIRECT);
599 if (rv != CONNECTION_ERROR_NONE)
604 rv = connection_profile_set_proxy_type(profile,
605 CONNECTION_PROXY_TYPE_AUTO);
608 rv = connection_profile_set_proxy_type(profile,
609 CONNECTION_PROXY_TYPE_MANUAL);
615 if (rv != CONNECTION_ERROR_NONE)
618 if (test_get_user_string("Input auto Proxy URL or Proxy address"
619 " - (Enter for skip) :", input_str, 100)) {
620 rv = connection_profile_set_proxy_address(profile,
623 if (rv != CONNECTION_ERROR_NONE)
633 static int test_update_network_info(connection_profile_h profile)
637 int address_family = 0;
639 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
641 if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
642 " - (Enter for skip) :", &input_int)) {
645 rv = connection_profile_set_ip_config_type(profile,
647 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
650 rv = connection_profile_set_ip_config_type(profile,
652 CONNECTION_IP_CONFIG_TYPE_STATIC);
653 if (rv != CONNECTION_ERROR_NONE)
656 if (test_update_ip_info(profile, address_family) == -1)
659 if (test_update_proxy_info(profile, address_family) == -1)
663 rv = connection_profile_set_ip_config_type(profile,
665 CONNECTION_IP_CONFIG_TYPE_AUTO);
671 if (rv != CONNECTION_ERROR_NONE)
679 static void test_print_cellular_info(connection_profile_h profile)
681 connection_cellular_service_type_e service_type;
682 connection_cellular_pdn_type_e pdn_type;
683 connection_cellular_pdn_type_e roam_pdn_type;
685 connection_cellular_auth_type_e auth_type;
686 char *user_name = NULL;
687 char *password = NULL;
688 char *home_url = NULL;
689 bool roaming = false;
691 bool editable = false;
693 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
694 printf("Fail to get cellular service type!\n");
696 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
698 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
699 printf("Fail to get cellular pdn type!\n");
701 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
703 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
704 printf("Fail to get cellular roam pdn type!\n");
706 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
708 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
709 printf("Fail to get cellular APN!\n");
711 printf("Cellular APN : %s\n", apn);
715 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
716 printf("Fail to get auth info!\n");
718 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
719 printf("Cellular user_name : %s\n", user_name);
720 printf("Cellular password : %s\n", password);
725 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
726 printf("Fail to get cellular home url!\n");
728 printf("Cellular home url : %s\n", home_url);
732 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
733 printf("Fail to get cellular roaming state!\n");
735 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
737 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
738 printf("Fail to get cellular hidden state!\n");
740 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
742 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
743 printf("Fail to get cellular editing state!\n");
745 printf("Cellular editable : %s\n", editable ? "true" : "false");
748 static void test_print_wifi_info(connection_profile_h profile)
755 connection_wifi_security_type_e security_type;
756 connection_wifi_encryption_type_e encryption_type;
757 bool pass_required = false;
758 bool wps_supported = false;
760 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
761 printf("Fail to get Wi-Fi essid!\n");
763 printf("Wi-Fi essid : %s\n", essid);
767 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
768 printf("Fail to get Wi-Fi bssid!\n");
770 printf("Wi-Fi bssid : %s\n", bssid);
774 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
775 printf("Fail to get Wi-Fi rssi!\n");
777 printf("Wi-Fi rssi : %d\n", rssi);
779 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
780 printf("Fail to get Wi-Fi frequency!\n");
782 printf("Wi-Fi frequency : %d\n", frequency);
784 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
785 printf("Fail to get Wi-Fi max speed!\n");
787 printf("Wi-Fi max speed : %d\n", max_speed);
789 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
790 printf("Fail to get Wi-Fi security type!\n");
792 printf("Wi-Fi security type : %d\n", security_type);
794 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
795 printf("Fail to get Wi-Fi encryption type!\n");
797 printf("Wi-Fi encryption type : %d\n", encryption_type);
799 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
800 printf("Fail to get Wi-Fi passphrase required!\n");
802 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
804 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
805 printf("Fail to get Wi-Fi wps info\n");
807 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
810 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
812 char *interface_name = NULL;
813 connection_ip_config_type_e ip_type;
816 char *gateway = NULL;
819 connection_proxy_type_e proxy_type;
822 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
823 printf("Fail to get interface name!\n");
825 printf("Interface name : %s\n", interface_name);
826 g_free(interface_name);
829 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
830 printf("Fail to get ipconfig type!\n");
832 printf("Ipconfig type : %d\n", ip_type);
834 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
835 printf("Fail to get IP address!\n");
837 printf("IP address : %s\n", ip);
841 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
842 printf("Fail to get subnet mask!\n");
844 printf("Subnet mask : %s\n", subnet);
848 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
849 printf("Fail to get gateway!\n");
851 printf("Gateway : %s\n", gateway);
855 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
856 printf("Fail to get DNS1!\n");
858 printf("DNS1 : %s\n", dns1);
862 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
863 printf("Fail to get DNS2!\n");
865 printf("DNS2 : %s\n", dns2);
869 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
870 printf("Fail to get proxy type!\n");
872 printf("Proxy type : %d\n", proxy_type);
874 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
875 printf("Fail to get proxy!\n");
877 printf("Proxy : %s\n", proxy);
882 int test_register_client(void)
885 int err = connection_create(&connection);
887 if (CONNECTION_ERROR_NONE == err) {
888 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
889 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
890 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
891 connection_set_ethernet_cable_state_chaged_cb(connection,
892 test_get_ethernet_cable_state_callback, NULL);
894 printf("Client registration failed [%s]\n", test_print_error(err));
898 printf("Client registration success\n");
902 int test_deregister_client(void)
906 connection_profile_h profile;
908 if (connection != NULL)
909 rv = connection_destroy(connection);
911 printf("Cannot deregister : Handle is NULL\n");
912 rv = CONNECTION_ERROR_INVALID_OPERATION;
915 if (rv != CONNECTION_ERROR_NONE) {
916 printf("Client deregistration fail [%s]\n", test_print_error(rv));
921 for (list = state_cb_list; list; list = list->next) {
922 profile = list->data;
923 connection_profile_destroy(profile);
926 g_slist_free(state_cb_list);
927 state_cb_list = NULL;
931 printf("Client deregistration success\n");
936 int test_get_network_state(void)
939 connection_type_e net_state;
941 rv = connection_get_type(connection, &net_state);
943 if (rv != CONNECTION_ERROR_NONE) {
944 printf("Fail to get network state [%s]\n", test_print_error(rv));
948 printf("Retval = [%s] network connection state [%s]\n",
949 test_print_error(rv), test_print_connection_type(net_state));
954 int test_get_cellular_state(void)
957 connection_cellular_state_e cellular_state;
959 rv = connection_get_cellular_state(connection, &cellular_state);
961 if (rv != CONNECTION_ERROR_NONE) {
962 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
966 printf("Retval = [%s] Cellular state [%s]\n",
967 test_print_error(rv), test_print_cellular_state(cellular_state));
972 int test_get_wifi_state(void)
975 connection_wifi_state_e wifi_state;
977 rv = connection_get_wifi_state(connection, &wifi_state);
979 if (rv != CONNECTION_ERROR_NONE) {
980 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
984 printf("Retval = [%s] WiFi state [%s]\n",
985 test_print_error(rv), test_print_wifi_state(wifi_state));
990 int test_get_current_proxy(void)
992 char *proxy_addr = NULL;
994 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
996 if (proxy_addr == NULL) {
997 printf("Proxy address does not exist\n");
1001 printf("Current Proxy [%s]\n", proxy_addr);
1007 int test_get_current_ip(void)
1009 char *ip_addr = NULL;
1013 rv = test_get_user_int("Input Address type to get"
1014 "(1:IPV4, 2:IPV6):", &input);
1017 printf("Invalid input!!\n");
1023 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1024 if (ip_addr == NULL) {
1025 printf("IPv4 address does not exist\n");
1028 printf("IPv4 address : %s\n", ip_addr);
1032 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1033 if (ip_addr == NULL) {
1034 printf("IPv6 address does not exist\n");
1037 printf("IPv6 address : %s\n", ip_addr);
1040 printf("Wrong IP address family!!\n");
1048 int test_get_call_statistics_info(void)
1052 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1053 printf("last recv data size [%lld]\n", rv);
1054 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1055 printf("last sent data size [%lld]\n", rv);
1056 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1057 printf("total received data size [%lld]\n", rv);
1058 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1059 printf("total sent data size [%lld]\n", rv);
1064 int test_get_wifi_call_statistics_info(void)
1068 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1069 printf("WiFi last recv data size [%lld]\n", rv);
1070 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1071 printf("WiFi last sent data size [%lld]\n", rv);
1072 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1073 printf("WiFi total received data size [%lld]\n", rv);
1074 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1075 printf("WiFi total sent data size [%lld]\n", rv);
1080 int test_get_profile_list(void)
1082 if (test_get_user_selected_profile(NULL, false) == false)
1088 int test_get_default_profile_list(void)
1091 char *profile_name = NULL;
1092 connection_profile_iterator_h profile_iter;
1093 connection_profile_h profile_h;
1094 connection_cellular_service_type_e service_type;
1095 bool is_default = false;
1097 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1098 if (rv != CONNECTION_ERROR_NONE) {
1099 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1103 while (connection_profile_iterator_has_next(profile_iter)) {
1104 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1105 printf("Fail to get profile handle\n");
1109 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1110 printf("Fail to get profile name\n");
1113 printf("profile name : %s\n", profile_name);
1114 g_free(profile_name);
1116 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1117 printf("Fail to get profile service type\n");
1120 printf("service type : %d\n", service_type);
1122 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1123 printf("Fail to get profile subscriber id\n");
1126 printf("Default : %d\n", is_default);
1132 int test_get_connected_profile_list(void)
1135 char *profile_name = NULL;
1136 connection_profile_iterator_h profile_iter;
1137 connection_profile_h profile_h;
1138 bool is_default = false;
1139 connection_profile_type_e type;
1141 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1142 if (rv != CONNECTION_ERROR_NONE) {
1143 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1147 while (connection_profile_iterator_has_next(profile_iter)) {
1148 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1149 printf("Fail to get profile handle\n");
1153 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1154 printf("Fail to get profile name\n");
1157 printf("profile name is %s\n", profile_name);
1158 g_free(profile_name);
1160 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1161 printf("Fail to get profile type\n");
1164 printf("profile type is %d\n", type);
1166 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1167 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1168 printf("Fail to get profile is default\n");
1171 printf("[%s]\n", is_default ? "default" : "not default");
1178 int test_get_current_profile(void)
1181 char *profile_name = NULL;
1182 connection_profile_h profile_h;
1184 rv = connection_get_current_profile(connection, &profile_h);
1185 if (rv != CONNECTION_ERROR_NONE) {
1186 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1190 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1191 printf("Fail to get profile name\n");
1194 printf("profile name : %s\n", profile_name);
1195 g_free(profile_name);
1197 connection_profile_destroy(profile_h);
1202 int test_open_profile(void)
1204 connection_profile_h profile;
1206 printf("\n** Choose a profile to open. **\n");
1208 if (test_get_user_selected_profile(&profile, true) == false)
1211 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1212 printf("Connection open Failed!!\n");
1219 int test_get_default_cellular_service_type(void)
1224 connection_profile_h profile;
1225 char *profile_name = NULL;
1227 rv = test_get_user_int("Input profile type to get"
1228 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1231 printf("Invalid input!!\n");
1237 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1240 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1243 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1246 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1249 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1252 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1255 printf("Wrong number!!\n");
1259 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1262 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1263 printf("Fail to get profile name\n");
1264 connection_profile_destroy(profile);
1267 printf("Default profile name : %s\n", profile_name);
1268 g_free(profile_name);
1270 connection_profile_destroy(profile);
1275 int test_set_default_cellular_service_type(void)
1277 connection_profile_h profile;
1278 connection_cellular_service_type_e type;
1281 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1283 if (rv == false || (input != 1 && input != 2)) {
1284 printf("Invalid input!!\n");
1288 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1290 if (test_get_user_selected_profile(&profile, true) == false)
1293 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1294 printf("Fail to get cellular service type\n");
1299 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1302 if (connection_set_default_cellular_service_profile_async(connection,
1303 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1310 int test_close_profile(void)
1312 connection_profile_h profile;
1314 printf("\n** Choose a profile to close. **\n");
1316 if (test_get_user_selected_profile(&profile, true) == false)
1319 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1320 printf("Connection close Failed!!\n");
1327 int test_add_profile(void)
1330 connection_profile_h profile;
1331 char input_str[100] = {0,};
1333 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1336 g_strstrip(input_str);
1337 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1338 if (rv != CONNECTION_ERROR_NONE)
1339 RETURN_FAIL_DESTROY(profile);
1341 if (test_update_cellular_info(profile) == -1)
1342 RETURN_FAIL_DESTROY(profile);
1344 rv = connection_add_profile(connection, profile);
1345 if (rv != CONNECTION_ERROR_NONE)
1346 RETURN_FAIL_DESTROY(profile);
1348 connection_profile_destroy(profile);
1352 int test_remove_profile(void)
1354 connection_profile_h profile;
1356 printf("\n** Choose a profile to remove. **\n");
1357 if (test_get_user_selected_profile(&profile, true) == false)
1360 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1361 printf("Remove profile Failed!!\n");
1368 int test_update_profile(void)
1372 connection_profile_type_e prof_type;
1373 connection_profile_h profile;
1375 printf("\n** Choose a profile to update. **\n");
1376 if (test_get_user_selected_profile(&profile, true) == false)
1379 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1382 switch (prof_type) {
1383 case CONNECTION_PROFILE_TYPE_CELLULAR:
1384 if (test_update_cellular_info(profile) == -1)
1388 case CONNECTION_PROFILE_TYPE_WIFI:
1389 if (test_update_wifi_info(profile) == -1)
1392 if (test_update_network_info(profile) == -1)
1396 case CONNECTION_PROFILE_TYPE_ETHERNET:
1397 if (test_update_network_info(profile) == -1)
1401 case CONNECTION_PROFILE_TYPE_BT:
1402 printf("Not supported!\n");
1408 rv = connection_update_profile(connection, profile);
1409 if (rv != CONNECTION_ERROR_NONE)
1415 int test_get_profile_info(void)
1417 connection_profile_type_e prof_type;
1418 connection_profile_state_e profile_state;
1419 connection_profile_h profile;
1420 char *profile_name = NULL;
1421 int address_family = 0;
1423 printf("\n** Choose a profile to print. **\n");
1424 if (test_get_user_selected_profile(&profile, true) == false)
1427 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1428 printf("Fail to get profile name\n");
1431 printf("Profile Name : %s\n", profile_name);
1432 g_free(profile_name);
1435 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1436 printf("Fail to get profile state\n");
1439 printf("Profile State : %s\n", test_print_state(profile_state));
1441 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1444 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1446 switch (prof_type) {
1447 case CONNECTION_PROFILE_TYPE_CELLULAR:
1448 printf("Profile Type : Cellular\n");
1449 test_print_cellular_info(profile);
1451 case CONNECTION_PROFILE_TYPE_WIFI:
1452 printf("Profile Type : Wi-Fi\n");
1453 test_print_wifi_info(profile);
1455 case CONNECTION_PROFILE_TYPE_ETHERNET:
1456 printf("Profile Type : Ethernet\n");
1458 case CONNECTION_PROFILE_TYPE_BT:
1459 printf("Profile Type : Bluetooth\n");
1465 test_print_network_info(profile, address_family);
1470 int test_refresh_profile_info(void)
1472 connection_profile_type_e prof_type;
1473 connection_profile_state_e profile_state;
1474 connection_profile_h profile;
1475 char *profile_name = NULL;
1476 int address_family = 0;
1478 printf("\n** Choose a profile to refresh. **\n");
1479 if (test_get_user_selected_profile(&profile, true) == false)
1482 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1485 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1486 printf("Fail to get profile name\n");
1489 printf("Profile Name : %s\n", profile_name);
1490 g_free(profile_name);
1493 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1494 printf("Fail to get profile state\n");
1497 printf("Profile State : %s\n", test_print_state(profile_state));
1500 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1503 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1505 switch (prof_type) {
1506 case CONNECTION_PROFILE_TYPE_CELLULAR:
1507 printf("Profile Type : Cellular\n");
1508 test_print_cellular_info(profile);
1510 case CONNECTION_PROFILE_TYPE_WIFI:
1511 printf("Profile Type : Wi-Fi\n");
1512 test_print_wifi_info(profile);
1514 case CONNECTION_PROFILE_TYPE_ETHERNET:
1515 printf("Profile Type : Ethernet\n");
1517 case CONNECTION_PROFILE_TYPE_BT:
1518 printf("Profile Type : Bluetooth\n");
1524 test_print_network_info(profile, address_family);
1529 int test_set_state_changed_callback()
1531 connection_profile_h profile;
1532 connection_profile_h profile_clone;
1534 printf("\n** Choose a profile to set callback. **\n");
1535 if (test_get_user_selected_profile(&profile, true) == false)
1538 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1541 if (connection_profile_set_state_changed_cb(profile,
1542 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1543 connection_profile_destroy(profile_clone);
1547 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1552 int test_unset_state_changed_callback()
1554 connection_profile_h profile;
1556 char *profile_name = NULL;
1560 printf("\n** Choose a profile to unset callback. **\n");
1561 for (list = state_cb_list; list; list = list->next) {
1562 profile = list->data;
1563 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1564 printf("Fail to get profile name!\n");
1567 printf("%d. %s\n", count, profile_name);
1568 g_free(profile_name);
1574 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1577 printf("Wrong number!!\n");
1582 for (list = state_cb_list; list; list = list->next) {
1583 if (count == input) {
1584 profile = list->data;
1594 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1597 state_cb_list = g_slist_remove(state_cb_list, profile);
1598 connection_profile_destroy(profile);
1603 int test_reset_call_statistics_info(void)
1605 int ret = CONNECTION_ERROR_NONE;
1607 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1608 printf("reset last recv data size [%d]\n", ret);
1609 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1610 printf("last sent data size [%d]\n", ret);
1611 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1612 printf("total received data size [%d]\n", ret);
1613 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1614 printf("total sent data size [%d]\n", ret);
1619 int test_reset_wifi_call_statistics_info(void)
1621 int ret = CONNECTION_ERROR_NONE;
1623 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1624 printf("WiFi last sent data size [%d]\n", ret);
1625 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1626 printf("WiFi last recv data size [%d]\n", ret);
1627 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1628 printf("WiFi total sent data size [%d]\n", ret);
1629 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1630 printf("WiFi total received data size [%d]\n", ret);
1635 int test_add_route(void)
1638 char ip_addr[100] = {0};
1639 char if_name[40] = {0};
1641 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1644 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1647 g_strstrip(ip_addr);
1648 g_strstrip(if_name);
1649 rv = connection_add_route(connection, if_name, ip_addr);
1650 if (rv != CONNECTION_ERROR_NONE) {
1651 printf("Fail to get add new route [%d]\n", rv);
1654 printf("Add Route successfully\n");
1659 int test_remove_route(void)
1662 char ip_addr[100] = {0};
1663 char if_name[40] = {0};
1665 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1668 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1671 g_strstrip(ip_addr);
1672 g_strstrip(if_name);
1673 rv = connection_remove_route(connection, if_name, ip_addr);
1674 if (rv != CONNECTION_ERROR_NONE) {
1675 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1678 printf("Remove Route successfully\n");
1683 int test_add_route_ipv6(void)
1686 char ip_addr[100] = {0};
1687 char gateway[100] = {0};
1688 char if_name[40] = {0};
1690 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1693 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1696 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1699 g_strstrip(ip_addr);
1700 g_strstrip(gateway);
1701 g_strstrip(if_name);
1702 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1703 if (rv != CONNECTION_ERROR_NONE) {
1704 printf("Fail to get add new route [%d]\n", rv);
1707 printf("Add Route successfully\n");
1712 int test_remove_route_ipv6(void)
1715 char ip_addr[100] = {0};
1716 char gateway[100] = {0};
1717 char if_name[40] = {0};
1719 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1722 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1725 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1728 g_strstrip(ip_addr);
1729 g_strstrip(gateway);
1730 g_strstrip(if_name);
1731 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1732 if (rv != CONNECTION_ERROR_NONE) {
1733 printf("Fail to remove the route [%d]\n", rv);
1736 printf("Remove Route successfully\n");
1741 int test_get_bt_state(void)
1744 connection_bt_state_e bt_state;
1746 rv = connection_get_bt_state(connection, &bt_state);
1748 if (rv != CONNECTION_ERROR_NONE) {
1749 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1753 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
1758 int test_get_profile_id(void)
1760 connection_profile_h profile;
1763 printf("\n** Choose a profile to see profile id. **\n");
1764 if (test_get_user_selected_profile(&profile, true) == false)
1767 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1768 printf("Fail to get profile name\n");
1771 printf("Profile id : %s\n", profile_id);
1778 int test_get_mac_address(void)
1780 int rv = 0, type = 0;
1781 connection_type_e conn_type;
1782 char *mac_addr = NULL;
1784 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
1788 conn_type = CONNECTION_TYPE_WIFI;
1791 conn_type = CONNECTION_TYPE_ETHERNET;
1794 printf("Wrong number!!\n");
1798 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
1800 if (rv != CONNECTION_ERROR_NONE) {
1801 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
1805 printf("mac address is %s\n", mac_addr);
1812 int test_get_ethernet_cable_state(void)
1815 connection_ethernet_cable_state_e cable_state;
1817 rv = connection_get_ethernet_cable_state(connection, &cable_state);
1819 if (rv != CONNECTION_ERROR_NONE) {
1820 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
1824 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
1829 int test_reset_profile(void)
1831 int type, sim_id, rv;
1833 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
1835 if (rv == false || (type != 0 && type != 1)) {
1836 printf("Invalid input!!\n");
1840 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
1842 if (rv == false || (sim_id != 0 && sim_id != 1)) {
1843 printf("Invalid input!!\n");
1847 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
1853 int main(int argc, char **argv)
1855 GMainLoop *mainloop;
1856 mainloop = g_main_loop_new(NULL, FALSE);
1858 GIOChannel *channel = g_io_channel_unix_new(0);
1859 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1861 printf("Test Thread created...\n");
1863 g_main_loop_run(mainloop);
1868 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1873 memset(a, '\0', 100);
1874 printf("Event received from stdin\n");
1876 rv = read(0, a, 100);
1878 if (rv < 0 || a[0] == '0') {
1879 if (connection != NULL)
1880 test_deregister_client();
1885 if (*a == '\n' || *a == '\r') {
1886 printf("\n\n Network Connection API Test App\n\n");
1887 printf("Options..\n");
1888 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
1889 printf("2 - Destroy Handle(unset callbacks automatically)\n");
1890 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
1891 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
1892 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
1893 printf("6 - Get current proxy address \n");
1894 printf("7 - Get current Ip address\n");
1895 printf("8 - Get cellular data call statistics\n");
1896 printf("9 - Get WiFi data call statistics\n");
1897 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
1898 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
1899 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
1900 printf("d - Open connection with profile\n");
1901 printf("e - Get default cellular service by type\n");
1902 printf("f - Set default cellular service by type\n");
1903 printf("g - Close connection with profile\n");
1904 printf("h - Add profile(Cellular and Wifi only)\n");
1905 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
1906 printf("j - Update profile\n");
1907 printf("k - Get profile info\n");
1908 printf("l - Refresh profile info\n");
1909 printf("m - Set state changed callback\n");
1910 printf("n - Unset state changed callback\n");
1911 printf("o - Reset cellular data call statistics\n");
1912 printf("p - Reset WiFi data call statistics\n");
1913 printf("q - Add new route\n");
1914 printf("r - Remove a route\n");
1915 printf("s - Get Bluetooth state\n");
1916 printf("t - Get profile id\n");
1917 printf("u - Reset profile\n");
1918 printf("v - Get all cellular default profiles\n");
1919 printf("w - Get mac address\n");
1920 printf("x - Get ethernet cable state\n");
1921 printf("B - Add IPv6 new route\n");
1922 printf("C - Remove IPv6 route\n");
1923 printf(LOG_RED "0 - Exit \n" LOG_END);
1924 printf("ENTER - Show options menu.......\n");
1929 rv = test_register_client();
1932 rv = test_deregister_client();
1935 rv = test_get_network_state();
1938 rv = test_get_cellular_state();
1941 rv = test_get_wifi_state();
1944 rv = test_get_current_proxy();
1947 rv = test_get_current_ip();
1950 rv = test_get_call_statistics_info();
1953 rv = test_get_wifi_call_statistics_info();
1956 rv = test_get_profile_list();
1959 rv = test_get_connected_profile_list();
1962 rv = test_get_current_profile();
1965 rv = test_open_profile();
1968 rv = test_get_default_cellular_service_type();
1971 rv = test_set_default_cellular_service_type();
1974 rv = test_close_profile();
1977 rv = test_add_profile();
1980 rv = test_remove_profile();
1983 rv = test_update_profile();
1986 rv = test_get_profile_info();
1989 rv = test_refresh_profile_info();
1992 rv = test_set_state_changed_callback();
1995 rv = test_unset_state_changed_callback();
1998 rv = test_reset_call_statistics_info();
2001 rv = test_reset_wifi_call_statistics_info();
2004 rv = test_add_route();
2007 rv = test_remove_route();
2010 rv = test_get_bt_state();
2013 rv = test_get_profile_id();
2016 rv = test_reset_profile();
2019 rv = test_get_default_profile_list();
2022 rv = test_get_mac_address();
2025 rv = test_get_ethernet_cable_state();
2028 rv = test_add_route_ipv6();
2031 rv = test_remove_route_ipv6();
2036 printf("Operation succeeded!\n");
2038 printf("Operation failed!\n");