Added new APIs for IPv6 tethering
[platform/core/api/tethering.git] / test / tethering_test.c
1 /*
2 * Copyright (c) 2011 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 <stdlib.h>
19 #include <string.h>
20 #include <unistd.h>
21 #include <glib.h>
22 #include <glib-object.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
26
27 #include <vconf.h>
28
29 #include "tethering.h"
30
31 #define DISABLE_REASON_TEXT_LEN 64
32 #define COMMON_STR_BUF_LEN      32
33
34 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
35
36 typedef struct {
37         tethering_enabled_cb enabled_cb;
38         tethering_disabled_cb disabled_cb;
39         tethering_connection_state_changed_cb changed_cb;
40         tethering_wifi_security_type_changed_cb security_type_changed_cb;
41         tethering_wifi_ssid_visibility_changed_cb ssid_visibility_changed_cb;
42         tethering_wifi_passphrase_changed_cb passphrase_changed_cb;
43 } __tethering_cbs;
44
45 tethering_h th = NULL;
46
47 static bool __is_err(tethering_error_e ret)
48 {
49         char *err_msg = NULL;
50
51         switch (ret) {
52         case TETHERING_ERROR_INVALID_PARAMETER:
53                 err_msg = "Wrong parameter is used";
54                 break;
55
56         case TETHERING_ERROR_OUT_OF_MEMORY:
57                 err_msg = "Memory is not enough";
58                 break;
59
60         case TETHERING_ERROR_NONE:
61                 return false;
62
63         case TETHERING_ERROR_NOT_ENABLED:
64                 err_msg = "Tethering is not enabled";
65                 break;
66
67         case TETHERING_ERROR_OPERATION_FAILED:
68                 err_msg = "Operation is failed";
69                 break;
70
71         case TETHERING_ERROR_RESOURCE_BUSY:
72                 err_msg = "Resource is busy";
73                 break;
74
75         case TETHERING_ERROR_NOT_PERMITTED:
76                 err_msg = "Operation is not permitted";
77                 break;
78
79         default:
80                 err_msg = "This should not be happened";
81                 break;
82         }
83
84         g_print("##ERR: %s\n", err_msg);
85
86         return true;
87 }
88
89 static const char *__convert_tethering_type_to_str(const tethering_type_e type)
90 {
91         static char str_buf[COMMON_STR_BUF_LEN] = {0, };
92
93         switch (type) {
94         case TETHERING_TYPE_USB:
95                 g_strlcpy(str_buf, "USB Tethering", sizeof(str_buf));
96                 break;
97
98         case TETHERING_TYPE_WIFI:
99                 g_strlcpy(str_buf, "Wi-Fi Tethering", sizeof(str_buf));
100                 break;
101
102         case TETHERING_TYPE_BT:
103                 g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf));
104                 break;
105
106         default:
107                 g_strlcpy(str_buf, "Unknown", sizeof(str_buf));
108                 break;
109         }
110
111         return str_buf;
112 }
113
114 static const char *__convert_disabled_code_to_str(const tethering_disabled_cause_e code)
115 {
116         static char str_buf[DISABLE_REASON_TEXT_LEN] = {0, };
117
118         switch (code) {
119         case TETHERING_DISABLED_BY_USB_DISCONNECTION:
120                 strncpy(str_buf, "disabled due to usb disconnection", sizeof(str_buf));
121                 break;
122
123         case TETHERING_DISABLED_BY_FLIGHT_MODE:
124                 strncpy(str_buf, "disabled due to flight mode on", sizeof(str_buf));
125                 break;
126
127         case TETHERING_DISABLED_BY_LOW_BATTERY:
128                 strncpy(str_buf, "disabled due to low battery", sizeof(str_buf));
129                 break;
130
131         case TETHERING_DISABLED_BY_NETWORK_CLOSE:
132                 strncpy(str_buf, "disabled due to pdp network close", sizeof(str_buf));
133                 break;
134
135         case TETHERING_DISABLED_BY_TIMEOUT:
136                 strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
137                 break;
138
139         case TETHERING_DISABLED_BY_OTHERS:
140                 strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
141                 break;
142
143         case TETHERING_DISABLED_BY_REQUEST:
144                 strncpy(str_buf, "disabled by my request", sizeof(str_buf));
145                 break;
146
147         case TETHERING_DISABLED_BY_WIFI_ON:
148                 strncpy(str_buf, "disabled by Wi-Fi station on", sizeof(str_buf));
149                 break;
150
151         case TETHERING_DISABLED_BY_BT_OFF:
152                 strncpy(str_buf, "disabled by bluetooth off", sizeof(str_buf));
153                 break;
154
155         default:
156                 strncpy(str_buf, "disabled by unknown reason", sizeof(str_buf));
157                 break;
158         }
159
160         return str_buf;
161 }
162
163 static void __register_cbs(tethering_h th, __tethering_cbs *cbs, void *user_data)
164 {
165         tethering_error_e ret = TETHERING_ERROR_NONE;
166
167         ret = tethering_set_enabled_cb(th, TETHERING_TYPE_ALL,
168                         cbs->enabled_cb, user_data);
169         if (__is_err(ret) == true)
170                 g_print("tethering_set_enabled_cb is failed\n");
171
172         ret = tethering_set_disabled_cb(th, TETHERING_TYPE_ALL,
173                         cbs->disabled_cb, user_data);
174         if (__is_err(ret) == true)
175                 g_print("tethering_set_disabled_cb is failed\n");
176
177         ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_ALL,
178                         cbs->changed_cb, user_data);
179         if (__is_err(ret) == true)
180                 g_print("tethering_set_connection_state_changed_cb is failed\n");
181
182         ret = tethering_wifi_set_security_type_changed_cb(th,
183                         cbs->security_type_changed_cb, user_data);
184         if (__is_err(ret) == true)
185                 g_print("tethering_wifi_set_security_type_changed_cb is failed\n");
186
187         ret = tethering_wifi_set_ssid_visibility_changed_cb(th,
188                         cbs->ssid_visibility_changed_cb, user_data);
189         if (__is_err(ret) == true)
190                 g_print("tethering_wifi_set_ssid_visibility_changed_cb is failed\n");
191
192         ret = tethering_wifi_set_passphrase_changed_cb(th,
193                         cbs->passphrase_changed_cb, user_data);
194         if (__is_err(ret) == true)
195                 g_print("tethering_wifi_set_passphrase_changed_cb is failed\n");
196
197         return;
198 }
199
200 static void __deregister_cbs(tethering_h th)
201 {
202         tethering_error_e ret = TETHERING_ERROR_NONE;
203
204         ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_ALL);
205         if (__is_err(ret) == true)
206                 g_print("tethering_unset_enabled_cb is failed\n");
207
208         ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_ALL);
209         if (__is_err(ret) == true)
210                 g_print("tethering_unset_disabled_cb is failed\n");
211
212         ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_ALL);
213         if (__is_err(ret) == true)
214                 g_print("tethering_unset_connection_state_changed_cb is failed\n");
215
216         ret = tethering_wifi_unset_security_type_changed_cb(th);
217         if (__is_err(ret) == true)
218                 g_print("tethering_wifi_unset_security_type_changed_cb is failed\n");
219
220         ret = tethering_wifi_unset_ssid_visibility_changed_cb(th);
221         if (__is_err(ret) == true)
222                 g_print("tethering_wifi_unset_ssid_visibility_changed_cb is failed\n");
223
224         ret = tethering_wifi_unset_passphrase_changed_cb(th);
225         if (__is_err(ret) == true)
226                 g_print("tethering_wifi_unset_passphrase_changed_cb is failed\n");
227
228         return;
229 }
230
231 /* Tethering callbacks */
232 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
233 {
234         if (__is_err(error)) {
235                 if (!is_requested)
236                         return;
237
238                 g_print("## %s is not enabled. error code[0x%X]\n",
239                                 __convert_tethering_type_to_str(type),
240                                 error);
241                 return;
242         }
243
244         if (is_requested)
245                 g_print("## %s is enabled successfully\n",
246                                 __convert_tethering_type_to_str(type));
247         else
248                 g_print("## %s is enabled by other app\n",
249                                 __convert_tethering_type_to_str(type));
250
251         return;
252 }
253
254 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
255 {
256         if (__is_err(error)) {
257                 if (code != TETHERING_DISABLED_BY_REQUEST)
258                         return;
259
260                 g_print("## %s is not disabled. error code[0x%X]\n",
261                                 __convert_tethering_type_to_str(type), error);
262                 return;
263         }
264
265         g_print("## %s is %s\n",
266                         __convert_tethering_type_to_str(type),
267                         __convert_disabled_code_to_str(code));
268
269         return;
270 }
271
272 static void __connection_state_changed_cb(tethering_client_h client, bool open, void *data)
273 {
274         tethering_client_h clone = NULL;
275         tethering_type_e type;
276         char *ip_address = NULL;
277         char *mac_address = NULL;
278         char *hostname = NULL;
279
280         tethering_client_clone(&clone, client);
281         if (clone == NULL) {
282                 g_print("tetheirng_client_clone is failed\n");
283                 return;
284         }
285
286         tethering_client_get_tethering_type(clone, &type);
287         tethering_client_get_ip_address(clone,
288                         TETHERING_ADDRESS_FAMILY_IPV4, &ip_address);
289         tethering_client_get_mac_address(clone, &mac_address);
290         tethering_client_get_name(clone, &hostname);
291
292         if (open) {
293                 g_print("## New station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
294                                 __convert_tethering_type_to_str(type),
295                                 ip_address, mac_address, hostname);
296         } else {
297                 g_print("## Disconnected station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
298                                 __convert_tethering_type_to_str(type),
299                                 ip_address, mac_address, hostname);
300         }
301
302         if (ip_address)
303                 free(ip_address);
304         if (mac_address)
305                 free(mac_address);
306         if (hostname)
307                 free(hostname);
308
309         tethering_client_destroy(clone);
310
311         return;
312 }
313
314 static void __data_usage_cb(tethering_error_e result, unsigned long long received_data,
315                 unsigned long long sent_data, void *user_data)
316 {
317         g_print("__data_usage_cb\n");
318
319         if (result != TETHERING_ERROR_NONE) {
320                 g_print("tethering_get_data_usage is failed. error[0x%X]\n", result);
321                 return;
322         }
323
324         g_print("## Received data : %llu bytes\n", received_data);
325         g_print("## Sent data : %llu bytes\n", sent_data);
326
327         return;
328 }
329
330 static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
331 {
332         g_print("__settings_reloaded_cb\n");
333
334         if (result != TETHERING_ERROR_NONE) {
335                 g_print("tethering_wifi_reload_settings is failed. error[0x%X]\n", result);
336                 return;
337         }
338
339         g_print("## Wi-Fi tethering setting is reloaded\n");
340
341         return;
342 }
343
344 static bool __clients_foreach_cb(tethering_client_h client, void *data)
345 {
346         tethering_client_h clone = NULL;
347         tethering_type_e type;
348         char *ip_address = NULL;
349         char *mac_address = NULL;
350         char *hostname = NULL;
351
352         /* Clone internal information */
353         if (tethering_client_clone(&clone, client) != TETHERING_ERROR_NONE) {
354                 g_print("tethering_client_clone is failed\n");
355                 return false;
356         }
357
358         /* Get information */
359         if (tethering_client_get_tethering_type(clone, &type) != TETHERING_ERROR_NONE)
360                 g_print("tethering_client_get_type is failed\n");
361
362         if (tethering_client_get_ip_address(clone, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address) != TETHERING_ERROR_NONE)
363                 g_print("tethering_client_get_ip_address is failed\n");
364
365         if (tethering_client_get_mac_address(clone, &mac_address) != TETHERING_ERROR_NONE)
366                 g_print("tethering_client_get_mac_address is failed\n");
367
368         if (tethering_client_get_name(clone, &hostname) != TETHERING_ERROR_NONE)
369                 g_print("tethering_client_get_hostname is failed\n");
370
371         /* End of getting information */
372
373         g_print("\n< Client Info. >\n");
374         g_print("\tType %s\n", __convert_tethering_type_to_str(type));
375         g_print("\tIP Address %s\n", ip_address);
376         g_print("\tMAC Address : %s\n", mac_address);
377         g_print("\tHostname : %s\n", hostname);
378
379         /* Destroy cloned objects */
380         if (ip_address)
381                 free(ip_address);
382         if (mac_address)
383                 free(mac_address);
384         if (hostname)
385                 free(hostname);
386
387         tethering_client_destroy(clone);
388
389         /* Continue iteration */
390         return true;
391 }
392
393 static void __security_type_changed_cb(tethering_wifi_security_type_e changed_type, void *user_data)
394 {
395
396         char *sec_str = NULL;
397
398         switch (changed_type) {
399         case TETHERING_WIFI_SECURITY_TYPE_NONE:
400                 sec_str = "open";
401                 break;
402         case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
403                 sec_str = "wpa2-psk";
404                 break;
405         case TETHERING_WIFI_SECURITY_TYPE_WPS:
406                 sec_str = "wps";
407                 break;
408         default:
409                 sec_str = "unknown";
410                 break;
411         }
412         g_print("Wi-Fi Tethering Security type is changed to [%s]\n", sec_str);
413
414         return;
415 }
416
417 static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
418 {
419         g_print("SSID visibility for Wi-Fi tethering changed to [%s]\n",
420                         changed_visible ? "visible" : "invisible");
421         return;
422 }
423
424 static void __passphrase_changed_cb(void *user_data)
425 {
426         g_print("Wi-Fi Tethering passphrase is changed\n");
427         return;
428 }
429 /* End of tethering callbacks */
430
431 static void __print_interface_info(tethering_h th, tethering_type_e type)
432 {
433         char *interface = NULL;
434         char *mac_address = NULL;
435         char *ip_address = NULL;
436         char *ip6_address = NULL;
437         char *gateway_address = NULL;
438         char *gateway6_address = NULL;
439         char *subnet_mask = NULL;
440         char *prefix = NULL;
441
442         if (tethering_is_enabled(th, type) == FALSE) {
443                 g_print("%s is not enabled\n",
444                                 __convert_tethering_type_to_str(type));
445                 return;
446         }
447
448         tethering_get_network_interface_name(th, type, &interface);
449         tethering_get_mac_address(th, type, &mac_address);
450         tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
451                         &ip_address);
452         tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV6,
453                         &ip6_address);
454         tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
455                         &gateway_address);
456         tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV6,
457                         &gateway6_address);
458         tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
459                         &subnet_mask);
460         tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV6,
461                         &prefix);
462
463         g_print("interface name : %s\n", interface);
464         g_print("mac address : %s\n", mac_address);
465         g_print("IPv4 address : %s\n", ip_address);
466         g_print("IPv6 address : %s\n", ip6_address);
467         g_print("gateway address: %s\n", gateway_address);
468         g_print("IPv6 gateway address: %s\n", gateway6_address);
469         g_print("subnet mask : %s\n", subnet_mask);
470         g_print("IPv6 prefix : %s\n", prefix);
471
472         if (interface)
473                 free(interface);
474         if (mac_address)
475                 free(mac_address);
476         if (ip_address)
477                 free(ip_address);
478         if (ip6_address)
479                 free(ip6_address);
480         if (gateway_address)
481                 free(gateway_address);
482         if (subnet_mask)
483                 free(subnet_mask);
484         if (gateway6_address)
485                 free(gateway6_address);
486         if (prefix)
487                 free(prefix);
488
489         return;
490 }
491
492 static void __print_wifi_tethering_setting(tethering_h th)
493 {
494         char *ssid = NULL;
495         char *passphrase = NULL;
496         char *sec_str = NULL;
497         bool visibility = false;
498         bool mac_filter = 0;
499         bool forwarding_enabled = false;
500         bool filtering_enabled = false;
501         int channel = 0;
502         int max_connected = 0;
503         tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
504         tethering_wifi_mode_type_e hw_mode = TETHERING_WIFI_MODE_TYPE_G;
505
506         int error = TETHERING_ERROR_NONE;
507
508         error = tethering_wifi_get_ssid(th, &ssid);
509         if (error != TETHERING_ERROR_NONE)
510                 __is_err(error);
511         else
512                 g_print("\n\t** WiFi tethering SSID : %s\n", ssid);
513
514         error = tethering_wifi_get_passphrase(th, &passphrase);
515         if (error != TETHERING_ERROR_NONE)
516                 __is_err(error);
517         else
518                 g_print("\t** WiFi tethering passphrase : %s\n", passphrase);
519
520         error = tethering_wifi_get_ssid_visibility(th, &visibility);
521         if (error != TETHERING_ERROR_NONE)
522                 __is_err(error);
523         else
524                 g_print("\t** WiFi tethering ssid visibility : %s\n",
525                                 visibility ? "visible" : "invisible");
526
527         error = tethering_wifi_get_security_type(th, &security_type);
528         if (error != TETHERING_ERROR_NONE)
529                 __is_err(error);
530         else {
531                 switch (security_type) {
532                 case TETHERING_WIFI_SECURITY_TYPE_NONE:
533                         sec_str = "open";
534                         break;
535                 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
536                         sec_str = "wpa2-psk";
537                         break;
538                 case TETHERING_WIFI_SECURITY_TYPE_WPS:
539                         sec_str = "wps";
540                         break;
541                 default:
542                         sec_str = "unknown";
543                         break;
544                 }
545                 g_print("\t** WiFi tethering security_type : %s\n", sec_str);
546         }
547
548         error = tethering_wifi_get_mode(th, &hw_mode);
549         if (error != TETHERING_ERROR_NONE)
550                 __is_err(error);
551         else
552                  g_print("\t** WiFi tethering mode : %d\n", hw_mode);
553
554         error = tethering_wifi_get_channel(th, &channel);
555         if (error != TETHERING_ERROR_NONE)
556                 __is_err(error);
557         else
558                  g_print("\t** WiFi tethering channel : %d\n", channel);
559
560         error = tethering_wifi_get_max_connected_device(th, &max_connected);
561         if (error != TETHERING_ERROR_NONE)
562                 __is_err(error);
563         else
564                  g_print("\t** WiFi tethering max connected device : %d\n", max_connected);
565
566         error = tethering_wifi_get_mac_filter(th, &mac_filter);
567         if (error != TETHERING_ERROR_NONE)
568                 __is_err(error);
569         else
570                 g_print("\t** WiFi tethering mac filter : %s\n",
571                                 mac_filter ? "enable" : "disable");
572
573         error = tethering_wifi_is_port_filtering_enabled(th, &filtering_enabled);
574         if (error != TETHERING_ERROR_NONE)
575                 __is_err(error);
576         else
577                 g_print("\t** WiFi tethering port filtering : %s\n",
578                                 filtering_enabled ? "enable" : "disable");
579
580         error = tethering_wifi_is_port_forwarding_enabled(th, &forwarding_enabled);
581         if (error != TETHERING_ERROR_NONE)
582                 __is_err(error);
583         else
584                 g_print("\t** WiFi tethering port forwarding : %s\n",
585                                 forwarding_enabled ? "enable" : "disable");
586
587         if (ssid)
588                 free(ssid);
589         if (passphrase)
590                 free(passphrase);
591
592         return;
593 }
594
595 void __display_list(GSList *list)
596 {
597         GSList *iterator = NULL;
598
599         for (iterator = list; iterator; iterator = iterator->next)
600                 printf("%s\n", (char*)iterator->data);
601 }
602
603 bool __get_tethering_type(tethering_type_e *type)
604 {
605         int sel;
606         int ret;
607
608         printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:ALL)\n");
609         ret = scanf("%9d", &sel);
610         if (ret < 0) {
611                 printf("scanf is failed!!\n");
612                 return false;
613         }
614
615         switch (sel) {
616         case 1:
617                 *type = TETHERING_TYPE_WIFI;
618                 break;
619         case 2:
620                 *type = TETHERING_TYPE_BT;
621                 break;
622         case 3:
623                 *type = TETHERING_TYPE_USB;
624                 break;
625         case 4:
626                 *type = TETHERING_TYPE_ALL;
627                 break;
628         default:
629                 printf("Invalid input!!\n");
630                 return false;
631         }
632
633         return true;
634 }
635
636 static int test_tethering_create(void)
637 {
638         int ret = tethering_create(&th);
639         __tethering_cbs cbs = {
640                 __enabled_cb, __disabled_cb,
641                 __connection_state_changed_cb, __security_type_changed_cb,
642                 __ssid_visibility_changed_cb, __passphrase_changed_cb};
643
644         if (__is_err(ret) == false) __register_cbs(th, &cbs, NULL);
645         else {
646                 printf("Tethering create is failed\n");
647                 return -1;
648         }
649         printf("Tethering create and register callback success\n");
650
651         return 1;
652 }
653
654 static int test_tethering_destroy(void)
655 {
656         int ret = TETHERING_ERROR_NONE;
657
658         __deregister_cbs(th);
659
660         ret = tethering_destroy(th);
661         if (__is_err(ret) == true) {
662                 printf("Tethering destroy is failed\n");
663                 return -1;
664         }
665
666         return 1;
667 }
668
669 static int test_tethering_enable(void)
670 {
671         int ret = TETHERING_ERROR_NONE;
672         tethering_type_e type;
673         int address_type = 0;
674
675         printf("IPv4: 0, IPv6: 1\n");
676         ret = scanf("%d", &address_type);
677
678         if (!__get_tethering_type(&type))
679                 return -1;
680
681         if (address_type)
682                 ret = tethering_ipv6_enable(th, type);
683         else
684                 ret = tethering_enable(th, type);
685
686         if (__is_err(ret) == true) {
687                 printf("Fail to enable tethering\n");
688                 return -1;
689         }
690         return 1;
691 }
692
693 static int test_tethering_disable(void)
694 {
695         int ret = TETHERING_ERROR_NONE;
696         tethering_type_e type;
697         int address_type = 0;
698
699         printf("IPv4: 0, IPv6: 1\n");
700         ret = scanf("%d", &address_type);
701
702         if (!__get_tethering_type(&type))
703                 return -1;
704
705         if (address_type)
706                 ret = tethering_ipv6_disable(th, type);
707         else
708                 ret = tethering_disable(th, type);
709
710         if (__is_err(ret) == true) {
711                 printf("Fail to disable tethering\n");
712                 return -1;
713         }
714         return 1;
715 }
716
717 static int test_tethering_get_client_info(void)
718 {
719         int ret;
720         tethering_type_e type;
721
722         if (!__get_tethering_type(&type))
723                 return -1;
724
725         ret = tethering_foreach_connected_clients(th, type,
726                                         __clients_foreach_cb, NULL);
727         if (__is_err(ret) == true) {
728                 printf("Fail to disable tethering\n");
729                 return -1;
730         }
731
732         return 1;
733 }
734
735 static int test_tethering_get_interface_info(void)
736 {
737         tethering_type_e type;
738
739         if (!__get_tethering_type(&type))
740                 return -1;
741
742         __print_interface_info(th, type);
743
744         return 1;
745 }
746
747 static int test_tethering_get_data_usage(void)
748 {
749         int ret = tethering_get_data_usage(th, __data_usage_cb, NULL);
750
751         if (__is_err(ret) == true) {
752                 printf("Fail to get data usage!!\n");
753                 return -1;
754         }
755
756         return 1;
757 }
758
759 static int test_tethering_wifi_get_setting(void)
760 {
761         __print_wifi_tethering_setting(th);
762         return 1;
763 }
764
765 static int test_tethering_wifi_set_ssid(void)
766 {
767         int ret;
768         char ssid[100];
769
770         printf("Input SSID for Wi-Fi tethering: ");
771         ret = scanf("%99s", ssid);
772         if (ret < 0) {
773                 printf("scanf is failed!!\n");
774                 return -1;
775         }
776
777         ret = tethering_wifi_set_ssid(th, ssid);
778         if (__is_err(ret) == true) {
779                 printf("Fail to set wifi ssid!!\n");
780                 return -1;
781         }
782
783         return 1;
784 }
785
786 static int test_tethering_wifi_set_security_type(void)
787 {
788         int ret;
789         int security_type;
790
791         printf("Input security type for Wi-Fi tethering (0:NONE, 1:WPA2_PSK, 2:WPS)");
792         ret = scanf("%9d", &security_type);
793         if (ret < 0) {
794                 printf("scanf is failed!!\n");
795                 return -1;
796         }
797
798         ret = tethering_wifi_set_security_type(th, security_type);
799         if (__is_err(ret) == true) {
800                 printf("Fail to set security type!!\n");
801                 return -1;
802         }
803
804         return 1;
805 }
806
807 int test_tethering_wifi_set_visibility(void)
808 {
809         int ret;
810         int visibility;
811
812         printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
813         ret = scanf("%9d", &visibility);
814         if (ret < 0) {
815                 printf("scanf is failed!!\n");
816                 return -1;
817         }
818
819         ret = tethering_wifi_set_ssid_visibility(th, visibility);
820         if (__is_err(ret) == true) {
821                 printf("Fail to set visibility!!\n");
822                 return -1;
823         }
824
825         return 1;
826 }
827
828 static int test_tethering_wifi_set_passphrase(void)
829 {
830         int ret;
831         char passphrase[100];
832
833         printf("Input passphrase for Wi-Fi tethering: ");
834         ret = scanf("%99s", passphrase);
835         if (ret < 0) {
836                 printf("scanf is failed!!\n");
837                 return -1;
838         }
839
840         ret = tethering_wifi_set_passphrase(th, passphrase);
841         if (__is_err(ret) == true) {
842                 printf("Fail to set passphrase!!\n");
843                 return -1;
844         }
845
846         return 1;
847 }
848
849 static int test_tethering_wifi_set_channel(void)
850 {
851         int ret;
852         int channel;
853
854         printf("Input channel for Wi-Fi tethering: ");
855         ret = scanf("%d", &channel);
856
857         ret = tethering_wifi_set_channel(th, channel);
858         if (__is_err(ret) == true) {
859                 printf("Fail to set channel!!\n");
860                 return -1;
861         }
862
863         return 1;
864 }
865
866 static int test_tethering_wifi_set_mode(void)
867 {
868         int ret;
869         int type;
870
871         printf("Input hw_mode for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
872         ret = scanf("%d", &type);
873
874         ret = tethering_wifi_set_mode(th, type);
875         if (__is_err(ret) == true) {
876                 printf("Fail to set mode!!\n");
877                 return -1;
878         }
879
880         return 1;
881 }
882
883 static int test_tethering_wifi_enable_dhcp(void)
884 {
885         int ret;
886         int enable;
887
888         printf("Input (0-Disable, 1-Enable): ");
889         ret = scanf("%d", &enable);
890
891         ret = tethering_wifi_enable_dhcp(th, enable);
892         if (__is_err(ret) == true) {
893                 printf("Fail to enable dhcp server!!\n");
894                 return -1;
895         }
896
897         return 1;
898 }
899
900 static int test_tethering_wifi_set_dhcp_range(void)
901 {
902         int ret;
903         char rangestart[16], rangestop[16];
904
905         printf("Input range (ex: 192.168.0.50 192.168.0.150): ");
906
907         ret = scanf("%15s %15s", rangestart, rangestop);
908
909         ret = tethering_wifi_set_dhcp_range(th, rangestart, rangestop);
910         if (__is_err(ret) == true) {
911                 printf("Fail to set dhcp range and enable dhcp server!!\n");
912                 return -1;
913         }
914
915         return 1;
916 }
917
918 static int test_tethering_wifi_is_dhcp_enabled(void)
919 {
920         int ret;
921         bool enabled;
922
923         ret = tethering_wifi_is_dhcp_enabled(th, &enabled);
924
925         if (__is_err(ret) == true) {
926                 printf("Fail to get dhcp server status!!\n");
927                 return -1;
928         } else {
929                 printf("DHCP server is %s\n", enabled ? "enabled" : "disabled");
930         }
931
932         return 1;
933 }
934
935 static int test_tethering_wifi_set_mac_filtering(void)
936 {
937         int ret;
938         int enable;
939
940         printf("Input mac filtering option (0: disable, 1: enable): ");
941         ret = scanf("%d", &enable);
942
943         ret = tethering_wifi_set_mac_filter(th, enable);
944         if (__is_err(ret) == true) {
945                 printf("Fail to set mac filtering!!\n");
946                 return -1;
947         }
948
949         return 1;
950 }
951
952 static int test_tethering_manage_mac_list(void)
953 {
954         int ret = 0;
955         int list, option;
956         char mac[100];
957
958         printf("Select MAC list to modify (0: allowed mac list, 1: blocked mac list): ");
959         ret = scanf("%d", &list);
960
961         printf("Select option (0: Add, 1: Remove): ");
962         ret = scanf("%d", &option);
963
964         printf("Input MAC Address to add/remove allowed/blocked mac list: ");
965         ret = scanf("%99s", mac);
966         if (ret < 0) {
967                 printf("scanf is failed!!\n");
968                 return -1;
969         }
970
971         if (!list && !option) {
972                 /* Add to allowed mac list*/
973                 ret = tethering_wifi_add_allowed_mac_list(th, mac);
974         } else if (!list && option) {
975                 /* Remove from allowed mac list */
976                 ret = tethering_wifi_remove_allowed_mac_list(th, mac);
977         } else if (list && !option) {
978                 /* Add to blocked mac list */
979                 ret = tethering_wifi_add_blocked_mac_list(th, mac);
980         } else if (list && option) {
981                 /* Remove from blocked mac list */
982                 ret = tethering_wifi_remove_blocked_mac_list(th, mac);
983         } else {
984                 printf("Input failed!!\n");
985                 return -1;
986         }
987
988         if (ret < 0)
989                 return -1;
990
991         return 1;
992 }
993
994 static int test_tethering_get_mac_list(void)
995 {
996         int ret = 0;
997         int list = 0;
998         void *mac_list = NULL;
999
1000         printf("Select MAC list to get (0: allowed mac list, 1: blocked mac list): ");
1001         ret = scanf("%d", &list);
1002
1003         switch (list) {
1004         case 0:
1005                 ret = tethering_wifi_get_allowed_mac_list(th, &mac_list);
1006                 break;
1007         case 1:
1008                 ret = tethering_wifi_get_blocked_mac_list(th, &mac_list);
1009                 break;
1010         default:
1011                 printf("Input failed!!\n");
1012                 break;
1013         }
1014
1015         if (ret < 0)
1016                 return -1;
1017
1018         __display_list(mac_list);
1019
1020         return 1;
1021 }
1022
1023 static int test_tethering_wifi_reload_settings(void)
1024 {
1025         int ret = tethering_wifi_reload_settings(th, __settings_reloaded_cb, NULL);
1026
1027         if (__is_err(ret) == true) {
1028                 printf("Fail to reload wifi tethering!!\n");
1029                 return -1;
1030         }
1031         return 1;
1032 }
1033
1034 static int test_tethering_wifi_get_txpower(void)
1035 {
1036         int ret = TETHERING_ERROR_NONE;
1037
1038         unsigned int txpower = 0;
1039         ret = tethering_wifi_get_txpower(th, &txpower);
1040         if (__is_err(ret) == true) {
1041                 printf("Fail to get txpower!!\n");
1042                 return -1;
1043         }
1044         g_print("tethering_hostapd_get_txpower received [%d]\n", txpower);
1045         return 1;
1046 }
1047
1048 static int test_tethering_wifi_set_txpower(void)
1049 {
1050         int ret;
1051         unsigned int txpower = 0;
1052
1053         printf("Input tx power for Wi-Fi tethering: ");
1054         ret = scanf("%d", &txpower);
1055
1056         ret = tethering_wifi_set_txpower(th, txpower);
1057         if (__is_err(ret) == true) {
1058                 printf("Fail to set txpower!!\n");
1059                 return -1;
1060         }
1061
1062         return 1;
1063 }
1064
1065 static int test_tethering_wifi_set_mtu(void)
1066 {
1067         int ret;
1068         unsigned int mtu = 0;
1069
1070         printf("Input mtu for Wi-Fi tethering: ");
1071         ret = scanf("%d", &mtu);
1072
1073         ret = tethering_wifi_set_mtu(th, mtu);
1074         if (__is_err(ret) == true) {
1075                 printf("Fail to set mtu!!\n");
1076                 return -1;
1077         }
1078
1079         return 1;
1080 }
1081
1082 static int test_tethering_wifi_change_mac(void)
1083 {
1084         int ret;
1085         char mac[18];
1086
1087         printf("Input mac address: ");
1088         ret = scanf("%17s", mac);
1089
1090         ret = tethering_wifi_change_mac(th, mac);
1091         if (__is_err(ret) == true) {
1092                 printf("Fail to change mac!\n");
1093                 return -1;
1094         }
1095
1096         return 1;
1097 }
1098
1099 static int test_tethering_wifi_set_max_connected_device(void)
1100 {
1101         int ret;
1102         int max_connected;
1103
1104         printf("Input max connected device: ");
1105         ret = scanf("%d", &max_connected);
1106
1107         ret = tethering_wifi_set_max_connected_device(th, max_connected);
1108         if (__is_err(ret) == true) {
1109                 printf("Fail to set max connected device!\n");
1110                 return -1;
1111         }
1112
1113         return 1;
1114
1115 }
1116
1117 static int test_tethering_wifi_enable_port_forwarding(void)
1118 {
1119         int ret;
1120         int enable = false;
1121
1122         printf("Wi-Fi tethring port forwarding(0:disable 1:enable): ");
1123         ret = scanf("%d", &enable);
1124
1125         ret = tethering_wifi_enable_port_forwarding(th, enable);
1126         if (__is_err(ret) == true) {
1127                 printf("Fail to enable port forwarding!\n");
1128                 return -1;
1129         }
1130
1131         return 1;
1132 }
1133
1134 static int test_tethering_wifi_add_port_forwarding_rule(void)
1135 {
1136         int ret;
1137         char ifname[20];
1138         char proto[20];
1139         char org_ip[16];
1140         char final_ip[16];
1141         int org_port, final_port;
1142
1143         printf("Input ifname, protocol, original ip/port, final ip/port: ");
1144         ret = scanf("%19s", ifname);
1145         ret = scanf("%19s", proto);
1146         ret = scanf("%15s", org_ip);
1147         ret = scanf("%d", &org_port);
1148         ret = scanf("%15s", final_ip);
1149         ret = scanf("%d", &final_port);
1150
1151         ret = tethering_wifi_add_port_forwarding_rule(th, ifname, proto, org_ip, org_port, final_ip, final_port);
1152         if (__is_err(ret) == true) {
1153                 printf("Fail to add port forwarding rule!\n");
1154                 return -1;
1155         }
1156
1157         return 1;
1158 }
1159
1160 static int test_tethering_wifi_reset_port_forwarding_rule(void)
1161 {
1162         int ret;
1163
1164         ret = tethering_wifi_reset_port_forwarding_rule(th);
1165         if (__is_err(ret) == true) {
1166                 printf("Fail to reset port forwarding rule!\n");
1167                 return -1;
1168         }
1169
1170         return 1;
1171 }
1172
1173 static int test_tethering_wifi_get_port_forwarding_rule(void)
1174 {
1175         int ret = 0;
1176         void *pf_list = NULL;
1177
1178         ret = tethering_wifi_get_port_forwarding_rule(th, &pf_list);
1179         if (__is_err(ret) == true) {
1180                 printf("Fail to get port forwarding rule!\n");
1181                 return -1;
1182         }
1183
1184         __display_list(pf_list);
1185
1186         return 1;
1187 }
1188
1189 static int test_tethering_wifi_enable_port_filtering(void)
1190 {
1191         int ret;
1192         int enable = false;
1193
1194         printf("Wi-Fi tethring port filtering(0:disable 1:enable): ");
1195         ret = scanf("%d", &enable);
1196
1197         ret = tethering_wifi_enable_port_filtering(th, enable);
1198         if (__is_err(ret) == true) {
1199                 printf("Fail to enable port filtering!\n");
1200                 return -1;
1201         }
1202
1203         return 1;
1204 }
1205
1206 static int test_tethering_wifi_add_port_filtering_rule(void)
1207 {
1208         int ret;
1209         char proto[20];
1210         int port;
1211         int allow;
1212
1213         printf("Input protocol, port, allow: ");
1214         ret = scanf("%19s", proto);
1215         ret = scanf("%d", &port);
1216         ret = scanf("%d", &allow);
1217
1218         ret = tethering_wifi_add_port_filtering_rule(th, port, proto, allow);
1219         if (__is_err(ret) == true) {
1220                 printf("Fail to add port forwarding rule!\n");
1221                 return -1;
1222         }
1223
1224         return 1;
1225 }
1226
1227 static int test_tethering_wifi_add_custom_port_filtering_rule(void)
1228 {
1229         int ret;
1230         char proto[20];
1231         int port1, port2;
1232         int allow;
1233
1234         printf("Input protocol, port1, port2, allow: ");
1235         ret = scanf("%19s", proto);
1236         ret = scanf("%d", &port1);
1237         ret = scanf("%d", &port2);
1238         ret = scanf("%d", &allow);
1239
1240         ret = tethering_wifi_add_custom_port_filtering_rule(th, port1, port2, proto, allow);
1241         if (__is_err(ret) == true) {
1242                 printf("Fail to add custom port forwarding rule!\n");
1243                 return -1;
1244         }
1245
1246         return 1;
1247 }
1248
1249 static int test_tethering_wifi_get_port_filtering_rule(void)
1250 {
1251         int ret = 0;
1252         void *pf_list = NULL;
1253
1254         ret = tethering_wifi_get_port_filtering_rule(th, &pf_list);
1255         if (__is_err(ret) == true) {
1256                 printf("Fail to get port filtering rule!\n");
1257                 return -1;
1258         }
1259
1260         __display_list(pf_list);
1261
1262         return 1;
1263 }
1264
1265 static int test_tethering_wifi_get_custom_port_filtering_rule(void)
1266 {
1267         int ret = 0;
1268         void *pf_list = NULL;
1269
1270         ret = tethering_wifi_get_custom_port_filtering_rule(th, &pf_list);
1271         if (__is_err(ret) == true) {
1272                 printf("Fail to get port filtering rule!\n");
1273                 return -1;
1274         }
1275
1276         __display_list(pf_list);
1277
1278         return 1;
1279 }
1280
1281 static int test_tethering_wifi_set_vpn_passthrough_rule(void)
1282 {
1283         int ret = 0;
1284         int type;
1285
1286         printf("Select vpn passthrough type (0:IPSEC 1:PPTP 2:L2TP): ");
1287         ret = scanf("%d", &type);
1288
1289         ret = tethering_wifi_set_vpn_passthrough_rule(th, (tethering_vpn_passthrough_type_e)type, true);
1290         if (__is_err(ret) == true) {
1291                 printf("Fail to get port filtering rule!\n");
1292                 return -1;
1293         }
1294
1295         return 1;
1296 }
1297
1298 static int test_tethering_wifi_push_wps_button(void)
1299 {
1300         int ret = 0;
1301
1302         ret = tethering_wifi_push_wps_button(th);
1303         if (__is_err(ret) == true) {
1304                 printf("Fail to get port filtering rule!\n");
1305                 return -1;
1306         }
1307
1308         return 1;
1309 }
1310
1311 static int test_tethering_wifi_set_wps_pin(void)
1312 {
1313         int ret = 0;
1314         char wps_pin[128];
1315
1316         printf("Input WPS PIN: ");
1317         ret = scanf("%127s", wps_pin);
1318
1319         ret = tethering_wifi_set_wps_pin(th, wps_pin);
1320         if (__is_err(ret) == true) {
1321                 printf("Fail to get port filtering rule!\n");
1322                 return -1;
1323         }
1324
1325         return 1;
1326 }
1327
1328 int main(int argc, char **argv)
1329 {
1330         GMainLoop *mainloop;
1331
1332 #if !GLIB_CHECK_VERSION(2, 36, 0)
1333         g_type_init();
1334 #endif
1335         mainloop = g_main_loop_new(NULL, false);
1336
1337         GIOChannel *channel = g_io_channel_unix_new(0);
1338         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1339         printf("Test Thread created...\n");
1340         g_main_loop_run(mainloop);
1341
1342         return 0;
1343 }
1344
1345 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1346 {
1347         int rv;
1348         char a[10];
1349
1350         printf("Event received from stdin\n");
1351
1352         rv = read(0, a, 10);
1353
1354         if (rv <= 0 || a[0] == '0')
1355                 exit(1);
1356
1357         if (a[0] == '\n' || a[0] == '\r') {
1358                 printf("\n\n Network Connection API Test App\n\n");
1359                 printf("Options..\n");
1360                 printf("1       - Tethering create and set callbacks\n");
1361                 printf("2       - Tethering destroy\n");
1362                 printf("3       - Enable Tethering\n");
1363                 printf("4       - Disable Tethering\n");
1364                 printf("5       - Get client information\n");
1365                 printf("6       - Get interface information\n");
1366                 printf("7       - Get data usage\n");
1367                 printf("8       - Get Wi-Fi tethering setting\n");
1368                 printf("a       - Set Wi-Fi tethering SSID\n");
1369                 printf("b       - Set Wi-Fi tethering security type\n");
1370                 printf("c       - Set Wi-Fi tethering visibility\n");
1371                 printf("d       - Set Wi-Fi tethering passphrase\n");
1372                 printf("e       - Set Wi-Fi tethering mac filtering\n");
1373                 printf("f       - Add/Remove MAC adress to/from allowed/blocked list\n");
1374                 printf("g       - Get allowed/blocked list\n");
1375                 printf("k       - Reload Wi-Fi tethering\n");
1376                 printf("m       - Set Wi-Fi channel\n");
1377                 printf("n       - Set Wi-Fi hw_mode\n");
1378                 printf("o       - Enable dhcp server\n");
1379                 printf("p       - Enable dhcp server with range\n");
1380                 printf("q       - Is dhcp server enabled?\n");
1381                 printf("r       - Get Wi-Fi txpower\n");
1382                 printf("s       - Set Wi-Fi txpower\n");
1383                 printf("t       - Set Wi-Fi mtu\n");
1384                 printf("u       - Change mac address\n");
1385                 printf("v       - Set max connected device(Wi-Fi tethering)\n");
1386                 printf("w       - Enable port forwarding\n");
1387                 printf("x       - Add port forwarding rule\n");
1388                 printf("y       - Reset port forwarding rule\n");
1389                 printf("z       - Get port forwarding rule\n");
1390                 printf("A       - Enable port filtering\n");
1391                 printf("B       - Add port filtering rule\n");
1392                 printf("C       - Add custom port filtering rule\n");
1393                 printf("D       - Get port filtering rule\n");
1394                 printf("E       - Get custom port filtering rule\n");
1395                 printf("F       - Set vpn passthrough rule\n");
1396                 printf("G       - Push WPS button\n");
1397                 printf("H       - Set WPS PIN\n");
1398                 printf("0       - \n");
1399                 printf("ENTER  - Show options menu.......\n");
1400         }
1401
1402         switch (a[0]) {
1403         case '1':
1404                 rv = test_tethering_create();
1405                 break;
1406         case '2':
1407                 rv = test_tethering_destroy();
1408                 break;
1409         case '3':
1410                 rv = test_tethering_enable();
1411                 break;
1412         case '4':
1413                 rv = test_tethering_disable();
1414                 break;
1415         case '5':
1416                 rv = test_tethering_get_client_info();
1417                 break;
1418         case '6':
1419                 rv = test_tethering_get_interface_info();
1420                 break;
1421         case '7':
1422                 rv = test_tethering_get_data_usage();
1423                 break;
1424         case '8':
1425                 rv = test_tethering_wifi_get_setting();
1426                 break;
1427         case 'a':
1428                 rv = test_tethering_wifi_set_ssid();
1429                 break;
1430         case 'b':
1431                 rv = test_tethering_wifi_set_security_type();
1432                 break;
1433         case 'c':
1434                 rv = test_tethering_wifi_set_visibility();
1435                 break;
1436         case 'd':
1437                 rv = test_tethering_wifi_set_passphrase();
1438                 break;
1439         case 'e':
1440                 rv = test_tethering_wifi_set_mac_filtering();
1441                 break;
1442         case 'f':
1443                 rv = test_tethering_manage_mac_list();
1444                 break;
1445         case 'g':
1446                 rv = test_tethering_get_mac_list();
1447                 break;
1448         case 'k':
1449                 rv = test_tethering_wifi_reload_settings();
1450                 break;
1451         case 'm':
1452                 rv = test_tethering_wifi_set_channel();
1453                 break;
1454         case 'n':
1455                 rv = test_tethering_wifi_set_mode();
1456                 break;
1457         case 'o':
1458                 rv = test_tethering_wifi_enable_dhcp();
1459                 break;
1460         case 'p':
1461                 rv = test_tethering_wifi_set_dhcp_range();
1462                 break;
1463         case 'q':
1464                 rv = test_tethering_wifi_is_dhcp_enabled();
1465                 break;
1466         case 'r':
1467                 rv = test_tethering_wifi_get_txpower();
1468                 break;
1469         case 's':
1470                 rv = test_tethering_wifi_set_txpower();
1471                 break;
1472         case 't':
1473                 rv = test_tethering_wifi_set_mtu();
1474                 break;
1475         case 'u':
1476                 rv = test_tethering_wifi_change_mac();
1477                 break;
1478         case 'v':
1479                 rv = test_tethering_wifi_set_max_connected_device();
1480                 break;
1481         case 'w':
1482                 rv = test_tethering_wifi_enable_port_forwarding();
1483                 break;
1484         case 'x':
1485                 rv = test_tethering_wifi_add_port_forwarding_rule();
1486                 break;
1487         case 'y':
1488                 rv = test_tethering_wifi_reset_port_forwarding_rule();
1489                 break;
1490         case 'z':
1491                 rv = test_tethering_wifi_get_port_forwarding_rule();
1492                 break;
1493         case 'A':
1494                 rv = test_tethering_wifi_enable_port_filtering();
1495                 break;
1496         case 'B':
1497                 rv = test_tethering_wifi_add_port_filtering_rule();
1498                 break;
1499         case 'C':
1500                 rv = test_tethering_wifi_add_custom_port_filtering_rule();
1501                 break;
1502         case 'D':
1503                 rv = test_tethering_wifi_get_port_filtering_rule();
1504                 break;
1505         case 'E':
1506                 rv = test_tethering_wifi_get_custom_port_filtering_rule();
1507                 break;
1508         case 'F':
1509                 rv = test_tethering_wifi_set_vpn_passthrough_rule();
1510                 break;
1511         case 'G':
1512                 rv = test_tethering_wifi_push_wps_button();
1513                 break;
1514         case 'H':
1515                 rv = test_tethering_wifi_set_wps_pin();
1516                 break;
1517         }
1518
1519         if (rv == 1)
1520                 printf("Operation succeeded!\n");
1521         else
1522                 printf("Operation failed!\n");
1523
1524         return true;
1525 }