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