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