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