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