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_profile_state_callback(connection_profile_state_e state, void* user_data)
296 connection_profile_h profile = user_data;
301 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
304 printf("[%s] : %s\n", test_print_state(state), profile_name);
305 g_free(profile_name);
308 static void test_connection_opened_callback(connection_error_e result, void* user_data)
310 if (result == CONNECTION_ERROR_NONE)
311 printf("Connection open Succeeded\n");
313 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
316 static void test_connection_closed_callback(connection_error_e result, void* user_data)
318 if (result == CONNECTION_ERROR_NONE)
319 printf("Connection close Succeeded\n");
321 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
324 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
326 if (result == CONNECTION_ERROR_NONE)
327 printf("Reset profile Succeeded\n");
329 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
332 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
334 if (result == CONNECTION_ERROR_NONE)
335 printf("Default profile setting Succeeded\n");
337 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
340 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
343 if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
344 printf("Ethernet Cable Connected\n");
345 else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
346 printf("Ethernet Cable Disconnected\n");
349 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
354 connection_profile_type_e profile_type;
355 connection_profile_state_e profile_state;
356 connection_profile_iterator_h profile_iter;
357 connection_profile_h profile_h;
359 connection_profile_h profile_list[100] = {0,};
360 int profile_count = 0;
362 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
363 if (rv != CONNECTION_ERROR_NONE) {
364 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
368 while (connection_profile_iterator_has_next(profile_iter)) {
369 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
370 printf("Fail to get profile handle\n");
374 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
375 printf("Fail to get profile name\n");
379 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
380 printf("Fail to get profile type\n");
381 g_free(profile_name);
385 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
386 printf("Fail to get profile state\n");
387 g_free(profile_name);
391 printf("%d. state:[%s], profile name:%s", profile_count,
392 test_print_state(profile_state), profile_name);
393 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
394 connection_cellular_service_type_e service_type;
395 if (connection_profile_get_cellular_service_type(
396 profile_h, &service_type) !=
397 CONNECTION_ERROR_NONE)
398 printf("Fail to get cellular service type!\n");
401 test_print_cellular_service_type(service_type));
402 } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
403 connection_wifi_security_type_e security_type;
404 if (connection_profile_get_wifi_security_type(
405 profile_h, &security_type) !=
406 CONNECTION_ERROR_NONE)
407 printf("Fail to get wifi security type!\n");
410 test_print_wifi_security_type(security_type));
414 profile_list[profile_count] = profile_h;
417 g_free(profile_name);
418 if (profile_count >= 100)
425 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
426 input >= profile_count ||
428 printf("Wrong number!!\n");
433 *profile = profile_list[input];
438 static int test_update_cellular_info(connection_profile_h profile)
441 char input_str1[100] = {0,};
442 char input_str2[100] = {0,};
446 if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
447 "Prepaid MMS:4, Tethering:5, Application:6)"
448 " - (Enter for skip) :", &input_int)) {
451 rv = connection_profile_set_cellular_service_type(profile,
452 CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
455 rv = connection_profile_set_cellular_service_type(profile,
456 CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
459 rv = connection_profile_set_cellular_service_type(profile,
460 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
463 rv = connection_profile_set_cellular_service_type(profile,
464 CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
467 rv = connection_profile_set_cellular_service_type(profile,
468 CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
471 rv = connection_profile_set_cellular_service_type(profile,
472 CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
478 if (rv != CONNECTION_ERROR_NONE)
483 if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
484 g_strstrip(input_str1);
485 rv = connection_profile_set_cellular_apn(profile, input_str1);
486 if (rv != CONNECTION_ERROR_NONE)
490 if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
491 g_strstrip(input_str1);
492 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
493 if (rv != CONNECTION_ERROR_NONE)
497 if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
498 g_strstrip(input_str1);
499 rv = connection_profile_set_cellular_home_url(profile, input_str1);
500 if (rv != CONNECTION_ERROR_NONE)
504 if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
507 rv = connection_profile_set_cellular_auth_info(profile,
508 CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
509 if (rv != CONNECTION_ERROR_NONE)
514 type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
517 if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
519 if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
521 if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
524 g_strstrip(input_str1);
525 g_strstrip(input_str2);
526 rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
527 if (rv != CONNECTION_ERROR_NONE)
532 if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
535 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
538 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
541 rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
545 if (rv != CONNECTION_ERROR_NONE)
549 if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
552 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
555 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
558 rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
562 if (rv != CONNECTION_ERROR_NONE)
569 static int test_update_wifi_info(connection_profile_h profile)
572 char input_str[100] = {0,};
574 if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
575 rv = connection_profile_set_wifi_passphrase(profile, input_str);
576 if (rv != CONNECTION_ERROR_NONE)
583 static int test_update_dns_info(connection_profile_h profile,
584 connection_address_family_e address_family)
587 char input_str[100] = {0,};
588 if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
589 rv = connection_profile_set_dns_address(profile,
593 if (rv != CONNECTION_ERROR_NONE)
596 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
597 rv = connection_profile_set_dns_address(profile,
601 if (rv != CONNECTION_ERROR_NONE)
608 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
612 char input_str[100] = {0,};
614 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
615 rv = connection_profile_set_ip_address(profile,
618 if (rv != CONNECTION_ERROR_NONE)
622 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
623 rv = connection_profile_set_subnet_mask(profile,
626 if (rv != CONNECTION_ERROR_NONE)
630 if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
631 rv = connection_profile_set_prefix_length(profile,
634 if (rv != CONNECTION_ERROR_NONE)
638 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
639 rv = connection_profile_set_gateway_address(profile,
642 if (rv != CONNECTION_ERROR_NONE)
646 if (test_update_dns_info(profile, address_family) < 0)
652 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
656 char input_str[100] = {0,};
658 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
659 " - (Enter for skip) :", &input_int)) {
662 rv = connection_profile_set_proxy_type(profile,
663 CONNECTION_PROXY_TYPE_DIRECT);
665 if (rv != CONNECTION_ERROR_NONE)
670 rv = connection_profile_set_proxy_type(profile,
671 CONNECTION_PROXY_TYPE_AUTO);
674 rv = connection_profile_set_proxy_type(profile,
675 CONNECTION_PROXY_TYPE_MANUAL);
681 if (rv != CONNECTION_ERROR_NONE)
684 if (test_get_user_string("Input auto Proxy URL or Proxy address"
685 " - (Enter for skip) :", input_str, 100)) {
686 rv = connection_profile_set_proxy_address(profile,
689 if (rv != CONNECTION_ERROR_NONE)
701 static int test_update_network_info(connection_profile_h profile)
706 int address_family = 0;
708 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
710 if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
711 " - (Enter for skip) :", &input_int)) {
714 rv = connection_profile_set_ip_config_type(profile,
716 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
717 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
718 " - (Enter for skip) :", &dns_input)) {
720 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
721 rv = connection_profile_set_dns_config_type(
724 CONNECTION_DNS_CONFIG_TYPE_STATIC);
725 if (rv != CONNECTION_ERROR_NONE)
727 if (test_update_dns_info(profile,
728 address_family) == -1)
731 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
732 rv = connection_profile_set_dns_config_type(
735 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
736 if (rv != CONNECTION_ERROR_NONE)
743 rv = connection_profile_set_ip_config_type(profile,
745 CONNECTION_IP_CONFIG_TYPE_STATIC);
746 if (rv != CONNECTION_ERROR_NONE)
749 if (test_update_ip_info(profile, address_family) == -1)
752 if (test_update_proxy_info(profile, address_family) == -1)
756 rv = connection_profile_set_ip_config_type(profile,
758 CONNECTION_IP_CONFIG_TYPE_AUTO);
764 if (rv != CONNECTION_ERROR_NONE)
772 static void test_print_cellular_info(connection_profile_h profile)
774 connection_cellular_service_type_e service_type;
775 connection_cellular_pdn_type_e pdn_type;
776 connection_cellular_pdn_type_e roam_pdn_type;
778 connection_cellular_auth_type_e auth_type;
779 char *user_name = NULL;
780 char *password = NULL;
781 char *home_url = NULL;
782 bool roaming = false;
784 bool editable = false;
786 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
787 printf("Fail to get cellular service type!\n");
789 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
791 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
792 printf("Fail to get cellular pdn type!\n");
794 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
796 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
797 printf("Fail to get cellular roam pdn type!\n");
799 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
801 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
802 printf("Fail to get cellular APN!\n");
804 printf("Cellular APN : %s\n", apn);
808 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
809 printf("Fail to get auth info!\n");
811 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
812 printf("Cellular user_name : %s\n", user_name);
813 printf("Cellular password : %s\n", password);
818 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
819 printf("Fail to get cellular home url!\n");
821 printf("Cellular home url : %s\n", home_url);
825 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
826 printf("Fail to get cellular roaming state!\n");
828 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
830 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
831 printf("Fail to get cellular hidden state!\n");
833 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
835 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
836 printf("Fail to get cellular editing state!\n");
838 printf("Cellular editable : %s\n", editable ? "true" : "false");
841 static void test_print_wifi_info(connection_profile_h profile)
848 connection_wifi_security_type_e security_type;
849 connection_wifi_encryption_type_e encryption_type;
850 bool pass_required = false;
851 bool wps_supported = false;
853 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
854 printf("Fail to get Wi-Fi essid!\n");
856 printf("Wi-Fi essid : %s\n", essid);
860 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
861 printf("Fail to get Wi-Fi bssid!\n");
863 printf("Wi-Fi bssid : %s\n", bssid);
867 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
868 printf("Fail to get Wi-Fi rssi!\n");
870 printf("Wi-Fi rssi : %d\n", rssi);
872 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
873 printf("Fail to get Wi-Fi frequency!\n");
875 printf("Wi-Fi frequency : %d\n", frequency);
877 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
878 printf("Fail to get Wi-Fi max speed!\n");
880 printf("Wi-Fi max speed : %d\n", max_speed);
882 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
883 printf("Fail to get Wi-Fi security type!\n");
885 printf("Wi-Fi security type : %s\n", test_print_wifi_security_type(security_type));
887 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
888 printf("Fail to get Wi-Fi encryption type!\n");
890 printf("Wi-Fi encryption type : %d\n", encryption_type);
892 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
893 printf("Fail to get Wi-Fi passphrase required!\n");
895 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
897 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
898 printf("Fail to get Wi-Fi wps info\n");
900 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
903 static void test_print_mesh_info(connection_profile_h profile)
909 connection_wifi_security_type_e security_type;
910 bool pass_required = false;
912 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
913 printf("Fail to get Mesh essid!\n");
915 printf("Mesh essid : %s\n", essid);
919 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
920 printf("Fail to get Mesh bssid!\n");
922 printf("Mesh bssid : %s\n", bssid);
926 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
927 printf("Fail to get Mesh rssi!\n");
929 printf("Mesh rssi : %d\n", rssi);
931 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
932 printf("Fail to get Mesh frequency!\n");
934 printf("Mesh frequency : %d\n", frequency);
936 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
937 printf("Fail to get Mesh security type!\n");
939 printf("Mesh security type : %s\n", test_print_wifi_security_type(security_type));
941 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
942 printf("Fail to get Mesh passphrase required!\n");
944 printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
947 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
949 char *interface_name = NULL;
952 char *gateway = NULL;
953 char *dhcp_server = NULL;
954 int dhcp_lease_duration = 0;
959 connection_ip_config_type_e ip_type;
960 connection_proxy_type_e proxy_type;
961 connection_dns_config_type_e dns_type;
963 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
964 printf("Fail to get interface name!\n");
966 printf("Interface name : %s\n", interface_name);
967 g_free(interface_name);
970 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
971 printf("Fail to get ipconfig type!\n");
973 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
974 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
975 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
976 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
977 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
978 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
979 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
980 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
982 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
985 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
986 printf("Fail to get IP address!\n");
988 printf("IP address : %s\n", ip);
992 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
993 printf("Fail to get gateway!\n");
995 printf("Gateway : %s\n", gateway);
999 if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
1000 printf("Fail to get DHCP Server address!\n");
1002 printf("DHCP Server : %s\n", dhcp_server);
1003 g_free(dhcp_server);
1006 if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
1007 printf("Fail to get DHCP lease duration!\n");
1009 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
1012 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
1013 printf("Fail to get subnet mask!\n");
1015 printf("Subnet mask : %s\n", subnet);
1019 if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
1020 printf("Fail to get prefix length!\n");
1022 printf("Prefix length : %d\n", prefix_len);
1024 if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
1025 printf("Fail to get DNS configuration type!\n");
1027 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
1028 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
1029 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
1030 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
1032 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
1035 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
1036 printf("Fail to get DNS1!\n");
1038 printf("DNS1 : %s\n", dns1);
1042 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
1043 printf("Fail to get DNS2!\n");
1045 printf("DNS2 : %s\n", dns2);
1049 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
1050 printf("Fail to get proxy type!\n");
1052 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
1053 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
1054 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
1055 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
1057 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
1060 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
1061 printf("Fail to get proxy!\n");
1063 printf("Proxy : %s\n", proxy);
1068 int test_register_client(void)
1071 int err = connection_create(&connection);
1073 if (CONNECTION_ERROR_NONE == err) {
1074 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1075 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1076 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1077 connection_set_ethernet_cable_state_changed_cb(connection,
1078 test_get_ethernet_cable_state_callback, NULL);
1079 connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
1081 printf("Client registration failed [%s]\n", test_print_error(err));
1085 printf("Client registration success\n");
1089 int test_deregister_client(void)
1093 connection_profile_h profile;
1095 if (connection != NULL)
1096 rv = connection_destroy(connection);
1098 printf("Cannot deregister : Handle is NULL\n");
1099 rv = CONNECTION_ERROR_INVALID_OPERATION;
1102 if (rv != CONNECTION_ERROR_NONE) {
1103 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1107 if (state_cb_list) {
1108 for (list = state_cb_list; list; list = list->next) {
1109 profile = list->data;
1110 connection_profile_destroy(profile);
1113 g_slist_free(state_cb_list);
1114 state_cb_list = NULL;
1118 printf("Client deregistration success\n");
1123 int test_register_client_cs(void)
1126 test_get_user_int("Input a TID in C# API :", &tid);
1128 int err = connection_create_cs(tid, &connection);
1130 if (CONNECTION_ERROR_NONE == err) {
1131 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1132 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1133 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1134 connection_set_ethernet_cable_state_changed_cb(connection,
1135 test_get_ethernet_cable_state_callback, NULL);
1137 printf("Client registration failed [%s]\n", test_print_error(err));
1141 printf("Client registration success\n");
1145 int test_deregister_client_cs(void)
1149 connection_profile_h profile;
1152 test_get_user_int("Input a TID in C# API :", &tid);
1154 if (connection != NULL)
1155 rv = connection_destroy_cs(tid, connection);
1157 printf("Cannot deregister : Handle is NULL\n");
1158 rv = CONNECTION_ERROR_INVALID_OPERATION;
1161 if (rv != CONNECTION_ERROR_NONE) {
1162 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1166 if (state_cb_list) {
1167 for (list = state_cb_list; list; list = list->next) {
1168 profile = list->data;
1169 connection_profile_destroy(profile);
1172 g_slist_free(state_cb_list);
1173 state_cb_list = NULL;
1177 printf("Client deregistration success\n");
1182 int test_get_network_state(void)
1185 connection_type_e net_state;
1187 rv = connection_get_type(connection, &net_state);
1189 if (rv != CONNECTION_ERROR_NONE) {
1190 printf("Fail to get network state [%s]\n", test_print_error(rv));
1194 printf("Retval = [%s] network connection state [%s]\n",
1195 test_print_error(rv), test_print_connection_type(net_state));
1200 int test_get_cellular_state(void)
1203 connection_cellular_state_e cellular_state;
1205 rv = connection_get_cellular_state(connection, &cellular_state);
1207 if (rv != CONNECTION_ERROR_NONE) {
1208 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1212 printf("Retval = [%s] Cellular state [%s]\n",
1213 test_print_error(rv), test_print_cellular_state(cellular_state));
1218 int test_get_wifi_state(void)
1221 connection_wifi_state_e wifi_state;
1223 rv = connection_get_wifi_state(connection, &wifi_state);
1225 if (rv != CONNECTION_ERROR_NONE) {
1226 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1230 printf("Retval = [%s] WiFi state [%s]\n",
1231 test_print_error(rv), test_print_wifi_state(wifi_state));
1236 int test_get_current_proxy(void)
1238 char *proxy_addr = NULL;
1240 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1242 if (proxy_addr == NULL) {
1243 printf("Proxy address does not exist\n");
1247 printf("Current Proxy [%s]\n", proxy_addr);
1253 int test_get_current_ip(void)
1255 char *ip_addr = NULL;
1259 rv = test_get_user_int("Input Address type to get"
1260 "(1:IPV4, 2:IPV6):", &input);
1263 printf("Invalid input!!\n");
1269 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1270 if (ip_addr == NULL) {
1271 printf("IPv4 address does not exist\n");
1274 printf("IPv4 address : %s\n", ip_addr);
1278 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1279 if (ip_addr == NULL) {
1280 printf("IPv6 address does not exist\n");
1283 printf("IPv6 address : %s\n", ip_addr);
1286 printf("Wrong IP address family!!\n");
1294 int test_get_call_statistics_info(void)
1298 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1299 printf("last recv data size [%lld]\n", rv);
1300 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1301 printf("last sent data size [%lld]\n", rv);
1302 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1303 printf("total received data size [%lld]\n", rv);
1304 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1305 printf("total sent data size [%lld]\n", rv);
1310 int test_get_wifi_call_statistics_info(void)
1314 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1315 printf("WiFi last recv data size [%lld]\n", rv);
1316 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1317 printf("WiFi last sent data size [%lld]\n", rv);
1318 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1319 printf("WiFi total received data size [%lld]\n", rv);
1320 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1321 printf("WiFi total sent data size [%lld]\n", rv);
1326 int test_get_profile_list(void)
1328 if (test_get_user_selected_profile(NULL, false) == false)
1334 int test_get_default_profile_list(void)
1337 char *profile_name = NULL;
1338 connection_profile_iterator_h profile_iter;
1339 connection_profile_h profile_h;
1340 connection_cellular_service_type_e service_type;
1341 bool is_default = false;
1343 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1344 if (rv != CONNECTION_ERROR_NONE) {
1345 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1349 while (connection_profile_iterator_has_next(profile_iter)) {
1350 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1351 printf("Fail to get profile handle\n");
1355 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1356 printf("Fail to get profile name\n");
1359 printf("profile name : %s\n", profile_name);
1360 g_free(profile_name);
1362 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1363 printf("Fail to get profile service type\n");
1366 printf("service type : %d\n", service_type);
1368 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1369 printf("Fail to get profile subscriber id\n");
1372 printf("Default : %d\n", is_default);
1378 int test_get_connected_profile_list(void)
1381 char *profile_name = NULL;
1382 connection_profile_iterator_h profile_iter;
1383 connection_profile_h profile_h;
1384 bool is_default = false;
1385 connection_profile_type_e type;
1387 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1388 if (rv != CONNECTION_ERROR_NONE) {
1389 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1393 while (connection_profile_iterator_has_next(profile_iter)) {
1394 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1395 printf("Fail to get profile handle\n");
1399 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1400 printf("Fail to get profile name\n");
1403 printf("profile name is %s\n", profile_name);
1404 g_free(profile_name);
1406 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1407 printf("Fail to get profile type\n");
1410 printf("profile type is %d\n", type);
1412 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1413 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1414 printf("Fail to get profile is default\n");
1417 printf("[%s]\n", is_default ? "default" : "not default");
1424 int test_get_current_profile(void)
1427 char *profile_name = NULL;
1428 connection_profile_h profile_h;
1430 rv = connection_get_current_profile(connection, &profile_h);
1431 if (rv != CONNECTION_ERROR_NONE) {
1432 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1436 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1437 printf("Fail to get profile name\n");
1440 printf("profile name : %s\n", profile_name);
1441 g_free(profile_name);
1443 connection_profile_destroy(profile_h);
1448 int test_open_profile(void)
1450 connection_profile_h profile;
1452 printf("\n** Choose a profile to open. **\n");
1454 if (test_get_user_selected_profile(&profile, true) == false)
1457 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1458 printf("Connection open Failed!!\n");
1465 int test_get_default_cellular_service_type(void)
1470 connection_profile_h profile;
1471 char *profile_name = NULL;
1473 rv = test_get_user_int("Input profile type to get"
1474 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1477 printf("Invalid input!!\n");
1483 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1486 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1489 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1492 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1495 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1498 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1501 printf("Wrong number!!\n");
1505 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1508 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1509 printf("Fail to get profile name\n");
1510 connection_profile_destroy(profile);
1513 printf("Default profile name : %s\n", profile_name);
1514 g_free(profile_name);
1516 connection_profile_destroy(profile);
1521 int test_set_default_cellular_service_type(void)
1523 connection_profile_h profile;
1524 connection_cellular_service_type_e type;
1527 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1529 if (rv == false || (input != 1 && input != 2)) {
1530 printf("Invalid input!!\n");
1534 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1536 if (test_get_user_selected_profile(&profile, true) == false)
1539 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1540 printf("Fail to get cellular service type\n");
1545 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1548 if (connection_set_default_cellular_service_profile_async(connection,
1549 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1556 int test_close_profile(void)
1558 connection_profile_h profile;
1560 printf("\n** Choose a profile to close. **\n");
1562 if (test_get_user_selected_profile(&profile, true) == false)
1565 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1566 printf("Connection close Failed!!\n");
1573 int test_add_profile(void)
1576 connection_profile_h profile;
1577 char input_str[100] = {0,};
1579 if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1582 g_strstrip(input_str);
1583 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1584 if (rv != CONNECTION_ERROR_NONE)
1585 RETURN_FAIL_DESTROY(profile);
1587 if (test_update_cellular_info(profile) == -1)
1588 RETURN_FAIL_DESTROY(profile);
1590 rv = connection_add_profile(connection, profile);
1591 if (rv != CONNECTION_ERROR_NONE)
1592 RETURN_FAIL_DESTROY(profile);
1594 connection_profile_destroy(profile);
1598 int test_remove_profile(void)
1600 connection_profile_h profile;
1602 printf("\n** Choose a profile to remove. **\n");
1603 if (test_get_user_selected_profile(&profile, true) == false)
1606 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1607 printf("Remove profile Failed!!\n");
1614 int test_update_profile(void)
1618 connection_profile_type_e prof_type;
1619 connection_profile_h profile;
1621 printf("\n** Choose a profile to update. **\n");
1622 if (test_get_user_selected_profile(&profile, true) == false)
1625 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1628 switch (prof_type) {
1629 case CONNECTION_PROFILE_TYPE_CELLULAR:
1630 if (test_update_cellular_info(profile) == -1)
1634 case CONNECTION_PROFILE_TYPE_WIFI:
1635 if (test_update_wifi_info(profile) == -1)
1638 if (test_update_network_info(profile) == -1)
1642 case CONNECTION_PROFILE_TYPE_ETHERNET:
1643 if (test_update_network_info(profile) == -1)
1647 case CONNECTION_PROFILE_TYPE_BT:
1648 printf("Not supported!\n");
1652 int profile_type = prof_type;
1653 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1654 if (test_update_wifi_info(profile) == -1)
1662 rv = connection_update_profile(connection, profile);
1663 if (rv != CONNECTION_ERROR_NONE)
1669 int test_get_profile_info(void)
1671 connection_profile_type_e prof_type;
1672 connection_profile_state_e profile_state;
1673 connection_profile_state_e profile_ipv6_state;
1674 connection_internet_state_e internet_state;
1675 connection_profile_h profile;
1676 char *profile_name = NULL;
1677 int address_family = 0;
1679 printf("\n** Choose a profile to print. **\n");
1680 if (test_get_user_selected_profile(&profile, true) == false)
1683 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1684 printf("Fail to get profile name\n");
1687 printf("Profile Name : %s\n", profile_name);
1688 g_free(profile_name);
1691 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1692 printf("Fail to get profile IPv4 state\n");
1695 printf("Profile State : %s\n", test_print_state(profile_state));
1697 if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1698 printf("Fail to get profile IPv6 state\n");
1701 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1703 if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
1704 printf("Fail to get Internet state\n");
1707 printf("Internet State : %s\n", test_print_internet_state(internet_state));
1709 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1712 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1714 switch (prof_type) {
1715 case CONNECTION_PROFILE_TYPE_CELLULAR:
1716 printf("Profile Type : Cellular\n");
1717 test_print_cellular_info(profile);
1719 case CONNECTION_PROFILE_TYPE_WIFI:
1720 printf("Profile Type : Wi-Fi\n");
1721 test_print_wifi_info(profile);
1723 case CONNECTION_PROFILE_TYPE_ETHERNET:
1724 printf("Profile Type : Ethernet\n");
1726 case CONNECTION_PROFILE_TYPE_BT:
1727 printf("Profile Type : Bluetooth\n");
1731 int profile_type = prof_type;
1732 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1733 printf("Profile Type : Mesh\n");
1734 test_print_mesh_info(profile);
1741 test_print_network_info(profile, address_family);
1746 int test_refresh_profile_info(void)
1748 connection_profile_type_e prof_type;
1749 connection_profile_state_e profile_state;
1750 connection_profile_h profile;
1751 char *profile_name = NULL;
1752 int address_family = 0;
1754 printf("\n** Choose a profile to refresh. **\n");
1755 if (test_get_user_selected_profile(&profile, true) == false)
1758 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1761 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1762 printf("Fail to get profile name\n");
1765 printf("Profile Name : %s\n", profile_name);
1766 g_free(profile_name);
1769 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1770 printf("Fail to get profile state\n");
1773 printf("Profile State : %s\n", test_print_state(profile_state));
1776 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1779 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1781 switch (prof_type) {
1782 case CONNECTION_PROFILE_TYPE_CELLULAR:
1783 printf("Profile Type : Cellular\n");
1784 test_print_cellular_info(profile);
1786 case CONNECTION_PROFILE_TYPE_WIFI:
1787 printf("Profile Type : Wi-Fi\n");
1788 test_print_wifi_info(profile);
1790 case CONNECTION_PROFILE_TYPE_ETHERNET:
1791 printf("Profile Type : Ethernet\n");
1793 case CONNECTION_PROFILE_TYPE_BT:
1794 printf("Profile Type : Bluetooth\n");
1798 int profile_type = prof_type;
1799 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1800 printf("Profile Type : Mesh\n");
1801 test_print_mesh_info(profile);
1808 test_print_network_info(profile, address_family);
1813 int test_set_state_changed_callback()
1815 connection_profile_h profile;
1816 connection_profile_h profile_clone;
1818 printf("\n** Choose a profile to set callback. **\n");
1819 if (test_get_user_selected_profile(&profile, true) == false)
1822 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1825 if (connection_profile_set_state_changed_cb(profile,
1826 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1827 connection_profile_destroy(profile_clone);
1831 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1836 int test_unset_state_changed_callback()
1838 connection_profile_h profile;
1840 char *profile_name = NULL;
1844 printf("\n** Choose a profile to unset callback. **\n");
1845 for (list = state_cb_list; list; list = list->next) {
1846 profile = list->data;
1847 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1848 printf("Fail to get profile name!\n");
1851 printf("%d. %s\n", count, profile_name);
1852 g_free(profile_name);
1858 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1861 printf("Wrong number!!\n");
1866 for (list = state_cb_list; list; list = list->next) {
1867 if (count == input) {
1868 profile = list->data;
1878 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1881 state_cb_list = g_slist_remove(state_cb_list, profile);
1882 connection_profile_destroy(profile);
1887 int test_reset_call_statistics_info(void)
1889 int ret = CONNECTION_ERROR_NONE;
1891 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1892 printf("reset last recv data size [%d]\n", ret);
1893 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1894 printf("last sent data size [%d]\n", ret);
1895 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1896 printf("total received data size [%d]\n", ret);
1897 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1898 printf("total sent data size [%d]\n", ret);
1903 int test_reset_wifi_call_statistics_info(void)
1905 int ret = CONNECTION_ERROR_NONE;
1907 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1908 printf("WiFi last sent data size [%d]\n", ret);
1909 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1910 printf("WiFi last recv data size [%d]\n", ret);
1911 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1912 printf("WiFi total sent data size [%d]\n", ret);
1913 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1914 printf("WiFi total received data size [%d]\n", ret);
1919 int test_add_route(void)
1922 char ip_addr[100] = {0};
1923 char if_name[40] = {0};
1925 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1928 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1931 g_strstrip(ip_addr);
1932 g_strstrip(if_name);
1933 rv = connection_add_route(connection, if_name, ip_addr);
1934 if (rv != CONNECTION_ERROR_NONE) {
1935 printf("Fail to get add new route [%d]\n", rv);
1938 printf("Add Route successfully\n");
1943 int test_remove_route(void)
1946 char ip_addr[100] = {0};
1947 char if_name[40] = {0};
1949 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1952 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1955 g_strstrip(ip_addr);
1956 g_strstrip(if_name);
1957 rv = connection_remove_route(connection, if_name, ip_addr);
1958 if (rv != CONNECTION_ERROR_NONE) {
1959 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1962 printf("Remove Route successfully\n");
1967 int test_add_route_ipv6(void)
1970 char ip_addr[100] = {0};
1971 char gateway[100] = {0};
1972 char if_name[40] = {0};
1974 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1977 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1980 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1983 g_strstrip(ip_addr);
1984 g_strstrip(gateway);
1985 g_strstrip(if_name);
1986 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1987 if (rv != CONNECTION_ERROR_NONE) {
1988 printf("Fail to get add new route [%d]\n", rv);
1991 printf("Add Route successfully\n");
1996 int test_remove_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 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2009 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2012 g_strstrip(ip_addr);
2013 g_strstrip(gateway);
2014 g_strstrip(if_name);
2015 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
2016 if (rv != CONNECTION_ERROR_NONE) {
2017 printf("Fail to remove the route [%d]\n", rv);
2020 printf("Remove Route successfully\n");
2025 int test_add_route_entry(void)
2027 char ip_addr[100] = {0};
2028 char gateway[100] = {0};
2029 char if_name[40] = {0};
2034 input_rv = test_get_user_int("Input Address type to get"
2035 "(1:IPV4, 2:IPV6):", &input);
2037 if (input_rv == false) {
2038 printf("Invalid input!!\n");
2044 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2047 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2050 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2053 g_strstrip(ip_addr);
2054 g_strstrip(gateway);
2055 g_strstrip(if_name);
2056 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2057 if (rv != CONNECTION_ERROR_NONE) {
2058 printf("Fail to get add new route [%d]\n", rv);
2061 printf("Add Route successfully\n");
2065 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2068 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2071 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2074 g_strstrip(ip_addr);
2075 g_strstrip(gateway);
2076 g_strstrip(if_name);
2077 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2078 if (rv != CONNECTION_ERROR_NONE) {
2079 printf("Fail to get add new route [%d]\n", rv);
2082 printf("Add Route successfully\n");
2086 printf("Wrong IP address family!!\n");
2095 int test_remove_route_entry(void)
2097 char ip_addr[100] = {0};
2098 char gateway[100] = {0};
2099 char if_name[40] = {0};
2104 input_rv = test_get_user_int("Input Address type to get"
2105 "(1:IPV4, 2:IPV6):", &input);
2107 if (input_rv == false) {
2108 printf("Invalid input!!\n");
2114 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2117 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2120 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2123 g_strstrip(ip_addr);
2124 g_strstrip(gateway);
2125 g_strstrip(if_name);
2126 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2127 if (rv != CONNECTION_ERROR_NONE) {
2128 printf("Fail to remove the route [%s]\n", test_print_error(rv));
2131 printf("Remove Route successfully\n");
2136 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2139 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2142 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2145 g_strstrip(ip_addr);
2146 g_strstrip(gateway);
2147 g_strstrip(if_name);
2148 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2149 if (rv != CONNECTION_ERROR_NONE) {
2150 printf("Fail to remove the route [%d]\n", rv);
2153 printf("Remove Route successfully\n");
2157 printf("Wrong IP address family!!\n");
2166 int test_get_bt_state(void)
2169 connection_bt_state_e bt_state;
2171 rv = connection_get_bt_state(connection, &bt_state);
2173 if (rv != CONNECTION_ERROR_NONE) {
2174 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
2178 printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
2183 int test_get_profile_id(void)
2185 connection_profile_h profile;
2188 printf("\n** Choose a profile to see profile id. **\n");
2189 if (test_get_user_selected_profile(&profile, true) == false)
2192 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2193 printf("Fail to get profile name\n");
2196 printf("Profile id : %s\n", profile_id);
2203 int test_get_mac_address(void)
2205 int rv = 0, type = 0;
2206 connection_type_e conn_type;
2207 char *mac_addr = NULL;
2209 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2213 conn_type = CONNECTION_TYPE_WIFI;
2216 conn_type = CONNECTION_TYPE_ETHERNET;
2219 printf("Wrong number!!\n");
2223 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2225 if (rv != CONNECTION_ERROR_NONE) {
2226 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2230 printf("mac address is %s\n", mac_addr);
2237 int test_get_ethernet_cable_state(void)
2240 connection_ethernet_cable_state_e cable_state;
2242 rv = connection_get_ethernet_cable_state(connection, &cable_state);
2244 if (rv != CONNECTION_ERROR_NONE) {
2245 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2249 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2254 int test_reset_profile(void)
2256 int type, sim_id, rv;
2258 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2260 if (rv == false || (type != 0 && type != 1)) {
2261 printf("Invalid input!!\n");
2265 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2267 if (rv == false || (sim_id != 0 && sim_id != 1)) {
2268 printf("Invalid input!!\n");
2272 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2278 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2280 printf("IPv6 Address : %s\n", ipv6_address);
2284 int test_foreach_ipv6_address(void)
2288 connection_type_e conn_type;
2290 test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2294 conn_type = CONNECTION_TYPE_WIFI;
2297 conn_type = CONNECTION_TYPE_ETHERNET;
2300 printf("Wrong number!!\n");
2304 rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2305 if (rv != CONNECTION_ERROR_NONE) {
2306 printf("Fail to get IPv6 address\n");
2313 int test_is_metered_network(void)
2318 rv = connection_is_metered_network(connection, &metered_state);
2320 if (rv != CONNECTION_ERROR_NONE) {
2321 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2325 printf("Retval = [%s] metered state [%s]\n",
2326 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2331 int test_start_tcpdump(void)
2333 if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2337 printf("Successfully started tcpdump\n");
2342 int test_stop_tcpdump(void)
2344 if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2348 printf("Successfully stopped tcpdump\n");
2353 int test_get_tcpdump_state(void)
2355 gboolean tcpdump_state = FALSE;
2357 if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
2361 printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2366 int test_mptcp_enable(void)
2369 bool supported = false;
2370 rv = connection_mptcp_is_supported(connection, &supported);
2371 if (rv != CONNECTION_ERROR_NONE) {
2372 printf("Failure[%s]\n", test_print_error(rv));
2375 printf("MPTCP Support: %d\n", supported);
2377 rv = connection_mptcp_enable(connection, CONNECTION_MPTCP_ENABLE_ALL);
2378 if (rv != CONNECTION_ERROR_NONE) {
2379 printf("Failure[%s]\n", test_print_error(rv));
2385 int test_mptcp_disable(void)
2388 rv = connection_mptcp_disable(connection);
2390 if (rv != CONNECTION_ERROR_NONE) {
2391 printf("Failure[%s]\n", test_print_error(rv));
2397 int test_mptcp_set_path_manager(void)
2401 rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
2405 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_DEFAULT);
2408 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_FULLMESH);
2411 printf("Invalid input!!\n");
2415 if (rv != CONNECTION_ERROR_NONE) {
2416 printf("Failure[%s]\n", test_print_error(rv));
2423 int test_mptcp_get_path_manager(void)
2426 connection_mptcp_path_manager_e pm;
2428 rv = connection_mptcp_get_path_manager(connection, &pm);
2429 if (rv != CONNECTION_ERROR_NONE) {
2430 printf("Failure[%s]\n", test_print_error(rv));
2435 case CONNECTION_MPTCP_PM_DEFAULT:
2436 printf("Path Manager: Default\n");
2438 case CONNECTION_MPTCP_PM_FULLMESH:
2439 printf("Path Manager: FullMesh\n");
2442 printf("Error: Invalid Path Manager\n");
2449 int test_mptcp_set_scheduler(void)
2453 rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
2457 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_DEFAULT);
2460 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
2463 printf("Invalid input!!\n");
2467 if (rv != CONNECTION_ERROR_NONE) {
2468 printf("Failure[%s]\n", test_print_error(rv));
2475 int test_mptcp_get_scheduler(void)
2478 connection_mptcp_scheduler_e scheduler;
2480 rv = connection_mptcp_get_scheduler(connection, &scheduler);
2481 if (rv != CONNECTION_ERROR_NONE) {
2482 printf("Failure[%s]\n", test_print_error(rv));
2486 switch (scheduler) {
2487 case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
2488 printf("Scheduler: Default\n");
2490 case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
2491 printf("Scheduler: RountRobin\n");
2494 printf("Error: Invalid Scheduler\n");
2501 int test_ethernet_eap_connect(void)
2505 bool enabled = false;
2508 char input_str1[130];
2509 char input_str2[130];
2510 connection_profile_h profile;
2512 printf("\n** Choose a ethernet profile to connect. **\n");
2514 if (test_get_user_selected_profile(&profile, true) == false)
2517 test_get_user_int("Input options (0:Use LAN 1:Use EAPoL) :", &input);
2519 if (connection_profile_enable_ethernet_eap(profile, true) != CONNECTION_ERROR_NONE) {
2520 printf("Failed to enable EAP over Ethernet\n");
2524 printf("Disabling EAPoL. Use proper option for normal Lan connection.\n");
2525 if (connection_profile_enable_ethernet_eap(profile, false) != CONNECTION_ERROR_NONE)
2526 printf("Failed to disable EAP over Ethernet\n");
2530 if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE) {
2531 printf("Failed to get ethernet eap enabled status!!\n");
2535 printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2537 printf("Input EAP type:\n");
2538 printf("0 -> CONNECTION_ETHERNET_EAP_TYPE_MD5\n");
2539 printf("1 -> CONNECTION_ETHERNET_EAP_TYPE_PEAP\n");
2540 printf("2 -> CONNECTION_ETHERNET_EAP_TYPE_TLS\n");
2541 printf("3 -> CONNECTION_ETHERNET_EAP_TYPE_TTLS\n");
2542 printf("4 -> CONNECTION_ETHERNET_EAP_TYPE_FAST\n");
2543 rv = scanf("%d", &type);
2546 case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2547 rv = connection_profile_set_ethernet_eap_type(profile, type);
2548 if (rv != CONNECTION_ERROR_NONE) {
2549 printf("Fail to set eap type : %s\n", test_print_error(rv));
2553 printf("Input user name for ethernet:");
2554 rv = scanf("%99s", input_str1);
2556 printf("Input password for ethernet:");
2557 rv = scanf("%99s", input_str2);
2559 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2560 if (rv != CONNECTION_ERROR_NONE) {
2561 printf("Fail to set eap passphrase : %s\n", test_print_error(rv));
2566 case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2568 rv = connection_profile_set_ethernet_eap_type(profile, type);
2569 if (rv != CONNECTION_ERROR_NONE) {
2570 printf("Fail to set eap type : %s\n", test_print_error(rv));
2574 printf("Input user identity for ethernet:");
2575 rv = scanf("%99s", input_str1);
2577 rv = connection_profile_set_ethernet_eap_identity(profile, input_str1);
2578 if (rv != CONNECTION_ERROR_NONE) {
2579 printf("Fail to set eap identity : %s\n", test_print_error(rv));
2583 printf("Input user certificate for ethernet:");
2584 rv = scanf("%129s", input_str1);
2586 rv = connection_profile_set_ethernet_eap_client_cert_file(profile, input_str1);
2587 if (rv != CONNECTION_ERROR_NONE) {
2588 printf("Fail to set eap user cetificate : %s\n", test_print_error(rv));
2592 printf("Input CA certificate for ethernet:");
2593 rv = scanf("%129s", input_str1);
2595 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2596 if (rv != CONNECTION_ERROR_NONE) {
2597 printf("Fail to set eap CA cetificate : %s\n", test_print_error(rv));
2601 printf("Input private key for ethernet:");
2602 rv = scanf("%129s", input_str1);
2604 printf("Input private key password for ethernet:");
2605 rv = scanf("%129s", input_str2);
2607 rv = connection_profile_set_ethernet_eap_private_key_info(profile, input_str1, input_str2);
2608 if (rv != CONNECTION_ERROR_NONE) {
2609 printf("Fail to set eap private key passphrase : %s\n", test_print_error(rv));
2615 case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2617 rv = connection_profile_set_ethernet_eap_type(profile, type);
2618 if (rv != CONNECTION_ERROR_NONE) {
2619 printf("Fail to set eap type : %s\n", test_print_error(rv));
2623 printf("Input anonymous_identity for PEAP ethernet:");
2624 rv = scanf("%99s", input_str1);
2626 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2627 if (rv != CONNECTION_ERROR_NONE) {
2628 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2632 printf("Input CA file for PEAP ethernet:");
2633 rv = scanf("%129s", input_str1);
2635 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2636 if (rv != CONNECTION_ERROR_NONE) {
2637 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2641 int peap_version = 0;
2642 printf("Input peap version[ 0 ~ 2] for PEAP ethernet:");
2643 rv = scanf("%1d", &peap_version);
2645 rv = connection_profile_set_ethernet_eap_peap_version(profile, peap_version);
2646 if (rv != CONNECTION_ERROR_NONE) {
2647 printf("Fail to set eap peap version : %s\n", test_print_error(rv));
2651 printf("Input authentication type[3:MSCHAPV2 4:GTC 5:MD5] for PEAP ethernet:");
2652 rv = scanf("%1d", &auth_type);
2654 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2655 if (rv != CONNECTION_ERROR_NONE) {
2656 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2660 printf("Input username for PEAP ethernet:");
2661 rv = scanf("%129s", input_str1);
2663 printf("Input password for PEAP ethernet:");
2664 rv = scanf("%129s", input_str2);
2666 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2667 if (rv != CONNECTION_ERROR_NONE) {
2668 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2674 case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2676 rv = connection_profile_set_ethernet_eap_type(profile, type);
2677 if (rv != CONNECTION_ERROR_NONE) {
2678 printf("Fail to set eap type : %s\n", test_print_error(rv));
2682 printf("Input anonymous_identity for TTLS ethernet:");
2683 rv = scanf("%99s", input_str1);
2685 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2686 if (rv != CONNECTION_ERROR_NONE) {
2687 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2691 printf("Input CA file for TTLS ethernet:");
2692 rv = scanf("%129s", input_str1);
2694 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2695 if (rv != CONNECTION_ERROR_NONE) {
2696 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2700 printf("Input authentication type[1:PAP, 2:MSCHAP, 3:MSCHAPV2] for TTLS ethernet:");
2701 rv = scanf("%1d", &auth_type);
2703 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2704 if (rv != CONNECTION_ERROR_NONE) {
2705 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2709 printf("Input username for TTLS ethernet:");
2710 rv = scanf("%129s", input_str1);
2712 printf("Input password for TTLS ethernet:");
2713 rv = scanf("%129s", input_str2);
2715 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2716 if (rv != CONNECTION_ERROR_NONE) {
2717 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2723 case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2725 rv = connection_profile_set_ethernet_eap_type(profile, type);
2726 if (rv != CONNECTION_ERROR_NONE) {
2727 printf("Fail to set eap type : %s\n", test_print_error(rv));
2731 printf("Input anonymous_identity for FAST ethernet:");
2732 rv = scanf("%99s", input_str1);
2734 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2735 if (rv != CONNECTION_ERROR_NONE) {
2736 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2740 printf("Input pac file for FAST ethernet:");
2741 rv = scanf("%129s", input_str1);
2743 rv = connection_profile_set_ethernet_eap_pac_file(profile, input_str1);
2744 if (rv != CONNECTION_ERROR_NONE) {
2745 printf("Fail to set eap pac file : %s\n", test_print_error(rv));
2749 printf("Input authentication type[3:MSCHAPV2, 4:GTC] for FAST ethernet:");
2750 rv = scanf("%1d", &auth_type);
2752 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2753 if (rv != CONNECTION_ERROR_NONE) {
2754 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2758 printf("Input username for FAST ethernet:");
2759 rv = scanf("%129s", input_str1);
2761 printf("Input password for FAST ethernet:");
2762 rv = scanf("%129s", input_str2);
2764 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2765 if (rv != CONNECTION_ERROR_NONE) {
2766 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2773 printf("Invalid EAP type\n");
2777 rv = connection_profile_save_ethernet_eap_config(connection, profile);
2778 if (rv != CONNECTION_ERROR_NONE) {
2779 printf("Fail to save eap config : %s\n", test_print_error(rv));
2783 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
2784 printf("Connection open Failed!!\n");
2791 static const char *test_print_eap_type(connection_ethernet_eap_type_e type)
2794 case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2796 case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2798 case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2800 case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2802 case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2809 static const char *test_print_eap_auth_type(connection_ethernet_eap_auth_type_e type)
2812 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_PAP:
2814 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAP:
2816 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2:
2818 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_GTC:
2820 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MD5:
2822 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_NONE:
2829 int test_get_eapol_info(void)
2831 connection_profile_type_e prof_type;
2832 connection_profile_state_e profile_state;
2833 connection_profile_h profile;
2834 char *profile_name = NULL;
2835 connection_ethernet_eap_type_e type;
2836 connection_ethernet_eap_auth_type_e auth_type;
2837 connection_ethernet_eap_peap_version_e peapver;
2840 printf("\n** Choose a ethernet profile to print eapol info. **\n");
2841 if (test_get_user_selected_profile(&profile, true) == false)
2844 bool enabled = false;
2845 if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE) {
2846 printf("Failed to get ethernet eap enabled status!!\n");
2848 printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2850 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
2851 printf("Fail to get profile name\n");
2854 printf("Profile Name : %s\n", profile_name);
2855 g_free(profile_name);
2858 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE) {
2859 printf("Fail to get profile type\n");
2863 if (prof_type != CONNECTION_PROFILE_TYPE_ETHERNET) {
2864 printf("Not ethernet profile\n");
2868 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
2869 printf("Fail to get profile state\n");
2872 printf("Profile State : %s\n", test_print_state(profile_state));
2875 if (connection_profile_get_ethernet_eap_type(profile, &type) != CONNECTION_ERROR_NONE) {
2876 printf("Fail to get eap type\n");
2879 printf("eap_type: %s\n", test_print_eap_type(type));
2882 if (connection_profile_get_ethernet_eap_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2883 printf("Fail to get eap identity\n");
2886 printf("identity: %s\n", str);
2890 if (type == CONNECTION_ETHERNET_EAP_TYPE_MD5)
2893 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2894 type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2895 if (connection_profile_get_ethernet_eap_anonymous_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2896 printf("Fail to get eap anonymous_identity\n");
2899 printf("anonymous_identity: %s\n", str);
2904 if (connection_profile_get_ethernet_eap_ca_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2905 printf("Fail to get eap ca_cert_file\n");
2908 printf("ca_cert_file: %s\n", str);
2912 if (type == CONNECTION_ETHERNET_EAP_TYPE_TLS) {
2913 if (connection_profile_get_ethernet_eap_client_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2914 printf("Fail to get eap client_cert_file\n");
2917 printf("client_cert_file: %s\n", str);
2921 if (connection_profile_get_ethernet_eap_private_key_file(profile, &str) != CONNECTION_ERROR_NONE) {
2922 printf("Fail to get eap private_key_file\n");
2925 printf("private_key_file: %s\n", str);
2930 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2931 type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2932 if (connection_profile_get_ethernet_eap_auth_type(profile, &auth_type) != CONNECTION_ERROR_NONE) {
2933 printf("Fail to get eap auth type\n");
2936 printf("eap_auth: %s\n", test_print_eap_auth_type(auth_type));
2940 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP) {
2941 if (connection_profile_get_ethernet_eap_peap_version(profile, &peapver) != CONNECTION_ERROR_NONE) {
2942 printf("Fail to get eap peap_version\n");
2945 printf("peap_version: %d\n", peapver);
2949 if (type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2950 if (connection_profile_get_ethernet_eap_pac_file(profile, &str) != CONNECTION_ERROR_NONE) {
2951 printf("Fail to get eap pac_file\n");
2954 printf("pac_file: %s\n", str);
2963 int main(int argc, char **argv)
2965 GMainLoop *mainloop;
2966 mainloop = g_main_loop_new(NULL, FALSE);
2968 GIOChannel *channel = g_io_channel_unix_new(0);
2969 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
2971 printf("Test Thread created...\n");
2973 g_main_loop_run(mainloop);
2978 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
2983 memset(a, '\0', 100);
2984 printf("Event received from stdin\n");
2986 rv = read(0, a, 100);
2988 if (rv < 0 || a[0] == '0') {
2989 if (connection != NULL)
2990 test_deregister_client();
2995 if (*a == '\n' || *a == '\r') {
2997 printf("\n\n Network Connection API Test App\n\n");
2998 printf("Options..\n");
2999 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
3000 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
3001 printf("2 - Destroy Handle(unset callbacks automatically)\n");
3002 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
3003 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
3004 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
3005 printf("6 - Get current proxy address \n");
3006 printf("7 - Get current Ip address\n");
3007 printf("8 - Get cellular data call statistics\n");
3008 printf("9 - Get WiFi data call statistics\n");
3009 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
3010 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
3011 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
3012 printf("d - Open connection with profile\n");
3013 printf("e - Get default cellular service by type\n");
3014 printf("f - Set default cellular service by type\n");
3015 printf("g - Close connection with profile\n");
3016 printf("h - Add profile(Cellular and Wifi only)\n");
3017 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
3018 printf("j - Update profile\n");
3019 printf("k - Get profile info\n");
3020 printf("l - Refresh profile info\n");
3021 printf("m - Set state changed callback\n");
3022 printf("n - Unset state changed callback\n");
3023 printf("o - Reset cellular data call statistics\n");
3024 printf("p - Reset WiFi data call statistics\n");
3025 printf("q - Add new route\n");
3026 printf("r - Remove a route\n");
3027 printf("s - Get Bluetooth state\n");
3028 printf("t - Get profile id\n");
3029 printf("u - Reset profile\n");
3030 printf("v - Get all cellular default profiles\n");
3031 printf("w - Get mac address\n");
3032 printf("x - Get ethernet cable state\n");
3033 printf("B - Add IPv6 new route\n");
3034 printf("C - Remove IPv6 route\n");
3035 printf("D - Add new route entry\n");
3036 printf("E - Remove route entry\n");
3037 printf("F - Get all IPv6 address\n");
3038 printf("G - Get metered state\n");
3040 printf(LOG_BLUE "[Extension API]\n" LOG_END);
3041 printf("H - Start TCP Dump\n");
3042 printf("I - Stop TCP Dump\n");
3043 printf("J - Get TCP Dump State\n");
3044 printf("K - Enable MPTCP (internal)\n");
3045 printf("L - Disable MPTCP (internal)\n");
3046 printf("M - Set MPTCP Path Manager (internal)\n");
3047 printf("N - Get MPTCP Path Manager (internal)\n");
3048 printf("O - Set MPTCP Scheduler (internal)\n");
3049 printf("P - Get MPTCP Scheduler (internal)\n");
3050 printf(LOG_GREEN "Q - Create Handle and set callbacks in C# API\n" LOG_END);
3051 printf("R - Destroy Handle(unset callbacks automatically in C# API)\n");
3052 printf("S - Connect Ethernet EAP)\n");
3053 printf("T - Get EAPoL info)\n");
3054 printf(LOG_RED "0 - Exit \n" LOG_END);
3055 printf("ENTER - Show options menu.......\n");
3061 rv = test_register_client();
3064 rv = test_deregister_client();
3067 rv = test_get_network_state();
3070 rv = test_get_cellular_state();
3073 rv = test_get_wifi_state();
3076 rv = test_get_current_proxy();
3079 rv = test_get_current_ip();
3082 rv = test_get_call_statistics_info();
3085 rv = test_get_wifi_call_statistics_info();
3088 rv = test_get_profile_list();
3091 rv = test_get_connected_profile_list();
3094 rv = test_get_current_profile();
3097 rv = test_open_profile();
3100 rv = test_get_default_cellular_service_type();
3103 rv = test_set_default_cellular_service_type();
3106 rv = test_close_profile();
3109 rv = test_add_profile();
3112 rv = test_remove_profile();
3115 rv = test_update_profile();
3118 rv = test_get_profile_info();
3121 rv = test_refresh_profile_info();
3124 rv = test_set_state_changed_callback();
3127 rv = test_unset_state_changed_callback();
3130 rv = test_reset_call_statistics_info();
3133 rv = test_reset_wifi_call_statistics_info();
3136 rv = test_add_route();
3139 rv = test_remove_route();
3142 rv = test_get_bt_state();
3145 rv = test_get_profile_id();
3148 rv = test_reset_profile();
3151 rv = test_get_default_profile_list();
3154 rv = test_get_mac_address();
3157 rv = test_get_ethernet_cable_state();
3160 rv = test_add_route_ipv6();
3163 rv = test_remove_route_ipv6();
3166 rv = test_add_route_entry();
3169 rv = test_remove_route_entry();
3172 rv = test_foreach_ipv6_address();
3175 rv = test_is_metered_network();
3179 rv = test_start_tcpdump();
3182 rv = test_stop_tcpdump();
3185 rv = test_get_tcpdump_state();
3188 rv = test_mptcp_enable();
3191 rv = test_mptcp_disable();
3194 rv = test_mptcp_set_path_manager();
3197 rv = test_mptcp_get_path_manager();
3200 rv = test_mptcp_set_scheduler();
3203 rv = test_mptcp_get_scheduler();
3206 rv = test_register_client_cs();
3209 rv = test_deregister_client_cs();
3212 rv = test_ethernet_eap_connect();
3215 rv = test_get_eapol_info();
3221 printf("Operation succeeded!\n");
3223 printf("Operation failed!\n");