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