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"
25 #include "connection_extension.h"
27 #include <tizen_error.h>
29 #define LOG_RED "\033[0;31m"
30 #define LOG_GREEN "\033[0;32m"
31 #define LOG_BROWN "\033[0;33m"
32 #define LOG_BLUE "\033[0;34m"
33 #define LOG_END "\033[0;m"
35 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
37 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
39 connection_h connection = NULL;
40 static GSList *state_cb_list = NULL;
43 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
45 if (msg == NULL || buf == NULL || buf_size < 2)
50 memset(buf, 0, buf_size);
51 rv = read(0, buf, buf_size - 1);
53 if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
62 static bool test_get_user_int(const char *msg, int *num)
64 if (msg == NULL || num == NULL)
70 rv = read(0, buf, 32);
72 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
79 static const char *test_print_state(connection_profile_state_e state)
82 case CONNECTION_PROFILE_STATE_DISCONNECTED:
83 return "Disconnected";
84 case CONNECTION_PROFILE_STATE_ASSOCIATION:
86 case CONNECTION_PROFILE_STATE_CONFIGURATION:
87 return "Configuration";
88 case CONNECTION_PROFILE_STATE_CONNECTED:
95 static const char *test_print_connection_type(connection_type_e type)
98 case CONNECTION_TYPE_DISCONNECTED:
99 return "Disconnected";
100 case CONNECTION_TYPE_WIFI:
102 case CONNECTION_TYPE_CELLULAR:
104 case CONNECTION_TYPE_ETHERNET:
106 case CONNECTION_TYPE_BT:
108 case CONNECTION_TYPE_NET_PROXY:
115 static const char *test_print_cellular_state(connection_cellular_state_e state)
118 case CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE:
119 return "Out of service";
120 case CONNECTION_CELLULAR_STATE_FLIGHT_MODE:
121 return "Flight mode";
122 case CONNECTION_CELLULAR_STATE_ROAMING_OFF:
123 return "Roaming off";
124 case CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE:
125 return "Call only available";
126 case CONNECTION_CELLULAR_STATE_AVAILABLE:
128 case CONNECTION_CELLULAR_STATE_CONNECTED:
135 static const char *test_print_wifi_state(connection_wifi_state_e state)
138 case CONNECTION_WIFI_STATE_DEACTIVATED:
139 return "Deactivated";
140 case CONNECTION_WIFI_STATE_DISCONNECTED:
141 return "Disconnected";
142 case CONNECTION_WIFI_STATE_CONNECTED:
149 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
152 case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
154 case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
156 case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
158 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
159 return "Prepaid internet";
160 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
161 return "Prepaid MMS";
162 case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
164 case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
165 return "Application";
171 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
174 case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
176 case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
178 case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
184 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
187 case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
189 case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
191 case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
193 case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
199 static const char *test_print_error(connection_error_e error)
202 case CONNECTION_ERROR_NONE:
203 return "CONNECTION_ERROR_NONE";
204 case CONNECTION_ERROR_INVALID_PARAMETER:
205 return "CONNECTION_ERROR_INVALID_PARAMETER";
206 case CONNECTION_ERROR_OUT_OF_MEMORY:
207 return "CONNECTION_ERROR_OUT_OF_MEMORY";
208 case CONNECTION_ERROR_INVALID_OPERATION:
209 return "CONNECTION_ERROR_INVALID_OPERATION";
210 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
211 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
212 case CONNECTION_ERROR_OPERATION_FAILED:
213 return "CONNECTION_ERROR_OPERATION_FAILED";
214 case CONNECTION_ERROR_ITERATOR_END:
215 return "CONNECTION_ERROR_ITERATOR_END";
216 case CONNECTION_ERROR_NO_CONNECTION:
217 return "CONNECTION_ERROR_NO_CONNECTION";
218 case CONNECTION_ERROR_NOW_IN_PROGRESS:
219 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
220 case CONNECTION_ERROR_ALREADY_EXISTS:
221 return "CONNECTION_ERROR_ALREADY_EXISTS";
222 case CONNECTION_ERROR_OPERATION_ABORTED:
223 return "CONNECTION_ERROR_OPERATION_ABORTED";
224 case CONNECTION_ERROR_DHCP_FAILED:
225 return "CONNECTION_ERROR_DHCP_FAILED";
226 case CONNECTION_ERROR_INVALID_KEY:
227 return "CONNECTION_ERROR_INVALID_KEY";
228 case CONNECTION_ERROR_NO_REPLY:
229 return "CONNECTION_ERROR_NO_REPLY";
230 case CONNECTION_ERROR_PERMISSION_DENIED:
231 return "CONNECTION_ERROR_PERMISSION_DENIED";
232 case CONNECTION_ERROR_NOT_SUPPORTED:
233 return "CONNECTION_ERROR_NOT_SUPPORTED";
235 return "CONNECTION_ERROR_UNKNOWN";
239 static void test_type_changed_callback(connection_type_e type, void* user_data)
241 printf("Type changed callback, connection type : %d\n", type);
244 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
246 printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
247 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
250 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
252 printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
253 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
256 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
259 connection_profile_h profile = user_data;
264 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
267 printf("[%s] : %s\n", test_print_state(state), profile_name);
268 g_free(profile_name);
271 static void test_connection_opened_callback(connection_error_e result, void* user_data)
273 if (result == CONNECTION_ERROR_NONE)
274 printf("Connection open Succeeded\n");
276 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
279 static void test_connection_closed_callback(connection_error_e result, void* user_data)
281 if (result == CONNECTION_ERROR_NONE)
282 printf("Connection close Succeeded\n");
284 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
287 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
289 if (result == CONNECTION_ERROR_NONE)
290 printf("Reset profile Succeeded\n");
292 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
295 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
297 if (result == CONNECTION_ERROR_NONE)
298 printf("Default profile setting Succeeded\n");
300 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
303 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
306 if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
307 printf("Ethernet Cable Connected\n");
308 else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
309 printf("Ethernet Cable Disconnected\n");
312 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
317 connection_profile_type_e profile_type;
318 connection_profile_state_e profile_state;
319 connection_profile_iterator_h profile_iter;
320 connection_profile_h profile_h;
322 connection_profile_h profile_list[100] = {0,};
323 int profile_count = 0;
325 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
326 if (rv != CONNECTION_ERROR_NONE) {
327 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
331 while (connection_profile_iterator_has_next(profile_iter)) {
332 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
333 printf("Fail to get profile handle\n");
337 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
338 printf("Fail to get profile name\n");
342 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
343 printf("Fail to get profile type\n");
344 g_free(profile_name);
348 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
349 printf("Fail to get profile state\n");
350 g_free(profile_name);
354 printf("%d. state:[%s], profile name:%s", profile_count,
355 test_print_state(profile_state), profile_name);
356 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
357 connection_cellular_service_type_e service_type;
358 if (connection_profile_get_cellular_service_type(
359 profile_h, &service_type) !=
360 CONNECTION_ERROR_NONE)
361 printf("Fail to get cellular service type!\n");
364 test_print_cellular_service_type(service_type));
368 profile_list[profile_count] = profile_h;
371 g_free(profile_name);
372 if (profile_count >= 100)
379 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
380 input >= profile_count ||
382 printf("Wrong number!!\n");
387 *profile = profile_list[input];
392 static int test_update_cellular_info(connection_profile_h profile)
395 char input_str1[100] = {0,};
396 char input_str2[100] = {0,};
400 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
401 "Prepaid MMS:4, Tethering:5, Application:6)"
402 " - (Enter for skip) :", &input_int)) {
405 rv = connection_profile_set_cellular_service_type(profile,
406 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
409 rv = connection_profile_set_cellular_service_type(profile,
410 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
413 rv = connection_profile_set_cellular_service_type(profile,
414 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
417 rv = connection_profile_set_cellular_service_type(profile,
418 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
421 rv = connection_profile_set_cellular_service_type(profile,
422 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
425 rv = connection_profile_set_cellular_service_type(profile,
426 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
432 if (rv != CONNECTION_ERROR_NONE)
437 if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
438 g_strstrip(input_str1);
439 rv = connection_profile_set_cellular_apn(profile, input_str1);
440 if (rv != CONNECTION_ERROR_NONE)
444 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
445 g_strstrip(input_str1);
446 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
447 if (rv != CONNECTION_ERROR_NONE)
451 if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
452 g_strstrip(input_str1);
453 rv = connection_profile_set_cellular_home_url(profile, input_str1);
454 if (rv != CONNECTION_ERROR_NONE)
458 if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
461 rv = connection_profile_set_cellular_auth_info(profile,
462 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
463 if (rv != CONNECTION_ERROR_NONE)
468 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
471 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
473 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
475 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
478 g_strstrip(input_str1);
479 g_strstrip(input_str2);
480 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
481 if (rv != CONNECTION_ERROR_NONE)
486 if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
489 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
492 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
495 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
499 if (rv != CONNECTION_ERROR_NONE)
503 if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
506 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
509 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
512 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
516 if (rv != CONNECTION_ERROR_NONE)
523 static int test_update_wifi_info(connection_profile_h profile)
526 char input_str[100] = {0,};
528 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
529 rv = connection_profile_set_wifi_passphrase(profile, input_str);
530 if (rv != CONNECTION_ERROR_NONE)
537 static int test_update_dns_info(connection_profile_h profile,
538 connection_address_family_e address_family)
541 char input_str[100] = {0,};
542 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
543 rv = connection_profile_set_dns_address(profile,
547 if (rv != CONNECTION_ERROR_NONE)
550 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
551 rv = connection_profile_set_dns_address(profile,
555 if (rv != CONNECTION_ERROR_NONE)
562 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
566 char input_str[100] = {0,};
568 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
569 rv = connection_profile_set_ip_address(profile,
572 if (rv != CONNECTION_ERROR_NONE)
576 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
577 rv = connection_profile_set_subnet_mask(profile,
580 if (rv != CONNECTION_ERROR_NONE)
584 if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
585 rv = connection_profile_set_prefix_length(profile,
588 if (rv != CONNECTION_ERROR_NONE)
592 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
593 rv = connection_profile_set_gateway_address(profile,
596 if (rv != CONNECTION_ERROR_NONE)
600 if (test_update_dns_info(profile, address_family) < 0)
606 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
610 char input_str[100] = {0,};
612 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
613 " - (Enter for skip) :", &input_int)) {
616 rv = connection_profile_set_proxy_type(profile,
617 CONNECTION_PROXY_TYPE_DIRECT);
619 if (rv != CONNECTION_ERROR_NONE)
624 rv = connection_profile_set_proxy_type(profile,
625 CONNECTION_PROXY_TYPE_AUTO);
628 rv = connection_profile_set_proxy_type(profile,
629 CONNECTION_PROXY_TYPE_MANUAL);
635 if (rv != CONNECTION_ERROR_NONE)
638 if (test_get_user_string("Input auto Proxy URL or Proxy address"
639 " - (Enter for skip) :", input_str, 100)) {
640 rv = connection_profile_set_proxy_address(profile,
643 if (rv != CONNECTION_ERROR_NONE)
655 static int test_update_network_info(connection_profile_h profile)
660 int address_family = 0;
662 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
664 if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
665 " - (Enter for skip) :", &input_int)) {
668 rv = connection_profile_set_ip_config_type(profile,
670 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
671 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
672 " - (Enter for skip) :", &dns_input)) {
674 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
675 rv = connection_profile_set_dns_config_type(
678 CONNECTION_DNS_CONFIG_TYPE_STATIC);
679 if (rv != CONNECTION_ERROR_NONE)
681 if (test_update_dns_info(profile,
682 address_family) == -1)
685 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
686 rv = connection_profile_set_dns_config_type(
689 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
690 if (rv != CONNECTION_ERROR_NONE)
697 rv = connection_profile_set_ip_config_type(profile,
699 CONNECTION_IP_CONFIG_TYPE_STATIC);
700 if (rv != CONNECTION_ERROR_NONE)
703 if (test_update_ip_info(profile, address_family) == -1)
706 if (test_update_proxy_info(profile, address_family) == -1)
710 rv = connection_profile_set_ip_config_type(profile,
712 CONNECTION_IP_CONFIG_TYPE_AUTO);
718 if (rv != CONNECTION_ERROR_NONE)
726 static void test_print_cellular_info(connection_profile_h profile)
728 connection_cellular_service_type_e service_type;
729 connection_cellular_pdn_type_e pdn_type;
730 connection_cellular_pdn_type_e roam_pdn_type;
732 connection_cellular_auth_type_e auth_type;
733 char *user_name = NULL;
734 char *password = NULL;
735 char *home_url = NULL;
736 bool roaming = false;
738 bool editable = false;
740 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
741 printf("Fail to get cellular service type!\n");
743 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
745 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
746 printf("Fail to get cellular pdn type!\n");
748 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
750 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
751 printf("Fail to get cellular roam pdn type!\n");
753 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
755 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
756 printf("Fail to get cellular APN!\n");
758 printf("Cellular APN : %s\n", apn);
762 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
763 printf("Fail to get auth info!\n");
765 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
766 printf("Cellular user_name : %s\n", user_name);
767 printf("Cellular password : %s\n", password);
772 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
773 printf("Fail to get cellular home url!\n");
775 printf("Cellular home url : %s\n", home_url);
779 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
780 printf("Fail to get cellular roaming state!\n");
782 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
784 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
785 printf("Fail to get cellular hidden state!\n");
787 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
789 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
790 printf("Fail to get cellular editing state!\n");
792 printf("Cellular editable : %s\n", editable ? "true" : "false");
795 static void test_print_wifi_info(connection_profile_h profile)
802 connection_wifi_security_type_e security_type;
803 connection_wifi_encryption_type_e encryption_type;
804 bool pass_required = false;
805 bool wps_supported = false;
807 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
808 printf("Fail to get Wi-Fi essid!\n");
810 printf("Wi-Fi essid : %s\n", essid);
814 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
815 printf("Fail to get Wi-Fi bssid!\n");
817 printf("Wi-Fi bssid : %s\n", bssid);
821 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
822 printf("Fail to get Wi-Fi rssi!\n");
824 printf("Wi-Fi rssi : %d\n", rssi);
826 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
827 printf("Fail to get Wi-Fi frequency!\n");
829 printf("Wi-Fi frequency : %d\n", frequency);
831 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
832 printf("Fail to get Wi-Fi max speed!\n");
834 printf("Wi-Fi max speed : %d\n", max_speed);
836 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
837 printf("Fail to get Wi-Fi security type!\n");
839 printf("Wi-Fi security type : %d\n", security_type);
841 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
842 printf("Fail to get Wi-Fi encryption type!\n");
844 printf("Wi-Fi encryption type : %d\n", encryption_type);
846 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
847 printf("Fail to get Wi-Fi passphrase required!\n");
849 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
851 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
852 printf("Fail to get Wi-Fi wps info\n");
854 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
857 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
859 char *interface_name = NULL;
862 char *gateway = NULL;
863 char *dhcp_server = NULL;
864 int dhcp_lease_duration = 0;
869 connection_ip_config_type_e ip_type;
870 connection_proxy_type_e proxy_type;
871 connection_dns_config_type_e dns_type;
873 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
874 printf("Fail to get interface name!\n");
876 printf("Interface name : %s\n", interface_name);
877 g_free(interface_name);
880 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
881 printf("Fail to get ipconfig type!\n");
883 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
884 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
885 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
886 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
887 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
888 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
889 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
890 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
892 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
895 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
896 printf("Fail to get IP address!\n");
898 printf("IP address : %s\n", ip);
902 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
903 printf("Fail to get gateway!\n");
905 printf("Gateway : %s\n", gateway);
909 if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
910 printf("Fail to get DHCP Server address!\n");
912 printf("DHCP Server : %s\n", dhcp_server);
916 if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
917 printf("Fail to get DHCP lease duration!\n");
919 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
922 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
923 printf("Fail to get subnet mask!\n");
925 printf("Subnet mask : %s\n", subnet);
929 if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
930 printf("Fail to get prefix length!\n");
932 printf("Prefix length : %d\n", prefix_len);
934 if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
935 printf("Fail to get DNS configuration type!\n");
937 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
938 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
939 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
940 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
942 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
945 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
946 printf("Fail to get DNS1!\n");
948 printf("DNS1 : %s\n", dns1);
952 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
953 printf("Fail to get DNS2!\n");
955 printf("DNS2 : %s\n", dns2);
959 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
960 printf("Fail to get proxy type!\n");
962 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
963 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
964 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
965 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
967 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
970 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
971 printf("Fail to get proxy!\n");
973 printf("Proxy : %s\n", proxy);
978 int test_register_client(void)
981 int err = connection_create(&connection);
983 if (CONNECTION_ERROR_NONE == err) {
984 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
985 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
986 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
987 connection_set_ethernet_cable_state_chaged_cb(connection,
988 test_get_ethernet_cable_state_callback, NULL);
990 printf("Client registration failed [%s]\n", test_print_error(err));
994 printf("Client registration success\n");
998 int test_deregister_client(void)
1002 connection_profile_h profile;
1004 if (connection != NULL)
1005 rv = connection_destroy(connection);
1007 printf("Cannot deregister : Handle is NULL\n");
1008 rv = CONNECTION_ERROR_INVALID_OPERATION;
1011 if (rv != CONNECTION_ERROR_NONE) {
1012 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1016 if (state_cb_list) {
1017 for (list = state_cb_list; list; list = list->next) {
1018 profile = list->data;
1019 connection_profile_destroy(profile);
1022 g_slist_free(state_cb_list);
1023 state_cb_list = NULL;
1027 printf("Client deregistration success\n");
1032 int test_get_network_state(void)
1035 connection_type_e net_state;
1037 rv = connection_get_type(connection, &net_state);
1039 if (rv != CONNECTION_ERROR_NONE) {
1040 printf("Fail to get network state [%s]\n", test_print_error(rv));
1044 printf("Retval = [%s] network connection state [%s]\n",
1045 test_print_error(rv), test_print_connection_type(net_state));
1050 int test_get_cellular_state(void)
1053 connection_cellular_state_e cellular_state;
1055 rv = connection_get_cellular_state(connection, &cellular_state);
1057 if (rv != CONNECTION_ERROR_NONE) {
1058 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1062 printf("Retval = [%s] Cellular state [%s]\n",
1063 test_print_error(rv), test_print_cellular_state(cellular_state));
1068 int test_get_wifi_state(void)
1071 connection_wifi_state_e wifi_state;
1073 rv = connection_get_wifi_state(connection, &wifi_state);
1075 if (rv != CONNECTION_ERROR_NONE) {
1076 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1080 printf("Retval = [%s] WiFi state [%s]\n",
1081 test_print_error(rv), test_print_wifi_state(wifi_state));
1086 int test_get_current_proxy(void)
1088 char *proxy_addr = NULL;
1090 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1092 if (proxy_addr == NULL) {
1093 printf("Proxy address does not exist\n");
1097 printf("Current Proxy [%s]\n", proxy_addr);
1103 int test_get_current_ip(void)
1105 char *ip_addr = NULL;
1109 rv = test_get_user_int("Input Address type to get"
1110 "(1:IPV4, 2:IPV6):", &input);
1113 printf("Invalid input!!\n");
1119 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1120 if (ip_addr == NULL) {
1121 printf("IPv4 address does not exist\n");
1124 printf("IPv4 address : %s\n", ip_addr);
1128 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1129 if (ip_addr == NULL) {
1130 printf("IPv6 address does not exist\n");
1133 printf("IPv6 address : %s\n", ip_addr);
1136 printf("Wrong IP address family!!\n");
1144 int test_get_call_statistics_info(void)
1148 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1149 printf("last recv data size [%lld]\n", rv);
1150 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1151 printf("last sent data size [%lld]\n", rv);
1152 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1153 printf("total received data size [%lld]\n", rv);
1154 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1155 printf("total sent data size [%lld]\n", rv);
1160 int test_get_wifi_call_statistics_info(void)
1164 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1165 printf("WiFi last recv data size [%lld]\n", rv);
1166 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1167 printf("WiFi last sent data size [%lld]\n", rv);
1168 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1169 printf("WiFi total received data size [%lld]\n", rv);
1170 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1171 printf("WiFi total sent data size [%lld]\n", rv);
1176 int test_get_profile_list(void)
1178 if (test_get_user_selected_profile(NULL, false) == false)
1184 int test_get_default_profile_list(void)
1187 char *profile_name = NULL;
1188 connection_profile_iterator_h profile_iter;
1189 connection_profile_h profile_h;
1190 connection_cellular_service_type_e service_type;
1191 bool is_default = false;
1193 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1194 if (rv != CONNECTION_ERROR_NONE) {
1195 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1199 while (connection_profile_iterator_has_next(profile_iter)) {
1200 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1201 printf("Fail to get profile handle\n");
1205 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1206 printf("Fail to get profile name\n");
1209 printf("profile name : %s\n", profile_name);
1210 g_free(profile_name);
1212 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1213 printf("Fail to get profile service type\n");
1216 printf("service type : %d\n", service_type);
1218 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1219 printf("Fail to get profile subscriber id\n");
1222 printf("Default : %d\n", is_default);
1228 int test_get_connected_profile_list(void)
1231 char *profile_name = NULL;
1232 connection_profile_iterator_h profile_iter;
1233 connection_profile_h profile_h;
1234 bool is_default = false;
1235 connection_profile_type_e type;
1237 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1238 if (rv != CONNECTION_ERROR_NONE) {
1239 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1243 while (connection_profile_iterator_has_next(profile_iter)) {
1244 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1245 printf("Fail to get profile handle\n");
1249 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1250 printf("Fail to get profile name\n");
1253 printf("profile name is %s\n", profile_name);
1254 g_free(profile_name);
1256 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1257 printf("Fail to get profile type\n");
1260 printf("profile type is %d\n", type);
1262 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1263 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1264 printf("Fail to get profile is default\n");
1267 printf("[%s]\n", is_default ? "default" : "not default");
1274 int test_get_current_profile(void)
1277 char *profile_name = NULL;
1278 connection_profile_h profile_h;
1280 rv = connection_get_current_profile(connection, &profile_h);
1281 if (rv != CONNECTION_ERROR_NONE) {
1282 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1286 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1287 printf("Fail to get profile name\n");
1290 printf("profile name : %s\n", profile_name);
1291 g_free(profile_name);
1293 connection_profile_destroy(profile_h);
1298 int test_open_profile(void)
1300 connection_profile_h profile;
1302 printf("\n** Choose a profile to open. **\n");
1304 if (test_get_user_selected_profile(&profile, true) == false)
1307 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1308 printf("Connection open Failed!!\n");
1315 int test_get_default_cellular_service_type(void)
1320 connection_profile_h profile;
1321 char *profile_name = NULL;
1323 rv = test_get_user_int("Input profile type to get"
1324 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1327 printf("Invalid input!!\n");
1333 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1336 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1339 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1342 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1345 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1348 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1351 printf("Wrong number!!\n");
1355 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1358 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1359 printf("Fail to get profile name\n");
1360 connection_profile_destroy(profile);
1363 printf("Default profile name : %s\n", profile_name);
1364 g_free(profile_name);
1366 connection_profile_destroy(profile);
1371 int test_set_default_cellular_service_type(void)
1373 connection_profile_h profile;
1374 connection_cellular_service_type_e type;
1377 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1379 if (rv == false || (input != 1 && input != 2)) {
1380 printf("Invalid input!!\n");
1384 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1386 if (test_get_user_selected_profile(&profile, true) == false)
1389 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1390 printf("Fail to get cellular service type\n");
1395 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1398 if (connection_set_default_cellular_service_profile_async(connection,
1399 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1406 int test_close_profile(void)
1408 connection_profile_h profile;
1410 printf("\n** Choose a profile to close. **\n");
1412 if (test_get_user_selected_profile(&profile, true) == false)
1415 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1416 printf("Connection close Failed!!\n");
1423 int test_add_profile(void)
1426 connection_profile_h profile;
1427 char input_str[100] = {0,};
1429 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1432 g_strstrip(input_str);
1433 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1434 if (rv != CONNECTION_ERROR_NONE)
1435 RETURN_FAIL_DESTROY(profile);
1437 if (test_update_cellular_info(profile) == -1)
1438 RETURN_FAIL_DESTROY(profile);
1440 rv = connection_add_profile(connection, profile);
1441 if (rv != CONNECTION_ERROR_NONE)
1442 RETURN_FAIL_DESTROY(profile);
1444 connection_profile_destroy(profile);
1448 int test_remove_profile(void)
1450 connection_profile_h profile;
1452 printf("\n** Choose a profile to remove. **\n");
1453 if (test_get_user_selected_profile(&profile, true) == false)
1456 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1457 printf("Remove profile Failed!!\n");
1464 int test_update_profile(void)
1468 connection_profile_type_e prof_type;
1469 connection_profile_h profile;
1471 printf("\n** Choose a profile to update. **\n");
1472 if (test_get_user_selected_profile(&profile, true) == false)
1475 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1478 switch (prof_type) {
1479 case CONNECTION_PROFILE_TYPE_CELLULAR:
1480 if (test_update_cellular_info(profile) == -1)
1484 case CONNECTION_PROFILE_TYPE_WIFI:
1485 if (test_update_wifi_info(profile) == -1)
1488 if (test_update_network_info(profile) == -1)
1492 case CONNECTION_PROFILE_TYPE_ETHERNET:
1493 if (test_update_network_info(profile) == -1)
1497 case CONNECTION_PROFILE_TYPE_BT:
1498 printf("Not supported!\n");
1504 rv = connection_update_profile(connection, profile);
1505 if (rv != CONNECTION_ERROR_NONE)
1511 int test_get_profile_info(void)
1513 connection_profile_type_e prof_type;
1514 connection_profile_state_e profile_state;
1515 connection_profile_state_e profile_ipv6_state;
1516 connection_profile_h profile;
1517 char *profile_name = NULL;
1518 int address_family = 0;
1520 printf("\n** Choose a profile to print. **\n");
1521 if (test_get_user_selected_profile(&profile, true) == false)
1524 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1525 printf("Fail to get profile name\n");
1528 printf("Profile Name : %s\n", profile_name);
1529 g_free(profile_name);
1532 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1533 printf("Fail to get profile IPv4 state\n");
1536 printf("Profile State : %s\n", test_print_state(profile_state));
1538 if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1539 printf("Fail to get profile IPv6 state\n");
1542 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1545 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1548 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1550 switch (prof_type) {
1551 case CONNECTION_PROFILE_TYPE_CELLULAR:
1552 printf("Profile Type : Cellular\n");
1553 test_print_cellular_info(profile);
1555 case CONNECTION_PROFILE_TYPE_WIFI:
1556 printf("Profile Type : Wi-Fi\n");
1557 test_print_wifi_info(profile);
1559 case CONNECTION_PROFILE_TYPE_ETHERNET:
1560 printf("Profile Type : Ethernet\n");
1562 case CONNECTION_PROFILE_TYPE_BT:
1563 printf("Profile Type : Bluetooth\n");
1569 test_print_network_info(profile, address_family);
1574 int test_refresh_profile_info(void)
1576 connection_profile_type_e prof_type;
1577 connection_profile_state_e profile_state;
1578 connection_profile_h profile;
1579 char *profile_name = NULL;
1580 int address_family = 0;
1582 printf("\n** Choose a profile to refresh. **\n");
1583 if (test_get_user_selected_profile(&profile, true) == false)
1586 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1589 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1590 printf("Fail to get profile name\n");
1593 printf("Profile Name : %s\n", profile_name);
1594 g_free(profile_name);
1597 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1598 printf("Fail to get profile state\n");
1601 printf("Profile State : %s\n", test_print_state(profile_state));
1604 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1607 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1609 switch (prof_type) {
1610 case CONNECTION_PROFILE_TYPE_CELLULAR:
1611 printf("Profile Type : Cellular\n");
1612 test_print_cellular_info(profile);
1614 case CONNECTION_PROFILE_TYPE_WIFI:
1615 printf("Profile Type : Wi-Fi\n");
1616 test_print_wifi_info(profile);
1618 case CONNECTION_PROFILE_TYPE_ETHERNET:
1619 printf("Profile Type : Ethernet\n");
1621 case CONNECTION_PROFILE_TYPE_BT:
1622 printf("Profile Type : Bluetooth\n");
1628 test_print_network_info(profile, address_family);
1633 int test_set_state_changed_callback()
1635 connection_profile_h profile;
1636 connection_profile_h profile_clone;
1638 printf("\n** Choose a profile to set callback. **\n");
1639 if (test_get_user_selected_profile(&profile, true) == false)
1642 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1645 if (connection_profile_set_state_changed_cb(profile,
1646 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1647 connection_profile_destroy(profile_clone);
1651 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1656 int test_unset_state_changed_callback()
1658 connection_profile_h profile;
1660 char *profile_name = NULL;
1664 printf("\n** Choose a profile to unset callback. **\n");
1665 for (list = state_cb_list; list; list = list->next) {
1666 profile = list->data;
1667 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1668 printf("Fail to get profile name!\n");
1671 printf("%d. %s\n", count, profile_name);
1672 g_free(profile_name);
1678 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1681 printf("Wrong number!!\n");
1686 for (list = state_cb_list; list; list = list->next) {
1687 if (count == input) {
1688 profile = list->data;
1698 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1701 state_cb_list = g_slist_remove(state_cb_list, profile);
1702 connection_profile_destroy(profile);
1707 int test_reset_call_statistics_info(void)
1709 int ret = CONNECTION_ERROR_NONE;
1711 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1712 printf("reset last recv data size [%d]\n", ret);
1713 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1714 printf("last sent data size [%d]\n", ret);
1715 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1716 printf("total received data size [%d]\n", ret);
1717 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1718 printf("total sent data size [%d]\n", ret);
1723 int test_reset_wifi_call_statistics_info(void)
1725 int ret = CONNECTION_ERROR_NONE;
1727 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1728 printf("WiFi last sent data size [%d]\n", ret);
1729 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1730 printf("WiFi last recv data size [%d]\n", ret);
1731 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1732 printf("WiFi total sent data size [%d]\n", ret);
1733 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1734 printf("WiFi total received data size [%d]\n", ret);
1739 int test_add_route(void)
1742 char ip_addr[100] = {0};
1743 char if_name[40] = {0};
1745 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1748 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1751 g_strstrip(ip_addr);
1752 g_strstrip(if_name);
1753 rv = connection_add_route(connection, if_name, ip_addr);
1754 if (rv != CONNECTION_ERROR_NONE) {
1755 printf("Fail to get add new route [%d]\n", rv);
1758 printf("Add Route successfully\n");
1763 int test_remove_route(void)
1766 char ip_addr[100] = {0};
1767 char if_name[40] = {0};
1769 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1772 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1775 g_strstrip(ip_addr);
1776 g_strstrip(if_name);
1777 rv = connection_remove_route(connection, if_name, ip_addr);
1778 if (rv != CONNECTION_ERROR_NONE) {
1779 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1782 printf("Remove Route successfully\n");
1787 int test_add_route_ipv6(void)
1790 char ip_addr[100] = {0};
1791 char gateway[100] = {0};
1792 char if_name[40] = {0};
1794 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1797 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1800 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1803 g_strstrip(ip_addr);
1804 g_strstrip(gateway);
1805 g_strstrip(if_name);
1806 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1807 if (rv != CONNECTION_ERROR_NONE) {
1808 printf("Fail to get add new route [%d]\n", rv);
1811 printf("Add Route successfully\n");
1816 int test_remove_route_ipv6(void)
1819 char ip_addr[100] = {0};
1820 char gateway[100] = {0};
1821 char if_name[40] = {0};
1823 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1826 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1829 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1832 g_strstrip(ip_addr);
1833 g_strstrip(gateway);
1834 g_strstrip(if_name);
1835 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1836 if (rv != CONNECTION_ERROR_NONE) {
1837 printf("Fail to remove the route [%d]\n", rv);
1840 printf("Remove Route successfully\n");
1845 int test_add_route_entry(void)
1847 char ip_addr[100] = {0};
1848 char gateway[100] = {0};
1849 char if_name[40] = {0};
1854 input_rv = test_get_user_int("Input Address type to get"
1855 "(1:IPV4, 2:IPV6):", &input);
1857 if (input_rv == false) {
1858 printf("Invalid input!!\n");
1864 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1867 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1870 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1873 g_strstrip(ip_addr);
1874 g_strstrip(gateway);
1875 g_strstrip(if_name);
1876 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
1877 if (rv != CONNECTION_ERROR_NONE) {
1878 printf("Fail to get add new route [%d]\n", rv);
1881 printf("Add Route successfully\n");
1885 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1888 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1891 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1894 g_strstrip(ip_addr);
1895 g_strstrip(gateway);
1896 g_strstrip(if_name);
1897 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
1898 if (rv != CONNECTION_ERROR_NONE) {
1899 printf("Fail to get add new route [%d]\n", rv);
1902 printf("Add Route successfully\n");
1906 printf("Wrong IP address family!!\n");
1915 int test_remove_route_entry(void)
1917 char ip_addr[100] = {0};
1918 char gateway[100] = {0};
1919 char if_name[40] = {0};
1924 input_rv = test_get_user_int("Input Address type to get"
1925 "(1:IPV4, 2:IPV6):", &input);
1927 if (input_rv == false) {
1928 printf("Invalid input!!\n");
1934 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1937 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1940 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1943 g_strstrip(ip_addr);
1944 g_strstrip(gateway);
1945 g_strstrip(if_name);
1946 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
1947 if (rv != CONNECTION_ERROR_NONE) {
1948 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1951 printf("Remove Route successfully\n");
1956 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1959 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1962 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1965 g_strstrip(ip_addr);
1966 g_strstrip(gateway);
1967 g_strstrip(if_name);
1968 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
1969 if (rv != CONNECTION_ERROR_NONE) {
1970 printf("Fail to remove the route [%d]\n", rv);
1973 printf("Remove Route successfully\n");
1977 printf("Wrong IP address family!!\n");
1986 int test_get_bt_state(void)
1989 connection_bt_state_e bt_state;
1991 rv = connection_get_bt_state(connection, &bt_state);
1993 if (rv != CONNECTION_ERROR_NONE) {
1994 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1998 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
2003 int test_get_profile_id(void)
2005 connection_profile_h profile;
2008 printf("\n** Choose a profile to see profile id. **\n");
2009 if (test_get_user_selected_profile(&profile, true) == false)
2012 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2013 printf("Fail to get profile name\n");
2016 printf("Profile id : %s\n", profile_id);
2023 int test_get_mac_address(void)
2025 int rv = 0, type = 0;
2026 connection_type_e conn_type;
2027 char *mac_addr = NULL;
2029 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2033 conn_type = CONNECTION_TYPE_WIFI;
2036 conn_type = CONNECTION_TYPE_ETHERNET;
2039 printf("Wrong number!!\n");
2043 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2045 if (rv != CONNECTION_ERROR_NONE) {
2046 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2050 printf("mac address is %s\n", mac_addr);
2057 int test_get_ethernet_cable_state(void)
2060 connection_ethernet_cable_state_e cable_state;
2062 rv = connection_get_ethernet_cable_state(connection, &cable_state);
2064 if (rv != CONNECTION_ERROR_NONE) {
2065 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2069 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2074 int test_reset_profile(void)
2076 int type, sim_id, rv;
2078 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2080 if (rv == false || (type != 0 && type != 1)) {
2081 printf("Invalid input!!\n");
2085 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2087 if (rv == false || (sim_id != 0 && sim_id != 1)) {
2088 printf("Invalid input!!\n");
2092 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2098 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2100 printf("IPv6 Address : %s\n", ipv6_address);
2104 int test_foreach_ipv6_address(void)
2108 connection_type_e conn_type;
2110 test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2114 conn_type = CONNECTION_TYPE_WIFI;
2117 conn_type = CONNECTION_TYPE_ETHERNET;
2120 printf("Wrong number!!\n");
2124 rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2125 if (rv != CONNECTION_ERROR_NONE) {
2126 printf("Fail to get IPv6 address\n");
2133 int test_is_metered_network(void)
2138 rv = connection_is_metered_network(connection, &metered_state);
2140 if (rv != CONNECTION_ERROR_NONE) {
2141 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2145 printf("Retval = [%s] metered state [%s]\n",
2146 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2151 int test_start_tcpdump(void)
2153 if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2157 printf("Successfully started tcpdump\n");
2162 int test_stop_tcpdump(void)
2164 if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2168 printf("Successfully stopped tcpdump\n");
2173 int test_get_tcpdump_state(void)
2175 gboolean tcpdump_state = FALSE;
2177 if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
2181 printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2186 int main(int argc, char **argv)
2188 GMainLoop *mainloop;
2189 mainloop = g_main_loop_new(NULL, FALSE);
2191 GIOChannel *channel = g_io_channel_unix_new(0);
2192 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
2194 printf("Test Thread created...\n");
2196 g_main_loop_run(mainloop);
2201 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
2206 memset(a, '\0', 100);
2207 printf("Event received from stdin\n");
2209 rv = read(0, a, 100);
2211 if (rv < 0 || a[0] == '0') {
2212 if (connection != NULL)
2213 test_deregister_client();
2218 if (*a == '\n' || *a == '\r') {
2220 printf("\n\n Network Connection API Test App\n\n");
2221 printf("Options..\n");
2222 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
2223 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
2224 printf("2 - Destroy Handle(unset callbacks automatically)\n");
2225 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
2226 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
2227 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
2228 printf("6 - Get current proxy address \n");
2229 printf("7 - Get current Ip address\n");
2230 printf("8 - Get cellular data call statistics\n");
2231 printf("9 - Get WiFi data call statistics\n");
2232 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
2233 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
2234 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
2235 printf("d - Open connection with profile\n");
2236 printf("e - Get default cellular service by type\n");
2237 printf("f - Set default cellular service by type\n");
2238 printf("g - Close connection with profile\n");
2239 printf("h - Add profile(Cellular and Wifi only)\n");
2240 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
2241 printf("j - Update profile\n");
2242 printf("k - Get profile info\n");
2243 printf("l - Refresh profile info\n");
2244 printf("m - Set state changed callback\n");
2245 printf("n - Unset state changed callback\n");
2246 printf("o - Reset cellular data call statistics\n");
2247 printf("p - Reset WiFi data call statistics\n");
2248 printf("q - Add new route\n");
2249 printf("r - Remove a route\n");
2250 printf("s - Get Bluetooth state\n");
2251 printf("t - Get profile id\n");
2252 printf("u - Reset profile\n");
2253 printf("v - Get all cellular default profiles\n");
2254 printf("w - Get mac address\n");
2255 printf("x - Get ethernet cable state\n");
2256 printf("B - Add IPv6 new route\n");
2257 printf("C - Remove IPv6 route\n");
2258 printf("D - Add new route entry\n");
2259 printf("E - Remove route entry\n");
2260 printf("F - Get all IPv6 address\n");
2261 printf("G - Get metered state\n");
2263 printf(LOG_BLUE "[Extension API]\n" LOG_END);
2264 printf("H - Start TCP Dump\n");
2265 printf("I - Stop TCP Dump\n");
2266 printf("J - Get TCP Dump State\n");
2267 printf(LOG_RED "0 - Exit \n" LOG_END);
2268 printf("ENTER - Show options menu.......\n");
2274 rv = test_register_client();
2277 rv = test_deregister_client();
2280 rv = test_get_network_state();
2283 rv = test_get_cellular_state();
2286 rv = test_get_wifi_state();
2289 rv = test_get_current_proxy();
2292 rv = test_get_current_ip();
2295 rv = test_get_call_statistics_info();
2298 rv = test_get_wifi_call_statistics_info();
2301 rv = test_get_profile_list();
2304 rv = test_get_connected_profile_list();
2307 rv = test_get_current_profile();
2310 rv = test_open_profile();
2313 rv = test_get_default_cellular_service_type();
2316 rv = test_set_default_cellular_service_type();
2319 rv = test_close_profile();
2322 rv = test_add_profile();
2325 rv = test_remove_profile();
2328 rv = test_update_profile();
2331 rv = test_get_profile_info();
2334 rv = test_refresh_profile_info();
2337 rv = test_set_state_changed_callback();
2340 rv = test_unset_state_changed_callback();
2343 rv = test_reset_call_statistics_info();
2346 rv = test_reset_wifi_call_statistics_info();
2349 rv = test_add_route();
2352 rv = test_remove_route();
2355 rv = test_get_bt_state();
2358 rv = test_get_profile_id();
2361 rv = test_reset_profile();
2364 rv = test_get_default_profile_list();
2367 rv = test_get_mac_address();
2370 rv = test_get_ethernet_cable_state();
2373 rv = test_add_route_ipv6();
2376 rv = test_remove_route_ipv6();
2379 rv = test_add_route_entry();
2382 rv = test_remove_route_entry();
2385 rv = test_foreach_ipv6_address();
2388 rv = test_is_metered_network();
2392 rv = test_start_tcpdump();
2395 rv = test_stop_tcpdump();
2398 rv = test_get_tcpdump_state();
2404 printf("Operation succeeded!\n");
2406 printf("Operation failed!\n");