4fec7719f3a1b4355bdd80afdbedb2759c0cd4ab
[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
26 #include <tizen_error.h>
27
28 #define LOG_RED "\033[0;31m"
29 #define LOG_GREEN "\033[0;32m"
30 #define LOG_BROWN "\033[0;33m"
31 #define LOG_BLUE "\033[0;34m"
32 #define LOG_END "\033[0;m"
33
34 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
35
36 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
37
38 connection_h connection = NULL;
39 static GSList *state_cb_list = NULL;
40
41
42 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
43 {
44         if (msg == NULL || buf == NULL || buf_size < 2)
45                 return false;
46
47         int rv;
48         printf("%s\n", msg);
49         memset(buf, 0, buf_size);
50         rv = read(0, buf, buf_size - 1);
51
52         if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
53                 buf[0] = '\0';
54                 return false;
55         }
56
57         buf[rv-1] = '\0';
58         return true;
59 }
60
61 static bool test_get_user_int(const char *msg, int *num)
62 {
63         if (msg == NULL || num == NULL)
64                 return false;
65
66         int rv;
67         char buf[32] = {0,};
68         printf("%s\n", msg);
69         rv = read(0, buf, 32);
70
71         if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
72                 return false;
73
74         *num = atoi(buf);
75         return true;
76 }
77
78 static const char *test_print_state(connection_profile_state_e state)
79 {
80         switch (state) {
81         case CONNECTION_PROFILE_STATE_DISCONNECTED:
82                 return "Disconnected";
83         case CONNECTION_PROFILE_STATE_ASSOCIATION:
84                 return "Association";
85         case CONNECTION_PROFILE_STATE_CONFIGURATION:
86                 return "Configuration";
87         case CONNECTION_PROFILE_STATE_CONNECTED:
88                 return "Connected";
89         default:
90                 return "Unknown";
91         }
92 }
93
94 static const char *test_print_connection_type(connection_type_e type)
95 {
96         switch (type) {
97         case CONNECTION_TYPE_DISCONNECTED:
98                 return "Disconnected";
99         case CONNECTION_TYPE_WIFI:
100                 return "Wifi";
101         case CONNECTION_TYPE_CELLULAR:
102                 return "Cellular";
103         case CONNECTION_TYPE_ETHERNET:
104                 return "Ethernet";
105         case CONNECTION_TYPE_BT:
106                 return "BT";
107         case CONNECTION_TYPE_NET_PROXY:
108                 return "Net_Proxy";
109         default:
110                 return "Unknown";
111         }
112 }
113
114 static const char *test_print_cellular_state(connection_cellular_state_e state)
115 {
116         switch (state) {
117         case CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE:
118                 return "Out of service";
119         case CONNECTION_CELLULAR_STATE_FLIGHT_MODE:
120                 return "Flight mode";
121         case CONNECTION_CELLULAR_STATE_ROAMING_OFF:
122                 return "Roaming off";
123         case CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE:
124                 return "Call only available";
125         case CONNECTION_CELLULAR_STATE_AVAILABLE:
126                 return "Available";
127         case CONNECTION_CELLULAR_STATE_CONNECTED:
128                 return "Connected";
129         default:
130                 return "Unknown";
131         }
132 }
133
134 static const char *test_print_wifi_state(connection_wifi_state_e state)
135 {
136         switch (state) {
137         case CONNECTION_WIFI_STATE_DEACTIVATED:
138                 return "Deactivated";
139         case CONNECTION_WIFI_STATE_DISCONNECTED:
140                 return "Disconnected";
141         case CONNECTION_WIFI_STATE_CONNECTED:
142                 return "Connected";
143         default:
144                 return "Unknown";
145         }
146 }
147
148 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
149 {
150         switch (type) {
151         case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
152                 return "Unknown";
153         case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
154                 return "Internet";
155         case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
156                 return "MMS";
157         case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
158                 return "Prepaid internet";
159         case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
160                 return "Prepaid MMS";
161         case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
162                 return "Tethering";
163         case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
164                 return "Application";
165         default:
166                 return "Unknown";
167         }
168 }
169
170 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
171 {
172         switch (type) {
173         case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
174                 return "PAP";
175         case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
176                 return "CHAP";
177         case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
178         default:
179                 return "None";
180         }
181 }
182
183 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
184 {
185         switch (type) {
186         case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
187                 return "IPv4";
188         case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
189                 return "IPv6";
190         case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
191                 return "Dual";
192         case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
193         default:
194                 return "Unknown";
195         }
196 }
197
198 static const char *test_print_error(connection_error_e error)
199 {
200         switch (error) {
201         case CONNECTION_ERROR_NONE:
202                 return "CONNECTION_ERROR_NONE";
203         case CONNECTION_ERROR_INVALID_PARAMETER:
204                 return "CONNECTION_ERROR_INVALID_PARAMETER";
205         case CONNECTION_ERROR_OUT_OF_MEMORY:
206                 return "CONNECTION_ERROR_OUT_OF_MEMORY";
207         case CONNECTION_ERROR_INVALID_OPERATION:
208                 return "CONNECTION_ERROR_INVALID_OPERATION";
209         case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
210                 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
211         case CONNECTION_ERROR_OPERATION_FAILED:
212                 return "CONNECTION_ERROR_OPERATION_FAILED";
213         case CONNECTION_ERROR_ITERATOR_END:
214                 return "CONNECTION_ERROR_ITERATOR_END";
215         case CONNECTION_ERROR_NO_CONNECTION:
216                 return "CONNECTION_ERROR_NO_CONNECTION";
217         case CONNECTION_ERROR_NOW_IN_PROGRESS:
218                 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
219         case CONNECTION_ERROR_ALREADY_EXISTS:
220                 return "CONNECTION_ERROR_ALREADY_EXISTS";
221         case CONNECTION_ERROR_OPERATION_ABORTED:
222                 return "CONNECTION_ERROR_OPERATION_ABORTED";
223         case CONNECTION_ERROR_DHCP_FAILED:
224                 return "CONNECTION_ERROR_DHCP_FAILED";
225         case CONNECTION_ERROR_INVALID_KEY:
226                 return "CONNECTION_ERROR_INVALID_KEY";
227         case CONNECTION_ERROR_NO_REPLY:
228                 return "CONNECTION_ERROR_NO_REPLY";
229         case CONNECTION_ERROR_PERMISSION_DENIED:
230                 return "CONNECTION_ERROR_PERMISSION_DENIED";
231         case CONNECTION_ERROR_NOT_SUPPORTED:
232                 return "CONNECTION_ERROR_NOT_SUPPORTED";
233         default:
234                 return "CONNECTION_ERROR_UNKNOWN";
235         }
236 }
237
238 static void test_type_changed_callback(connection_type_e type, void* user_data)
239 {
240         printf("Type changed callback, connection type : %d\n", type);
241 }
242
243 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
244 {
245         printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
246                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
247 }
248
249 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
250 {
251         printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
252                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
253 }
254
255 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
256 {
257         char *profile_name;
258         connection_profile_h profile = user_data;
259
260         if (profile == NULL)
261                 return;
262
263         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
264                 return;
265
266         printf("[%s] : %s\n", test_print_state(state), profile_name);
267         g_free(profile_name);
268 }
269
270 static void test_connection_opened_callback(connection_error_e result, void* user_data)
271 {
272         if (result ==  CONNECTION_ERROR_NONE)
273                 printf("Connection open Succeeded\n");
274         else
275                 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
276 }
277
278 static void test_connection_closed_callback(connection_error_e result, void* user_data)
279 {
280         if (result ==  CONNECTION_ERROR_NONE)
281                 printf("Connection close Succeeded\n");
282         else
283                 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
284 }
285
286 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
287 {
288         if (result ==  CONNECTION_ERROR_NONE)
289                 printf("Reset profile Succeeded\n");
290         else
291                 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
292 }
293
294 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
295 {
296         if (result ==  CONNECTION_ERROR_NONE)
297                 printf("Default profile setting Succeeded\n");
298         else
299                 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
300 }
301
302 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
303                                                                 void* user_data)
304 {
305         if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
306                 printf("Ethernet Cable Connected\n");
307         else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
308                 printf("Ethernet Cable Disconnected\n");
309 }
310
311 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
312 {
313         int rv = 0;
314         int input = 0;
315         char *profile_name;
316         connection_profile_type_e profile_type;
317         connection_profile_state_e profile_state;
318         connection_profile_iterator_h profile_iter;
319         connection_profile_h profile_h;
320
321         connection_profile_h profile_list[100] = {0,};
322         int profile_count = 0;
323
324         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
325         if (rv != CONNECTION_ERROR_NONE) {
326                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
327                 return false;
328         }
329
330         while (connection_profile_iterator_has_next(profile_iter)) {
331                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
332                         printf("Fail to get profile handle\n");
333                         return false;
334                 }
335
336                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
337                         printf("Fail to get profile name\n");
338                         return false;
339                 }
340
341                 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
342                         printf("Fail to get profile type\n");
343                         g_free(profile_name);
344                         return false;
345                 }
346
347                 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
348                         printf("Fail to get profile state\n");
349                         g_free(profile_name);
350                         return false;
351                 }
352
353                 if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
354                         char *essid;
355                         connection_profile_get_wifi_essid(profile_h, &essid);
356                         printf("%d. state:[%s], profile name:%s, essid:%s\n",
357                                 profile_count, test_print_state(profile_state),
358                                 profile_name, (essid) ? essid : "");
359                         g_free(essid);
360
361                         profile_list[profile_count] = profile_h;
362                         profile_count++;
363                 } else {
364                         connection_cellular_service_type_e service_type;
365                         if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE)
366                                 printf("Fail to get cellular service type!\n");
367
368                         printf("%d. state:[%s], profile name:%s[%s]\n",
369                                 profile_count, test_print_state(profile_state),
370                                 profile_name, test_print_cellular_service_type(service_type));
371
372                         profile_list[profile_count] = profile_h;
373                         profile_count++;
374                 }
375
376                 g_free(profile_name);
377                 if (profile_count >= 100)
378                         break;
379         }
380
381         if (select == false)
382                 return true;
383
384         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
385             input >= profile_count ||
386             input < 0) {
387                 printf("Wrong number!!\n");
388                 return false;
389         }
390
391         if (profile)
392                 *profile = profile_list[input];
393
394         return true;
395 }
396
397 static int test_update_cellular_info(connection_profile_h profile)
398 {
399         int rv = 0;
400         char input_str1[100] = {0,};
401         char input_str2[100] = {0,};
402         int input_int = 0;
403         int type_val = 0;
404
405         if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
406                         "Prepaid MMS:4, Tethering:5, Application:6)"
407                         " - (Enter for skip) :", &input_int)) {
408                 switch (input_int) {
409                 case 1:
410                         rv = connection_profile_set_cellular_service_type(profile,
411                                         CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
412                         break;
413                 case 2:
414                         rv = connection_profile_set_cellular_service_type(profile,
415                                         CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
416                         break;
417                 case 3:
418                         rv = connection_profile_set_cellular_service_type(profile,
419                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
420                         break;
421                 case 4:
422                         rv = connection_profile_set_cellular_service_type(profile,
423                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
424                         break;
425                 case 5:
426                         rv = connection_profile_set_cellular_service_type(profile,
427                                         CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
428                         break;
429                 case 6:
430                         rv = connection_profile_set_cellular_service_type(profile,
431                                         CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
432                         break;
433                 default:
434                         return -1;
435                 }
436
437                 if (rv != CONNECTION_ERROR_NONE)
438                         return -1;
439         } else
440                 return -1;
441
442         if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
443                 g_strstrip(input_str1);
444                 rv = connection_profile_set_cellular_apn(profile, input_str1);
445                 if (rv != CONNECTION_ERROR_NONE)
446                         return -1;
447         }
448
449         if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
450                 g_strstrip(input_str1);
451                 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
452                 if (rv != CONNECTION_ERROR_NONE)
453                         return -1;
454         }
455
456         if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
457                 g_strstrip(input_str1);
458                 rv = connection_profile_set_cellular_home_url(profile, input_str1);
459                 if (rv != CONNECTION_ERROR_NONE)
460                         return -1;
461         }
462
463         if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
464                 switch (input_int) {
465                 case 0:
466                         rv = connection_profile_set_cellular_auth_info(profile,
467                                         CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
468                         if (rv != CONNECTION_ERROR_NONE)
469                                 return -1;
470
471                         break;
472                 case 1:
473                         type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
474                         /* fall through */
475                 case 2:
476                         if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
477
478                         if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
479                                 input_str1[0] = 0;
480                         if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
481                                 input_str2[0] = 0;
482
483                         g_strstrip(input_str1);
484                         g_strstrip(input_str2);
485                         rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
486                         if (rv != CONNECTION_ERROR_NONE)
487                                 return -1;
488                 }
489         }
490
491         if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
492                 switch (input_int) {
493                 case 1:
494                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
495                         break;
496                 case 2:
497                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
498                         break;
499                 case 3:
500                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
501                         break;
502                 }
503
504                 if (rv != CONNECTION_ERROR_NONE)
505                         return -1;
506         }
507
508         if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
509                 switch (input_int) {
510                 case 1:
511                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
512                         break;
513                 case 2:
514                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
515                         break;
516                 case 3:
517                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
518                         break;
519                 }
520
521                 if (rv != CONNECTION_ERROR_NONE)
522                         return -1;
523         }
524
525         return 1;
526 }
527
528 static int test_update_wifi_info(connection_profile_h profile)
529 {
530         int rv = 0;
531         char input_str[100] = {0,};
532
533         if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
534                 rv = connection_profile_set_wifi_passphrase(profile, input_str);
535                 if (rv != CONNECTION_ERROR_NONE)
536                         return -1;
537         }
538
539         return 1;
540 }
541
542 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
543 {
544         int rv = 0;
545         char input_str[100] = {0,};
546
547         if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
548                 rv = connection_profile_set_ip_address(profile,
549                                                         address_family,
550                                                         input_str);
551                 if (rv != CONNECTION_ERROR_NONE)
552                         return -1;
553         }
554
555         if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
556                 rv = connection_profile_set_subnet_mask(profile,
557                                                         address_family,
558                                                         input_str);
559                 if (rv != CONNECTION_ERROR_NONE)
560                         return -1;
561         }
562
563         if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
564                 rv = connection_profile_set_gateway_address(profile,
565                                                         address_family,
566                                                         input_str);
567                 if (rv != CONNECTION_ERROR_NONE)
568                         return -1;
569         }
570
571         if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
572                 rv = connection_profile_set_dns_address(profile,
573                                                         1,
574                                                         address_family,
575                                                         input_str);
576                 if (rv != CONNECTION_ERROR_NONE)
577                         return -1;
578
579                 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
580                         rv = connection_profile_set_dns_address(profile,
581                                                                 2,
582                                                                 address_family,
583                                                                 input_str);
584                         if (rv != CONNECTION_ERROR_NONE)
585                                 return -1;
586                 }
587         }
588
589         return 1;
590 }
591
592 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
593 {
594         int rv = 0;
595         int input_int = 0;
596         char input_str[100] = {0,};
597
598         if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
599                                         " - (Enter for skip) :", &input_int)) {
600                 switch (input_int) {
601                 case 1:
602                         rv = connection_profile_set_proxy_type(profile,
603                                         CONNECTION_PROXY_TYPE_DIRECT);
604
605                         if (rv != CONNECTION_ERROR_NONE)
606                                 return -1;
607                         else
608                                 return 1;
609                 case 2:
610                         rv = connection_profile_set_proxy_type(profile,
611                                         CONNECTION_PROXY_TYPE_AUTO);
612                         break;
613                 case 3:
614                         rv = connection_profile_set_proxy_type(profile,
615                                         CONNECTION_PROXY_TYPE_MANUAL);
616                         break;
617                 default:
618                         return -1;
619                 }
620
621                 if (rv != CONNECTION_ERROR_NONE)
622                         return -1;
623
624                 if (test_get_user_string("Input auto Proxy URL or Proxy address"
625                                         " - (Enter for skip) :", input_str, 100)) {
626                         rv = connection_profile_set_proxy_address(profile,
627                                                                 address_family,
628                                                                 input_str);
629                         if (rv != CONNECTION_ERROR_NONE)
630                                 return -1;
631                 }
632
633         } else
634                 return -1;
635
636         return 1;
637 }
638
639 static int test_update_network_info(connection_profile_h profile)
640 {
641         int rv = 0;
642         int input_int = 0;
643         int address_family = 0;
644
645         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
646
647         if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
648                                 " - (Enter for skip) :", &input_int)) {
649                 switch (input_int) {
650                 case 1:
651                         rv = connection_profile_set_ip_config_type(profile,
652                                                                    address_family,
653                                                                    CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
654                         break;
655                 case 2:
656                         rv = connection_profile_set_ip_config_type(profile,
657                                                                    address_family,
658                                                                    CONNECTION_IP_CONFIG_TYPE_STATIC);
659                         if (rv != CONNECTION_ERROR_NONE)
660                                 return -1;
661
662                         if (test_update_ip_info(profile, address_family) == -1)
663                                 return -1;
664
665                         if (test_update_proxy_info(profile, address_family) == -1)
666                                 return -1;
667                         break;
668                 default:
669                         return -1;
670                 }
671
672                 if (rv != CONNECTION_ERROR_NONE)
673                         return -1;
674         } else
675                 return -1;
676
677         return 1;
678 }
679
680 static void test_print_cellular_info(connection_profile_h profile)
681 {
682         connection_cellular_service_type_e service_type;
683         connection_cellular_pdn_type_e pdn_type;
684         connection_cellular_pdn_type_e roam_pdn_type;
685         char *apn = NULL;
686         connection_cellular_auth_type_e auth_type;
687         char *user_name = NULL;
688         char *password = NULL;
689         char *home_url = NULL;
690         bool roaming = false;
691         bool hidden = false;
692         bool editable = false;
693
694         if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
695                 printf("Fail to get cellular service type!\n");
696         else
697                 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
698
699         if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
700                 printf("Fail to get cellular pdn type!\n");
701         else
702                 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
703
704         if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
705                 printf("Fail to get cellular roam pdn type!\n");
706         else
707                 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
708
709         if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
710                 printf("Fail to get cellular APN!\n");
711         else {
712                 printf("Cellular APN : %s\n", apn);
713                 g_free(apn);
714         }
715
716         if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
717                 printf("Fail to get auth info!\n");
718         else {
719                 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
720                 printf("Cellular user_name : %s\n", user_name);
721                 printf("Cellular password : %s\n", password);
722                 g_free(user_name);
723                 g_free(password);
724         }
725
726         if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
727                 printf("Fail to get cellular home url!\n");
728         else {
729                 printf("Cellular home url : %s\n", home_url);
730                 g_free(home_url);
731         }
732
733         if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
734                 printf("Fail to get cellular roaming state!\n");
735         else
736                 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
737
738         if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
739                 printf("Fail to get cellular hidden state!\n");
740         else
741                 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
742
743         if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
744                 printf("Fail to get cellular editing state!\n");
745         else
746                 printf("Cellular editable : %s\n", editable ? "true" : "false");
747 }
748
749 static void test_print_wifi_info(connection_profile_h profile)
750 {
751         char *essid = NULL;
752         char *bssid = NULL;
753         int rssi = 0;
754         int frequency = 0;
755         int max_speed = 0;
756         connection_wifi_security_type_e security_type;
757         connection_wifi_encryption_type_e encryption_type;
758         bool pass_required = false;
759         bool wps_supported = false;
760
761         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
762                 printf("Fail to get Wi-Fi essid!\n");
763         else {
764                 printf("Wi-Fi essid : %s\n", essid);
765                 g_free(essid);
766         }
767
768         if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
769                 printf("Fail to get Wi-Fi bssid!\n");
770         else {
771                 printf("Wi-Fi bssid : %s\n", bssid);
772                 g_free(bssid);
773         }
774
775         if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
776                 printf("Fail to get Wi-Fi rssi!\n");
777         else
778                 printf("Wi-Fi rssi : %d\n", rssi);
779
780         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
781                 printf("Fail to get Wi-Fi frequency!\n");
782         else
783                 printf("Wi-Fi frequency : %d\n", frequency);
784
785         if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
786                 printf("Fail to get Wi-Fi max speed!\n");
787         else
788                 printf("Wi-Fi max speed : %d\n", max_speed);
789
790         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
791                 printf("Fail to get Wi-Fi security type!\n");
792         else
793                 printf("Wi-Fi security type : %d\n", security_type);
794
795         if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
796                 printf("Fail to get Wi-Fi encryption type!\n");
797         else
798                 printf("Wi-Fi encryption type : %d\n", encryption_type);
799
800         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
801                 printf("Fail to get Wi-Fi passphrase required!\n");
802         else
803                 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
804
805         if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
806                 printf("Fail to get Wi-Fi wps info\n");
807         else
808                 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
809 }
810
811 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
812 {
813         char *interface_name = NULL;
814         connection_ip_config_type_e ip_type;
815         char *ip = NULL;
816         char *subnet = NULL;
817         char *gateway = NULL;
818         char *dns1 = NULL;
819         char *dns2 = NULL;
820         connection_proxy_type_e proxy_type;
821         char *proxy = NULL;
822
823         if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
824                 printf("Fail to get interface name!\n");
825         else {
826                 printf("Interface name : %s\n", interface_name);
827                 g_free(interface_name);
828         }
829
830         if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
831                 printf("Fail to get ipconfig type!\n");
832         else
833                 printf("Ipconfig type : %d\n", ip_type);
834
835         if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
836                 printf("Fail to get IP address!\n");
837         else {
838                 printf("IP address : %s\n", ip);
839                 g_free(ip);
840         }
841
842         if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
843                 printf("Fail to get subnet mask!\n");
844         else {
845                 printf("Subnet mask : %s\n", subnet);
846                 g_free(subnet);
847         }
848
849         if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
850                 printf("Fail to get gateway!\n");
851         else {
852                 printf("Gateway : %s\n", gateway);
853                 g_free(gateway);
854         }
855
856         if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
857                 printf("Fail to get DNS1!\n");
858         else {
859                 printf("DNS1 : %s\n", dns1);
860                 g_free(dns1);
861         }
862
863         if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
864                 printf("Fail to get DNS2!\n");
865         else {
866                 printf("DNS2 : %s\n", dns2);
867                 g_free(dns2);
868         }
869
870         if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
871                 printf("Fail to get proxy type!\n");
872         else
873                 printf("Proxy type : %d\n", proxy_type);
874
875         if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
876                 printf("Fail to get proxy!\n");
877         else {
878                 printf("Proxy : %s\n", proxy);
879                 g_free(proxy);
880         }
881 }
882
883 int test_register_client(void)
884 {
885
886         int err = connection_create(&connection);
887
888         if (CONNECTION_ERROR_NONE == err) {
889                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
890                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
891                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
892                 connection_set_ethernet_cable_state_chaged_cb(connection,
893                                         test_get_ethernet_cable_state_callback, NULL);
894         } else {
895                 printf("Client registration failed [%s]\n", test_print_error(err));
896                 return -1;
897         }
898
899         printf("Client registration success\n");
900         return 1;
901 }
902
903 int  test_deregister_client(void)
904 {
905         int rv = 0;
906         GSList *list;
907         connection_profile_h profile;
908
909         if (connection != NULL)
910                 rv = connection_destroy(connection);
911         else {
912                 printf("Cannot deregister : Handle is NULL\n");
913                 rv = CONNECTION_ERROR_INVALID_OPERATION;
914         }
915
916         if (rv != CONNECTION_ERROR_NONE) {
917                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
918                 return -1;
919         }
920
921         if (state_cb_list) {
922                 for (list = state_cb_list; list; list = list->next) {
923                         profile = list->data;
924                         connection_profile_destroy(profile);
925                 }
926
927                 g_slist_free(state_cb_list);
928                 state_cb_list = NULL;
929         }
930
931         connection = NULL;
932         printf("Client deregistration success\n");
933
934         return 1;
935 }
936
937 int test_get_network_state(void)
938 {
939         int rv = 0;
940         connection_type_e net_state;
941
942         rv = connection_get_type(connection, &net_state);
943
944         if (rv != CONNECTION_ERROR_NONE) {
945                 printf("Fail to get network state [%s]\n", test_print_error(rv));
946                 return -1;
947         }
948
949         printf("Retval = [%s] network connection state [%s]\n",
950                 test_print_error(rv), test_print_connection_type(net_state));
951
952         return 1;
953 }
954
955 int test_get_cellular_state(void)
956 {
957         int rv = 0;
958         connection_cellular_state_e cellular_state;
959
960         rv = connection_get_cellular_state(connection, &cellular_state);
961
962         if (rv != CONNECTION_ERROR_NONE) {
963                 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
964                 return -1;
965         }
966
967         printf("Retval = [%s] Cellular state [%s]\n",
968                 test_print_error(rv), test_print_cellular_state(cellular_state));
969
970         return 1;
971 }
972
973 int test_get_wifi_state(void)
974 {
975         int rv = 0;
976         connection_wifi_state_e wifi_state;
977
978         rv = connection_get_wifi_state(connection, &wifi_state);
979
980         if (rv != CONNECTION_ERROR_NONE) {
981                 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
982                 return -1;
983         }
984
985         printf("Retval = [%s] WiFi state [%s]\n",
986                 test_print_error(rv), test_print_wifi_state(wifi_state));
987
988         return 1;
989 }
990
991 int test_get_current_proxy(void)
992 {
993         char *proxy_addr = NULL;
994
995         connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
996
997         if (proxy_addr == NULL) {
998                 printf("Proxy address does not exist\n");
999                 return -1;
1000         }
1001
1002         printf("Current Proxy [%s]\n", proxy_addr);
1003         g_free(proxy_addr);
1004
1005         return 1;
1006 }
1007
1008 int test_get_current_ip(void)
1009 {
1010         char *ip_addr = NULL;
1011         int input;
1012         bool rv;
1013
1014         rv = test_get_user_int("Input Address type to get"
1015                 "(1:IPV4, 2:IPV6):", &input);
1016
1017         if (rv == false) {
1018                 printf("Invalid input!!\n");
1019                 return -1;
1020         }
1021
1022         switch (input) {
1023         case 1:
1024                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1025                 if (ip_addr == NULL) {
1026                         printf("IPv4 address does not exist\n");
1027                         return -1;
1028                 }
1029                 printf("IPv4 address : %s\n", ip_addr);
1030                 break;
1031
1032         case 2:
1033                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1034                 if (ip_addr == NULL) {
1035                         printf("IPv6 address does not exist\n");
1036                         return -1;
1037                 }
1038                 printf("IPv6 address : %s\n", ip_addr);
1039                 break;
1040         default:
1041                 printf("Wrong IP address family!!\n");
1042                 return -1;
1043         }
1044
1045         g_free(ip_addr);
1046         return 1;
1047 }
1048
1049 int test_get_call_statistics_info(void)
1050 {
1051         long long rv = 0;
1052
1053         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1054         printf("last recv data size [%lld]\n", rv);
1055         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1056         printf("last sent data size [%lld]\n", rv);
1057         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1058         printf("total received data size [%lld]\n", rv);
1059         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1060         printf("total sent data size [%lld]\n", rv);
1061
1062         return 1;
1063 }
1064
1065 int test_get_wifi_call_statistics_info(void)
1066 {
1067         long long rv = 0;
1068
1069         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1070         printf("WiFi last recv data size [%lld]\n", rv);
1071         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1072         printf("WiFi last sent data size [%lld]\n", rv);
1073         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1074         printf("WiFi total received data size [%lld]\n", rv);
1075         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1076         printf("WiFi total sent data size [%lld]\n", rv);
1077
1078         return 1;
1079 }
1080
1081 int test_get_profile_list(void)
1082 {
1083         if (test_get_user_selected_profile(NULL, false) == false)
1084                 return -1;
1085
1086         return 1;
1087 }
1088
1089 int test_get_default_profile_list(void)
1090 {
1091         int rv = 0;
1092         char *profile_name = NULL;
1093         connection_profile_iterator_h profile_iter;
1094         connection_profile_h profile_h;
1095         connection_cellular_service_type_e service_type;
1096         bool is_default = false;
1097
1098         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1099         if (rv != CONNECTION_ERROR_NONE) {
1100                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1101                 return -1;
1102         }
1103
1104         while (connection_profile_iterator_has_next(profile_iter)) {
1105                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1106                         printf("Fail to get profile handle\n");
1107                         return -1;
1108                 }
1109
1110                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1111                         printf("Fail to get profile name\n");
1112                         return -1;
1113                 }
1114                 printf("profile name : %s\n", profile_name);
1115                 g_free(profile_name);
1116
1117                 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1118                         printf("Fail to get profile service type\n");
1119                         return -1;
1120                 }
1121                 printf("service type : %d\n", service_type);
1122
1123                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1124                         printf("Fail to get profile subscriber id\n");
1125                         return -1;
1126                 }
1127                 printf("Default : %d\n", is_default);
1128         }
1129
1130         return 1;
1131 }
1132
1133 int test_get_connected_profile_list(void)
1134 {
1135         int rv = 0;
1136         char *profile_name = NULL;
1137         connection_profile_iterator_h profile_iter;
1138         connection_profile_h profile_h;
1139         bool is_default = false;
1140         connection_profile_type_e type;
1141
1142         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1143         if (rv != CONNECTION_ERROR_NONE) {
1144                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1145                 return -1;
1146         }
1147
1148         while (connection_profile_iterator_has_next(profile_iter)) {
1149                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1150                         printf("Fail to get profile handle\n");
1151                         return -1;
1152                 }
1153
1154                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1155                         printf("Fail to get profile name\n");
1156                         return -1;
1157                 }
1158                 printf("profile name is %s\n", profile_name);
1159                 g_free(profile_name);
1160
1161                 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1162                         printf("Fail to get profile type\n");
1163                         return -1;
1164                 }
1165                 printf("profile type is %d\n", type);
1166
1167                 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1168                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1169                         printf("Fail to get profile is default\n");
1170                         return -1;
1171                 }
1172                         printf("[%s]\n", is_default ? "default" : "not default");
1173                 }
1174         }
1175
1176         return 1;
1177 }
1178
1179 int test_get_current_profile(void)
1180 {
1181         int rv = 0;
1182         char *profile_name = NULL;
1183         connection_profile_h profile_h;
1184
1185         rv = connection_get_current_profile(connection, &profile_h);
1186         if (rv != CONNECTION_ERROR_NONE) {
1187                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1188                 return -1;
1189         }
1190
1191         if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1192                 printf("Fail to get profile name\n");
1193                 return -1;
1194         }
1195         printf("profile name : %s\n", profile_name);
1196         g_free(profile_name);
1197
1198         connection_profile_destroy(profile_h);
1199
1200         return 1;
1201 }
1202
1203 int test_open_profile(void)
1204 {
1205         connection_profile_h profile;
1206
1207         printf("\n** Choose a profile to open. **\n");
1208
1209         if (test_get_user_selected_profile(&profile, true) == false)
1210                 return -1;
1211
1212         if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1213                 printf("Connection open Failed!!\n");
1214                 return -1;
1215         }
1216
1217         return 1;
1218 }
1219
1220 int test_get_default_cellular_service_type(void)
1221 {
1222         int input;
1223         int rv;
1224         int service_type;
1225         connection_profile_h profile;
1226         char *profile_name = NULL;
1227
1228         rv = test_get_user_int("Input profile type to get"
1229                         "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1230
1231         if (rv == false) {
1232                 printf("Invalid input!!\n");
1233                 return -1;
1234         }
1235
1236         switch (input) {
1237         case 1:
1238                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1239                 break;
1240         case 2:
1241                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1242                 break;
1243         case 3:
1244                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1245                 break;
1246         case 4:
1247                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1248                 break;
1249         case 5:
1250                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1251                 break;
1252         case 6:
1253                 service_type =  CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1254                 break;
1255         default:
1256                 printf("Wrong number!!\n");
1257                 return -1;
1258         }
1259
1260         if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1261                 return -1;
1262
1263         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1264                 printf("Fail to get profile name\n");
1265                 connection_profile_destroy(profile);
1266                 return -1;
1267         }
1268         printf("Default profile name : %s\n", profile_name);
1269         g_free(profile_name);
1270
1271         connection_profile_destroy(profile);
1272
1273         return 1;
1274 }
1275
1276 int test_set_default_cellular_service_type(void)
1277 {
1278         connection_profile_h profile;
1279         connection_cellular_service_type_e type;
1280         int input, rv;
1281
1282         rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1283
1284         if (rv == false || (input != 1 && input != 2)) {
1285                 printf("Invalid input!!\n");
1286                 return -1;
1287         }
1288
1289         printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1290
1291         if (test_get_user_selected_profile(&profile, true) == false)
1292                 return -1;
1293
1294         if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1295                 printf("Fail to get cellular service type\n");
1296                 return -1;
1297         }
1298
1299         if (input == 1) {
1300                 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1301                         return -1;
1302         } else {
1303                 if (connection_set_default_cellular_service_profile_async(connection,
1304                                 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1305                         return -1;
1306         }
1307
1308         return 1;
1309 }
1310
1311 int test_close_profile(void)
1312 {
1313         connection_profile_h profile;
1314
1315         printf("\n** Choose a profile to close. **\n");
1316
1317         if (test_get_user_selected_profile(&profile, true) == false)
1318                 return -1;
1319
1320         if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1321                 printf("Connection close Failed!!\n");
1322                 return -1;
1323         }
1324
1325         return 1;
1326 }
1327
1328 int test_add_profile(void)
1329 {
1330         int rv = 0;
1331         connection_profile_h profile;
1332         char input_str[100] = {0,};
1333
1334         if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1335                 return -1;
1336
1337         g_strstrip(input_str);
1338         rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1339         if (rv != CONNECTION_ERROR_NONE)
1340                 RETURN_FAIL_DESTROY(profile);
1341
1342         if (test_update_cellular_info(profile) == -1)
1343                 RETURN_FAIL_DESTROY(profile);
1344
1345         rv = connection_add_profile(connection, profile);
1346         if (rv != CONNECTION_ERROR_NONE)
1347                 RETURN_FAIL_DESTROY(profile);
1348
1349         connection_profile_destroy(profile);
1350         return 1;
1351 }
1352
1353 int test_remove_profile(void)
1354 {
1355         connection_profile_h profile;
1356
1357         printf("\n** Choose a profile to remove. **\n");
1358         if (test_get_user_selected_profile(&profile, true) == false)
1359                 return -1;
1360
1361         if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1362                 printf("Remove profile Failed!!\n");
1363                 return -1;
1364         }
1365
1366         return 1;
1367 }
1368
1369 int test_update_profile(void)
1370 {
1371         int rv = 0;
1372
1373         connection_profile_type_e prof_type;
1374         connection_profile_h profile;
1375
1376         printf("\n** Choose a profile to update. **\n");
1377         if (test_get_user_selected_profile(&profile, true) == false)
1378                 return -1;
1379
1380         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1381                 return -1;
1382
1383         switch (prof_type) {
1384         case CONNECTION_PROFILE_TYPE_CELLULAR:
1385                 if (test_update_cellular_info(profile) == -1)
1386                         return -1;
1387
1388                 break;
1389         case CONNECTION_PROFILE_TYPE_WIFI:
1390                 if (test_update_wifi_info(profile) == -1)
1391                         return -1;
1392
1393                 if (test_update_network_info(profile) == -1)
1394                         return -1;
1395
1396                 break;
1397         case CONNECTION_PROFILE_TYPE_ETHERNET:
1398                 if (test_update_network_info(profile) == -1)
1399                         return -1;
1400                 break;
1401
1402         case CONNECTION_PROFILE_TYPE_BT:
1403                 printf("Not supported!\n");
1404                 /* fall through */
1405         default:
1406                 return -1;
1407         }
1408
1409         rv = connection_update_profile(connection, profile);
1410         if (rv != CONNECTION_ERROR_NONE)
1411                 return -1;
1412
1413         return 1;
1414 }
1415
1416 int test_get_profile_info(void)
1417 {
1418         connection_profile_type_e prof_type;
1419         connection_profile_state_e profile_state;
1420         connection_profile_h profile;
1421         char *profile_name = NULL;
1422         int address_family = 0;
1423
1424         printf("\n** Choose a profile to print. **\n");
1425         if (test_get_user_selected_profile(&profile, true) == false)
1426                 return -1;
1427
1428         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1429                 printf("Fail to get profile name\n");
1430                 return -1;
1431         } else {
1432                 printf("Profile Name : %s\n", profile_name);
1433                 g_free(profile_name);
1434         }
1435
1436         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1437                 printf("Fail to get profile state\n");
1438                 return -1;
1439         } else
1440                 printf("Profile State : %s\n", test_print_state(profile_state));
1441
1442         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1443                 return -1;
1444
1445         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1446
1447         switch (prof_type) {
1448         case CONNECTION_PROFILE_TYPE_CELLULAR:
1449                 printf("Profile Type : Cellular\n");
1450                 test_print_cellular_info(profile);
1451                 break;
1452         case CONNECTION_PROFILE_TYPE_WIFI:
1453                 printf("Profile Type : Wi-Fi\n");
1454                 test_print_wifi_info(profile);
1455                 break;
1456         case CONNECTION_PROFILE_TYPE_ETHERNET:
1457                 printf("Profile Type : Ethernet\n");
1458                 break;
1459         case CONNECTION_PROFILE_TYPE_BT:
1460                 printf("Profile Type : Bluetooth\n");
1461                 break;
1462         default:
1463                 return -1;
1464         }
1465
1466         test_print_network_info(profile, address_family);
1467
1468         return 1;
1469 }
1470
1471 int test_refresh_profile_info(void)
1472 {
1473         connection_profile_type_e prof_type;
1474         connection_profile_state_e profile_state;
1475         connection_profile_h profile;
1476         char *profile_name = NULL;
1477         int address_family = 0;
1478
1479         printf("\n** Choose a profile to refresh. **\n");
1480         if (test_get_user_selected_profile(&profile, true) == false)
1481                 return -1;
1482
1483         if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1484                 return -1;
1485
1486         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1487                 printf("Fail to get profile name\n");
1488                 return -1;
1489         } else {
1490                 printf("Profile Name : %s\n", profile_name);
1491                 g_free(profile_name);
1492         }
1493
1494         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1495                 printf("Fail to get profile state\n");
1496                 return -1;
1497         } else
1498                 printf("Profile State : %s\n", test_print_state(profile_state));
1499
1500
1501         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1502                 return -1;
1503
1504         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1505
1506         switch (prof_type) {
1507         case CONNECTION_PROFILE_TYPE_CELLULAR:
1508                 printf("Profile Type : Cellular\n");
1509                 test_print_cellular_info(profile);
1510                 break;
1511         case CONNECTION_PROFILE_TYPE_WIFI:
1512                 printf("Profile Type : Wi-Fi\n");
1513                 test_print_wifi_info(profile);
1514                 break;
1515         case CONNECTION_PROFILE_TYPE_ETHERNET:
1516                 printf("Profile Type : Ethernet\n");
1517                 break;
1518         case CONNECTION_PROFILE_TYPE_BT:
1519                 printf("Profile Type : Bluetooth\n");
1520                 break;
1521         default:
1522                 return -1;
1523         }
1524
1525         test_print_network_info(profile, address_family);
1526
1527         return 1;
1528 }
1529
1530 int test_set_state_changed_callback()
1531 {
1532         connection_profile_h profile;
1533         connection_profile_h profile_clone;
1534
1535         printf("\n** Choose a profile to set callback. **\n");
1536         if (test_get_user_selected_profile(&profile, true) == false)
1537                 return -1;
1538
1539         if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1540                 return -1;
1541
1542         if (connection_profile_set_state_changed_cb(profile,
1543                         test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1544                 connection_profile_destroy(profile_clone);
1545                 return -1;
1546         }
1547
1548         state_cb_list = g_slist_append(state_cb_list, profile_clone);
1549
1550         return 1;
1551 }
1552
1553 int test_unset_state_changed_callback()
1554 {
1555         connection_profile_h profile;
1556         GSList *list;
1557         char *profile_name = NULL;
1558         int count = 0;
1559         int input = 0;
1560
1561         printf("\n** Choose a profile to unset callback. **\n");
1562         for (list = state_cb_list; list; list = list->next) {
1563                 profile = list->data;
1564                 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1565                         printf("Fail to get profile name!\n");
1566                         return -1;
1567                 } else {
1568                         printf("%d. %s\n", count, profile_name);
1569                         g_free(profile_name);
1570                 }
1571
1572                 count++;
1573         }
1574
1575         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1576             input >= count ||
1577             input < 0) {
1578                 printf("Wrong number!!\n");
1579                 return -1;
1580         }
1581
1582         count = 0;
1583         for (list = state_cb_list; list; list = list->next) {
1584                 if (count == input) {
1585                         profile = list->data;
1586                         goto unset;
1587                 }
1588
1589                 count++;
1590         }
1591
1592         return -1;
1593
1594 unset:
1595         if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1596                 return -1;
1597
1598         state_cb_list = g_slist_remove(state_cb_list, profile);
1599         connection_profile_destroy(profile);
1600
1601         return 1;
1602 }
1603
1604 int test_reset_call_statistics_info(void)
1605 {
1606         int ret = CONNECTION_ERROR_NONE;
1607
1608         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1609         printf("reset last recv data size [%d]\n", ret);
1610         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1611         printf("last sent data size [%d]\n", ret);
1612         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1613         printf("total received data size [%d]\n", ret);
1614         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1615         printf("total sent data size [%d]\n", ret);
1616
1617         return 1;
1618 }
1619
1620 int test_reset_wifi_call_statistics_info(void)
1621 {
1622         int ret = CONNECTION_ERROR_NONE;
1623
1624         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1625         printf("WiFi last sent data size [%d]\n", ret);
1626         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1627         printf("WiFi last recv data size [%d]\n", ret);
1628         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1629         printf("WiFi total sent data size [%d]\n", ret);
1630         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1631         printf("WiFi total received data size [%d]\n", ret);
1632
1633         return 1;
1634 }
1635
1636 int test_add_route(void)
1637 {
1638         int rv = 0;
1639         char ip_addr[100] = {0};
1640         char if_name[40] = {0};
1641
1642         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1643                 return -1;
1644
1645         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1646                 return -1;
1647
1648         g_strstrip(ip_addr);
1649         g_strstrip(if_name);
1650         rv = connection_add_route(connection, if_name, ip_addr);
1651         if (rv != CONNECTION_ERROR_NONE) {
1652                 printf("Fail to get add new route [%d]\n", rv);
1653                 return -1;
1654         }
1655         printf("Add Route successfully\n");
1656
1657         return 1;
1658 }
1659
1660 int test_remove_route(void)
1661 {
1662         int rv = 0;
1663         char ip_addr[100] = {0};
1664         char if_name[40] = {0};
1665
1666         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1667                 return -1;
1668
1669         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1670                 return -1;
1671
1672         g_strstrip(ip_addr);
1673         g_strstrip(if_name);
1674         rv = connection_remove_route(connection, if_name, ip_addr);
1675         if (rv != CONNECTION_ERROR_NONE) {
1676                 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1677                 return -1;
1678         }
1679         printf("Remove Route successfully\n");
1680
1681         return 1;
1682 }
1683
1684 int test_add_route_ipv6(void)
1685 {
1686         int rv = 0;
1687         char ip_addr[100] = {0};
1688         char gateway[100] = {0};
1689         char if_name[40] = {0};
1690
1691         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1692                 return -1;
1693
1694         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1695                 return -1;
1696
1697         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1698                 return -1;
1699
1700         g_strstrip(ip_addr);
1701         g_strstrip(gateway);
1702         g_strstrip(if_name);
1703         rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1704         if (rv != CONNECTION_ERROR_NONE) {
1705                 printf("Fail to get add new route [%d]\n", rv);
1706                 return -1;
1707         }
1708         printf("Add Route successfully\n");
1709
1710         return 1;
1711 }
1712
1713 int test_remove_route_ipv6(void)
1714 {
1715         int rv = 0;
1716         char ip_addr[100] = {0};
1717         char gateway[100] = {0};
1718         char if_name[40] = {0};
1719
1720         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1721                 return -1;
1722
1723         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1724                 return -1;
1725
1726         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1727                 return -1;
1728
1729         g_strstrip(ip_addr);
1730         g_strstrip(gateway);
1731         g_strstrip(if_name);
1732         rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1733         if (rv != CONNECTION_ERROR_NONE) {
1734                 printf("Fail to remove the route [%d]\n", rv);
1735                 return -1;
1736         }
1737         printf("Remove Route successfully\n");
1738
1739         return 1;
1740 }
1741
1742 int test_get_bt_state(void)
1743 {
1744         int rv = 0;
1745         connection_bt_state_e bt_state;
1746
1747         rv = connection_get_bt_state(connection, &bt_state);
1748
1749         if (rv != CONNECTION_ERROR_NONE) {
1750                 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
1751                 return -1;
1752         }
1753
1754         printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
1755
1756         return 1;
1757 }
1758
1759 int test_get_profile_id(void)
1760 {
1761         connection_profile_h profile;
1762         char *profile_id;
1763
1764         printf("\n** Choose a profile to see profile id. **\n");
1765         if (test_get_user_selected_profile(&profile, true) == false)
1766                 return -1;
1767
1768         if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1769                 printf("Fail to get profile name\n");
1770                 return -1;
1771         } else {
1772                 printf("Profile id : %s\n", profile_id);
1773                 g_free(profile_id);
1774         }
1775
1776         return 1;
1777 }
1778
1779 int test_get_mac_address(void)
1780 {
1781         int rv = 0, type = 0;
1782         connection_type_e conn_type;
1783         char *mac_addr = NULL;
1784
1785         test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
1786
1787         switch (type) {
1788         case 1:
1789                 conn_type = CONNECTION_TYPE_WIFI;
1790                 break;
1791         case 2:
1792                 conn_type = CONNECTION_TYPE_ETHERNET;
1793                 break;
1794         default:
1795                 printf("Wrong number!!\n");
1796                 return -1;
1797         }
1798
1799         rv = connection_get_mac_address(connection, conn_type, &mac_addr);
1800
1801         if (rv != CONNECTION_ERROR_NONE) {
1802                 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
1803                 return -1;
1804         }
1805
1806         printf("mac address is %s\n", mac_addr);
1807
1808         g_free(mac_addr);
1809
1810         return 1;
1811 }
1812
1813 int test_get_ethernet_cable_state(void)
1814 {
1815         int rv = 0;
1816         connection_ethernet_cable_state_e cable_state;
1817
1818         rv = connection_get_ethernet_cable_state(connection, &cable_state);
1819
1820         if (rv != CONNECTION_ERROR_NONE) {
1821                 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
1822                 return -1;
1823         }
1824
1825         printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
1826
1827         return 1;
1828 }
1829
1830 int test_reset_profile(void)
1831 {
1832         int type, sim_id, rv;
1833
1834         rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
1835
1836         if (rv == false || (type != 0 && type != 1)) {
1837                 printf("Invalid input!!\n");
1838                 return -1;
1839         }
1840
1841         rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
1842
1843         if (rv == false || (sim_id != 0 && sim_id != 1)) {
1844                 printf("Invalid input!!\n");
1845                 return -1;
1846         }
1847
1848         if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
1849                 return -1;
1850
1851         return 1;
1852 }
1853
1854 int main(int argc, char **argv)
1855 {
1856         GMainLoop *mainloop;
1857         mainloop = g_main_loop_new(NULL, FALSE);
1858
1859         GIOChannel *channel = g_io_channel_unix_new(0);
1860         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1861
1862         printf("Test Thread created...\n");
1863
1864         g_main_loop_run(mainloop);
1865
1866         return 0;
1867 }
1868
1869 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1870 {
1871         int rv = 0;
1872         char a[100];
1873
1874         memset(a, '\0', 100);
1875         printf("Event received from stdin\n");
1876
1877         rv = read(0, a, 100);
1878
1879         if (rv < 0 || a[0] == '0') {
1880                 if (connection != NULL)
1881                         test_deregister_client();
1882
1883                 exit(1);
1884         }
1885
1886         if (*a == '\n' || *a == '\r') {
1887                 printf("\n\n Network Connection API Test App\n\n");
1888                 printf("Options..\n");
1889                 printf(LOG_GREEN "1   - Create Handle and set callbacks\n" LOG_END);
1890                 printf("2   - Destroy Handle(unset callbacks automatically)\n");
1891                 printf(LOG_GREEN "3   - Get network state\n" LOG_END);
1892                 printf(LOG_GREEN "4   - Get cellular state (please insert SIM Card)\n" LOG_END);
1893                 printf(LOG_GREEN "5   - Get wifi state (please turn on WiFi)\n" LOG_END);
1894                 printf("6   - Get current proxy address \n");
1895                 printf("7   - Get current Ip address\n");
1896                 printf("8   - Get cellular data call statistics\n");
1897                 printf("9   - Get WiFi data call statistics\n");
1898                 printf(LOG_GREEN "a   - Get Profile list\n" LOG_END);
1899                 printf(LOG_GREEN "b   - Get Connected Profile list\n" LOG_END);
1900                 printf(LOG_GREEN "c   - Get Current profile\n" LOG_END);
1901                 printf("d   - Open connection with profile\n");
1902                 printf("e   - Get default cellular service by type\n");
1903                 printf("f   - Set default cellular service by type\n");
1904                 printf("g   - Close connection with profile\n");
1905                 printf("h   - Add profile(Cellular and Wifi only)\n");
1906                 printf("i   - Remove profile(Cellular:delete, WiFi:forgot)\n");
1907                 printf("j   - Update profile\n");
1908                 printf("k   - Get profile info\n");
1909                 printf("l   - Refresh profile info\n");
1910                 printf("m   - Set state changed callback\n");
1911                 printf("n   - Unset state changed callback\n");
1912                 printf("o   - Reset cellular data call statistics\n");
1913                 printf("p   - Reset WiFi data call statistics\n");
1914                 printf("q   - Add new route\n");
1915                 printf("r   - Remove a route\n");
1916                 printf("s   - Get Bluetooth state\n");
1917                 printf("t   - Get profile id\n");
1918                 printf("u   - Reset profile\n");
1919                 printf("v   - Get all cellular default profiles\n");
1920                 printf("w   - Get mac address\n");
1921                 printf("x   - Get ethernet cable state\n");
1922                 printf("B   - Add IPv6 new route\n");
1923                 printf("C   - Remove IPv6 route\n");
1924                 printf(LOG_RED "0   - Exit \n" LOG_END);
1925                 printf("ENTER   - Show options menu.......\n");
1926         }
1927
1928         switch (a[0]) {
1929         case '1':
1930                 rv = test_register_client();
1931                 break;
1932         case '2':
1933                 rv = test_deregister_client();
1934                 break;
1935         case '3':
1936                 rv = test_get_network_state();
1937                 break;
1938         case '4':
1939                 rv = test_get_cellular_state();
1940                 break;
1941         case '5':
1942                 rv = test_get_wifi_state();
1943                 break;
1944         case '6':
1945                 rv = test_get_current_proxy();
1946                 break;
1947         case '7':
1948                 rv = test_get_current_ip();
1949                 break;
1950         case '8':
1951                 rv = test_get_call_statistics_info();
1952                 break;
1953         case '9':
1954                 rv = test_get_wifi_call_statistics_info();
1955                 break;
1956         case 'a':
1957                 rv = test_get_profile_list();
1958                 break;
1959         case 'b':
1960                 rv = test_get_connected_profile_list();
1961                 break;
1962         case 'c':
1963                 rv = test_get_current_profile();
1964                 break;
1965         case 'd':
1966                 rv = test_open_profile();
1967                 break;
1968         case 'e':
1969                 rv = test_get_default_cellular_service_type();
1970                 break;
1971         case 'f':
1972                 rv = test_set_default_cellular_service_type();
1973                 break;
1974         case 'g':
1975                 rv = test_close_profile();
1976                 break;
1977         case 'h':
1978                 rv = test_add_profile();
1979                 break;
1980         case 'i':
1981                 rv = test_remove_profile();
1982                 break;
1983         case 'j':
1984                 rv = test_update_profile();
1985                 break;
1986         case 'k':
1987                 rv = test_get_profile_info();
1988                 break;
1989         case 'l':
1990                 rv = test_refresh_profile_info();
1991                 break;
1992         case 'm':
1993                 rv = test_set_state_changed_callback();
1994                 break;
1995         case 'n':
1996                 rv = test_unset_state_changed_callback();
1997                 break;
1998         case 'o':
1999                 rv = test_reset_call_statistics_info();
2000                 break;
2001         case 'p':
2002                 rv = test_reset_wifi_call_statistics_info();
2003                 break;
2004         case 'q':
2005                 rv = test_add_route();
2006                 break;
2007         case 'r':
2008                 rv = test_remove_route();
2009                 break;
2010         case 's':
2011                 rv = test_get_bt_state();
2012                 break;
2013         case 't':
2014                 rv = test_get_profile_id();
2015                 break;
2016         case 'u':
2017                 rv = test_reset_profile();
2018                 break;
2019         case 'v':
2020                 rv = test_get_default_profile_list();
2021                 break;
2022         case 'w':
2023                 rv = test_get_mac_address();
2024                 break;
2025         case 'x':
2026                 rv = test_get_ethernet_cable_state();
2027                 break;
2028         case 'B':
2029                 rv = test_add_route_ipv6();
2030                 break;
2031         case 'C':
2032                 rv = test_remove_route_ipv6();
2033                 break;
2034         }
2035
2036         if (rv == 1)
2037                 printf("Operation succeeded!\n");
2038         else
2039                 printf("Operation failed!\n");
2040
2041         return TRUE;
2042 }