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