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_internet_state(connection_internet_state_e state)
97 if (state == CONNECTION_INTERNET_STATE_ONLINE)
103 static const char *test_print_connection_type(connection_type_e type)
106 case CONNECTION_TYPE_DISCONNECTED:
107 return "Disconnected";
108 case CONNECTION_TYPE_WIFI:
110 case CONNECTION_TYPE_CELLULAR:
112 case CONNECTION_TYPE_ETHERNET:
114 case CONNECTION_TYPE_BT:
116 case CONNECTION_TYPE_NET_PROXY:
123 static const char *test_print_cellular_state(connection_cellular_state_e state)
126 case CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE:
127 return "Out of service";
128 case CONNECTION_CELLULAR_STATE_FLIGHT_MODE:
129 return "Flight mode";
130 case CONNECTION_CELLULAR_STATE_ROAMING_OFF:
131 return "Roaming off";
132 case CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE:
133 return "Call only available";
134 case CONNECTION_CELLULAR_STATE_AVAILABLE:
136 case CONNECTION_CELLULAR_STATE_CONNECTED:
143 static const char *test_print_wifi_state(connection_wifi_state_e state)
146 case CONNECTION_WIFI_STATE_DEACTIVATED:
147 return "Deactivated";
148 case CONNECTION_WIFI_STATE_DISCONNECTED:
149 return "Disconnected";
150 case CONNECTION_WIFI_STATE_CONNECTED:
157 static const char *test_print_wifi_security_type(connection_wifi_security_type_e type)
160 case CONNECTION_WIFI_SECURITY_TYPE_NONE:
162 case CONNECTION_WIFI_SECURITY_TYPE_WEP:
164 case CONNECTION_WIFI_SECURITY_TYPE_WPA_PSK:
166 case CONNECTION_WIFI_SECURITY_TYPE_WPA2_PSK:
168 case CONNECTION_WIFI_SECURITY_TYPE_EAP:
170 case CONNECTION_WIFI_SECURITY_TYPE_SAE:
177 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
180 case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
182 case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
184 case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
186 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
187 return "Prepaid internet";
188 case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
189 return "Prepaid MMS";
190 case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
192 case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
193 return "Application";
199 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
202 case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
204 case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
206 case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
212 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
215 case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
217 case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
219 case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
221 case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
227 static const char *test_print_error(connection_error_e error)
230 case CONNECTION_ERROR_NONE:
231 return "CONNECTION_ERROR_NONE";
232 case CONNECTION_ERROR_INVALID_PARAMETER:
233 return "CONNECTION_ERROR_INVALID_PARAMETER";
234 case CONNECTION_ERROR_OUT_OF_MEMORY:
235 return "CONNECTION_ERROR_OUT_OF_MEMORY";
236 case CONNECTION_ERROR_INVALID_OPERATION:
237 return "CONNECTION_ERROR_INVALID_OPERATION";
238 case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
239 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
240 case CONNECTION_ERROR_OPERATION_FAILED:
241 return "CONNECTION_ERROR_OPERATION_FAILED";
242 case CONNECTION_ERROR_ITERATOR_END:
243 return "CONNECTION_ERROR_ITERATOR_END";
244 case CONNECTION_ERROR_NO_CONNECTION:
245 return "CONNECTION_ERROR_NO_CONNECTION";
246 case CONNECTION_ERROR_NOW_IN_PROGRESS:
247 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
248 case CONNECTION_ERROR_ALREADY_EXISTS:
249 return "CONNECTION_ERROR_ALREADY_EXISTS";
250 case CONNECTION_ERROR_OPERATION_ABORTED:
251 return "CONNECTION_ERROR_OPERATION_ABORTED";
252 case CONNECTION_ERROR_DHCP_FAILED:
253 return "CONNECTION_ERROR_DHCP_FAILED";
254 case CONNECTION_ERROR_INVALID_KEY:
255 return "CONNECTION_ERROR_INVALID_KEY";
256 case CONNECTION_ERROR_NO_REPLY:
257 return "CONNECTION_ERROR_NO_REPLY";
258 case CONNECTION_ERROR_PERMISSION_DENIED:
259 return "CONNECTION_ERROR_PERMISSION_DENIED";
260 case CONNECTION_ERROR_NOT_SUPPORTED:
261 return "CONNECTION_ERROR_NOT_SUPPORTED";
262 case CONNECTION_ERROR_NOT_INITIALIZED:
263 return "CONNECTION_ERROR_NOT_INITIALIZED";
264 case CONNECTION_ERROR_ALREADY_INITIALIZED:
265 return "CONNECTION_ERROR_ALREADY_INITIALIZED";
267 return "CONNECTION_ERROR_UNKNOWN";
271 static void test_type_changed_callback(connection_type_e type, void* user_data)
273 printf("Type changed callback, connection type : %d\n", type);
276 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
278 printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
279 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
282 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
284 printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
285 ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
288 static void test_internet_state_changed_callback(connection_internet_state_e state, void* user_data)
290 printf("Internet state changed callback, state : %d\n", state);
293 static void test_dhcp_state_changed_callback(connection_dhcp_state_e state,
294 const char *interface_name, connection_error_e result, void *user_data)
296 printf("DHCP state changed callback, ifname: %s, state: %d, result: %d\n",
297 interface_name, state, result);
300 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
303 connection_profile_h profile = user_data;
308 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
311 printf("[%s] : %s\n", test_print_state(state), profile_name);
312 g_free(profile_name);
315 static void test_connection_opened_callback(connection_error_e result, void* user_data)
317 if (result == CONNECTION_ERROR_NONE)
318 printf("Connection open Succeeded\n");
320 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
323 static void test_connection_closed_callback(connection_error_e result, void* user_data)
325 if (result == CONNECTION_ERROR_NONE)
326 printf("Connection close Succeeded\n");
328 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
331 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
333 if (result == CONNECTION_ERROR_NONE)
334 printf("Reset profile Succeeded\n");
336 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
339 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
341 if (result == CONNECTION_ERROR_NONE)
342 printf("Default profile setting Succeeded\n");
344 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
347 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
350 if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
351 printf("Ethernet Cable Connected\n");
352 else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
353 printf("Ethernet Cable Disconnected\n");
356 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
361 connection_profile_type_e profile_type;
362 connection_profile_state_e profile_state;
363 connection_profile_iterator_h profile_iter;
364 connection_profile_h profile_h;
366 connection_profile_h profile_list[100] = {0,};
367 int profile_count = 0;
369 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
370 if (rv != CONNECTION_ERROR_NONE) {
371 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
375 while (connection_profile_iterator_has_next(profile_iter)) {
376 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
377 printf("Fail to get profile handle\n");
381 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
382 printf("Fail to get profile name\n");
386 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
387 printf("Fail to get profile type\n");
388 g_free(profile_name);
392 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
393 printf("Fail to get profile state\n");
394 g_free(profile_name);
398 printf("%d. state:[%s], profile name:%s", profile_count,
399 test_print_state(profile_state), profile_name);
400 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
401 connection_cellular_service_type_e service_type;
402 if (connection_profile_get_cellular_service_type(
403 profile_h, &service_type) !=
404 CONNECTION_ERROR_NONE)
405 printf("Fail to get cellular service type!\n");
408 test_print_cellular_service_type(service_type));
409 } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
410 connection_wifi_security_type_e security_type;
411 if (connection_profile_get_wifi_security_type(
412 profile_h, &security_type) !=
413 CONNECTION_ERROR_NONE)
414 printf("Fail to get wifi security type!\n");
417 test_print_wifi_security_type(security_type));
421 profile_list[profile_count] = profile_h;
424 g_free(profile_name);
425 if (profile_count >= 100)
432 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
433 input >= profile_count ||
435 printf("Wrong number!!\n");
440 *profile = profile_list[input];
445 static int test_update_cellular_info(connection_profile_h profile)
448 char input_str1[100] = {0,};
449 char input_str2[100] = {0,};
453 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
454 "Prepaid MMS:4, Tethering:5, Application:6)"
455 " - (Enter for skip) :", &input_int)) {
458 rv = connection_profile_set_cellular_service_type(profile,
459 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
462 rv = connection_profile_set_cellular_service_type(profile,
463 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
466 rv = connection_profile_set_cellular_service_type(profile,
467 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
470 rv = connection_profile_set_cellular_service_type(profile,
471 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
474 rv = connection_profile_set_cellular_service_type(profile,
475 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
478 rv = connection_profile_set_cellular_service_type(profile,
479 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
485 if (rv != CONNECTION_ERROR_NONE)
490 if (test_get_user_string("Input apn - (Enter for skip) :", input_str1, 100)) {
491 g_strstrip(input_str1);
492 rv = connection_profile_set_cellular_apn(profile, input_str1);
493 if (rv != CONNECTION_ERROR_NONE)
497 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
498 g_strstrip(input_str1);
499 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
500 if (rv != CONNECTION_ERROR_NONE)
504 if (test_get_user_string("Input home_url - (Enter for skip) :", input_str1, 100)) {
505 g_strstrip(input_str1);
506 rv = connection_profile_set_cellular_home_url(profile, input_str1);
507 if (rv != CONNECTION_ERROR_NONE)
511 if (test_get_user_int("Input auth_type(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
514 rv = connection_profile_set_cellular_auth_info(profile,
515 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
516 if (rv != CONNECTION_ERROR_NONE)
521 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
524 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
526 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
528 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
531 g_strstrip(input_str1);
532 g_strstrip(input_str2);
533 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
534 if (rv != CONNECTION_ERROR_NONE)
539 if (test_get_user_int("Input pdn_type(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
542 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
545 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
548 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
552 if (rv != CONNECTION_ERROR_NONE)
556 if (test_get_user_int("Input roam_pdn_type(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
559 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
562 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
565 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
569 if (rv != CONNECTION_ERROR_NONE)
576 static int test_update_wifi_info(connection_profile_h profile)
579 char input_str[100] = {0,};
581 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
582 rv = connection_profile_set_wifi_passphrase(profile, input_str);
583 if (rv != CONNECTION_ERROR_NONE)
590 static int test_update_dns_info(connection_profile_h profile,
591 connection_address_family_e address_family)
594 char input_str[100] = {0,};
595 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
596 rv = connection_profile_set_dns_address(profile,
600 if (rv != CONNECTION_ERROR_NONE)
603 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
604 rv = connection_profile_set_dns_address(profile,
608 if (rv != CONNECTION_ERROR_NONE)
615 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
619 char input_str[100] = {0,};
622 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
623 rv = connection_profile_set_ip_address(profile,
626 if (rv != CONNECTION_ERROR_NONE)
630 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
631 rv = connection_profile_set_subnet_mask(profile,
634 if (rv != CONNECTION_ERROR_NONE)
638 if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
639 rv = connection_profile_set_prefix_length(profile,
642 if (rv != CONNECTION_ERROR_NONE)
646 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
647 rv = connection_profile_set_gateway_address(profile,
650 if (rv != CONNECTION_ERROR_NONE)
654 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
655 " - (Enter for skip) :", &dns_input)) {
657 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
658 rv = connection_profile_set_dns_config_type(
661 CONNECTION_DNS_CONFIG_TYPE_STATIC);
662 if (rv != CONNECTION_ERROR_NONE)
664 if (test_update_dns_info(profile,
665 address_family) == -1)
668 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
669 rv = connection_profile_set_dns_config_type(
672 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
673 if (rv != CONNECTION_ERROR_NONE)
682 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
686 char input_str[100] = {0,};
688 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
689 " - (Enter for skip) :", &input_int)) {
692 rv = connection_profile_set_proxy_type(profile,
693 CONNECTION_PROXY_TYPE_DIRECT);
695 if (rv != CONNECTION_ERROR_NONE)
700 rv = connection_profile_set_proxy_type(profile,
701 CONNECTION_PROXY_TYPE_AUTO);
704 rv = connection_profile_set_proxy_type(profile,
705 CONNECTION_PROXY_TYPE_MANUAL);
711 if (rv != CONNECTION_ERROR_NONE)
714 if (test_get_user_string("Input auto Proxy URL or Proxy address"
715 " - (Enter for skip) :", input_str, 100)) {
716 rv = connection_profile_set_proxy_address(profile,
719 if (rv != CONNECTION_ERROR_NONE)
731 static int test_update_network_info(connection_profile_h profile)
736 int address_family = 0;
738 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
740 if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
741 " - (Enter for skip) :", &input_int)) {
744 rv = connection_profile_set_ip_config_type(profile,
746 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
747 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
748 " - (Enter for skip) :", &dns_input)) {
750 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
751 rv = connection_profile_set_dns_config_type(
754 CONNECTION_DNS_CONFIG_TYPE_STATIC);
755 if (rv != CONNECTION_ERROR_NONE)
757 if (test_update_dns_info(profile,
758 address_family) == -1)
761 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
762 rv = connection_profile_set_dns_config_type(
765 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
766 if (rv != CONNECTION_ERROR_NONE)
773 rv = connection_profile_set_ip_config_type(profile,
775 CONNECTION_IP_CONFIG_TYPE_STATIC);
776 if (rv != CONNECTION_ERROR_NONE)
779 if (test_update_ip_info(profile, address_family) == -1)
782 if (test_update_proxy_info(profile, address_family) == -1)
786 rv = connection_profile_set_ip_config_type(profile,
788 CONNECTION_IP_CONFIG_TYPE_AUTO);
794 if (rv != CONNECTION_ERROR_NONE)
802 static void test_print_cellular_info(connection_profile_h profile)
804 connection_cellular_service_type_e service_type;
805 connection_cellular_pdn_type_e pdn_type;
806 connection_cellular_pdn_type_e roam_pdn_type;
808 connection_cellular_auth_type_e auth_type;
809 char *user_name = NULL;
810 char *password = NULL;
811 char *home_url = NULL;
812 bool roaming = false;
814 bool editable = false;
816 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
817 printf("Fail to get cellular service type!\n");
819 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
821 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
822 printf("Fail to get cellular pdn type!\n");
824 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
826 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
827 printf("Fail to get cellular roam pdn type!\n");
829 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
831 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
832 printf("Fail to get cellular APN!\n");
834 printf("Cellular APN : %s\n", apn);
838 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
839 printf("Fail to get auth info!\n");
841 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
842 printf("Cellular user_name : %s\n", user_name);
843 printf("Cellular password : %s\n", password);
848 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
849 printf("Fail to get cellular home url!\n");
851 printf("Cellular home url : %s\n", home_url);
855 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
856 printf("Fail to get cellular roaming state!\n");
858 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
860 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
861 printf("Fail to get cellular hidden state!\n");
863 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
865 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
866 printf("Fail to get cellular editing state!\n");
868 printf("Cellular editable : %s\n", editable ? "true" : "false");
871 static void test_print_wifi_info(connection_profile_h profile)
878 connection_wifi_security_type_e security_type;
879 connection_wifi_encryption_type_e encryption_type;
880 bool pass_required = false;
881 bool wps_supported = false;
883 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
884 printf("Fail to get Wi-Fi essid!\n");
886 printf("Wi-Fi essid : %s\n", essid);
890 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
891 printf("Fail to get Wi-Fi bssid!\n");
893 printf("Wi-Fi bssid : %s\n", bssid);
897 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
898 printf("Fail to get Wi-Fi rssi!\n");
900 printf("Wi-Fi rssi : %d\n", rssi);
902 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
903 printf("Fail to get Wi-Fi frequency!\n");
905 printf("Wi-Fi frequency : %d\n", frequency);
907 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
908 printf("Fail to get Wi-Fi max speed!\n");
910 printf("Wi-Fi max speed : %d\n", max_speed);
912 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
913 printf("Fail to get Wi-Fi security type!\n");
915 printf("Wi-Fi security type : %s\n", test_print_wifi_security_type(security_type));
917 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
918 printf("Fail to get Wi-Fi encryption type!\n");
920 printf("Wi-Fi encryption type : %d\n", encryption_type);
922 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
923 printf("Fail to get Wi-Fi passphrase required!\n");
925 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
927 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
928 printf("Fail to get Wi-Fi wps info\n");
930 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
933 static void test_print_mesh_info(connection_profile_h profile)
939 connection_wifi_security_type_e security_type;
940 bool pass_required = false;
942 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
943 printf("Fail to get Mesh essid!\n");
945 printf("Mesh essid : %s\n", essid);
949 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
950 printf("Fail to get Mesh bssid!\n");
952 printf("Mesh bssid : %s\n", bssid);
956 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
957 printf("Fail to get Mesh rssi!\n");
959 printf("Mesh rssi : %d\n", rssi);
961 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
962 printf("Fail to get Mesh frequency!\n");
964 printf("Mesh frequency : %d\n", frequency);
966 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
967 printf("Fail to get Mesh security type!\n");
969 printf("Mesh security type : %s\n", test_print_wifi_security_type(security_type));
971 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
972 printf("Fail to get Mesh passphrase required!\n");
974 printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
977 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
979 char *interface_name = NULL;
982 char *gateway = NULL;
983 char *dhcp_server = NULL;
984 int dhcp_lease_duration = 0;
989 connection_ip_config_type_e ip_type;
990 connection_proxy_type_e proxy_type;
991 connection_dns_config_type_e dns_type;
993 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
994 printf("Fail to get interface name!\n");
996 printf("Interface name : %s\n", interface_name);
997 g_free(interface_name);
1000 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
1001 printf("Fail to get ipconfig type!\n");
1003 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
1004 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
1005 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
1006 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
1007 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
1008 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
1009 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
1010 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
1012 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
1015 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
1016 printf("Fail to get IP address!\n");
1018 printf("IP address : %s\n", ip);
1022 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
1023 printf("Fail to get gateway!\n");
1025 printf("Gateway : %s\n", gateway);
1029 if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
1030 printf("Fail to get DHCP Server address!\n");
1032 printf("DHCP Server : %s\n", dhcp_server);
1033 g_free(dhcp_server);
1036 if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
1037 printf("Fail to get DHCP lease duration!\n");
1039 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
1040 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
1041 printf("Fail to get subnet mask!\n");
1043 printf("Subnet mask : %s\n", subnet);
1047 if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
1048 printf("Fail to get prefix length!\n");
1050 printf("Prefix length : %d\n", prefix_len);
1052 if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
1053 printf("Fail to get DNS configuration type!\n");
1055 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
1056 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
1057 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
1058 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
1060 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
1063 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
1064 printf("Fail to get DNS1!\n");
1066 printf("DNS1 : %s\n", dns1);
1070 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
1071 printf("Fail to get DNS2!\n");
1073 printf("DNS2 : %s\n", dns2);
1077 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
1078 printf("Fail to get proxy type!\n");
1080 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
1081 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
1082 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
1083 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
1085 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
1088 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
1089 printf("Fail to get proxy!\n");
1091 printf("Proxy : %s\n", proxy);
1096 int test_register_client(void)
1099 int err = connection_create(&connection);
1101 if (CONNECTION_ERROR_NONE == err) {
1102 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1103 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1104 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1105 connection_set_ethernet_cable_state_changed_cb(connection,
1106 test_get_ethernet_cable_state_callback, NULL);
1107 connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
1108 connection_set_dhcp_state_changed_cb(connection, test_dhcp_state_changed_callback, NULL);
1110 printf("Client registration failed [%s]\n", test_print_error(err));
1114 printf("Client registration success\n");
1118 int test_deregister_client(void)
1122 connection_profile_h profile;
1124 if (connection != NULL)
1125 rv = connection_destroy(connection);
1127 printf("Cannot deregister : Handle is NULL\n");
1128 rv = CONNECTION_ERROR_INVALID_OPERATION;
1131 if (rv != CONNECTION_ERROR_NONE) {
1132 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1136 if (state_cb_list) {
1137 for (list = state_cb_list; list; list = list->next) {
1138 profile = list->data;
1139 connection_profile_destroy(profile);
1142 g_slist_free(state_cb_list);
1143 state_cb_list = NULL;
1147 printf("Client deregistration success\n");
1152 int test_register_client_cs(void)
1155 test_get_user_int("Input a TID in C# API :", &tid);
1157 int err = connection_create_cs(tid, &connection);
1159 if (CONNECTION_ERROR_NONE == err) {
1160 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1161 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1162 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1163 connection_set_ethernet_cable_state_changed_cb(connection,
1164 test_get_ethernet_cable_state_callback, NULL);
1166 printf("Client registration failed [%s]\n", test_print_error(err));
1170 printf("Client registration success\n");
1174 int test_deregister_client_cs(void)
1178 connection_profile_h profile;
1181 test_get_user_int("Input a TID in C# API :", &tid);
1183 if (connection != NULL)
1184 rv = connection_destroy_cs(tid, connection);
1186 printf("Cannot deregister : Handle is NULL\n");
1187 rv = CONNECTION_ERROR_INVALID_OPERATION;
1190 if (rv != CONNECTION_ERROR_NONE) {
1191 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1195 if (state_cb_list) {
1196 for (list = state_cb_list; list; list = list->next) {
1197 profile = list->data;
1198 connection_profile_destroy(profile);
1201 g_slist_free(state_cb_list);
1202 state_cb_list = NULL;
1206 printf("Client deregistration success\n");
1211 int test_get_network_state(void)
1214 connection_type_e net_state;
1216 rv = connection_get_type(connection, &net_state);
1218 if (rv != CONNECTION_ERROR_NONE) {
1219 printf("Fail to get network state [%s]\n", test_print_error(rv));
1223 printf("Retval = [%s] network connection state [%s]\n",
1224 test_print_error(rv), test_print_connection_type(net_state));
1229 int test_get_cellular_state(void)
1232 connection_cellular_state_e cellular_state;
1234 rv = connection_get_cellular_state(connection, &cellular_state);
1236 if (rv != CONNECTION_ERROR_NONE) {
1237 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1241 printf("Retval = [%s] Cellular state [%s]\n",
1242 test_print_error(rv), test_print_cellular_state(cellular_state));
1247 int test_get_wifi_state(void)
1250 connection_wifi_state_e wifi_state;
1252 rv = connection_get_wifi_state(connection, &wifi_state);
1254 if (rv != CONNECTION_ERROR_NONE) {
1255 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1259 printf("Retval = [%s] WiFi state [%s]\n",
1260 test_print_error(rv), test_print_wifi_state(wifi_state));
1265 int test_get_current_proxy(void)
1267 char *proxy_addr = NULL;
1269 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1271 if (proxy_addr == NULL) {
1272 printf("Proxy address does not exist\n");
1276 printf("Current Proxy [%s]\n", proxy_addr);
1282 int test_get_current_ip(void)
1284 char *ip_addr = NULL;
1288 rv = test_get_user_int("Input Address type to get"
1289 "(1:IPV4, 2:IPV6):", &input);
1292 printf("Invalid input!!\n");
1298 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1299 if (ip_addr == NULL) {
1300 printf("IPv4 address does not exist\n");
1303 printf("IPv4 address : %s\n", ip_addr);
1307 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1308 if (ip_addr == NULL) {
1309 printf("IPv6 address does not exist\n");
1312 printf("IPv6 address : %s\n", ip_addr);
1315 printf("Wrong IP address family!!\n");
1323 int test_get_call_statistics_info(void)
1327 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1328 printf("last recv data size [%lld]\n", rv);
1329 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1330 printf("last sent data size [%lld]\n", rv);
1331 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1332 printf("total received data size [%lld]\n", rv);
1333 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1334 printf("total sent data size [%lld]\n", rv);
1339 int test_get_wifi_call_statistics_info(void)
1343 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1344 printf("WiFi last recv data size [%lld]\n", rv);
1345 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1346 printf("WiFi last sent data size [%lld]\n", rv);
1347 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1348 printf("WiFi total received data size [%lld]\n", rv);
1349 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1350 printf("WiFi total sent data size [%lld]\n", rv);
1355 int test_get_profile_list(void)
1357 if (test_get_user_selected_profile(NULL, false) == false)
1363 int test_get_default_profile_list(void)
1366 char *profile_name = NULL;
1367 connection_profile_iterator_h profile_iter;
1368 connection_profile_h profile_h;
1369 connection_cellular_service_type_e service_type;
1370 bool is_default = false;
1372 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1373 if (rv != CONNECTION_ERROR_NONE) {
1374 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1378 while (connection_profile_iterator_has_next(profile_iter)) {
1379 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1380 printf("Fail to get profile handle\n");
1384 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1385 printf("Fail to get profile name\n");
1388 printf("profile name : %s\n", profile_name);
1389 g_free(profile_name);
1391 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1392 printf("Fail to get profile service type\n");
1395 printf("service type : %d\n", service_type);
1397 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1398 printf("Fail to get profile subscriber id\n");
1401 printf("Default : %d\n", is_default);
1407 int test_get_connected_profile_list(void)
1410 char *profile_name = NULL;
1411 connection_profile_iterator_h profile_iter;
1412 connection_profile_h profile_h;
1413 bool is_default = false;
1414 connection_profile_type_e type;
1416 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1417 if (rv != CONNECTION_ERROR_NONE) {
1418 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1422 while (connection_profile_iterator_has_next(profile_iter)) {
1423 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1424 printf("Fail to get profile handle\n");
1428 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1429 printf("Fail to get profile name\n");
1432 printf("profile name is %s\n", profile_name);
1433 g_free(profile_name);
1435 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1436 printf("Fail to get profile type\n");
1439 printf("profile type is %d\n", type);
1441 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1442 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1443 printf("Fail to get profile is default\n");
1446 printf("[%s]\n", is_default ? "default" : "not default");
1453 int test_get_current_profile(void)
1456 char *profile_name = NULL;
1457 connection_profile_h profile_h;
1459 rv = connection_get_current_profile(connection, &profile_h);
1460 if (rv != CONNECTION_ERROR_NONE) {
1461 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1465 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1466 printf("Fail to get profile name\n");
1469 printf("profile name : %s\n", profile_name);
1470 g_free(profile_name);
1472 connection_profile_destroy(profile_h);
1477 int test_open_profile(void)
1479 connection_profile_h profile;
1481 printf("\n** Choose a profile to open. **\n");
1483 if (test_get_user_selected_profile(&profile, true) == false)
1486 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1487 printf("Connection open Failed!!\n");
1494 int test_get_default_cellular_service_type(void)
1499 connection_profile_h profile;
1500 char *profile_name = NULL;
1502 rv = test_get_user_int("Input profile type to get"
1503 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1506 printf("Invalid input!!\n");
1512 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1515 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1518 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1521 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1524 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1527 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1530 printf("Wrong number!!\n");
1534 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1537 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1538 printf("Fail to get profile name\n");
1539 connection_profile_destroy(profile);
1542 printf("Default profile name : %s\n", profile_name);
1543 g_free(profile_name);
1545 connection_profile_destroy(profile);
1550 int test_set_default_cellular_service_type(void)
1552 connection_profile_h profile;
1553 connection_cellular_service_type_e type;
1556 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1558 if (rv == false || (input != 1 && input != 2)) {
1559 printf("Invalid input!!\n");
1563 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1565 if (test_get_user_selected_profile(&profile, true) == false)
1568 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1569 printf("Fail to get cellular service type\n");
1574 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1577 if (connection_set_default_cellular_service_profile_async(connection,
1578 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1585 int test_close_profile(void)
1587 connection_profile_h profile;
1589 printf("\n** Choose a profile to close. **\n");
1591 if (test_get_user_selected_profile(&profile, true) == false)
1594 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1595 printf("Connection close Failed!!\n");
1602 int test_add_profile(void)
1605 connection_profile_h profile;
1606 char input_str[100] = {0,};
1608 if (test_get_user_string("Input keyword - (Enter for skip) :", input_str, 100) == false)
1611 g_strstrip(input_str);
1612 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1613 if (rv != CONNECTION_ERROR_NONE)
1614 RETURN_FAIL_DESTROY(profile);
1616 if (test_update_cellular_info(profile) == -1)
1617 RETURN_FAIL_DESTROY(profile);
1619 rv = connection_add_profile(connection, profile);
1620 if (rv != CONNECTION_ERROR_NONE)
1621 RETURN_FAIL_DESTROY(profile);
1623 connection_profile_destroy(profile);
1627 int test_remove_profile(void)
1629 connection_profile_h profile;
1631 printf("\n** Choose a profile to remove. **\n");
1632 if (test_get_user_selected_profile(&profile, true) == false)
1635 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1636 printf("Remove profile Failed!!\n");
1643 int test_update_profile(void)
1647 connection_profile_type_e prof_type;
1648 connection_profile_h profile;
1650 printf("\n** Choose a profile to update. **\n");
1651 if (test_get_user_selected_profile(&profile, true) == false)
1654 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1657 switch (prof_type) {
1658 case CONNECTION_PROFILE_TYPE_CELLULAR:
1659 if (test_update_cellular_info(profile) == -1)
1663 case CONNECTION_PROFILE_TYPE_WIFI:
1664 if (test_update_wifi_info(profile) == -1)
1667 if (test_update_network_info(profile) == -1)
1671 case CONNECTION_PROFILE_TYPE_ETHERNET:
1672 if (test_update_network_info(profile) == -1)
1676 case CONNECTION_PROFILE_TYPE_BT:
1677 printf("Not supported!\n");
1681 int profile_type = prof_type;
1682 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1683 if (test_update_wifi_info(profile) == -1)
1691 rv = connection_update_profile(connection, profile);
1692 if (rv != CONNECTION_ERROR_NONE)
1698 int test_get_profile_info(void)
1700 connection_profile_type_e prof_type;
1701 connection_profile_state_e profile_state;
1702 connection_profile_state_e profile_ipv6_state;
1703 connection_internet_state_e internet_state;
1704 connection_profile_h profile;
1705 char *profile_name = NULL;
1706 int address_family = 0;
1708 printf("\n** Choose a profile to print. **\n");
1709 if (test_get_user_selected_profile(&profile, true) == false)
1712 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1713 printf("Fail to get profile name\n");
1716 printf("Profile Name : %s\n", profile_name);
1717 g_free(profile_name);
1720 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1721 printf("Fail to get profile IPv4 state\n");
1724 printf("Profile State : %s\n", test_print_state(profile_state));
1726 if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1727 printf("Fail to get profile IPv6 state\n");
1730 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1732 if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
1733 printf("Fail to get Internet state\n");
1736 printf("Internet State : %s\n", test_print_internet_state(internet_state));
1738 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1741 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1743 switch (prof_type) {
1744 case CONNECTION_PROFILE_TYPE_CELLULAR:
1745 printf("Profile Type : Cellular\n");
1746 test_print_cellular_info(profile);
1748 case CONNECTION_PROFILE_TYPE_WIFI:
1749 printf("Profile Type : Wi-Fi\n");
1750 test_print_wifi_info(profile);
1752 case CONNECTION_PROFILE_TYPE_ETHERNET:
1753 printf("Profile Type : Ethernet\n");
1755 case CONNECTION_PROFILE_TYPE_BT:
1756 printf("Profile Type : bluetooth\n");
1760 int profile_type = prof_type;
1761 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1762 printf("Profile Type : Mesh\n");
1763 test_print_mesh_info(profile);
1770 test_print_network_info(profile, address_family);
1775 int test_refresh_profile_info(void)
1777 connection_profile_type_e prof_type;
1778 connection_profile_state_e profile_state;
1779 connection_profile_h profile;
1780 char *profile_name = NULL;
1781 int address_family = 0;
1783 printf("\n** Choose a profile to refresh. **\n");
1784 if (test_get_user_selected_profile(&profile, true) == false)
1787 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1790 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1791 printf("Fail to get profile name\n");
1794 printf("Profile Name : %s\n", profile_name);
1795 g_free(profile_name);
1798 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1799 printf("Fail to get profile state\n");
1802 printf("Profile State : %s\n", test_print_state(profile_state));
1805 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1808 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1810 switch (prof_type) {
1811 case CONNECTION_PROFILE_TYPE_CELLULAR:
1812 printf("Profile Type : Cellular\n");
1813 test_print_cellular_info(profile);
1815 case CONNECTION_PROFILE_TYPE_WIFI:
1816 printf("Profile Type : Wi-Fi\n");
1817 test_print_wifi_info(profile);
1819 case CONNECTION_PROFILE_TYPE_ETHERNET:
1820 printf("Profile Type : Ethernet\n");
1822 case CONNECTION_PROFILE_TYPE_BT:
1823 printf("Profile Type : bluetooth\n");
1827 int profile_type = prof_type;
1828 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1829 printf("Profile Type : Mesh\n");
1830 test_print_mesh_info(profile);
1837 test_print_network_info(profile, address_family);
1842 int test_set_state_changed_callback()
1844 connection_profile_h profile;
1845 connection_profile_h profile_clone;
1847 printf("\n** Choose a profile to set callback. **\n");
1848 if (test_get_user_selected_profile(&profile, true) == false)
1851 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1854 if (connection_profile_set_state_changed_cb(profile,
1855 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1856 connection_profile_destroy(profile_clone);
1860 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1865 int test_unset_state_changed_callback()
1867 connection_profile_h profile;
1869 char *profile_name = NULL;
1873 printf("\n** Choose a profile to unset callback. **\n");
1874 for (list = state_cb_list; list; list = list->next) {
1875 profile = list->data;
1876 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1877 printf("Fail to get profile name!\n");
1880 printf("%d. %s\n", count, profile_name);
1881 g_free(profile_name);
1887 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1890 printf("Wrong number!!\n");
1895 for (list = state_cb_list; list; list = list->next) {
1896 if (count == input) {
1897 profile = list->data;
1907 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1910 state_cb_list = g_slist_remove(state_cb_list, profile);
1911 connection_profile_destroy(profile);
1916 int test_reset_call_statistics_info(void)
1918 int ret = CONNECTION_ERROR_NONE;
1920 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1921 printf("reset last recv data size [%d]\n", ret);
1922 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1923 printf("last sent data size [%d]\n", ret);
1924 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1925 printf("total received data size [%d]\n", ret);
1926 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1927 printf("total sent data size [%d]\n", ret);
1932 int test_reset_wifi_call_statistics_info(void)
1934 int ret = CONNECTION_ERROR_NONE;
1936 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1937 printf("WiFi last sent data size [%d]\n", ret);
1938 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1939 printf("WiFi last recv data size [%d]\n", ret);
1940 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1941 printf("WiFi total sent data size [%d]\n", ret);
1942 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1943 printf("WiFi total received data size [%d]\n", ret);
1948 int test_add_route(void)
1951 char ip_addr[100] = {0};
1952 char if_name[40] = {0};
1954 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1957 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1960 g_strstrip(ip_addr);
1961 g_strstrip(if_name);
1962 rv = connection_add_route(connection, if_name, ip_addr);
1963 if (rv != CONNECTION_ERROR_NONE) {
1964 printf("Fail to get add new route [%d]\n", rv);
1967 printf("Add Route successfully\n");
1972 int test_remove_route(void)
1975 char ip_addr[100] = {0};
1976 char if_name[40] = {0};
1978 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1981 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1984 g_strstrip(ip_addr);
1985 g_strstrip(if_name);
1986 rv = connection_remove_route(connection, if_name, ip_addr);
1987 if (rv != CONNECTION_ERROR_NONE) {
1988 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1991 printf("Remove Route successfully\n");
1996 int test_add_route_ipv6(void)
1999 char ip_addr[100] = {0};
2000 char gateway[100] = {0};
2001 char if_name[40] = {0};
2003 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
2006 test_get_user_string("Input Gateway - (Enter for unspecified address) :", gateway, 100);
2008 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2011 g_strstrip(ip_addr);
2012 g_strstrip(gateway);
2013 g_strstrip(if_name);
2014 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
2015 if (rv != CONNECTION_ERROR_NONE) {
2016 printf("Fail to get add new route [%d]\n", rv);
2019 printf("Add Route successfully\n");
2024 int test_remove_route_ipv6(void)
2027 char ip_addr[100] = {0};
2028 char gateway[100] = {0};
2029 char if_name[40] = {0};
2031 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
2034 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2037 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2040 g_strstrip(ip_addr);
2041 g_strstrip(gateway);
2042 g_strstrip(if_name);
2043 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
2044 if (rv != CONNECTION_ERROR_NONE) {
2045 printf("Fail to remove the route [%d]\n", rv);
2048 printf("Remove Route successfully\n");
2053 int test_add_route_entry(void)
2055 char ip_addr[100] = {0};
2056 char gateway[100] = {0};
2057 char if_name[40] = {0};
2062 input_rv = test_get_user_int("Input Address type to get"
2063 "(1:IPV4, 2:IPV6):", &input);
2065 if (input_rv == false) {
2066 printf("Invalid input!!\n");
2072 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2075 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2078 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2081 g_strstrip(ip_addr);
2082 g_strstrip(gateway);
2083 g_strstrip(if_name);
2084 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2085 if (rv != CONNECTION_ERROR_NONE) {
2086 printf("Fail to get add new route [%d]\n", rv);
2089 printf("Add Route successfully\n");
2093 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2096 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2099 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2102 g_strstrip(ip_addr);
2103 g_strstrip(gateway);
2104 g_strstrip(if_name);
2105 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2106 if (rv != CONNECTION_ERROR_NONE) {
2107 printf("Fail to get add new route [%d]\n", rv);
2110 printf("Add Route successfully\n");
2114 printf("Wrong IP address family!!\n");
2123 int test_remove_route_entry(void)
2125 char ip_addr[100] = {0};
2126 char gateway[100] = {0};
2127 char if_name[40] = {0};
2132 input_rv = test_get_user_int("Input Address type to get"
2133 "(1:IPV4, 2:IPV6):", &input);
2135 if (input_rv == false) {
2136 printf("Invalid input!!\n");
2142 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2145 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2148 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2151 g_strstrip(ip_addr);
2152 g_strstrip(gateway);
2153 g_strstrip(if_name);
2154 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2155 if (rv != CONNECTION_ERROR_NONE) {
2156 printf("Fail to remove the route [%s]\n", test_print_error(rv));
2159 printf("Remove Route successfully\n");
2164 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2167 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2170 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2173 g_strstrip(ip_addr);
2174 g_strstrip(gateway);
2175 g_strstrip(if_name);
2176 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2177 if (rv != CONNECTION_ERROR_NONE) {
2178 printf("Fail to remove the route [%d]\n", rv);
2181 printf("Remove Route successfully\n");
2185 printf("Wrong IP address family!!\n");
2194 int test_get_bt_state(void)
2197 connection_bt_state_e bt_state;
2199 rv = connection_get_bt_state(connection, &bt_state);
2201 if (rv != CONNECTION_ERROR_NONE) {
2202 printf("Fail to get bluetooth state [%s]\n", test_print_error(rv));
2206 printf("Retval = [%s], bluetooth state [%d]\n", test_print_error(rv), bt_state);
2211 int test_get_profile_id(void)
2213 connection_profile_h profile;
2216 printf("\n** Choose a profile to see profile id. **\n");
2217 if (test_get_user_selected_profile(&profile, true) == false)
2220 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2221 printf("Fail to get profile name\n");
2224 printf("Profile id : %s\n", profile_id);
2231 int test_get_mac_address(void)
2233 int rv = 0, type = 0;
2234 connection_type_e conn_type;
2235 char *mac_addr = NULL;
2237 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2241 conn_type = CONNECTION_TYPE_WIFI;
2244 conn_type = CONNECTION_TYPE_ETHERNET;
2247 printf("Wrong number!!\n");
2251 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2253 if (rv != CONNECTION_ERROR_NONE) {
2254 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2258 printf("mac address is %s\n", mac_addr);
2265 int test_get_ethernet_cable_state(void)
2268 connection_ethernet_cable_state_e cable_state;
2270 rv = connection_get_ethernet_cable_state(connection, &cable_state);
2272 if (rv != CONNECTION_ERROR_NONE) {
2273 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2277 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2282 int test_get_dhcp_state(void)
2285 connection_dhcp_state_e dhcp_state;
2286 char if_name[40] = {0};
2288 if (test_get_user_string("Input Interface name: ", if_name, 40) == false)
2291 g_strstrip(if_name);
2293 rv = connection_get_dhcp_state(connection, if_name, &dhcp_state);
2295 if (rv != CONNECTION_ERROR_NONE) {
2296 printf("Fail to get DHCP state [%s]\n", test_print_error(rv));
2300 printf("Retval = [%s], DHCP state [%d]\n", test_print_error(rv), dhcp_state);
2305 int test_reset_profile(void)
2307 int type, sim_id, rv;
2309 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2311 if (rv == false || (type != 0 && type != 1)) {
2312 printf("Invalid input!!\n");
2316 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2318 if (rv == false || (sim_id != 0 && sim_id != 1)) {
2319 printf("Invalid input!!\n");
2323 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2329 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2331 printf("IPv6 Address : %s\n", ipv6_address);
2335 int test_foreach_ipv6_address(void)
2339 connection_type_e conn_type;
2341 test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2345 conn_type = CONNECTION_TYPE_WIFI;
2348 conn_type = CONNECTION_TYPE_ETHERNET;
2351 printf("Wrong number!!\n");
2355 rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2356 if (rv != CONNECTION_ERROR_NONE) {
2357 printf("Fail to get IPv6 address\n");
2364 int test_is_metered_network(void)
2369 rv = connection_is_metered_network(connection, &metered_state);
2371 if (rv != CONNECTION_ERROR_NONE) {
2372 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2376 printf("Retval = [%s] metered state [%s]\n",
2377 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2382 int test_start_tcpdump(void)
2384 if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE)
2386 printf("Successfully started tcpdump\n");
2391 int test_stop_tcpdump(void)
2393 if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE)
2395 printf("Successfully stopped tcpdump\n");
2400 int test_get_tcpdump_state(void)
2402 gboolean tcpdump_state = FALSE;
2404 if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE)
2406 printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2411 int test_mptcp_enable(void)
2414 bool supported = false;
2415 rv = connection_mptcp_is_supported(connection, &supported);
2416 if (rv != CONNECTION_ERROR_NONE) {
2417 printf("Failure[%s]\n", test_print_error(rv));
2420 printf("MPTCP Support: %d\n", supported);
2422 rv = connection_mptcp_enable(connection, CONNECTION_MPTCP_ENABLE_ALL);
2423 if (rv != CONNECTION_ERROR_NONE) {
2424 printf("Failure[%s]\n", test_print_error(rv));
2430 int test_mptcp_disable(void)
2433 rv = connection_mptcp_disable(connection);
2435 if (rv != CONNECTION_ERROR_NONE) {
2436 printf("Failure[%s]\n", test_print_error(rv));
2442 int test_mptcp_set_path_manager(void)
2446 rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
2450 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_DEFAULT);
2453 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_FULLMESH);
2456 printf("Invalid input!!\n");
2460 if (rv != CONNECTION_ERROR_NONE) {
2461 printf("Failure[%s]\n", test_print_error(rv));
2468 int test_mptcp_get_path_manager(void)
2471 connection_mptcp_path_manager_e pm;
2473 rv = connection_mptcp_get_path_manager(connection, &pm);
2474 if (rv != CONNECTION_ERROR_NONE) {
2475 printf("Failure[%s]\n", test_print_error(rv));
2480 case CONNECTION_MPTCP_PM_DEFAULT:
2481 printf("Path Manager: Default\n");
2483 case CONNECTION_MPTCP_PM_FULLMESH:
2484 printf("Path Manager: FullMesh\n");
2487 printf("Error: Invalid Path Manager\n");
2494 int test_mptcp_set_scheduler(void)
2498 rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
2502 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_DEFAULT);
2505 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
2508 printf("Invalid input!!\n");
2512 if (rv != CONNECTION_ERROR_NONE) {
2513 printf("Failure[%s]\n", test_print_error(rv));
2520 int test_mptcp_get_scheduler(void)
2523 connection_mptcp_scheduler_e scheduler;
2525 rv = connection_mptcp_get_scheduler(connection, &scheduler);
2526 if (rv != CONNECTION_ERROR_NONE) {
2527 printf("Failure[%s]\n", test_print_error(rv));
2531 switch (scheduler) {
2532 case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
2533 printf("Scheduler: Default\n");
2535 case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
2536 printf("Scheduler: RountRobin\n");
2539 printf("Error: Invalid Scheduler\n");
2546 int test_ethernet_eap_connect(void)
2550 bool enabled = false;
2553 char input_str1[130];
2554 char input_str2[130];
2555 connection_profile_h profile;
2557 printf("\n** Choose a ethernet profile to connect. **\n");
2559 if (test_get_user_selected_profile(&profile, true) == false)
2562 test_get_user_int("Input options (0:Use LAN 1:Use EAPoL) :", &input);
2564 if (connection_profile_enable_ethernet_eap(profile, true) != CONNECTION_ERROR_NONE) {
2565 printf("Failed to enable EAP over Ethernet\n");
2569 printf("Disabling EAPoL. Use proper option for normal Lan connection.\n");
2570 if (connection_profile_enable_ethernet_eap(profile, false) != CONNECTION_ERROR_NONE)
2571 printf("Failed to disable EAP over Ethernet\n");
2575 if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE) {
2576 printf("Failed to get ethernet eap enabled status!!\n");
2580 printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2582 printf("Input EAP type:\n");
2583 printf("0 -> CONNECTION_ETHERNET_EAP_TYPE_MD5\n");
2584 printf("1 -> CONNECTION_ETHERNET_EAP_TYPE_PEAP\n");
2585 printf("2 -> CONNECTION_ETHERNET_EAP_TYPE_TLS\n");
2586 printf("3 -> CONNECTION_ETHERNET_EAP_TYPE_TTLS\n");
2587 printf("4 -> CONNECTION_ETHERNET_EAP_TYPE_FAST\n");
2588 rv = scanf("%d", &type);
2591 case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2592 rv = connection_profile_set_ethernet_eap_type(profile, type);
2593 if (rv != CONNECTION_ERROR_NONE) {
2594 printf("Fail to set eap type : %s\n", test_print_error(rv));
2598 printf("Input user name for ethernet:");
2599 rv = scanf("%99s", input_str1);
2601 printf("Input password for ethernet:");
2602 rv = scanf("%99s", input_str2);
2604 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2605 if (rv != CONNECTION_ERROR_NONE) {
2606 printf("Fail to set eap passphrase : %s\n", test_print_error(rv));
2611 case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2613 rv = connection_profile_set_ethernet_eap_type(profile, type);
2614 if (rv != CONNECTION_ERROR_NONE) {
2615 printf("Fail to set eap type : %s\n", test_print_error(rv));
2619 printf("Input user identity for ethernet:");
2620 rv = scanf("%99s", input_str1);
2622 rv = connection_profile_set_ethernet_eap_identity(profile, input_str1);
2623 if (rv != CONNECTION_ERROR_NONE) {
2624 printf("Fail to set eap identity : %s\n", test_print_error(rv));
2628 printf("Input user certificate for ethernet:");
2629 rv = scanf("%129s", input_str1);
2631 rv = connection_profile_set_ethernet_eap_client_cert_file(profile, input_str1);
2632 if (rv != CONNECTION_ERROR_NONE) {
2633 printf("Fail to set eap user cetificate : %s\n", test_print_error(rv));
2637 printf("Input CA certificate for ethernet:");
2638 rv = scanf("%129s", input_str1);
2640 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2641 if (rv != CONNECTION_ERROR_NONE) {
2642 printf("Fail to set eap CA cetificate : %s\n", test_print_error(rv));
2646 printf("Input private key for ethernet:");
2647 rv = scanf("%129s", input_str1);
2649 printf("Input private key password for ethernet:");
2650 rv = scanf("%129s", input_str2);
2652 rv = connection_profile_set_ethernet_eap_private_key_info(profile, input_str1, input_str2);
2653 if (rv != CONNECTION_ERROR_NONE) {
2654 printf("Fail to set eap private key passphrase : %s\n", test_print_error(rv));
2660 case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2662 rv = connection_profile_set_ethernet_eap_type(profile, type);
2663 if (rv != CONNECTION_ERROR_NONE) {
2664 printf("Fail to set eap type : %s\n", test_print_error(rv));
2668 printf("Input anonymous_identity for PEAP ethernet:");
2669 rv = scanf("%99s", input_str1);
2671 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2672 if (rv != CONNECTION_ERROR_NONE) {
2673 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2677 printf("Input CA file for PEAP ethernet:");
2678 rv = scanf("%129s", input_str1);
2680 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2681 if (rv != CONNECTION_ERROR_NONE) {
2682 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2686 int peap_version = 0;
2687 printf("Input peap version[ 0 ~ 2] for PEAP ethernet:");
2688 rv = scanf("%1d", &peap_version);
2690 rv = connection_profile_set_ethernet_eap_peap_version(profile, peap_version);
2691 if (rv != CONNECTION_ERROR_NONE) {
2692 printf("Fail to set eap peap version : %s\n", test_print_error(rv));
2696 printf("Input authentication type[3:MSCHAPV2 4:GTC 5:MD5] for PEAP ethernet:");
2697 rv = scanf("%1d", &auth_type);
2699 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2700 if (rv != CONNECTION_ERROR_NONE) {
2701 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2705 printf("Input username for PEAP ethernet:");
2706 rv = scanf("%129s", input_str1);
2708 printf("Input password for PEAP ethernet:");
2709 rv = scanf("%129s", input_str2);
2711 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2712 if (rv != CONNECTION_ERROR_NONE) {
2713 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2719 case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2721 rv = connection_profile_set_ethernet_eap_type(profile, type);
2722 if (rv != CONNECTION_ERROR_NONE) {
2723 printf("Fail to set eap type : %s\n", test_print_error(rv));
2727 printf("Input anonymous_identity for TTLS ethernet:");
2728 rv = scanf("%99s", input_str1);
2730 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2731 if (rv != CONNECTION_ERROR_NONE) {
2732 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2736 printf("Input CA file for TTLS ethernet:");
2737 rv = scanf("%129s", input_str1);
2739 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2740 if (rv != CONNECTION_ERROR_NONE) {
2741 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2745 printf("Input authentication type[1:PAP, 2:MSCHAP, 3:MSCHAPV2] for TTLS ethernet:");
2746 rv = scanf("%1d", &auth_type);
2748 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2749 if (rv != CONNECTION_ERROR_NONE) {
2750 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2754 printf("Input username for TTLS ethernet:");
2755 rv = scanf("%129s", input_str1);
2757 printf("Input password for TTLS ethernet:");
2758 rv = scanf("%129s", input_str2);
2760 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2761 if (rv != CONNECTION_ERROR_NONE) {
2762 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2768 case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2770 rv = connection_profile_set_ethernet_eap_type(profile, type);
2771 if (rv != CONNECTION_ERROR_NONE) {
2772 printf("Fail to set eap type : %s\n", test_print_error(rv));
2776 printf("Input anonymous_identity for FAST ethernet:");
2777 rv = scanf("%99s", input_str1);
2779 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2780 if (rv != CONNECTION_ERROR_NONE) {
2781 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2785 printf("Input pac file for FAST ethernet:");
2786 rv = scanf("%129s", input_str1);
2788 rv = connection_profile_set_ethernet_eap_pac_file(profile, input_str1);
2789 if (rv != CONNECTION_ERROR_NONE) {
2790 printf("Fail to set eap pac file : %s\n", test_print_error(rv));
2794 printf("Input authentication type[3:MSCHAPV2, 4:GTC] for FAST ethernet:");
2795 rv = scanf("%1d", &auth_type);
2797 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2798 if (rv != CONNECTION_ERROR_NONE) {
2799 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2803 printf("Input username for FAST ethernet:");
2804 rv = scanf("%129s", input_str1);
2806 printf("Input password for FAST ethernet:");
2807 rv = scanf("%129s", input_str2);
2809 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2810 if (rv != CONNECTION_ERROR_NONE) {
2811 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2818 printf("Invalid EAP type\n");
2822 rv = connection_profile_save_ethernet_eap_config(connection, profile);
2823 if (rv != CONNECTION_ERROR_NONE) {
2824 printf("Fail to save eap config : %s\n", test_print_error(rv));
2828 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
2829 printf("Connection open Failed!!\n");
2836 static const char *test_print_eap_type(connection_ethernet_eap_type_e type)
2839 case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2841 case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2843 case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2845 case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2847 case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2854 static const char *test_print_eap_auth_type(connection_ethernet_eap_auth_type_e type)
2857 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_PAP:
2859 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAP:
2861 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2:
2863 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_GTC:
2865 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MD5:
2867 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_NONE:
2874 int test_get_eapol_info(void)
2876 connection_profile_type_e prof_type;
2877 connection_profile_state_e profile_state;
2878 connection_profile_h profile;
2879 char *profile_name = NULL;
2880 connection_ethernet_eap_type_e type;
2881 connection_ethernet_eap_auth_type_e auth_type;
2882 connection_ethernet_eap_peap_version_e peapver;
2885 printf("\n** Choose a ethernet profile to print eapol info. **\n");
2886 if (test_get_user_selected_profile(&profile, true) == false)
2889 bool enabled = false;
2890 if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE)
2891 printf("Failed to get ethernet eap enabled status!!\n");
2892 printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2894 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
2895 printf("Fail to get profile name\n");
2898 printf("Profile Name : %s\n", profile_name);
2899 g_free(profile_name);
2902 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE) {
2903 printf("Fail to get profile type\n");
2907 if (prof_type != CONNECTION_PROFILE_TYPE_ETHERNET) {
2908 printf("Not ethernet profile\n");
2912 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
2913 printf("Fail to get profile state\n");
2916 printf("Profile State : %s\n", test_print_state(profile_state));
2919 if (connection_profile_get_ethernet_eap_type(profile, &type) != CONNECTION_ERROR_NONE) {
2920 printf("Fail to get eap type\n");
2923 printf("eap_type: %s\n", test_print_eap_type(type));
2926 if (connection_profile_get_ethernet_eap_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2927 printf("Fail to get eap identity\n");
2930 printf("identity: %s\n", str);
2934 if (type == CONNECTION_ETHERNET_EAP_TYPE_MD5)
2937 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2938 type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2939 if (connection_profile_get_ethernet_eap_anonymous_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2940 printf("Fail to get eap anonymous_identity\n");
2943 printf("anonymous_identity: %s\n", str);
2948 if (connection_profile_get_ethernet_eap_ca_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2949 printf("Fail to get eap ca_cert_file\n");
2952 printf("ca_cert_file: %s\n", str);
2956 if (type == CONNECTION_ETHERNET_EAP_TYPE_TLS) {
2957 if (connection_profile_get_ethernet_eap_client_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2958 printf("Fail to get eap client_cert_file\n");
2961 printf("client_cert_file: %s\n", str);
2965 if (connection_profile_get_ethernet_eap_private_key_file(profile, &str) != CONNECTION_ERROR_NONE) {
2966 printf("Fail to get eap private_key_file\n");
2969 printf("private_key_file: %s\n", str);
2974 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2975 type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2976 if (connection_profile_get_ethernet_eap_auth_type(profile, &auth_type) != CONNECTION_ERROR_NONE) {
2977 printf("Fail to get eap auth type\n");
2980 printf("eap_auth: %s\n", test_print_eap_auth_type(auth_type));
2984 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP) {
2985 if (connection_profile_get_ethernet_eap_peap_version(profile, &peapver) != CONNECTION_ERROR_NONE) {
2986 printf("Fail to get eap peap_version\n");
2989 printf("peap_version: %d\n", peapver);
2993 if (type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2994 if (connection_profile_get_ethernet_eap_pac_file(profile, &str) != CONNECTION_ERROR_NONE) {
2995 printf("Fail to get eap pac_file\n");
2998 printf("pac_file: %s\n", str);
3007 int test_get_clock_update_info(void)
3012 rv = connection_clock_is_updated(connection, &updated);
3014 if (rv != CONNECTION_ERROR_NONE) {
3015 printf("Fail to get clock update information [%s]\n", test_print_error(rv));
3019 printf("Retval = [%s] clock updated [%s]\n",
3020 test_print_error(rv), updated ? "TRUE" : "FALSE");
3025 int test_set_ntp_server(void)
3028 char input_str1[100] = {0,};
3030 if (test_get_user_string("Enter NTP Server Url (Enter for skip) :", input_str1, 100)) {
3032 g_strstrip(input_str1);
3034 rv = connection_set_ntp_server(connection, input_str1);
3036 if (rv != CONNECTION_ERROR_NONE) {
3037 printf("Fail to set NTP Server [%s]\n", test_print_error(rv));
3041 printf("Retval = [%s]\n",test_print_error(rv));
3047 int test_get_ntp_server(void)
3052 rv = connection_get_ntp_server(connection, &ntp_server);
3054 if (rv != CONNECTION_ERROR_NONE) {
3055 printf("Fail to get ntp server [%s]\n", test_print_error(rv));
3059 printf("Retval = [%s] NTP Server : [%s]\n", test_print_error(rv), ntp_server);
3066 int test_clear_ntp_server(void)
3070 rv = connection_clear_ntp_server(connection);
3072 if (rv != CONNECTION_ERROR_NONE) {
3073 printf("Fail to clear ntp server[%s]\n", test_print_error(rv));
3077 printf("Retval = [%s]\n", test_print_error(rv));
3082 int main(int argc, char **argv)
3084 GMainLoop *mainloop;
3085 mainloop = g_main_loop_new(NULL, FALSE);
3087 GIOChannel *channel = g_io_channel_unix_new(0);
3088 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
3090 printf("Test Thread created...\n");
3092 g_main_loop_run(mainloop);
3097 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
3102 memset(a, '\0', 100);
3103 printf("event received from stdin\n");
3105 rv = read(0, a, 100);
3107 if (rv < 0 || a[0] == '0') {
3108 if (connection != NULL)
3109 test_deregister_client();
3114 if (*a == '\n' || *a == '\r') {
3116 printf("\n\n Network Connection API Test App\n\n");
3117 printf("Options..\n");
3118 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
3119 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
3120 printf("2 - Destroy Handle(unset callbacks automatically)\n");
3121 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
3122 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
3123 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
3124 printf("6 - Get current proxy address \n");
3125 printf("7 - Get current Ip address\n");
3126 printf("8 - Get cellular data call statistics\n");
3127 printf("9 - Get WiFi data call statistics\n");
3128 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
3129 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
3130 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
3131 printf("d - Open connection with profile\n");
3132 printf("e - Get default cellular service by type\n");
3133 printf("f - Set default cellular service by type\n");
3134 printf("g - Close connection with profile\n");
3135 printf("h - Add profile(Cellular and Wifi only)\n");
3136 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
3137 printf("j - Update profile\n");
3138 printf("k - Get profile info\n");
3139 printf("l - Refresh profile info\n");
3140 printf("m - Set state changed callback\n");
3141 printf("n - Unset state changed callback\n");
3142 printf("o - Reset cellular data call statistics\n");
3143 printf("p - Reset WiFi data call statistics\n");
3144 printf("q - Add new route\n");
3145 printf("r - Remove a route\n");
3146 printf("s - Get bluetooth state\n");
3147 printf("t - Get profile id\n");
3148 printf("u - Reset profile\n");
3149 printf("v - Get all cellular default profiles\n");
3150 printf("w - Get mac address\n");
3151 printf("x - Get ethernet cable state\n");
3152 printf("y - Get DHCP state\n");
3153 printf("B - Add IPv6 new route\n");
3154 printf("C - Remove IPv6 route\n");
3155 printf("D - Add new route entry\n");
3156 printf("E - Remove route entry\n");
3157 printf("F - Get all IPv6 address\n");
3158 printf("G - Get metered state\n");
3160 printf(LOG_BLUE "[Extension API]\n" LOG_END);
3161 printf("H - Start TCP Dump\n");
3162 printf("I - Stop TCP Dump\n");
3163 printf("J - Get TCP Dump State\n");
3164 printf("K - Enable MPTCP (internal)\n");
3165 printf("L - Disable MPTCP (internal)\n");
3166 printf("M - Set MPTCP Path Manager (internal)\n");
3167 printf("N - Get MPTCP Path Manager (internal)\n");
3168 printf("O - Set MPTCP Scheduler (internal)\n");
3169 printf("P - Get MPTCP Scheduler (internal)\n");
3170 printf(LOG_GREEN "Q - Create Handle and set callbacks in C# API\n" LOG_END);
3171 printf("R - Destroy Handle(unset callbacks automatically in C# API)\n");
3172 printf("S - Connect Ethernet EAP)\n");
3173 printf("T - Get EAPoL info)\n");
3174 printf("U - Get Clock update info)\n");
3175 printf("V - Set NTP Server\n");
3176 printf("W - Get NTP Server\n");
3177 printf("X - Clear NTP Server\n");
3178 printf(LOG_RED "0 - Exit \n" LOG_END);
3179 printf("ENTER - Show options menu.......\n");
3185 rv = test_register_client();
3188 rv = test_deregister_client();
3191 rv = test_get_network_state();
3194 rv = test_get_cellular_state();
3197 rv = test_get_wifi_state();
3200 rv = test_get_current_proxy();
3203 rv = test_get_current_ip();
3206 rv = test_get_call_statistics_info();
3209 rv = test_get_wifi_call_statistics_info();
3212 rv = test_get_profile_list();
3215 rv = test_get_connected_profile_list();
3218 rv = test_get_current_profile();
3221 rv = test_open_profile();
3224 rv = test_get_default_cellular_service_type();
3227 rv = test_set_default_cellular_service_type();
3230 rv = test_close_profile();
3233 rv = test_add_profile();
3236 rv = test_remove_profile();
3239 rv = test_update_profile();
3242 rv = test_get_profile_info();
3245 rv = test_refresh_profile_info();
3248 rv = test_set_state_changed_callback();
3251 rv = test_unset_state_changed_callback();
3254 rv = test_reset_call_statistics_info();
3257 rv = test_reset_wifi_call_statistics_info();
3260 rv = test_add_route();
3263 rv = test_remove_route();
3266 rv = test_get_bt_state();
3269 rv = test_get_profile_id();
3272 rv = test_reset_profile();
3275 rv = test_get_default_profile_list();
3278 rv = test_get_mac_address();
3281 rv = test_get_ethernet_cable_state();
3284 rv = test_get_dhcp_state();
3287 rv = test_add_route_ipv6();
3290 rv = test_remove_route_ipv6();
3293 rv = test_add_route_entry();
3296 rv = test_remove_route_entry();
3299 rv = test_foreach_ipv6_address();
3302 rv = test_is_metered_network();
3306 rv = test_start_tcpdump();
3309 rv = test_stop_tcpdump();
3312 rv = test_get_tcpdump_state();
3315 rv = test_mptcp_enable();
3318 rv = test_mptcp_disable();
3321 rv = test_mptcp_set_path_manager();
3324 rv = test_mptcp_get_path_manager();
3327 rv = test_mptcp_set_scheduler();
3330 rv = test_mptcp_get_scheduler();
3333 rv = test_register_client_cs();
3336 rv = test_deregister_client_cs();
3339 rv = test_ethernet_eap_connect();
3342 rv = test_get_eapol_info();
3345 rv = test_get_clock_update_info();
3348 rv = test_set_ntp_server();
3351 rv = test_get_ntp_server();
3354 rv = test_clear_ntp_server();
3359 printf("Operation succeeded!\n");
3361 printf("Operation failed!\n");