Fix null dereferencing and unchecked return value
[platform/core/api/connection.git] / test / connection_test.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <stdio.h>
18 #include <errno.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include <glib.h>
23
24 #include "net_connection.h"
25 #include "connection_extension.h"
26
27 #include <tizen_error.h>
28
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"
34
35 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
36
37 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
38
39 connection_h connection = NULL;
40 static GSList *state_cb_list = NULL;
41
42
43 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
44 {
45         if (msg == NULL || buf == NULL || buf_size < 2)
46                 return false;
47
48         int rv;
49         printf("%s\n", msg);
50         memset(buf, 0, buf_size);
51         rv = read(0, buf, buf_size - 1);
52
53         if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
54                 buf[0] = '\0';
55                 return false;
56         }
57
58         buf[rv-1] = '\0';
59         return true;
60 }
61
62 static bool test_get_user_int(const char *msg, int *num)
63 {
64         if (msg == NULL || num == NULL)
65                 return false;
66
67         int rv;
68         char buf[32] = {0,};
69         printf("%s\n", msg);
70         rv = read(0, buf, 32);
71
72         if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
73                 return false;
74
75         *num = atoi(buf);
76         return true;
77 }
78
79 static const char *test_print_state(connection_profile_state_e state)
80 {
81         switch (state) {
82         case CONNECTION_PROFILE_STATE_DISCONNECTED:
83                 return "Disconnected";
84         case CONNECTION_PROFILE_STATE_ASSOCIATION:
85                 return "Association";
86         case CONNECTION_PROFILE_STATE_CONFIGURATION:
87                 return "Configuration";
88         case CONNECTION_PROFILE_STATE_CONNECTED:
89                 return "Connected";
90         default:
91                 return "Unknown";
92         }
93 }
94
95 static const char *test_print_internet_state(connection_internet_state_e state)
96 {
97         if (state == CONNECTION_INTERNET_STATE_ONLINE)
98                 return "Online";
99
100         return "Offline";
101 }
102
103 static const char *test_print_connection_type(connection_type_e type)
104 {
105         switch (type) {
106         case CONNECTION_TYPE_DISCONNECTED:
107                 return "Disconnected";
108         case CONNECTION_TYPE_WIFI:
109                 return "Wifi";
110         case CONNECTION_TYPE_CELLULAR:
111                 return "Cellular";
112         case CONNECTION_TYPE_ETHERNET:
113                 return "Ethernet";
114         case CONNECTION_TYPE_BT:
115                 return "BT";
116         case CONNECTION_TYPE_NET_PROXY:
117                 return "Net_Proxy";
118         default:
119                 return "Unknown";
120         }
121 }
122
123 static const char *test_print_cellular_state(connection_cellular_state_e state)
124 {
125         switch (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:
135                 return "Available";
136         case CONNECTION_CELLULAR_STATE_CONNECTED:
137                 return "Connected";
138         default:
139                 return "Unknown";
140         }
141 }
142
143 static const char *test_print_wifi_state(connection_wifi_state_e state)
144 {
145         switch (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:
151                 return "Connected";
152         default:
153                 return "Unknown";
154         }
155 }
156
157 static const char *test_print_wifi_security_type(connection_wifi_security_type_e type)
158 {
159         switch (type) {
160         case CONNECTION_WIFI_SECURITY_TYPE_NONE:
161                 return "None";
162         case CONNECTION_WIFI_SECURITY_TYPE_WEP:
163                 return "WEP";
164         case CONNECTION_WIFI_SECURITY_TYPE_WPA_PSK:
165                 return "WPA_PSK";
166         case CONNECTION_WIFI_SECURITY_TYPE_WPA2_PSK:
167                 return "WPA2_PSK";
168         case CONNECTION_WIFI_SECURITY_TYPE_EAP:
169                 return "EAP";
170         case CONNECTION_WIFI_SECURITY_TYPE_SAE:
171                 return "SAE";
172         default:
173                 return "Unknown";
174         }
175 }
176
177 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
178 {
179         switch (type) {
180         case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
181                 return "Unknown";
182         case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
183                 return "Internet";
184         case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
185                 return "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:
191                 return "Tethering";
192         case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
193                 return "Application";
194         default:
195                 return "Unknown";
196         }
197 }
198
199 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
200 {
201         switch (type) {
202         case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
203                 return "PAP";
204         case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
205                 return "CHAP";
206         case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
207         default:
208                 return "None";
209         }
210 }
211
212 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
213 {
214         switch (type) {
215         case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
216                 return "IPv4";
217         case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
218                 return "IPv6";
219         case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
220                 return "Dual";
221         case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
222         default:
223                 return "Unknown";
224         }
225 }
226
227 static const char *test_print_error(connection_error_e error)
228 {
229         switch (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";
266         default:
267                 return "CONNECTION_ERROR_UNKNOWN";
268         }
269 }
270
271 static void test_type_changed_callback(connection_type_e type, void* user_data)
272 {
273         printf("Type changed callback, connection type : %d\n", type);
274 }
275
276 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
277 {
278         printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
279                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
280 }
281
282 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
283 {
284         printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
285                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
286 }
287
288 static void test_internet_state_changed_callback(connection_internet_state_e state, void* user_data)
289 {
290         printf("Internet state changed callback, state : %d\n", state);
291 }
292
293 static void test_dhcp_state_changed_callback(connection_dhcp_state_e state,
294                 const char *interface_name, connection_error_e result, void *user_data)
295 {
296         printf("DHCP state changed callback, ifname: %s, state: %d, result: %d\n",
297                         interface_name, state, result);
298 }
299
300 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
301 {
302         char *profile_name;
303         connection_profile_h profile = user_data;
304
305         if (profile == NULL)
306                 return;
307
308         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
309                 return;
310
311         printf("[%s] : %s\n", test_print_state(state), profile_name);
312         g_free(profile_name);
313 }
314
315 static void test_connection_opened_callback(connection_error_e result, void* user_data)
316 {
317         if (result ==  CONNECTION_ERROR_NONE)
318                 printf("Connection open Succeeded\n");
319         else
320                 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
321 }
322
323 static void test_connection_closed_callback(connection_error_e result, void* user_data)
324 {
325         if (result ==  CONNECTION_ERROR_NONE)
326                 printf("Connection close Succeeded\n");
327         else
328                 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
329 }
330
331 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
332 {
333         if (result ==  CONNECTION_ERROR_NONE)
334                 printf("Reset profile Succeeded\n");
335         else
336                 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
337 }
338
339 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
340 {
341         if (result ==  CONNECTION_ERROR_NONE)
342                 printf("Default profile setting Succeeded\n");
343         else
344                 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
345 }
346
347 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
348                                                                 void* user_data)
349 {
350         if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
351                 printf("Ethernet Cable Connected\n");
352         else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
353                 printf("Ethernet Cable Disconnected\n");
354 }
355
356 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
357 {
358         int rv = 0;
359         int input = 0;
360         char *profile_name;
361         connection_profile_type_e profile_type;
362         connection_profile_state_e profile_state;
363         connection_profile_iterator_h profile_iter;
364         connection_profile_h profile_h;
365
366         connection_profile_h profile_list[100] = {0,};
367         int profile_count = 0;
368
369         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
370         if (rv != CONNECTION_ERROR_NONE) {
371                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
372                 return false;
373         }
374
375         while (connection_profile_iterator_has_next(profile_iter)) {
376                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
377                         printf("Fail to get profile handle\n");
378                         return false;
379                 }
380
381                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
382                         printf("Fail to get profile name\n");
383                         return false;
384                 }
385
386                 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
387                         printf("Fail to get profile type\n");
388                         g_free(profile_name);
389                         return false;
390                 }
391
392                 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
393                         printf("Fail to get profile state\n");
394                         g_free(profile_name);
395                         return false;
396                 }
397
398                 printf("%d. state:[%s], profile name:%s", profile_count,
399                                 test_print_state(profile_state), profile_name);
400                 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
401                         connection_cellular_service_type_e service_type;
402                         if (connection_profile_get_cellular_service_type(
403                                 profile_h, &service_type) !=
404                                 CONNECTION_ERROR_NONE)
405                                 printf("Fail to get cellular service type!\n");
406
407                         printf(" [%s]",
408                                 test_print_cellular_service_type(service_type));
409                 } else if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
410                         connection_wifi_security_type_e security_type;
411                         if (connection_profile_get_wifi_security_type(
412                                 profile_h, &security_type) !=
413                                 CONNECTION_ERROR_NONE)
414                                 printf("Fail to get wifi security type!\n");
415
416                         printf(" [%s]",
417                                 test_print_wifi_security_type(security_type));
418                 }
419                 printf("\n");
420
421                 profile_list[profile_count] = profile_h;
422                 profile_count++;
423
424                 g_free(profile_name);
425                 if (profile_count >= 100)
426                         break;
427         }
428
429         if (select == false)
430                 return true;
431
432         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
433             input >= profile_count ||
434             input < 0) {
435                 printf("Wrong number!!\n");
436                 return false;
437         }
438
439         if (profile)
440                 *profile = profile_list[input];
441
442         return true;
443 }
444
445 static int test_update_cellular_info(connection_profile_h profile)
446 {
447         int rv = 0;
448         char input_str1[100] = {0,};
449         char input_str2[100] = {0,};
450         int input_int = 0;
451         int type_val = 0;
452
453         if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
454                         "Prepaid MMS:4, Tethering:5, Application:6)"
455                         " - (Enter for skip) :", &input_int)) {
456                 switch (input_int) {
457                 case 1:
458                         rv = connection_profile_set_cellular_service_type(profile,
459                                         CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
460                         break;
461                 case 2:
462                         rv = connection_profile_set_cellular_service_type(profile,
463                                         CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
464                         break;
465                 case 3:
466                         rv = connection_profile_set_cellular_service_type(profile,
467                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
468                         break;
469                 case 4:
470                         rv = connection_profile_set_cellular_service_type(profile,
471                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
472                         break;
473                 case 5:
474                         rv = connection_profile_set_cellular_service_type(profile,
475                                         CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
476                         break;
477                 case 6:
478                         rv = connection_profile_set_cellular_service_type(profile,
479                                         CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
480                         break;
481                 default:
482                         return -1;
483                 }
484
485                 if (rv != CONNECTION_ERROR_NONE)
486                         return -1;
487         } else
488                 return -1;
489
490         if (test_get_user_string("Input apn - (Enter for skip) :", input_str1, 100)) {
491                 g_strstrip(input_str1);
492                 rv = connection_profile_set_cellular_apn(profile, input_str1);
493                 if (rv != CONNECTION_ERROR_NONE)
494                         return -1;
495         }
496
497         if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
498                 g_strstrip(input_str1);
499                 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
500                 if (rv != CONNECTION_ERROR_NONE)
501                         return -1;
502         }
503
504         if (test_get_user_string("Input home_url - (Enter for skip) :", input_str1, 100)) {
505                 g_strstrip(input_str1);
506                 rv = connection_profile_set_cellular_home_url(profile, input_str1);
507                 if (rv != CONNECTION_ERROR_NONE)
508                         return -1;
509         }
510
511         if (test_get_user_int("Input auth_type(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
512                 switch (input_int) {
513                 case 0:
514                         rv = connection_profile_set_cellular_auth_info(profile,
515                                         CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
516                         if (rv != CONNECTION_ERROR_NONE)
517                                 return -1;
518
519                         break;
520                 case 1:
521                         type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
522                         /* fall through */
523                 case 2:
524                         if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
525
526                         if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
527                                 input_str1[0] = 0;
528                         if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
529                                 input_str2[0] = 0;
530
531                         g_strstrip(input_str1);
532                         g_strstrip(input_str2);
533                         rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
534                         if (rv != CONNECTION_ERROR_NONE)
535                                 return -1;
536                 }
537         }
538
539         if (test_get_user_int("Input pdn_type(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
540                 switch (input_int) {
541                 case 1:
542                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
543                         break;
544                 case 2:
545                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
546                         break;
547                 case 3:
548                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
549                         break;
550                 }
551
552                 if (rv != CONNECTION_ERROR_NONE)
553                         return -1;
554         }
555
556         if (test_get_user_int("Input roam_pdn_type(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
557                 switch (input_int) {
558                 case 1:
559                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
560                         break;
561                 case 2:
562                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
563                         break;
564                 case 3:
565                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
566                         break;
567                 }
568
569                 if (rv != CONNECTION_ERROR_NONE)
570                         return -1;
571         }
572
573         return 1;
574 }
575
576 static int test_update_wifi_info(connection_profile_h profile)
577 {
578         int rv = 0;
579         char input_str[100] = {0,};
580
581         if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
582                 rv = connection_profile_set_wifi_passphrase(profile, input_str);
583                 if (rv != CONNECTION_ERROR_NONE)
584                         return -1;
585         }
586
587         return 1;
588 }
589
590 static int test_update_dns_info(connection_profile_h profile,
591                 connection_address_family_e address_family)
592 {
593         int rv = 0;
594         char input_str[100] = {0,};
595         if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
596                 rv = connection_profile_set_dns_address(profile,
597                                 1,
598                                 address_family,
599                                 input_str);
600                 if (rv != CONNECTION_ERROR_NONE)
601                         return -1;
602
603                 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
604                         rv = connection_profile_set_dns_address(profile,
605                                         2,
606                                         address_family,
607                                         input_str);
608                         if (rv != CONNECTION_ERROR_NONE)
609                                 return -1;
610                 }
611         }
612         return 1;
613 }
614
615 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
616 {
617         int rv = 0;
618         int input_int = 0;
619         char input_str[100] = {0,};
620         int dns_input = 0;
621
622         if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
623                 rv = connection_profile_set_ip_address(profile,
624                                                         address_family,
625                                                         input_str);
626                 if (rv != CONNECTION_ERROR_NONE)
627                         return -1;
628         }
629
630         if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
631                 rv = connection_profile_set_subnet_mask(profile,
632                                                         address_family,
633                                                         input_str);
634                 if (rv != CONNECTION_ERROR_NONE)
635                         return -1;
636         }
637
638         if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
639                 rv = connection_profile_set_prefix_length(profile,
640                                                         address_family,
641                                                         input_int);
642                 if (rv != CONNECTION_ERROR_NONE)
643                         return -1;
644         }
645
646         if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
647                 rv = connection_profile_set_gateway_address(profile,
648                                                         address_family,
649                                                         input_str);
650                 if (rv != CONNECTION_ERROR_NONE)
651                         return -1;
652         }
653
654         if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
655                                 " - (Enter for skip) :", &dns_input)) {
656                 switch (dns_input) {
657                 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
658                         rv = connection_profile_set_dns_config_type(
659                                         profile,
660                                         address_family,
661                                         CONNECTION_DNS_CONFIG_TYPE_STATIC);
662                         if (rv != CONNECTION_ERROR_NONE)
663                                 return -1;
664                         if (test_update_dns_info(profile,
665                                                 address_family) == -1)
666                                 return -1;
667                         break;
668                 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
669                         rv = connection_profile_set_dns_config_type(
670                                         profile,
671                                         address_family,
672                                         CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
673                         if (rv != CONNECTION_ERROR_NONE)
674                                 return -1;
675                         break;
676                 }
677         }
678
679         return 1;
680 }
681
682 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
683 {
684         int rv = 0;
685         int input_int = 0;
686         char input_str[100] = {0,};
687
688         if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
689                                         " - (Enter for skip) :", &input_int)) {
690                 switch (input_int) {
691                 case 1:
692                         rv = connection_profile_set_proxy_type(profile,
693                                         CONNECTION_PROXY_TYPE_DIRECT);
694
695                         if (rv != CONNECTION_ERROR_NONE)
696                                 return -1;
697                         else
698                                 return 1;
699                 case 2:
700                         rv = connection_profile_set_proxy_type(profile,
701                                         CONNECTION_PROXY_TYPE_AUTO);
702                         break;
703                 case 3:
704                         rv = connection_profile_set_proxy_type(profile,
705                                         CONNECTION_PROXY_TYPE_MANUAL);
706                         break;
707                 default:
708                         return -1;
709                 }
710
711                 if (rv != CONNECTION_ERROR_NONE)
712                         return -1;
713
714                 if (test_get_user_string("Input auto Proxy URL or Proxy address"
715                                         " - (Enter for skip) :", input_str, 100)) {
716                         rv = connection_profile_set_proxy_address(profile,
717                                                                 address_family,
718                                                                 input_str);
719                         if (rv != CONNECTION_ERROR_NONE)
720                                 return -1;
721                 }
722
723         } else
724                 return -1;
725
726         return 1;
727 }
728
729
730
731 static int test_update_network_info(connection_profile_h profile)
732 {
733         int rv = 0;
734         int input_int = 0;
735         int dns_input = 0;
736         int address_family = 0;
737
738         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
739
740         if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
741                                 " - (Enter for skip) :", &input_int)) {
742                 switch (input_int) {
743                 case 1:
744                         rv = connection_profile_set_ip_config_type(profile,
745                                         address_family,
746                                         CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
747                         if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
748                                                 " - (Enter for skip) :", &dns_input)) {
749                                 switch (dns_input) {
750                                 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
751                                         rv = connection_profile_set_dns_config_type(
752                                                         profile,
753                                                         address_family,
754                                                         CONNECTION_DNS_CONFIG_TYPE_STATIC);
755                                         if (rv != CONNECTION_ERROR_NONE)
756                                                 return -1;
757                                         if (test_update_dns_info(profile,
758                                                                 address_family) == -1)
759                                                 return -1;
760                                         break;
761                                 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
762                                         rv = connection_profile_set_dns_config_type(
763                                                         profile,
764                                                         address_family,
765                                                         CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
766                                         if (rv != CONNECTION_ERROR_NONE)
767                                                 return -1;
768                                         break;
769                                 }
770                         }
771                         break;
772                 case 2:
773                         rv = connection_profile_set_ip_config_type(profile,
774                                                                    address_family,
775                                                                    CONNECTION_IP_CONFIG_TYPE_STATIC);
776                         if (rv != CONNECTION_ERROR_NONE)
777                                 return -1;
778
779                         if (test_update_ip_info(profile, address_family) == -1)
780                                 return -1;
781
782                         if (test_update_proxy_info(profile, address_family) == -1)
783                                 return -1;
784                         break;
785                 case 3:
786                         rv = connection_profile_set_ip_config_type(profile,
787                                                                 address_family,
788                                                                 CONNECTION_IP_CONFIG_TYPE_AUTO);
789                         break;
790                 default:
791                         return -1;
792                 }
793
794                 if (rv != CONNECTION_ERROR_NONE)
795                         return -1;
796         } else
797                 return -1;
798
799         return 1;
800 }
801
802 static void test_print_cellular_info(connection_profile_h profile)
803 {
804         connection_cellular_service_type_e service_type;
805         connection_cellular_pdn_type_e pdn_type;
806         connection_cellular_pdn_type_e roam_pdn_type;
807         char *apn = NULL;
808         connection_cellular_auth_type_e auth_type;
809         char *user_name = NULL;
810         char *password = NULL;
811         char *home_url = NULL;
812         bool roaming = false;
813         bool hidden = false;
814         bool editable = false;
815
816         if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
817                 printf("Fail to get cellular service type!\n");
818         else
819                 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
820
821         if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
822                 printf("Fail to get cellular pdn type!\n");
823         else
824                 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
825
826         if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
827                 printf("Fail to get cellular roam pdn type!\n");
828         else
829                 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
830
831         if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
832                 printf("Fail to get cellular APN!\n");
833         else {
834                 printf("Cellular APN : %s\n", apn);
835                 g_free(apn);
836         }
837
838         if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
839                 printf("Fail to get auth info!\n");
840         else {
841                 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
842                 printf("Cellular user_name : %s\n", user_name);
843                 printf("Cellular password : %s\n", password);
844                 g_free(user_name);
845                 g_free(password);
846         }
847
848         if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
849                 printf("Fail to get cellular home url!\n");
850         else {
851                 printf("Cellular home url : %s\n", home_url);
852                 g_free(home_url);
853         }
854
855         if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
856                 printf("Fail to get cellular roaming state!\n");
857         else
858                 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
859
860         if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
861                 printf("Fail to get cellular hidden state!\n");
862         else
863                 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
864
865         if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
866                 printf("Fail to get cellular editing state!\n");
867         else
868                 printf("Cellular editable : %s\n", editable ? "true" : "false");
869 }
870
871 static void test_print_wifi_info(connection_profile_h profile)
872 {
873         char *essid = NULL;
874         char *bssid = NULL;
875         int rssi = 0;
876         int frequency = 0;
877         int max_speed = 0;
878         connection_wifi_security_type_e security_type;
879         connection_wifi_encryption_type_e encryption_type;
880         bool pass_required = false;
881         bool wps_supported = false;
882
883         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
884                 printf("Fail to get Wi-Fi essid!\n");
885         else {
886                 printf("Wi-Fi essid : %s\n", essid);
887                 g_free(essid);
888         }
889
890         if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
891                 printf("Fail to get Wi-Fi bssid!\n");
892         else {
893                 printf("Wi-Fi bssid : %s\n", bssid);
894                 g_free(bssid);
895         }
896
897         if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
898                 printf("Fail to get Wi-Fi rssi!\n");
899         else
900                 printf("Wi-Fi rssi : %d\n", rssi);
901
902         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
903                 printf("Fail to get Wi-Fi frequency!\n");
904         else
905                 printf("Wi-Fi frequency : %d\n", frequency);
906
907         if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
908                 printf("Fail to get Wi-Fi max speed!\n");
909         else
910                 printf("Wi-Fi max speed : %d\n", max_speed);
911
912         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
913                 printf("Fail to get Wi-Fi security type!\n");
914         else
915                 printf("Wi-Fi security type : %s\n", test_print_wifi_security_type(security_type));
916
917         if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
918                 printf("Fail to get Wi-Fi encryption type!\n");
919         else
920                 printf("Wi-Fi encryption type : %d\n", encryption_type);
921
922         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
923                 printf("Fail to get Wi-Fi passphrase required!\n");
924         else
925                 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
926
927         if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
928                 printf("Fail to get Wi-Fi wps info\n");
929         else
930                 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
931 }
932
933 static void test_print_mesh_info(connection_profile_h profile)
934 {
935         char *essid = NULL;
936         char *bssid = NULL;
937         int rssi = 0;
938         int frequency = 0;
939         connection_wifi_security_type_e security_type;
940         bool pass_required = false;
941
942         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
943                 printf("Fail to get Mesh essid!\n");
944         else {
945                 printf("Mesh essid : %s\n", essid);
946                 g_free(essid);
947         }
948
949         if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
950                 printf("Fail to get Mesh bssid!\n");
951         else {
952                 printf("Mesh bssid : %s\n", bssid);
953                 g_free(bssid);
954         }
955
956         if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
957                 printf("Fail to get Mesh rssi!\n");
958         else
959                 printf("Mesh rssi : %d\n", rssi);
960
961         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
962                 printf("Fail to get Mesh frequency!\n");
963         else
964                 printf("Mesh frequency : %d\n", frequency);
965
966         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
967                 printf("Fail to get Mesh security type!\n");
968         else
969                 printf("Mesh security type : %s\n", test_print_wifi_security_type(security_type));
970
971         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
972                 printf("Fail to get Mesh passphrase required!\n");
973         else
974                 printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
975 }
976
977 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
978 {
979         char *interface_name = NULL;
980         char *ip = NULL;
981         char *subnet = NULL;
982         char *gateway = NULL;
983         char *dhcp_server = NULL;
984         int dhcp_lease_duration = 0;
985         char *dns1 = NULL;
986         char *dns2 = NULL;
987         char *proxy = NULL;
988         int prefix_len;
989         connection_ip_config_type_e ip_type;
990         connection_proxy_type_e proxy_type;
991         connection_dns_config_type_e dns_type;
992
993         if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
994                 printf("Fail to get interface name!\n");
995         else {
996                 printf("Interface name : %s\n", interface_name);
997                 g_free(interface_name);
998         }
999
1000         if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
1001                 printf("Fail to get ipconfig type!\n");
1002         else {
1003                 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
1004                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
1005                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
1006                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
1007                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
1008                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
1009                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
1010                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
1011                 else
1012                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
1013         }
1014
1015         if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
1016                 printf("Fail to get IP address!\n");
1017         else {
1018                 printf("IP address : %s\n", ip);
1019                 g_free(ip);
1020         }
1021
1022         if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
1023                 printf("Fail to get gateway!\n");
1024         else {
1025                 printf("Gateway : %s\n", gateway);
1026                 g_free(gateway);
1027         }
1028
1029         if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
1030                 printf("Fail to get DHCP Server address!\n");
1031         else {
1032                 printf("DHCP Server : %s\n", dhcp_server);
1033                 g_free(dhcp_server);
1034         }
1035
1036         if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
1037                 printf("Fail to get DHCP lease duration!\n");
1038         else
1039                 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
1040         if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
1041                 printf("Fail to get subnet mask!\n");
1042         else {
1043                 printf("Subnet mask : %s\n", subnet);
1044                 g_free(subnet);
1045         }
1046
1047         if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
1048                 printf("Fail to get prefix length!\n");
1049         else
1050                 printf("Prefix length : %d\n", prefix_len);
1051
1052         if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
1053                 printf("Fail to get DNS configuration type!\n");
1054         else {
1055                 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
1056                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
1057                 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
1058                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
1059                 else
1060                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
1061         }
1062
1063         if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
1064                 printf("Fail to get DNS1!\n");
1065         else {
1066                 printf("DNS1 : %s\n", dns1);
1067                 g_free(dns1);
1068         }
1069
1070         if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
1071                 printf("Fail to get DNS2!\n");
1072         else {
1073                 printf("DNS2 : %s\n", dns2);
1074                 g_free(dns2);
1075         }
1076
1077         if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
1078                 printf("Fail to get proxy type!\n");
1079         else {
1080                 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
1081                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
1082                 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
1083                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
1084                 else
1085                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
1086         }
1087
1088         if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
1089                 printf("Fail to get proxy!\n");
1090         else {
1091                 printf("Proxy : %s\n", proxy);
1092                 g_free(proxy);
1093         }
1094 }
1095
1096 int test_register_client(void)
1097 {
1098
1099         int err = connection_create(&connection);
1100
1101         if (CONNECTION_ERROR_NONE == err) {
1102                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1103                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1104                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1105                 connection_set_ethernet_cable_state_changed_cb(connection,
1106                                         test_get_ethernet_cable_state_callback, NULL);
1107                 connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
1108                 connection_set_dhcp_state_changed_cb(connection, test_dhcp_state_changed_callback, NULL);
1109         } else {
1110                 printf("Client registration failed [%s]\n", test_print_error(err));
1111                 return -1;
1112         }
1113
1114         printf("Client registration success\n");
1115         return 1;
1116 }
1117
1118 int  test_deregister_client(void)
1119 {
1120         int rv = 0;
1121         GSList *list;
1122         connection_profile_h profile;
1123
1124         if (connection != NULL)
1125                 rv = connection_destroy(connection);
1126         else {
1127                 printf("Cannot deregister : Handle is NULL\n");
1128                 rv = CONNECTION_ERROR_INVALID_OPERATION;
1129         }
1130
1131         if (rv != CONNECTION_ERROR_NONE) {
1132                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1133                 return -1;
1134         }
1135
1136         if (state_cb_list) {
1137                 for (list = state_cb_list; list; list = list->next) {
1138                         profile = list->data;
1139                         connection_profile_destroy(profile);
1140                 }
1141
1142                 g_slist_free(state_cb_list);
1143                 state_cb_list = NULL;
1144         }
1145
1146         connection = NULL;
1147         printf("Client deregistration success\n");
1148
1149         return 1;
1150 }
1151
1152 int test_register_client_cs(void)
1153 {
1154         int tid = 0;
1155         test_get_user_int("Input a TID in C# API :", &tid);
1156
1157         int err = connection_create_cs(tid, &connection);
1158
1159         if (CONNECTION_ERROR_NONE == err) {
1160                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1161                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1162                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1163                 connection_set_ethernet_cable_state_changed_cb(connection,
1164                                         test_get_ethernet_cable_state_callback, NULL);
1165         } else {
1166                 printf("Client registration failed [%s]\n", test_print_error(err));
1167                 return -1;
1168         }
1169
1170         printf("Client registration success\n");
1171         return 1;
1172 }
1173
1174 int  test_deregister_client_cs(void)
1175 {
1176         int rv = 0;
1177         GSList *list;
1178         connection_profile_h profile;
1179         int tid = 0;
1180
1181         test_get_user_int("Input a TID in C# API :", &tid);
1182
1183         if (connection != NULL)
1184                 rv = connection_destroy_cs(tid, connection);
1185         else {
1186                 printf("Cannot deregister : Handle is NULL\n");
1187                 rv = CONNECTION_ERROR_INVALID_OPERATION;
1188         }
1189
1190         if (rv != CONNECTION_ERROR_NONE) {
1191                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1192                 return -1;
1193         }
1194
1195         if (state_cb_list) {
1196                 for (list = state_cb_list; list; list = list->next) {
1197                         profile = list->data;
1198                         connection_profile_destroy(profile);
1199                 }
1200
1201                 g_slist_free(state_cb_list);
1202                 state_cb_list = NULL;
1203         }
1204
1205         connection = NULL;
1206         printf("Client deregistration success\n");
1207
1208         return 1;
1209 }
1210
1211 int test_get_network_state(void)
1212 {
1213         int rv = 0;
1214         connection_type_e net_state;
1215
1216         rv = connection_get_type(connection, &net_state);
1217
1218         if (rv != CONNECTION_ERROR_NONE) {
1219                 printf("Fail to get network state [%s]\n", test_print_error(rv));
1220                 return -1;
1221         }
1222
1223         printf("Retval = [%s] network connection state [%s]\n",
1224                 test_print_error(rv), test_print_connection_type(net_state));
1225
1226         return 1;
1227 }
1228
1229 int test_get_cellular_state(void)
1230 {
1231         int rv = 0;
1232         connection_cellular_state_e cellular_state;
1233
1234         rv = connection_get_cellular_state(connection, &cellular_state);
1235
1236         if (rv != CONNECTION_ERROR_NONE) {
1237                 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1238                 return -1;
1239         }
1240
1241         printf("Retval = [%s] Cellular state [%s]\n",
1242                 test_print_error(rv), test_print_cellular_state(cellular_state));
1243
1244         return 1;
1245 }
1246
1247 int test_get_wifi_state(void)
1248 {
1249         int rv = 0;
1250         connection_wifi_state_e wifi_state;
1251
1252         rv = connection_get_wifi_state(connection, &wifi_state);
1253
1254         if (rv != CONNECTION_ERROR_NONE) {
1255                 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1256                 return -1;
1257         }
1258
1259         printf("Retval = [%s] WiFi state [%s]\n",
1260                 test_print_error(rv), test_print_wifi_state(wifi_state));
1261
1262         return 1;
1263 }
1264
1265 int test_get_current_proxy(void)
1266 {
1267         char *proxy_addr = NULL;
1268
1269         connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1270
1271         if (proxy_addr == NULL) {
1272                 printf("Proxy address does not exist\n");
1273                 return -1;
1274         }
1275
1276         printf("Current Proxy [%s]\n", proxy_addr);
1277         g_free(proxy_addr);
1278
1279         return 1;
1280 }
1281
1282 int test_get_current_ip(void)
1283 {
1284         char *ip_addr = NULL;
1285         int input;
1286         bool rv;
1287
1288         rv = test_get_user_int("Input Address type to get"
1289                 "(1:IPV4, 2:IPV6):", &input);
1290
1291         if (rv == false) {
1292                 printf("Invalid input!!\n");
1293                 return -1;
1294         }
1295
1296         switch (input) {
1297         case 1:
1298                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1299                 if (ip_addr == NULL) {
1300                         printf("IPv4 address does not exist\n");
1301                         return -1;
1302                 }
1303                 printf("IPv4 address : %s\n", ip_addr);
1304                 break;
1305
1306         case 2:
1307                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1308                 if (ip_addr == NULL) {
1309                         printf("IPv6 address does not exist\n");
1310                         return -1;
1311                 }
1312                 printf("IPv6 address : %s\n", ip_addr);
1313                 break;
1314         default:
1315                 printf("Wrong IP address family!!\n");
1316                 return -1;
1317         }
1318
1319         g_free(ip_addr);
1320         return 1;
1321 }
1322
1323 int test_get_call_statistics_info(void)
1324 {
1325         long long rv = 0;
1326
1327         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1328         printf("last recv data size [%lld]\n", rv);
1329         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1330         printf("last sent data size [%lld]\n", rv);
1331         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1332         printf("total received data size [%lld]\n", rv);
1333         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1334         printf("total sent data size [%lld]\n", rv);
1335
1336         return 1;
1337 }
1338
1339 int test_get_wifi_call_statistics_info(void)
1340 {
1341         long long rv = 0;
1342
1343         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1344         printf("WiFi last recv data size [%lld]\n", rv);
1345         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1346         printf("WiFi last sent data size [%lld]\n", rv);
1347         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1348         printf("WiFi total received data size [%lld]\n", rv);
1349         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1350         printf("WiFi total sent data size [%lld]\n", rv);
1351
1352         return 1;
1353 }
1354
1355 int test_get_profile_list(void)
1356 {
1357         if (test_get_user_selected_profile(NULL, false) == false)
1358                 return -1;
1359
1360         return 1;
1361 }
1362
1363 int test_get_default_profile_list(void)
1364 {
1365         int rv = 0;
1366         char *profile_name = NULL;
1367         connection_profile_iterator_h profile_iter;
1368         connection_profile_h profile_h;
1369         connection_cellular_service_type_e service_type;
1370         bool is_default = false;
1371
1372         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1373         if (rv != CONNECTION_ERROR_NONE) {
1374                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1375                 return -1;
1376         }
1377
1378         while (connection_profile_iterator_has_next(profile_iter)) {
1379                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1380                         printf("Fail to get profile handle\n");
1381                         return -1;
1382                 }
1383
1384                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1385                         printf("Fail to get profile name\n");
1386                         return -1;
1387                 }
1388                 printf("profile name : %s\n", profile_name);
1389                 g_free(profile_name);
1390
1391                 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1392                         printf("Fail to get profile service type\n");
1393                         return -1;
1394                 }
1395                 printf("service type : %d\n", service_type);
1396
1397                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1398                         printf("Fail to get profile subscriber id\n");
1399                         return -1;
1400                 }
1401                 printf("Default : %d\n", is_default);
1402         }
1403
1404         return 1;
1405 }
1406
1407 int test_get_connected_profile_list(void)
1408 {
1409         int rv = 0;
1410         char *profile_name = NULL;
1411         connection_profile_iterator_h profile_iter;
1412         connection_profile_h profile_h;
1413         bool is_default = false;
1414         connection_profile_type_e type;
1415
1416         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1417         if (rv != CONNECTION_ERROR_NONE) {
1418                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1419                 return -1;
1420         }
1421
1422         while (connection_profile_iterator_has_next(profile_iter)) {
1423                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1424                         printf("Fail to get profile handle\n");
1425                         return -1;
1426                 }
1427
1428                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1429                         printf("Fail to get profile name\n");
1430                         return -1;
1431                 }
1432                 printf("profile name is %s\n", profile_name);
1433                 g_free(profile_name);
1434
1435                 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1436                         printf("Fail to get profile type\n");
1437                         return -1;
1438                 }
1439                 printf("profile type is %d\n", type);
1440
1441                 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1442                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1443                         printf("Fail to get profile is default\n");
1444                         return -1;
1445                 }
1446                         printf("[%s]\n", is_default ? "default" : "not default");
1447                 }
1448         }
1449
1450         return 1;
1451 }
1452
1453 int test_get_current_profile(void)
1454 {
1455         int rv = 0;
1456         char *profile_name = NULL;
1457         connection_profile_h profile_h;
1458
1459         rv = connection_get_current_profile(connection, &profile_h);
1460         if (rv != CONNECTION_ERROR_NONE) {
1461                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1462                 return -1;
1463         }
1464
1465         if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1466                 printf("Fail to get profile name\n");
1467                 return -1;
1468         }
1469         printf("profile name : %s\n", profile_name);
1470         g_free(profile_name);
1471
1472         connection_profile_destroy(profile_h);
1473
1474         return 1;
1475 }
1476
1477 int test_open_profile(void)
1478 {
1479         connection_profile_h profile;
1480
1481         printf("\n** Choose a profile to open. **\n");
1482
1483         if (test_get_user_selected_profile(&profile, true) == false)
1484                 return -1;
1485
1486         if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1487                 printf("Connection open Failed!!\n");
1488                 return -1;
1489         }
1490
1491         return 1;
1492 }
1493
1494 int test_get_default_cellular_service_type(void)
1495 {
1496         int input;
1497         int rv;
1498         int service_type;
1499         connection_profile_h profile;
1500         char *profile_name = NULL;
1501
1502         rv = test_get_user_int("Input profile type to get"
1503                         "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1504
1505         if (rv == false) {
1506                 printf("Invalid input!!\n");
1507                 return -1;
1508         }
1509
1510         switch (input) {
1511         case 1:
1512                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1513                 break;
1514         case 2:
1515                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1516                 break;
1517         case 3:
1518                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1519                 break;
1520         case 4:
1521                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1522                 break;
1523         case 5:
1524                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1525                 break;
1526         case 6:
1527                 service_type =  CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1528                 break;
1529         default:
1530                 printf("Wrong number!!\n");
1531                 return -1;
1532         }
1533
1534         if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1535                 return -1;
1536
1537         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1538                 printf("Fail to get profile name\n");
1539                 connection_profile_destroy(profile);
1540                 return -1;
1541         }
1542         printf("Default profile name : %s\n", profile_name);
1543         g_free(profile_name);
1544
1545         connection_profile_destroy(profile);
1546
1547         return 1;
1548 }
1549
1550 int test_set_default_cellular_service_type(void)
1551 {
1552         connection_profile_h profile;
1553         connection_cellular_service_type_e type;
1554         int input, rv;
1555
1556         rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1557
1558         if (rv == false || (input != 1 && input != 2)) {
1559                 printf("Invalid input!!\n");
1560                 return -1;
1561         }
1562
1563         printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1564
1565         if (test_get_user_selected_profile(&profile, true) == false)
1566                 return -1;
1567
1568         if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1569                 printf("Fail to get cellular service type\n");
1570                 return -1;
1571         }
1572
1573         if (input == 1) {
1574                 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1575                         return -1;
1576         } else {
1577                 if (connection_set_default_cellular_service_profile_async(connection,
1578                                 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1579                         return -1;
1580         }
1581
1582         return 1;
1583 }
1584
1585 int test_close_profile(void)
1586 {
1587         connection_profile_h profile;
1588
1589         printf("\n** Choose a profile to close. **\n");
1590
1591         if (test_get_user_selected_profile(&profile, true) == false)
1592                 return -1;
1593
1594         if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1595                 printf("Connection close Failed!!\n");
1596                 return -1;
1597         }
1598
1599         return 1;
1600 }
1601
1602 int test_add_profile(void)
1603 {
1604         int rv = 0;
1605         connection_profile_h profile;
1606         char input_str[100] = {0,};
1607
1608         if (test_get_user_string("Input keyword - (Enter for skip) :", input_str, 100) == false)
1609                 return -1;
1610
1611         g_strstrip(input_str);
1612         rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1613         if (rv != CONNECTION_ERROR_NONE)
1614                 RETURN_FAIL_DESTROY(profile);
1615
1616         if (test_update_cellular_info(profile) == -1)
1617                 RETURN_FAIL_DESTROY(profile);
1618
1619         rv = connection_add_profile(connection, profile);
1620         if (rv != CONNECTION_ERROR_NONE)
1621                 RETURN_FAIL_DESTROY(profile);
1622
1623         connection_profile_destroy(profile);
1624         return 1;
1625 }
1626
1627 int test_remove_profile(void)
1628 {
1629         connection_profile_h profile;
1630
1631         printf("\n** Choose a profile to remove. **\n");
1632         if (test_get_user_selected_profile(&profile, true) == false)
1633                 return -1;
1634
1635         if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1636                 printf("Remove profile Failed!!\n");
1637                 return -1;
1638         }
1639
1640         return 1;
1641 }
1642
1643 int test_update_profile(void)
1644 {
1645         int rv = 0;
1646
1647         connection_profile_type_e prof_type;
1648         connection_profile_h profile;
1649
1650         printf("\n** Choose a profile to update. **\n");
1651         if (test_get_user_selected_profile(&profile, true) == false)
1652                 return -1;
1653
1654         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1655                 return -1;
1656
1657         switch (prof_type) {
1658         case CONNECTION_PROFILE_TYPE_CELLULAR:
1659                 if (test_update_cellular_info(profile) == -1)
1660                         return -1;
1661
1662                 break;
1663         case CONNECTION_PROFILE_TYPE_WIFI:
1664                 if (test_update_wifi_info(profile) == -1)
1665                         return -1;
1666
1667                 if (test_update_network_info(profile) == -1)
1668                         return -1;
1669
1670                 break;
1671         case CONNECTION_PROFILE_TYPE_ETHERNET:
1672                 if (test_update_network_info(profile) == -1)
1673                         return -1;
1674
1675                 break;
1676         case CONNECTION_PROFILE_TYPE_BT:
1677                 printf("Not supported!\n");
1678                 /* fall through */
1679         default:
1680                 {
1681                         int profile_type = prof_type;
1682                         if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1683                                 if (test_update_wifi_info(profile) == -1)
1684                                         return -1;
1685                                 break;
1686                         }
1687                 }
1688                 return -1;
1689         }
1690
1691         rv = connection_update_profile(connection, profile);
1692         if (rv != CONNECTION_ERROR_NONE)
1693                 return -1;
1694
1695         return 1;
1696 }
1697
1698 int test_get_profile_info(void)
1699 {
1700         connection_profile_type_e prof_type;
1701         connection_profile_state_e profile_state;
1702         connection_profile_state_e profile_ipv6_state;
1703         connection_internet_state_e internet_state;
1704         connection_profile_h profile;
1705         char *profile_name = NULL;
1706         int address_family = 0;
1707
1708         printf("\n** Choose a profile to print. **\n");
1709         if (test_get_user_selected_profile(&profile, true) == false)
1710                 return -1;
1711
1712         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1713                 printf("Fail to get profile name\n");
1714                 return -1;
1715         } else {
1716                 printf("Profile Name : %s\n", profile_name);
1717                 g_free(profile_name);
1718         }
1719
1720         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1721                 printf("Fail to get profile IPv4 state\n");
1722                 return -1;
1723         } else
1724                 printf("Profile State : %s\n", test_print_state(profile_state));
1725
1726         if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1727                 printf("Fail to get profile IPv6 state\n");
1728                 return -1;
1729         } else
1730                 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1731
1732         if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
1733                 printf("Fail to get Internet state\n");
1734                 return -1;
1735         } else
1736                 printf("Internet State : %s\n", test_print_internet_state(internet_state));
1737
1738         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1739                 return -1;
1740
1741         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1742
1743         switch (prof_type) {
1744         case CONNECTION_PROFILE_TYPE_CELLULAR:
1745                 printf("Profile Type : Cellular\n");
1746                 test_print_cellular_info(profile);
1747                 break;
1748         case CONNECTION_PROFILE_TYPE_WIFI:
1749                 printf("Profile Type : Wi-Fi\n");
1750                 test_print_wifi_info(profile);
1751                 break;
1752         case CONNECTION_PROFILE_TYPE_ETHERNET:
1753                 printf("Profile Type : Ethernet\n");
1754                 break;
1755         case CONNECTION_PROFILE_TYPE_BT:
1756                 printf("Profile Type : bluetooth\n");
1757                 break;
1758         default:
1759                 {
1760                         int profile_type = prof_type;
1761                         if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1762                                 printf("Profile Type : Mesh\n");
1763                                 test_print_mesh_info(profile);
1764                                 break;
1765                         }
1766                 }
1767                 return -1;
1768         }
1769
1770         test_print_network_info(profile, address_family);
1771
1772         return 1;
1773 }
1774
1775 int test_refresh_profile_info(void)
1776 {
1777         connection_profile_type_e prof_type;
1778         connection_profile_state_e profile_state;
1779         connection_profile_h profile;
1780         char *profile_name = NULL;
1781         int address_family = 0;
1782
1783         printf("\n** Choose a profile to refresh. **\n");
1784         if (test_get_user_selected_profile(&profile, true) == false)
1785                 return -1;
1786
1787         if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1788                 return -1;
1789
1790         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1791                 printf("Fail to get profile name\n");
1792                 return -1;
1793         } else {
1794                 printf("Profile Name : %s\n", profile_name);
1795                 g_free(profile_name);
1796         }
1797
1798         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1799                 printf("Fail to get profile state\n");
1800                 return -1;
1801         } else
1802                 printf("Profile State : %s\n", test_print_state(profile_state));
1803
1804
1805         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1806                 return -1;
1807
1808         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1809
1810         switch (prof_type) {
1811         case CONNECTION_PROFILE_TYPE_CELLULAR:
1812                 printf("Profile Type : Cellular\n");
1813                 test_print_cellular_info(profile);
1814                 break;
1815         case CONNECTION_PROFILE_TYPE_WIFI:
1816                 printf("Profile Type : Wi-Fi\n");
1817                 test_print_wifi_info(profile);
1818                 break;
1819         case CONNECTION_PROFILE_TYPE_ETHERNET:
1820                 printf("Profile Type : Ethernet\n");
1821                 break;
1822         case CONNECTION_PROFILE_TYPE_BT:
1823                 printf("Profile Type : bluetooth\n");
1824                 break;
1825         default:
1826                 {
1827                         int profile_type = prof_type;
1828                         if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1829                                 printf("Profile Type : Mesh\n");
1830                                 test_print_mesh_info(profile);
1831                                 break;
1832                         }
1833                 }
1834                 return -1;
1835         }
1836
1837         test_print_network_info(profile, address_family);
1838
1839         return 1;
1840 }
1841
1842 int test_set_state_changed_callback()
1843 {
1844         connection_profile_h profile;
1845         connection_profile_h profile_clone;
1846
1847         printf("\n** Choose a profile to set callback. **\n");
1848         if (test_get_user_selected_profile(&profile, true) == false)
1849                 return -1;
1850
1851         if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1852                 return -1;
1853
1854         if (connection_profile_set_state_changed_cb(profile,
1855                         test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1856                 connection_profile_destroy(profile_clone);
1857                 return -1;
1858         }
1859
1860         state_cb_list = g_slist_append(state_cb_list, profile_clone);
1861
1862         return 1;
1863 }
1864
1865 int test_unset_state_changed_callback()
1866 {
1867         connection_profile_h profile;
1868         GSList *list;
1869         char *profile_name = NULL;
1870         int count = 0;
1871         int input = 0;
1872
1873         printf("\n** Choose a profile to unset callback. **\n");
1874         for (list = state_cb_list; list; list = list->next) {
1875                 profile = list->data;
1876                 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1877                         printf("Fail to get profile name!\n");
1878                         return -1;
1879                 } else {
1880                         printf("%d. %s\n", count, profile_name);
1881                         g_free(profile_name);
1882                 }
1883
1884                 count++;
1885         }
1886
1887         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1888             input >= count ||
1889             input < 0) {
1890                 printf("Wrong number!!\n");
1891                 return -1;
1892         }
1893
1894         count = 0;
1895         for (list = state_cb_list; list; list = list->next) {
1896                 if (count == input) {
1897                         profile = list->data;
1898                         goto unset;
1899                 }
1900
1901                 count++;
1902         }
1903
1904         return -1;
1905
1906 unset:
1907         if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1908                 return -1;
1909
1910         state_cb_list = g_slist_remove(state_cb_list, profile);
1911         connection_profile_destroy(profile);
1912
1913         return 1;
1914 }
1915
1916 int test_reset_call_statistics_info(void)
1917 {
1918         int ret = CONNECTION_ERROR_NONE;
1919
1920         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1921         printf("reset last recv data size [%d]\n", ret);
1922         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1923         printf("last sent data size [%d]\n", ret);
1924         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1925         printf("total received data size [%d]\n", ret);
1926         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1927         printf("total sent data size [%d]\n", ret);
1928
1929         return 1;
1930 }
1931
1932 int test_reset_wifi_call_statistics_info(void)
1933 {
1934         int ret = CONNECTION_ERROR_NONE;
1935
1936         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1937         printf("WiFi last sent data size [%d]\n", ret);
1938         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1939         printf("WiFi last recv data size [%d]\n", ret);
1940         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1941         printf("WiFi total sent data size [%d]\n", ret);
1942         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1943         printf("WiFi total received data size [%d]\n", ret);
1944
1945         return 1;
1946 }
1947
1948 int test_add_route(void)
1949 {
1950         int rv = 0;
1951         char ip_addr[100] = {0};
1952         char if_name[40] = {0};
1953
1954         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1955                 return -1;
1956
1957         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1958                 return -1;
1959
1960         g_strstrip(ip_addr);
1961         g_strstrip(if_name);
1962         rv = connection_add_route(connection, if_name, ip_addr);
1963         if (rv != CONNECTION_ERROR_NONE) {
1964                 printf("Fail to get add new route [%d]\n", rv);
1965                 return -1;
1966         }
1967         printf("Add Route successfully\n");
1968
1969         return 1;
1970 }
1971
1972 int test_remove_route(void)
1973 {
1974         int rv = 0;
1975         char ip_addr[100] = {0};
1976         char if_name[40] = {0};
1977
1978         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1979                 return -1;
1980
1981         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1982                 return -1;
1983
1984         g_strstrip(ip_addr);
1985         g_strstrip(if_name);
1986         rv = connection_remove_route(connection, if_name, ip_addr);
1987         if (rv != CONNECTION_ERROR_NONE) {
1988                 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1989                 return -1;
1990         }
1991         printf("Remove Route successfully\n");
1992
1993         return 1;
1994 }
1995
1996 int test_add_route_ipv6(void)
1997 {
1998         int rv = 0;
1999         char ip_addr[100] = {0};
2000         char gateway[100] = {0};
2001         char if_name[40] = {0};
2002
2003         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
2004                 return -1;
2005
2006         test_get_user_string("Input Gateway - (Enter for unspecified address) :", gateway, 100);
2007
2008         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2009                 return -1;
2010
2011         g_strstrip(ip_addr);
2012         g_strstrip(gateway);
2013         g_strstrip(if_name);
2014         rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
2015         if (rv != CONNECTION_ERROR_NONE) {
2016                 printf("Fail to get add new route [%d]\n", rv);
2017                 return -1;
2018         }
2019         printf("Add Route successfully\n");
2020
2021         return 1;
2022 }
2023
2024 int test_remove_route_ipv6(void)
2025 {
2026         int rv = 0;
2027         char ip_addr[100] = {0};
2028         char gateway[100] = {0};
2029         char if_name[40] = {0};
2030
2031         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
2032                 return -1;
2033
2034         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2035                 return -1;
2036
2037         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2038                 return -1;
2039
2040         g_strstrip(ip_addr);
2041         g_strstrip(gateway);
2042         g_strstrip(if_name);
2043         rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
2044         if (rv != CONNECTION_ERROR_NONE) {
2045                 printf("Fail to remove the route [%d]\n", rv);
2046                 return -1;
2047         }
2048         printf("Remove Route successfully\n");
2049
2050         return 1;
2051 }
2052
2053 int test_add_route_entry(void)
2054 {
2055         char ip_addr[100] = {0};
2056         char gateway[100] = {0};
2057         char if_name[40] = {0};
2058         int input;
2059         bool input_rv;
2060         int rv = 0;
2061
2062         input_rv = test_get_user_int("Input Address type to get"
2063                 "(1:IPV4, 2:IPV6):", &input);
2064
2065         if (input_rv == false) {
2066                 printf("Invalid input!!\n");
2067                 return -1;
2068         }
2069
2070         switch (input) {
2071         case 1:
2072                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2073                         return -1;
2074
2075                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2076                         return -1;
2077
2078                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2079                         return -1;
2080
2081                 g_strstrip(ip_addr);
2082                 g_strstrip(gateway);
2083                 g_strstrip(if_name);
2084                 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2085                 if (rv != CONNECTION_ERROR_NONE) {
2086                         printf("Fail to get add new route [%d]\n", rv);
2087                         return -1;
2088                 }
2089                 printf("Add Route successfully\n");
2090                 break;
2091
2092         case 2:
2093                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2094                         return -1;
2095
2096                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2097                         return -1;
2098
2099                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2100                         return -1;
2101
2102                 g_strstrip(ip_addr);
2103                 g_strstrip(gateway);
2104                 g_strstrip(if_name);
2105                 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2106                 if (rv != CONNECTION_ERROR_NONE) {
2107                         printf("Fail to get add new route [%d]\n", rv);
2108                         return -1;
2109                 }
2110                 printf("Add Route successfully\n");
2111                 break;
2112
2113         default:
2114                 printf("Wrong IP address family!!\n");
2115                 return -1;
2116
2117         }
2118
2119         return 1;
2120
2121 }
2122
2123 int test_remove_route_entry(void)
2124 {
2125         char ip_addr[100] = {0};
2126         char gateway[100] = {0};
2127         char if_name[40] = {0};
2128         int input;
2129         bool input_rv;
2130         int rv = 0;
2131
2132         input_rv = test_get_user_int("Input Address type to get"
2133                 "(1:IPV4, 2:IPV6):", &input);
2134
2135         if (input_rv == false) {
2136                 printf("Invalid input!!\n");
2137                 return -1;
2138         }
2139
2140         switch (input) {
2141         case 1:
2142                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2143                         return -1;
2144
2145                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2146                         return -1;
2147
2148                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2149                         return -1;
2150
2151                 g_strstrip(ip_addr);
2152                 g_strstrip(gateway);
2153                 g_strstrip(if_name);
2154                 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2155                 if (rv != CONNECTION_ERROR_NONE) {
2156                         printf("Fail to remove the route [%s]\n", test_print_error(rv));
2157                         return -1;
2158                 }
2159                 printf("Remove Route successfully\n");
2160
2161                 break;
2162
2163         case 2:
2164                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2165                         return -1;
2166
2167                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2168                         return -1;
2169
2170                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2171                         return -1;
2172
2173                 g_strstrip(ip_addr);
2174                 g_strstrip(gateway);
2175                 g_strstrip(if_name);
2176                 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2177                 if (rv != CONNECTION_ERROR_NONE) {
2178                         printf("Fail to remove the route [%d]\n", rv);
2179                         return -1;
2180                 }
2181                 printf("Remove Route successfully\n");
2182                 break;
2183
2184         default:
2185                 printf("Wrong IP address family!!\n");
2186                 return -1;
2187
2188         }
2189
2190         return 1;
2191
2192 }
2193
2194 int test_get_bt_state(void)
2195 {
2196         int rv = 0;
2197         connection_bt_state_e bt_state;
2198
2199         rv = connection_get_bt_state(connection, &bt_state);
2200
2201         if (rv != CONNECTION_ERROR_NONE) {
2202                 printf("Fail to get bluetooth state [%s]\n", test_print_error(rv));
2203                 return -1;
2204         }
2205
2206         printf("Retval = [%s], bluetooth state [%d]\n", test_print_error(rv), bt_state);
2207
2208         return 1;
2209 }
2210
2211 int test_get_profile_id(void)
2212 {
2213         connection_profile_h profile;
2214         char *profile_id;
2215
2216         printf("\n** Choose a profile to see profile id. **\n");
2217         if (test_get_user_selected_profile(&profile, true) == false)
2218                 return -1;
2219
2220         if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2221                 printf("Fail to get profile name\n");
2222                 return -1;
2223         } else {
2224                 printf("Profile id : %s\n", profile_id);
2225                 g_free(profile_id);
2226         }
2227
2228         return 1;
2229 }
2230
2231 int test_get_mac_address(void)
2232 {
2233         int rv = 0, type = 0;
2234         connection_type_e conn_type;
2235         char *mac_addr = NULL;
2236
2237         test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2238
2239         switch (type) {
2240         case 1:
2241                 conn_type = CONNECTION_TYPE_WIFI;
2242                 break;
2243         case 2:
2244                 conn_type = CONNECTION_TYPE_ETHERNET;
2245                 break;
2246         default:
2247                 printf("Wrong number!!\n");
2248                 return -1;
2249         }
2250
2251         rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2252
2253         if (rv != CONNECTION_ERROR_NONE) {
2254                 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2255                 return -1;
2256         }
2257
2258         printf("mac address is %s\n", mac_addr);
2259
2260         g_free(mac_addr);
2261
2262         return 1;
2263 }
2264
2265 int test_get_ethernet_cable_state(void)
2266 {
2267         int rv = 0;
2268         connection_ethernet_cable_state_e cable_state;
2269
2270         rv = connection_get_ethernet_cable_state(connection, &cable_state);
2271
2272         if (rv != CONNECTION_ERROR_NONE) {
2273                 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2274                 return -1;
2275         }
2276
2277         printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2278
2279         return 1;
2280 }
2281
2282 int test_get_dhcp_state(void)
2283 {
2284         int rv = 0;
2285         connection_dhcp_state_e dhcp_state;
2286         char if_name[40] = {0};
2287
2288         if (test_get_user_string("Input Interface name: ", if_name, 40) == false)
2289                 return -1;
2290
2291         g_strstrip(if_name);
2292
2293         rv = connection_get_dhcp_state(connection, if_name, &dhcp_state);
2294
2295         if (rv != CONNECTION_ERROR_NONE) {
2296                 printf("Fail to get DHCP state [%s]\n", test_print_error(rv));
2297                 return -1;
2298         }
2299
2300         printf("Retval = [%s], DHCP state [%d]\n", test_print_error(rv), dhcp_state);
2301
2302         return 1;
2303 }
2304
2305 int test_reset_profile(void)
2306 {
2307         int type, sim_id, rv;
2308
2309         rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2310
2311         if (rv == false || (type != 0 && type != 1)) {
2312                 printf("Invalid input!!\n");
2313                 return -1;
2314         }
2315
2316         rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2317
2318         if (rv == false || (sim_id != 0 && sim_id != 1)) {
2319                 printf("Invalid input!!\n");
2320                 return -1;
2321         }
2322
2323         if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2324                 return -1;
2325
2326         return 1;
2327 }
2328
2329 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2330 {
2331         printf("IPv6 Address : %s\n", ipv6_address);
2332         return true;
2333 }
2334
2335 int test_foreach_ipv6_address(void)
2336 {
2337         int rv = 0;
2338         int type = 0;
2339         connection_type_e conn_type;
2340
2341         test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2342
2343         switch (type) {
2344         case 1:
2345                 conn_type = CONNECTION_TYPE_WIFI;
2346                 break;
2347         case 2:
2348                 conn_type = CONNECTION_TYPE_ETHERNET;
2349                 break;
2350         default:
2351                 printf("Wrong number!!\n");
2352                 return -1;
2353         }
2354
2355         rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2356         if (rv != CONNECTION_ERROR_NONE) {
2357                 printf("Fail to get IPv6 address\n");
2358                 return -1;
2359         }
2360
2361         return 1;
2362 }
2363
2364 int test_is_metered_network(void)
2365 {
2366         int rv = 0;
2367         bool metered_state;
2368
2369         rv = connection_is_metered_network(connection, &metered_state);
2370
2371         if (rv != CONNECTION_ERROR_NONE) {
2372                 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2373                 return -1;
2374         }
2375
2376         printf("Retval = [%s] metered state [%s]\n",
2377                 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2378
2379         return 1;
2380 }
2381
2382 int test_start_tcpdump(void)
2383 {
2384         if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE)
2385                 return -1;
2386         printf("Successfully started tcpdump\n");
2387
2388         return 1;
2389 }
2390
2391 int test_stop_tcpdump(void)
2392 {
2393         if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE)
2394                 return -1;
2395         printf("Successfully stopped tcpdump\n");
2396
2397         return 1;
2398 }
2399
2400 int test_get_tcpdump_state(void)
2401 {
2402         gboolean tcpdump_state = FALSE;
2403
2404         if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE)
2405                 return -1;
2406         printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2407
2408         return 1;
2409 }
2410
2411 int test_mptcp_enable(void)
2412 {
2413         int rv = 0;
2414         bool supported = false;
2415         rv = connection_mptcp_is_supported(connection, &supported);
2416         if (rv != CONNECTION_ERROR_NONE) {
2417                 printf("Failure[%s]\n", test_print_error(rv));
2418                 return -1;
2419         }
2420         printf("MPTCP Support: %d\n", supported);
2421
2422         rv = connection_mptcp_enable(connection, CONNECTION_MPTCP_ENABLE_ALL);
2423         if (rv != CONNECTION_ERROR_NONE) {
2424                 printf("Failure[%s]\n", test_print_error(rv));
2425                 return -1;
2426         }
2427         return 1;
2428 }
2429
2430 int test_mptcp_disable(void)
2431 {
2432         int rv = 0;
2433         rv = connection_mptcp_disable(connection);
2434
2435         if (rv != CONNECTION_ERROR_NONE) {
2436                 printf("Failure[%s]\n", test_print_error(rv));
2437                 return -1;
2438         }
2439         return 1;
2440 }
2441
2442 int test_mptcp_set_path_manager(void)
2443 {
2444         int rv = 0;
2445         int input = 0;
2446         rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
2447
2448         switch (input) {
2449         case 1:
2450                 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_DEFAULT);
2451                 break;
2452         case 2:
2453                 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_FULLMESH);
2454                 break;
2455         default:
2456                 printf("Invalid input!!\n");
2457                 return -1;
2458         }
2459
2460         if (rv != CONNECTION_ERROR_NONE) {
2461                 printf("Failure[%s]\n", test_print_error(rv));
2462                 return -1;
2463         }
2464
2465         return 1;
2466 }
2467
2468 int test_mptcp_get_path_manager(void)
2469 {
2470         int rv = 0;
2471         connection_mptcp_path_manager_e pm;
2472
2473         rv = connection_mptcp_get_path_manager(connection, &pm);
2474         if (rv != CONNECTION_ERROR_NONE) {
2475                 printf("Failure[%s]\n", test_print_error(rv));
2476                 return -1;
2477         }
2478
2479         switch (pm) {
2480         case CONNECTION_MPTCP_PM_DEFAULT:
2481                 printf("Path Manager: Default\n");
2482                 break;
2483         case CONNECTION_MPTCP_PM_FULLMESH:
2484                 printf("Path Manager: FullMesh\n");
2485                 break;
2486         default:
2487                 printf("Error: Invalid Path Manager\n");
2488                 return -1;
2489         }
2490
2491         return 1;
2492 }
2493
2494 int test_mptcp_set_scheduler(void)
2495 {
2496         int rv = 0;
2497         int input = 0;
2498         rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
2499
2500         switch (input) {
2501         case 1:
2502                 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_DEFAULT);
2503                 break;
2504         case 2:
2505                 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
2506                 break;
2507         default:
2508                 printf("Invalid input!!\n");
2509                 return -1;
2510         }
2511
2512         if (rv != CONNECTION_ERROR_NONE) {
2513                 printf("Failure[%s]\n", test_print_error(rv));
2514                 return -1;
2515         }
2516
2517         return 1;
2518 }
2519
2520 int test_mptcp_get_scheduler(void)
2521 {
2522         int rv = 0;
2523         connection_mptcp_scheduler_e scheduler;
2524
2525         rv = connection_mptcp_get_scheduler(connection, &scheduler);
2526         if (rv != CONNECTION_ERROR_NONE) {
2527                 printf("Failure[%s]\n", test_print_error(rv));
2528                 return -1;
2529         }
2530
2531         switch (scheduler) {
2532         case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
2533                 printf("Scheduler: Default\n");
2534                 break;
2535         case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
2536                 printf("Scheduler: RountRobin\n");
2537                 break;
2538         default:
2539                 printf("Error: Invalid Scheduler\n");
2540                 return -1;
2541         }
2542
2543         return 1;
2544 }
2545
2546 int test_ethernet_eap_connect(void)
2547 {
2548         int rv;
2549         int input;
2550         bool enabled = false;
2551         int type = 0;
2552         int auth_type = 0;
2553         char input_str1[130];
2554         char input_str2[130];
2555         connection_profile_h profile;
2556
2557         printf("\n** Choose a ethernet profile to connect. **\n");
2558
2559         if (test_get_user_selected_profile(&profile, true) == false)
2560                 return -1;
2561
2562         test_get_user_int("Input options (0:Use LAN 1:Use EAPoL) :", &input);
2563         if (input == 1) {
2564                 if (connection_profile_enable_ethernet_eap(profile, true) != CONNECTION_ERROR_NONE) {
2565                         printf("Failed to enable EAP over Ethernet\n");
2566                         return -1;
2567                 }
2568         } else {
2569                 printf("Disabling EAPoL. Use proper option for normal Lan connection.\n");
2570                 if (connection_profile_enable_ethernet_eap(profile, false) != CONNECTION_ERROR_NONE)
2571                         printf("Failed to disable EAP over Ethernet\n");
2572                 return -1;
2573         }
2574
2575         if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE) {
2576                 printf("Failed to get ethernet eap enabled status!!\n");
2577                 return -1;
2578         }
2579
2580         printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2581
2582         printf("Input EAP type:\n");
2583         printf("0 -> CONNECTION_ETHERNET_EAP_TYPE_MD5\n");
2584         printf("1 -> CONNECTION_ETHERNET_EAP_TYPE_PEAP\n");
2585         printf("2 -> CONNECTION_ETHERNET_EAP_TYPE_TLS\n");
2586         printf("3 -> CONNECTION_ETHERNET_EAP_TYPE_TTLS\n");
2587         printf("4 -> CONNECTION_ETHERNET_EAP_TYPE_FAST\n");
2588         rv = scanf("%d", &type);
2589
2590         switch (type) {
2591         case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2592                 rv = connection_profile_set_ethernet_eap_type(profile, type);
2593                 if (rv != CONNECTION_ERROR_NONE) {
2594                         printf("Fail to set eap type : %s\n", test_print_error(rv));
2595                         return -1;
2596                 }
2597
2598                 printf("Input user name for ethernet:");
2599                 rv = scanf("%99s", input_str1);
2600
2601                 printf("Input password for ethernet:");
2602                 rv = scanf("%99s", input_str2);
2603
2604                 rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2605                 if (rv != CONNECTION_ERROR_NONE) {
2606                         printf("Fail to set eap passphrase : %s\n", test_print_error(rv));
2607                         return -1;
2608                 }
2609                 break;
2610
2611         case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2612                 {
2613                         rv = connection_profile_set_ethernet_eap_type(profile, type);
2614                         if (rv != CONNECTION_ERROR_NONE) {
2615                                 printf("Fail to set eap type : %s\n", test_print_error(rv));
2616                                 return -1;
2617                         }
2618
2619                         printf("Input user identity for ethernet:");
2620                         rv = scanf("%99s", input_str1);
2621
2622                         rv = connection_profile_set_ethernet_eap_identity(profile, input_str1);
2623                         if (rv != CONNECTION_ERROR_NONE) {
2624                                 printf("Fail to set eap identity : %s\n", test_print_error(rv));
2625                                 return -1;
2626                         }
2627
2628                         printf("Input user certificate for ethernet:");
2629                         rv = scanf("%129s", input_str1);
2630
2631                         rv = connection_profile_set_ethernet_eap_client_cert_file(profile, input_str1);
2632                         if (rv != CONNECTION_ERROR_NONE) {
2633                                 printf("Fail to set eap user cetificate : %s\n", test_print_error(rv));
2634                                 return -1;
2635                         }
2636
2637                         printf("Input CA certificate for ethernet:");
2638                         rv = scanf("%129s", input_str1);
2639
2640                         rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2641                         if (rv != CONNECTION_ERROR_NONE) {
2642                                 printf("Fail to set eap CA cetificate : %s\n", test_print_error(rv));
2643                                 return -1;
2644                         }
2645
2646                         printf("Input private key for ethernet:");
2647                         rv = scanf("%129s", input_str1);
2648
2649                         printf("Input private key password for ethernet:");
2650                         rv = scanf("%129s", input_str2);
2651
2652                         rv = connection_profile_set_ethernet_eap_private_key_info(profile, input_str1, input_str2);
2653                         if (rv != CONNECTION_ERROR_NONE) {
2654                                 printf("Fail to set eap private key  passphrase : %s\n", test_print_error(rv));
2655                                 return -1;
2656                         }
2657                 }
2658                 break;
2659
2660         case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2661                 {
2662                         rv = connection_profile_set_ethernet_eap_type(profile, type);
2663                         if (rv != CONNECTION_ERROR_NONE) {
2664                                 printf("Fail to set eap type : %s\n", test_print_error(rv));
2665                                 return -1;
2666                         }
2667
2668                         printf("Input anonymous_identity for PEAP ethernet:");
2669                         rv = scanf("%99s", input_str1);
2670
2671                         rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2672                         if (rv != CONNECTION_ERROR_NONE) {
2673                                 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2674                                 return -1;
2675                         }
2676
2677                         printf("Input CA file for PEAP ethernet:");
2678                         rv = scanf("%129s", input_str1);
2679
2680                         rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2681                         if (rv != CONNECTION_ERROR_NONE) {
2682                                 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2683                                 return -1;
2684                         }
2685
2686                         int peap_version = 0;
2687                         printf("Input peap version[ 0 ~ 2] for PEAP ethernet:");
2688                         rv = scanf("%1d", &peap_version);
2689
2690                         rv = connection_profile_set_ethernet_eap_peap_version(profile, peap_version);
2691                         if (rv != CONNECTION_ERROR_NONE) {
2692                                 printf("Fail to set eap peap version : %s\n", test_print_error(rv));
2693                                 return -1;
2694                         }
2695
2696                         printf("Input authentication type[3:MSCHAPV2 4:GTC 5:MD5] for PEAP ethernet:");
2697                         rv = scanf("%1d", &auth_type);
2698
2699                         rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2700                         if (rv != CONNECTION_ERROR_NONE) {
2701                                 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2702                                 return -1;
2703                         }
2704
2705                         printf("Input username for PEAP ethernet:");
2706                         rv = scanf("%129s", input_str1);
2707
2708                         printf("Input password for PEAP ethernet:");
2709                         rv = scanf("%129s", input_str2);
2710
2711                         rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2712                         if (rv != CONNECTION_ERROR_NONE) {
2713                                 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2714                                 return -1;
2715                         }
2716                 }
2717                 break;
2718
2719         case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2720                 {
2721                         rv = connection_profile_set_ethernet_eap_type(profile, type);
2722                         if (rv != CONNECTION_ERROR_NONE) {
2723                                 printf("Fail to set eap type : %s\n", test_print_error(rv));
2724                                 return -1;
2725                         }
2726
2727                         printf("Input anonymous_identity for TTLS ethernet:");
2728                         rv = scanf("%99s", input_str1);
2729
2730                         rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2731                         if (rv != CONNECTION_ERROR_NONE) {
2732                                 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2733                                 return -1;
2734                         }
2735
2736                         printf("Input CA file for TTLS ethernet:");
2737                         rv = scanf("%129s", input_str1);
2738
2739                         rv = connection_profile_set_ethernet_eap_ca_cert_file(profile, input_str1);
2740                         if (rv != CONNECTION_ERROR_NONE) {
2741                                 printf("Fail to set eap CA file : %s\n", test_print_error(rv));
2742                                 return -1;
2743                         }
2744
2745                         printf("Input authentication type[1:PAP, 2:MSCHAP, 3:MSCHAPV2] for TTLS ethernet:");
2746                         rv = scanf("%1d", &auth_type);
2747
2748                         rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2749                         if (rv != CONNECTION_ERROR_NONE) {
2750                                 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2751                                 return -1;
2752                         }
2753
2754                         printf("Input username for TTLS ethernet:");
2755                         rv = scanf("%129s", input_str1);
2756
2757                         printf("Input password for TTLS ethernet:");
2758                         rv = scanf("%129s", input_str2);
2759
2760                         rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2761                         if (rv != CONNECTION_ERROR_NONE) {
2762                                 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2763                                 return -1;
2764                         }
2765                 }
2766                 break;
2767
2768         case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2769                 {
2770                         rv = connection_profile_set_ethernet_eap_type(profile, type);
2771                         if (rv != CONNECTION_ERROR_NONE) {
2772                                 printf("Fail to set eap type : %s\n", test_print_error(rv));
2773                                 return -1;
2774                         }
2775
2776                         printf("Input anonymous_identity for FAST ethernet:");
2777                         rv = scanf("%99s", input_str1);
2778
2779                         rv = connection_profile_set_ethernet_eap_anonymous_identity(profile, input_str1);
2780                         if (rv != CONNECTION_ERROR_NONE) {
2781                                 printf("Fail to set eap anonymous_identity: %s\n", test_print_error(rv));
2782                                 return -1;
2783                         }
2784
2785                         printf("Input pac file for FAST ethernet:");
2786                         rv = scanf("%129s", input_str1);
2787
2788                         rv = connection_profile_set_ethernet_eap_pac_file(profile, input_str1);
2789                         if (rv != CONNECTION_ERROR_NONE) {
2790                                 printf("Fail to set eap pac file : %s\n", test_print_error(rv));
2791                                 return -1;
2792                         }
2793
2794                         printf("Input authentication type[3:MSCHAPV2, 4:GTC] for FAST ethernet:");
2795                         rv = scanf("%1d", &auth_type);
2796
2797                         rv = connection_profile_set_ethernet_eap_auth_type(profile, auth_type);
2798                         if (rv != CONNECTION_ERROR_NONE) {
2799                                 printf("Fail to set eap authentication type : %s\n", test_print_error(rv));
2800                                 return -1;
2801                         }
2802
2803                         printf("Input username for FAST ethernet:");
2804                         rv = scanf("%129s", input_str1);
2805
2806                         printf("Input password for FAST ethernet:");
2807                         rv = scanf("%129s", input_str2);
2808
2809                         rv = connection_profile_set_ethernet_eap_passphrase(profile, input_str1, input_str2);
2810                         if (rv != CONNECTION_ERROR_NONE) {
2811                                 printf("Fail to set eap username and password : %s\n", test_print_error(rv));
2812                                 return -1;
2813                         }
2814                 }
2815                 break;
2816
2817         default:
2818                 printf("Invalid EAP type\n");
2819                 return -1;
2820         }
2821
2822         rv = connection_profile_save_ethernet_eap_config(connection, profile);
2823         if (rv != CONNECTION_ERROR_NONE) {
2824                 printf("Fail to save eap config : %s\n", test_print_error(rv));
2825                 return -1;
2826         }
2827
2828         if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
2829                 printf("Connection open Failed!!\n");
2830                 return -1;
2831         }
2832
2833         return 1;
2834 }
2835
2836 static const char *test_print_eap_type(connection_ethernet_eap_type_e type)
2837 {
2838         switch (type) {
2839         case CONNECTION_ETHERNET_EAP_TYPE_MD5:
2840                 return "MD5";
2841         case CONNECTION_ETHERNET_EAP_TYPE_PEAP:
2842                 return "PEAP";
2843         case CONNECTION_ETHERNET_EAP_TYPE_TLS:
2844                 return "TLS";
2845         case CONNECTION_ETHERNET_EAP_TYPE_TTLS:
2846                 return "TTLS";
2847         case CONNECTION_ETHERNET_EAP_TYPE_FAST:
2848                 return "FAST";
2849         default:
2850                 return NULL;
2851         }
2852 }
2853
2854 static const char *test_print_eap_auth_type(connection_ethernet_eap_auth_type_e type)
2855 {
2856         switch (type) {
2857         case CONNECTION_ETHERNET_EAP_AUTH_TYPE_PAP:
2858                 return "PAP";
2859         case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAP:
2860                 return "MSCHAP";
2861         case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MSCHAPV2:
2862                 return "MSCHAPV2";
2863         case CONNECTION_ETHERNET_EAP_AUTH_TYPE_GTC:
2864                 return "GTC";
2865         case CONNECTION_ETHERNET_EAP_AUTH_TYPE_MD5:
2866                 return "MD5";
2867         case CONNECTION_ETHERNET_EAP_AUTH_TYPE_NONE:
2868                 return "NONE";
2869         default:
2870                 return NULL;
2871         }
2872 }
2873
2874 int test_get_eapol_info(void)
2875 {
2876         connection_profile_type_e prof_type;
2877         connection_profile_state_e profile_state;
2878         connection_profile_h profile;
2879         char *profile_name = NULL;
2880         connection_ethernet_eap_type_e type;
2881         connection_ethernet_eap_auth_type_e auth_type;
2882         connection_ethernet_eap_peap_version_e peapver;
2883         char *str = NULL;
2884
2885         printf("\n** Choose a ethernet profile to print eapol info. **\n");
2886         if (test_get_user_selected_profile(&profile, true) == false)
2887                 return -1;
2888
2889         bool enabled = false;
2890         if (connection_profile_is_ethernet_eap_enabled(profile, &enabled) != CONNECTION_ERROR_NONE)
2891                 printf("Failed to get ethernet eap enabled status!!\n");
2892         printf("EAP over Ethernet is %s\n", enabled ? "enabled" : "not enabled");
2893
2894         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
2895                 printf("Fail to get profile name\n");
2896                 return -1;
2897         } else {
2898                 printf("Profile Name : %s\n", profile_name);
2899                 g_free(profile_name);
2900         }
2901
2902         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE) {
2903                 printf("Fail to get profile type\n");
2904                 return -1;
2905         }
2906
2907         if (prof_type != CONNECTION_PROFILE_TYPE_ETHERNET) {
2908                 printf("Not ethernet profile\n");
2909                 return -1;
2910         }
2911
2912         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
2913                 printf("Fail to get profile state\n");
2914                 return -1;
2915         } else
2916                 printf("Profile State : %s\n", test_print_state(profile_state));
2917
2918
2919         if (connection_profile_get_ethernet_eap_type(profile, &type)  != CONNECTION_ERROR_NONE) {
2920                 printf("Fail to get eap type\n");
2921                 return -1;
2922         } else {
2923                 printf("eap_type: %s\n", test_print_eap_type(type));
2924         }
2925
2926         if (connection_profile_get_ethernet_eap_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2927                 printf("Fail to get eap identity\n");
2928                 return -1;
2929         } else {
2930                 printf("identity: %s\n", str);
2931                 g_free(str);
2932         }
2933
2934         if (type == CONNECTION_ETHERNET_EAP_TYPE_MD5)
2935                 goto out;
2936
2937         if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2938                         type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2939                 if (connection_profile_get_ethernet_eap_anonymous_identity(profile, &str) != CONNECTION_ERROR_NONE) {
2940                         printf("Fail to get eap anonymous_identity\n");
2941                         return -1;
2942                 } else {
2943                         printf("anonymous_identity: %s\n", str);
2944                         g_free(str);
2945                 }
2946         }
2947
2948         if (connection_profile_get_ethernet_eap_ca_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2949                 printf("Fail to get eap ca_cert_file\n");
2950                 return -1;
2951         } else {
2952                 printf("ca_cert_file: %s\n", str);
2953                 g_free(str);
2954         }
2955
2956         if (type == CONNECTION_ETHERNET_EAP_TYPE_TLS) {
2957                 if (connection_profile_get_ethernet_eap_client_cert_file(profile, &str) != CONNECTION_ERROR_NONE) {
2958                         printf("Fail to get eap client_cert_file\n");
2959                         return -1;
2960                 } else {
2961                         printf("client_cert_file: %s\n", str);
2962                         g_free(str);
2963                 }
2964
2965                 if (connection_profile_get_ethernet_eap_private_key_file(profile, &str) != CONNECTION_ERROR_NONE) {
2966                         printf("Fail to get eap private_key_file\n");
2967                         return -1;
2968                 } else {
2969                         printf("private_key_file: %s\n", str);
2970                         g_free(str);
2971                 }
2972         }
2973
2974         if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP || type == CONNECTION_ETHERNET_EAP_TYPE_TTLS ||
2975                         type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2976                 if (connection_profile_get_ethernet_eap_auth_type(profile, &auth_type) != CONNECTION_ERROR_NONE) {
2977                         printf("Fail to get eap auth type\n");
2978                         return -1;
2979                 } else {
2980                         printf("eap_auth: %s\n", test_print_eap_auth_type(auth_type));
2981                 }
2982         }
2983
2984         if (type == CONNECTION_ETHERNET_EAP_TYPE_PEAP) {
2985                 if (connection_profile_get_ethernet_eap_peap_version(profile, &peapver) != CONNECTION_ERROR_NONE) {
2986                         printf("Fail to get eap peap_version\n");
2987                         return -1;
2988                 } else {
2989                         printf("peap_version: %d\n", peapver);
2990                 }
2991         }
2992
2993         if (type == CONNECTION_ETHERNET_EAP_TYPE_FAST) {
2994                 if (connection_profile_get_ethernet_eap_pac_file(profile, &str) != CONNECTION_ERROR_NONE) {
2995                         printf("Fail to get eap pac_file\n");
2996                         return -1;
2997                 } else {
2998                         printf("pac_file: %s\n", str);
2999                         g_free(str);
3000                 }
3001         }
3002
3003 out:
3004         return 1;
3005 }
3006
3007 int test_get_clock_update_info(void)
3008 {
3009         int rv = 0;
3010         bool updated;
3011
3012         rv = connection_clock_is_updated(connection, &updated);
3013
3014         if (rv != CONNECTION_ERROR_NONE) {
3015                 printf("Fail to get clock update information [%s]\n", test_print_error(rv));
3016                 return -1;
3017         }
3018
3019         printf("Retval = [%s] clock updated [%s]\n",
3020                 test_print_error(rv), updated ? "TRUE" : "FALSE");
3021
3022         return 1;
3023 }
3024
3025 int test_set_ntp_server(void)
3026 {
3027         int rv = 0;
3028         char input_str1[100] = {0,};
3029
3030         if (test_get_user_string("Enter NTP Server Url (Enter for skip) :", input_str1, 100)) {
3031
3032                 g_strstrip(input_str1);
3033
3034                 rv = connection_set_ntp_server(connection, input_str1);
3035
3036                 if (rv != CONNECTION_ERROR_NONE) {
3037                         printf("Fail to set NTP Server [%s]\n", test_print_error(rv));
3038                         return -1;
3039                 }
3040
3041                 printf("Retval = [%s]\n",test_print_error(rv));
3042         }
3043
3044         return 1;
3045 }
3046
3047 int test_get_ntp_server(void)
3048 {
3049         int rv = 0;
3050         char *ntp_server;
3051
3052         rv = connection_get_ntp_server(connection, &ntp_server);
3053
3054         if (rv != CONNECTION_ERROR_NONE) {
3055                 printf("Fail to get ntp server [%s]\n", test_print_error(rv));
3056                 return -1;
3057         }
3058
3059         printf("Retval = [%s] NTP Server : [%s]\n", test_print_error(rv), ntp_server);
3060
3061         free(ntp_server);
3062
3063         return 1;
3064 }
3065
3066 int test_clear_ntp_server(void)
3067 {
3068         int rv = 0;
3069
3070         rv = connection_clear_ntp_server(connection);
3071
3072         if (rv != CONNECTION_ERROR_NONE) {
3073                 printf("Fail to clear ntp server[%s]\n", test_print_error(rv));
3074                 return -1;
3075         }
3076
3077         printf("Retval = [%s]\n", test_print_error(rv));
3078
3079         return 1;
3080 }
3081
3082 int main(int argc, char **argv)
3083 {
3084         GMainLoop *mainloop;
3085         mainloop = g_main_loop_new(NULL, FALSE);
3086
3087         GIOChannel *channel = g_io_channel_unix_new(0);
3088         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
3089
3090         printf("Test Thread created...\n");
3091
3092         g_main_loop_run(mainloop);
3093
3094         return 0;
3095 }
3096
3097 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
3098 {
3099         int rv = 0;
3100         char a[100];
3101
3102         memset(a, '\0', 100);
3103         printf("event received from stdin\n");
3104
3105         rv = read(0, a, 100);
3106
3107         if (rv < 0 || a[0] == '0') {
3108                 if (connection != NULL)
3109                         test_deregister_client();
3110
3111                 exit(1);
3112         }
3113
3114         if (*a == '\n' || *a == '\r') {
3115 /* Public API */
3116                 printf("\n\n Network Connection API Test App\n\n");
3117                 printf("Options..\n");
3118                 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
3119                 printf(LOG_GREEN "1   - Create Handle and set callbacks\n" LOG_END);
3120                 printf("2   - Destroy Handle(unset callbacks automatically)\n");
3121                 printf(LOG_GREEN "3   - Get network state\n" LOG_END);
3122                 printf(LOG_GREEN "4   - Get cellular state (please insert SIM Card)\n" LOG_END);
3123                 printf(LOG_GREEN "5   - Get wifi state (please turn on WiFi)\n" LOG_END);
3124                 printf("6   - Get current proxy address \n");
3125                 printf("7   - Get current Ip address\n");
3126                 printf("8   - Get cellular data call statistics\n");
3127                 printf("9   - Get WiFi data call statistics\n");
3128                 printf(LOG_GREEN "a   - Get Profile list\n" LOG_END);
3129                 printf(LOG_GREEN "b   - Get Connected Profile list\n" LOG_END);
3130                 printf(LOG_GREEN "c   - Get Current profile\n" LOG_END);
3131                 printf("d   - Open connection with profile\n");
3132                 printf("e   - Get default cellular service by type\n");
3133                 printf("f   - Set default cellular service by type\n");
3134                 printf("g   - Close connection with profile\n");
3135                 printf("h   - Add profile(Cellular and Wifi only)\n");
3136                 printf("i   - Remove profile(Cellular:delete, WiFi:forgot)\n");
3137                 printf("j   - Update profile\n");
3138                 printf("k   - Get profile info\n");
3139                 printf("l   - Refresh profile info\n");
3140                 printf("m   - Set state changed callback\n");
3141                 printf("n   - Unset state changed callback\n");
3142                 printf("o   - Reset cellular data call statistics\n");
3143                 printf("p   - Reset WiFi data call statistics\n");
3144                 printf("q   - Add new route\n");
3145                 printf("r   - Remove a route\n");
3146                 printf("s   - Get bluetooth state\n");
3147                 printf("t   - Get profile id\n");
3148                 printf("u   - Reset profile\n");
3149                 printf("v   - Get all cellular default profiles\n");
3150                 printf("w   - Get mac address\n");
3151                 printf("x   - Get ethernet cable state\n");
3152                 printf("y   - Get DHCP state\n");
3153                 printf("B   - Add IPv6 new route\n");
3154                 printf("C   - Remove IPv6 route\n");
3155                 printf("D   - Add new route entry\n");
3156                 printf("E   - Remove route entry\n");
3157                 printf("F   - Get all IPv6 address\n");
3158                 printf("G   - Get metered state\n");
3159 /* Extension API */
3160                 printf(LOG_BLUE "[Extension API]\n" LOG_END);
3161                 printf("H   - Start TCP Dump\n");
3162                 printf("I   - Stop TCP Dump\n");
3163                 printf("J   - Get TCP Dump State\n");
3164                 printf("K   - Enable MPTCP (internal)\n");
3165                 printf("L   - Disable MPTCP (internal)\n");
3166                 printf("M   - Set MPTCP Path Manager (internal)\n");
3167                 printf("N   - Get MPTCP Path Manager (internal)\n");
3168                 printf("O   - Set MPTCP Scheduler (internal)\n");
3169                 printf("P   - Get MPTCP Scheduler (internal)\n");
3170                 printf(LOG_GREEN "Q   - Create Handle and set callbacks in C# API\n" LOG_END);
3171                 printf("R   - Destroy Handle(unset callbacks automatically in C# API)\n");
3172                 printf("S   - Connect Ethernet EAP)\n");
3173                 printf("T   - Get EAPoL info)\n");
3174                 printf("U   - Get Clock update info)\n");
3175                 printf("V   - Set NTP Server\n");
3176                 printf("W   - Get NTP Server\n");
3177                 printf("X   - Clear NTP Server\n");
3178                 printf(LOG_RED "0   - Exit \n" LOG_END);
3179                 printf("ENTER   - Show options menu.......\n");
3180         }
3181
3182         switch (a[0]) {
3183 /* Public API */
3184         case '1':
3185                 rv = test_register_client();
3186                 break;
3187         case '2':
3188                 rv = test_deregister_client();
3189                 break;
3190         case '3':
3191                 rv = test_get_network_state();
3192                 break;
3193         case '4':
3194                 rv = test_get_cellular_state();
3195                 break;
3196         case '5':
3197                 rv = test_get_wifi_state();
3198                 break;
3199         case '6':
3200                 rv = test_get_current_proxy();
3201                 break;
3202         case '7':
3203                 rv = test_get_current_ip();
3204                 break;
3205         case '8':
3206                 rv = test_get_call_statistics_info();
3207                 break;
3208         case '9':
3209                 rv = test_get_wifi_call_statistics_info();
3210                 break;
3211         case 'a':
3212                 rv = test_get_profile_list();
3213                 break;
3214         case 'b':
3215                 rv = test_get_connected_profile_list();
3216                 break;
3217         case 'c':
3218                 rv = test_get_current_profile();
3219                 break;
3220         case 'd':
3221                 rv = test_open_profile();
3222                 break;
3223         case 'e':
3224                 rv = test_get_default_cellular_service_type();
3225                 break;
3226         case 'f':
3227                 rv = test_set_default_cellular_service_type();
3228                 break;
3229         case 'g':
3230                 rv = test_close_profile();
3231                 break;
3232         case 'h':
3233                 rv = test_add_profile();
3234                 break;
3235         case 'i':
3236                 rv = test_remove_profile();
3237                 break;
3238         case 'j':
3239                 rv = test_update_profile();
3240                 break;
3241         case 'k':
3242                 rv = test_get_profile_info();
3243                 break;
3244         case 'l':
3245                 rv = test_refresh_profile_info();
3246                 break;
3247         case 'm':
3248                 rv = test_set_state_changed_callback();
3249                 break;
3250         case 'n':
3251                 rv = test_unset_state_changed_callback();
3252                 break;
3253         case 'o':
3254                 rv = test_reset_call_statistics_info();
3255                 break;
3256         case 'p':
3257                 rv = test_reset_wifi_call_statistics_info();
3258                 break;
3259         case 'q':
3260                 rv = test_add_route();
3261                 break;
3262         case 'r':
3263                 rv = test_remove_route();
3264                 break;
3265         case 's':
3266                 rv = test_get_bt_state();
3267                 break;
3268         case 't':
3269                 rv = test_get_profile_id();
3270                 break;
3271         case 'u':
3272                 rv = test_reset_profile();
3273                 break;
3274         case 'v':
3275                 rv = test_get_default_profile_list();
3276                 break;
3277         case 'w':
3278                 rv = test_get_mac_address();
3279                 break;
3280         case 'x':
3281                 rv = test_get_ethernet_cable_state();
3282                 break;
3283         case 'y':
3284                 rv = test_get_dhcp_state();
3285                 break;
3286         case 'B':
3287                 rv = test_add_route_ipv6();
3288                 break;
3289         case 'C':
3290                 rv = test_remove_route_ipv6();
3291                 break;
3292         case 'D':
3293                 rv = test_add_route_entry();
3294                 break;
3295         case 'E':
3296                 rv = test_remove_route_entry();
3297                 break;
3298         case 'F':
3299                 rv = test_foreach_ipv6_address();
3300                 break;
3301         case 'G':
3302                 rv = test_is_metered_network();
3303                 break;
3304 /* Extension API */
3305         case 'H':
3306                 rv = test_start_tcpdump();
3307                 break;
3308         case 'I':
3309                 rv = test_stop_tcpdump();
3310                 break;
3311         case 'J':
3312                 rv = test_get_tcpdump_state();
3313                 break;
3314         case 'K':
3315                 rv = test_mptcp_enable();
3316                 break;
3317         case 'L':
3318                 rv = test_mptcp_disable();
3319                 break;
3320         case 'M':
3321                 rv = test_mptcp_set_path_manager();
3322                 break;
3323         case 'N':
3324                 rv = test_mptcp_get_path_manager();
3325                 break;
3326         case 'O':
3327                 rv = test_mptcp_set_scheduler();
3328                 break;
3329         case 'P':
3330                 rv = test_mptcp_get_scheduler();
3331                 break;
3332         case 'Q':
3333                 rv = test_register_client_cs();
3334                 break;
3335         case 'R':
3336                 rv = test_deregister_client_cs();
3337                 break;
3338         case 'S':
3339                 rv = test_ethernet_eap_connect();
3340                 break;
3341         case 'T':
3342                 rv = test_get_eapol_info();
3343                 break;
3344         case 'U':
3345                 rv = test_get_clock_update_info();
3346                 break;
3347         case 'V':
3348                 rv = test_set_ntp_server();
3349                 break;
3350         case 'W':
3351                 rv = test_get_ntp_server();
3352                 break;
3353         case 'X':
3354                 rv = test_clear_ntp_server();
3355                 break;
3356         }
3357
3358         if (rv == 1)
3359                 printf("Operation succeeded!\n");
3360         else
3361                 printf("Operation failed!\n");
3362
3363         return TRUE;
3364 }