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