Merge "Remove DEPRECATED connection_set_ethernet_cable_state_chaged_cb() call" into...
[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_cellular_service_type(connection_cellular_service_type_e type)
158 {
159         switch (type) {
160         case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
161                 return "Unknown";
162         case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
163                 return "Internet";
164         case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
165                 return "MMS";
166         case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
167                 return "Prepaid internet";
168         case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
169                 return "Prepaid MMS";
170         case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
171                 return "Tethering";
172         case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
173                 return "Application";
174         default:
175                 return "Unknown";
176         }
177 }
178
179 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
180 {
181         switch (type) {
182         case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
183                 return "PAP";
184         case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
185                 return "CHAP";
186         case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
187         default:
188                 return "None";
189         }
190 }
191
192 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
193 {
194         switch (type) {
195         case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
196                 return "IPv4";
197         case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
198                 return "IPv6";
199         case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
200                 return "Dual";
201         case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
202         default:
203                 return "Unknown";
204         }
205 }
206
207 static const char *test_print_error(connection_error_e error)
208 {
209         switch (error) {
210         case CONNECTION_ERROR_NONE:
211                 return "CONNECTION_ERROR_NONE";
212         case CONNECTION_ERROR_INVALID_PARAMETER:
213                 return "CONNECTION_ERROR_INVALID_PARAMETER";
214         case CONNECTION_ERROR_OUT_OF_MEMORY:
215                 return "CONNECTION_ERROR_OUT_OF_MEMORY";
216         case CONNECTION_ERROR_INVALID_OPERATION:
217                 return "CONNECTION_ERROR_INVALID_OPERATION";
218         case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
219                 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
220         case CONNECTION_ERROR_OPERATION_FAILED:
221                 return "CONNECTION_ERROR_OPERATION_FAILED";
222         case CONNECTION_ERROR_ITERATOR_END:
223                 return "CONNECTION_ERROR_ITERATOR_END";
224         case CONNECTION_ERROR_NO_CONNECTION:
225                 return "CONNECTION_ERROR_NO_CONNECTION";
226         case CONNECTION_ERROR_NOW_IN_PROGRESS:
227                 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
228         case CONNECTION_ERROR_ALREADY_EXISTS:
229                 return "CONNECTION_ERROR_ALREADY_EXISTS";
230         case CONNECTION_ERROR_OPERATION_ABORTED:
231                 return "CONNECTION_ERROR_OPERATION_ABORTED";
232         case CONNECTION_ERROR_DHCP_FAILED:
233                 return "CONNECTION_ERROR_DHCP_FAILED";
234         case CONNECTION_ERROR_INVALID_KEY:
235                 return "CONNECTION_ERROR_INVALID_KEY";
236         case CONNECTION_ERROR_NO_REPLY:
237                 return "CONNECTION_ERROR_NO_REPLY";
238         case CONNECTION_ERROR_PERMISSION_DENIED:
239                 return "CONNECTION_ERROR_PERMISSION_DENIED";
240         case CONNECTION_ERROR_NOT_SUPPORTED:
241                 return "CONNECTION_ERROR_NOT_SUPPORTED";
242         case CONNECTION_ERROR_NOT_INITIALIZED:
243                 return "CONNECTION_ERROR_NOT_INITIALIZED";
244         case CONNECTION_ERROR_ALREADY_INITIALIZED:
245                 return "CONNECTION_ERROR_ALREADY_INITIALIZED";
246         default:
247                 return "CONNECTION_ERROR_UNKNOWN";
248         }
249 }
250
251 static void test_type_changed_callback(connection_type_e type, void* user_data)
252 {
253         printf("Type changed callback, connection type : %d\n", type);
254 }
255
256 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
257 {
258         printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
259                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
260 }
261
262 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
263 {
264         printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
265                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
266 }
267
268 static void test_internet_state_changed_callback(connection_internet_state_e state, void* user_data)
269 {
270         printf("Internet state changed callback, state : %d\n", state);
271 }
272
273 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
274 {
275         char *profile_name;
276         connection_profile_h profile = user_data;
277
278         if (profile == NULL)
279                 return;
280
281         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
282                 return;
283
284         printf("[%s] : %s\n", test_print_state(state), profile_name);
285         g_free(profile_name);
286 }
287
288 static void test_connection_opened_callback(connection_error_e result, void* user_data)
289 {
290         if (result ==  CONNECTION_ERROR_NONE)
291                 printf("Connection open Succeeded\n");
292         else
293                 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
294 }
295
296 static void test_connection_closed_callback(connection_error_e result, void* user_data)
297 {
298         if (result ==  CONNECTION_ERROR_NONE)
299                 printf("Connection close Succeeded\n");
300         else
301                 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
302 }
303
304 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
305 {
306         if (result ==  CONNECTION_ERROR_NONE)
307                 printf("Reset profile Succeeded\n");
308         else
309                 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
310 }
311
312 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
313 {
314         if (result ==  CONNECTION_ERROR_NONE)
315                 printf("Default profile setting Succeeded\n");
316         else
317                 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
318 }
319
320 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
321                                                                 void* user_data)
322 {
323         if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
324                 printf("Ethernet Cable Connected\n");
325         else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
326                 printf("Ethernet Cable Disconnected\n");
327 }
328
329 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
330 {
331         int rv = 0;
332         int input = 0;
333         char *profile_name;
334         connection_profile_type_e profile_type;
335         connection_profile_state_e profile_state;
336         connection_profile_iterator_h profile_iter;
337         connection_profile_h profile_h;
338
339         connection_profile_h profile_list[100] = {0,};
340         int profile_count = 0;
341
342         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
343         if (rv != CONNECTION_ERROR_NONE) {
344                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
345                 return false;
346         }
347
348         while (connection_profile_iterator_has_next(profile_iter)) {
349                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
350                         printf("Fail to get profile handle\n");
351                         return false;
352                 }
353
354                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
355                         printf("Fail to get profile name\n");
356                         return false;
357                 }
358
359                 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
360                         printf("Fail to get profile type\n");
361                         g_free(profile_name);
362                         return false;
363                 }
364
365                 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
366                         printf("Fail to get profile state\n");
367                         g_free(profile_name);
368                         return false;
369                 }
370
371                 printf("%d. state:[%s], profile name:%s", profile_count,
372                                 test_print_state(profile_state), profile_name);
373                 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
374                         connection_cellular_service_type_e service_type;
375                         if (connection_profile_get_cellular_service_type(
376                                 profile_h, &service_type) !=
377                                 CONNECTION_ERROR_NONE)
378                                 printf("Fail to get cellular service type!\n");
379
380                         printf("[%s]",
381                                 test_print_cellular_service_type(service_type));
382                 }
383                 printf("\n");
384
385                 profile_list[profile_count] = profile_h;
386                 profile_count++;
387
388                 g_free(profile_name);
389                 if (profile_count >= 100)
390                         break;
391         }
392
393         if (select == false)
394                 return true;
395
396         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
397             input >= profile_count ||
398             input < 0) {
399                 printf("Wrong number!!\n");
400                 return false;
401         }
402
403         if (profile)
404                 *profile = profile_list[input];
405
406         return true;
407 }
408
409 static int test_update_cellular_info(connection_profile_h profile)
410 {
411         int rv = 0;
412         char input_str1[100] = {0,};
413         char input_str2[100] = {0,};
414         int input_int = 0;
415         int type_val = 0;
416
417         if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
418                         "Prepaid MMS:4, Tethering:5, Application:6)"
419                         " - (Enter for skip) :", &input_int)) {
420                 switch (input_int) {
421                 case 1:
422                         rv = connection_profile_set_cellular_service_type(profile,
423                                         CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
424                         break;
425                 case 2:
426                         rv = connection_profile_set_cellular_service_type(profile,
427                                         CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
428                         break;
429                 case 3:
430                         rv = connection_profile_set_cellular_service_type(profile,
431                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
432                         break;
433                 case 4:
434                         rv = connection_profile_set_cellular_service_type(profile,
435                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
436                         break;
437                 case 5:
438                         rv = connection_profile_set_cellular_service_type(profile,
439                                         CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
440                         break;
441                 case 6:
442                         rv = connection_profile_set_cellular_service_type(profile,
443                                         CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
444                         break;
445                 default:
446                         return -1;
447                 }
448
449                 if (rv != CONNECTION_ERROR_NONE)
450                         return -1;
451         } else
452                 return -1;
453
454         if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
455                 g_strstrip(input_str1);
456                 rv = connection_profile_set_cellular_apn(profile, input_str1);
457                 if (rv != CONNECTION_ERROR_NONE)
458                         return -1;
459         }
460
461         if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
462                 g_strstrip(input_str1);
463                 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
464                 if (rv != CONNECTION_ERROR_NONE)
465                         return -1;
466         }
467
468         if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
469                 g_strstrip(input_str1);
470                 rv = connection_profile_set_cellular_home_url(profile, input_str1);
471                 if (rv != CONNECTION_ERROR_NONE)
472                         return -1;
473         }
474
475         if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
476                 switch (input_int) {
477                 case 0:
478                         rv = connection_profile_set_cellular_auth_info(profile,
479                                         CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
480                         if (rv != CONNECTION_ERROR_NONE)
481                                 return -1;
482
483                         break;
484                 case 1:
485                         type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
486                         /* fall through */
487                 case 2:
488                         if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
489
490                         if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
491                                 input_str1[0] = 0;
492                         if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
493                                 input_str2[0] = 0;
494
495                         g_strstrip(input_str1);
496                         g_strstrip(input_str2);
497                         rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
498                         if (rv != CONNECTION_ERROR_NONE)
499                                 return -1;
500                 }
501         }
502
503         if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
504                 switch (input_int) {
505                 case 1:
506                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
507                         break;
508                 case 2:
509                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
510                         break;
511                 case 3:
512                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
513                         break;
514                 }
515
516                 if (rv != CONNECTION_ERROR_NONE)
517                         return -1;
518         }
519
520         if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
521                 switch (input_int) {
522                 case 1:
523                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
524                         break;
525                 case 2:
526                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
527                         break;
528                 case 3:
529                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
530                         break;
531                 }
532
533                 if (rv != CONNECTION_ERROR_NONE)
534                         return -1;
535         }
536
537         return 1;
538 }
539
540 static int test_update_wifi_info(connection_profile_h profile)
541 {
542         int rv = 0;
543         char input_str[100] = {0,};
544
545         if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
546                 rv = connection_profile_set_wifi_passphrase(profile, input_str);
547                 if (rv != CONNECTION_ERROR_NONE)
548                         return -1;
549         }
550
551         return 1;
552 }
553
554 static int test_update_dns_info(connection_profile_h profile,
555                 connection_address_family_e address_family)
556 {
557         int rv = 0;
558         char input_str[100] = {0,};
559         if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
560                 rv = connection_profile_set_dns_address(profile,
561                                 1,
562                                 address_family,
563                                 input_str);
564                 if (rv != CONNECTION_ERROR_NONE)
565                         return -1;
566
567                 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
568                         rv = connection_profile_set_dns_address(profile,
569                                         2,
570                                         address_family,
571                                         input_str);
572                         if (rv != CONNECTION_ERROR_NONE)
573                                 return -1;
574                 }
575         }
576         return 1;
577 }
578
579 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
580 {
581         int rv = 0;
582         int input_int = 0;
583         char input_str[100] = {0,};
584
585         if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
586                 rv = connection_profile_set_ip_address(profile,
587                                                         address_family,
588                                                         input_str);
589                 if (rv != CONNECTION_ERROR_NONE)
590                         return -1;
591         }
592
593         if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
594                 rv = connection_profile_set_subnet_mask(profile,
595                                                         address_family,
596                                                         input_str);
597                 if (rv != CONNECTION_ERROR_NONE)
598                         return -1;
599         }
600
601         if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
602                 rv = connection_profile_set_prefix_length(profile,
603                                                         address_family,
604                                                         input_int);
605                 if (rv != CONNECTION_ERROR_NONE)
606                         return -1;
607         }
608
609         if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
610                 rv = connection_profile_set_gateway_address(profile,
611                                                         address_family,
612                                                         input_str);
613                 if (rv != CONNECTION_ERROR_NONE)
614                         return -1;
615         }
616
617         if (test_update_dns_info(profile, address_family) < 0)
618                 return -1;
619
620         return 1;
621 }
622
623 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
624 {
625         int rv = 0;
626         int input_int = 0;
627         char input_str[100] = {0,};
628
629         if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
630                                         " - (Enter for skip) :", &input_int)) {
631                 switch (input_int) {
632                 case 1:
633                         rv = connection_profile_set_proxy_type(profile,
634                                         CONNECTION_PROXY_TYPE_DIRECT);
635
636                         if (rv != CONNECTION_ERROR_NONE)
637                                 return -1;
638                         else
639                                 return 1;
640                 case 2:
641                         rv = connection_profile_set_proxy_type(profile,
642                                         CONNECTION_PROXY_TYPE_AUTO);
643                         break;
644                 case 3:
645                         rv = connection_profile_set_proxy_type(profile,
646                                         CONNECTION_PROXY_TYPE_MANUAL);
647                         break;
648                 default:
649                         return -1;
650                 }
651
652                 if (rv != CONNECTION_ERROR_NONE)
653                         return -1;
654
655                 if (test_get_user_string("Input auto Proxy URL or Proxy address"
656                                         " - (Enter for skip) :", input_str, 100)) {
657                         rv = connection_profile_set_proxy_address(profile,
658                                                                 address_family,
659                                                                 input_str);
660                         if (rv != CONNECTION_ERROR_NONE)
661                                 return -1;
662                 }
663
664         } else
665                 return -1;
666
667         return 1;
668 }
669
670
671
672 static int test_update_network_info(connection_profile_h profile)
673 {
674         int rv = 0;
675         int input_int = 0;
676         int dns_input = 0;
677         int address_family = 0;
678
679         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
680
681         if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
682                                 " - (Enter for skip) :", &input_int)) {
683                 switch (input_int) {
684                 case 1:
685                         rv = connection_profile_set_ip_config_type(profile,
686                                         address_family,
687                                         CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
688                         if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
689                                                 " - (Enter for skip) :", &dns_input)) {
690                                 switch (dns_input) {
691                                 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
692                                         rv = connection_profile_set_dns_config_type(
693                                                         profile,
694                                                         address_family,
695                                                         CONNECTION_DNS_CONFIG_TYPE_STATIC);
696                                         if (rv != CONNECTION_ERROR_NONE)
697                                                 return -1;
698                                         if (test_update_dns_info(profile,
699                                                                 address_family) == -1)
700                                                 return -1;
701                                         break;
702                                 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
703                                         rv = connection_profile_set_dns_config_type(
704                                                         profile,
705                                                         address_family,
706                                                         CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
707                                         if (rv != CONNECTION_ERROR_NONE)
708                                                 return -1;
709                                         break;
710                                 }
711                         }
712                         break;
713                 case 2:
714                         rv = connection_profile_set_ip_config_type(profile,
715                                                                    address_family,
716                                                                    CONNECTION_IP_CONFIG_TYPE_STATIC);
717                         if (rv != CONNECTION_ERROR_NONE)
718                                 return -1;
719
720                         if (test_update_ip_info(profile, address_family) == -1)
721                                 return -1;
722
723                         if (test_update_proxy_info(profile, address_family) == -1)
724                                 return -1;
725                         break;
726                 case 3:
727                         rv = connection_profile_set_ip_config_type(profile,
728                                                                 address_family,
729                                                                 CONNECTION_IP_CONFIG_TYPE_AUTO);
730                         break;
731                 default:
732                         return -1;
733                 }
734
735                 if (rv != CONNECTION_ERROR_NONE)
736                         return -1;
737         } else
738                 return -1;
739
740         return 1;
741 }
742
743 static void test_print_cellular_info(connection_profile_h profile)
744 {
745         connection_cellular_service_type_e service_type;
746         connection_cellular_pdn_type_e pdn_type;
747         connection_cellular_pdn_type_e roam_pdn_type;
748         char *apn = NULL;
749         connection_cellular_auth_type_e auth_type;
750         char *user_name = NULL;
751         char *password = NULL;
752         char *home_url = NULL;
753         bool roaming = false;
754         bool hidden = false;
755         bool editable = false;
756
757         if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
758                 printf("Fail to get cellular service type!\n");
759         else
760                 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
761
762         if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
763                 printf("Fail to get cellular pdn type!\n");
764         else
765                 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
766
767         if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
768                 printf("Fail to get cellular roam pdn type!\n");
769         else
770                 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
771
772         if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
773                 printf("Fail to get cellular APN!\n");
774         else {
775                 printf("Cellular APN : %s\n", apn);
776                 g_free(apn);
777         }
778
779         if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
780                 printf("Fail to get auth info!\n");
781         else {
782                 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
783                 printf("Cellular user_name : %s\n", user_name);
784                 printf("Cellular password : %s\n", password);
785                 g_free(user_name);
786                 g_free(password);
787         }
788
789         if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
790                 printf("Fail to get cellular home url!\n");
791         else {
792                 printf("Cellular home url : %s\n", home_url);
793                 g_free(home_url);
794         }
795
796         if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
797                 printf("Fail to get cellular roaming state!\n");
798         else
799                 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
800
801         if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
802                 printf("Fail to get cellular hidden state!\n");
803         else
804                 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
805
806         if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
807                 printf("Fail to get cellular editing state!\n");
808         else
809                 printf("Cellular editable : %s\n", editable ? "true" : "false");
810 }
811
812 static void test_print_wifi_info(connection_profile_h profile)
813 {
814         char *essid = NULL;
815         char *bssid = NULL;
816         int rssi = 0;
817         int frequency = 0;
818         int max_speed = 0;
819         connection_wifi_security_type_e security_type;
820         connection_wifi_encryption_type_e encryption_type;
821         bool pass_required = false;
822         bool wps_supported = false;
823
824         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
825                 printf("Fail to get Wi-Fi essid!\n");
826         else {
827                 printf("Wi-Fi essid : %s\n", essid);
828                 g_free(essid);
829         }
830
831         if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
832                 printf("Fail to get Wi-Fi bssid!\n");
833         else {
834                 printf("Wi-Fi bssid : %s\n", bssid);
835                 g_free(bssid);
836         }
837
838         if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
839                 printf("Fail to get Wi-Fi rssi!\n");
840         else
841                 printf("Wi-Fi rssi : %d\n", rssi);
842
843         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
844                 printf("Fail to get Wi-Fi frequency!\n");
845         else
846                 printf("Wi-Fi frequency : %d\n", frequency);
847
848         if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
849                 printf("Fail to get Wi-Fi max speed!\n");
850         else
851                 printf("Wi-Fi max speed : %d\n", max_speed);
852
853         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
854                 printf("Fail to get Wi-Fi security type!\n");
855         else
856                 printf("Wi-Fi security type : %d\n", security_type);
857
858         if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
859                 printf("Fail to get Wi-Fi encryption type!\n");
860         else
861                 printf("Wi-Fi encryption type : %d\n", encryption_type);
862
863         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
864                 printf("Fail to get Wi-Fi passphrase required!\n");
865         else
866                 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
867
868         if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
869                 printf("Fail to get Wi-Fi wps info\n");
870         else
871                 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
872 }
873
874 static void test_print_mesh_info(connection_profile_h profile)
875 {
876         char *essid = NULL;
877         char *bssid = NULL;
878         int rssi = 0;
879         int frequency = 0;
880         connection_wifi_security_type_e security_type;
881         bool pass_required = false;
882
883         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
884                 printf("Fail to get Mesh essid!\n");
885         else {
886                 printf("Mesh 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 Mesh bssid!\n");
892         else {
893                 printf("Mesh 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 Mesh rssi!\n");
899         else
900                 printf("Mesh rssi : %d\n", rssi);
901
902         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
903                 printf("Fail to get Mesh frequency!\n");
904         else
905                 printf("Mesh frequency : %d\n", frequency);
906
907         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
908                 printf("Fail to get Mesh security type!\n");
909         else
910                 printf("Mesh security type : %d\n", security_type);
911
912         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
913                 printf("Fail to get Mesh passphrase required!\n");
914         else
915                 printf("Mesh passphrase required : %s\n", pass_required ? "true" : "false");
916 }
917
918 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
919 {
920         char *interface_name = NULL;
921         char *ip = NULL;
922         char *subnet = NULL;
923         char *gateway = NULL;
924         char *dhcp_server = NULL;
925         int dhcp_lease_duration = 0;
926         char *dns1 = NULL;
927         char *dns2 = NULL;
928         char *proxy = NULL;
929         int prefix_len;
930         connection_ip_config_type_e ip_type;
931         connection_proxy_type_e proxy_type;
932         connection_dns_config_type_e dns_type;
933
934         if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
935                 printf("Fail to get interface name!\n");
936         else {
937                 printf("Interface name : %s\n", interface_name);
938                 g_free(interface_name);
939         }
940
941         if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
942                 printf("Fail to get ipconfig type!\n");
943         else {
944                 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
945                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
946                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
947                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
948                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
949                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
950                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
951                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
952                 else
953                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
954         }
955
956         if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
957                 printf("Fail to get IP address!\n");
958         else {
959                 printf("IP address : %s\n", ip);
960                 g_free(ip);
961         }
962
963         if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
964                 printf("Fail to get gateway!\n");
965         else {
966                 printf("Gateway : %s\n", gateway);
967                 g_free(gateway);
968         }
969
970         if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
971                 printf("Fail to get DHCP Server address!\n");
972         else {
973                 printf("DHCP Server : %s\n", dhcp_server);
974                 g_free(dhcp_server);
975         }
976
977         if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
978                 printf("Fail to get DHCP lease duration!\n");
979         else {
980                 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
981         }
982
983         if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
984                 printf("Fail to get subnet mask!\n");
985         else {
986                 printf("Subnet mask : %s\n", subnet);
987                 g_free(subnet);
988         }
989
990         if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
991                 printf("Fail to get prefix length!\n");
992         else
993                 printf("Prefix length : %d\n", prefix_len);
994
995         if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
996                 printf("Fail to get DNS configuration type!\n");
997         else {
998                 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
999                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
1000                 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
1001                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
1002                 else
1003                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
1004         }
1005
1006         if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
1007                 printf("Fail to get DNS1!\n");
1008         else {
1009                 printf("DNS1 : %s\n", dns1);
1010                 g_free(dns1);
1011         }
1012
1013         if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
1014                 printf("Fail to get DNS2!\n");
1015         else {
1016                 printf("DNS2 : %s\n", dns2);
1017                 g_free(dns2);
1018         }
1019
1020         if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
1021                 printf("Fail to get proxy type!\n");
1022         else {
1023                 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
1024                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
1025                 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
1026                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
1027                 else
1028                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
1029         }
1030
1031         if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
1032                 printf("Fail to get proxy!\n");
1033         else {
1034                 printf("Proxy : %s\n", proxy);
1035                 g_free(proxy);
1036         }
1037 }
1038
1039 int test_register_client(void)
1040 {
1041
1042         int err = connection_create(&connection);
1043
1044         if (CONNECTION_ERROR_NONE == err) {
1045                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1046                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1047                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1048                 connection_set_ethernet_cable_state_changed_cb(connection,
1049                                         test_get_ethernet_cable_state_callback, NULL);
1050                 connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
1051         } else {
1052                 printf("Client registration failed [%s]\n", test_print_error(err));
1053                 return -1;
1054         }
1055
1056         printf("Client registration success\n");
1057         return 1;
1058 }
1059
1060 int  test_deregister_client(void)
1061 {
1062         int rv = 0;
1063         GSList *list;
1064         connection_profile_h profile;
1065
1066         if (connection != NULL)
1067                 rv = connection_destroy(connection);
1068         else {
1069                 printf("Cannot deregister : Handle is NULL\n");
1070                 rv = CONNECTION_ERROR_INVALID_OPERATION;
1071         }
1072
1073         if (rv != CONNECTION_ERROR_NONE) {
1074                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1075                 return -1;
1076         }
1077
1078         if (state_cb_list) {
1079                 for (list = state_cb_list; list; list = list->next) {
1080                         profile = list->data;
1081                         connection_profile_destroy(profile);
1082                 }
1083
1084                 g_slist_free(state_cb_list);
1085                 state_cb_list = NULL;
1086         }
1087
1088         connection = NULL;
1089         printf("Client deregistration success\n");
1090
1091         return 1;
1092 }
1093
1094 int test_register_client_cs(void)
1095 {
1096         int tid = 0;
1097         test_get_user_int("Input a TID in C# API :", &tid);
1098
1099         int err = connection_create_cs(tid, &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         } else {
1108                 printf("Client registration failed [%s]\n", test_print_error(err));
1109                 return -1;
1110         }
1111
1112         printf("Client registration success\n");
1113         return 1;
1114 }
1115
1116 int  test_deregister_client_cs(void)
1117 {
1118         int rv = 0;
1119         GSList *list;
1120         connection_profile_h profile;
1121         int tid = 0;
1122
1123         test_get_user_int("Input a TID in C# API :", &tid);
1124
1125         if (connection != NULL)
1126                 rv = connection_destroy_cs(tid, connection);
1127         else {
1128                 printf("Cannot deregister : Handle is NULL\n");
1129                 rv = CONNECTION_ERROR_INVALID_OPERATION;
1130         }
1131
1132         if (rv != CONNECTION_ERROR_NONE) {
1133                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1134                 return -1;
1135         }
1136
1137         if (state_cb_list) {
1138                 for (list = state_cb_list; list; list = list->next) {
1139                         profile = list->data;
1140                         connection_profile_destroy(profile);
1141                 }
1142
1143                 g_slist_free(state_cb_list);
1144                 state_cb_list = NULL;
1145         }
1146
1147         connection = NULL;
1148         printf("Client deregistration success\n");
1149
1150         return 1;
1151 }
1152
1153 int test_get_network_state(void)
1154 {
1155         int rv = 0;
1156         connection_type_e net_state;
1157
1158         rv = connection_get_type(connection, &net_state);
1159
1160         if (rv != CONNECTION_ERROR_NONE) {
1161                 printf("Fail to get network state [%s]\n", test_print_error(rv));
1162                 return -1;
1163         }
1164
1165         printf("Retval = [%s] network connection state [%s]\n",
1166                 test_print_error(rv), test_print_connection_type(net_state));
1167
1168         return 1;
1169 }
1170
1171 int test_get_cellular_state(void)
1172 {
1173         int rv = 0;
1174         connection_cellular_state_e cellular_state;
1175
1176         rv = connection_get_cellular_state(connection, &cellular_state);
1177
1178         if (rv != CONNECTION_ERROR_NONE) {
1179                 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1180                 return -1;
1181         }
1182
1183         printf("Retval = [%s] Cellular state [%s]\n",
1184                 test_print_error(rv), test_print_cellular_state(cellular_state));
1185
1186         return 1;
1187 }
1188
1189 int test_get_wifi_state(void)
1190 {
1191         int rv = 0;
1192         connection_wifi_state_e wifi_state;
1193
1194         rv = connection_get_wifi_state(connection, &wifi_state);
1195
1196         if (rv != CONNECTION_ERROR_NONE) {
1197                 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1198                 return -1;
1199         }
1200
1201         printf("Retval = [%s] WiFi state [%s]\n",
1202                 test_print_error(rv), test_print_wifi_state(wifi_state));
1203
1204         return 1;
1205 }
1206
1207 int test_get_current_proxy(void)
1208 {
1209         char *proxy_addr = NULL;
1210
1211         connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1212
1213         if (proxy_addr == NULL) {
1214                 printf("Proxy address does not exist\n");
1215                 return -1;
1216         }
1217
1218         printf("Current Proxy [%s]\n", proxy_addr);
1219         g_free(proxy_addr);
1220
1221         return 1;
1222 }
1223
1224 int test_get_current_ip(void)
1225 {
1226         char *ip_addr = NULL;
1227         int input;
1228         bool rv;
1229
1230         rv = test_get_user_int("Input Address type to get"
1231                 "(1:IPV4, 2:IPV6):", &input);
1232
1233         if (rv == false) {
1234                 printf("Invalid input!!\n");
1235                 return -1;
1236         }
1237
1238         switch (input) {
1239         case 1:
1240                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1241                 if (ip_addr == NULL) {
1242                         printf("IPv4 address does not exist\n");
1243                         return -1;
1244                 }
1245                 printf("IPv4 address : %s\n", ip_addr);
1246                 break;
1247
1248         case 2:
1249                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1250                 if (ip_addr == NULL) {
1251                         printf("IPv6 address does not exist\n");
1252                         return -1;
1253                 }
1254                 printf("IPv6 address : %s\n", ip_addr);
1255                 break;
1256         default:
1257                 printf("Wrong IP address family!!\n");
1258                 return -1;
1259         }
1260
1261         g_free(ip_addr);
1262         return 1;
1263 }
1264
1265 int test_get_call_statistics_info(void)
1266 {
1267         long long rv = 0;
1268
1269         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1270         printf("last recv data size [%lld]\n", rv);
1271         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1272         printf("last sent data size [%lld]\n", rv);
1273         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1274         printf("total received data size [%lld]\n", rv);
1275         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1276         printf("total sent data size [%lld]\n", rv);
1277
1278         return 1;
1279 }
1280
1281 int test_get_wifi_call_statistics_info(void)
1282 {
1283         long long rv = 0;
1284
1285         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1286         printf("WiFi last recv data size [%lld]\n", rv);
1287         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1288         printf("WiFi last sent data size [%lld]\n", rv);
1289         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1290         printf("WiFi total received data size [%lld]\n", rv);
1291         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1292         printf("WiFi total sent data size [%lld]\n", rv);
1293
1294         return 1;
1295 }
1296
1297 int test_get_profile_list(void)
1298 {
1299         if (test_get_user_selected_profile(NULL, false) == false)
1300                 return -1;
1301
1302         return 1;
1303 }
1304
1305 int test_get_default_profile_list(void)
1306 {
1307         int rv = 0;
1308         char *profile_name = NULL;
1309         connection_profile_iterator_h profile_iter;
1310         connection_profile_h profile_h;
1311         connection_cellular_service_type_e service_type;
1312         bool is_default = false;
1313
1314         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1315         if (rv != CONNECTION_ERROR_NONE) {
1316                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1317                 return -1;
1318         }
1319
1320         while (connection_profile_iterator_has_next(profile_iter)) {
1321                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1322                         printf("Fail to get profile handle\n");
1323                         return -1;
1324                 }
1325
1326                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1327                         printf("Fail to get profile name\n");
1328                         return -1;
1329                 }
1330                 printf("profile name : %s\n", profile_name);
1331                 g_free(profile_name);
1332
1333                 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1334                         printf("Fail to get profile service type\n");
1335                         return -1;
1336                 }
1337                 printf("service type : %d\n", service_type);
1338
1339                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1340                         printf("Fail to get profile subscriber id\n");
1341                         return -1;
1342                 }
1343                 printf("Default : %d\n", is_default);
1344         }
1345
1346         return 1;
1347 }
1348
1349 int test_get_connected_profile_list(void)
1350 {
1351         int rv = 0;
1352         char *profile_name = NULL;
1353         connection_profile_iterator_h profile_iter;
1354         connection_profile_h profile_h;
1355         bool is_default = false;
1356         connection_profile_type_e type;
1357
1358         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1359         if (rv != CONNECTION_ERROR_NONE) {
1360                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1361                 return -1;
1362         }
1363
1364         while (connection_profile_iterator_has_next(profile_iter)) {
1365                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1366                         printf("Fail to get profile handle\n");
1367                         return -1;
1368                 }
1369
1370                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1371                         printf("Fail to get profile name\n");
1372                         return -1;
1373                 }
1374                 printf("profile name is %s\n", profile_name);
1375                 g_free(profile_name);
1376
1377                 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1378                         printf("Fail to get profile type\n");
1379                         return -1;
1380                 }
1381                 printf("profile type is %d\n", type);
1382
1383                 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1384                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1385                         printf("Fail to get profile is default\n");
1386                         return -1;
1387                 }
1388                         printf("[%s]\n", is_default ? "default" : "not default");
1389                 }
1390         }
1391
1392         return 1;
1393 }
1394
1395 int test_get_current_profile(void)
1396 {
1397         int rv = 0;
1398         char *profile_name = NULL;
1399         connection_profile_h profile_h;
1400
1401         rv = connection_get_current_profile(connection, &profile_h);
1402         if (rv != CONNECTION_ERROR_NONE) {
1403                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1404                 return -1;
1405         }
1406
1407         if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1408                 printf("Fail to get profile name\n");
1409                 return -1;
1410         }
1411         printf("profile name : %s\n", profile_name);
1412         g_free(profile_name);
1413
1414         connection_profile_destroy(profile_h);
1415
1416         return 1;
1417 }
1418
1419 int test_open_profile(void)
1420 {
1421         connection_profile_h profile;
1422
1423         printf("\n** Choose a profile to open. **\n");
1424
1425         if (test_get_user_selected_profile(&profile, true) == false)
1426                 return -1;
1427
1428         if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1429                 printf("Connection open Failed!!\n");
1430                 return -1;
1431         }
1432
1433         return 1;
1434 }
1435
1436 int test_get_default_cellular_service_type(void)
1437 {
1438         int input;
1439         int rv;
1440         int service_type;
1441         connection_profile_h profile;
1442         char *profile_name = NULL;
1443
1444         rv = test_get_user_int("Input profile type to get"
1445                         "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1446
1447         if (rv == false) {
1448                 printf("Invalid input!!\n");
1449                 return -1;
1450         }
1451
1452         switch (input) {
1453         case 1:
1454                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1455                 break;
1456         case 2:
1457                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1458                 break;
1459         case 3:
1460                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1461                 break;
1462         case 4:
1463                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1464                 break;
1465         case 5:
1466                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1467                 break;
1468         case 6:
1469                 service_type =  CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1470                 break;
1471         default:
1472                 printf("Wrong number!!\n");
1473                 return -1;
1474         }
1475
1476         if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1477                 return -1;
1478
1479         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1480                 printf("Fail to get profile name\n");
1481                 connection_profile_destroy(profile);
1482                 return -1;
1483         }
1484         printf("Default profile name : %s\n", profile_name);
1485         g_free(profile_name);
1486
1487         connection_profile_destroy(profile);
1488
1489         return 1;
1490 }
1491
1492 int test_set_default_cellular_service_type(void)
1493 {
1494         connection_profile_h profile;
1495         connection_cellular_service_type_e type;
1496         int input, rv;
1497
1498         rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1499
1500         if (rv == false || (input != 1 && input != 2)) {
1501                 printf("Invalid input!!\n");
1502                 return -1;
1503         }
1504
1505         printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1506
1507         if (test_get_user_selected_profile(&profile, true) == false)
1508                 return -1;
1509
1510         if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1511                 printf("Fail to get cellular service type\n");
1512                 return -1;
1513         }
1514
1515         if (input == 1) {
1516                 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1517                         return -1;
1518         } else {
1519                 if (connection_set_default_cellular_service_profile_async(connection,
1520                                 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1521                         return -1;
1522         }
1523
1524         return 1;
1525 }
1526
1527 int test_close_profile(void)
1528 {
1529         connection_profile_h profile;
1530
1531         printf("\n** Choose a profile to close. **\n");
1532
1533         if (test_get_user_selected_profile(&profile, true) == false)
1534                 return -1;
1535
1536         if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1537                 printf("Connection close Failed!!\n");
1538                 return -1;
1539         }
1540
1541         return 1;
1542 }
1543
1544 int test_add_profile(void)
1545 {
1546         int rv = 0;
1547         connection_profile_h profile;
1548         char input_str[100] = {0,};
1549
1550         if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1551                 return -1;
1552
1553         g_strstrip(input_str);
1554         rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1555         if (rv != CONNECTION_ERROR_NONE)
1556                 RETURN_FAIL_DESTROY(profile);
1557
1558         if (test_update_cellular_info(profile) == -1)
1559                 RETURN_FAIL_DESTROY(profile);
1560
1561         rv = connection_add_profile(connection, profile);
1562         if (rv != CONNECTION_ERROR_NONE)
1563                 RETURN_FAIL_DESTROY(profile);
1564
1565         connection_profile_destroy(profile);
1566         return 1;
1567 }
1568
1569 int test_remove_profile(void)
1570 {
1571         connection_profile_h profile;
1572
1573         printf("\n** Choose a profile to remove. **\n");
1574         if (test_get_user_selected_profile(&profile, true) == false)
1575                 return -1;
1576
1577         if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1578                 printf("Remove profile Failed!!\n");
1579                 return -1;
1580         }
1581
1582         return 1;
1583 }
1584
1585 int test_update_profile(void)
1586 {
1587         int rv = 0;
1588
1589         connection_profile_type_e prof_type;
1590         connection_profile_h profile;
1591
1592         printf("\n** Choose a profile to update. **\n");
1593         if (test_get_user_selected_profile(&profile, true) == false)
1594                 return -1;
1595
1596         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1597                 return -1;
1598
1599         switch (prof_type) {
1600         case CONNECTION_PROFILE_TYPE_CELLULAR:
1601                 if (test_update_cellular_info(profile) == -1)
1602                         return -1;
1603
1604                 break;
1605         case CONNECTION_PROFILE_TYPE_WIFI:
1606                 if (test_update_wifi_info(profile) == -1)
1607                         return -1;
1608
1609                 if (test_update_network_info(profile) == -1)
1610                         return -1;
1611
1612                 break;
1613         case CONNECTION_PROFILE_TYPE_ETHERNET:
1614                 if (test_update_network_info(profile) == -1)
1615                         return -1;
1616
1617                 break;
1618         case CONNECTION_PROFILE_TYPE_BT:
1619                 printf("Not supported!\n");
1620                 /* fall through */
1621         default:
1622                 {
1623                         int profile_type = prof_type;
1624                         if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1625                                 if (test_update_wifi_info(profile) == -1)
1626                                         return -1;
1627                                 break;
1628                         }
1629                 }
1630                 return -1;
1631         }
1632
1633         rv = connection_update_profile(connection, profile);
1634         if (rv != CONNECTION_ERROR_NONE)
1635                 return -1;
1636
1637         return 1;
1638 }
1639
1640 int test_get_profile_info(void)
1641 {
1642         connection_profile_type_e prof_type;
1643         connection_profile_state_e profile_state;
1644         connection_profile_state_e profile_ipv6_state;
1645         connection_internet_state_e internet_state;
1646         connection_profile_h profile;
1647         char *profile_name = NULL;
1648         int address_family = 0;
1649
1650         printf("\n** Choose a profile to print. **\n");
1651         if (test_get_user_selected_profile(&profile, true) == false)
1652                 return -1;
1653
1654         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1655                 printf("Fail to get profile name\n");
1656                 return -1;
1657         } else {
1658                 printf("Profile Name : %s\n", profile_name);
1659                 g_free(profile_name);
1660         }
1661
1662         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1663                 printf("Fail to get profile IPv4 state\n");
1664                 return -1;
1665         } else
1666                 printf("Profile State : %s\n", test_print_state(profile_state));
1667
1668         if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1669                 printf("Fail to get profile IPv6 state\n");
1670                 return -1;
1671         } else
1672                 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1673
1674         if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
1675                 printf("Fail to get Internet state\n");
1676                 return -1;
1677         } else
1678                 printf("Internet State : %s\n", test_print_internet_state(internet_state));
1679
1680         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1681                 return -1;
1682
1683         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1684
1685         switch (prof_type) {
1686         case CONNECTION_PROFILE_TYPE_CELLULAR:
1687                 printf("Profile Type : Cellular\n");
1688                 test_print_cellular_info(profile);
1689                 break;
1690         case CONNECTION_PROFILE_TYPE_WIFI:
1691                 printf("Profile Type : Wi-Fi\n");
1692                 test_print_wifi_info(profile);
1693                 break;
1694         case CONNECTION_PROFILE_TYPE_ETHERNET:
1695                 printf("Profile Type : Ethernet\n");
1696                 break;
1697         case CONNECTION_PROFILE_TYPE_BT:
1698                 printf("Profile Type : Bluetooth\n");
1699                 break;
1700         default:
1701                 {
1702                         int profile_type = prof_type;
1703                         if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1704                                 printf("Profile Type : Mesh\n");
1705                                 test_print_mesh_info(profile);
1706                                 break;
1707                         }
1708                 }
1709                 return -1;
1710         }
1711
1712         test_print_network_info(profile, address_family);
1713
1714         return 1;
1715 }
1716
1717 int test_refresh_profile_info(void)
1718 {
1719         connection_profile_type_e prof_type;
1720         connection_profile_state_e profile_state;
1721         connection_profile_h profile;
1722         char *profile_name = NULL;
1723         int address_family = 0;
1724
1725         printf("\n** Choose a profile to refresh. **\n");
1726         if (test_get_user_selected_profile(&profile, true) == false)
1727                 return -1;
1728
1729         if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1730                 return -1;
1731
1732         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1733                 printf("Fail to get profile name\n");
1734                 return -1;
1735         } else {
1736                 printf("Profile Name : %s\n", profile_name);
1737                 g_free(profile_name);
1738         }
1739
1740         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1741                 printf("Fail to get profile state\n");
1742                 return -1;
1743         } else
1744                 printf("Profile State : %s\n", test_print_state(profile_state));
1745
1746
1747         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1748                 return -1;
1749
1750         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1751
1752         switch (prof_type) {
1753         case CONNECTION_PROFILE_TYPE_CELLULAR:
1754                 printf("Profile Type : Cellular\n");
1755                 test_print_cellular_info(profile);
1756                 break;
1757         case CONNECTION_PROFILE_TYPE_WIFI:
1758                 printf("Profile Type : Wi-Fi\n");
1759                 test_print_wifi_info(profile);
1760                 break;
1761         case CONNECTION_PROFILE_TYPE_ETHERNET:
1762                 printf("Profile Type : Ethernet\n");
1763                 break;
1764         case CONNECTION_PROFILE_TYPE_BT:
1765                 printf("Profile Type : Bluetooth\n");
1766                 break;
1767         default:
1768                 {
1769                         int profile_type = prof_type;
1770                         if (profile_type == CONNECTION_PROFILE_TYPE_MESH) {
1771                                 printf("Profile Type : Mesh\n");
1772                                 test_print_mesh_info(profile);
1773                                 break;
1774                         }
1775                 }
1776                 return -1;
1777         }
1778
1779         test_print_network_info(profile, address_family);
1780
1781         return 1;
1782 }
1783
1784 int test_set_state_changed_callback()
1785 {
1786         connection_profile_h profile;
1787         connection_profile_h profile_clone;
1788
1789         printf("\n** Choose a profile to set callback. **\n");
1790         if (test_get_user_selected_profile(&profile, true) == false)
1791                 return -1;
1792
1793         if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1794                 return -1;
1795
1796         if (connection_profile_set_state_changed_cb(profile,
1797                         test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1798                 connection_profile_destroy(profile_clone);
1799                 return -1;
1800         }
1801
1802         state_cb_list = g_slist_append(state_cb_list, profile_clone);
1803
1804         return 1;
1805 }
1806
1807 int test_unset_state_changed_callback()
1808 {
1809         connection_profile_h profile;
1810         GSList *list;
1811         char *profile_name = NULL;
1812         int count = 0;
1813         int input = 0;
1814
1815         printf("\n** Choose a profile to unset callback. **\n");
1816         for (list = state_cb_list; list; list = list->next) {
1817                 profile = list->data;
1818                 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1819                         printf("Fail to get profile name!\n");
1820                         return -1;
1821                 } else {
1822                         printf("%d. %s\n", count, profile_name);
1823                         g_free(profile_name);
1824                 }
1825
1826                 count++;
1827         }
1828
1829         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1830             input >= count ||
1831             input < 0) {
1832                 printf("Wrong number!!\n");
1833                 return -1;
1834         }
1835
1836         count = 0;
1837         for (list = state_cb_list; list; list = list->next) {
1838                 if (count == input) {
1839                         profile = list->data;
1840                         goto unset;
1841                 }
1842
1843                 count++;
1844         }
1845
1846         return -1;
1847
1848 unset:
1849         if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1850                 return -1;
1851
1852         state_cb_list = g_slist_remove(state_cb_list, profile);
1853         connection_profile_destroy(profile);
1854
1855         return 1;
1856 }
1857
1858 int test_reset_call_statistics_info(void)
1859 {
1860         int ret = CONNECTION_ERROR_NONE;
1861
1862         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1863         printf("reset last recv data size [%d]\n", ret);
1864         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1865         printf("last sent data size [%d]\n", ret);
1866         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1867         printf("total received data size [%d]\n", ret);
1868         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1869         printf("total sent data size [%d]\n", ret);
1870
1871         return 1;
1872 }
1873
1874 int test_reset_wifi_call_statistics_info(void)
1875 {
1876         int ret = CONNECTION_ERROR_NONE;
1877
1878         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1879         printf("WiFi last sent data size [%d]\n", ret);
1880         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1881         printf("WiFi last recv data size [%d]\n", ret);
1882         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1883         printf("WiFi total sent data size [%d]\n", ret);
1884         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1885         printf("WiFi total received data size [%d]\n", ret);
1886
1887         return 1;
1888 }
1889
1890 int test_add_route(void)
1891 {
1892         int rv = 0;
1893         char ip_addr[100] = {0};
1894         char if_name[40] = {0};
1895
1896         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1897                 return -1;
1898
1899         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1900                 return -1;
1901
1902         g_strstrip(ip_addr);
1903         g_strstrip(if_name);
1904         rv = connection_add_route(connection, if_name, ip_addr);
1905         if (rv != CONNECTION_ERROR_NONE) {
1906                 printf("Fail to get add new route [%d]\n", rv);
1907                 return -1;
1908         }
1909         printf("Add Route successfully\n");
1910
1911         return 1;
1912 }
1913
1914 int test_remove_route(void)
1915 {
1916         int rv = 0;
1917         char ip_addr[100] = {0};
1918         char if_name[40] = {0};
1919
1920         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1921                 return -1;
1922
1923         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1924                 return -1;
1925
1926         g_strstrip(ip_addr);
1927         g_strstrip(if_name);
1928         rv = connection_remove_route(connection, if_name, ip_addr);
1929         if (rv != CONNECTION_ERROR_NONE) {
1930                 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1931                 return -1;
1932         }
1933         printf("Remove Route successfully\n");
1934
1935         return 1;
1936 }
1937
1938 int test_add_route_ipv6(void)
1939 {
1940         int rv = 0;
1941         char ip_addr[100] = {0};
1942         char gateway[100] = {0};
1943         char if_name[40] = {0};
1944
1945         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1946                 return -1;
1947
1948         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1949                 return -1;
1950
1951         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1952                 return -1;
1953
1954         g_strstrip(ip_addr);
1955         g_strstrip(gateway);
1956         g_strstrip(if_name);
1957         rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1958         if (rv != CONNECTION_ERROR_NONE) {
1959                 printf("Fail to get add new route [%d]\n", rv);
1960                 return -1;
1961         }
1962         printf("Add Route successfully\n");
1963
1964         return 1;
1965 }
1966
1967 int test_remove_route_ipv6(void)
1968 {
1969         int rv = 0;
1970         char ip_addr[100] = {0};
1971         char gateway[100] = {0};
1972         char if_name[40] = {0};
1973
1974         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1975                 return -1;
1976
1977         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1978                 return -1;
1979
1980         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1981                 return -1;
1982
1983         g_strstrip(ip_addr);
1984         g_strstrip(gateway);
1985         g_strstrip(if_name);
1986         rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1987         if (rv != CONNECTION_ERROR_NONE) {
1988                 printf("Fail to remove the route [%d]\n", rv);
1989                 return -1;
1990         }
1991         printf("Remove Route successfully\n");
1992
1993         return 1;
1994 }
1995
1996 int test_add_route_entry(void)
1997 {
1998         char ip_addr[100] = {0};
1999         char gateway[100] = {0};
2000         char if_name[40] = {0};
2001         int input;
2002         bool input_rv;
2003         int rv = 0;
2004
2005         input_rv = test_get_user_int("Input Address type to get"
2006                 "(1:IPV4, 2:IPV6):", &input);
2007
2008         if (input_rv == false) {
2009                 printf("Invalid input!!\n");
2010                 return -1;
2011         }
2012
2013         switch (input) {
2014         case 1:
2015                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2016                         return -1;
2017
2018                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2019                         return -1;
2020
2021                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2022                         return -1;
2023
2024                 g_strstrip(ip_addr);
2025                 g_strstrip(gateway);
2026                 g_strstrip(if_name);
2027                 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2028                 if (rv != CONNECTION_ERROR_NONE) {
2029                         printf("Fail to get add new route [%d]\n", rv);
2030                         return -1;
2031                 }
2032                 printf("Add Route successfully\n");
2033                 break;
2034
2035         case 2:
2036                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2037                         return -1;
2038
2039                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2040                         return -1;
2041
2042                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2043                         return -1;
2044
2045                 g_strstrip(ip_addr);
2046                 g_strstrip(gateway);
2047                 g_strstrip(if_name);
2048                 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2049                 if (rv != CONNECTION_ERROR_NONE) {
2050                         printf("Fail to get add new route [%d]\n", rv);
2051                         return -1;
2052                 }
2053                 printf("Add Route successfully\n");
2054                 break;
2055
2056         default:
2057                 printf("Wrong IP address family!!\n");
2058                 return -1;
2059
2060         }
2061
2062         return 1;
2063
2064 }
2065
2066 int test_remove_route_entry(void)
2067 {
2068         char ip_addr[100] = {0};
2069         char gateway[100] = {0};
2070         char if_name[40] = {0};
2071         int input;
2072         bool input_rv;
2073         int rv = 0;
2074
2075         input_rv = test_get_user_int("Input Address type to get"
2076                 "(1:IPV4, 2:IPV6):", &input);
2077
2078         if (input_rv == false) {
2079                 printf("Invalid input!!\n");
2080                 return -1;
2081         }
2082
2083         switch (input) {
2084         case 1:
2085                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2086                         return -1;
2087
2088                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2089                         return -1;
2090
2091                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2092                         return -1;
2093
2094                 g_strstrip(ip_addr);
2095                 g_strstrip(gateway);
2096                 g_strstrip(if_name);
2097                 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2098                 if (rv != CONNECTION_ERROR_NONE) {
2099                         printf("Fail to remove the route [%s]\n", test_print_error(rv));
2100                         return -1;
2101                 }
2102                 printf("Remove Route successfully\n");
2103
2104                 break;
2105
2106         case 2:
2107                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2108                         return -1;
2109
2110                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2111                         return -1;
2112
2113                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2114                         return -1;
2115
2116                 g_strstrip(ip_addr);
2117                 g_strstrip(gateway);
2118                 g_strstrip(if_name);
2119                 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2120                 if (rv != CONNECTION_ERROR_NONE) {
2121                         printf("Fail to remove the route [%d]\n", rv);
2122                         return -1;
2123                 }
2124                 printf("Remove Route successfully\n");
2125                 break;
2126
2127         default:
2128                 printf("Wrong IP address family!!\n");
2129                 return -1;
2130
2131         }
2132
2133         return 1;
2134
2135 }
2136
2137 int test_get_bt_state(void)
2138 {
2139         int rv = 0;
2140         connection_bt_state_e bt_state;
2141
2142         rv = connection_get_bt_state(connection, &bt_state);
2143
2144         if (rv != CONNECTION_ERROR_NONE) {
2145                 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
2146                 return -1;
2147         }
2148
2149         printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
2150
2151         return 1;
2152 }
2153
2154 int test_get_profile_id(void)
2155 {
2156         connection_profile_h profile;
2157         char *profile_id;
2158
2159         printf("\n** Choose a profile to see profile id. **\n");
2160         if (test_get_user_selected_profile(&profile, true) == false)
2161                 return -1;
2162
2163         if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2164                 printf("Fail to get profile name\n");
2165                 return -1;
2166         } else {
2167                 printf("Profile id : %s\n", profile_id);
2168                 g_free(profile_id);
2169         }
2170
2171         return 1;
2172 }
2173
2174 int test_get_mac_address(void)
2175 {
2176         int rv = 0, type = 0;
2177         connection_type_e conn_type;
2178         char *mac_addr = NULL;
2179
2180         test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2181
2182         switch (type) {
2183         case 1:
2184                 conn_type = CONNECTION_TYPE_WIFI;
2185                 break;
2186         case 2:
2187                 conn_type = CONNECTION_TYPE_ETHERNET;
2188                 break;
2189         default:
2190                 printf("Wrong number!!\n");
2191                 return -1;
2192         }
2193
2194         rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2195
2196         if (rv != CONNECTION_ERROR_NONE) {
2197                 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2198                 return -1;
2199         }
2200
2201         printf("mac address is %s\n", mac_addr);
2202
2203         g_free(mac_addr);
2204
2205         return 1;
2206 }
2207
2208 int test_get_ethernet_cable_state(void)
2209 {
2210         int rv = 0;
2211         connection_ethernet_cable_state_e cable_state;
2212
2213         rv = connection_get_ethernet_cable_state(connection, &cable_state);
2214
2215         if (rv != CONNECTION_ERROR_NONE) {
2216                 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2217                 return -1;
2218         }
2219
2220         printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2221
2222         return 1;
2223 }
2224
2225 int test_reset_profile(void)
2226 {
2227         int type, sim_id, rv;
2228
2229         rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2230
2231         if (rv == false || (type != 0 && type != 1)) {
2232                 printf("Invalid input!!\n");
2233                 return -1;
2234         }
2235
2236         rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2237
2238         if (rv == false || (sim_id != 0 && sim_id != 1)) {
2239                 printf("Invalid input!!\n");
2240                 return -1;
2241         }
2242
2243         if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2244                 return -1;
2245
2246         return 1;
2247 }
2248
2249 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2250 {
2251         printf("IPv6 Address : %s\n", ipv6_address);
2252         return true;
2253 }
2254
2255 int test_foreach_ipv6_address(void)
2256 {
2257         int rv = 0;
2258         int type;
2259         connection_type_e conn_type;
2260
2261         test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2262
2263         switch (type) {
2264         case 1:
2265                 conn_type = CONNECTION_TYPE_WIFI;
2266                 break;
2267         case 2:
2268                 conn_type = CONNECTION_TYPE_ETHERNET;
2269                 break;
2270         default:
2271                 printf("Wrong number!!\n");
2272                 return -1;
2273         }
2274
2275         rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2276         if (rv != CONNECTION_ERROR_NONE) {
2277                 printf("Fail to get IPv6 address\n");
2278                 return -1;
2279         }
2280
2281         return 1;
2282 }
2283
2284 int test_is_metered_network(void)
2285 {
2286         int rv = 0;
2287         bool metered_state;
2288
2289         rv = connection_is_metered_network(connection, &metered_state);
2290
2291         if (rv != CONNECTION_ERROR_NONE) {
2292                 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2293                 return -1;
2294         }
2295
2296         printf("Retval = [%s] metered state [%s]\n",
2297                 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2298
2299         return 1;
2300 }
2301
2302 int test_start_tcpdump(void)
2303 {
2304         if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2305                 return -1;
2306         }
2307
2308         printf("Successfully started tcpdump\n");
2309
2310         return 1;
2311 }
2312
2313 int test_stop_tcpdump(void)
2314 {
2315         if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2316                 return -1;
2317         }
2318
2319         printf("Successfully stopped tcpdump\n");
2320
2321         return 1;
2322 }
2323
2324 int test_get_tcpdump_state(void)
2325 {
2326         gboolean tcpdump_state = FALSE;
2327
2328         if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
2329                 return -1;
2330         }
2331
2332         printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2333
2334         return 1;
2335 }
2336
2337 int test_mptcp_enable(void)
2338 {
2339         int rv = 0;
2340         bool supported = false;
2341         rv = connection_mptcp_is_supported(connection, &supported);
2342         if (rv != CONNECTION_ERROR_NONE) {
2343                 printf("Failure[%s]\n", test_print_error(rv));
2344                 return -1;
2345         }
2346         printf("MPTCP Support: %d\n", supported);
2347
2348         rv = connection_mptcp_enable(connection, CONNECTION_MPTCP_ENABLE_ALL);
2349         if (rv != CONNECTION_ERROR_NONE) {
2350                 printf("Failure[%s]\n", test_print_error(rv));
2351                 return -1;
2352         }
2353         return 1;
2354 }
2355
2356 int test_mptcp_disable(void)
2357 {
2358         int rv = 0;
2359         rv = connection_mptcp_disable(connection);
2360
2361         if (rv != CONNECTION_ERROR_NONE) {
2362                 printf("Failure[%s]\n", test_print_error(rv));
2363                 return -1;
2364         }
2365         return 1;
2366 }
2367
2368 int test_mptcp_set_path_manager(void)
2369 {
2370         int rv = 0;
2371         int input = 0;
2372         rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
2373
2374         switch (input) {
2375         case 1:
2376                 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_DEFAULT);
2377                 break;
2378         case 2:
2379                 rv = connection_mptcp_set_path_manager(connection, CONNECTION_MPTCP_PM_FULLMESH);
2380                 break;
2381         default:
2382                 printf("Invalid input!!\n");
2383                 return -1;
2384         }
2385
2386         if (rv != CONNECTION_ERROR_NONE) {
2387                 printf("Failure[%s]\n", test_print_error(rv));
2388                 return -1;
2389         }
2390
2391         return 1;
2392 }
2393
2394 int test_mptcp_get_path_manager(void)
2395 {
2396         int rv = 0;
2397         connection_mptcp_path_manager_e pm;
2398
2399         rv = connection_mptcp_get_path_manager(connection, &pm);
2400         if (rv != CONNECTION_ERROR_NONE) {
2401                 printf("Failure[%s]\n", test_print_error(rv));
2402                 return -1;
2403         }
2404
2405         switch (pm) {
2406         case CONNECTION_MPTCP_PM_DEFAULT:
2407                 printf("Path Manager: Default\n");
2408                 break;
2409         case CONNECTION_MPTCP_PM_FULLMESH:
2410                 printf("Path Manager: FullMesh\n");
2411                 break;
2412         default:
2413                 printf("Error: Invalid Path Manager\n");
2414                 return -1;
2415         }
2416
2417         return 1;
2418 }
2419
2420 int test_mptcp_set_scheduler(void)
2421 {
2422         int rv = 0;
2423         int input = 0;
2424         rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
2425
2426         switch (input) {
2427         case 1:
2428                 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_DEFAULT);
2429                 break;
2430         case 2:
2431                 rv = connection_mptcp_set_scheduler(connection, CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
2432                 break;
2433         default:
2434                 printf("Invalid input!!\n");
2435                 return -1;
2436         }
2437
2438         if (rv != CONNECTION_ERROR_NONE) {
2439                 printf("Failure[%s]\n", test_print_error(rv));
2440                 return -1;
2441         }
2442
2443         return 1;
2444 }
2445
2446 int test_mptcp_get_scheduler(void)
2447 {
2448         int rv = 0;
2449         connection_mptcp_scheduler_e scheduler;
2450
2451         rv = connection_mptcp_get_scheduler(connection, &scheduler);
2452         if (rv != CONNECTION_ERROR_NONE) {
2453                 printf("Failure[%s]\n", test_print_error(rv));
2454                 return -1;
2455         }
2456
2457         switch (scheduler) {
2458         case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
2459                 printf("Scheduler: Default\n");
2460                 break;
2461         case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
2462                 printf("Scheduler: RountRobin\n");
2463                 break;
2464         default:
2465                 printf("Error: Invalid Scheduler\n");
2466                 return -1;
2467         }
2468
2469         return 1;
2470 }
2471
2472 int main(int argc, char **argv)
2473 {
2474         GMainLoop *mainloop;
2475         mainloop = g_main_loop_new(NULL, FALSE);
2476
2477         GIOChannel *channel = g_io_channel_unix_new(0);
2478         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
2479
2480         printf("Test Thread created...\n");
2481
2482         g_main_loop_run(mainloop);
2483
2484         return 0;
2485 }
2486
2487 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
2488 {
2489         int rv = 0;
2490         char a[100];
2491
2492         memset(a, '\0', 100);
2493         printf("Event received from stdin\n");
2494
2495         rv = read(0, a, 100);
2496
2497         if (rv < 0 || a[0] == '0') {
2498                 if (connection != NULL)
2499                         test_deregister_client();
2500
2501                 exit(1);
2502         }
2503
2504         if (*a == '\n' || *a == '\r') {
2505 /* Public API */
2506                 printf("\n\n Network Connection API Test App\n\n");
2507                 printf("Options..\n");
2508                 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
2509                 printf(LOG_GREEN "1   - Create Handle and set callbacks\n" LOG_END);
2510                 printf("2   - Destroy Handle(unset callbacks automatically)\n");
2511                 printf(LOG_GREEN "3   - Get network state\n" LOG_END);
2512                 printf(LOG_GREEN "4   - Get cellular state (please insert SIM Card)\n" LOG_END);
2513                 printf(LOG_GREEN "5   - Get wifi state (please turn on WiFi)\n" LOG_END);
2514                 printf("6   - Get current proxy address \n");
2515                 printf("7   - Get current Ip address\n");
2516                 printf("8   - Get cellular data call statistics\n");
2517                 printf("9   - Get WiFi data call statistics\n");
2518                 printf(LOG_GREEN "a   - Get Profile list\n" LOG_END);
2519                 printf(LOG_GREEN "b   - Get Connected Profile list\n" LOG_END);
2520                 printf(LOG_GREEN "c   - Get Current profile\n" LOG_END);
2521                 printf("d   - Open connection with profile\n");
2522                 printf("e   - Get default cellular service by type\n");
2523                 printf("f   - Set default cellular service by type\n");
2524                 printf("g   - Close connection with profile\n");
2525                 printf("h   - Add profile(Cellular and Wifi only)\n");
2526                 printf("i   - Remove profile(Cellular:delete, WiFi:forgot)\n");
2527                 printf("j   - Update profile\n");
2528                 printf("k   - Get profile info\n");
2529                 printf("l   - Refresh profile info\n");
2530                 printf("m   - Set state changed callback\n");
2531                 printf("n   - Unset state changed callback\n");
2532                 printf("o   - Reset cellular data call statistics\n");
2533                 printf("p   - Reset WiFi data call statistics\n");
2534                 printf("q   - Add new route\n");
2535                 printf("r   - Remove a route\n");
2536                 printf("s   - Get Bluetooth state\n");
2537                 printf("t   - Get profile id\n");
2538                 printf("u   - Reset profile\n");
2539                 printf("v   - Get all cellular default profiles\n");
2540                 printf("w   - Get mac address\n");
2541                 printf("x   - Get ethernet cable state\n");
2542                 printf("B   - Add IPv6 new route\n");
2543                 printf("C   - Remove IPv6 route\n");
2544                 printf("D   - Add new route entry\n");
2545                 printf("E   - Remove route entry\n");
2546                 printf("F   - Get all IPv6 address\n");
2547                 printf("G   - Get metered state\n");
2548 /* Extension API */
2549                 printf(LOG_BLUE "[Extension API]\n" LOG_END);
2550                 printf("H   - Start TCP Dump\n");
2551                 printf("I   - Stop TCP Dump\n");
2552                 printf("J   - Get TCP Dump State\n");
2553                 printf("K   - Enable MPTCP (internal)\n");
2554                 printf("L   - Disable MPTCP (internal)\n");
2555                 printf("M   - Set MPTCP Path Manager (internal)\n");
2556                 printf("N   - Get MPTCP Path Manager (internal)\n");
2557                 printf("O   - Set MPTCP Scheduler (internal)\n");
2558                 printf("P   - Get MPTCP Scheduler (internal)\n");
2559                 printf(LOG_GREEN "Q   - Create Handle and set callbacks in C# API\n" LOG_END);
2560                 printf("R   - Destroy Handle(unset callbacks automatically in C# API)\n");
2561                 printf(LOG_RED "0   - Exit \n" LOG_END);
2562                 printf("ENTER   - Show options menu.......\n");
2563         }
2564
2565         switch (a[0]) {
2566 /* Public API */
2567         case '1':
2568                 rv = test_register_client();
2569                 break;
2570         case '2':
2571                 rv = test_deregister_client();
2572                 break;
2573         case '3':
2574                 rv = test_get_network_state();
2575                 break;
2576         case '4':
2577                 rv = test_get_cellular_state();
2578                 break;
2579         case '5':
2580                 rv = test_get_wifi_state();
2581                 break;
2582         case '6':
2583                 rv = test_get_current_proxy();
2584                 break;
2585         case '7':
2586                 rv = test_get_current_ip();
2587                 break;
2588         case '8':
2589                 rv = test_get_call_statistics_info();
2590                 break;
2591         case '9':
2592                 rv = test_get_wifi_call_statistics_info();
2593                 break;
2594         case 'a':
2595                 rv = test_get_profile_list();
2596                 break;
2597         case 'b':
2598                 rv = test_get_connected_profile_list();
2599                 break;
2600         case 'c':
2601                 rv = test_get_current_profile();
2602                 break;
2603         case 'd':
2604                 rv = test_open_profile();
2605                 break;
2606         case 'e':
2607                 rv = test_get_default_cellular_service_type();
2608                 break;
2609         case 'f':
2610                 rv = test_set_default_cellular_service_type();
2611                 break;
2612         case 'g':
2613                 rv = test_close_profile();
2614                 break;
2615         case 'h':
2616                 rv = test_add_profile();
2617                 break;
2618         case 'i':
2619                 rv = test_remove_profile();
2620                 break;
2621         case 'j':
2622                 rv = test_update_profile();
2623                 break;
2624         case 'k':
2625                 rv = test_get_profile_info();
2626                 break;
2627         case 'l':
2628                 rv = test_refresh_profile_info();
2629                 break;
2630         case 'm':
2631                 rv = test_set_state_changed_callback();
2632                 break;
2633         case 'n':
2634                 rv = test_unset_state_changed_callback();
2635                 break;
2636         case 'o':
2637                 rv = test_reset_call_statistics_info();
2638                 break;
2639         case 'p':
2640                 rv = test_reset_wifi_call_statistics_info();
2641                 break;
2642         case 'q':
2643                 rv = test_add_route();
2644                 break;
2645         case 'r':
2646                 rv = test_remove_route();
2647                 break;
2648         case 's':
2649                 rv = test_get_bt_state();
2650                 break;
2651         case 't':
2652                 rv = test_get_profile_id();
2653                 break;
2654         case 'u':
2655                 rv = test_reset_profile();
2656                 break;
2657         case 'v':
2658                 rv = test_get_default_profile_list();
2659                 break;
2660         case 'w':
2661                 rv = test_get_mac_address();
2662                 break;
2663         case 'x':
2664                 rv = test_get_ethernet_cable_state();
2665                 break;
2666         case 'B':
2667                 rv = test_add_route_ipv6();
2668                 break;
2669         case 'C':
2670                 rv = test_remove_route_ipv6();
2671                 break;
2672         case 'D':
2673                 rv = test_add_route_entry();
2674                 break;
2675         case 'E':
2676                 rv = test_remove_route_entry();
2677                 break;
2678         case 'F':
2679                 rv = test_foreach_ipv6_address();
2680                 break;
2681         case 'G':
2682                 rv = test_is_metered_network();
2683                 break;
2684 /* Extension API */
2685         case 'H':
2686                 rv = test_start_tcpdump();
2687                 break;
2688         case 'I':
2689                 rv = test_stop_tcpdump();
2690                 break;
2691         case 'J':
2692                 rv = test_get_tcpdump_state();
2693                 break;
2694         case 'K':
2695                 rv = test_mptcp_enable();
2696                 break;
2697         case 'L':
2698                 rv = test_mptcp_disable();
2699                 break;
2700         case 'M':
2701                 rv = test_mptcp_set_path_manager();
2702                 break;
2703         case 'N':
2704                 rv = test_mptcp_get_path_manager();
2705                 break;
2706         case 'O':
2707                 rv = test_mptcp_set_scheduler();
2708                 break;
2709         case 'P':
2710                 rv = test_mptcp_get_scheduler();
2711                 break;
2712         case 'Q':
2713                 rv = test_register_client_cs();
2714                 break;
2715         case 'R':
2716                 rv = test_deregister_client_cs();
2717                 break;
2718
2719         }
2720
2721         if (rv == 1)
2722                 printf("Operation succeeded!\n");
2723         else
2724                 printf("Operation failed!\n");
2725
2726         return TRUE;
2727 }