Fix memory leak
[platform/core/api/tethering.git] / tools / 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 bool test_get_user_string(const char *msg, char *buf, int buf_size)
94 {
95         if (msg == NULL || buf == NULL || buf_size < 2)
96                 return false;
97
98         int rv;
99         printf("%s\n", msg);
100         memset(buf, 0, buf_size);
101         rv = read(0, buf, buf_size - 1);
102
103         if (rv < 0 || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r') {
104                 buf[0] = '\0';
105                 return false;
106         }
107
108         buf[rv-1] = '\0';
109         return true;
110 }
111
112 static const char *__convert_tethering_type_to_str(const tethering_type_e type)
113 {
114         static char str_buf[COMMON_STR_BUF_LEN] = {0, };
115
116         switch (type) {
117         case TETHERING_TYPE_USB:
118                 g_strlcpy(str_buf, "USB Tethering", sizeof(str_buf));
119                 break;
120
121         case TETHERING_TYPE_WIFI:
122                 g_strlcpy(str_buf, "Wi-Fi Tethering", sizeof(str_buf));
123                 break;
124
125         case TETHERING_TYPE_BT:
126                 g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf));
127                 break;
128
129         case TETHERING_TYPE_P2P:
130                 g_strlcpy(str_buf, "P2P Tethering", sizeof(str_buf));
131                 break;
132
133         default:
134                 g_strlcpy(str_buf, "Unknown", sizeof(str_buf));
135                 break;
136         }
137
138         return str_buf;
139 }
140
141 static const char *__convert_disabled_code_to_str(const tethering_disabled_cause_e code)
142 {
143         static char str_buf[DISABLE_REASON_TEXT_LEN] = {0, };
144
145         switch (code) {
146         case TETHERING_DISABLED_BY_USB_DISCONNECTION:
147                 strncpy(str_buf, "disabled due to usb disconnection", sizeof(str_buf));
148                 break;
149
150         case TETHERING_DISABLED_BY_FLIGHT_MODE:
151                 strncpy(str_buf, "disabled due to flight mode on", sizeof(str_buf));
152                 break;
153
154         case TETHERING_DISABLED_BY_LOW_BATTERY:
155                 strncpy(str_buf, "disabled due to low battery", sizeof(str_buf));
156                 break;
157
158         case TETHERING_DISABLED_BY_NETWORK_CLOSE:
159                 strncpy(str_buf, "disabled due to pdp network close", sizeof(str_buf));
160                 break;
161
162         case TETHERING_DISABLED_BY_TIMEOUT:
163                 strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
164                 break;
165
166         case TETHERING_DISABLED_BY_OTHERS:
167                 strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
168                 break;
169
170         case TETHERING_DISABLED_BY_REQUEST:
171                 strncpy(str_buf, "disabled by my request", sizeof(str_buf));
172                 break;
173
174         case TETHERING_DISABLED_BY_WIFI_ON:
175                 strncpy(str_buf, "disabled by Wi-Fi station on", sizeof(str_buf));
176                 break;
177
178         case TETHERING_DISABLED_BY_BT_OFF:
179                 strncpy(str_buf, "disabled by bluetooth off", sizeof(str_buf));
180                 break;
181
182         default:
183                 strncpy(str_buf, "disabled by unknown reason", sizeof(str_buf));
184                 break;
185         }
186
187         return str_buf;
188 }
189
190 static void __register_cbs(tethering_h th, __tethering_cbs *cbs, void *user_data)
191 {
192         tethering_error_e ret = TETHERING_ERROR_NONE;
193
194         ret = tethering_set_enabled_cb(th, TETHERING_TYPE_ALL,
195                         cbs->enabled_cb, user_data);
196         if (__is_err(ret) == true)
197                 g_print("tethering_set_enabled_cb is failed\n");
198
199         ret = tethering_set_disabled_cb(th, TETHERING_TYPE_ALL,
200                         cbs->disabled_cb, user_data);
201         if (__is_err(ret) == true)
202                 g_print("tethering_set_disabled_cb is failed\n");
203
204         ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_ALL,
205                         cbs->changed_cb, user_data);
206         if (__is_err(ret) == true)
207                 g_print("tethering_set_connection_state_changed_cb is failed\n");
208
209         ret = tethering_wifi_set_security_type_changed_cb(th,
210                         cbs->security_type_changed_cb, user_data);
211         if (__is_err(ret) == true)
212                 g_print("tethering_wifi_set_security_type_changed_cb is failed\n");
213
214         ret = tethering_wifi_set_ssid_visibility_changed_cb(th,
215                         cbs->ssid_visibility_changed_cb, user_data);
216         if (__is_err(ret) == true)
217                 g_print("tethering_wifi_set_ssid_visibility_changed_cb is failed\n");
218
219         ret = tethering_wifi_set_passphrase_changed_cb(th,
220                         cbs->passphrase_changed_cb, user_data);
221         if (__is_err(ret) == true)
222                 g_print("tethering_wifi_set_passphrase_changed_cb is failed\n");
223
224         return;
225 }
226
227 static void __deregister_cbs(tethering_h th)
228 {
229         tethering_error_e ret = TETHERING_ERROR_NONE;
230
231         ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_ALL);
232         if (__is_err(ret) == true)
233                 g_print("tethering_unset_enabled_cb is failed\n");
234
235         ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_ALL);
236         if (__is_err(ret) == true)
237                 g_print("tethering_unset_disabled_cb is failed\n");
238
239         ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_ALL);
240         if (__is_err(ret) == true)
241                 g_print("tethering_unset_connection_state_changed_cb is failed\n");
242
243         ret = tethering_wifi_unset_security_type_changed_cb(th);
244         if (__is_err(ret) == true)
245                 g_print("tethering_wifi_unset_security_type_changed_cb is failed\n");
246
247         ret = tethering_wifi_unset_ssid_visibility_changed_cb(th);
248         if (__is_err(ret) == true)
249                 g_print("tethering_wifi_unset_ssid_visibility_changed_cb is failed\n");
250
251         ret = tethering_wifi_unset_passphrase_changed_cb(th);
252         if (__is_err(ret) == true)
253                 g_print("tethering_wifi_unset_passphrase_changed_cb is failed\n");
254
255         return;
256 }
257
258 /* Tethering callbacks */
259 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
260 {
261         if (__is_err(error)) {
262                 if (!is_requested)
263                         return;
264
265                 g_print("## %s is not enabled. error code[0x%X]\n",
266                                 __convert_tethering_type_to_str(type),
267                                 error);
268                 return;
269         }
270
271         if (is_requested)
272                 g_print("## %s is enabled successfully\n",
273                                 __convert_tethering_type_to_str(type));
274         else
275                 g_print("## %s is enabled by other app\n",
276                                 __convert_tethering_type_to_str(type));
277
278         return;
279 }
280
281 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
282 {
283         if (__is_err(error)) {
284                 if (code != TETHERING_DISABLED_BY_REQUEST)
285                         return;
286
287                 g_print("## %s is not disabled. error code[0x%X]\n",
288                                 __convert_tethering_type_to_str(type), error);
289                 return;
290         }
291
292         g_print("## %s is %s\n",
293                         __convert_tethering_type_to_str(type),
294                         __convert_disabled_code_to_str(code));
295
296         return;
297 }
298
299 static void __connection_state_changed_cb(tethering_client_h client, bool open, void *data)
300 {
301         tethering_client_h clone = NULL;
302         tethering_type_e type;
303         char *ip_address = NULL;
304         char *mac_address = NULL;
305         char *hostname = NULL;
306
307         tethering_client_clone(&clone, client);
308         if (clone == NULL) {
309                 g_print("tetheirng_client_clone is failed\n");
310                 return;
311         }
312
313         tethering_client_get_tethering_type(clone, &type);
314         tethering_client_get_ip_address(clone,
315                         TETHERING_ADDRESS_FAMILY_IPV4, &ip_address);
316         tethering_client_get_mac_address(clone, &mac_address);
317         tethering_client_get_name(clone, &hostname);
318
319         if (open) {
320                 g_print("## New station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
321                                 __convert_tethering_type_to_str(type),
322                                 ip_address, mac_address, hostname);
323         } else {
324                 g_print("## Disconnected station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
325                                 __convert_tethering_type_to_str(type),
326                                 ip_address, mac_address, hostname);
327         }
328
329         if (ip_address)
330                 free(ip_address);
331         if (mac_address)
332                 free(mac_address);
333         if (hostname)
334                 free(hostname);
335
336         tethering_client_destroy(clone);
337
338         return;
339 }
340
341 static void __data_usage_cb(tethering_error_e result, unsigned long long received_data,
342                 unsigned long long sent_data, void *user_data)
343 {
344         g_print("__data_usage_cb\n");
345
346         if (result != TETHERING_ERROR_NONE) {
347                 g_print("tethering_get_data_usage is failed. error[0x%X]\n", result);
348                 return;
349         }
350
351         g_print("## Received data : %llu bytes\n", received_data);
352         g_print("## Sent data : %llu bytes\n", sent_data);
353
354         return;
355 }
356
357 static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
358 {
359         g_print("__settings_reloaded_cb\n");
360
361         if (result != TETHERING_ERROR_NONE) {
362                 g_print("tethering_wifi_reload_settings is failed. error[0x%X]\n", result);
363                 return;
364         }
365
366         g_print("## Wi-Fi tethering setting is reloaded\n");
367
368         return;
369 }
370
371 static bool __clients_foreach_cb(tethering_client_h client, void *data)
372 {
373         tethering_client_h clone = NULL;
374         tethering_type_e type;
375         char *ip_address = NULL;
376         char *mac_address = NULL;
377         char *hostname = NULL;
378
379         /* Clone internal information */
380         if (tethering_client_clone(&clone, client) != TETHERING_ERROR_NONE) {
381                 g_print("tethering_client_clone is failed\n");
382                 return false;
383         }
384
385         /* Get information */
386         if (tethering_client_get_tethering_type(clone, &type) != TETHERING_ERROR_NONE)
387                 g_print("tethering_client_get_type is failed\n");
388
389         if (tethering_client_get_ip_address(clone, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address) != TETHERING_ERROR_NONE)
390                 g_print("tethering_client_get_ip_address is failed\n");
391
392         if (tethering_client_get_mac_address(clone, &mac_address) != TETHERING_ERROR_NONE)
393                 g_print("tethering_client_get_mac_address is failed\n");
394
395         if (tethering_client_get_name(clone, &hostname) != TETHERING_ERROR_NONE)
396                 g_print("tethering_client_get_hostname is failed\n");
397
398         /* End of getting information */
399
400         g_print("\n< Client Info. >\n");
401         g_print("\tType %s\n", __convert_tethering_type_to_str(type));
402         g_print("\tIP Address %s\n", ip_address);
403         g_print("\tMAC Address : %s\n", mac_address);
404         g_print("\tHostname : %s\n", hostname);
405
406         /* Destroy cloned objects */
407         if (ip_address)
408                 free(ip_address);
409         if (mac_address)
410                 free(mac_address);
411         if (hostname)
412                 free(hostname);
413
414         tethering_client_destroy(clone);
415
416         /* Continue iteration */
417         return true;
418 }
419
420 static void __security_type_changed_cb(tethering_wifi_security_type_e changed_type, void *user_data)
421 {
422
423         char *sec_str = NULL;
424
425         switch (changed_type) {
426         case TETHERING_WIFI_SECURITY_TYPE_NONE:
427                 sec_str = "open";
428                 break;
429         case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
430                 sec_str = "wpa2-psk";
431                 break;
432         case TETHERING_WIFI_SECURITY_TYPE_WPS:
433                 sec_str = "wps";
434                 break;
435         case TETHERING_WIFI_SECURITY_TYPE_SAE:
436                 sec_str = "sae";
437                 break;
438         default:
439                 sec_str = "unknown";
440                 break;
441         }
442         g_print("Wi-Fi Tethering Security type is changed to [%s]\n", sec_str);
443
444         return;
445 }
446
447 static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
448 {
449         g_print("SSID visibility for Wi-Fi tethering changed to [%s]\n",
450                         changed_visible ? "visible" : "invisible");
451         return;
452 }
453
454 static void __passphrase_changed_cb(void *user_data)
455 {
456         g_print("Wi-Fi Tethering passphrase is changed\n");
457         return;
458 }
459 /* End of tethering callbacks */
460
461 static void __print_interface_info(tethering_h th, tethering_type_e type)
462 {
463         char *interface = NULL;
464         char *mac_address = NULL;
465         char *ip_address = NULL;
466         char *ip6_address = NULL;
467         char *gateway_address = NULL;
468         char *gateway6_address = NULL;
469         char *subnet_mask = NULL;
470         char *prefix = NULL;
471
472         if (tethering_is_enabled(th, type) == FALSE) {
473                 g_print("%s is not enabled\n",
474                                 __convert_tethering_type_to_str(type));
475                 return;
476         }
477
478         tethering_get_network_interface_name(th, type, &interface);
479         tethering_get_mac_address(th, type, &mac_address);
480         tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
481                         &ip_address);
482         tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV6,
483                         &ip6_address);
484         tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
485                         &gateway_address);
486         tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV6,
487                         &gateway6_address);
488         tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
489                         &subnet_mask);
490         tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV6,
491                         &prefix);
492
493         g_print("interface name : %s\n", interface);
494         g_print("mac address : %s\n", mac_address);
495         g_print("IPv4 address : %s\n", ip_address);
496         g_print("IPv6 address : %s\n", ip6_address);
497         g_print("gateway address: %s\n", gateway_address);
498         g_print("IPv6 gateway address: %s\n", gateway6_address);
499         g_print("subnet mask : %s\n", subnet_mask);
500         g_print("IPv6 prefix : %s\n", prefix);
501
502         if (interface)
503                 free(interface);
504         if (mac_address)
505                 free(mac_address);
506         if (ip_address)
507                 free(ip_address);
508         if (ip6_address)
509                 free(ip6_address);
510         if (gateway_address)
511                 free(gateway_address);
512         if (subnet_mask)
513                 free(subnet_mask);
514         if (gateway6_address)
515                 free(gateway6_address);
516         if (prefix)
517                 free(prefix);
518
519         return;
520 }
521
522 static void __print_wifi_tethering_setting(tethering_h th)
523 {
524         char *ssid = NULL;
525         char *passphrase = NULL;
526         char *sec_str = NULL;
527         bool visibility = false;
528         bool mac_filter = 0;
529         bool forwarding_enabled = false;
530         bool filtering_enabled = false;
531         int channel = 0;
532         int max_connected = 0;
533         tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
534         tethering_wifi_mode_type_e hw_mode = TETHERING_WIFI_MODE_TYPE_G;
535
536         int error = TETHERING_ERROR_NONE;
537
538         error = tethering_wifi_get_ssid(th, &ssid);
539         if (error == TETHERING_ERROR_NONE)
540                 g_print("\n\t** WiFi tethering SSID : %s\n", ssid);
541
542         error = tethering_wifi_get_passphrase(th, &passphrase);
543         if (error == TETHERING_ERROR_NONE)
544                 g_print("\t** WiFi tethering passphrase : %s\n", passphrase);
545
546         error = tethering_wifi_get_ssid_visibility(th, &visibility);
547         if (error == TETHERING_ERROR_NONE)
548                 g_print("\t** WiFi tethering ssid visibility : %s\n",
549                                 visibility ? "visible" : "invisible");
550
551         error = tethering_wifi_get_security_type(th, &security_type);
552         if (error == TETHERING_ERROR_NONE) {
553                 switch (security_type) {
554                 case TETHERING_WIFI_SECURITY_TYPE_NONE:
555                         sec_str = "open";
556                         break;
557                 case TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK:
558                         sec_str = "wpa2-psk";
559                         break;
560                 case TETHERING_WIFI_SECURITY_TYPE_WPS:
561                         sec_str = "wps";
562                         break;
563                 case TETHERING_WIFI_SECURITY_TYPE_SAE:
564                         sec_str = "sae";
565                         break;
566                 default:
567                         sec_str = "unknown";
568                         break;
569                 }
570                 g_print("\t** WiFi tethering security_type : %s\n", sec_str);
571         }
572
573         error = tethering_wifi_get_mode(th, &hw_mode);
574         if (error == TETHERING_ERROR_NONE)
575                  g_print("\t** WiFi tethering mode : %d\n", hw_mode);
576
577         error = tethering_wifi_get_channel(th, &channel);
578         if (error == TETHERING_ERROR_NONE)
579                  g_print("\t** WiFi tethering channel : %d\n", channel);
580
581         error = tethering_wifi_get_max_connected_device(th, &max_connected);
582         if (error == TETHERING_ERROR_NONE)
583                  g_print("\t** WiFi tethering max connected device : %d\n", max_connected);
584
585         error = tethering_wifi_get_mac_filter(th, &mac_filter);
586         if (error == TETHERING_ERROR_NONE)
587                 g_print("\t** WiFi tethering mac filter : %s\n",
588                                 mac_filter ? "enable" : "disable");
589
590         error = tethering_wifi_is_port_filtering_enabled(th, &filtering_enabled);
591         if (error == TETHERING_ERROR_NONE)
592                 g_print("\t** WiFi tethering port filtering : %s\n",
593                                 filtering_enabled ? "enable" : "disable");
594
595         error = tethering_wifi_is_port_forwarding_enabled(th, &forwarding_enabled);
596         if (error == TETHERING_ERROR_NONE)
597                 g_print("\t** WiFi tethering port forwarding : %s\n",
598                                 forwarding_enabled ? "enable" : "disable");
599
600         if (ssid)
601                 free(ssid);
602         if (passphrase)
603                 free(passphrase);
604
605         return;
606 }
607
608 void __display_list(GSList *list)
609 {
610         GSList *iterator = NULL;
611
612         for (iterator = list; iterator; iterator = iterator->next)
613                 printf("%s\n", (char*)iterator->data);
614 }
615
616 bool __get_tethering_type(tethering_type_e *type)
617 {
618         int sel;
619         int ret;
620
621         printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:P2P 5:ALL)\n");
622         ret = scanf("%9d", &sel);
623         if (ret < 0) {
624                 printf("scanf is failed!!\n");
625                 return false;
626         }
627
628         switch (sel) {
629         case 1:
630                 *type = TETHERING_TYPE_WIFI;
631                 break;
632         case 2:
633                 *type = TETHERING_TYPE_BT;
634                 break;
635         case 3:
636                 *type = TETHERING_TYPE_USB;
637                 break;
638         case 4:
639                 *type = TETHERING_TYPE_P2P;
640                 break;
641         case 5:
642                 *type = TETHERING_TYPE_ALL;
643                 break;
644         default:
645                 printf("Invalid input!!\n");
646                 return false;
647         }
648
649         return true;
650 }
651
652 static int test_tethering_create(void)
653 {
654         int ret = tethering_create(&th);
655         __tethering_cbs cbs = {
656                 __enabled_cb, __disabled_cb,
657                 __connection_state_changed_cb, __security_type_changed_cb,
658                 __ssid_visibility_changed_cb, __passphrase_changed_cb};
659
660         if (__is_err(ret) == false) __register_cbs(th, &cbs, NULL);
661         else {
662                 printf("Tethering create is failed\n");
663                 return -1;
664         }
665         printf("Tethering create and register callback success\n");
666
667         return 1;
668 }
669
670 static int test_tethering_destroy(void)
671 {
672         int ret = TETHERING_ERROR_NONE;
673
674         __deregister_cbs(th);
675
676         ret = tethering_destroy(th);
677         if (__is_err(ret) == true) {
678                 printf("Tethering destroy is failed\n");
679                 return -1;
680         }
681
682         return 1;
683 }
684
685 static int test_tethering_enable(void)
686 {
687         int ret = TETHERING_ERROR_NONE;
688         tethering_type_e type;
689         int address_type = 0;
690
691         printf("IPv4: 0, IPv6: 1\n");
692         ret = scanf("%d", &address_type);
693
694         if (!__get_tethering_type(&type))
695                 return -1;
696
697         if (address_type)
698                 ret = tethering_ipv6_enable(th, type);
699         else
700                 ret = tethering_enable(th, type);
701
702         if (__is_err(ret) == true) {
703                 printf("Fail to enable tethering\n");
704                 return -1;
705         }
706         return 1;
707 }
708
709 static int test_tethering_disable(void)
710 {
711         int ret = TETHERING_ERROR_NONE;
712         tethering_type_e type;
713         int address_type = 0;
714
715         printf("IPv4: 0, IPv6: 1\n");
716         ret = scanf("%d", &address_type);
717
718         if (!__get_tethering_type(&type))
719                 return -1;
720
721         if (address_type)
722                 ret = tethering_ipv6_disable(th, type);
723         else
724                 ret = tethering_disable(th, type);
725
726         if (__is_err(ret) == true) {
727                 printf("Fail to disable tethering\n");
728                 return -1;
729         }
730         return 1;
731 }
732
733 static int test_tethering_get_client_info(void)
734 {
735         int ret;
736         tethering_type_e type;
737
738         if (!__get_tethering_type(&type))
739                 return -1;
740
741         ret = tethering_foreach_connected_clients(th, type,
742                                         __clients_foreach_cb, NULL);
743         if (__is_err(ret) == true) {
744                 printf("Fail to disable tethering\n");
745                 return -1;
746         }
747
748         return 1;
749 }
750
751 static int test_tethering_get_interface_info(void)
752 {
753         tethering_type_e type;
754
755         if (!__get_tethering_type(&type))
756                 return -1;
757
758         __print_interface_info(th, type);
759
760         return 1;
761 }
762
763 static int test_tethering_get_data_usage(void)
764 {
765         int ret = tethering_get_data_usage(th, __data_usage_cb, NULL);
766
767         if (__is_err(ret) == true) {
768                 printf("Fail to get data usage!!\n");
769                 return -1;
770         }
771
772         return 1;
773 }
774
775 static int test_tethering_wifi_get_setting(void)
776 {
777         __print_wifi_tethering_setting(th);
778         return 1;
779 }
780
781 static int test_tethering_wifi_set_ssid(void)
782 {
783         int ret;
784         char ssid[100] = {0, };
785
786         if (test_get_user_string("Input SSID for Wi-Fi tethering:",
787                                 ssid, 100) == false) {
788                 printf("Failed to read user input!!\n");
789                 return -1;
790         }
791
792         ret = tethering_wifi_set_ssid(th, ssid);
793         if (__is_err(ret) == true) {
794                 printf("Fail to set wifi ssid!!\n");
795                 return -1;
796         }
797
798         return 1;
799 }
800
801 static int test_tethering_wifi_set_security_type(void)
802 {
803         int ret;
804         int security_type;
805
806         printf("Input security type for Wi-Fi tethering (0:NONE, 1:WPA2_PSK, 2:WPS, 3:SAE)");
807         ret = scanf("%9d", &security_type);
808         if (ret < 0) {
809                 printf("scanf is failed!!\n");
810                 return -1;
811         }
812
813         ret = tethering_wifi_set_security_type(th, security_type);
814         if (__is_err(ret) == true) {
815                 printf("Fail to set security type!!\n");
816                 return -1;
817         }
818
819         return 1;
820 }
821
822 int test_tethering_wifi_set_visibility(void)
823 {
824         int ret;
825         int visibility;
826
827         printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
828         ret = scanf("%9d", &visibility);
829         if (ret < 0) {
830                 printf("scanf is failed!!\n");
831                 return -1;
832         }
833
834         ret = tethering_wifi_set_ssid_visibility(th, visibility);
835         if (__is_err(ret) == true) {
836                 printf("Fail to set visibility!!\n");
837                 return -1;
838         }
839
840         return 1;
841 }
842
843 static int test_tethering_wifi_set_passphrase(void)
844 {
845         int ret;
846         char passphrase[100] = {0, };
847
848         if (test_get_user_string("Input passphrase for Wi-Fi tethering:",
849                                 passphrase, 100) == false) {
850                 printf("Failed to read user input!!\n");
851                 return -1;
852         }
853
854         ret = tethering_wifi_set_passphrase(th, passphrase);
855         if (__is_err(ret) == true) {
856                 printf("Fail to set passphrase!!\n");
857                 return -1;
858         }
859
860         return 1;
861 }
862
863 static int test_tethering_wifi_set_channel(void)
864 {
865         int ret;
866         int channel;
867
868         printf("Input channel for Wi-Fi tethering: ");
869         ret = scanf("%d", &channel);
870
871         ret = tethering_wifi_set_channel(th, channel);
872         if (__is_err(ret) == true) {
873                 printf("Fail to set channel!!\n");
874                 return -1;
875         }
876
877         return 1;
878 }
879
880 static int test_tethering_wifi_set_mode(void)
881 {
882         int ret;
883         int type;
884
885         printf("Input hw_mode for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
886         ret = scanf("%d", &type);
887
888         ret = tethering_wifi_set_mode(th, type);
889         if (__is_err(ret) == true) {
890                 printf("Fail to set mode!!\n");
891                 return -1;
892         }
893
894         return 1;
895 }
896
897 static int test_tethering_wifi_enable_dhcp(void)
898 {
899         int ret;
900         int enable;
901
902         printf("Input (0-Disable, 1-Enable): ");
903         ret = scanf("%d", &enable);
904
905         ret = tethering_wifi_enable_dhcp(th, enable);
906         if (__is_err(ret) == true) {
907                 printf("Fail to enable dhcp server!!\n");
908                 return -1;
909         }
910
911         return 1;
912 }
913
914 static int test_tethering_wifi_set_dhcp_range(void)
915 {
916         int ret;
917         char rangestart[16], rangestop[16];
918
919         printf("Input range (ex: 192.168.0.50 192.168.0.150): ");
920
921         ret = scanf("%15s %15s", rangestart, rangestop);
922
923         ret = tethering_wifi_set_dhcp_range(th, rangestart, rangestop);
924         if (__is_err(ret) == true) {
925                 printf("Fail to set dhcp range and enable dhcp server!!\n");
926                 return -1;
927         }
928
929         return 1;
930 }
931
932 static int test_tethering_wifi_is_dhcp_enabled(void)
933 {
934         int ret;
935         bool enabled;
936
937         ret = tethering_wifi_is_dhcp_enabled(th, &enabled);
938
939         if (__is_err(ret) == true) {
940                 printf("Fail to get dhcp server status!!\n");
941                 return -1;
942         } else {
943                 printf("DHCP server is %s\n", enabled ? "enabled" : "disabled");
944         }
945
946         return 1;
947 }
948
949 static int test_tethering_wifi_set_mac_filtering(void)
950 {
951         int ret;
952         int enable;
953
954         printf("Input mac filtering option (0: disable, 1: enable): ");
955         ret = scanf("%d", &enable);
956
957         ret = tethering_wifi_set_mac_filter(th, enable);
958         if (__is_err(ret) == true) {
959                 printf("Fail to set mac filtering!!\n");
960                 return -1;
961         }
962
963         return 1;
964 }
965
966 static int test_tethering_manage_mac_list(void)
967 {
968         int ret = 0;
969         int list, option;
970         char mac[100];
971
972         printf("Select MAC list to modify (0: allowed mac list, 1: blocked mac list): ");
973         ret = scanf("%d", &list);
974
975         printf("Select option (0: Add, 1: Remove): ");
976         ret = scanf("%d", &option);
977
978         printf("Input MAC Address to add/remove allowed/blocked mac list: ");
979         ret = scanf("%99s", mac);
980         if (ret < 0) {
981                 printf("scanf is failed!!\n");
982                 return -1;
983         }
984
985         if (!list && !option) {
986                 /* Add to allowed mac list*/
987                 ret = tethering_wifi_add_allowed_mac_list(th, mac);
988         } else if (!list && option) {
989                 /* Remove from allowed mac list */
990                 ret = tethering_wifi_remove_allowed_mac_list(th, mac);
991         } else if (list && !option) {
992                 /* Add to blocked mac list */
993                 ret = tethering_wifi_add_blocked_mac_list(th, mac);
994         } else {
995                 /* Remove from blocked mac list */
996                 ret = tethering_wifi_remove_blocked_mac_list(th, mac);
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] = {0, };
1326
1327         if (test_get_user_string("Input WPS PIN: ",
1328                                 wps_pin, 128) == false) {
1329                 printf("Failed to read user input!!\n");
1330                 return -1;
1331         }
1332
1333         ret = tethering_wifi_set_wps_pin(th, wps_pin);
1334         if (__is_err(ret) == true) {
1335                 printf("Fail to get port filtering rule!\n");
1336                 return -1;
1337         }
1338
1339         return 1;
1340 }
1341
1342 int main(int argc, char **argv)
1343 {
1344         GMainLoop *mainloop;
1345
1346 #if !GLIB_CHECK_VERSION(2, 36, 0)
1347         g_type_init();
1348 #endif
1349         mainloop = g_main_loop_new(NULL, false);
1350
1351         GIOChannel *channel = g_io_channel_unix_new(0);
1352         g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1353         printf("Test Thread created...\n");
1354         g_main_loop_run(mainloop);
1355
1356         return 0;
1357 }
1358
1359 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1360 {
1361         int rv;
1362         char a[10];
1363
1364         printf("Event received from stdin\n");
1365
1366         rv = read(0, a, 10);
1367
1368         if (rv <= 0 || a[0] == '0')
1369                 exit(1);
1370
1371         if (a[0] == '\n' || a[0] == '\r') {
1372                 printf("\n\n Network Connection API Test App\n\n");
1373                 printf("Options..\n");
1374                 printf("1       - Tethering create and set callbacks\n");
1375                 printf("2       - Tethering destroy\n");
1376                 printf("3       - Enable Tethering\n");
1377                 printf("4       - Disable Tethering\n");
1378                 printf("5       - Get client information\n");
1379                 printf("6       - Get interface information\n");
1380                 printf("7       - Get data usage\n");
1381                 printf("8       - Get Wi-Fi tethering setting\n");
1382                 printf("a       - Set Wi-Fi tethering SSID\n");
1383                 printf("b       - Set Wi-Fi tethering security type\n");
1384                 printf("c       - Set Wi-Fi tethering visibility\n");
1385                 printf("d       - Set Wi-Fi tethering passphrase\n");
1386                 printf("e       - Set Wi-Fi tethering mac filtering\n");
1387                 printf("f       - Add/Remove MAC adress to/from allowed/blocked list\n");
1388                 printf("g       - Get allowed/blocked list\n");
1389                 printf("k       - Reload Wi-Fi tethering\n");
1390                 printf("m       - Set Wi-Fi channel\n");
1391                 printf("n       - Set Wi-Fi hw_mode\n");
1392                 printf("o       - Enable dhcp server\n");
1393                 printf("p       - Enable dhcp server with range\n");
1394                 printf("q       - Is dhcp server enabled?\n");
1395                 printf("r       - Get Wi-Fi txpower\n");
1396                 printf("s       - Set Wi-Fi txpower\n");
1397                 printf("t       - Set Wi-Fi mtu\n");
1398                 printf("u       - Change mac address\n");
1399                 printf("v       - Set max connected device(Wi-Fi tethering)\n");
1400                 printf("w       - Enable port forwarding\n");
1401                 printf("x       - Add port forwarding rule\n");
1402                 printf("y       - Reset port forwarding rule\n");
1403                 printf("z       - Get port forwarding rule\n");
1404                 printf("A       - Enable port filtering\n");
1405                 printf("B       - Add port filtering rule\n");
1406                 printf("C       - Add custom port filtering rule\n");
1407                 printf("D       - Get port filtering rule\n");
1408                 printf("E       - Get custom port filtering rule\n");
1409                 printf("F       - Set vpn passthrough rule\n");
1410                 printf("G       - Push WPS button\n");
1411                 printf("H       - Set WPS PIN\n");
1412                 printf("0       - \n");
1413                 printf("ENTER  - Show options menu.......\n");
1414         }
1415
1416         switch (a[0]) {
1417         case '1':
1418                 rv = test_tethering_create();
1419                 break;
1420         case '2':
1421                 rv = test_tethering_destroy();
1422                 break;
1423         case '3':
1424                 rv = test_tethering_enable();
1425                 break;
1426         case '4':
1427                 rv = test_tethering_disable();
1428                 break;
1429         case '5':
1430                 rv = test_tethering_get_client_info();
1431                 break;
1432         case '6':
1433                 rv = test_tethering_get_interface_info();
1434                 break;
1435         case '7':
1436                 rv = test_tethering_get_data_usage();
1437                 break;
1438         case '8':
1439                 rv = test_tethering_wifi_get_setting();
1440                 break;
1441         case 'a':
1442                 rv = test_tethering_wifi_set_ssid();
1443                 break;
1444         case 'b':
1445                 rv = test_tethering_wifi_set_security_type();
1446                 break;
1447         case 'c':
1448                 rv = test_tethering_wifi_set_visibility();
1449                 break;
1450         case 'd':
1451                 rv = test_tethering_wifi_set_passphrase();
1452                 break;
1453         case 'e':
1454                 rv = test_tethering_wifi_set_mac_filtering();
1455                 break;
1456         case 'f':
1457                 rv = test_tethering_manage_mac_list();
1458                 break;
1459         case 'g':
1460                 rv = test_tethering_get_mac_list();
1461                 break;
1462         case 'k':
1463                 rv = test_tethering_wifi_reload_settings();
1464                 break;
1465         case 'm':
1466                 rv = test_tethering_wifi_set_channel();
1467                 break;
1468         case 'n':
1469                 rv = test_tethering_wifi_set_mode();
1470                 break;
1471         case 'o':
1472                 rv = test_tethering_wifi_enable_dhcp();
1473                 break;
1474         case 'p':
1475                 rv = test_tethering_wifi_set_dhcp_range();
1476                 break;
1477         case 'q':
1478                 rv = test_tethering_wifi_is_dhcp_enabled();
1479                 break;
1480         case 'r':
1481                 rv = test_tethering_wifi_get_txpower();
1482                 break;
1483         case 's':
1484                 rv = test_tethering_wifi_set_txpower();
1485                 break;
1486         case 't':
1487                 rv = test_tethering_wifi_set_mtu();
1488                 break;
1489         case 'u':
1490                 rv = test_tethering_wifi_change_mac();
1491                 break;
1492         case 'v':
1493                 rv = test_tethering_wifi_set_max_connected_device();
1494                 break;
1495         case 'w':
1496                 rv = test_tethering_wifi_enable_port_forwarding();
1497                 break;
1498         case 'x':
1499                 rv = test_tethering_wifi_add_port_forwarding_rule();
1500                 break;
1501         case 'y':
1502                 rv = test_tethering_wifi_reset_port_forwarding_rule();
1503                 break;
1504         case 'z':
1505                 rv = test_tethering_wifi_get_port_forwarding_rule();
1506                 break;
1507         case 'A':
1508                 rv = test_tethering_wifi_enable_port_filtering();
1509                 break;
1510         case 'B':
1511                 rv = test_tethering_wifi_add_port_filtering_rule();
1512                 break;
1513         case 'C':
1514                 rv = test_tethering_wifi_add_custom_port_filtering_rule();
1515                 break;
1516         case 'D':
1517                 rv = test_tethering_wifi_get_port_filtering_rule();
1518                 break;
1519         case 'E':
1520                 rv = test_tethering_wifi_get_custom_port_filtering_rule();
1521                 break;
1522         case 'F':
1523                 rv = test_tethering_wifi_set_vpn_passthrough_rule();
1524                 break;
1525         case 'G':
1526                 rv = test_tethering_wifi_push_wps_button();
1527                 break;
1528         case 'H':
1529                 rv = test_tethering_wifi_set_wps_pin();
1530                 break;
1531         }
1532
1533         if (rv == 1)
1534                 printf("Operation succeeded!\n");
1535         else
1536                 printf("Operation failed!\n");
1537
1538         return true;
1539 }