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