Added CAPIs for C# thread handling
[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 #include "connection_extension.h"
26
27 #include <tizen_error.h>
28
29 #define LOG_RED "\033[0;31m"
30 #define LOG_GREEN "\033[0;32m"
31 #define LOG_BROWN "\033[0;33m"
32 #define LOG_BLUE "\033[0;34m"
33 #define LOG_END "\033[0;m"
34
35 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1; }
36
37 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
38
39 connection_h connection = NULL;
40 static GSList *state_cb_list = NULL;
41
42
43 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
44 {
45         if (msg == NULL || buf == NULL || buf_size < 2)
46                 return false;
47
48         int rv;
49         printf("%s\n", msg);
50         memset(buf, 0, buf_size);
51         rv = read(0, buf, buf_size - 1);
52
53         if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
54                 buf[0] = '\0';
55                 return false;
56         }
57
58         buf[rv-1] = '\0';
59         return true;
60 }
61
62 static bool test_get_user_int(const char *msg, int *num)
63 {
64         if (msg == NULL || num == NULL)
65                 return false;
66
67         int rv;
68         char buf[32] = {0,};
69         printf("%s\n", msg);
70         rv = read(0, buf, 32);
71
72         if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
73                 return false;
74
75         *num = atoi(buf);
76         return true;
77 }
78
79 static const char *test_print_state(connection_profile_state_e state)
80 {
81         switch (state) {
82         case CONNECTION_PROFILE_STATE_DISCONNECTED:
83                 return "Disconnected";
84         case CONNECTION_PROFILE_STATE_ASSOCIATION:
85                 return "Association";
86         case CONNECTION_PROFILE_STATE_CONFIGURATION:
87                 return "Configuration";
88         case CONNECTION_PROFILE_STATE_CONNECTED:
89                 return "Connected";
90         default:
91                 return "Unknown";
92         }
93 }
94
95 static const char *test_print_connection_type(connection_type_e type)
96 {
97         switch (type) {
98         case CONNECTION_TYPE_DISCONNECTED:
99                 return "Disconnected";
100         case CONNECTION_TYPE_WIFI:
101                 return "Wifi";
102         case CONNECTION_TYPE_CELLULAR:
103                 return "Cellular";
104         case CONNECTION_TYPE_ETHERNET:
105                 return "Ethernet";
106         case CONNECTION_TYPE_BT:
107                 return "BT";
108         case CONNECTION_TYPE_NET_PROXY:
109                 return "Net_Proxy";
110         default:
111                 return "Unknown";
112         }
113 }
114
115 static const char *test_print_cellular_state(connection_cellular_state_e state)
116 {
117         switch (state) {
118         case CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE:
119                 return "Out of service";
120         case CONNECTION_CELLULAR_STATE_FLIGHT_MODE:
121                 return "Flight mode";
122         case CONNECTION_CELLULAR_STATE_ROAMING_OFF:
123                 return "Roaming off";
124         case CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE:
125                 return "Call only available";
126         case CONNECTION_CELLULAR_STATE_AVAILABLE:
127                 return "Available";
128         case CONNECTION_CELLULAR_STATE_CONNECTED:
129                 return "Connected";
130         default:
131                 return "Unknown";
132         }
133 }
134
135 static const char *test_print_wifi_state(connection_wifi_state_e state)
136 {
137         switch (state) {
138         case CONNECTION_WIFI_STATE_DEACTIVATED:
139                 return "Deactivated";
140         case CONNECTION_WIFI_STATE_DISCONNECTED:
141                 return "Disconnected";
142         case CONNECTION_WIFI_STATE_CONNECTED:
143                 return "Connected";
144         default:
145                 return "Unknown";
146         }
147 }
148
149 static const char *test_print_cellular_service_type(connection_cellular_service_type_e type)
150 {
151         switch (type) {
152         case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN:
153                 return "Unknown";
154         case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET:
155                 return "Internet";
156         case CONNECTION_CELLULAR_SERVICE_TYPE_MMS:
157                 return "MMS";
158         case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET:
159                 return "Prepaid internet";
160         case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS:
161                 return "Prepaid MMS";
162         case CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING:
163                 return "Tethering";
164         case CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION:
165                 return "Application";
166         default:
167                 return "Unknown";
168         }
169 }
170
171 static const char* test_print_cellular_auth_type(connection_cellular_auth_type_e type)
172 {
173         switch (type) {
174         case CONNECTION_CELLULAR_AUTH_TYPE_PAP:
175                 return "PAP";
176         case CONNECTION_CELLULAR_AUTH_TYPE_CHAP:
177                 return "CHAP";
178         case CONNECTION_CELLULAR_AUTH_TYPE_NONE:
179         default:
180                 return "None";
181         }
182 }
183
184 static const char* test_print_cellular_pdn_type(connection_cellular_pdn_type_e type)
185 {
186         switch (type) {
187         case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
188                 return "IPv4";
189         case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
190                 return "IPv6";
191         case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
192                 return "Dual";
193         case CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN:
194         default:
195                 return "Unknown";
196         }
197 }
198
199 static const char *test_print_error(connection_error_e error)
200 {
201         switch (error) {
202         case CONNECTION_ERROR_NONE:
203                 return "CONNECTION_ERROR_NONE";
204         case CONNECTION_ERROR_INVALID_PARAMETER:
205                 return "CONNECTION_ERROR_INVALID_PARAMETER";
206         case CONNECTION_ERROR_OUT_OF_MEMORY:
207                 return "CONNECTION_ERROR_OUT_OF_MEMORY";
208         case CONNECTION_ERROR_INVALID_OPERATION:
209                 return "CONNECTION_ERROR_INVALID_OPERATION";
210         case CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED:
211                 return "CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED";
212         case CONNECTION_ERROR_OPERATION_FAILED:
213                 return "CONNECTION_ERROR_OPERATION_FAILED";
214         case CONNECTION_ERROR_ITERATOR_END:
215                 return "CONNECTION_ERROR_ITERATOR_END";
216         case CONNECTION_ERROR_NO_CONNECTION:
217                 return "CONNECTION_ERROR_NO_CONNECTION";
218         case CONNECTION_ERROR_NOW_IN_PROGRESS:
219                 return "CONNECTION_ERROR_NOW_IN_PROGRESS";
220         case CONNECTION_ERROR_ALREADY_EXISTS:
221                 return "CONNECTION_ERROR_ALREADY_EXISTS";
222         case CONNECTION_ERROR_OPERATION_ABORTED:
223                 return "CONNECTION_ERROR_OPERATION_ABORTED";
224         case CONNECTION_ERROR_DHCP_FAILED:
225                 return "CONNECTION_ERROR_DHCP_FAILED";
226         case CONNECTION_ERROR_INVALID_KEY:
227                 return "CONNECTION_ERROR_INVALID_KEY";
228         case CONNECTION_ERROR_NO_REPLY:
229                 return "CONNECTION_ERROR_NO_REPLY";
230         case CONNECTION_ERROR_PERMISSION_DENIED:
231                 return "CONNECTION_ERROR_PERMISSION_DENIED";
232         case CONNECTION_ERROR_NOT_SUPPORTED:
233                 return "CONNECTION_ERROR_NOT_SUPPORTED";
234         default:
235                 return "CONNECTION_ERROR_UNKNOWN";
236         }
237 }
238
239 static void test_type_changed_callback(connection_type_e type, void* user_data)
240 {
241         printf("Type changed callback, connection type : %d\n", type);
242 }
243
244 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
245 {
246         printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
247                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
248 }
249
250 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
251 {
252         printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
253                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
254 }
255
256 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
257 {
258         char *profile_name;
259         connection_profile_h profile = user_data;
260
261         if (profile == NULL)
262                 return;
263
264         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
265                 return;
266
267         printf("[%s] : %s\n", test_print_state(state), profile_name);
268         g_free(profile_name);
269 }
270
271 static void test_connection_opened_callback(connection_error_e result, void* user_data)
272 {
273         if (result ==  CONNECTION_ERROR_NONE)
274                 printf("Connection open Succeeded\n");
275         else
276                 printf("Connection open Failed, err : [%s]\n", test_print_error(result));
277 }
278
279 static void test_connection_closed_callback(connection_error_e result, void* user_data)
280 {
281         if (result ==  CONNECTION_ERROR_NONE)
282                 printf("Connection close Succeeded\n");
283         else
284                 printf("Connection close Failed, err : [%s]\n", test_print_error(result));
285 }
286
287 static void test_connection_reset_profile_callback(connection_error_e result, void* user_data)
288 {
289         if (result ==  CONNECTION_ERROR_NONE)
290                 printf("Reset profile Succeeded\n");
291         else
292                 printf("Reset profile Failed, err : [%s]\n", test_print_error(result));
293 }
294
295 static void test_connection_set_default_callback(connection_error_e result, void* user_data)
296 {
297         if (result ==  CONNECTION_ERROR_NONE)
298                 printf("Default profile setting Succeeded\n");
299         else
300                 printf("Default profile setting Failed, err : [%s]\n", test_print_error(result));
301 }
302
303 void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state,
304                                                                 void* user_data)
305 {
306         if (state == CONNECTION_ETHERNET_CABLE_ATTACHED)
307                 printf("Ethernet Cable Connected\n");
308         else if (state == CONNECTION_ETHERNET_CABLE_DETACHED)
309                 printf("Ethernet Cable Disconnected\n");
310 }
311
312 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
313 {
314         int rv = 0;
315         int input = 0;
316         char *profile_name;
317         connection_profile_type_e profile_type;
318         connection_profile_state_e profile_state;
319         connection_profile_iterator_h profile_iter;
320         connection_profile_h profile_h;
321
322         connection_profile_h profile_list[100] = {0,};
323         int profile_count = 0;
324
325         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
326         if (rv != CONNECTION_ERROR_NONE) {
327                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
328                 return false;
329         }
330
331         while (connection_profile_iterator_has_next(profile_iter)) {
332                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
333                         printf("Fail to get profile handle\n");
334                         return false;
335                 }
336
337                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
338                         printf("Fail to get profile name\n");
339                         return false;
340                 }
341
342                 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
343                         printf("Fail to get profile type\n");
344                         g_free(profile_name);
345                         return false;
346                 }
347
348                 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
349                         printf("Fail to get profile state\n");
350                         g_free(profile_name);
351                         return false;
352                 }
353
354                 printf("%d. state:[%s], profile name:%s", profile_count,
355                                 test_print_state(profile_state), profile_name);
356                 if (profile_type == CONNECTION_PROFILE_TYPE_CELLULAR) {
357                         connection_cellular_service_type_e service_type;
358                         if (connection_profile_get_cellular_service_type(
359                                 profile_h, &service_type) !=
360                                 CONNECTION_ERROR_NONE)
361                                 printf("Fail to get cellular service type!\n");
362
363                         printf("[%s]",
364                                 test_print_cellular_service_type(service_type));
365                 }
366                 printf("\n");
367
368                 profile_list[profile_count] = profile_h;
369                 profile_count++;
370
371                 g_free(profile_name);
372                 if (profile_count >= 100)
373                         break;
374         }
375
376         if (select == false)
377                 return true;
378
379         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
380             input >= profile_count ||
381             input < 0) {
382                 printf("Wrong number!!\n");
383                 return false;
384         }
385
386         if (profile)
387                 *profile = profile_list[input];
388
389         return true;
390 }
391
392 static int test_update_cellular_info(connection_profile_h profile)
393 {
394         int rv = 0;
395         char input_str1[100] = {0,};
396         char input_str2[100] = {0,};
397         int input_int = 0;
398         int type_val = 0;
399
400         if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
401                         "Prepaid MMS:4, Tethering:5, Application:6)"
402                         " - (Enter for skip) :", &input_int)) {
403                 switch (input_int) {
404                 case 1:
405                         rv = connection_profile_set_cellular_service_type(profile,
406                                         CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
407                         break;
408                 case 2:
409                         rv = connection_profile_set_cellular_service_type(profile,
410                                         CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
411                         break;
412                 case 3:
413                         rv = connection_profile_set_cellular_service_type(profile,
414                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
415                         break;
416                 case 4:
417                         rv = connection_profile_set_cellular_service_type(profile,
418                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
419                         break;
420                 case 5:
421                         rv = connection_profile_set_cellular_service_type(profile,
422                                         CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
423                         break;
424                 case 6:
425                         rv = connection_profile_set_cellular_service_type(profile,
426                                         CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
427                         break;
428                 default:
429                         return -1;
430                 }
431
432                 if (rv != CONNECTION_ERROR_NONE)
433                         return -1;
434         } else
435                 return -1;
436
437         if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
438                 g_strstrip(input_str1);
439                 rv = connection_profile_set_cellular_apn(profile, input_str1);
440                 if (rv != CONNECTION_ERROR_NONE)
441                         return -1;
442         }
443
444         if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
445                 g_strstrip(input_str1);
446                 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
447                 if (rv != CONNECTION_ERROR_NONE)
448                         return -1;
449         }
450
451         if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
452                 g_strstrip(input_str1);
453                 rv = connection_profile_set_cellular_home_url(profile, input_str1);
454                 if (rv != CONNECTION_ERROR_NONE)
455                         return -1;
456         }
457
458         if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
459                 switch (input_int) {
460                 case 0:
461                         rv = connection_profile_set_cellular_auth_info(profile,
462                                         CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
463                         if (rv != CONNECTION_ERROR_NONE)
464                                 return -1;
465
466                         break;
467                 case 1:
468                         type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
469                         /* fall through */
470                 case 2:
471                         if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
472
473                         if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
474                                 input_str1[0] = 0;
475                         if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
476                                 input_str2[0] = 0;
477
478                         g_strstrip(input_str1);
479                         g_strstrip(input_str2);
480                         rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
481                         if (rv != CONNECTION_ERROR_NONE)
482                                 return -1;
483                 }
484         }
485
486         if (test_get_user_int("Input PdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
487                 switch (input_int) {
488                 case 1:
489                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
490                         break;
491                 case 2:
492                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
493                         break;
494                 case 3:
495                         rv = connection_profile_set_cellular_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
496                         break;
497                 }
498
499                 if (rv != CONNECTION_ERROR_NONE)
500                         return -1;
501         }
502
503         if (test_get_user_int("Input RoamPdnType(1:IPv4 2:IPv6 3:IPv4v6) - (Enter for skip) :", &input_int)) {
504                 switch (input_int) {
505                 case 1:
506                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4);
507                         break;
508                 case 2:
509                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV6);
510                         break;
511                 case 3:
512                         rv = connection_profile_set_cellular_roam_pdn_type(profile, CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6);
513                         break;
514                 }
515
516                 if (rv != CONNECTION_ERROR_NONE)
517                         return -1;
518         }
519
520         return 1;
521 }
522
523 static int test_update_wifi_info(connection_profile_h profile)
524 {
525         int rv = 0;
526         char input_str[100] = {0,};
527
528         if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
529                 rv = connection_profile_set_wifi_passphrase(profile, input_str);
530                 if (rv != CONNECTION_ERROR_NONE)
531                         return -1;
532         }
533
534         return 1;
535 }
536
537 static int test_update_dns_info(connection_profile_h profile,
538                 connection_address_family_e address_family)
539 {
540         int rv = 0;
541         char input_str[100] = {0,};
542         if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
543                 rv = connection_profile_set_dns_address(profile,
544                                 1,
545                                 address_family,
546                                 input_str);
547                 if (rv != CONNECTION_ERROR_NONE)
548                         return -1;
549
550                 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
551                         rv = connection_profile_set_dns_address(profile,
552                                         2,
553                                         address_family,
554                                         input_str);
555                         if (rv != CONNECTION_ERROR_NONE)
556                                 return -1;
557                 }
558         }
559         return 1;
560 }
561
562 static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family)
563 {
564         int rv = 0;
565         int input_int = 0;
566         char input_str[100] = {0,};
567
568         if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
569                 rv = connection_profile_set_ip_address(profile,
570                                                         address_family,
571                                                         input_str);
572                 if (rv != CONNECTION_ERROR_NONE)
573                         return -1;
574         }
575
576         if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
577                 rv = connection_profile_set_subnet_mask(profile,
578                                                         address_family,
579                                                         input_str);
580                 if (rv != CONNECTION_ERROR_NONE)
581                         return -1;
582         }
583
584         if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) {
585                 rv = connection_profile_set_prefix_length(profile,
586                                                         address_family,
587                                                         input_int);
588                 if (rv != CONNECTION_ERROR_NONE)
589                         return -1;
590         }
591
592         if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
593                 rv = connection_profile_set_gateway_address(profile,
594                                                         address_family,
595                                                         input_str);
596                 if (rv != CONNECTION_ERROR_NONE)
597                         return -1;
598         }
599
600         if (test_update_dns_info(profile, address_family) < 0)
601                 return -1;
602
603         return 1;
604 }
605
606 static int test_update_proxy_info(connection_profile_h profile, connection_address_family_e address_family)
607 {
608         int rv = 0;
609         int input_int = 0;
610         char input_str[100] = {0,};
611
612         if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
613                                         " - (Enter for skip) :", &input_int)) {
614                 switch (input_int) {
615                 case 1:
616                         rv = connection_profile_set_proxy_type(profile,
617                                         CONNECTION_PROXY_TYPE_DIRECT);
618
619                         if (rv != CONNECTION_ERROR_NONE)
620                                 return -1;
621                         else
622                                 return 1;
623                 case 2:
624                         rv = connection_profile_set_proxy_type(profile,
625                                         CONNECTION_PROXY_TYPE_AUTO);
626                         break;
627                 case 3:
628                         rv = connection_profile_set_proxy_type(profile,
629                                         CONNECTION_PROXY_TYPE_MANUAL);
630                         break;
631                 default:
632                         return -1;
633                 }
634
635                 if (rv != CONNECTION_ERROR_NONE)
636                         return -1;
637
638                 if (test_get_user_string("Input auto Proxy URL or Proxy address"
639                                         " - (Enter for skip) :", input_str, 100)) {
640                         rv = connection_profile_set_proxy_address(profile,
641                                                                 address_family,
642                                                                 input_str);
643                         if (rv != CONNECTION_ERROR_NONE)
644                                 return -1;
645                 }
646
647         } else
648                 return -1;
649
650         return 1;
651 }
652
653
654
655 static int test_update_network_info(connection_profile_h profile)
656 {
657         int rv = 0;
658         int input_int = 0;
659         int dns_input = 0;
660         int address_family = 0;
661
662         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
663
664         if (test_get_user_int("Input IPv4/IPv6 Address Type (DHCP:1, Static:2, Auto:3)"
665                                 " - (Enter for skip) :", &input_int)) {
666                 switch (input_int) {
667                 case 1:
668                         rv = connection_profile_set_ip_config_type(profile,
669                                         address_family,
670                                         CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
671                         if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)"
672                                                 " - (Enter for skip) :", &dns_input)) {
673                                 switch (dns_input) {
674                                 case CONNECTION_DNS_CONFIG_TYPE_STATIC:
675                                         rv = connection_profile_set_dns_config_type(
676                                                         profile,
677                                                         address_family,
678                                                         CONNECTION_DNS_CONFIG_TYPE_STATIC);
679                                         if (rv != CONNECTION_ERROR_NONE)
680                                                 return -1;
681                                         if (test_update_dns_info(profile,
682                                                                 address_family) == -1)
683                                                 return -1;
684                                         break;
685                                 case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC:
686                                         rv = connection_profile_set_dns_config_type(
687                                                         profile,
688                                                         address_family,
689                                                         CONNECTION_DNS_CONFIG_TYPE_DYNAMIC);
690                                         if (rv != CONNECTION_ERROR_NONE)
691                                                 return -1;
692                                         break;
693                                 }
694                         }
695                         break;
696                 case 2:
697                         rv = connection_profile_set_ip_config_type(profile,
698                                                                    address_family,
699                                                                    CONNECTION_IP_CONFIG_TYPE_STATIC);
700                         if (rv != CONNECTION_ERROR_NONE)
701                                 return -1;
702
703                         if (test_update_ip_info(profile, address_family) == -1)
704                                 return -1;
705
706                         if (test_update_proxy_info(profile, address_family) == -1)
707                                 return -1;
708                         break;
709                 case 3:
710                         rv = connection_profile_set_ip_config_type(profile,
711                                                                 address_family,
712                                                                 CONNECTION_IP_CONFIG_TYPE_AUTO);
713                         break;
714                 default:
715                         return -1;
716                 }
717
718                 if (rv != CONNECTION_ERROR_NONE)
719                         return -1;
720         } else
721                 return -1;
722
723         return 1;
724 }
725
726 static void test_print_cellular_info(connection_profile_h profile)
727 {
728         connection_cellular_service_type_e service_type;
729         connection_cellular_pdn_type_e pdn_type;
730         connection_cellular_pdn_type_e roam_pdn_type;
731         char *apn = NULL;
732         connection_cellular_auth_type_e auth_type;
733         char *user_name = NULL;
734         char *password = NULL;
735         char *home_url = NULL;
736         bool roaming = false;
737         bool hidden = false;
738         bool editable = false;
739
740         if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
741                 printf("Fail to get cellular service type!\n");
742         else
743                 printf("Cellular service type : %s\n", test_print_cellular_service_type(service_type));
744
745         if (connection_profile_get_cellular_pdn_type(profile, &pdn_type) != CONNECTION_ERROR_NONE)
746                 printf("Fail to get cellular pdn type!\n");
747         else
748                 printf("Cellular pdn type : %s\n", test_print_cellular_pdn_type(pdn_type));
749
750         if (connection_profile_get_cellular_roam_pdn_type(profile, &roam_pdn_type) != CONNECTION_ERROR_NONE)
751                 printf("Fail to get cellular roam pdn type!\n");
752         else
753                 printf("Cellular roam pdn type : %s\n", test_print_cellular_pdn_type(roam_pdn_type));
754
755         if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
756                 printf("Fail to get cellular APN!\n");
757         else {
758                 printf("Cellular APN : %s\n", apn);
759                 g_free(apn);
760         }
761
762         if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
763                 printf("Fail to get auth info!\n");
764         else {
765                 printf("Cellular auth type : %s\n", test_print_cellular_auth_type(auth_type));
766                 printf("Cellular user_name : %s\n", user_name);
767                 printf("Cellular password : %s\n", password);
768                 g_free(user_name);
769                 g_free(password);
770         }
771
772         if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
773                 printf("Fail to get cellular home url!\n");
774         else {
775                 printf("Cellular home url : %s\n", home_url);
776                 g_free(home_url);
777         }
778
779         if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
780                 printf("Fail to get cellular roaming state!\n");
781         else
782                 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
783
784         if (connection_profile_is_cellular_hidden(profile, &hidden) != CONNECTION_ERROR_NONE)
785                 printf("Fail to get cellular hidden state!\n");
786         else
787                 printf("Cellular hidden : %s\n", hidden ? "true" : "false");
788
789         if (connection_profile_is_cellular_editable(profile, &editable) != CONNECTION_ERROR_NONE)
790                 printf("Fail to get cellular editing state!\n");
791         else
792                 printf("Cellular editable : %s\n", editable ? "true" : "false");
793 }
794
795 static void test_print_wifi_info(connection_profile_h profile)
796 {
797         char *essid = NULL;
798         char *bssid = NULL;
799         int rssi = 0;
800         int frequency = 0;
801         int max_speed = 0;
802         connection_wifi_security_type_e security_type;
803         connection_wifi_encryption_type_e encryption_type;
804         bool pass_required = false;
805         bool wps_supported = false;
806
807         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
808                 printf("Fail to get Wi-Fi essid!\n");
809         else {
810                 printf("Wi-Fi essid : %s\n", essid);
811                 g_free(essid);
812         }
813
814         if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
815                 printf("Fail to get Wi-Fi bssid!\n");
816         else {
817                 printf("Wi-Fi bssid : %s\n", bssid);
818                 g_free(bssid);
819         }
820
821         if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
822                 printf("Fail to get Wi-Fi rssi!\n");
823         else
824                 printf("Wi-Fi rssi : %d\n", rssi);
825
826         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
827                 printf("Fail to get Wi-Fi frequency!\n");
828         else
829                 printf("Wi-Fi frequency : %d\n", frequency);
830
831         if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
832                 printf("Fail to get Wi-Fi max speed!\n");
833         else
834                 printf("Wi-Fi max speed : %d\n", max_speed);
835
836         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
837                 printf("Fail to get Wi-Fi security type!\n");
838         else
839                 printf("Wi-Fi security type : %d\n", security_type);
840
841         if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
842                 printf("Fail to get Wi-Fi encryption type!\n");
843         else
844                 printf("Wi-Fi encryption type : %d\n", encryption_type);
845
846         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
847                 printf("Fail to get Wi-Fi passphrase required!\n");
848         else
849                 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
850
851         if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
852                 printf("Fail to get Wi-Fi wps info\n");
853         else
854                 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
855 }
856
857 static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family)
858 {
859         char *interface_name = NULL;
860         char *ip = NULL;
861         char *subnet = NULL;
862         char *gateway = NULL;
863         char *dhcp_server = NULL;
864         int dhcp_lease_duration = 0;
865         char *dns1 = NULL;
866         char *dns2 = NULL;
867         char *proxy = NULL;
868         int prefix_len;
869         connection_ip_config_type_e ip_type;
870         connection_proxy_type_e proxy_type;
871         connection_dns_config_type_e dns_type;
872
873         if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
874                 printf("Fail to get interface name!\n");
875         else {
876                 printf("Interface name : %s\n", interface_name);
877                 g_free(interface_name);
878         }
879
880         if (connection_profile_get_ip_config_type(profile, address_family, &ip_type) != CONNECTION_ERROR_NONE)
881                 printf("Fail to get ipconfig type!\n");
882         else {
883                 if (ip_type == CONNECTION_IP_CONFIG_TYPE_STATIC)
884                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_STATIC");
885                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_DYNAMIC)
886                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_DYNAMIC");
887                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_AUTO)
888                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_AUTO");
889                 else if (ip_type == CONNECTION_IP_CONFIG_TYPE_FIXED)
890                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_FIXED");
891                 else
892                         printf("ip type : %s\n", "CONNECTION_IP_CONFIG_TYPE_NONE");
893         }
894
895         if (connection_profile_get_ip_address(profile, address_family, &ip) != CONNECTION_ERROR_NONE)
896                 printf("Fail to get IP address!\n");
897         else {
898                 printf("IP address : %s\n", ip);
899                 g_free(ip);
900         }
901
902         if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE)
903                 printf("Fail to get gateway!\n");
904         else {
905                 printf("Gateway : %s\n", gateway);
906                 g_free(gateway);
907         }
908
909         if (connection_profile_get_dhcp_server_address(profile, address_family, &dhcp_server) != CONNECTION_ERROR_NONE)
910                 printf("Fail to get DHCP Server address!\n");
911         else {
912                 printf("DHCP Server : %s\n", dhcp_server);
913                 g_free(dhcp_server);
914         }
915
916         if (connection_profile_get_dhcp_lease_duration(profile, address_family, &dhcp_lease_duration) != CONNECTION_ERROR_NONE)
917                 printf("Fail to get DHCP lease duration!\n");
918         else {
919                 printf("DHCP lease duration : %d\n", dhcp_lease_duration);
920         }
921
922         if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE)
923                 printf("Fail to get subnet mask!\n");
924         else {
925                 printf("Subnet mask : %s\n", subnet);
926                 g_free(subnet);
927         }
928
929         if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE)
930                 printf("Fail to get prefix length!\n");
931         else
932                 printf("Prefix length : %d\n", prefix_len);
933
934         if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE)
935                 printf("Fail to get DNS configuration type!\n");
936         else {
937                 if (dns_type == CONNECTION_DNS_CONFIG_TYPE_STATIC)
938                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_STATIC");
939                 else if (dns_type == CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)
940                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_DYNAMIC");
941                 else
942                         printf("DNS config type : %s\n", "CONNECTION_DNS_CONFIG_TYPE_NONE");
943         }
944
945         if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE)
946                 printf("Fail to get DNS1!\n");
947         else {
948                 printf("DNS1 : %s\n", dns1);
949                 g_free(dns1);
950         }
951
952         if (connection_profile_get_dns_address(profile, 2, address_family, &dns2) != CONNECTION_ERROR_NONE)
953                 printf("Fail to get DNS2!\n");
954         else {
955                 printf("DNS2 : %s\n", dns2);
956                 g_free(dns2);
957         }
958
959         if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
960                 printf("Fail to get proxy type!\n");
961         else {
962                 if (proxy_type == CONNECTION_PROXY_TYPE_DIRECT)
963                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_DIRECT");
964                 else if (proxy_type == CONNECTION_PROXY_TYPE_AUTO)
965                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_AUTO");
966                 else
967                         printf("proxy type : %s\n", "CONNECTION_PROXY_TYPE_MANUAL");
968         }
969
970         if (connection_profile_get_proxy_address(profile, address_family, &proxy) != CONNECTION_ERROR_NONE)
971                 printf("Fail to get proxy!\n");
972         else {
973                 printf("Proxy : %s\n", proxy);
974                 g_free(proxy);
975         }
976 }
977
978 int test_register_client(void)
979 {
980
981         int err = connection_create(&connection);
982
983         if (CONNECTION_ERROR_NONE == err) {
984                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
985                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
986                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
987                 connection_set_ethernet_cable_state_chaged_cb(connection,
988                                         test_get_ethernet_cable_state_callback, NULL);
989         } else {
990                 printf("Client registration failed [%s]\n", test_print_error(err));
991                 return -1;
992         }
993
994         printf("Client registration success\n");
995         return 1;
996 }
997
998 int  test_deregister_client(void)
999 {
1000         int rv = 0;
1001         GSList *list;
1002         connection_profile_h profile;
1003
1004         if (connection != NULL)
1005                 rv = connection_destroy(connection);
1006         else {
1007                 printf("Cannot deregister : Handle is NULL\n");
1008                 rv = CONNECTION_ERROR_INVALID_OPERATION;
1009         }
1010
1011         if (rv != CONNECTION_ERROR_NONE) {
1012                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1013                 return -1;
1014         }
1015
1016         if (state_cb_list) {
1017                 for (list = state_cb_list; list; list = list->next) {
1018                         profile = list->data;
1019                         connection_profile_destroy(profile);
1020                 }
1021
1022                 g_slist_free(state_cb_list);
1023                 state_cb_list = NULL;
1024         }
1025
1026         connection = NULL;
1027         printf("Client deregistration success\n");
1028
1029         return 1;
1030 }
1031
1032 int test_register_client_cs(void)
1033 {
1034         int tid = 0;
1035         test_get_user_int("Input a TID in C# API :", &tid);
1036
1037         int err = connection_create_cs(tid, &connection);
1038
1039         if (CONNECTION_ERROR_NONE == err) {
1040                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
1041                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
1042                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
1043                 connection_set_ethernet_cable_state_chaged_cb(connection,
1044                                         test_get_ethernet_cable_state_callback, NULL);
1045         } else {
1046                 printf("Client registration failed [%s]\n", test_print_error(err));
1047                 return -1;
1048         }
1049
1050         printf("Client registration success\n");
1051         return 1;
1052 }
1053
1054 int  test_deregister_client_cs(void)
1055 {
1056         int rv = 0;
1057         GSList *list;
1058         connection_profile_h profile;
1059         int tid = 0;
1060
1061         test_get_user_int("Input a TID in C# API :", &tid);
1062
1063         if (connection != NULL)
1064                 rv = connection_destroy_cs(tid, connection);
1065         else {
1066                 printf("Cannot deregister : Handle is NULL\n");
1067                 rv = CONNECTION_ERROR_INVALID_OPERATION;
1068         }
1069
1070         if (rv != CONNECTION_ERROR_NONE) {
1071                 printf("Client deregistration fail [%s]\n", test_print_error(rv));
1072                 return -1;
1073         }
1074
1075         if (state_cb_list) {
1076                 for (list = state_cb_list; list; list = list->next) {
1077                         profile = list->data;
1078                         connection_profile_destroy(profile);
1079                 }
1080
1081                 g_slist_free(state_cb_list);
1082                 state_cb_list = NULL;
1083         }
1084
1085         connection = NULL;
1086         printf("Client deregistration success\n");
1087
1088         return 1;
1089 }
1090
1091 int test_get_network_state(void)
1092 {
1093         int rv = 0;
1094         connection_type_e net_state;
1095
1096         rv = connection_get_type(connection, &net_state);
1097
1098         if (rv != CONNECTION_ERROR_NONE) {
1099                 printf("Fail to get network state [%s]\n", test_print_error(rv));
1100                 return -1;
1101         }
1102
1103         printf("Retval = [%s] network connection state [%s]\n",
1104                 test_print_error(rv), test_print_connection_type(net_state));
1105
1106         return 1;
1107 }
1108
1109 int test_get_cellular_state(void)
1110 {
1111         int rv = 0;
1112         connection_cellular_state_e cellular_state;
1113
1114         rv = connection_get_cellular_state(connection, &cellular_state);
1115
1116         if (rv != CONNECTION_ERROR_NONE) {
1117                 printf("Fail to get Cellular state [%s]\n", test_print_error(rv));
1118                 return -1;
1119         }
1120
1121         printf("Retval = [%s] Cellular state [%s]\n",
1122                 test_print_error(rv), test_print_cellular_state(cellular_state));
1123
1124         return 1;
1125 }
1126
1127 int test_get_wifi_state(void)
1128 {
1129         int rv = 0;
1130         connection_wifi_state_e wifi_state;
1131
1132         rv = connection_get_wifi_state(connection, &wifi_state);
1133
1134         if (rv != CONNECTION_ERROR_NONE) {
1135                 printf("Fail to get WiFi state [%s]\n", test_print_error(rv));
1136                 return -1;
1137         }
1138
1139         printf("Retval = [%s] WiFi state [%s]\n",
1140                 test_print_error(rv), test_print_wifi_state(wifi_state));
1141
1142         return 1;
1143 }
1144
1145 int test_get_current_proxy(void)
1146 {
1147         char *proxy_addr = NULL;
1148
1149         connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
1150
1151         if (proxy_addr == NULL) {
1152                 printf("Proxy address does not exist\n");
1153                 return -1;
1154         }
1155
1156         printf("Current Proxy [%s]\n", proxy_addr);
1157         g_free(proxy_addr);
1158
1159         return 1;
1160 }
1161
1162 int test_get_current_ip(void)
1163 {
1164         char *ip_addr = NULL;
1165         int input;
1166         bool rv;
1167
1168         rv = test_get_user_int("Input Address type to get"
1169                 "(1:IPV4, 2:IPV6):", &input);
1170
1171         if (rv == false) {
1172                 printf("Invalid input!!\n");
1173                 return -1;
1174         }
1175
1176         switch (input) {
1177         case 1:
1178                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
1179                 if (ip_addr == NULL) {
1180                         printf("IPv4 address does not exist\n");
1181                         return -1;
1182                 }
1183                 printf("IPv4 address : %s\n", ip_addr);
1184                 break;
1185
1186         case 2:
1187                 connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV6, &ip_addr);
1188                 if (ip_addr == NULL) {
1189                         printf("IPv6 address does not exist\n");
1190                         return -1;
1191                 }
1192                 printf("IPv6 address : %s\n", ip_addr);
1193                 break;
1194         default:
1195                 printf("Wrong IP address family!!\n");
1196                 return -1;
1197         }
1198
1199         g_free(ip_addr);
1200         return 1;
1201 }
1202
1203 int test_get_call_statistics_info(void)
1204 {
1205         long long rv = 0;
1206
1207         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1208         printf("last recv data size [%lld]\n", rv);
1209         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1210         printf("last sent data size [%lld]\n", rv);
1211         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1212         printf("total received data size [%lld]\n", rv);
1213         connection_get_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1214         printf("total sent data size [%lld]\n", rv);
1215
1216         return 1;
1217 }
1218
1219 int test_get_wifi_call_statistics_info(void)
1220 {
1221         long long rv = 0;
1222
1223         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
1224         printf("WiFi last recv data size [%lld]\n", rv);
1225         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
1226         printf("WiFi last sent data size [%lld]\n", rv);
1227         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
1228         printf("WiFi total received data size [%lld]\n", rv);
1229         connection_get_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
1230         printf("WiFi total sent data size [%lld]\n", rv);
1231
1232         return 1;
1233 }
1234
1235 int test_get_profile_list(void)
1236 {
1237         if (test_get_user_selected_profile(NULL, false) == false)
1238                 return -1;
1239
1240         return 1;
1241 }
1242
1243 int test_get_default_profile_list(void)
1244 {
1245         int rv = 0;
1246         char *profile_name = NULL;
1247         connection_profile_iterator_h profile_iter;
1248         connection_profile_h profile_h;
1249         connection_cellular_service_type_e service_type;
1250         bool is_default = false;
1251
1252         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_DEFAULT, &profile_iter);
1253         if (rv != CONNECTION_ERROR_NONE) {
1254                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1255                 return -1;
1256         }
1257
1258         while (connection_profile_iterator_has_next(profile_iter)) {
1259                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1260                         printf("Fail to get profile handle\n");
1261                         return -1;
1262                 }
1263
1264                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1265                         printf("Fail to get profile name\n");
1266                         return -1;
1267                 }
1268                 printf("profile name : %s\n", profile_name);
1269                 g_free(profile_name);
1270
1271                 if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) {
1272                         printf("Fail to get profile service type\n");
1273                         return -1;
1274                 }
1275                 printf("service type : %d\n", service_type);
1276
1277                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1278                         printf("Fail to get profile subscriber id\n");
1279                         return -1;
1280                 }
1281                 printf("Default : %d\n", is_default);
1282         }
1283
1284         return 1;
1285 }
1286
1287 int test_get_connected_profile_list(void)
1288 {
1289         int rv = 0;
1290         char *profile_name = NULL;
1291         connection_profile_iterator_h profile_iter;
1292         connection_profile_h profile_h;
1293         bool is_default = false;
1294         connection_profile_type_e type;
1295
1296         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
1297         if (rv != CONNECTION_ERROR_NONE) {
1298                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1299                 return -1;
1300         }
1301
1302         while (connection_profile_iterator_has_next(profile_iter)) {
1303                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
1304                         printf("Fail to get profile handle\n");
1305                         return -1;
1306                 }
1307
1308                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1309                         printf("Fail to get profile name\n");
1310                         return -1;
1311                 }
1312                 printf("profile name is %s\n", profile_name);
1313                 g_free(profile_name);
1314
1315                 if (connection_profile_get_type(profile_h, &type) != CONNECTION_ERROR_NONE) {
1316                         printf("Fail to get profile type\n");
1317                         return -1;
1318                 }
1319                 printf("profile type is %d\n", type);
1320
1321                 if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
1322                 if (connection_profile_is_cellular_default(profile_h, &is_default) != CONNECTION_ERROR_NONE) {
1323                         printf("Fail to get profile is default\n");
1324                         return -1;
1325                 }
1326                         printf("[%s]\n", is_default ? "default" : "not default");
1327                 }
1328         }
1329
1330         return 1;
1331 }
1332
1333 int test_get_current_profile(void)
1334 {
1335         int rv = 0;
1336         char *profile_name = NULL;
1337         connection_profile_h profile_h;
1338
1339         rv = connection_get_current_profile(connection, &profile_h);
1340         if (rv != CONNECTION_ERROR_NONE) {
1341                 printf("Fail to get profile iterator [%s]\n", test_print_error(rv));
1342                 return -1;
1343         }
1344
1345         if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
1346                 printf("Fail to get profile name\n");
1347                 return -1;
1348         }
1349         printf("profile name : %s\n", profile_name);
1350         g_free(profile_name);
1351
1352         connection_profile_destroy(profile_h);
1353
1354         return 1;
1355 }
1356
1357 int test_open_profile(void)
1358 {
1359         connection_profile_h profile;
1360
1361         printf("\n** Choose a profile to open. **\n");
1362
1363         if (test_get_user_selected_profile(&profile, true) == false)
1364                 return -1;
1365
1366         if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
1367                 printf("Connection open Failed!!\n");
1368                 return -1;
1369         }
1370
1371         return 1;
1372 }
1373
1374 int test_get_default_cellular_service_type(void)
1375 {
1376         int input;
1377         int rv;
1378         int service_type;
1379         connection_profile_h profile;
1380         char *profile_name = NULL;
1381
1382         rv = test_get_user_int("Input profile type to get"
1383                         "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input);
1384
1385         if (rv == false) {
1386                 printf("Invalid input!!\n");
1387                 return -1;
1388         }
1389
1390         switch (input) {
1391         case 1:
1392                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
1393                 break;
1394         case 2:
1395                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
1396                 break;
1397         case 3:
1398                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
1399                 break;
1400         case 4:
1401                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
1402                 break;
1403         case 5:
1404                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
1405                 break;
1406         case 6:
1407                 service_type =  CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION;
1408                 break;
1409         default:
1410                 printf("Wrong number!!\n");
1411                 return -1;
1412         }
1413
1414         if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
1415                 return -1;
1416
1417         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1418                 printf("Fail to get profile name\n");
1419                 connection_profile_destroy(profile);
1420                 return -1;
1421         }
1422         printf("Default profile name : %s\n", profile_name);
1423         g_free(profile_name);
1424
1425         connection_profile_destroy(profile);
1426
1427         return 1;
1428 }
1429
1430 int test_set_default_cellular_service_type(void)
1431 {
1432         connection_profile_h profile;
1433         connection_cellular_service_type_e type;
1434         int input, rv;
1435
1436         rv = test_get_user_int("Input API type (1:sync, 2:async)", &input);
1437
1438         if (rv == false || (input != 1 && input != 2)) {
1439                 printf("Invalid input!!\n");
1440                 return -1;
1441         }
1442
1443         printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
1444
1445         if (test_get_user_selected_profile(&profile, true) == false)
1446                 return -1;
1447
1448         if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
1449                 printf("Fail to get cellular service type\n");
1450                 return -1;
1451         }
1452
1453         if (input == 1) {
1454                 if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
1455                         return -1;
1456         } else {
1457                 if (connection_set_default_cellular_service_profile_async(connection,
1458                                 type, profile, test_connection_set_default_callback, NULL) != CONNECTION_ERROR_NONE)
1459                         return -1;
1460         }
1461
1462         return 1;
1463 }
1464
1465 int test_close_profile(void)
1466 {
1467         connection_profile_h profile;
1468
1469         printf("\n** Choose a profile to close. **\n");
1470
1471         if (test_get_user_selected_profile(&profile, true) == false)
1472                 return -1;
1473
1474         if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
1475                 printf("Connection close Failed!!\n");
1476                 return -1;
1477         }
1478
1479         return 1;
1480 }
1481
1482 int test_add_profile(void)
1483 {
1484         int rv = 0;
1485         connection_profile_h profile;
1486         char input_str[100] = {0,};
1487
1488         if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
1489                 return -1;
1490
1491         g_strstrip(input_str);
1492         rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
1493         if (rv != CONNECTION_ERROR_NONE)
1494                 RETURN_FAIL_DESTROY(profile);
1495
1496         if (test_update_cellular_info(profile) == -1)
1497                 RETURN_FAIL_DESTROY(profile);
1498
1499         rv = connection_add_profile(connection, profile);
1500         if (rv != CONNECTION_ERROR_NONE)
1501                 RETURN_FAIL_DESTROY(profile);
1502
1503         connection_profile_destroy(profile);
1504         return 1;
1505 }
1506
1507 int test_remove_profile(void)
1508 {
1509         connection_profile_h profile;
1510
1511         printf("\n** Choose a profile to remove. **\n");
1512         if (test_get_user_selected_profile(&profile, true) == false)
1513                 return -1;
1514
1515         if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1516                 printf("Remove profile Failed!!\n");
1517                 return -1;
1518         }
1519
1520         return 1;
1521 }
1522
1523 int test_update_profile(void)
1524 {
1525         int rv = 0;
1526
1527         connection_profile_type_e prof_type;
1528         connection_profile_h profile;
1529
1530         printf("\n** Choose a profile to update. **\n");
1531         if (test_get_user_selected_profile(&profile, true) == false)
1532                 return -1;
1533
1534         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1535                 return -1;
1536
1537         switch (prof_type) {
1538         case CONNECTION_PROFILE_TYPE_CELLULAR:
1539                 if (test_update_cellular_info(profile) == -1)
1540                         return -1;
1541
1542                 break;
1543         case CONNECTION_PROFILE_TYPE_WIFI:
1544                 if (test_update_wifi_info(profile) == -1)
1545                         return -1;
1546
1547                 if (test_update_network_info(profile) == -1)
1548                         return -1;
1549
1550                 break;
1551         case CONNECTION_PROFILE_TYPE_ETHERNET:
1552                 if (test_update_network_info(profile) == -1)
1553                         return -1;
1554                 break;
1555
1556         case CONNECTION_PROFILE_TYPE_BT:
1557                 printf("Not supported!\n");
1558                 /* fall through */
1559         default:
1560                 return -1;
1561         }
1562
1563         rv = connection_update_profile(connection, profile);
1564         if (rv != CONNECTION_ERROR_NONE)
1565                 return -1;
1566
1567         return 1;
1568 }
1569
1570 int test_get_profile_info(void)
1571 {
1572         connection_profile_type_e prof_type;
1573         connection_profile_state_e profile_state;
1574         connection_profile_state_e profile_ipv6_state;
1575         connection_profile_h profile;
1576         char *profile_name = NULL;
1577         int address_family = 0;
1578
1579         printf("\n** Choose a profile to print. **\n");
1580         if (test_get_user_selected_profile(&profile, true) == false)
1581                 return -1;
1582
1583         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1584                 printf("Fail to get profile name\n");
1585                 return -1;
1586         } else {
1587                 printf("Profile Name : %s\n", profile_name);
1588                 g_free(profile_name);
1589         }
1590
1591         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1592                 printf("Fail to get profile IPv4 state\n");
1593                 return -1;
1594         } else
1595                 printf("Profile State : %s\n", test_print_state(profile_state));
1596
1597         if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) {
1598                 printf("Fail to get profile IPv6 state\n");
1599                 return -1;
1600         } else
1601                 printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
1602
1603
1604         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1605                 return -1;
1606
1607         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1608
1609         switch (prof_type) {
1610         case CONNECTION_PROFILE_TYPE_CELLULAR:
1611                 printf("Profile Type : Cellular\n");
1612                 test_print_cellular_info(profile);
1613                 break;
1614         case CONNECTION_PROFILE_TYPE_WIFI:
1615                 printf("Profile Type : Wi-Fi\n");
1616                 test_print_wifi_info(profile);
1617                 break;
1618         case CONNECTION_PROFILE_TYPE_ETHERNET:
1619                 printf("Profile Type : Ethernet\n");
1620                 break;
1621         case CONNECTION_PROFILE_TYPE_BT:
1622                 printf("Profile Type : Bluetooth\n");
1623                 break;
1624         default:
1625                 return -1;
1626         }
1627
1628         test_print_network_info(profile, address_family);
1629
1630         return 1;
1631 }
1632
1633 int test_refresh_profile_info(void)
1634 {
1635         connection_profile_type_e prof_type;
1636         connection_profile_state_e profile_state;
1637         connection_profile_h profile;
1638         char *profile_name = NULL;
1639         int address_family = 0;
1640
1641         printf("\n** Choose a profile to refresh. **\n");
1642         if (test_get_user_selected_profile(&profile, true) == false)
1643                 return -1;
1644
1645         if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1646                 return -1;
1647
1648         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1649                 printf("Fail to get profile name\n");
1650                 return -1;
1651         } else {
1652                 printf("Profile Name : %s\n", profile_name);
1653                 g_free(profile_name);
1654         }
1655
1656         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1657                 printf("Fail to get profile state\n");
1658                 return -1;
1659         } else
1660                 printf("Profile State : %s\n", test_print_state(profile_state));
1661
1662
1663         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1664                 return -1;
1665
1666         test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family);
1667
1668         switch (prof_type) {
1669         case CONNECTION_PROFILE_TYPE_CELLULAR:
1670                 printf("Profile Type : Cellular\n");
1671                 test_print_cellular_info(profile);
1672                 break;
1673         case CONNECTION_PROFILE_TYPE_WIFI:
1674                 printf("Profile Type : Wi-Fi\n");
1675                 test_print_wifi_info(profile);
1676                 break;
1677         case CONNECTION_PROFILE_TYPE_ETHERNET:
1678                 printf("Profile Type : Ethernet\n");
1679                 break;
1680         case CONNECTION_PROFILE_TYPE_BT:
1681                 printf("Profile Type : Bluetooth\n");
1682                 break;
1683         default:
1684                 return -1;
1685         }
1686
1687         test_print_network_info(profile, address_family);
1688
1689         return 1;
1690 }
1691
1692 int test_set_state_changed_callback()
1693 {
1694         connection_profile_h profile;
1695         connection_profile_h profile_clone;
1696
1697         printf("\n** Choose a profile to set callback. **\n");
1698         if (test_get_user_selected_profile(&profile, true) == false)
1699                 return -1;
1700
1701         if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1702                 return -1;
1703
1704         if (connection_profile_set_state_changed_cb(profile,
1705                         test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1706                 connection_profile_destroy(profile_clone);
1707                 return -1;
1708         }
1709
1710         state_cb_list = g_slist_append(state_cb_list, profile_clone);
1711
1712         return 1;
1713 }
1714
1715 int test_unset_state_changed_callback()
1716 {
1717         connection_profile_h profile;
1718         GSList *list;
1719         char *profile_name = NULL;
1720         int count = 0;
1721         int input = 0;
1722
1723         printf("\n** Choose a profile to unset callback. **\n");
1724         for (list = state_cb_list; list; list = list->next) {
1725                 profile = list->data;
1726                 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1727                         printf("Fail to get profile name!\n");
1728                         return -1;
1729                 } else {
1730                         printf("%d. %s\n", count, profile_name);
1731                         g_free(profile_name);
1732                 }
1733
1734                 count++;
1735         }
1736
1737         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1738             input >= count ||
1739             input < 0) {
1740                 printf("Wrong number!!\n");
1741                 return -1;
1742         }
1743
1744         count = 0;
1745         for (list = state_cb_list; list; list = list->next) {
1746                 if (count == input) {
1747                         profile = list->data;
1748                         goto unset;
1749                 }
1750
1751                 count++;
1752         }
1753
1754         return -1;
1755
1756 unset:
1757         if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1758                 return -1;
1759
1760         state_cb_list = g_slist_remove(state_cb_list, profile);
1761         connection_profile_destroy(profile);
1762
1763         return 1;
1764 }
1765
1766 int test_reset_call_statistics_info(void)
1767 {
1768         int ret = CONNECTION_ERROR_NONE;
1769
1770         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1771         printf("reset last recv data size [%d]\n", ret);
1772         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1773         printf("last sent data size [%d]\n", ret);
1774         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1775         printf("total received data size [%d]\n", ret);
1776         ret = connection_reset_statistics(connection, CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1777         printf("total sent data size [%d]\n", ret);
1778
1779         return 1;
1780 }
1781
1782 int test_reset_wifi_call_statistics_info(void)
1783 {
1784         int ret = CONNECTION_ERROR_NONE;
1785
1786         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1787         printf("WiFi last sent data size [%d]\n", ret);
1788         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1789         printf("WiFi last recv data size [%d]\n", ret);
1790         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1791         printf("WiFi total sent data size [%d]\n", ret);
1792         ret = connection_reset_statistics(connection, CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1793         printf("WiFi total received data size [%d]\n", ret);
1794
1795         return 1;
1796 }
1797
1798 int test_add_route(void)
1799 {
1800         int rv = 0;
1801         char ip_addr[100] = {0};
1802         char if_name[40] = {0};
1803
1804         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1805                 return -1;
1806
1807         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1808                 return -1;
1809
1810         g_strstrip(ip_addr);
1811         g_strstrip(if_name);
1812         rv = connection_add_route(connection, if_name, ip_addr);
1813         if (rv != CONNECTION_ERROR_NONE) {
1814                 printf("Fail to get add new route [%d]\n", rv);
1815                 return -1;
1816         }
1817         printf("Add Route successfully\n");
1818
1819         return 1;
1820 }
1821
1822 int test_remove_route(void)
1823 {
1824         int rv = 0;
1825         char ip_addr[100] = {0};
1826         char if_name[40] = {0};
1827
1828         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1829                 return -1;
1830
1831         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1832                 return -1;
1833
1834         g_strstrip(ip_addr);
1835         g_strstrip(if_name);
1836         rv = connection_remove_route(connection, if_name, ip_addr);
1837         if (rv != CONNECTION_ERROR_NONE) {
1838                 printf("Fail to remove the route [%s]\n", test_print_error(rv));
1839                 return -1;
1840         }
1841         printf("Remove Route successfully\n");
1842
1843         return 1;
1844 }
1845
1846 int test_add_route_ipv6(void)
1847 {
1848         int rv = 0;
1849         char ip_addr[100] = {0};
1850         char gateway[100] = {0};
1851         char if_name[40] = {0};
1852
1853         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1854                 return -1;
1855
1856         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1857                 return -1;
1858
1859         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1860                 return -1;
1861
1862         g_strstrip(ip_addr);
1863         g_strstrip(gateway);
1864         g_strstrip(if_name);
1865         rv = connection_add_route_ipv6(connection, if_name, ip_addr, gateway);
1866         if (rv != CONNECTION_ERROR_NONE) {
1867                 printf("Fail to get add new route [%d]\n", rv);
1868                 return -1;
1869         }
1870         printf("Add Route successfully\n");
1871
1872         return 1;
1873 }
1874
1875 int test_remove_route_ipv6(void)
1876 {
1877         int rv = 0;
1878         char ip_addr[100] = {0};
1879         char gateway[100] = {0};
1880         char if_name[40] = {0};
1881
1882         if (test_get_user_string("Input IPv6 - (Enter for skip) :", ip_addr, 100) == false)
1883                 return -1;
1884
1885         if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1886                 return -1;
1887
1888         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1889                 return -1;
1890
1891         g_strstrip(ip_addr);
1892         g_strstrip(gateway);
1893         g_strstrip(if_name);
1894         rv = connection_remove_route_ipv6(connection, if_name, ip_addr, gateway);
1895         if (rv != CONNECTION_ERROR_NONE) {
1896                 printf("Fail to remove the route [%d]\n", rv);
1897                 return -1;
1898         }
1899         printf("Remove Route successfully\n");
1900
1901         return 1;
1902 }
1903
1904 int test_add_route_entry(void)
1905 {
1906         char ip_addr[100] = {0};
1907         char gateway[100] = {0};
1908         char if_name[40] = {0};
1909         int input;
1910         bool input_rv;
1911         int rv = 0;
1912
1913         input_rv = test_get_user_int("Input Address type to get"
1914                 "(1:IPV4, 2:IPV6):", &input);
1915
1916         if (input_rv == false) {
1917                 printf("Invalid input!!\n");
1918                 return -1;
1919         }
1920
1921         switch (input) {
1922         case 1:
1923                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1924                         return -1;
1925
1926                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1927                         return -1;
1928
1929                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1930                         return -1;
1931
1932                 g_strstrip(ip_addr);
1933                 g_strstrip(gateway);
1934                 g_strstrip(if_name);
1935                 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
1936                 if (rv != CONNECTION_ERROR_NONE) {
1937                         printf("Fail to get add new route [%d]\n", rv);
1938                         return -1;
1939                 }
1940                 printf("Add Route successfully\n");
1941                 break;
1942
1943         case 2:
1944                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1945                         return -1;
1946
1947                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1948                         return -1;
1949
1950                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
1951                         return -1;
1952
1953                 g_strstrip(ip_addr);
1954                 g_strstrip(gateway);
1955                 g_strstrip(if_name);
1956                 rv = connection_add_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
1957                 if (rv != CONNECTION_ERROR_NONE) {
1958                         printf("Fail to get add new route [%d]\n", rv);
1959                         return -1;
1960                 }
1961                 printf("Add Route successfully\n");
1962                 break;
1963
1964         default:
1965                 printf("Wrong IP address family!!\n");
1966                 return -1;
1967
1968         }
1969
1970         return 1;
1971
1972 }
1973
1974 int test_remove_route_entry(void)
1975 {
1976         char ip_addr[100] = {0};
1977         char gateway[100] = {0};
1978         char if_name[40] = {0};
1979         int input;
1980         bool input_rv;
1981         int rv = 0;
1982
1983         input_rv = test_get_user_int("Input Address type to get"
1984                 "(1:IPV4, 2:IPV6):", &input);
1985
1986         if (input_rv == false) {
1987                 printf("Invalid input!!\n");
1988                 return -1;
1989         }
1990
1991         switch (input) {
1992         case 1:
1993                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1994                         return -1;
1995
1996                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
1997                         return -1;
1998
1999                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2000                         return -1;
2001
2002                 g_strstrip(ip_addr);
2003                 g_strstrip(gateway);
2004                 g_strstrip(if_name);
2005                 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV4, if_name, ip_addr, gateway);
2006                 if (rv != CONNECTION_ERROR_NONE) {
2007                         printf("Fail to remove the route [%s]\n", test_print_error(rv));
2008                         return -1;
2009                 }
2010                 printf("Remove Route successfully\n");
2011
2012                 break;
2013
2014         case 2:
2015                 if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
2016                         return -1;
2017
2018                 if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 100) == false)
2019                         return -1;
2020
2021                 if (test_get_user_string("Input Gateway - (Enter for skip) :", gateway, 100) == false)
2022                         return -1;
2023
2024                 g_strstrip(ip_addr);
2025                 g_strstrip(gateway);
2026                 g_strstrip(if_name);
2027                 rv = connection_remove_route_entry(connection, CONNECTION_ADDRESS_FAMILY_IPV6, if_name, ip_addr, gateway);
2028                 if (rv != CONNECTION_ERROR_NONE) {
2029                         printf("Fail to remove the route [%d]\n", rv);
2030                         return -1;
2031                 }
2032                 printf("Remove Route successfully\n");
2033                 break;
2034
2035         default:
2036                 printf("Wrong IP address family!!\n");
2037                 return -1;
2038
2039         }
2040
2041         return 1;
2042
2043 }
2044
2045 int test_get_bt_state(void)
2046 {
2047         int rv = 0;
2048         connection_bt_state_e bt_state;
2049
2050         rv = connection_get_bt_state(connection, &bt_state);
2051
2052         if (rv != CONNECTION_ERROR_NONE) {
2053                 printf("Fail to get Bluetooth state [%s]\n", test_print_error(rv));
2054                 return -1;
2055         }
2056
2057         printf("Retval = [%s], Bluetooth state [%d]\n", test_print_error(rv), bt_state);
2058
2059         return 1;
2060 }
2061
2062 int test_get_profile_id(void)
2063 {
2064         connection_profile_h profile;
2065         char *profile_id;
2066
2067         printf("\n** Choose a profile to see profile id. **\n");
2068         if (test_get_user_selected_profile(&profile, true) == false)
2069                 return -1;
2070
2071         if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
2072                 printf("Fail to get profile name\n");
2073                 return -1;
2074         } else {
2075                 printf("Profile id : %s\n", profile_id);
2076                 g_free(profile_id);
2077         }
2078
2079         return 1;
2080 }
2081
2082 int test_get_mac_address(void)
2083 {
2084         int rv = 0, type = 0;
2085         connection_type_e conn_type;
2086         char *mac_addr = NULL;
2087
2088         test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type);
2089
2090         switch (type) {
2091         case 1:
2092                 conn_type = CONNECTION_TYPE_WIFI;
2093                 break;
2094         case 2:
2095                 conn_type = CONNECTION_TYPE_ETHERNET;
2096                 break;
2097         default:
2098                 printf("Wrong number!!\n");
2099                 return -1;
2100         }
2101
2102         rv = connection_get_mac_address(connection, conn_type, &mac_addr);
2103
2104         if (rv != CONNECTION_ERROR_NONE) {
2105                 printf("Fail to get MAC address [%s]\n", test_print_error(rv));
2106                 return -1;
2107         }
2108
2109         printf("mac address is %s\n", mac_addr);
2110
2111         g_free(mac_addr);
2112
2113         return 1;
2114 }
2115
2116 int test_get_ethernet_cable_state(void)
2117 {
2118         int rv = 0;
2119         connection_ethernet_cable_state_e cable_state;
2120
2121         rv = connection_get_ethernet_cable_state(connection, &cable_state);
2122
2123         if (rv != CONNECTION_ERROR_NONE) {
2124                 printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv));
2125                 return -1;
2126         }
2127
2128         printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state);
2129
2130         return 1;
2131 }
2132
2133 int test_reset_profile(void)
2134 {
2135         int type, sim_id, rv;
2136
2137         rv = test_get_user_int("Input reset type (0:default profile reset, 1:delete profile reset)", &type);
2138
2139         if (rv == false || (type != 0 && type != 1)) {
2140                 printf("Invalid input!!\n");
2141                 return -1;
2142         }
2143
2144         rv = test_get_user_int("Input SIM id to reset (0:SIM1, 1:SIM2)", &sim_id);
2145
2146         if (rv == false || (sim_id != 0 && sim_id != 1)) {
2147                 printf("Invalid input!!\n");
2148                 return -1;
2149         }
2150
2151         if (connection_reset_profile(connection, type, sim_id, test_connection_reset_profile_callback, NULL) != CONNECTION_ERROR_NONE)
2152                 return -1;
2153
2154         return 1;
2155 }
2156
2157 static bool test_get_ipv6_address_callback(char *ipv6_address, void* user_data)
2158 {
2159         printf("IPv6 Address : %s\n", ipv6_address);
2160         return true;
2161 }
2162
2163 int test_foreach_ipv6_address(void)
2164 {
2165         int rv = 0;
2166         int type;
2167         connection_type_e conn_type;
2168
2169         test_get_user_int("Input Connection Type(1: WiFi 2: Ethernet) :", &type);
2170
2171         switch (type) {
2172         case 1:
2173                 conn_type = CONNECTION_TYPE_WIFI;
2174                 break;
2175         case 2:
2176                 conn_type = CONNECTION_TYPE_ETHERNET;
2177                 break;
2178         default:
2179                 printf("Wrong number!!\n");
2180                 return -1;
2181         }
2182
2183         rv = connection_foreach_ipv6_address(connection, conn_type, test_get_ipv6_address_callback, NULL);
2184         if (rv != CONNECTION_ERROR_NONE) {
2185                 printf("Fail to get IPv6 address\n");
2186                 return -1;
2187         }
2188
2189         return 1;
2190 }
2191
2192 int test_is_metered_network(void)
2193 {
2194         int rv = 0;
2195         bool metered_state;
2196
2197         rv = connection_is_metered_network(connection, &metered_state);
2198
2199         if (rv != CONNECTION_ERROR_NONE) {
2200                 printf("Fail to get metered state [%s]\n", test_print_error(rv));
2201                 return -1;
2202         }
2203
2204         printf("Retval = [%s] metered state [%s]\n",
2205                 test_print_error(rv), metered_state ? "TRUE" : "FALSE");
2206
2207         return 1;
2208 }
2209
2210 int test_start_tcpdump(void)
2211 {
2212         if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2213                 return -1;
2214         }
2215
2216         printf("Successfully started tcpdump\n");
2217
2218         return 1;
2219 }
2220
2221 int test_stop_tcpdump(void)
2222 {
2223         if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
2224                 return -1;
2225         }
2226
2227         printf("Successfully stopped tcpdump\n");
2228
2229         return 1;
2230 }
2231
2232 int test_get_tcpdump_state(void)
2233 {
2234         gboolean tcpdump_state = FALSE;
2235
2236         if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
2237                 return -1;
2238         }
2239
2240         printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
2241
2242         return 1;
2243 }
2244
2245 int test_mptcp_enable(void)
2246 {
2247         int rv = 0;
2248         rv = connection_mptcp_enable(CONNECTION_MPTCP_ENABLE_ALL);
2249
2250         if (rv != CONNECTION_ERROR_NONE) {
2251                 printf("Failure[%s]\n", test_print_error(rv));
2252                 return -1;
2253         }
2254         return 1;
2255 }
2256
2257 int test_mptcp_disable(void)
2258 {
2259         int rv = 0;
2260         rv = connection_mptcp_disable();
2261
2262         if (rv != CONNECTION_ERROR_NONE) {
2263                 printf("Failure[%s]\n", test_print_error(rv));
2264                 return -1;
2265         }
2266         return 1;
2267 }
2268
2269 int test_mptcp_set_path_manager(void)
2270 {
2271         int rv = 0;
2272         int input = 0;
2273         rv = test_get_user_int("Input Path Manager (1: default, 2: fullmesh)", &input);
2274
2275         switch (input) {
2276         case 1:
2277                 rv = connection_mptcp_set_path_manager(CONNECTION_MPTCP_PM_DEFAULT);
2278                 break;
2279         case 2:
2280                 rv = connection_mptcp_set_path_manager(CONNECTION_MPTCP_PM_FULLMESH);
2281                 break;
2282         default:
2283                 printf("Invalid input!!\n");
2284                 return -1;
2285         }
2286
2287         if (rv != CONNECTION_ERROR_NONE) {
2288                 printf("Failure[%s]\n", test_print_error(rv));
2289                 return -1;
2290         }
2291
2292         return 1;
2293 }
2294
2295 int test_mptcp_get_path_manager(void)
2296 {
2297         int rv = 0;
2298         connection_mptcp_path_manager_e pm;
2299
2300         rv = connection_mptcp_get_path_manager(&pm);
2301         if (rv != CONNECTION_ERROR_NONE) {
2302                 printf("Failure[%s]\n", test_print_error(rv));
2303                 return -1;
2304         }
2305
2306         switch (pm) {
2307         case CONNECTION_MPTCP_PM_DEFAULT:
2308                 printf("Path Manager: Default\n");
2309                 break;
2310         case CONNECTION_MPTCP_PM_FULLMESH:
2311                 printf("Path Manager: FullMesh\n");
2312                 break;
2313         default:
2314                 printf("Error: Invalid Path Manager\n");
2315                 return -1;
2316         }
2317
2318         return 1;
2319 }
2320
2321 int test_mptcp_set_scheduler(void)
2322 {
2323         int rv = 0;
2324         int input = 0;
2325         rv = test_get_user_int("Input Scheduler (1: default, 2: roundrobin)", &input);
2326
2327         switch (input) {
2328         case 1:
2329                 rv = connection_mptcp_set_scheduler(CONNECTION_MPTCP_SCHEDULER_DEFAULT);
2330                 break;
2331         case 2:
2332                 rv = connection_mptcp_set_scheduler(CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN);
2333                 break;
2334         default:
2335                 printf("Invalid input!!\n");
2336                 return -1;
2337         }
2338
2339         if (rv != CONNECTION_ERROR_NONE) {
2340                 printf("Failure[%s]\n", test_print_error(rv));
2341                 return -1;
2342         }
2343
2344         return 1;
2345 }
2346
2347 int test_mptcp_get_scheduler(void)
2348 {
2349         int rv = 0;
2350         connection_mptcp_scheduler_e scheduler;
2351
2352         rv = connection_mptcp_get_scheduler(&scheduler);
2353         if (rv != CONNECTION_ERROR_NONE) {
2354                 printf("Failure[%s]\n", test_print_error(rv));
2355                 return -1;
2356         }
2357
2358         switch (scheduler) {
2359         case CONNECTION_MPTCP_SCHEDULER_DEFAULT:
2360                 printf("Scheduler: Default\n");
2361                 break;
2362         case CONNECTION_MPTCP_SCHEDULER_ROUNDROBIN:
2363                 printf("Scheduler: RountRobin\n");
2364                 break;
2365         default:
2366                 printf("Error: Invalid Scheduler\n");
2367                 return -1;
2368         }
2369
2370         return 1;
2371 }
2372
2373 int main(int argc, char **argv)
2374 {
2375         GMainLoop *mainloop;
2376         mainloop = g_main_loop_new(NULL, FALSE);
2377
2378         GIOChannel *channel = g_io_channel_unix_new(0);
2379         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
2380
2381         printf("Test Thread created...\n");
2382
2383         g_main_loop_run(mainloop);
2384
2385         return 0;
2386 }
2387
2388 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
2389 {
2390         int rv = 0;
2391         char a[100];
2392
2393         memset(a, '\0', 100);
2394         printf("Event received from stdin\n");
2395
2396         rv = read(0, a, 100);
2397
2398         if (rv < 0 || a[0] == '0') {
2399                 if (connection != NULL)
2400                         test_deregister_client();
2401
2402                 exit(1);
2403         }
2404
2405         if (*a == '\n' || *a == '\r') {
2406 /* Public API */
2407                 printf("\n\n Network Connection API Test App\n\n");
2408                 printf("Options..\n");
2409                 printf(LOG_BLUE "[Public APIs]\n" LOG_END);
2410                 printf(LOG_GREEN "1   - Create Handle and set callbacks\n" LOG_END);
2411                 printf("2   - Destroy Handle(unset callbacks automatically)\n");
2412                 printf(LOG_GREEN "3   - Get network state\n" LOG_END);
2413                 printf(LOG_GREEN "4   - Get cellular state (please insert SIM Card)\n" LOG_END);
2414                 printf(LOG_GREEN "5   - Get wifi state (please turn on WiFi)\n" LOG_END);
2415                 printf("6   - Get current proxy address \n");
2416                 printf("7   - Get current Ip address\n");
2417                 printf("8   - Get cellular data call statistics\n");
2418                 printf("9   - Get WiFi data call statistics\n");
2419                 printf(LOG_GREEN "a   - Get Profile list\n" LOG_END);
2420                 printf(LOG_GREEN "b   - Get Connected Profile list\n" LOG_END);
2421                 printf(LOG_GREEN "c   - Get Current profile\n" LOG_END);
2422                 printf("d   - Open connection with profile\n");
2423                 printf("e   - Get default cellular service by type\n");
2424                 printf("f   - Set default cellular service by type\n");
2425                 printf("g   - Close connection with profile\n");
2426                 printf("h   - Add profile(Cellular and Wifi only)\n");
2427                 printf("i   - Remove profile(Cellular:delete, WiFi:forgot)\n");
2428                 printf("j   - Update profile\n");
2429                 printf("k   - Get profile info\n");
2430                 printf("l   - Refresh profile info\n");
2431                 printf("m   - Set state changed callback\n");
2432                 printf("n   - Unset state changed callback\n");
2433                 printf("o   - Reset cellular data call statistics\n");
2434                 printf("p   - Reset WiFi data call statistics\n");
2435                 printf("q   - Add new route\n");
2436                 printf("r   - Remove a route\n");
2437                 printf("s   - Get Bluetooth state\n");
2438                 printf("t   - Get profile id\n");
2439                 printf("u   - Reset profile\n");
2440                 printf("v   - Get all cellular default profiles\n");
2441                 printf("w   - Get mac address\n");
2442                 printf("x   - Get ethernet cable state\n");
2443                 printf("B   - Add IPv6 new route\n");
2444                 printf("C   - Remove IPv6 route\n");
2445                 printf("D   - Add new route entry\n");
2446                 printf("E   - Remove route entry\n");
2447                 printf("F   - Get all IPv6 address\n");
2448                 printf("G   - Get metered state\n");
2449 /* Extension API */
2450                 printf(LOG_BLUE "[Extension API]\n" LOG_END);
2451                 printf("H   - Start TCP Dump\n");
2452                 printf("I   - Stop TCP Dump\n");
2453                 printf("J   - Get TCP Dump State\n");
2454                 printf("K   - Enable MPTCP (internal)\n");
2455                 printf("L   - Disable MPTCP (internal)\n");
2456                 printf("M   - Set MPTCP Path Manager (internal)\n");
2457                 printf("N   - Get MPTCP Path Manager (internal)\n");
2458                 printf("O   - Set MPTCP Scheduler (internal)\n");
2459                 printf("P   - Get MPTCP Scheduler (internal)\n");
2460                 printf(LOG_GREEN "Q   - Create Handle and set callbacks in C# API\n" LOG_END);
2461                 printf("R   - Destroy Handle(unset callbacks automatically in C# API)\n");
2462                 printf(LOG_RED "0   - Exit \n" LOG_END);
2463                 printf("ENTER   - Show options menu.......\n");
2464         }
2465
2466         switch (a[0]) {
2467 /* Public API */
2468         case '1':
2469                 rv = test_register_client();
2470                 break;
2471         case '2':
2472                 rv = test_deregister_client();
2473                 break;
2474         case '3':
2475                 rv = test_get_network_state();
2476                 break;
2477         case '4':
2478                 rv = test_get_cellular_state();
2479                 break;
2480         case '5':
2481                 rv = test_get_wifi_state();
2482                 break;
2483         case '6':
2484                 rv = test_get_current_proxy();
2485                 break;
2486         case '7':
2487                 rv = test_get_current_ip();
2488                 break;
2489         case '8':
2490                 rv = test_get_call_statistics_info();
2491                 break;
2492         case '9':
2493                 rv = test_get_wifi_call_statistics_info();
2494                 break;
2495         case 'a':
2496                 rv = test_get_profile_list();
2497                 break;
2498         case 'b':
2499                 rv = test_get_connected_profile_list();
2500                 break;
2501         case 'c':
2502                 rv = test_get_current_profile();
2503                 break;
2504         case 'd':
2505                 rv = test_open_profile();
2506                 break;
2507         case 'e':
2508                 rv = test_get_default_cellular_service_type();
2509                 break;
2510         case 'f':
2511                 rv = test_set_default_cellular_service_type();
2512                 break;
2513         case 'g':
2514                 rv = test_close_profile();
2515                 break;
2516         case 'h':
2517                 rv = test_add_profile();
2518                 break;
2519         case 'i':
2520                 rv = test_remove_profile();
2521                 break;
2522         case 'j':
2523                 rv = test_update_profile();
2524                 break;
2525         case 'k':
2526                 rv = test_get_profile_info();
2527                 break;
2528         case 'l':
2529                 rv = test_refresh_profile_info();
2530                 break;
2531         case 'm':
2532                 rv = test_set_state_changed_callback();
2533                 break;
2534         case 'n':
2535                 rv = test_unset_state_changed_callback();
2536                 break;
2537         case 'o':
2538                 rv = test_reset_call_statistics_info();
2539                 break;
2540         case 'p':
2541                 rv = test_reset_wifi_call_statistics_info();
2542                 break;
2543         case 'q':
2544                 rv = test_add_route();
2545                 break;
2546         case 'r':
2547                 rv = test_remove_route();
2548                 break;
2549         case 's':
2550                 rv = test_get_bt_state();
2551                 break;
2552         case 't':
2553                 rv = test_get_profile_id();
2554                 break;
2555         case 'u':
2556                 rv = test_reset_profile();
2557                 break;
2558         case 'v':
2559                 rv = test_get_default_profile_list();
2560                 break;
2561         case 'w':
2562                 rv = test_get_mac_address();
2563                 break;
2564         case 'x':
2565                 rv = test_get_ethernet_cable_state();
2566                 break;
2567         case 'B':
2568                 rv = test_add_route_ipv6();
2569                 break;
2570         case 'C':
2571                 rv = test_remove_route_ipv6();
2572                 break;
2573         case 'D':
2574                 rv = test_add_route_entry();
2575                 break;
2576         case 'E':
2577                 rv = test_remove_route_entry();
2578                 break;
2579         case 'F':
2580                 rv = test_foreach_ipv6_address();
2581                 break;
2582         case 'G':
2583                 rv = test_is_metered_network();
2584                 break;
2585 /* Extension API */
2586         case 'H':
2587                 rv = test_start_tcpdump();
2588                 break;
2589         case 'I':
2590                 rv = test_stop_tcpdump();
2591                 break;
2592         case 'J':
2593                 rv = test_get_tcpdump_state();
2594                 break;
2595         case 'K':
2596                 rv = test_mptcp_enable();
2597                 break;
2598         case 'L':
2599                 rv = test_mptcp_disable();
2600                 break;
2601         case 'M':
2602                 rv = test_mptcp_set_path_manager();
2603                 break;
2604         case 'N':
2605                 rv = test_mptcp_get_path_manager();
2606                 break;
2607         case 'O':
2608                 rv = test_mptcp_set_scheduler();
2609                 break;
2610         case 'P':
2611                 rv = test_mptcp_get_scheduler();
2612                 break;
2613         case 'Q':
2614                 rv = test_register_client_cs();
2615                 break;
2616         case 'R':
2617                 rv = test_deregister_client_cs();
2618                 break;
2619
2620         }
2621
2622         if (rv == 1)
2623                 printf("Operation succeeded!\n");
2624         else
2625                 printf("Operation failed!\n");
2626
2627         return TRUE;
2628 }