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