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