Tizen 2.1 base
[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 <tizen_error.h>
26
27 #define RETURN_FAIL_DESTROY(x) {connection_profile_destroy(x); return -1;}
28
29 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
30
31 connection_h connection = NULL;
32 static GSList *state_cb_list = NULL;
33
34
35 static bool test_get_user_string(const char *msg, char *buf, int buf_size)
36 {
37         if (msg == NULL || buf == NULL || buf_size < 2)
38                 return false;
39
40         int rv;
41         printf("%s\n", msg);
42         memset(buf, 0, buf_size);
43         rv = read(0, buf, buf_size - 1);
44
45         if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
46                 buf[0] = '\0';
47                 return false;
48         }
49
50         buf[buf_size - 1] = '\0';
51
52         return true;
53 }
54
55 static bool test_get_user_int(const char *msg, int *num)
56 {
57         if (msg == NULL || num == NULL)
58                 return false;
59
60         int rv;
61         char buf[32] = {0,};
62         printf("%s\n", msg);
63         rv = read(0, buf, 32);
64
65         if (rv < 0 || *buf == 0 || *buf == '\n' || *buf == '\r')
66                 return false;
67
68         *num = atoi(buf);
69         return true;
70 }
71
72 static const char *test_print_state(connection_profile_state_e state)
73 {
74         switch (state) {
75         case CONNECTION_PROFILE_STATE_DISCONNECTED:
76                 return "Disconnected";
77         case CONNECTION_PROFILE_STATE_ASSOCIATION:
78                 return "Association";
79         case CONNECTION_PROFILE_STATE_CONFIGURATION:
80                 return "Configuration";
81         case CONNECTION_PROFILE_STATE_CONNECTED:
82                 return "Connected";
83         default:
84                 return "Unknown";
85         }
86 }
87
88 static void test_type_changed_callback(connection_type_e type, void* user_data)
89 {
90         printf("Type changed callback, connection type : %d\n", type);
91 }
92
93 static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
94 {
95         printf("IP changed callback, IPv4 address : %s, IPv6 address : %s\n",
96                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
97 }
98
99 static void test_proxy_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data)
100 {
101         printf("Proxy changed callback, IPv4 address : %s, IPv6 address : %s\n",
102                         ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
103 }
104
105 static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
106 {
107         char *profile_name;
108         connection_profile_h profile = user_data;
109
110         if (profile == NULL)
111                 return;
112
113         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE)
114                 return;
115
116         printf("[%s] : %s\n", test_print_state(state), profile_name);
117         g_free(profile_name);
118 }
119
120 static void test_connection_opened_callback(connection_error_e result, void* user_data)
121 {
122         if (result ==  CONNECTION_ERROR_NONE)
123                 printf("Connection open Succeeded\n");
124         else
125                 printf("Connection open Failed, err : %d\n", result);
126 }
127
128 static void test_connection_closed_callback(connection_error_e result, void* user_data)
129 {
130         if (result ==  CONNECTION_ERROR_NONE)
131                 printf("Connection close Succeeded\n");
132         else
133                 printf("Connection close Failed, err : %d\n", result);
134 }
135
136 static bool test_get_user_selected_profile(connection_profile_h *profile, bool select)
137 {
138         int rv = 0;
139         int input = 0;
140         char *profile_name;
141         connection_profile_type_e profile_type;
142         connection_profile_state_e profile_state;
143         connection_profile_iterator_h profile_iter;
144         connection_profile_h profile_h;
145
146         connection_profile_h profile_list[100] = {0,};
147         int profile_count = 0;
148
149         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
150         if (rv != CONNECTION_ERROR_NONE) {
151                 printf("Fail to get profile iterator [%d]\n", rv);
152                 return false;
153         }
154
155         while (connection_profile_iterator_has_next(profile_iter)) {
156                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
157                         printf("Fail to get profile handle\n");
158                         return false;
159                 }
160
161                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
162                         printf("Fail to get profile name\n");
163                         return false;
164                 }
165
166                 if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
167                         printf("Fail to get profile type\n");
168                         g_free(profile_name);
169                         return false;
170                 }
171
172                 if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
173                         printf("Fail to get profile state\n");
174                         g_free(profile_name);
175                         return false;
176                 }
177
178                 if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) {
179                         char *essid;
180                         connection_profile_get_wifi_essid(profile_h, &essid);
181                         printf("%d. state:[%s], profile name:%s, essid:%s\n",
182                                 profile_count, test_print_state(profile_state),
183                                 profile_name, (essid)? essid : "");
184                         g_free(essid);
185
186                         profile_list[profile_count] = profile_h;
187                         profile_count++;
188                 } else {
189                         printf("%d. state:[%s], profile name : %s\n",
190                                 profile_count, test_print_state(profile_state), profile_name);
191
192                         profile_list[profile_count] = profile_h;
193                         profile_count++;
194                 }
195
196                 g_free(profile_name);
197                 if (profile_count >= 100)
198                         break;
199         }
200
201         if (select == false)
202                 return true;
203
204         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
205             input >= profile_count ||
206             input < 0) {
207                 printf("Wrong number!!\n");
208                 return false;
209         }
210
211         if (profile)
212                 *profile = profile_list[input];
213
214         return true;
215 }
216
217 static int test_update_cellular_info(connection_profile_h profile)
218 {
219         int rv = 0;
220         char input_str1[100] = {0,};
221         char input_str2[100] = {0,};
222         int input_int = 0;
223         int type_val = 0;
224
225         if (test_get_user_int("Input Network Type (internet:1, MMS:2, Prepaid internet:3, "
226                         "Prepaid MMS:4, Tethering:5, Application:6)"
227                         " - (Enter for skip) :", &input_int)) {
228                 switch (input_int) {
229                 case 1:
230                         rv = connection_profile_set_cellular_service_type(profile,
231                                         CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET);
232                         break;
233                 case 2:
234                         rv = connection_profile_set_cellular_service_type(profile,
235                                         CONNECTION_CELLULAR_SERVICE_TYPE_MMS);
236                         break;
237                 case 3:
238                         rv = connection_profile_set_cellular_service_type(profile,
239                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET);
240                         break;
241                 case 4:
242                         rv = connection_profile_set_cellular_service_type(profile,
243                                         CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS);
244                         break;
245                 case 5:
246                         rv = connection_profile_set_cellular_service_type(profile,
247                                         CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING);
248                         break;
249                 case 6:
250                         rv = connection_profile_set_cellular_service_type(profile,
251                                         CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION);
252                         break;
253                 default:
254                         return -1;
255                 }
256
257                 if (rv != CONNECTION_ERROR_NONE)
258                         return -1;
259         } else
260                 return -1;
261
262         if (test_get_user_string("Input Apn - (Enter for skip) :", input_str1, 100)) {
263                 rv = connection_profile_set_cellular_apn(profile, input_str1);
264                 if (rv != CONNECTION_ERROR_NONE)
265                         return -1;
266         }
267
268         if (test_get_user_string("Input Proxy - (Enter for skip) :", input_str1, 100)) {
269                 rv = connection_profile_set_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, input_str1);
270                 if (rv != CONNECTION_ERROR_NONE)
271                         return -1;
272         }
273
274         if (test_get_user_string("Input HomeURL - (Enter for skip) :", input_str1, 100)) {
275                 rv = connection_profile_set_cellular_home_url(profile, input_str1);
276                 if (rv != CONNECTION_ERROR_NONE)
277                         return -1;
278         }
279
280         if (test_get_user_int("Input AuthType(0:NONE 1:PAP 2:CHAP) - (Enter for skip) :", &input_int)) {
281                 switch (input_int) {
282                 case 0:
283                         rv = connection_profile_set_cellular_auth_info(profile,
284                                         CONNECTION_CELLULAR_AUTH_TYPE_NONE, "", "");
285                         if (rv != CONNECTION_ERROR_NONE)
286                                 return -1;
287
288                         break;
289                 case 1:
290                         type_val = CONNECTION_CELLULAR_AUTH_TYPE_PAP;
291                         /* fall through */
292                 case 2:
293                         if (input_int == 2) type_val = CONNECTION_CELLULAR_AUTH_TYPE_CHAP;
294
295                         if (test_get_user_string("Input AuthId(Enter for skip) :", input_str1, 100) == false)
296                                 input_str1[0] = 0;
297                         if (test_get_user_string("Input AuthPwd(Enter for skip) :", input_str2, 100) == false)
298                                 input_str2[0] = 0;
299
300                         rv = connection_profile_set_cellular_auth_info(profile, type_val, input_str1, input_str2);
301                         if (rv != CONNECTION_ERROR_NONE)
302                                 return -1;
303                 }
304         }
305
306         return 1;
307 }
308
309 static int test_update_wifi_info(connection_profile_h profile)
310 {
311         int rv = 0;
312         char input_str[100] = {0,};
313
314         if (test_get_user_string("Input Passphrase - (Enter for skip) :", input_str, 100)) {
315                 rv = connection_profile_set_wifi_passphrase(profile, input_str);
316                 if (rv != CONNECTION_ERROR_NONE)
317                         return -1;
318         }
319
320         return 1;
321 }
322
323 static int test_update_ip_info(connection_profile_h profile)
324 {
325         int rv = 0;
326         char input_str[100] = {0,};
327
328         if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) {
329                 rv = connection_profile_set_ip_address(profile,
330                                                         CONNECTION_ADDRESS_FAMILY_IPV4,
331                                                         input_str);
332                 if (rv != CONNECTION_ERROR_NONE)
333                         return -1;
334         }
335
336         if (test_get_user_string("Input Netmask - (Enter for skip) :", input_str, 100)) {
337                 rv = connection_profile_set_subnet_mask(profile,
338                                                         CONNECTION_ADDRESS_FAMILY_IPV4,
339                                                         input_str);
340                 if (rv != CONNECTION_ERROR_NONE)
341                         return -1;
342         }
343
344         if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) {
345                 rv = connection_profile_set_gateway_address(profile,
346                                                         CONNECTION_ADDRESS_FAMILY_IPV4,
347                                                         input_str);
348                 if (rv != CONNECTION_ERROR_NONE)
349                         return -1;
350         }
351
352         if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) {
353                 rv = connection_profile_set_dns_address(profile,
354                                                         1,
355                                                         CONNECTION_ADDRESS_FAMILY_IPV4,
356                                                         input_str);
357                 if (rv != CONNECTION_ERROR_NONE)
358                         return -1;
359
360                 if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) {
361                         rv = connection_profile_set_dns_address(profile,
362                                                                 2,
363                                                                 CONNECTION_ADDRESS_FAMILY_IPV4,
364                                                                 input_str);
365                         if (rv != CONNECTION_ERROR_NONE)
366                                 return -1;
367                 }
368         }
369
370         return 1;
371 }
372
373 static int test_update_proxy_info(connection_profile_h profile)
374 {
375         int rv = 0;
376         int input_int = 0;
377         char input_str[100] = {0,};
378
379         if (test_get_user_int("Input Proxy Type (1:direct, 2:auto, 3:manual)"
380                                         " - (Enter for skip) :", &input_int)) {
381                 switch (input_int) {
382                 case 1:
383                         rv = connection_profile_set_proxy_type(profile,
384                                         CONNECTION_PROXY_TYPE_DIRECT);
385
386                         if (rv != CONNECTION_ERROR_NONE)
387                                 return -1;
388                         else
389                                 return 1;
390                 case 2:
391                         rv = connection_profile_set_proxy_type(profile,
392                                         CONNECTION_PROXY_TYPE_AUTO);
393                         break;
394                 case 3:
395                         rv = connection_profile_set_proxy_type(profile,
396                                         CONNECTION_PROXY_TYPE_MANUAL);
397                         break;
398                 default:
399                         return -1;
400                 }
401
402                 if (rv != CONNECTION_ERROR_NONE)
403                         return -1;
404
405                 if (test_get_user_string("Input auto Proxy URL or Proxy address"
406                                         " - (Enter for skip) :", input_str, 100)) {
407                         rv = connection_profile_set_proxy_address(profile,
408                                                                 CONNECTION_ADDRESS_FAMILY_IPV4,
409                                                                 input_str);
410                         if (rv != CONNECTION_ERROR_NONE)
411                                 return -1;
412                 }
413
414         } else
415                 return -1;
416
417         return 1;
418 }
419
420 static int test_update_network_info(connection_profile_h profile)
421 {
422         int rv = 0;
423         int input_int = 0;
424
425         if (test_get_user_int("Input IPv4 Address Type (DHCP:1, Static:2)"
426                                 " - (Enter for skip) :", &input_int)) {
427                 switch (input_int) {
428                 case 1:
429                         rv = connection_profile_set_ip_config_type(profile,
430                                                                 CONNECTION_ADDRESS_FAMILY_IPV4,
431                                                                 CONNECTION_IP_CONFIG_TYPE_DYNAMIC);
432                         break;
433                 case 2:
434                         rv = connection_profile_set_ip_config_type(profile,
435                                                                 CONNECTION_ADDRESS_FAMILY_IPV4,
436                                                                 CONNECTION_IP_CONFIG_TYPE_STATIC);
437                         if (rv != CONNECTION_ERROR_NONE)
438                                 return -1;
439
440                         if (test_update_ip_info(profile) == -1)
441                                 return -1;
442
443                         if (test_update_proxy_info(profile) == -1)
444                                 return -1;
445                         break;
446                 default:
447                         return -1;
448                 }
449
450                 if (rv != CONNECTION_ERROR_NONE)
451                         return -1;
452         } else
453                 return -1;
454
455         return 1;
456 }
457
458 static void test_print_cellular_info(connection_profile_h profile)
459 {
460         connection_cellular_network_type_e network_type;
461         connection_cellular_service_type_e service_type;
462         char *apn = NULL;
463         connection_cellular_auth_type_e auth_type;
464         char *user_name = NULL;
465         char *password = NULL;
466         char *home_url = NULL;
467         bool roaming = false;
468
469         if (connection_profile_get_cellular_network_type(profile, &network_type) != CONNECTION_ERROR_NONE)
470                 printf("Fail to get cellular network type!\n");
471         else
472                 printf("Cellular network type : %d\n", network_type);
473
474         if (connection_profile_get_cellular_service_type(profile, &service_type) != CONNECTION_ERROR_NONE)
475                 printf("Fail to get cellular service type!\n");
476         else
477                 printf("Cellular service type : %d\n", service_type);
478
479         if (connection_profile_get_cellular_apn(profile, &apn) != CONNECTION_ERROR_NONE)
480                 printf("Fail to get cellular APN!\n");
481         else {
482                 printf("Cellular APN : %s\n", apn);
483                 g_free(apn);
484         }
485
486         if (connection_profile_get_cellular_auth_info(profile, &auth_type, &user_name, &password) != CONNECTION_ERROR_NONE)
487                 printf("Fail to get auth info!\n");
488         else {
489                 printf("Cellular auth type : %d\n", auth_type);
490                 printf("Cellular user_name : %s\n", user_name);
491                 printf("Cellular password : %s\n", password);
492                 g_free(user_name);
493                 g_free(password);
494         }
495
496         if (connection_profile_get_cellular_home_url(profile, &home_url) != CONNECTION_ERROR_NONE)
497                 printf("Fail to get cellular home url!\n");
498         else {
499                 printf("Cellular home url : %s\n", home_url);
500                 g_free(home_url);
501         }
502
503         if (connection_profile_is_cellular_roaming(profile, &roaming) != CONNECTION_ERROR_NONE)
504                 printf("Fail to get cellular is roaming!\n");
505         else
506                 printf("Cellular roaming : %s\n", roaming ? "true" : "false");
507 }
508
509 static void test_print_wifi_info(connection_profile_h profile)
510 {
511         char *essid = NULL;
512         char *bssid = NULL;
513         int rssi = 0;
514         int frequency = 0;
515         int max_speed = 0;
516         connection_wifi_security_type_e security_type;
517         connection_wifi_encryption_type_e encryption_type;
518         bool pass_required = false;
519         bool wps_supported = false;
520
521         if (connection_profile_get_wifi_essid(profile, &essid) != CONNECTION_ERROR_NONE)
522                 printf("Fail to get Wi-Fi essid!\n");
523         else {
524                 printf("Wi-Fi essid : %s\n", essid);
525                 g_free(essid);
526         }
527
528         if (connection_profile_get_wifi_bssid(profile, &bssid) != CONNECTION_ERROR_NONE)
529                 printf("Fail to get Wi-Fi bssid!\n");
530         else {
531                 printf("Wi-Fi bssid : %s\n", bssid);
532                 g_free(bssid);
533         }
534
535         if (connection_profile_get_wifi_rssi(profile, &rssi) != CONNECTION_ERROR_NONE)
536                 printf("Fail to get Wi-Fi rssi!\n");
537         else
538                 printf("Wi-Fi rssi : %d\n", rssi);
539
540         if (connection_profile_get_wifi_frequency(profile, &frequency) != CONNECTION_ERROR_NONE)
541                 printf("Fail to get Wi-Fi frequency!\n");
542         else
543                 printf("Wi-Fi frequency : %d\n", frequency);
544
545         if (connection_profile_get_wifi_max_speed(profile, &max_speed) != CONNECTION_ERROR_NONE)
546                 printf("Fail to get Wi-Fi max speed!\n");
547         else
548                 printf("Wi-Fi max speed : %d\n", max_speed);
549
550         if (connection_profile_get_wifi_security_type(profile, &security_type) != CONNECTION_ERROR_NONE)
551                 printf("Fail to get Wi-Fi security type!\n");
552         else
553                 printf("Wi-Fi security type : %d\n", security_type);
554
555         if (connection_profile_get_wifi_encryption_type(profile, &encryption_type) != CONNECTION_ERROR_NONE)
556                 printf("Fail to get Wi-Fi encryption type!\n");
557         else
558                 printf("Wi-Fi encryption type : %d\n", encryption_type);
559
560         if (connection_profile_is_wifi_passphrase_required(profile, &pass_required) != CONNECTION_ERROR_NONE)
561                 printf("Fail to get Wi-Fi passphrase required!\n");
562         else
563                 printf("Wi-Fi passphrase required : %s\n", pass_required ? "true" : "false");
564
565         if (connection_profile_is_wifi_wps_supported(profile, &wps_supported) != CONNECTION_ERROR_NONE)
566                 printf("Fail to get Wi-Fi wps info\n");
567         else
568                 printf("Wi-Fi wps supported : %s\n", wps_supported ? "true" : "false");
569 }
570
571 static void test_print_network_info(connection_profile_h profile)
572 {
573         char *interface_name = NULL;
574         connection_ip_config_type_e ip_type;
575         char *ip = NULL;
576         char *subnet = NULL;
577         char *gateway = NULL;
578         char *dns1 = NULL;
579         char *dns2 = NULL;
580         connection_proxy_type_e proxy_type;
581         char *proxy = NULL;
582
583         if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE)
584                 printf("Fail to get interface name!\n");
585         else {
586                 printf("Interface name : %s\n", interface_name);
587                 g_free(interface_name);
588         }
589
590         if (connection_profile_get_ip_config_type(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_type) != CONNECTION_ERROR_NONE)
591                 printf("Fail to get ipconfig type!\n");
592         else
593                 printf("Ipconfig type : %d\n", ip_type);
594
595         if (connection_profile_get_ip_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &ip) != CONNECTION_ERROR_NONE)
596                 printf("Fail to get IP address!\n");
597         else {
598                 printf("IP address : %s\n", ip);
599                 g_free(ip);
600         }
601
602         if (connection_profile_get_subnet_mask(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &subnet) != CONNECTION_ERROR_NONE)
603                 printf("Fail to get subnet mask!\n");
604         else {
605                 printf("Subnet mask : %s\n", subnet);
606                 g_free(subnet);
607         }
608
609         if (connection_profile_get_gateway_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &gateway) != CONNECTION_ERROR_NONE)
610                 printf("Fail to get gateway!\n");
611         else {
612                 printf("Gateway : %s\n", gateway);
613                 g_free(gateway);
614         }
615
616         if (connection_profile_get_dns_address(profile, 1, CONNECTION_ADDRESS_FAMILY_IPV4, &dns1) != CONNECTION_ERROR_NONE)
617                 printf("Fail to get DNS1!\n");
618         else {
619                 printf("DNS1 : %s\n", dns1);
620                 g_free(dns1);
621         }
622
623         if (connection_profile_get_dns_address(profile, 2, CONNECTION_ADDRESS_FAMILY_IPV4, &dns2) != CONNECTION_ERROR_NONE)
624                 printf("Fail to get DNS2!\n");
625         else {
626                 printf("DNS2 : %s\n", dns2);
627                 g_free(dns2);
628         }
629
630         if (connection_profile_get_proxy_type(profile, &proxy_type) != CONNECTION_ERROR_NONE)
631                 printf("Fail to get proxy type!\n");
632         else
633                 printf("Proxy type : %d\n", proxy_type);
634
635         if (connection_profile_get_proxy_address(profile, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy) != CONNECTION_ERROR_NONE)
636                 printf("Fail to get proxy!\n");
637         else {
638                 printf("Proxy : %s\n", proxy);
639                 g_free(proxy);
640         }
641 }
642
643 int test_register_client(void)
644 {
645
646         int err = connection_create(&connection);
647
648         if (CONNECTION_ERROR_NONE == err) {
649                 connection_set_type_changed_cb(connection, test_type_changed_callback, NULL);
650                 connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL);
651                 connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
652         } else {
653                 printf("Client registration failed %d\n", err);
654                 return -1;
655         }
656
657         printf("Client registration success\n");
658         return 1;
659 }
660
661 int  test_deregister_client(void)
662 {
663         int rv = 0;
664         GSList *list;
665         connection_profile_h profile;
666
667         if (connection != NULL)
668                 rv = connection_destroy(connection);
669         else {
670                 printf("Cannot deregister : Handle is NULL\n");
671                 rv = CONNECTION_ERROR_INVALID_OPERATION;
672         }
673
674         if (rv != CONNECTION_ERROR_NONE){
675                 printf("Client deregistration fail [%d]\n", rv);
676                 return -1;
677         }
678
679         if (state_cb_list) {
680                 for (list = state_cb_list; list; list = list->next) {
681                         profile = list->data;
682                         connection_profile_destroy(profile);
683                 }
684
685                 g_slist_free(state_cb_list);
686                 state_cb_list = NULL;
687         }
688
689         connection = NULL;
690         printf("Client deregistration success\n");
691
692         return 1;
693 }
694
695 int test_get_network_state(void)
696 {
697         int rv = 0;
698         connection_type_e net_state;
699
700         rv = connection_get_type(connection, &net_state);
701
702         if (rv != CONNECTION_ERROR_NONE) {
703                 printf("Fail to get network state [%d]\n", rv);
704                 return -1;
705         }
706
707         printf("Retval = %d network connection state [%d]\n", rv, net_state);
708
709         return 1;
710 }
711
712 int test_get_cellular_state(void)
713 {
714         int rv = 0;
715         connection_cellular_state_e cellular_state;
716
717         rv = connection_get_cellular_state(connection, &cellular_state);
718
719         if (rv != CONNECTION_ERROR_NONE) {
720                 printf("Fail to get Cellular state [%d]\n", rv);
721                 return -1;
722         }
723
724         printf("Retval = %d Cellular state [%d]\n", rv, cellular_state);
725
726         return 1;
727 }
728
729 int test_get_wifi_state(void)
730 {
731         int rv = 0;
732         connection_wifi_state_e wifi_state;
733
734         rv = connection_get_wifi_state(connection, &wifi_state);
735
736         if (rv != CONNECTION_ERROR_NONE) {
737                 printf("Fail to get WiFi state [%d]\n", rv);
738                 return -1;
739         }
740
741         printf("Retval = %d WiFi state [%d]\n", rv, wifi_state);
742
743         return 1;
744 }
745
746 int test_get_current_proxy(void)
747 {
748         char *proxy_addr = NULL;
749
750         connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_addr);
751
752         if (proxy_addr == NULL) {
753                 printf("Proxy address does not exist\n");
754                 return -1;
755         }
756
757         printf("Current Proxy [%s]\n", proxy_addr);
758         g_free(proxy_addr);
759
760         return 1;
761 }
762
763 int test_get_current_ip(void)
764 {
765         char *ip_addr = NULL;
766
767         connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
768
769         if (ip_addr == NULL) {
770                 printf("IP address does not exist\n");
771                 return -1;
772         }
773
774         printf("IPv4 address : %s\n", ip_addr);
775         g_free(ip_addr);
776
777         return 1;       
778 }
779
780 int test_get_call_statistics_info(void)
781 {
782         long long rv = 0;
783
784         connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
785         printf("last recv data size [%lld]\n", rv);
786         connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
787         printf("last sent data size [%lld]\n",rv );
788         connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
789         printf("total received data size [%lld]\n",rv );
790         connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
791         printf("total sent data size [%lld]\n", rv);
792
793         return 1;
794 }
795
796 int test_get_wifi_call_statistics_info(void)
797 {
798         long long rv = 0;
799
800         connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv);
801         printf("WiFi last recv data size [%lld]\n", rv);
802         connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv);
803         printf("WiFi last sent data size [%lld]\n",rv );
804         connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv);
805         printf("WiFi total received data size [%lld]\n",rv );
806         connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv);
807         printf("WiFi total sent data size [%lld]\n", rv);
808
809         return 1;
810 }
811
812 int test_get_profile_list(void)
813 {
814         if (test_get_user_selected_profile(NULL, false) == false)
815                 return -1;
816
817         return 1;
818 }
819
820 int test_get_connected_profile_list(void)
821 {
822         int rv = 0;
823         char *profile_name = NULL;
824         connection_profile_iterator_h profile_iter;
825         connection_profile_h profile_h;
826
827         rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter);
828         if (rv != CONNECTION_ERROR_NONE) {
829                 printf("Fail to get profile iterator [%d]\n", rv);
830                 return -1;
831         }
832
833         while (connection_profile_iterator_has_next(profile_iter)) {
834                 if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
835                         printf("Fail to get profile handle\n");
836                         return -1;
837                 }
838
839                 if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
840                         printf("Fail to get profile name\n");
841                         return -1;
842                 }
843                 printf("profile name : %s\n", profile_name);
844                 g_free(profile_name);
845         }
846
847         return 1;
848 }
849
850 int test_get_current_profile(void)
851 {
852         int rv = 0;
853         char *profile_name = NULL;
854         connection_profile_h profile_h;
855
856         rv = connection_get_current_profile(connection, &profile_h);
857         if (rv != CONNECTION_ERROR_NONE) {
858                 printf("Fail to get profile iterator [%d]\n", rv);
859                 return -1;
860         }
861
862         if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
863                 printf("Fail to get profile name\n");
864                 return -1;
865         }
866         printf("profile name : %s\n", profile_name);
867         g_free(profile_name);
868
869         connection_profile_destroy(profile_h);
870
871         return 1;
872 }
873
874 int test_open_profile(void)
875 {
876         connection_profile_h profile;
877
878         printf("\n** Choose a profile to open. **\n");
879
880         if (test_get_user_selected_profile(&profile, true) == false)
881                 return -1;
882
883         if (connection_open_profile(connection, profile, test_connection_opened_callback, NULL) != CONNECTION_ERROR_NONE) {
884                 printf("Connection open Failed!!\n");
885                 return -1;
886         }
887
888         return 1;
889 }
890
891 int test_get_default_cellular_service_type(void)
892 {
893         int input;
894         int rv;
895         int service_type;
896         connection_profile_h profile;
897         char *profile_name = NULL;
898
899         rv = test_get_user_int("Input profile type to get"
900                         "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering):", &input);
901
902         if (rv == false) {
903                 printf("Invalid input!!\n");
904                 return -1;
905         }
906
907         switch (input) {
908         case 1:
909                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET;
910                 break;
911         case 2:
912                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS;
913                 break;
914         case 3:
915                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET;
916                 break;
917         case 4:
918                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS;
919                 break;
920         case 5:
921                 service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING;
922                 break;
923         default:
924                 printf("Wrong number!!\n");
925                 return -1;
926         }
927
928         if (connection_get_default_cellular_service_profile(connection, service_type, &profile) != CONNECTION_ERROR_NONE)
929                 return -1;
930
931         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
932                 printf("Fail to get profile name\n");
933                 connection_profile_destroy(profile);
934                 return -1;
935         }
936         printf("Default profile name : %s\n", profile_name);
937         g_free(profile_name);
938
939         connection_profile_destroy(profile);
940
941         return 1;
942 }
943
944 int test_set_default_cellular_service_type(void)
945 {
946         connection_profile_h profile;
947         connection_cellular_service_type_e type;
948
949         printf("\n** Choose a profile to set default service(internet or prepaid internet type only). **\n");
950         if (test_get_user_selected_profile(&profile, true) == false)
951                 return -1;
952
953         if (connection_profile_get_cellular_service_type(profile, &type) != CONNECTION_ERROR_NONE) {
954                 printf("Fail to get cellular service type\n");
955                 return -1;
956         }
957
958         if (connection_set_default_cellular_service_profile(connection, type, profile) != CONNECTION_ERROR_NONE)
959                 return -1;
960
961         return 1;
962 }
963
964 int test_close_profile(void)
965 {
966         connection_profile_h profile;
967
968         printf("\n** Choose a profile to close. **\n");
969
970         if (test_get_user_selected_profile(&profile, true) == false)
971                 return -1;
972
973         if (connection_close_profile(connection, profile, test_connection_closed_callback, NULL) != CONNECTION_ERROR_NONE) {
974                 printf("Connection close Failed!!\n");
975                 return -1;
976         }
977
978         return 1;
979 }
980
981 int test_add_profile(void)
982 {
983         int rv = 0;
984         connection_profile_h profile;
985         char input_str[100] = {0,};
986
987         if (test_get_user_string("Input Keyword - (Enter for skip) :", input_str, 100) == false)
988                 return -1;
989
990         rv = connection_profile_create(CONNECTION_PROFILE_TYPE_CELLULAR, input_str, &profile);
991         if (rv != CONNECTION_ERROR_NONE)
992                 RETURN_FAIL_DESTROY(profile);
993
994         if (test_update_cellular_info(profile) == -1)
995                 RETURN_FAIL_DESTROY(profile);
996
997         rv = connection_add_profile(connection, profile);
998         if (rv != CONNECTION_ERROR_NONE)
999                 RETURN_FAIL_DESTROY(profile);
1000
1001         connection_profile_destroy(profile);
1002         return 1;
1003 }
1004
1005 int test_remove_profile(void)
1006 {
1007         connection_profile_h profile;
1008
1009         printf("\n** Choose a profile to remove. **\n");
1010         if (test_get_user_selected_profile(&profile, true) == false)
1011                 return -1;
1012
1013         if (connection_remove_profile(connection, profile) != CONNECTION_ERROR_NONE) {
1014                 printf("Remove profile Failed!!\n");
1015                 return -1;
1016         }
1017
1018         return 1;
1019 }
1020
1021 int test_update_profile(void)
1022 {
1023         int rv = 0;
1024
1025         connection_profile_type_e prof_type;
1026         connection_profile_h profile;
1027
1028         printf("\n** Choose a profile to update. **\n");
1029         if (test_get_user_selected_profile(&profile, true) == false)
1030                 return -1;
1031
1032         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1033                 return -1;
1034
1035         switch (prof_type) {
1036         case CONNECTION_PROFILE_TYPE_CELLULAR:
1037                 if (test_update_cellular_info(profile) == -1)
1038                         return -1;
1039
1040                 break;
1041         case CONNECTION_PROFILE_TYPE_WIFI:
1042                 if (test_update_wifi_info(profile) == -1)
1043                         return -1;
1044
1045                 if (test_update_network_info(profile) == -1)
1046                         return -1;
1047
1048                 break;
1049         case CONNECTION_PROFILE_TYPE_ETHERNET:
1050         case CONNECTION_PROFILE_TYPE_BT:
1051                 printf("Not supported!\n");
1052                 /* fall through */
1053         default:
1054                 return -1;
1055         }
1056
1057         rv = connection_update_profile(connection, profile);
1058         if (rv != CONNECTION_ERROR_NONE)
1059                 return -1;
1060
1061         return 1;
1062 }
1063
1064 int test_get_profile_info(void)
1065 {
1066         connection_profile_type_e prof_type;
1067         connection_profile_state_e profile_state;
1068         connection_profile_h profile;
1069         char *profile_name = NULL;
1070
1071         printf("\n** Choose a profile to print. **\n");
1072         if (test_get_user_selected_profile(&profile, true) == false)
1073                 return -1;
1074
1075         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1076                 printf("Fail to get profile name\n");
1077                 return -1;
1078         } else {
1079                 printf("Profile Name : %s\n", profile_name);
1080                 g_free(profile_name);
1081         }
1082
1083         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1084                 printf("Fail to get profile state\n");
1085                 return -1;
1086         } else
1087                 printf("Profile State : %s\n", test_print_state(profile_state));
1088
1089
1090         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1091                 return -1;
1092
1093         switch (prof_type) {
1094         case CONNECTION_PROFILE_TYPE_CELLULAR:
1095                 printf("Profile Type : Cellular\n");
1096                 test_print_cellular_info(profile);
1097                 break;
1098         case CONNECTION_PROFILE_TYPE_WIFI:
1099                 printf("Profile Type : Wi-Fi\n");
1100                 test_print_wifi_info(profile);
1101                 break;
1102         case CONNECTION_PROFILE_TYPE_ETHERNET:
1103                 printf("Profile Type : Ethernet\n");
1104                 break;
1105         case CONNECTION_PROFILE_TYPE_BT:
1106                 printf("Profile Type : Bluetooth\n");
1107                 break;
1108         default:
1109                 return -1;
1110         }
1111
1112         test_print_network_info(profile);
1113
1114         return 1;
1115 }
1116
1117 int test_refresh_profile_info(void)
1118 {
1119         connection_profile_type_e prof_type;
1120         connection_profile_state_e profile_state;
1121         connection_profile_h profile;
1122         char *profile_name = NULL;
1123
1124         printf("\n** Choose a profile to refresh. **\n");
1125         if (test_get_user_selected_profile(&profile, true) == false)
1126                 return -1;
1127
1128         if (connection_profile_refresh(profile) != CONNECTION_ERROR_NONE)
1129                 return -1;
1130
1131         if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1132                 printf("Fail to get profile name\n");
1133                 return -1;
1134         } else {
1135                 printf("Profile Name : %s\n", profile_name);
1136                 g_free(profile_name);
1137         }
1138
1139         if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) {
1140                 printf("Fail to get profile state\n");
1141                 return -1;
1142         } else
1143                 printf("Profile State : %s\n", test_print_state(profile_state));
1144
1145
1146         if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
1147                 return -1;
1148
1149         switch (prof_type) {
1150         case CONNECTION_PROFILE_TYPE_CELLULAR:
1151                 printf("Profile Type : Cellular\n");
1152                 test_print_cellular_info(profile);
1153                 break;
1154         case CONNECTION_PROFILE_TYPE_WIFI:
1155                 printf("Profile Type : Wi-Fi\n");
1156                 test_print_wifi_info(profile);
1157                 break;
1158         case CONNECTION_PROFILE_TYPE_ETHERNET:
1159                 printf("Profile Type : Ethernet\n");
1160                 break;
1161         case CONNECTION_PROFILE_TYPE_BT:
1162                 printf("Profile Type : Bluetooth\n");
1163                 break;
1164         default:
1165                 return -1;
1166         }
1167
1168         test_print_network_info(profile);
1169
1170         return 1;
1171 }
1172
1173 int test_set_state_changed_callback()
1174 {
1175         connection_profile_h profile;
1176         connection_profile_h profile_clone;
1177
1178         printf("\n** Choose a profile to set callback. **\n");
1179         if (test_get_user_selected_profile(&profile, true) == false)
1180                 return -1;
1181
1182         if (connection_profile_clone(&profile_clone, profile) != CONNECTION_ERROR_NONE)
1183                 return -1;
1184
1185         if (connection_profile_set_state_changed_cb(profile,
1186                         test_profile_state_callback, profile_clone) != CONNECTION_ERROR_NONE) {
1187                 connection_profile_destroy(profile_clone);
1188                 return -1;
1189         }
1190
1191         state_cb_list = g_slist_append(state_cb_list, profile_clone);
1192
1193         return 1;
1194 }
1195
1196 int test_unset_state_changed_callback()
1197 {
1198         connection_profile_h profile;
1199         GSList *list;
1200         char *profile_name = NULL;
1201         int count = 0;
1202         int input = 0;
1203
1204         printf("\n** Choose a profile to unset callback. **\n");
1205         for (list = state_cb_list; list; list = list->next) {
1206                 profile = list->data;
1207                 if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) {
1208                         printf("Fail to get profile name!\n");
1209                         return -1;
1210                 } else {
1211                         printf("%d. %s\n", count, profile_name);
1212                         g_free(profile_name);
1213                 }
1214
1215                 count++;
1216         }
1217
1218         if (test_get_user_int("Input profile number(Enter for cancel) :", &input) == false ||
1219             input >= count ||
1220             input < 0) {
1221                 printf("Wrong number!!\n");
1222                 return -1;
1223         }
1224
1225         count = 0;
1226         for (list = state_cb_list; list; list = list->next) {
1227                 if (count == input) {
1228                         profile = list->data;
1229                         goto unset;
1230                 }
1231
1232                 count++;
1233         }
1234
1235         return -1;
1236
1237 unset:
1238         if (connection_profile_unset_state_changed_cb(profile) != CONNECTION_ERROR_NONE)
1239                 return -1;
1240
1241         state_cb_list = g_slist_remove(state_cb_list, profile);
1242         connection_profile_destroy(profile);
1243
1244         return 1;
1245 }
1246
1247 int test_reset_call_statistics_info(void)
1248 {
1249         int ret = CONNECTION_ERROR_NONE;
1250
1251         ret = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1252         printf("reset last recv data size [%d]\n", ret);
1253         ret = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1254         printf("last sent data size [%d]\n", ret);
1255         ret = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1256         printf("total received data size [%d]\n", ret);
1257         ret = connection_reset_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1258         printf("total sent data size [%d]\n", ret);
1259
1260         return 1;
1261 }
1262
1263 int test_reset_wifi_call_statistics_info(void)
1264 {
1265         int ret = CONNECTION_ERROR_NONE;
1266
1267         ret = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA);
1268         printf("WiFi last sent data size [%d]\n", ret);
1269         ret = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA);
1270         printf("WiFi last recv data size [%d]\n", ret);
1271         ret = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA);
1272         printf("WiFi total sent data size [%d]\n", ret);
1273         ret = connection_reset_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA);
1274         printf("WiFi total received data size [%d]\n", ret);
1275
1276         return 1;
1277 }
1278
1279 int test_add_route(void)
1280 {
1281         int rv = 0;
1282         char ip_addr[30];
1283         char if_name[40];
1284
1285         if (test_get_user_string("Input IP - (Enter for skip) :", ip_addr, 30) == false)
1286                 return -1;
1287
1288         if (test_get_user_string("Input Interface name - (Enter for skip) :", if_name, 40) == false)
1289                 return -1;
1290
1291         rv = connection_add_route(connection, if_name, ip_addr);
1292         if (rv != CONNECTION_ERROR_NONE) {
1293                 printf("Fail to get add new route [%d]\n", rv);
1294                 return -1;
1295         }
1296
1297         return 1;
1298 }
1299
1300 int test_get_bt_state(void)
1301 {
1302         int rv = 0;
1303         connection_bt_state_e bt_state;
1304
1305         rv = connection_get_bt_state(connection, &bt_state);
1306
1307         if (rv != CONNECTION_ERROR_NONE) {
1308                 printf("Fail to get Bluetooth state [%d]\n", rv);
1309                 return -1;
1310         }
1311
1312         printf("Retval = %d, Bluetooth state [%d]\n", rv, bt_state);
1313
1314         return 1;
1315 }
1316
1317 int test_get_profile_id(void)
1318 {
1319         connection_profile_h profile;
1320         char *profile_id;
1321
1322         printf("\n** Choose a profile to see profile id. **\n");
1323         if (test_get_user_selected_profile(&profile, true) == false)
1324                 return -1;
1325
1326         if (connection_profile_get_id(profile, &profile_id) != CONNECTION_ERROR_NONE) {
1327                 printf("Fail to get profile name\n");
1328                 return -1;
1329         } else {
1330                 printf("Profile id : %s\n", profile_id);
1331                 g_free(profile_id);
1332         }
1333
1334         return 1;
1335 }
1336
1337 int main(int argc, char **argv)
1338 {
1339         
1340         GMainLoop *mainloop;
1341         mainloop = g_main_loop_new (NULL, FALSE);
1342
1343         GIOChannel *channel = g_io_channel_unix_new(0);
1344         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread,NULL );
1345
1346         printf("Test Thread created...\n");
1347
1348         g_main_loop_run (mainloop);
1349
1350         return 0;
1351 }
1352
1353 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1354 {
1355         int rv = 0;
1356         char a[100];
1357         
1358         memset(a, '\0', 100);
1359         printf("Event received from stdin\n");
1360         
1361         rv = read(0, a, 100);
1362         
1363         if (rv < 0 || a[0] == '0') {
1364                 if (connection != NULL)
1365                         test_deregister_client();
1366
1367                 exit(1);
1368         }
1369
1370         if (*a == '\n' || *a == '\r'){
1371                 printf("\n\n Network Connection API Test App\n\n");
1372                 printf("Options..\n");
1373                 printf("1       - Create Handle and set callbacks\n");
1374                 printf("2       - Destroy Handle(unset callbacks automatically)\n");
1375                 printf("3       - Get network state\n");
1376                 printf("4       - Get cellular state (please insert SIM Card)\n");
1377                 printf("5       - Get wifi state (please turn on WiFi)\n");
1378                 printf("6       - Get current proxy address \n");
1379                 printf("7       - Get current Ip address\n");
1380                 printf("8       - Get cellular data call statistics\n");
1381                 printf("9       - Get WiFi data call statistics\n");
1382                 printf("a       - Get Profile list\n");
1383                 printf("b       - Get Connected Profile list\n");
1384                 printf("c       - Get Current profile\n");
1385                 printf("d       - Open connection with profile\n");
1386                 printf("e       - Get default cellular service by type\n");
1387                 printf("f       - Set default cellular service by type\n");
1388                 printf("g       - Close connection with profile\n");
1389                 printf("h       - Add profile(Cellular only)\n");
1390                 printf("i       - Remove profile(Cellular:delete, WiFi:forgot)\n");
1391                 printf("j       - Update profile\n");
1392                 printf("k       - Get profile info\n");
1393                 printf("l       - Refresh profile info\n");
1394                 printf("m       - Set state changed callback\n");
1395                 printf("n       - Unset state changed callback\n");
1396                 printf("o       - Reset cellular data call statistics\n");
1397                 printf("p       - Reset WiFi data call statistics\n");
1398                 printf("q       - Add new route\n");
1399                 printf("r       - Get Bluetooth state\n");
1400                 printf("s       - Get profile id\n");
1401                 printf("0       - Exit \n");
1402                 printf("ENTER  - Show options menu.......\n");
1403         }
1404
1405         switch (a[0]) {
1406         case '1':
1407                 rv = test_register_client();
1408                 break;
1409         case '2':
1410                 rv = test_deregister_client();
1411                 break;
1412         case '3':
1413                 rv = test_get_network_state();
1414                 break;
1415         case '4':
1416                 rv = test_get_cellular_state();
1417                 break;
1418         case '5':
1419                 rv = test_get_wifi_state();
1420                 break;
1421         case '6':
1422                 rv = test_get_current_proxy();
1423                 break;
1424         case '7':
1425                 rv = test_get_current_ip();
1426                 break;
1427         case '8':
1428                 rv = test_get_call_statistics_info();
1429                 break;
1430         case '9':
1431                 rv = test_get_wifi_call_statistics_info();
1432                 break;
1433         case 'a':
1434                 rv = test_get_profile_list();
1435                 break;
1436         case 'b':
1437                 rv = test_get_connected_profile_list();
1438                 break;
1439         case 'c':
1440                 rv = test_get_current_profile();
1441                 break;
1442         case 'd':
1443                 rv = test_open_profile();
1444                 break;
1445         case 'e':
1446                 rv = test_get_default_cellular_service_type();
1447                 break;
1448         case 'f':
1449                 rv = test_set_default_cellular_service_type();
1450                 break;
1451         case 'g':
1452                 rv = test_close_profile();
1453                 break;
1454         case 'h':
1455                 rv = test_add_profile();
1456                 break;
1457         case 'i':
1458                 rv = test_remove_profile();
1459                 break;
1460         case 'j':
1461                 rv = test_update_profile();
1462                 break;
1463         case 'k':
1464                 rv = test_get_profile_info();
1465                 break;
1466         case 'l':
1467                 rv = test_refresh_profile_info();
1468                 break;
1469         case 'm':
1470                 rv = test_set_state_changed_callback();
1471                 break;
1472         case 'n':
1473                 rv = test_unset_state_changed_callback();
1474                 break;
1475         case 'o':
1476                 rv = test_reset_call_statistics_info();
1477                 break;
1478         case 'p':
1479                 rv = test_reset_wifi_call_statistics_info();
1480                 break;
1481         case 'q':
1482                 rv = test_add_route();
1483                 break;
1484         case 'r':
1485                 rv = test_get_bt_state();
1486                 break;
1487         case 's':
1488                 rv = test_get_profile_id();
1489                 break;
1490         }
1491
1492         if (rv == 1)
1493                 printf("Operation succeeded!\n");
1494         else
1495                 printf("Operation failed!\n");
1496
1497         return TRUE;
1498 }