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_dns_info(connection_profile_h profile,
537 connection_address_family_e address_family)
540 char input_str[100] = {0,};
541 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
542 rv = connection_profile_set_dns_address(profile,
546 if (rv != CONNECTION_ERROR_NONE)
549 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
550 rv = connection_profile_set_dns_address(profile,
554 if (rv != CONNECTION_ERROR_NONE)
561 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
565 char input_str[100] = {0,};
567 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
568 rv = connection_profile_set_ip_address(profile,
571 if (rv != CONNECTION_ERROR_NONE)
575 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
576 rv = connection_profile_set_subnet_mask(profile,
579 if (rv != CONNECTION_ERROR_NONE)
583 if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
584 rv = connection_profile_set_prefix_length(profile,
587 if (rv != CONNECTION_ERROR_NONE)
591 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
592 rv = connection_profile_set_gateway_address(profile,
595 if (rv != CONNECTION_ERROR_NONE)
599 if (test_update_dns_info(profile, address_family) < 0)
605 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
609 char input_str[100] = {0,};
611 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
612 " - (Enter for skip) :", &input_int)) {
615 rv = connection_profile_set_proxy_type(profile,
616 CONNECTION_PROXY_TYPE_DIRECT);
618 if (rv != CONNECTION_ERROR_NONE)
623 rv = connection_profile_set_proxy_type(profile,
624 CONNECTION_PROXY_TYPE_AUTO);
627 rv = connection_profile_set_proxy_type(profile,
628 CONNECTION_PROXY_TYPE_MANUAL);
634 if (rv != CONNECTION_ERROR_NONE)
637 if (test_get_user_string("Input auto Proxy URL or Proxy address"
638 " - (Enter for skip) :", input_str, 100)) {
639 rv = connection_profile_set_proxy_address(profile,
642 if (rv != CONNECTION_ERROR_NONE)
654 static int test_update_network_info(connection_profile_h profile)
659 int address_family = 0;
661 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
663 if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
664 " - (Enter for skip) :", &input_int)) {
667 rv = connection_profile_set_ip_config_type(profile,
669 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
670 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
671 " - (Enter for skip) :", &dns_input)) {
673 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
674 rv = connection_profile_set_dns_config_type(
677 CONNECTION_DNS_CONFIG_TYPE_STATIC);
678 if (rv != CONNECTION_ERROR_NONE)
680 if (test_update_dns_info(profile,
681 address_family) == -1)
684 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
685 rv = connection_profile_set_dns_config_type(
688 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
689 if (rv != CONNECTION_ERROR_NONE)
696 rv = connection_profile_set_ip_config_type(profile,
698 CONNECTION_IP_CONFIG_TYPE_STATIC);
699 if (rv != CONNECTION_ERROR_NONE)
702 if (test_update_ip_info(profile, address_family) == -1)
705 if (test_update_proxy_info(profile, address_family) == -1)
709 rv = connection_profile_set_ip_config_type(profile,
711 CONNECTION_IP_CONFIG_TYPE_AUTO);
717 if (rv != CONNECTION_ERROR_NONE)
725 static void test_print_cellular_info(connection_profile_h profile)
727 connection_cellular_service_type_e service_type;
728 connection_cellular_pdn_type_e pdn_type;
729 connection_cellular_pdn_type_e roam_pdn_type;
731 connection_cellular_auth_type_e auth_type;
732 char *user_name = NULL;
733 char *password = NULL;
734 char *home_url = NULL;
735 bool roaming = false;
737 bool editable = false;
739 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
740 printf("Fail to get cellular service type!\n");
742 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
744 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
745 printf("Fail to get cellular pdn type!\n");
747 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
749 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
750 printf("Fail to get cellular roam pdn type!\n");
752 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
754 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
755 printf("Fail to get cellular APN!\n");
757 printf("Cellular APN : %s\n", apn);
761 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
762 printf("Fail to get auth info!\n");
764 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
765 printf("Cellular user_name : %s\n", user_name);
766 printf("Cellular password : %s\n", password);
771 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
772 printf("Fail to get cellular home url!\n");
774 printf("Cellular home url : %s\n", home_url);
778 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
779 printf("Fail to get cellular roaming state!\n");
781 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
783 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
784 printf("Fail to get cellular hidden state!\n");
786 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
788 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
789 printf("Fail to get cellular editing state!\n");
791 printf("Cellular editable : %s\n", editable ? "true" : "false");
794 static void test_print_wifi_info(connection_profile_h profile)
801 connection_wifi_security_type_e security_type;
802 connection_wifi_encryption_type_e encryption_type;
803 bool pass_required = false;
804 bool wps_supported = false;
806 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
807 printf("Fail to get Wi-Fi essid!\n");
809 printf("Wi-Fi essid : %s\n", essid);
813 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
814 printf("Fail to get Wi-Fi bssid!\n");
816 printf("Wi-Fi bssid : %s\n", bssid);
820 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
821 printf("Fail to get Wi-Fi rssi!\n");
823 printf("Wi-Fi rssi : %d\n", rssi);
825 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
826 printf("Fail to get Wi-Fi frequency!\n");
828 printf("Wi-Fi frequency : %d\n", frequency);
830 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
831 printf("Fail to get Wi-Fi max speed!\n");
833 printf("Wi-Fi max speed : %d\n", max_speed);
835 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
836 printf("Fail to get Wi-Fi security type!\n");
838 printf("Wi-Fi security type : %d\n", security_type);
840 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
841 printf("Fail to get Wi-Fi encryption type!\n");
843 printf("Wi-Fi encryption type : %d\n", encryption_type);
845 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
846 printf("Fail to get Wi-Fi passphrase required!\n");
848 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
850 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
851 printf("Fail to get Wi-Fi wps info\n");
853 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
856 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
858 char *interface_name = NULL;
861 char *gateway = NULL;
862 char *dhcp_server = NULL;
867 connection_ip_config_type_e ip_type;
868 connection_proxy_type_e proxy_type;
869 connection_dns_config_type_e dns_type;
871 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
872 printf("Fail to get interface name!\n");
874 printf("Interface name : %s\n", interface_name);
875 g_free(interface_name);
878 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
879 printf("Fail to get ipconfig type!\n");
881 printf("Ipconfig type : %d\n", ip_type);
883 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
884 printf("Fail to get IP address!\n");
886 printf("IP address : %s\n", ip);
890 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
891 printf("Fail to get gateway!\n");
893 printf("Gateway : %s\n", gateway);
897 if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
898 printf("Fail to get DHCP Server address!\n");
900 printf("DHCP Server : %s\n", dhcp_server);
904 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
905 printf("Fail to get subnet mask!\n");
907 printf("Subnet mask : %s\n", subnet);
911 if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
912 printf("Fail to get prefix length!\n");
914 printf("Prefix length : %d\n", prefix_len);
916 if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
917 printf("Fail to get DNS configuration type!\n");
919 printf("DNS configuration type : %d\n", dns_type);
921 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
922 printf("Fail to get DNS1!\n");
924 printf("DNS1 : %s\n", dns1);
928 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
929 printf("Fail to get DNS2!\n");
931 printf("DNS2 : %s\n", dns2);
935 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
936 printf("Fail to get proxy type!\n");
938 printf("Proxy type : %d\n", proxy_type);
940 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
941 printf("Fail to get proxy!\n");
943 printf("Proxy : %s\n", proxy);
948 int test_register_client(void)
951 int err = connection_create(&connection);
953 if (CONNECTION_ERROR_NONE == err) {
954 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
955 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
956 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
957 connection_set_ethernet_cable_state_chaged_cb(connection,
958 test_get_ethernet_cable_state_callback, NULL);
960 printf("Client registration failed [%s]\n", test_print_error(err));
964 printf("Client registration success\n");
968 int test_deregister_client(void)
972 connection_profile_h profile;
974 if (connection != NULL)
975 rv = connection_destroy(connection);
977 printf("Cannot deregister : Handle is NULL\n");
978 rv = CONNECTION_ERROR_INVALID_OPERATION;
981 if (rv != CONNECTION_ERROR_NONE) {
982 printf("Client deregistration fail [%s]\n", test_print_error(rv));
987 for (list = state_cb_list; list; list = list->next) {
988 profile = list->data;
989 connection_profile_destroy(profile);
992 g_slist_free(state_cb_list);
993 state_cb_list = NULL;
997 printf("Client deregistration success\n");
1002 int test_get_network_state(void)
1005 connection_type_e net_state;
1007 rv = connection_get_type(connection, &net_state);
1009 if (rv != CONNECTION_ERROR_NONE) {
1010 printf("Fail to get network state [%s]\n", test_print_error(rv));
1014 printf("Retval = [%s] network connection state [%s]\n",
1015 test_print_error(rv), test_print_connection_type(net_state));
1020 int test_get_cellular_state(void)
1023 connection_cellular_state_e cellular_state;
1025 rv = connection_get_cellular_state(connection, &cellular_state);
1027 if (rv != CONNECTION_ERROR_NONE) {
1028 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1032 printf("Retval = [%s] Cellular state [%s]\n",
1033 test_print_error(rv), test_print_cellular_state(cellular_state));
1038 int test_get_wifi_state(void)
1041 connection_wifi_state_e wifi_state;
1043 rv = connection_get_wifi_state(connection, &wifi_state);
1045 if (rv != CONNECTION_ERROR_NONE) {
1046 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1050 printf("Retval = [%s] WiFi state [%s]\n",
1051 test_print_error(rv), test_print_wifi_state(wifi_state));
1056 int test_get_current_proxy(void)
1058 char *proxy_addr = NULL;
1060 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1062 if (proxy_addr == NULL) {
1063 printf("Proxy address does not exist\n");
1067 printf("Current Proxy [%s]\n", proxy_addr);
1073 int test_get_current_ip(void)
1075 char *ip_addr = NULL;
1079 rv = test_get_user_int("Input Address type to get"
1080 "(1:IPV4, 2:IPV6):", &input);
1083 printf("Invalid input!!\n");
1089 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1090 if (ip_addr == NULL) {
1091 printf("IPv4 address does not exist\n");
1094 printf("IPv4 address : %s\n", ip_addr);
1098 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1099 if (ip_addr == NULL) {
1100 printf("IPv6 address does not exist\n");
1103 printf("IPv6 address : %s\n", ip_addr);
1106 printf("Wrong IP address family!!\n");
1114 int test_get_call_statistics_info(void)
1118 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1119 printf("last recv data size [%lld]\n", rv);
1120 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1121 printf("last sent data size [%lld]\n", rv);
1122 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1123 printf("total received data size [%lld]\n", rv);
1124 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1125 printf("total sent data size [%lld]\n", rv);
1130 int test_get_wifi_call_statistics_info(void)
1134 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1135 printf("WiFi last recv data size [%lld]\n", rv);
1136 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1137 printf("WiFi last sent data size [%lld]\n", rv);
1138 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1139 printf("WiFi total received data size [%lld]\n", rv);
1140 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1141 printf("WiFi total sent data size [%lld]\n", rv);
1146 int test_get_profile_list(void)
1148 if (test_get_user_selected_profile(NULL, false) == false)
1154 int test_get_default_profile_list(void)
1157 char *profile_name = NULL;
1158 connection_profile_iterator_h profile_iter;
1159 connection_profile_h profile_h;
1160 connection_cellular_service_type_e service_type;
1161 bool is_default = false;
1163 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1164 if (rv != CONNECTION_ERROR_NONE) {
1165 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1169 while (connection_profile_iterator_has_next(profile_iter)) {
1170 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1171 printf("Fail to get profile handle\n");
1175 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1176 printf("Fail to get profile name\n");
1179 printf("profile name : %s\n", profile_name);
1180 g_free(profile_name);
1182 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1183 printf("Fail to get profile service type\n");
1186 printf("service type : %d\n", service_type);
1188 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1189 printf("Fail to get profile subscriber id\n");
1192 printf("Default : %d\n", is_default);
1198 int test_get_connected_profile_list(void)
1201 char *profile_name = NULL;
1202 connection_profile_iterator_h profile_iter;
1203 connection_profile_h profile_h;
1204 bool is_default = false;
1205 connection_profile_type_e type;
1207 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1208 if (rv != CONNECTION_ERROR_NONE) {
1209 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1213 while (connection_profile_iterator_has_next(profile_iter)) {
1214 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1215 printf("Fail to get profile handle\n");
1219 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1220 printf("Fail to get profile name\n");
1223 printf("profile name is %s\n", profile_name);
1224 g_free(profile_name);
1226 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1227 printf("Fail to get profile type\n");
1230 printf("profile type is %d\n", type);
1232 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1233 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1234 printf("Fail to get profile is default\n");
1237 printf("[%s]\n", is_default ? "default" : "not default");
1244 int test_get_current_profile(void)
1247 char *profile_name = NULL;
1248 connection_profile_h profile_h;
1250 rv = connection_get_current_profile(connection, &profile_h);
1251 if (rv != CONNECTION_ERROR_NONE) {
1252 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1256 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1257 printf("Fail to get profile name\n");
1260 printf("profile name : %s\n", profile_name);
1261 g_free(profile_name);
1263 connection_profile_destroy(profile_h);
1268 int test_open_profile(void)
1270 connection_profile_h profile;
1272 printf("\n** Choose a profile to open. **\n");
1274 if (test_get_user_selected_profile(&profile, true) == false)
1277 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1278 printf("Connection open Failed!!\n");
1285 int test_get_default_cellular_service_type(void)
1290 connection_profile_h profile;
1291 char *profile_name = NULL;
1293 rv = test_get_user_int("Input profile type to get"
1294 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1297 printf("Invalid input!!\n");
1303 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1306 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1309 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1312 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1315 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1318 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1321 printf("Wrong number!!\n");
1325 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1328 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1329 printf("Fail to get profile name\n");
1330 connection_profile_destroy(profile);
1333 printf("Default profile name : %s\n", profile_name);
1334 g_free(profile_name);
1336 connection_profile_destroy(profile);
1341 int test_set_default_cellular_service_type(void)
1343 connection_profile_h profile;
1344 connection_cellular_service_type_e type;
1347 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1349 if (rv == false || (input != 1 && input != 2)) {
1350 printf("Invalid input!!\n");
1354 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1356 if (test_get_user_selected_profile(&profile, true) == false)
1359 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1360 printf("Fail to get cellular service type\n");
1365 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1368 if (connection_set_default_cellular_service_profile_async(connection,
1369 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1376 int test_close_profile(void)
1378 connection_profile_h profile;
1380 printf("\n** Choose a profile to close. **\n");
1382 if (test_get_user_selected_profile(&profile, true) == false)
1385 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1386 printf("Connection close Failed!!\n");
1393 int test_add_profile(void)
1396 connection_profile_h profile;
1397 char input_str[100] = {0,};
1399 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1402 g_strstrip(input_str);
1403 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1404 if (rv != CONNECTION_ERROR_NONE)
1405 RETURN_FAIL_DESTROY(profile);
1407 if (test_update_cellular_info(profile) == -1)
1408 RETURN_FAIL_DESTROY(profile);
1410 rv = connection_add_profile(connection, profile);
1411 if (rv != CONNECTION_ERROR_NONE)
1412 RETURN_FAIL_DESTROY(profile);
1414 connection_profile_destroy(profile);
1418 int test_remove_profile(void)
1420 connection_profile_h profile;
1422 printf("\n** Choose a profile to remove. **\n");
1423 if (test_get_user_selected_profile(&profile, true) == false)
1426 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1427 printf("Remove profile Failed!!\n");
1434 int test_update_profile(void)
1438 connection_profile_type_e prof_type;
1439 connection_profile_h profile;
1441 printf("\n** Choose a profile to update. **\n");
1442 if (test_get_user_selected_profile(&profile, true) == false)
1445 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1448 switch (prof_type) {
1449 case CONNECTION_PROFILE_TYPE_CELLULAR:
1450 if (test_update_cellular_info(profile) == -1)
1454 case CONNECTION_PROFILE_TYPE_WIFI:
1455 if (test_update_wifi_info(profile) == -1)
1458 if (test_update_network_info(profile) == -1)
1462 case CONNECTION_PROFILE_TYPE_ETHERNET:
1463 if (test_update_network_info(profile) == -1)
1467 case CONNECTION_PROFILE_TYPE_BT:
1468 printf("Not supported!\n");
1474 rv = connection_update_profile(connection, profile);
1475 if (rv != CONNECTION_ERROR_NONE)
1481 int test_get_profile_info(void)
1483 connection_profile_type_e prof_type;
1484 connection_profile_state_e profile_state;
1485 connection_profile_state_e profile_ipv6_state;
1486 connection_profile_h profile;
1487 char *profile_name = NULL;
1488 int address_family = 0;
1490 printf("\n** Choose a profile to print. **\n");
1491 if (test_get_user_selected_profile(&profile, true) == false)
1494 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1495 printf("Fail to get profile name\n");
1498 printf("Profile Name : %s\n", profile_name);
1499 g_free(profile_name);
1502 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1503 printf("Fail to get profile IPv4 state\n");
1506 printf("Profile State : %s\n", test_print_state(profile_state));
1508 if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1509 printf("Fail to get profile IPv6 state\n");
1512 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1515 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1518 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1520 switch (prof_type) {
1521 case CONNECTION_PROFILE_TYPE_CELLULAR:
1522 printf("Profile Type : Cellular\n");
1523 test_print_cellular_info(profile);
1525 case CONNECTION_PROFILE_TYPE_WIFI:
1526 printf("Profile Type : Wi-Fi\n");
1527 test_print_wifi_info(profile);
1529 case CONNECTION_PROFILE_TYPE_ETHERNET:
1530 printf("Profile Type : Ethernet\n");
1532 case CONNECTION_PROFILE_TYPE_BT:
1533 printf("Profile Type : Bluetooth\n");
1539 test_print_network_info(profile, address_family);
1544 int test_refresh_profile_info(void)
1546 connection_profile_type_e prof_type;
1547 connection_profile_state_e profile_state;
1548 connection_profile_h profile;
1549 char *profile_name = NULL;
1550 int address_family = 0;
1552 printf("\n** Choose a profile to refresh. **\n");
1553 if (test_get_user_selected_profile(&profile, true) == false)
1556 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1559 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1560 printf("Fail to get profile name\n");
1563 printf("Profile Name : %s\n", profile_name);
1564 g_free(profile_name);
1567 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1568 printf("Fail to get profile state\n");
1571 printf("Profile State : %s\n", test_print_state(profile_state));
1574 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1577 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1579 switch (prof_type) {
1580 case CONNECTION_PROFILE_TYPE_CELLULAR:
1581 printf("Profile Type : Cellular\n");
1582 test_print_cellular_info(profile);
1584 case CONNECTION_PROFILE_TYPE_WIFI:
1585 printf("Profile Type : Wi-Fi\n");
1586 test_print_wifi_info(profile);
1588 case CONNECTION_PROFILE_TYPE_ETHERNET:
1589 printf("Profile Type : Ethernet\n");
1591 case CONNECTION_PROFILE_TYPE_BT:
1592 printf("Profile Type : Bluetooth\n");
1598 test_print_network_info(profile, address_family);
1603 int test_set_state_changed_callback()
1605 connection_profile_h profile;
1606 connection_profile_h profile_clone;
1608 printf("\n** Choose a profile to set callback. **\n");
1609 if (test_get_user_selected_profile(&profile, true) == false)
1612 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1615 if (connection_profile_set_state_changed_cb(profile,
1616 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1617 connection_profile_destroy(profile_clone);
1621 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1626 int test_unset_state_changed_callback()
1628 connection_profile_h profile;
1630 char *profile_name = NULL;
1634 printf("\n** Choose a profile to unset callback. **\n");
1635 for (list = state_cb_list; list; list = list->next) {
1636 profile = list->data;
1637 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1638 printf("Fail to get profile name!\n");
1641 printf("%d. %s\n", count, profile_name);
1642 g_free(profile_name);
1648 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1651 printf("Wrong number!!\n");
1656 for (list = state_cb_list; list; list = list->next) {
1657 if (count == input) {
1658 profile = list->data;
1668 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1671 state_cb_list = g_slist_remove(state_cb_list, profile);
1672 connection_profile_destroy(profile);
1677 int test_reset_call_statistics_info(void)
1679 int ret = CONNECTION_ERROR_NONE;
1681 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1682 printf("reset last recv data size [%d]\n", ret);
1683 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1684 printf("last sent data size [%d]\n", ret);
1685 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1686 printf("total received data size [%d]\n", ret);
1687 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1688 printf("total sent data size [%d]\n", ret);
1693 int test_reset_wifi_call_statistics_info(void)
1695 int ret = CONNECTION_ERROR_NONE;
1697 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1698 printf("WiFi last sent data size [%d]\n", ret);
1699 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1700 printf("WiFi last recv data size [%d]\n", ret);
1701 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1702 printf("WiFi total sent data size [%d]\n", ret);
1703 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1704 printf("WiFi total received data size [%d]\n", ret);
1709 int test_add_route(void)
1712 char ip_addr[100] = {0};
1713 char if_name[40] = {0};
1715 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1718 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1721 g_strstrip(ip_addr);
1722 g_strstrip(if_name);
1723 rv = connection_add_route(connection, if_name, ip_addr);
1724 if (rv != CONNECTION_ERROR_NONE) {
1725 printf("Fail to get add new route [%d]\n", rv);
1728 printf("Add Route successfully\n");
1733 int test_remove_route(void)
1736 char ip_addr[100] = {0};
1737 char if_name[40] = {0};
1739 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1742 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1745 g_strstrip(ip_addr);
1746 g_strstrip(if_name);
1747 rv = connection_remove_route(connection, if_name, ip_addr);
1748 if (rv != CONNECTION_ERROR_NONE) {
1749 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1752 printf("Remove Route successfully\n");
1757 int test_add_route_ipv6(void)
1760 char ip_addr[100] = {0};
1761 char gateway[100] = {0};
1762 char if_name[40] = {0};
1764 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1767 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1770 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1773 g_strstrip(ip_addr);
1774 g_strstrip(gateway);
1775 g_strstrip(if_name);
1776 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1777 if (rv != CONNECTION_ERROR_NONE) {
1778 printf("Fail to get add new route [%d]\n", rv);
1781 printf("Add Route successfully\n");
1786 int test_remove_route_ipv6(void)
1789 char ip_addr[100] = {0};
1790 char gateway[100] = {0};
1791 char if_name[40] = {0};
1793 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1796 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1799 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1802 g_strstrip(ip_addr);
1803 g_strstrip(gateway);
1804 g_strstrip(if_name);
1805 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1806 if (rv != CONNECTION_ERROR_NONE) {
1807 printf("Fail to remove the route [%d]\n", rv);
1810 printf("Remove Route successfully\n");
1815 int test_add_route_entry(void)
1817 char ip_addr[100] = {0};
1818 char gateway[100] = {0};
1819 char if_name[40] = {0};
1824 input_rv = test_get_user_int("Input Address type to get"
1825 "(1:IPV4, 2:IPV6):", &input);
1827 if (input_rv == false) {
1828 printf("Invalid input!!\n");
1834 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1837 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1840 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1843 g_strstrip(ip_addr);
1844 g_strstrip(gateway);
1845 g_strstrip(if_name);
1846 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
1847 if (rv != CONNECTION_ERROR_NONE) {
1848 printf("Fail to get add new route [%d]\n", rv);
1851 printf("Add Route successfully\n");
1855 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1858 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1861 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1864 g_strstrip(ip_addr);
1865 g_strstrip(gateway);
1866 g_strstrip(if_name);
1867 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
1868 if (rv != CONNECTION_ERROR_NONE) {
1869 printf("Fail to get add new route [%d]\n", rv);
1872 printf("Add Route successfully\n");
1876 printf("Wrong IP address family!!\n");
1885 int test_remove_route_entry(void)
1887 char ip_addr[100] = {0};
1888 char gateway[100] = {0};
1889 char if_name[40] = {0};
1894 input_rv = test_get_user_int("Input Address type to get"
1895 "(1:IPV4, 2:IPV6):", &input);
1897 if (input_rv == false) {
1898 printf("Invalid input!!\n");
1904 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1907 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1910 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1913 g_strstrip(ip_addr);
1914 g_strstrip(gateway);
1915 g_strstrip(if_name);
1916 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
1917 if (rv != CONNECTION_ERROR_NONE) {
1918 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1921 printf("Remove Route successfully\n");
1926 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1929 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1932 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1935 g_strstrip(ip_addr);
1936 g_strstrip(gateway);
1937 g_strstrip(if_name);
1938 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
1939 if (rv != CONNECTION_ERROR_NONE) {
1940 printf("Fail to remove the route [%d]\n", rv);
1943 printf("Remove Route successfully\n");
1947 printf("Wrong IP address family!!\n");
1956 int test_get_bt_state(void)
1959 connection_bt_state_e bt_state;
1961 rv = connection_get_bt_state(connection, &bt_state);
1963 if (rv != CONNECTION_ERROR_NONE) {
1964 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1968 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
1973 int test_get_profile_id(void)
1975 connection_profile_h profile;
1978 printf("\n** Choose a profile to see profile id. **\n");
1979 if (test_get_user_selected_profile(&profile, true) == false)
1982 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1983 printf("Fail to get profile name\n");
1986 printf("Profile id : %s\n", profile_id);
1993 int test_get_mac_address(void)
1995 int rv = 0, type = 0;
1996 connection_type_e conn_type;
1997 char *mac_addr = NULL;
1999 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2003 conn_type = CONNECTION_TYPE_WIFI;
2006 conn_type = CONNECTION_TYPE_ETHERNET;
2009 printf("Wrong number!!\n");
2013 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2015 if (rv != CONNECTION_ERROR_NONE) {
2016 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2020 printf("mac address is %s\n", mac_addr);
2027 int test_get_ethernet_cable_state(void)
2030 connection_ethernet_cable_state_e cable_state;
2032 rv = connection_get_ethernet_cable_state(connection, &cable_state);
2034 if (rv != CONNECTION_ERROR_NONE) {
2035 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2039 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2044 int test_reset_profile(void)
2046 int type, sim_id, rv;
2048 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2050 if (rv == false || (type != 0 && type != 1)) {
2051 printf("Invalid input!!\n");
2055 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2057 if (rv == false || (sim_id != 0 && sim_id != 1)) {
2058 printf("Invalid input!!\n");
2062 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2068 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2070 printf("IPv6 Address : %s\n", ipv6_address);
2074 int test_foreach_ipv6_address(void)
2078 connection_type_e conn_type;
2080 test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2084 conn_type = CONNECTION_TYPE_WIFI;
2087 conn_type = CONNECTION_TYPE_ETHERNET;
2090 printf("Wrong number!!\n");
2094 rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2095 if (rv != CONNECTION_ERROR_NONE) {
2096 printf("Fail to get IPv6 address\n");
2104 int main(int argc, char **argv)
2106 GMainLoop *mainloop;
2107 mainloop = g_main_loop_new(NULL, FALSE);
2109 GIOChannel *channel = g_io_channel_unix_new(0);
2110 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
2112 printf("Test Thread created...\n");
2114 g_main_loop_run(mainloop);
2119 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
2124 memset(a, '\0', 100);
2125 printf("Event received from stdin\n");
2127 rv = read(0, a, 100);
2129 if (rv < 0 || a[0] == '0') {
2130 if (connection != NULL)
2131 test_deregister_client();
2136 if (*a == '\n' || *a == '\r') {
2137 printf("\n\n Network Connection API Test App\n\n");
2138 printf("Options..\n");
2139 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
2140 printf("2 - Destroy Handle(unset callbacks automatically)\n");
2141 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
2142 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
2143 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
2144 printf("6 - Get current proxy address \n");
2145 printf("7 - Get current Ip address\n");
2146 printf("8 - Get cellular data call statistics\n");
2147 printf("9 - Get WiFi data call statistics\n");
2148 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
2149 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
2150 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
2151 printf("d - Open connection with profile\n");
2152 printf("e - Get default cellular service by type\n");
2153 printf("f - Set default cellular service by type\n");
2154 printf("g - Close connection with profile\n");
2155 printf("h - Add profile(Cellular and Wifi only)\n");
2156 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
2157 printf("j - Update profile\n");
2158 printf("k - Get profile info\n");
2159 printf("l - Refresh profile info\n");
2160 printf("m - Set state changed callback\n");
2161 printf("n - Unset state changed callback\n");
2162 printf("o - Reset cellular data call statistics\n");
2163 printf("p - Reset WiFi data call statistics\n");
2164 printf("q - Add new route\n");
2165 printf("r - Remove a route\n");
2166 printf("s - Get Bluetooth state\n");
2167 printf("t - Get profile id\n");
2168 printf("u - Reset profile\n");
2169 printf("v - Get all cellular default profiles\n");
2170 printf("w - Get mac address\n");
2171 printf("x - Get ethernet cable state\n");
2172 printf("B - Add IPv6 new route\n");
2173 printf("C - Remove IPv6 route\n");
2174 printf("D - Add new route entry\n");
2175 printf("E - Remove route entry\n");
2176 printf("F - Get all IPv6 address\n");
2177 printf(LOG_RED "0 - Exit \n" LOG_END);
2178 printf("ENTER - Show options menu.......\n");
2183 rv = test_register_client();
2186 rv = test_deregister_client();
2189 rv = test_get_network_state();
2192 rv = test_get_cellular_state();
2195 rv = test_get_wifi_state();
2198 rv = test_get_current_proxy();
2201 rv = test_get_current_ip();
2204 rv = test_get_call_statistics_info();
2207 rv = test_get_wifi_call_statistics_info();
2210 rv = test_get_profile_list();
2213 rv = test_get_connected_profile_list();
2216 rv = test_get_current_profile();
2219 rv = test_open_profile();
2222 rv = test_get_default_cellular_service_type();
2225 rv = test_set_default_cellular_service_type();
2228 rv = test_close_profile();
2231 rv = test_add_profile();
2234 rv = test_remove_profile();
2237 rv = test_update_profile();
2240 rv = test_get_profile_info();
2243 rv = test_refresh_profile_info();
2246 rv = test_set_state_changed_callback();
2249 rv = test_unset_state_changed_callback();
2252 rv = test_reset_call_statistics_info();
2255 rv = test_reset_wifi_call_statistics_info();
2258 rv = test_add_route();
2261 rv = test_remove_route();
2264 rv = test_get_bt_state();
2267 rv = test_get_profile_id();
2270 rv = test_reset_profile();
2273 rv = test_get_default_profile_list();
2276 rv = test_get_mac_address();
2279 rv = test_get_ethernet_cable_state();
2282 rv = test_add_route_ipv6();
2285 rv = test_remove_route_ipv6();
2288 rv = test_add_route_entry();
2291 rv = test_remove_route_entry();
2294 rv = test_foreach_ipv6_address();
2299 printf("Operation succeeded!\n");
2301 printf("Operation failed!\n");