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