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