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 <tizen_error.h>
27 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1;}
29 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
31 connection_h connection = NULL;
32 static GSList *state_cb_list = NULL;
35 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
37 if (msg == NULL || buf == NULL || buf_size < 2)
42 memset(buf, 0, buf_size);
43 rv = read(0, buf, buf_size - 1);
45 if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
50 buf[strlen(buf) - 1] = '\0';
55 static bool test_get_user_int(const char *msg, int *num)
57 if (msg == NULL || num == NULL)
63 rv = read(0, buf, 32);
65 if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
72 static const char *test_print_state(connection_profile_state_e state)
75 case CONNECTION_PROFILE_STATE_DISCONNECTED:
76 return "Disconnected";
77 case CONNECTION_PROFILE_STATE_ASSOCIATION:
79 case CONNECTION_PROFILE_STATE_CONFIGURATION:
80 return "Configuration";
81 case CONNECTION_PROFILE_STATE_CONNECTED:
88 static void test_type_changed_callback(connection_type_e type, void* user_data)
90 printf("Type changed callback, connection type : %d\n", type);
93 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
95 printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
96 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
99 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
101 printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
102 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
105 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
108 connection_profile_h profile = user_data;
113 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
116 printf("[%s] : %s\n", test_print_state(state), profile_name);
117 g_free(profile_name);
120 static void test_connection_opened_callback(connection_error_e result, void* user_data)
122 if (result == CONNECTION_ERROR_NONE)
123 printf("Connection open Succeeded\n");
125 printf("Connection open Failed, err : %d\n", result);
128 static void test_connection_closed_callback(connection_error_e result, void* user_data)
130 if (result == CONNECTION_ERROR_NONE)
131 printf("Connection close Succeeded\n");
133 printf("Connection close Failed, err : %d\n", result);
136 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
138 if (result == CONNECTION_ERROR_NONE)
139 printf("Default profile setting Succeeded\n");
141 printf("Default profile setting Failed, err : %d\n", result);
144 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
149 connection_profile_type_e profile_type;
150 connection_profile_state_e profile_state;
151 connection_profile_iterator_h profile_iter;
152 connection_profile_h profile_h;
154 connection_profile_h profile_list[100] = {0,};
155 int profile_count = 0;
157 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
158 if (rv != CONNECTION_ERROR_NONE) {
159 printf("Fail to get profile iterator [%d]\n", rv);
163 while (connection_profile_iterator_has_next(profile_iter)) {
164 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
165 printf("Fail to get profile handle\n");
169 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
170 printf("Fail to get profile name\n");
174 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
175 printf("Fail to get profile type\n");
176 g_free(profile_name);
180 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
181 printf("Fail to get profile state\n");
182 g_free(profile_name);
186 if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
188 connection_profile_get_wifi_essid(profile_h, &essid);
189 printf("%d. state:[%s], profile name:%s, essid:%s\n",
190 profile_count, test_print_state(profile_state),
191 profile_name, (essid)? essid : "");
194 profile_list[profile_count] = profile_h;
197 printf("%d. state:[%s], profile name : %s\n",
198 profile_count, test_print_state(profile_state), profile_name);
200 profile_list[profile_count] = profile_h;
204 g_free(profile_name);
205 if (profile_count >= 100)
212 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
213 input >= profile_count ||
215 printf("Wrong number!!\n");
220 *profile = profile_list[input];
225 static int test_update_cellular_info(connection_profile_h profile)
228 char input_str1[100] = {0,};
229 char input_str2[100] = {0,};
233 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
234 "Prepaid MMS:4, Tethering:5, Application:6)"
235 " - (Enter for skip) :", &input_int)) {
238 rv = connection_profile_set_cellular_service_type(profile,
239 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
242 rv = connection_profile_set_cellular_service_type(profile,
243 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
246 rv = connection_profile_set_cellular_service_type(profile,
247 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
250 rv = connection_profile_set_cellular_service_type(profile,
251 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
254 rv = connection_profile_set_cellular_service_type(profile,
255 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
258 rv = connection_profile_set_cellular_service_type(profile,
259 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
265 if (rv != CONNECTION_ERROR_NONE)
270 if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
271 rv = connection_profile_set_cellular_apn(profile, input_str1);
272 if (rv != CONNECTION_ERROR_NONE)
276 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
277 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
278 if (rv != CONNECTION_ERROR_NONE)
282 if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
283 rv = connection_profile_set_cellular_home_url(profile, input_str1);
284 if (rv != CONNECTION_ERROR_NONE)
288 if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
291 rv = connection_profile_set_cellular_auth_info(profile,
292 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
293 if (rv != CONNECTION_ERROR_NONE)
298 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
301 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
303 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
305 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
308 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
309 if (rv != CONNECTION_ERROR_NONE)
317 static int test_update_wifi_info(connection_profile_h profile)
320 char input_str[100] = {0,};
322 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
323 rv = connection_profile_set_wifi_passphrase(profile, input_str);
324 if (rv != CONNECTION_ERROR_NONE)
331 static int test_update_ip_info(connection_profile_h profile)
334 char input_str[100] = {0,};
336 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
337 rv = connection_profile_set_ip_address(profile,
338 CONNECTION_ADDRESS_FAMILY_IPV4,
340 if (rv != CONNECTION_ERROR_NONE)
344 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
345 rv = connection_profile_set_subnet_mask(profile,
346 CONNECTION_ADDRESS_FAMILY_IPV4,
348 if (rv != CONNECTION_ERROR_NONE)
352 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
353 rv = connection_profile_set_gateway_address(profile,
354 CONNECTION_ADDRESS_FAMILY_IPV4,
356 if (rv != CONNECTION_ERROR_NONE)
360 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
361 rv = connection_profile_set_dns_address(profile,
363 CONNECTION_ADDRESS_FAMILY_IPV4,
365 if (rv != CONNECTION_ERROR_NONE)
368 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
369 rv = connection_profile_set_dns_address(profile,
371 CONNECTION_ADDRESS_FAMILY_IPV4,
373 if (rv != CONNECTION_ERROR_NONE)
381 static int test_update_proxy_info(connection_profile_h profile)
385 char input_str[100] = {0,};
387 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
388 " - (Enter for skip) :", &input_int)) {
391 rv = connection_profile_set_proxy_type(profile,
392 CONNECTION_PROXY_TYPE_DIRECT);
394 if (rv != CONNECTION_ERROR_NONE)
399 rv = connection_profile_set_proxy_type(profile,
400 CONNECTION_PROXY_TYPE_AUTO);
403 rv = connection_profile_set_proxy_type(profile,
404 CONNECTION_PROXY_TYPE_MANUAL);
410 if (rv != CONNECTION_ERROR_NONE)
413 if (test_get_user_string("Input auto Proxy URL or Proxy address"
414 " - (Enter for skip) :", input_str, 100)) {
415 rv = connection_profile_set_proxy_address(profile,
416 CONNECTION_ADDRESS_FAMILY_IPV4,
418 if (rv != CONNECTION_ERROR_NONE)
428 static int test_update_network_info(connection_profile_h profile)
433 if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
434 " - (Enter for skip) :", &input_int)) {
437 rv = connection_profile_set_ip_config_type(profile,
438 CONNECTION_ADDRESS_FAMILY_IPV4,
439 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
442 rv = connection_profile_set_ip_config_type(profile,
443 CONNECTION_ADDRESS_FAMILY_IPV4,
444 CONNECTION_IP_CONFIG_TYPE_STATIC);
445 if (rv != CONNECTION_ERROR_NONE)
448 if (test_update_ip_info(profile) == -1)
451 if (test_update_proxy_info(profile) == -1)
458 if (rv != CONNECTION_ERROR_NONE)
466 static void test_print_cellular_info(connection_profile_h profile)
468 connection_cellular_network_type_e network_type;
469 connection_cellular_service_type_e service_type;
471 connection_cellular_auth_type_e auth_type;
472 char *user_name = NULL;
473 char *password = NULL;
474 char *home_url = NULL;
475 bool roaming = false;
477 if (connection_profile_get_cellular_network_type(profile, &network_type) != CONNECTION_ERROR_NONE)
478 printf("Fail to get cellular network type!\n");
480 printf("Cellular network type : %d\n", network_type);
482 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
483 printf("Fail to get cellular service type!\n");
485 printf("Cellular service type : %d\n", service_type);
487 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
488 printf("Fail to get cellular APN!\n");
490 printf("Cellular APN : %s\n", apn);
494 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
495 printf("Fail to get auth info!\n");
497 printf("Cellular auth type : %d\n", auth_type);
498 printf("Cellular user_name : %s\n", user_name);
499 printf("Cellular password : %s\n", password);
504 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
505 printf("Fail to get cellular home url!\n");
507 printf("Cellular home url : %s\n", home_url);
511 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
512 printf("Fail to get cellular is roaming!\n");
514 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
517 static void test_print_wifi_info(connection_profile_h profile)
524 connection_wifi_security_type_e security_type;
525 connection_wifi_encryption_type_e encryption_type;
526 bool pass_required = false;
527 bool wps_supported = false;
529 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
530 printf("Fail to get Wi-Fi essid!\n");
532 printf("Wi-Fi essid : %s\n", essid);
536 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
537 printf("Fail to get Wi-Fi bssid!\n");
539 printf("Wi-Fi bssid : %s\n", bssid);
543 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
544 printf("Fail to get Wi-Fi rssi!\n");
546 printf("Wi-Fi rssi : %d\n", rssi);
548 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
549 printf("Fail to get Wi-Fi frequency!\n");
551 printf("Wi-Fi frequency : %d\n", frequency);
553 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
554 printf("Fail to get Wi-Fi max speed!\n");
556 printf("Wi-Fi max speed : %d\n", max_speed);
558 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
559 printf("Fail to get Wi-Fi security type!\n");
561 printf("Wi-Fi security type : %d\n", security_type);
563 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
564 printf("Fail to get Wi-Fi encryption type!\n");
566 printf("Wi-Fi encryption type : %d\n", encryption_type);
568 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
569 printf("Fail to get Wi-Fi passphrase required!\n");
571 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
573 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
574 printf("Fail to get Wi-Fi wps info\n");
576 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
579 static void test_print_network_info(connection_profile_h profile)
581 char *interface_name = NULL;
582 connection_ip_config_type_e ip_type;
585 char *gateway = NULL;
588 connection_proxy_type_e proxy_type;
591 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
592 printf("Fail to get interface name!\n");
594 printf("Interface name : %s\n", interface_name);
595 g_free(interface_name);
598 if (connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type) != CONNECTION_ERROR_NONE)
599 printf("Fail to get ipconfig type!\n");
601 printf("Ipconfig type : %d\n", ip_type);
603 if (connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip) != CONNECTION_ERROR_NONE)
604 printf("Fail to get IP address!\n");
606 printf("IP address : %s\n", ip);
610 if (connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet) != CONNECTION_ERROR_NONE)
611 printf("Fail to get subnet mask!\n");
613 printf("Subnet mask : %s\n", subnet);
617 if (connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway) != CONNECTION_ERROR_NONE)
618 printf("Fail to get gateway!\n");
620 printf("Gateway : %s\n", gateway);
624 if (connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns1) != CONNECTION_ERROR_NONE)
625 printf("Fail to get DNS1!\n");
627 printf("DNS1 : %s\n", dns1);
631 if (connection_profile_get_dns_address(profile, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &dns2) != CONNECTION_ERROR_NONE)
632 printf("Fail to get DNS2!\n");
634 printf("DNS2 : %s\n", dns2);
638 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
639 printf("Fail to get proxy type!\n");
641 printf("Proxy type : %d\n", proxy_type);
643 if (connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy) != CONNECTION_ERROR_NONE)
644 printf("Fail to get proxy!\n");
646 printf("Proxy : %s\n", proxy);
651 int test_register_client(void)
654 int err = connection_create(&connection);
656 if (CONNECTION_ERROR_NONE == err) {
657 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
658 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
659 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
661 printf("Client registration failed %d\n", err);
665 printf("Client registration success\n");
669 int test_deregister_client(void)
673 connection_profile_h profile;
675 if (connection != NULL)
676 rv = connection_destroy(connection);
678 printf("Cannot deregister : Handle is NULL\n");
679 rv = CONNECTION_ERROR_INVALID_OPERATION;
682 if (rv != CONNECTION_ERROR_NONE){
683 printf("Client deregistration fail [%d]\n", rv);
688 for (list = state_cb_list; list; list = list->next) {
689 profile = list->data;
690 connection_profile_destroy(profile);
693 g_slist_free(state_cb_list);
694 state_cb_list = NULL;
698 printf("Client deregistration success\n");
703 int test_get_network_state(void)
706 connection_type_e net_state;
708 rv = connection_get_type(connection, &net_state);
710 if (rv != CONNECTION_ERROR_NONE) {
711 printf("Fail to get network state [%d]\n", rv);
715 printf("Retval = %d network connection state [%d]\n", rv, net_state);
720 int test_get_cellular_state(void)
723 connection_cellular_state_e cellular_state;
725 rv = connection_get_cellular_state(connection, &cellular_state);
727 if (rv != CONNECTION_ERROR_NONE) {
728 printf("Fail to get Cellular state [%d]\n", rv);
732 printf("Retval = %d Cellular state [%d]\n", rv, cellular_state);
737 int test_get_wifi_state(void)
740 connection_wifi_state_e wifi_state;
742 rv = connection_get_wifi_state(connection, &wifi_state);
744 if (rv != CONNECTION_ERROR_NONE) {
745 printf("Fail to get WiFi state [%d]\n", rv);
749 printf("Retval = %d WiFi state [%d]\n", rv, wifi_state);
754 int test_get_current_proxy(void)
756 char *proxy_addr = NULL;
758 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
760 if (proxy_addr == NULL) {
761 printf("Proxy address does not exist\n");
765 printf("Current Proxy [%s]\n", proxy_addr);
771 int test_get_current_ip(void)
773 char *ip_addr = NULL;
775 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
777 if (ip_addr == NULL) {
778 printf("IP address does not exist\n");
782 printf("IPv4 address : %s\n", ip_addr);
788 int test_get_call_statistics_info(void)
792 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
793 printf("last recv data size [%lld]\n", rv);
794 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
795 printf("last sent data size [%lld]\n",rv );
796 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
797 printf("total received data size [%lld]\n",rv );
798 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
799 printf("total sent data size [%lld]\n", rv);
804 int test_get_wifi_call_statistics_info(void)
808 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
809 printf("WiFi last recv data size [%lld]\n", rv);
810 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
811 printf("WiFi last sent data size [%lld]\n",rv );
812 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
813 printf("WiFi total received data size [%lld]\n",rv );
814 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
815 printf("WiFi total sent data size [%lld]\n", rv);
820 int test_get_profile_list(void)
822 if (test_get_user_selected_profile(NULL, false) == false)
828 int test_get_connected_profile_list(void)
831 char *profile_name = NULL;
832 connection_profile_iterator_h profile_iter;
833 connection_profile_h profile_h;
835 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
836 if (rv != CONNECTION_ERROR_NONE) {
837 printf("Fail to get profile iterator [%d]\n", rv);
841 while (connection_profile_iterator_has_next(profile_iter)) {
842 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
843 printf("Fail to get profile handle\n");
847 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
848 printf("Fail to get profile name\n");
851 printf("profile name : %s\n", profile_name);
852 g_free(profile_name);
858 int test_get_current_profile(void)
861 char *profile_name = NULL;
862 connection_profile_h profile_h;
864 rv = connection_get_current_profile(connection, &profile_h);
865 if (rv != CONNECTION_ERROR_NONE) {
866 printf("Fail to get profile iterator [%d]\n", rv);
870 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
871 printf("Fail to get profile name\n");
874 printf("profile name : %s\n", profile_name);
875 g_free(profile_name);
877 connection_profile_destroy(profile_h);
882 int test_open_profile(void)
884 connection_profile_h profile;
886 printf("\n** Choose a profile to open. **\n");
888 if (test_get_user_selected_profile(&profile, true) == false)
891 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
892 printf("Connection open Failed!!\n");
899 int test_get_default_cellular_service_type(void)
904 connection_profile_h profile;
905 char *profile_name = NULL;
907 rv = test_get_user_int("Input profile type to get"
908 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering):", &input);
911 printf("Invalid input!!\n");
917 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
920 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
923 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
926 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
929 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
932 printf("Wrong number!!\n");
936 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
939 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
940 printf("Fail to get profile name\n");
941 connection_profile_destroy(profile);
944 printf("Default profile name : %s\n", profile_name);
945 g_free(profile_name);
947 connection_profile_destroy(profile);
952 int test_set_default_cellular_service_type(void)
954 connection_profile_h profile;
955 connection_cellular_service_type_e type;
958 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
960 if (rv == false || (input != 1 && input != 2)) {
961 printf("Invalid input!!\n");
965 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
967 if (test_get_user_selected_profile(&profile, true) == false)
970 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
971 printf("Fail to get cellular service type\n");
976 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
979 if (connection_set_default_cellular_service_profile_async(connection,
980 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
987 int test_close_profile(void)
989 connection_profile_h profile;
991 printf("\n** Choose a profile to close. **\n");
993 if (test_get_user_selected_profile(&profile, true) == false)
996 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
997 printf("Connection close Failed!!\n");
1004 int test_add_profile(void)
1007 connection_profile_h profile;
1008 char input_str[100] = {0,};
1010 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1013 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1014 if (rv != CONNECTION_ERROR_NONE)
1015 RETURN_FAIL_DESTROY(profile);
1017 if (test_update_cellular_info(profile) == -1)
1018 RETURN_FAIL_DESTROY(profile);
1020 rv = connection_add_profile(connection, profile);
1021 if (rv != CONNECTION_ERROR_NONE)
1022 RETURN_FAIL_DESTROY(profile);
1024 connection_profile_destroy(profile);
1028 int test_remove_profile(void)
1030 connection_profile_h profile;
1032 printf("\n** Choose a profile to remove. **\n");
1033 if (test_get_user_selected_profile(&profile, true) == false)
1036 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1037 printf("Remove profile Failed!!\n");
1044 int test_update_profile(void)
1048 connection_profile_type_e prof_type;
1049 connection_profile_h profile;
1051 printf("\n** Choose a profile to update. **\n");
1052 if (test_get_user_selected_profile(&profile, true) == false)
1055 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1058 switch (prof_type) {
1059 case CONNECTION_PROFILE_TYPE_CELLULAR:
1060 if (test_update_cellular_info(profile) == -1)
1064 case CONNECTION_PROFILE_TYPE_WIFI:
1065 if (test_update_wifi_info(profile) == -1)
1068 if (test_update_network_info(profile) == -1)
1072 case CONNECTION_PROFILE_TYPE_ETHERNET:
1073 case CONNECTION_PROFILE_TYPE_BT:
1074 printf("Not supported!\n");
1080 rv = connection_update_profile(connection, profile);
1081 if (rv != CONNECTION_ERROR_NONE)
1087 int test_get_profile_info(void)
1089 connection_profile_type_e prof_type;
1090 connection_profile_state_e profile_state;
1091 connection_profile_h profile;
1092 char *profile_name = NULL;
1094 printf("\n** Choose a profile to print. **\n");
1095 if (test_get_user_selected_profile(&profile, true) == false)
1098 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1099 printf("Fail to get profile name\n");
1102 printf("Profile Name : %s\n", profile_name);
1103 g_free(profile_name);
1106 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1107 printf("Fail to get profile state\n");
1110 printf("Profile State : %s\n", test_print_state(profile_state));
1113 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1116 switch (prof_type) {
1117 case CONNECTION_PROFILE_TYPE_CELLULAR:
1118 printf("Profile Type : Cellular\n");
1119 test_print_cellular_info(profile);
1121 case CONNECTION_PROFILE_TYPE_WIFI:
1122 printf("Profile Type : Wi-Fi\n");
1123 test_print_wifi_info(profile);
1125 case CONNECTION_PROFILE_TYPE_ETHERNET:
1126 printf("Profile Type : Ethernet\n");
1128 case CONNECTION_PROFILE_TYPE_BT:
1129 printf("Profile Type : Bluetooth\n");
1135 test_print_network_info(profile);
1140 int test_refresh_profile_info(void)
1142 connection_profile_type_e prof_type;
1143 connection_profile_state_e profile_state;
1144 connection_profile_h profile;
1145 char *profile_name = NULL;
1147 printf("\n** Choose a profile to refresh. **\n");
1148 if (test_get_user_selected_profile(&profile, true) == false)
1151 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1154 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1155 printf("Fail to get profile name\n");
1158 printf("Profile Name : %s\n", profile_name);
1159 g_free(profile_name);
1162 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1163 printf("Fail to get profile state\n");
1166 printf("Profile State : %s\n", test_print_state(profile_state));
1169 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1172 switch (prof_type) {
1173 case CONNECTION_PROFILE_TYPE_CELLULAR:
1174 printf("Profile Type : Cellular\n");
1175 test_print_cellular_info(profile);
1177 case CONNECTION_PROFILE_TYPE_WIFI:
1178 printf("Profile Type : Wi-Fi\n");
1179 test_print_wifi_info(profile);
1181 case CONNECTION_PROFILE_TYPE_ETHERNET:
1182 printf("Profile Type : Ethernet\n");
1184 case CONNECTION_PROFILE_TYPE_BT:
1185 printf("Profile Type : Bluetooth\n");
1191 test_print_network_info(profile);
1196 int test_set_state_changed_callback()
1198 connection_profile_h profile;
1199 connection_profile_h profile_clone;
1201 printf("\n** Choose a profile to set callback. **\n");
1202 if (test_get_user_selected_profile(&profile, true) == false)
1205 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1208 if (connection_profile_set_state_changed_cb(profile,
1209 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1210 connection_profile_destroy(profile_clone);
1214 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1219 int test_unset_state_changed_callback()
1221 connection_profile_h profile;
1223 char *profile_name = NULL;
1227 printf("\n** Choose a profile to unset callback. **\n");
1228 for (list = state_cb_list; list; list = list->next) {
1229 profile = list->data;
1230 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1231 printf("Fail to get profile name!\n");
1234 printf("%d. %s\n", count, profile_name);
1235 g_free(profile_name);
1241 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1244 printf("Wrong number!!\n");
1249 for (list = state_cb_list; list; list = list->next) {
1250 if (count == input) {
1251 profile = list->data;
1261 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1264 state_cb_list = g_slist_remove(state_cb_list, profile);
1265 connection_profile_destroy(profile);
1270 int test_reset_call_statistics_info(void)
1272 int ret = CONNECTION_ERROR_NONE;
1274 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1275 printf("reset last recv data size [%d]\n", ret);
1276 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1277 printf("last sent data size [%d]\n", ret);
1278 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1279 printf("total received data size [%d]\n", ret);
1280 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1281 printf("total sent data size [%d]\n", ret);
1286 int test_reset_wifi_call_statistics_info(void)
1288 int ret = CONNECTION_ERROR_NONE;
1290 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1291 printf("WiFi last sent data size [%d]\n", ret);
1292 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1293 printf("WiFi last recv data size [%d]\n", ret);
1294 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1295 printf("WiFi total sent data size [%d]\n", ret);
1296 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1297 printf("WiFi total received data size [%d]\n", ret);
1302 int test_add_route(void)
1308 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 30) == false)
1311 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1314 rv = connection_add_route(connection, if_name, ip_addr);
1315 if (rv != CONNECTION_ERROR_NONE) {
1316 printf("Fail to get add new route [%d]\n", rv);
1323 int test_get_bt_state(void)
1326 connection_bt_state_e bt_state;
1328 rv = connection_get_bt_state(connection, &bt_state);
1330 if (rv != CONNECTION_ERROR_NONE) {
1331 printf("Fail to get Bluetooth state [%d]\n", rv);
1335 printf("Retval = %d, Bluetooth state [%d]\n", rv, bt_state);
1340 int test_get_profile_id(void)
1342 connection_profile_h profile;
1345 printf("\n** Choose a profile to see profile id. **\n");
1346 if (test_get_user_selected_profile(&profile, true) == false)
1349 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1350 printf("Fail to get profile name\n");
1353 printf("Profile id : %s\n", profile_id);
1360 int main(int argc, char **argv)
1363 GMainLoop *mainloop;
1364 mainloop = g_main_loop_new (NULL, FALSE);
1366 GIOChannel *channel = g_io_channel_unix_new(0);
1367 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread,NULL );
1369 printf("Test Thread created...\n");
1371 g_main_loop_run (mainloop);
1376 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1381 memset(a, '\0', 100);
1382 printf("Event received from stdin\n");
1384 rv = read(0, a, 100);
1386 if (rv < 0 || a[0] == '0') {
1387 if (connection != NULL)
1388 test_deregister_client();
1393 if (*a == '\n' || *a == '\r'){
1394 printf("\n\n Network Connection API Test App\n\n");
1395 printf("Options..\n");
1396 printf("1 - Create Handle and set callbacks\n");
1397 printf("2 - Destroy Handle(unset callbacks automatically)\n");
1398 printf("3 - Get network state\n");
1399 printf("4 - Get cellular state (please insert SIM Card)\n");
1400 printf("5 - Get wifi state (please turn on WiFi)\n");
1401 printf("6 - Get current proxy address \n");
1402 printf("7 - Get current Ip address\n");
1403 printf("8 - Get cellular data call statistics\n");
1404 printf("9 - Get WiFi data call statistics\n");
1405 printf("a - Get Profile list\n");
1406 printf("b - Get Connected Profile list\n");
1407 printf("c - Get Current profile\n");
1408 printf("d - Open connection with profile\n");
1409 printf("e - Get default cellular service by type\n");
1410 printf("f - Set default cellular service by type\n");
1411 printf("g - Close connection with profile\n");
1412 printf("h - Add profile(Cellular only)\n");
1413 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
1414 printf("j - Update profile\n");
1415 printf("k - Get profile info\n");
1416 printf("l - Refresh profile info\n");
1417 printf("m - Set state changed callback\n");
1418 printf("n - Unset state changed callback\n");
1419 printf("o - Reset cellular data call statistics\n");
1420 printf("p - Reset WiFi data call statistics\n");
1421 printf("q - Add new route\n");
1422 printf("r - Get Bluetooth state\n");
1423 printf("s - Get profile id\n");
1424 printf("0 - Exit \n");
1425 printf("ENTER - Show options menu.......\n");
1430 rv = test_register_client();
1433 rv = test_deregister_client();
1436 rv = test_get_network_state();
1439 rv = test_get_cellular_state();
1442 rv = test_get_wifi_state();
1445 rv = test_get_current_proxy();
1448 rv = test_get_current_ip();
1451 rv = test_get_call_statistics_info();
1454 rv = test_get_wifi_call_statistics_info();
1457 rv = test_get_profile_list();
1460 rv = test_get_connected_profile_list();
1463 rv = test_get_current_profile();
1466 rv = test_open_profile();
1469 rv = test_get_default_cellular_service_type();
1472 rv = test_set_default_cellular_service_type();
1475 rv = test_close_profile();
1478 rv = test_add_profile();
1481 rv = test_remove_profile();
1484 rv = test_update_profile();
1487 rv = test_get_profile_info();
1490 rv = test_refresh_profile_info();
1493 rv = test_set_state_changed_callback();
1496 rv = test_unset_state_changed_callback();
1499 rv = test_reset_call_statistics_info();
1502 rv = test_reset_wifi_call_statistics_info();
1505 rv = test_add_route();
1508 rv = test_get_bt_state();
1511 rv = test_get_profile_id();
1516 printf("Operation succeeded!\n");
1518 printf("Operation failed!\n");