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 home_url - (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 auth_type(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 pdn_type(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 roam_pdn_type(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,};
615 if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
616 rv = connection_profile_set_ip_address(profile,
619 if (rv != CONNECTION_ERROR_NONE)
623 if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
624 rv = connection_profile_set_subnet_mask(profile,
627 if (rv != CONNECTION_ERROR_NONE)
631 if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
632 rv = connection_profile_set_prefix_length(profile,
635 if (rv != CONNECTION_ERROR_NONE)
639 if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
640 rv = connection_profile_set_gateway_address(profile,
643 if (rv != CONNECTION_ERROR_NONE)
647 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
648 " - (Enter for skip) :", &dns_input)) {
650 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
651 rv = connection_profile_set_dns_config_type(
654 CONNECTION_DNS_CONFIG_TYPE_STATIC);
655 if (rv != CONNECTION_ERROR_NONE)
657 if (test_update_dns_info(profile,
658 address_family) == -1)
661 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
662 rv = connection_profile_set_dns_config_type(
665 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
666 if (rv != CONNECTION_ERROR_NONE)
675 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
679 char input_str[100] = {0,};
681 if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
682 " - (Enter for skip) :", &input_int)) {
685 rv = connection_profile_set_proxy_type(profile,
686 CONNECTION_PROXY_TYPE_DIRECT);
688 if (rv != CONNECTION_ERROR_NONE)
693 rv = connection_profile_set_proxy_type(profile,
694 CONNECTION_PROXY_TYPE_AUTO);
697 rv = connection_profile_set_proxy_type(profile,
698 CONNECTION_PROXY_TYPE_MANUAL);
704 if (rv != CONNECTION_ERROR_NONE)
707 if (test_get_user_string("Input auto Proxy URL or Proxy address"
708 " - (Enter for skip) :", input_str, 100)) {
709 rv = connection_profile_set_proxy_address(profile,
712 if (rv != CONNECTION_ERROR_NONE)
724 static int test_update_network_info(connection_profile_h profile)
729 int address_family = 0;
731 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
733 if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
734 " - (Enter for skip) :", &input_int)) {
737 rv = connection_profile_set_ip_config_type(profile,
739 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
740 if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
741 " - (Enter for skip) :", &dns_input)) {
743 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
744 rv = connection_profile_set_dns_config_type(
747 CONNECTION_DNS_CONFIG_TYPE_STATIC);
748 if (rv != CONNECTION_ERROR_NONE)
750 if (test_update_dns_info(profile,
751 address_family) == -1)
754 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
755 rv = connection_profile_set_dns_config_type(
758 CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
759 if (rv != CONNECTION_ERROR_NONE)
766 rv = connection_profile_set_ip_config_type(profile,
768 CONNECTION_IP_CONFIG_TYPE_STATIC);
769 if (rv != CONNECTION_ERROR_NONE)
772 if (test_update_ip_info(profile, address_family) == -1)
775 if (test_update_proxy_info(profile, address_family) == -1)
779 rv = connection_profile_set_ip_config_type(profile,
781 CONNECTION_IP_CONFIG_TYPE_AUTO);
787 if (rv != CONNECTION_ERROR_NONE)
795 static void test_print_cellular_info(connection_profile_h profile)
797 connection_cellular_service_type_e service_type;
798 connection_cellular_pdn_type_e pdn_type;
799 connection_cellular_pdn_type_e roam_pdn_type;
801 connection_cellular_auth_type_e auth_type;
802 char *user_name = NULL;
803 char *password = NULL;
804 char *home_url = NULL;
805 bool roaming = false;
807 bool editable = false;
809 if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
810 printf("Fail to get cellular service type!\n");
812 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
814 if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
815 printf("Fail to get cellular pdn type!\n");
817 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
819 if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
820 printf("Fail to get cellular roam pdn type!\n");
822 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
824 if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
825 printf("Fail to get cellular APN!\n");
827 printf("Cellular APN : %s\n", apn);
831 if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
832 printf("Fail to get auth info!\n");
834 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
835 printf("Cellular user_name : %s\n", user_name);
836 printf("Cellular password : %s\n", password);
841 if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
842 printf("Fail to get cellular home url!\n");
844 printf("Cellular home url : %s\n", home_url);
848 if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
849 printf("Fail to get cellular roaming state!\n");
851 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
853 if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
854 printf("Fail to get cellular hidden state!\n");
856 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
858 if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
859 printf("Fail to get cellular editing state!\n");
861 printf("Cellular editable : %s\n", editable ? "true" : "false");
864 static void test_print_wifi_info(connection_profile_h profile)
871 connection_wifi_security_type_e security_type;
872 connection_wifi_encryption_type_e encryption_type;
873 bool pass_required = false;
874 bool wps_supported = false;
876 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
877 printf("Fail to get Wi-Fi essid!\n");
879 printf("Wi-Fi essid : %s\n", essid);
883 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
884 printf("Fail to get Wi-Fi bssid!\n");
886 printf("Wi-Fi bssid : %s\n", bssid);
890 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
891 printf("Fail to get Wi-Fi rssi!\n");
893 printf("Wi-Fi rssi : %d\n", rssi);
895 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
896 printf("Fail to get Wi-Fi frequency!\n");
898 printf("Wi-Fi frequency : %d\n", frequency);
900 if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
901 printf("Fail to get Wi-Fi max speed!\n");
903 printf("Wi-Fi max speed : %d\n", max_speed);
905 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
906 printf("Fail to get Wi-Fi security type!\n");
908 printf("Wi-Fi security type : %s\n", test_print_wifi_security_type(security_type));
910 if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
911 printf("Fail to get Wi-Fi encryption type!\n");
913 printf("Wi-Fi encryption type : %d\n", encryption_type);
915 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
916 printf("Fail to get Wi-Fi passphrase required!\n");
918 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
920 if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
921 printf("Fail to get Wi-Fi wps info\n");
923 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
926 static void test_print_mesh_info(connection_profile_h profile)
932 connection_wifi_security_type_e security_type;
933 bool pass_required = false;
935 if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
936 printf("Fail to get Mesh essid!\n");
938 printf("Mesh essid : %s\n", essid);
942 if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
943 printf("Fail to get Mesh bssid!\n");
945 printf("Mesh bssid : %s\n", bssid);
949 if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
950 printf("Fail to get Mesh rssi!\n");
952 printf("Mesh rssi : %d\n", rssi);
954 if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
955 printf("Fail to get Mesh frequency!\n");
957 printf("Mesh frequency : %d\n", frequency);
959 if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
960 printf("Fail to get Mesh security type!\n");
962 printf("Mesh security type : %s\n", test_print_wifi_security_type(security_type));
964 if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
965 printf("Fail to get Mesh passphrase required!\n");
967 printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
970 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
972 char *interface_name = NULL;
975 char *gateway = NULL;
976 char *dhcp_server = NULL;
977 int dhcp_lease_duration = 0;
982 connection_ip_config_type_e ip_type;
983 connection_proxy_type_e proxy_type;
984 connection_dns_config_type_e dns_type;
986 if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
987 printf("Fail to get interface name!\n");
989 printf("Interface name : %s\n", interface_name);
990 g_free(interface_name);
993 if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
994 printf("Fail to get ipconfig type!\n");
996 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
997 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
998 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
999 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
1000 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
1001 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
1002 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
1003 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
1005 printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
1008 if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
1009 printf("Fail to get IP address!\n");
1011 printf("IP address : %s\n", ip);
1015 if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
1016 printf("Fail to get gateway!\n");
1018 printf("Gateway : %s\n", gateway);
1022 if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
1023 printf("Fail to get DHCP Server address!\n");
1025 printf("DHCP Server : %s\n", dhcp_server);
1026 g_free(dhcp_server);
1029 if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
1030 printf("Fail to get DHCP lease duration!\n");
1032 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
1035 if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
1036 printf("Fail to get subnet mask!\n");
1038 printf("Subnet mask : %s\n", subnet);
1042 if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
1043 printf("Fail to get prefix length!\n");
1045 printf("Prefix length : %d\n", prefix_len);
1047 if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
1048 printf("Fail to get DNS configuration type!\n");
1050 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
1051 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
1052 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
1053 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
1055 printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
1058 if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
1059 printf("Fail to get DNS1!\n");
1061 printf("DNS1 : %s\n", dns1);
1065 if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
1066 printf("Fail to get DNS2!\n");
1068 printf("DNS2 : %s\n", dns2);
1072 if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
1073 printf("Fail to get proxy type!\n");
1075 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
1076 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
1077 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
1078 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
1080 printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
1083 if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
1084 printf("Fail to get proxy!\n");
1086 printf("Proxy : %s\n", proxy);
1091 int test_register_client(void)
1094 int err = connection_create(&connection);
1096 if (CONNECTION_ERROR_NONE == err) {
1097 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1098 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1099 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1100 connection_set_ethernet_cable_state_changed_cb(connection,
1101 test_get_ethernet_cable_state_callback, NULL);
1102 connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
1104 printf("Client registration failed [%s]\n", test_print_error(err));
1108 printf("Client registration success\n");
1112 int test_deregister_client(void)
1116 connection_profile_h profile;
1118 if (connection != NULL)
1119 rv = connection_destroy(connection);
1121 printf("Cannot deregister : Handle is NULL\n");
1122 rv = CONNECTION_ERROR_INVALID_OPERATION;
1125 if (rv != CONNECTION_ERROR_NONE) {
1126 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1130 if (state_cb_list) {
1131 for (list = state_cb_list; list; list = list->next) {
1132 profile = list->data;
1133 connection_profile_destroy(profile);
1136 g_slist_free(state_cb_list);
1137 state_cb_list = NULL;
1141 printf("Client deregistration success\n");
1146 int test_register_client_cs(void)
1149 test_get_user_int("Input a TID in C# API :", &tid);
1151 int err = connection_create_cs(tid, &connection);
1153 if (CONNECTION_ERROR_NONE == err) {
1154 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1155 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1156 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1157 connection_set_ethernet_cable_state_changed_cb(connection,
1158 test_get_ethernet_cable_state_callback, NULL);
1160 printf("Client registration failed [%s]\n", test_print_error(err));
1164 printf("Client registration success\n");
1168 int test_deregister_client_cs(void)
1172 connection_profile_h profile;
1175 test_get_user_int("Input a TID in C# API :", &tid);
1177 if (connection != NULL)
1178 rv = connection_destroy_cs(tid, connection);
1180 printf("Cannot deregister : Handle is NULL\n");
1181 rv = CONNECTION_ERROR_INVALID_OPERATION;
1184 if (rv != CONNECTION_ERROR_NONE) {
1185 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1189 if (state_cb_list) {
1190 for (list = state_cb_list; list; list = list->next) {
1191 profile = list->data;
1192 connection_profile_destroy(profile);
1195 g_slist_free(state_cb_list);
1196 state_cb_list = NULL;
1200 printf("Client deregistration success\n");
1205 int test_get_network_state(void)
1208 connection_type_e net_state;
1210 rv = connection_get_type(connection, &net_state);
1212 if (rv != CONNECTION_ERROR_NONE) {
1213 printf("Fail to get network state [%s]\n", test_print_error(rv));
1217 printf("Retval = [%s] network connection state [%s]\n",
1218 test_print_error(rv), test_print_connection_type(net_state));
1223 int test_get_cellular_state(void)
1226 connection_cellular_state_e cellular_state;
1228 rv = connection_get_cellular_state(connection, &cellular_state);
1230 if (rv != CONNECTION_ERROR_NONE) {
1231 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1235 printf("Retval = [%s] Cellular state [%s]\n",
1236 test_print_error(rv), test_print_cellular_state(cellular_state));
1241 int test_get_wifi_state(void)
1244 connection_wifi_state_e wifi_state;
1246 rv = connection_get_wifi_state(connection, &wifi_state);
1248 if (rv != CONNECTION_ERROR_NONE) {
1249 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1253 printf("Retval = [%s] WiFi state [%s]\n",
1254 test_print_error(rv), test_print_wifi_state(wifi_state));
1259 int test_get_current_proxy(void)
1261 char *proxy_addr = NULL;
1263 connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1265 if (proxy_addr == NULL) {
1266 printf("Proxy address does not exist\n");
1270 printf("Current Proxy [%s]\n", proxy_addr);
1276 int test_get_current_ip(void)
1278 char *ip_addr = NULL;
1282 rv = test_get_user_int("Input Address type to get"
1283 "(1:IPV4, 2:IPV6):", &input);
1286 printf("Invalid input!!\n");
1292 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1293 if (ip_addr == NULL) {
1294 printf("IPv4 address does not exist\n");
1297 printf("IPv4 address : %s\n", ip_addr);
1301 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1302 if (ip_addr == NULL) {
1303 printf("IPv6 address does not exist\n");
1306 printf("IPv6 address : %s\n", ip_addr);
1309 printf("Wrong IP address family!!\n");
1317 int test_get_call_statistics_info(void)
1321 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1322 printf("last recv data size [%lld]\n", rv);
1323 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1324 printf("last sent data size [%lld]\n", rv);
1325 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1326 printf("total received data size [%lld]\n", rv);
1327 connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1328 printf("total sent data size [%lld]\n", rv);
1333 int test_get_wifi_call_statistics_info(void)
1337 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1338 printf("WiFi last recv data size [%lld]\n", rv);
1339 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1340 printf("WiFi last sent data size [%lld]\n", rv);
1341 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1342 printf("WiFi total received data size [%lld]\n", rv);
1343 connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1344 printf("WiFi total sent data size [%lld]\n", rv);
1349 int test_get_profile_list(void)
1351 if (test_get_user_selected_profile(NULL, false) == false)
1357 int test_get_default_profile_list(void)
1360 char *profile_name = NULL;
1361 connection_profile_iterator_h profile_iter;
1362 connection_profile_h profile_h;
1363 connection_cellular_service_type_e service_type;
1364 bool is_default = false;
1366 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1367 if (rv != CONNECTION_ERROR_NONE) {
1368 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1372 while (connection_profile_iterator_has_next(profile_iter)) {
1373 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1374 printf("Fail to get profile handle\n");
1378 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1379 printf("Fail to get profile name\n");
1382 printf("profile name : %s\n", profile_name);
1383 g_free(profile_name);
1385 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1386 printf("Fail to get profile service type\n");
1389 printf("service type : %d\n", service_type);
1391 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1392 printf("Fail to get profile subscriber id\n");
1395 printf("Default : %d\n", is_default);
1401 int test_get_connected_profile_list(void)
1404 char *profile_name = NULL;
1405 connection_profile_iterator_h profile_iter;
1406 connection_profile_h profile_h;
1407 bool is_default = false;
1408 connection_profile_type_e type;
1410 rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1411 if (rv != CONNECTION_ERROR_NONE) {
1412 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1416 while (connection_profile_iterator_has_next(profile_iter)) {
1417 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1418 printf("Fail to get profile handle\n");
1422 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1423 printf("Fail to get profile name\n");
1426 printf("profile name is %s\n", profile_name);
1427 g_free(profile_name);
1429 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1430 printf("Fail to get profile type\n");
1433 printf("profile type is %d\n", type);
1435 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1436 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1437 printf("Fail to get profile is default\n");
1440 printf("[%s]\n", is_default ? "default" : "not default");
1447 int test_get_current_profile(void)
1450 char *profile_name = NULL;
1451 connection_profile_h profile_h;
1453 rv = connection_get_current_profile(connection, &profile_h);
1454 if (rv != CONNECTION_ERROR_NONE) {
1455 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1459 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1460 printf("Fail to get profile name\n");
1463 printf("profile name : %s\n", profile_name);
1464 g_free(profile_name);
1466 connection_profile_destroy(profile_h);
1471 int test_open_profile(void)
1473 connection_profile_h profile;
1475 printf("\n** Choose a profile to open. **\n");
1477 if (test_get_user_selected_profile(&profile, true) == false)
1480 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1481 printf("Connection open Failed!!\n");
1488 int test_get_default_cellular_service_type(void)
1493 connection_profile_h profile;
1494 char *profile_name = NULL;
1496 rv = test_get_user_int("Input profile type to get"
1497 "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1500 printf("Invalid input!!\n");
1506 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1509 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1512 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1515 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1518 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1521 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1524 printf("Wrong number!!\n");
1528 if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1531 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1532 printf("Fail to get profile name\n");
1533 connection_profile_destroy(profile);
1536 printf("Default profile name : %s\n", profile_name);
1537 g_free(profile_name);
1539 connection_profile_destroy(profile);
1544 int test_set_default_cellular_service_type(void)
1546 connection_profile_h profile;
1547 connection_cellular_service_type_e type;
1550 rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1552 if (rv == false || (input != 1 && input != 2)) {
1553 printf("Invalid input!!\n");
1557 printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1559 if (test_get_user_selected_profile(&profile, true) == false)
1562 if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1563 printf("Fail to get cellular service type\n");
1568 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1571 if (connection_set_default_cellular_service_profile_async(connection,
1572 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1579 int test_close_profile(void)
1581 connection_profile_h profile;
1583 printf("\n** Choose a profile to close. **\n");
1585 if (test_get_user_selected_profile(&profile, true) == false)
1588 if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1589 printf("Connection close Failed!!\n");
1596 int test_add_profile(void)
1599 connection_profile_h profile;
1600 char input_str[100] = {0,};
1602 if (test_get_user_string("Input keyword - (Enter for skip) :", input_str, 100) == false)
1605 g_strstrip(input_str);
1606 rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1607 if (rv != CONNECTION_ERROR_NONE)
1608 RETURN_FAIL_DESTROY(profile);
1610 if (test_update_cellular_info(profile) == -1)
1611 RETURN_FAIL_DESTROY(profile);
1613 rv = connection_add_profile(connection, profile);
1614 if (rv != CONNECTION_ERROR_NONE)
1615 RETURN_FAIL_DESTROY(profile);
1617 connection_profile_destroy(profile);
1621 int test_remove_profile(void)
1623 connection_profile_h profile;
1625 printf("\n** Choose a profile to remove. **\n");
1626 if (test_get_user_selected_profile(&profile, true) == false)
1629 if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1630 printf("Remove profile Failed!!\n");
1637 int test_update_profile(void)
1641 connection_profile_type_e prof_type;
1642 connection_profile_h profile;
1644 printf("\n** Choose a profile to update. **\n");
1645 if (test_get_user_selected_profile(&profile, true) == false)
1648 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1651 switch (prof_type) {
1652 case CONNECTION_PROFILE_TYPE_CELLULAR:
1653 if (test_update_cellular_info(profile) == -1)
1657 case CONNECTION_PROFILE_TYPE_WIFI:
1658 if (test_update_wifi_info(profile) == -1)
1661 if (test_update_network_info(profile) == -1)
1665 case CONNECTION_PROFILE_TYPE_ETHERNET:
1666 if (test_update_network_info(profile) == -1)
1670 case CONNECTION_PROFILE_TYPE_BT:
1671 printf("Not supported!\n");
1675 int profile_type = prof_type;
1676 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1677 if (test_update_wifi_info(profile) == -1)
1685 rv = connection_update_profile(connection, profile);
1686 if (rv != CONNECTION_ERROR_NONE)
1692 int test_get_profile_info(void)
1694 connection_profile_type_e prof_type;
1695 connection_profile_state_e profile_state;
1696 connection_profile_state_e profile_ipv6_state;
1697 connection_internet_state_e internet_state;
1698 connection_profile_h profile;
1699 char *profile_name = NULL;
1700 int address_family = 0;
1702 printf("\n** Choose a profile to print. **\n");
1703 if (test_get_user_selected_profile(&profile, true) == false)
1706 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1707 printf("Fail to get profile name\n");
1710 printf("Profile Name : %s\n", profile_name);
1711 g_free(profile_name);
1714 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1715 printf("Fail to get profile IPv4 state\n");
1718 printf("Profile State : %s\n", test_print_state(profile_state));
1720 if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1721 printf("Fail to get profile IPv6 state\n");
1724 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1726 if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
1727 printf("Fail to get Internet state\n");
1730 printf("Internet State : %s\n", test_print_internet_state(internet_state));
1732 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1735 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1737 switch (prof_type) {
1738 case CONNECTION_PROFILE_TYPE_CELLULAR:
1739 printf("Profile Type : Cellular\n");
1740 test_print_cellular_info(profile);
1742 case CONNECTION_PROFILE_TYPE_WIFI:
1743 printf("Profile Type : Wi-Fi\n");
1744 test_print_wifi_info(profile);
1746 case CONNECTION_PROFILE_TYPE_ETHERNET:
1747 printf("Profile Type : Ethernet\n");
1749 case CONNECTION_PROFILE_TYPE_BT:
1750 printf("Profile Type : bluetooth\n");
1754 int profile_type = prof_type;
1755 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1756 printf("Profile Type : Mesh\n");
1757 test_print_mesh_info(profile);
1764 test_print_network_info(profile, address_family);
1769 int test_refresh_profile_info(void)
1771 connection_profile_type_e prof_type;
1772 connection_profile_state_e profile_state;
1773 connection_profile_h profile;
1774 char *profile_name = NULL;
1775 int address_family = 0;
1777 printf("\n** Choose a profile to refresh. **\n");
1778 if (test_get_user_selected_profile(&profile, true) == false)
1781 if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1784 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1785 printf("Fail to get profile name\n");
1788 printf("Profile Name : %s\n", profile_name);
1789 g_free(profile_name);
1792 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1793 printf("Fail to get profile state\n");
1796 printf("Profile State : %s\n", test_print_state(profile_state));
1799 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1802 test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1804 switch (prof_type) {
1805 case CONNECTION_PROFILE_TYPE_CELLULAR:
1806 printf("Profile Type : Cellular\n");
1807 test_print_cellular_info(profile);
1809 case CONNECTION_PROFILE_TYPE_WIFI:
1810 printf("Profile Type : Wi-Fi\n");
1811 test_print_wifi_info(profile);
1813 case CONNECTION_PROFILE_TYPE_ETHERNET:
1814 printf("Profile Type : Ethernet\n");
1816 case CONNECTION_PROFILE_TYPE_BT:
1817 printf("Profile Type : bluetooth\n");
1821 int profile_type = prof_type;
1822 if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1823 printf("Profile Type : Mesh\n");
1824 test_print_mesh_info(profile);
1831 test_print_network_info(profile, address_family);
1836 int test_set_state_changed_callback()
1838 connection_profile_h profile;
1839 connection_profile_h profile_clone;
1841 printf("\n** Choose a profile to set callback. **\n");
1842 if (test_get_user_selected_profile(&profile, true) == false)
1845 if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1848 if (connection_profile_set_state_changed_cb(profile,
1849 test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1850 connection_profile_destroy(profile_clone);
1854 state_cb_list = g_slist_append(state_cb_list, profile_clone);
1859 int test_unset_state_changed_callback()
1861 connection_profile_h profile;
1863 char *profile_name = NULL;
1867 printf("\n** Choose a profile to unset callback. **\n");
1868 for (list = state_cb_list; list; list = list->next) {
1869 profile = list->data;
1870 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1871 printf("Fail to get profile name!\n");
1874 printf("%d. %s\n", count, profile_name);
1875 g_free(profile_name);
1881 if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1884 printf("Wrong number!!\n");
1889 for (list = state_cb_list; list; list = list->next) {
1890 if (count == input) {
1891 profile = list->data;
1901 if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1904 state_cb_list = g_slist_remove(state_cb_list, profile);
1905 connection_profile_destroy(profile);
1910 int test_reset_call_statistics_info(void)
1912 int ret = CONNECTION_ERROR_NONE;
1914 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1915 printf("reset last recv data size [%d]\n", ret);
1916 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1917 printf("last sent data size [%d]\n", ret);
1918 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1919 printf("total received data size [%d]\n", ret);
1920 ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1921 printf("total sent data size [%d]\n", ret);
1926 int test_reset_wifi_call_statistics_info(void)
1928 int ret = CONNECTION_ERROR_NONE;
1930 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1931 printf("WiFi last sent data size [%d]\n", ret);
1932 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1933 printf("WiFi last recv data size [%d]\n", ret);
1934 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1935 printf("WiFi total sent data size [%d]\n", ret);
1936 ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1937 printf("WiFi total received data size [%d]\n", ret);
1942 int test_add_route(void)
1945 char ip_addr[100] = {0};
1946 char if_name[40] = {0};
1948 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1951 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1954 g_strstrip(ip_addr);
1955 g_strstrip(if_name);
1956 rv = connection_add_route(connection, if_name, ip_addr);
1957 if (rv != CONNECTION_ERROR_NONE) {
1958 printf("Fail to get add new route [%d]\n", rv);
1961 printf("Add Route successfully\n");
1966 int test_remove_route(void)
1969 char ip_addr[100] = {0};
1970 char if_name[40] = {0};
1972 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1975 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1978 g_strstrip(ip_addr);
1979 g_strstrip(if_name);
1980 rv = connection_remove_route(connection, if_name, ip_addr);
1981 if (rv != CONNECTION_ERROR_NONE) {
1982 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1985 printf("Remove Route successfully\n");
1990 int test_add_route_ipv6(void)
1993 char ip_addr[100] = {0};
1994 char gateway[100] = {0};
1995 char if_name[40] = {0};
1997 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
2000 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2003 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2006 g_strstrip(ip_addr);
2007 g_strstrip(gateway);
2008 g_strstrip(if_name);
2009 rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
2010 if (rv != CONNECTION_ERROR_NONE) {
2011 printf("Fail to get add new route [%d]\n", rv);
2014 printf("Add Route successfully\n");
2019 int test_remove_route_ipv6(void)
2022 char ip_addr[100] = {0};
2023 char gateway[100] = {0};
2024 char if_name[40] = {0};
2026 if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
2029 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2032 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2035 g_strstrip(ip_addr);
2036 g_strstrip(gateway);
2037 g_strstrip(if_name);
2038 rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
2039 if (rv != CONNECTION_ERROR_NONE) {
2040 printf("Fail to remove the route [%d]\n", rv);
2043 printf("Remove Route successfully\n");
2048 int test_add_route_entry(void)
2050 char ip_addr[100] = {0};
2051 char gateway[100] = {0};
2052 char if_name[40] = {0};
2057 input_rv = test_get_user_int("Input Address type to get"
2058 "(1:IPV4, 2:IPV6):", &input);
2060 if (input_rv == false) {
2061 printf("Invalid input!!\n");
2067 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2070 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2073 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2076 g_strstrip(ip_addr);
2077 g_strstrip(gateway);
2078 g_strstrip(if_name);
2079 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2080 if (rv != CONNECTION_ERROR_NONE) {
2081 printf("Fail to get add new route [%d]\n", rv);
2084 printf("Add Route successfully\n");
2088 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2091 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2094 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2097 g_strstrip(ip_addr);
2098 g_strstrip(gateway);
2099 g_strstrip(if_name);
2100 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2101 if (rv != CONNECTION_ERROR_NONE) {
2102 printf("Fail to get add new route [%d]\n", rv);
2105 printf("Add Route successfully\n");
2109 printf("Wrong IP address family!!\n");
2118 int test_remove_route_entry(void)
2120 char ip_addr[100] = {0};
2121 char gateway[100] = {0};
2122 char if_name[40] = {0};
2127 input_rv = test_get_user_int("Input Address type to get"
2128 "(1:IPV4, 2:IPV6):", &input);
2130 if (input_rv == false) {
2131 printf("Invalid input!!\n");
2137 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2140 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2143 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2146 g_strstrip(ip_addr);
2147 g_strstrip(gateway);
2148 g_strstrip(if_name);
2149 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2150 if (rv != CONNECTION_ERROR_NONE) {
2151 printf("Fail to remove the route [%s]\n", test_print_error(rv));
2154 printf("Remove Route successfully\n");
2159 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2162 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2165 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2168 g_strstrip(ip_addr);
2169 g_strstrip(gateway);
2170 g_strstrip(if_name);
2171 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2172 if (rv != CONNECTION_ERROR_NONE) {
2173 printf("Fail to remove the route [%d]\n", rv);
2176 printf("Remove Route successfully\n");
2180 printf("Wrong IP address family!!\n");
2189 int test_get_bt_state(void)
2192 connection_bt_state_e bt_state;
2194 rv = connection_get_bt_state(connection, &bt_state);
2196 if (rv != CONNECTION_ERROR_NONE) {
2197 printf("Fail to get bluetooth state [%s]\n", test_print_error(rv));
2201 printf("Retval = [%s], bluetooth state [%d]\n", test_print_error(rv), bt_state);
2206 int test_get_profile_id(void)
2208 connection_profile_h profile;
2211 printf("\n** Choose a profile to see profile id. **\n");
2212 if (test_get_user_selected_profile(&profile, true) == false)
2215 if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2216 printf("Fail to get profile name\n");
2219 printf("Profile id : %s\n", profile_id);
2226 int test_get_mac_address(void)
2228 int rv = 0, type = 0;
2229 connection_type_e conn_type;
2230 char *mac_addr = NULL;
2232 test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2236 conn_type = CONNECTION_TYPE_WIFI;
2239 conn_type = CONNECTION_TYPE_ETHERNET;
2242 printf("Wrong number!!\n");
2246 rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2248 if (rv != CONNECTION_ERROR_NONE) {
2249 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2253 printf("mac address is %s\n", mac_addr);
2260 int test_get_ethernet_cable_state(void)
2263 connection_ethernet_cable_state_e cable_state;
2265 rv = connection_get_ethernet_cable_state(connection, &cable_state);
2267 if (rv != CONNECTION_ERROR_NONE) {
2268 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2272 printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2277 int test_reset_profile(void)
2279 int type, sim_id, rv;
2281 rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2283 if (rv == false || (type != 0 && type != 1)) {
2284 printf("Invalid input!!\n");
2288 rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2290 if (rv == false || (sim_id != 0 && sim_id != 1)) {
2291 printf("Invalid input!!\n");
2295 if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2301 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2303 printf("IPv6 Address : %s\n", ipv6_address);
2307 int test_foreach_ipv6_address(void)
2311 connection_type_e conn_type;
2313 test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2317 conn_type = CONNECTION_TYPE_WIFI;
2320 conn_type = CONNECTION_TYPE_ETHERNET;
2323 printf("Wrong number!!\n");
2327 rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2328 if (rv != CONNECTION_ERROR_NONE) {
2329 printf("Fail to get IPv6 address\n");
2336 int test_is_metered_network(void)
2341 rv = connection_is_metered_network(connection, &metered_state);
2343 if (rv != CONNECTION_ERROR_NONE) {
2344 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2348 printf("Retval = [%s] metered state [%s]\n",
2349 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2354 int test_start_tcpdump(void)
2356 if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2360 printf("Successfully started tcpdump\n");
2365 int test_stop_tcpdump(void)
2367 if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2371 printf("Successfully stopped tcpdump\n");
2376 int test_get_tcpdump_state(void)
2378 gboolean tcpdump_state = FALSE;
2380 if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
2384 printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2389 int test_mptcp_enable(void)
2392 bool supported = false;
2393 rv = connection_mptcp_is_supported(connection, &supported);
2394 if (rv != CONNECTION_ERROR_NONE) {
2395 printf("Failure[%s]\n", test_print_error(rv));
2398 printf("MPTCP Support: %d\n", supported);
2400 rv = connection_mptcp_enable(connection, CONNECTION_MPTCP_ENABLE_ALL);
2401 if (rv != CONNECTION_ERROR_NONE) {
2402 printf("Failure[%s]\n", test_print_error(rv));
2408 int test_mptcp_disable(void)
2411 rv = connection_mptcp_disable(connection);
2413 if (rv != CONNECTION_ERROR_NONE) {
2414 printf("Failure[%s]\n", test_print_error(rv));
2420 int test_mptcp_set_path_manager(void)
2424 rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
2428 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_DEFAULT);
2431 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_FULLMESH);
2434 printf("Invalid input!!\n");
2438 if (rv != CONNECTION_ERROR_NONE) {
2439 printf("Failure[%s]\n", test_print_error(rv));
2446 int test_mptcp_get_path_manager(void)
2449 connection_mptcp_path_manager_e pm;
2451 rv = connection_mptcp_get_path_manager(connection, &pm);
2452 if (rv != CONNECTION_ERROR_NONE) {
2453 printf("Failure[%s]\n", test_print_error(rv));
2458 case CONNECTION_MPTCP_PM_DEFAULT:
2459 printf("Path Manager: Default\n");
2461 case CONNECTION_MPTCP_PM_FULLMESH:
2462 printf("Path Manager: FullMesh\n");
2465 printf("Error: Invalid Path Manager\n");
2472 int test_mptcp_set_scheduler(void)
2476 rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
2480 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_DEFAULT);
2483 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
2486 printf("Invalid input!!\n");
2490 if (rv != CONNECTION_ERROR_NONE) {
2491 printf("Failure[%s]\n", test_print_error(rv));
2498 int test_mptcp_get_scheduler(void)
2501 connection_mptcp_scheduler_e scheduler;
2503 rv = connection_mptcp_get_scheduler(connection, &scheduler);
2504 if (rv != CONNECTION_ERROR_NONE) {
2505 printf("Failure[%s]\n", test_print_error(rv));
2509 switch (scheduler) {
2510 case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
2511 printf("Scheduler: Default\n");
2513 case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
2514 printf("Scheduler: RountRobin\n");
2517 printf("Error: Invalid Scheduler\n");
2524 int test_ethernet_eap_connect(void)
2528 bool enabled = false;
2531 char input_str1[130];
2532 char input_str2[130];
2533 connection_profile_h profile;
2535 printf("\n** Choose a ethernet profile to connect. **\n");
2537 if (test_get_user_selected_profile(&profile, true) == false)
2540 test_get_user_int("Input options (0:Use LAN 1:Use EAPoL) :", &input);
2542 if (connection_profile_enable_ethernet_eap(profile, true) != CONNECTION_ERROR_NONE) {
2543 printf("Failed to enable EAP over Ethernet\n");
2547 printf("Disabling EAPoL. Use proper option for normal Lan connection.\n");
2548 if (connection_profile_enable_ethernet_eap(profile, false) != CONNECTION_ERROR_NONE)
2549 printf("Failed to disable EAP over Ethernet\n");
2553 if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE) {
2554 printf("Failed to get ethernet eap enabled status!!\n");
2558 printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2560 printf("Input EAP type:\n");
2561 printf("0 -> CONNECTION_ETHERNET_EAP_TYPE_MD5\n");
2562 printf("1 -> CONNECTION_ETHERNET_EAP_TYPE_PEAP\n");
2563 printf("2 -> CONNECTION_ETHERNET_EAP_TYPE_TLS\n");
2564 printf("3 -> CONNECTION_ETHERNET_EAP_TYPE_TTLS\n");
2565 printf("4 -> CONNECTION_ETHERNET_EAP_TYPE_FAST\n");
2566 rv = scanf("%d", &type);
2569 case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2570 rv = connection_profile_set_ethernet_eap_type(profile, type);
2571 if (rv != CONNECTION_ERROR_NONE) {
2572 printf("Fail to set eap type : %s\n", test_print_error(rv));
2576 printf("Input user name for ethernet:");
2577 rv = scanf("%99s", input_str1);
2579 printf("Input password for ethernet:");
2580 rv = scanf("%99s", input_str2);
2582 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2583 if (rv != CONNECTION_ERROR_NONE) {
2584 printf("Fail to set eap passphrase : %s\n", test_print_error(rv));
2589 case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2591 rv = connection_profile_set_ethernet_eap_type(profile, type);
2592 if (rv != CONNECTION_ERROR_NONE) {
2593 printf("Fail to set eap type : %s\n", test_print_error(rv));
2597 printf("Input user identity for ethernet:");
2598 rv = scanf("%99s", input_str1);
2600 rv = connection_profile_set_ethernet_eap_identity(profile, input_str1);
2601 if (rv != CONNECTION_ERROR_NONE) {
2602 printf("Fail to set eap identity : %s\n", test_print_error(rv));
2606 printf("Input user certificate for ethernet:");
2607 rv = scanf("%129s", input_str1);
2609 rv = connection_profile_set_ethernet_eap_client_cert_file(profile, input_str1);
2610 if (rv != CONNECTION_ERROR_NONE) {
2611 printf("Fail to set eap user cetificate : %s\n", test_print_error(rv));
2615 printf("Input CA certificate for ethernet:");
2616 rv = scanf("%129s", input_str1);
2618 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2619 if (rv != CONNECTION_ERROR_NONE) {
2620 printf("Fail to set eap CA cetificate : %s\n", test_print_error(rv));
2624 printf("Input private key for ethernet:");
2625 rv = scanf("%129s", input_str1);
2627 printf("Input private key password for ethernet:");
2628 rv = scanf("%129s", input_str2);
2630 rv = connection_profile_set_ethernet_eap_private_key_info(profile, input_str1, input_str2);
2631 if (rv != CONNECTION_ERROR_NONE) {
2632 printf("Fail to set eap private key passphrase : %s\n", test_print_error(rv));
2638 case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2640 rv = connection_profile_set_ethernet_eap_type(profile, type);
2641 if (rv != CONNECTION_ERROR_NONE) {
2642 printf("Fail to set eap type : %s\n", test_print_error(rv));
2646 printf("Input anonymous_identity for PEAP ethernet:");
2647 rv = scanf("%99s", input_str1);
2649 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2650 if (rv != CONNECTION_ERROR_NONE) {
2651 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2655 printf("Input CA file for PEAP ethernet:");
2656 rv = scanf("%129s", input_str1);
2658 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2659 if (rv != CONNECTION_ERROR_NONE) {
2660 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2664 int peap_version = 0;
2665 printf("Input peap version[ 0 ~ 2] for PEAP ethernet:");
2666 rv = scanf("%1d", &peap_version);
2668 rv = connection_profile_set_ethernet_eap_peap_version(profile, peap_version);
2669 if (rv != CONNECTION_ERROR_NONE) {
2670 printf("Fail to set eap peap version : %s\n", test_print_error(rv));
2674 printf("Input authentication type[3:MSCHAPV2 4:GTC 5:MD5] for PEAP ethernet:");
2675 rv = scanf("%1d", &auth_type);
2677 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2678 if (rv != CONNECTION_ERROR_NONE) {
2679 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2683 printf("Input username for PEAP ethernet:");
2684 rv = scanf("%129s", input_str1);
2686 printf("Input password for PEAP ethernet:");
2687 rv = scanf("%129s", input_str2);
2689 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2690 if (rv != CONNECTION_ERROR_NONE) {
2691 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2697 case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2699 rv = connection_profile_set_ethernet_eap_type(profile, type);
2700 if (rv != CONNECTION_ERROR_NONE) {
2701 printf("Fail to set eap type : %s\n", test_print_error(rv));
2705 printf("Input anonymous_identity for TTLS ethernet:");
2706 rv = scanf("%99s", input_str1);
2708 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2709 if (rv != CONNECTION_ERROR_NONE) {
2710 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2714 printf("Input CA file for TTLS ethernet:");
2715 rv = scanf("%129s", input_str1);
2717 rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2718 if (rv != CONNECTION_ERROR_NONE) {
2719 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2723 printf("Input authentication type[1:PAP, 2:MSCHAP, 3:MSCHAPV2] for TTLS ethernet:");
2724 rv = scanf("%1d", &auth_type);
2726 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2727 if (rv != CONNECTION_ERROR_NONE) {
2728 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2732 printf("Input username for TTLS ethernet:");
2733 rv = scanf("%129s", input_str1);
2735 printf("Input password for TTLS ethernet:");
2736 rv = scanf("%129s", input_str2);
2738 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2739 if (rv != CONNECTION_ERROR_NONE) {
2740 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2746 case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2748 rv = connection_profile_set_ethernet_eap_type(profile, type);
2749 if (rv != CONNECTION_ERROR_NONE) {
2750 printf("Fail to set eap type : %s\n", test_print_error(rv));
2754 printf("Input anonymous_identity for FAST ethernet:");
2755 rv = scanf("%99s", input_str1);
2757 rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2758 if (rv != CONNECTION_ERROR_NONE) {
2759 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2763 printf("Input pac file for FAST ethernet:");
2764 rv = scanf("%129s", input_str1);
2766 rv = connection_profile_set_ethernet_eap_pac_file(profile, input_str1);
2767 if (rv != CONNECTION_ERROR_NONE) {
2768 printf("Fail to set eap pac file : %s\n", test_print_error(rv));
2772 printf("Input authentication type[3:MSCHAPV2, 4:GTC] for FAST ethernet:");
2773 rv = scanf("%1d", &auth_type);
2775 rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2776 if (rv != CONNECTION_ERROR_NONE) {
2777 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2781 printf("Input username for FAST ethernet:");
2782 rv = scanf("%129s", input_str1);
2784 printf("Input password for FAST ethernet:");
2785 rv = scanf("%129s", input_str2);
2787 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2788 if (rv != CONNECTION_ERROR_NONE) {
2789 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2796 printf("Invalid EAP type\n");
2800 rv = connection_profile_save_ethernet_eap_config(connection, profile);
2801 if (rv != CONNECTION_ERROR_NONE) {
2802 printf("Fail to save eap config : %s\n", test_print_error(rv));
2806 if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
2807 printf("Connection open Failed!!\n");
2814 static const char *test_print_eap_type(connection_ethernet_eap_type_e type)
2817 case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2819 case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2821 case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2823 case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2825 case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2832 static const char *test_print_eap_auth_type(connection_ethernet_eap_auth_type_e type)
2835 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_PAP:
2837 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAP:
2839 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2:
2841 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_GTC:
2843 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MD5:
2845 case CONNECTION_ETHERNET_EAP_AUTH_TYPE_NONE:
2852 int test_get_eapol_info(void)
2854 connection_profile_type_e prof_type;
2855 connection_profile_state_e profile_state;
2856 connection_profile_h profile;
2857 char *profile_name = NULL;
2858 connection_ethernet_eap_type_e type;
2859 connection_ethernet_eap_auth_type_e auth_type;
2860 connection_ethernet_eap_peap_version_e peapver;
2863 printf("\n** Choose a ethernet profile to print eapol info. **\n");
2864 if (test_get_user_selected_profile(&profile, true) == false)
2867 bool enabled = false;
2868 if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE) {
2869 printf("Failed to get ethernet eap enabled status!!\n");
2871 printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2873 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
2874 printf("Fail to get profile name\n");
2877 printf("Profile Name : %s\n", profile_name);
2878 g_free(profile_name);
2881 if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE) {
2882 printf("Fail to get profile type\n");
2886 if (prof_type != CONNECTION_PROFILE_TYPE_ETHERNET) {
2887 printf("Not ethernet profile\n");
2891 if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
2892 printf("Fail to get profile state\n");
2895 printf("Profile State : %s\n", test_print_state(profile_state));
2898 if (connection_profile_get_ethernet_eap_type(profile, &type) != CONNECTION_ERROR_NONE) {
2899 printf("Fail to get eap type\n");
2902 printf("eap_type: %s\n", test_print_eap_type(type));
2905 if (connection_profile_get_ethernet_eap_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2906 printf("Fail to get eap identity\n");
2909 printf("identity: %s\n", str);
2913 if (type == CONNECTION_ETHERNET_EAP_TYPE_MD5)
2916 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2917 type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2918 if (connection_profile_get_ethernet_eap_anonymous_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2919 printf("Fail to get eap anonymous_identity\n");
2922 printf("anonymous_identity: %s\n", str);
2927 if (connection_profile_get_ethernet_eap_ca_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2928 printf("Fail to get eap ca_cert_file\n");
2931 printf("ca_cert_file: %s\n", str);
2935 if (type == CONNECTION_ETHERNET_EAP_TYPE_TLS) {
2936 if (connection_profile_get_ethernet_eap_client_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2937 printf("Fail to get eap client_cert_file\n");
2940 printf("client_cert_file: %s\n", str);
2944 if (connection_profile_get_ethernet_eap_private_key_file(profile, &str) != CONNECTION_ERROR_NONE) {
2945 printf("Fail to get eap private_key_file\n");
2948 printf("private_key_file: %s\n", str);
2953 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2954 type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2955 if (connection_profile_get_ethernet_eap_auth_type(profile, &auth_type) != CONNECTION_ERROR_NONE) {
2956 printf("Fail to get eap auth type\n");
2959 printf("eap_auth: %s\n", test_print_eap_auth_type(auth_type));
2963 if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP) {
2964 if (connection_profile_get_ethernet_eap_peap_version(profile, &peapver) != CONNECTION_ERROR_NONE) {
2965 printf("Fail to get eap peap_version\n");
2968 printf("peap_version: %d\n", peapver);
2972 if (type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2973 if (connection_profile_get_ethernet_eap_pac_file(profile, &str) != CONNECTION_ERROR_NONE) {
2974 printf("Fail to get eap pac_file\n");
2977 printf("pac_file: %s\n", str);
2986 int test_get_clock_update_info(void)
2991 rv = connection_clock_is_updated(connection, &updated);
2993 if (rv != CONNECTION_ERROR_NONE) {
2994 printf("Fail to get clock update information [%s]\n", test_print_error(rv));
2998 printf("Retval = [%s] clock updated [%s]\n",
2999 test_print_error(rv), updated ? "TRUE" : "FALSE");
3004 int main(int argc, char **argv)
3006 GMainLoop *mainloop;
3007 mainloop = g_main_loop_new(NULL, FALSE);
3009 GIOChannel *channel = g_io_channel_unix_new(0);
3010 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
3012 printf("Test Thread created...\n");
3014 g_main_loop_run(mainloop);
3019 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
3024 memset(a, '\0', 100);
3025 printf("event received from stdin\n");
3027 rv = read(0, a, 100);
3029 if (rv < 0 || a[0] == '0') {
3030 if (connection != NULL)
3031 test_deregister_client();
3036 if (*a == '\n' || *a == '\r') {
3038 printf("\n\n Network Connection API Test App\n\n");
3039 printf("Options..\n");
3040 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
3041 printf(LOG_GREEN "1 - Create Handle and set callbacks\n" LOG_END);
3042 printf("2 - Destroy Handle(unset callbacks automatically)\n");
3043 printf(LOG_GREEN "3 - Get network state\n" LOG_END);
3044 printf(LOG_GREEN "4 - Get cellular state (please insert SIM Card)\n" LOG_END);
3045 printf(LOG_GREEN "5 - Get wifi state (please turn on WiFi)\n" LOG_END);
3046 printf("6 - Get current proxy address \n");
3047 printf("7 - Get current Ip address\n");
3048 printf("8 - Get cellular data call statistics\n");
3049 printf("9 - Get WiFi data call statistics\n");
3050 printf(LOG_GREEN "a - Get Profile list\n" LOG_END);
3051 printf(LOG_GREEN "b - Get Connected Profile list\n" LOG_END);
3052 printf(LOG_GREEN "c - Get Current profile\n" LOG_END);
3053 printf("d - Open connection with profile\n");
3054 printf("e - Get default cellular service by type\n");
3055 printf("f - Set default cellular service by type\n");
3056 printf("g - Close connection with profile\n");
3057 printf("h - Add profile(Cellular and Wifi only)\n");
3058 printf("i - Remove profile(Cellular:delete, WiFi:forgot)\n");
3059 printf("j - Update profile\n");
3060 printf("k - Get profile info\n");
3061 printf("l - Refresh profile info\n");
3062 printf("m - Set state changed callback\n");
3063 printf("n - Unset state changed callback\n");
3064 printf("o - Reset cellular data call statistics\n");
3065 printf("p - Reset WiFi data call statistics\n");
3066 printf("q - Add new route\n");
3067 printf("r - Remove a route\n");
3068 printf("s - Get bluetooth state\n");
3069 printf("t - Get profile id\n");
3070 printf("u - Reset profile\n");
3071 printf("v - Get all cellular default profiles\n");
3072 printf("w - Get mac address\n");
3073 printf("x - Get ethernet cable state\n");
3074 printf("B - Add IPv6 new route\n");
3075 printf("C - Remove IPv6 route\n");
3076 printf("D - Add new route entry\n");
3077 printf("E - Remove route entry\n");
3078 printf("F - Get all IPv6 address\n");
3079 printf("G - Get metered state\n");
3081 printf(LOG_BLUE "[Extension API]\n" LOG_END);
3082 printf("H - Start TCP Dump\n");
3083 printf("I - Stop TCP Dump\n");
3084 printf("J - Get TCP Dump State\n");
3085 printf("K - Enable MPTCP (internal)\n");
3086 printf("L - Disable MPTCP (internal)\n");
3087 printf("M - Set MPTCP Path Manager (internal)\n");
3088 printf("N - Get MPTCP Path Manager (internal)\n");
3089 printf("O - Set MPTCP Scheduler (internal)\n");
3090 printf("P - Get MPTCP Scheduler (internal)\n");
3091 printf(LOG_GREEN "Q - Create Handle and set callbacks in C# API\n" LOG_END);
3092 printf("R - Destroy Handle(unset callbacks automatically in C# API)\n");
3093 printf("S - Connect Ethernet EAP)\n");
3094 printf("T - Get EAPoL info)\n");
3095 printf("U - Get Clock update info)\n");
3096 printf(LOG_RED "0 - Exit \n" LOG_END);
3097 printf("ENTER - Show options menu.......\n");
3103 rv = test_register_client();
3106 rv = test_deregister_client();
3109 rv = test_get_network_state();
3112 rv = test_get_cellular_state();
3115 rv = test_get_wifi_state();
3118 rv = test_get_current_proxy();
3121 rv = test_get_current_ip();
3124 rv = test_get_call_statistics_info();
3127 rv = test_get_wifi_call_statistics_info();
3130 rv = test_get_profile_list();
3133 rv = test_get_connected_profile_list();
3136 rv = test_get_current_profile();
3139 rv = test_open_profile();
3142 rv = test_get_default_cellular_service_type();
3145 rv = test_set_default_cellular_service_type();
3148 rv = test_close_profile();
3151 rv = test_add_profile();
3154 rv = test_remove_profile();
3157 rv = test_update_profile();
3160 rv = test_get_profile_info();
3163 rv = test_refresh_profile_info();
3166 rv = test_set_state_changed_callback();
3169 rv = test_unset_state_changed_callback();
3172 rv = test_reset_call_statistics_info();
3175 rv = test_reset_wifi_call_statistics_info();
3178 rv = test_add_route();
3181 rv = test_remove_route();
3184 rv = test_get_bt_state();
3187 rv = test_get_profile_id();
3190 rv = test_reset_profile();
3193 rv = test_get_default_profile_list();
3196 rv = test_get_mac_address();
3199 rv = test_get_ethernet_cable_state();
3202 rv = test_add_route_ipv6();
3205 rv = test_remove_route_ipv6();
3208 rv = test_add_route_entry();
3211 rv = test_remove_route_entry();
3214 rv = test_foreach_ipv6_address();
3217 rv = test_is_metered_network();
3221 rv = test_start_tcpdump();
3224 rv = test_stop_tcpdump();
3227 rv = test_get_tcpdump_state();
3230 rv = test_mptcp_enable();
3233 rv = test_mptcp_disable();
3236 rv = test_mptcp_set_path_manager();
3239 rv = test_mptcp_get_path_manager();
3242 rv = test_mptcp_set_scheduler();
3245 rv = test_mptcp_get_scheduler();
3248 rv = test_register_client_cs();
3251 rv = test_deregister_client_cs();
3254 rv = test_ethernet_eap_connect();
3257 rv = test_get_eapol_info();
3260 rv = test_get_clock_update_info();
3265 printf("Operation succeeded!\n");
3267 printf("Operation failed!\n");