2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <glib-object.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
29 #include "tethering.h"
31 #define DISABLE_REASON_TEXT_LEN 64
32 #define COMMON_STR_BUF_LEN 32
34 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data);
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;
45 tethering_h th = NULL;
47 static bool __is_err(tethering_error_e ret)
52 case TETHERING_ERROR_INVALID_PARAMETER:
53 err_msg = "Wrong parameter is used";
56 case TETHERING_ERROR_OUT_OF_MEMORY:
57 err_msg = "Memory is not enough";
60 case TETHERING_ERROR_NONE:
63 case TETHERING_ERROR_NOT_ENABLED:
64 err_msg = "Tethering is not enabled";
67 case TETHERING_ERROR_OPERATION_FAILED:
68 err_msg = "Operation is failed";
71 case TETHERING_ERROR_RESOURCE_BUSY:
72 err_msg = "Resource is busy";
76 err_msg = "This should not be happened";
80 g_print("##ERR: %s\n", err_msg);
85 static const char *__convert_tethering_type_to_str(const tethering_type_e type)
87 static char str_buf[COMMON_STR_BUF_LEN] = {0, };
90 case TETHERING_TYPE_USB:
91 g_strlcpy(str_buf, "USB Tethering", sizeof(str_buf));
94 case TETHERING_TYPE_WIFI:
95 g_strlcpy(str_buf, "Wi-Fi Tethering", sizeof(str_buf));
98 case TETHERING_TYPE_BT:
99 g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf));
102 case TETHERING_TYPE_RESERVED:
103 g_strlcpy(str_buf, "Wi-Fi AP", sizeof(str_buf));
107 g_strlcpy(str_buf, "Unknown", sizeof(str_buf));
114 static const char *__convert_disabled_code_to_str(const tethering_disabled_cause_e code)
116 static char str_buf[DISABLE_REASON_TEXT_LEN] = {0, };
119 case TETHERING_DISABLED_BY_USB_DISCONNECTION:
120 strncpy(str_buf, "disabled due to usb disconnection", sizeof(str_buf));
123 case TETHERING_DISABLED_BY_FLIGHT_MODE:
124 strncpy(str_buf, "disabled due to flight mode on", sizeof(str_buf));
127 case TETHERING_DISABLED_BY_LOW_BATTERY:
128 strncpy(str_buf, "disabled due to low battery", sizeof(str_buf));
131 case TETHERING_DISABLED_BY_NETWORK_CLOSE:
132 strncpy(str_buf, "disabled due to pdp network close", sizeof(str_buf));
135 case TETHERING_DISABLED_BY_TIMEOUT:
136 strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
139 case TETHERING_DISABLED_BY_OTHERS:
140 strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
143 case TETHERING_DISABLED_BY_REQUEST:
144 strncpy(str_buf, "disabled by my request", sizeof(str_buf));
147 case TETHERING_DISABLED_BY_WIFI_ON:
148 strncpy(str_buf, "disabled by Wi-Fi station on", sizeof(str_buf));
151 case TETHERING_DISABLED_BY_BT_OFF:
152 strncpy(str_buf, "disabled by bluetooth off", sizeof(str_buf));
156 strncpy(str_buf, "disabled by unknown reason", sizeof(str_buf));
163 static void __register_cbs(tethering_h th, __tethering_cbs *cbs, void *user_data)
165 tethering_error_e ret = TETHERING_ERROR_NONE;
167 ret = tethering_set_enabled_cb(th, TETHERING_TYPE_ALL,
168 cbs->enabled_cb, user_data);
169 if (__is_err(ret) == true)
170 g_print("tethering_set_enabled_cb is failed\n");
172 ret = tethering_set_enabled_cb(th, TETHERING_TYPE_RESERVED,
173 cbs->enabled_cb, user_data);
174 if (__is_err(ret) == true)
175 g_print("tethering_set_enabled_cb is failed\n");
177 ret = tethering_set_disabled_cb(th, TETHERING_TYPE_ALL,
178 cbs->disabled_cb, user_data);
179 if (__is_err(ret) == true)
180 g_print("tethering_set_disabled_cb is failed\n");
182 ret = tethering_set_disabled_cb(th, TETHERING_TYPE_RESERVED,
183 cbs->disabled_cb, user_data);
184 if (__is_err(ret) == true)
185 g_print("tethering_set_disabled_cb is failed\n");
187 ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_ALL,
188 cbs->changed_cb, user_data);
189 if (__is_err(ret) == true)
190 g_print("tethering_set_connection_state_changed_cb is failed\n");
192 ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED,
193 cbs->changed_cb, user_data);
194 if (__is_err(ret) == true)
195 g_print("tethering_set_connection_state_changed_cb is failed\n");
197 ret = tethering_wifi_set_security_type_changed_cb(th,
198 cbs->security_type_changed_cb, user_data);
199 if (__is_err(ret) == true)
200 g_print("tethering_wifi_set_security_type_changed_cb is failed\n");
202 ret = tethering_wifi_set_ssid_visibility_changed_cb(th,
203 cbs->ssid_visibility_changed_cb, user_data);
204 if (__is_err(ret) == true)
205 g_print("tethering_wifi_set_ssid_visibility_changed_cb is failed\n");
207 ret = tethering_wifi_set_passphrase_changed_cb(th,
208 cbs->passphrase_changed_cb, user_data);
209 if (__is_err(ret) == true)
210 g_print("tethering_wifi_set_passphrase_changed_cb is failed\n");
215 static void __deregister_cbs(tethering_h th)
217 tethering_error_e ret = TETHERING_ERROR_NONE;
219 ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_ALL);
220 if (__is_err(ret) == true)
221 g_print("tethering_unset_enabled_cb is failed\n");
223 ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_RESERVED);
224 if (__is_err(ret) == true)
225 g_print("tethering_unset_enabled_cb is failed\n");
227 ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_ALL);
228 if (__is_err(ret) == true)
229 g_print("tethering_unset_disabled_cb is failed\n");
231 ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_RESERVED);
232 if (__is_err(ret) == true)
233 g_print("tethering_unset_disabled_cb is failed\n");
235 ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_ALL);
236 if (__is_err(ret) == true)
237 g_print("tethering_unset_connection_state_changed_cb is failed\n");
239 ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED);
240 if (__is_err(ret) == true)
241 g_print("tethering_unset_connection_state_changed_cb is failed\n");
243 ret = tethering_wifi_unset_security_type_changed_cb(th);
244 if (__is_err(ret) == true)
245 g_print("tethering_wifi_unset_security_type_changed_cb is failed\n");
247 ret = tethering_wifi_unset_ssid_visibility_changed_cb(th);
248 if (__is_err(ret) == true)
249 g_print("tethering_wifi_unset_ssid_visibility_changed_cb is failed\n");
251 ret = tethering_wifi_unset_passphrase_changed_cb(th);
252 if (__is_err(ret) == true)
253 g_print("tethering_wifi_unset_passphrase_changed_cb is failed\n");
258 /* Tethering callbacks */
259 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
261 if (__is_err(error)) {
265 g_print("## %s is not enabled. error code[0x%X]\n",
266 __convert_tethering_type_to_str(type),
272 g_print("## %s is enabled successfully\n",
273 __convert_tethering_type_to_str(type));
275 g_print("## %s is enabled by other app\n",
276 __convert_tethering_type_to_str(type));
281 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
283 if (__is_err(error)) {
284 if (code != TETHERING_DISABLED_BY_REQUEST)
287 g_print("## %s is not disabled. error code[0x%X]\n",
288 __convert_tethering_type_to_str(type), error);
292 g_print("## %s is %s\n",
293 __convert_tethering_type_to_str(type),
294 __convert_disabled_code_to_str(code));
299 static void __connection_state_changed_cb(tethering_client_h client, bool open, void *data)
301 tethering_client_h clone = NULL;
302 tethering_type_e type;
303 char *ip_address = NULL;
304 char *mac_address = NULL;
305 char *hostname = NULL;
307 tethering_client_clone(&clone, client);
309 g_print("tetheirng_client_clone is failed\n");
313 tethering_client_get_tethering_type(clone, &type);
314 tethering_client_get_ip_address(clone,
315 TETHERING_ADDRESS_FAMILY_IPV4, &ip_address);
316 tethering_client_get_mac_address(clone, &mac_address);
317 tethering_client_get_name(clone, &hostname);
320 g_print("## New station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
321 __convert_tethering_type_to_str(type),
322 ip_address, mac_address, hostname);
324 g_print("## Disconnected station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
325 __convert_tethering_type_to_str(type),
326 ip_address, mac_address, hostname);
336 tethering_client_destroy(clone);
341 static void __data_usage_cb(tethering_error_e result, unsigned long long received_data,
342 unsigned long long sent_data, void *user_data)
344 g_print("__data_usage_cb\n");
346 if (result != TETHERING_ERROR_NONE) {
347 g_print("tethering_get_data_usage is failed. error[0x%X]\n", result);
351 g_print("## Received data : %llu bytes\n", received_data);
352 g_print("## Sent data : %llu bytes\n", sent_data);
357 static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
359 g_print("__settings_reloaded_cb\n");
361 if (result != TETHERING_ERROR_NONE) {
362 g_print("tethering_wifi_reload_settings is failed. error[0x%X]\n", result);
366 g_print("## Wi-Fi tethering setting is reloaded\n");
371 static bool __clients_foreach_cb(tethering_client_h client, void *data)
373 tethering_client_h clone = NULL;
374 tethering_type_e type;
375 char *ip_address = NULL;
376 char *mac_address = NULL;
377 char *hostname = NULL;
379 /* Clone internal information */
380 if (tethering_client_clone(&clone, client) != TETHERING_ERROR_NONE) {
381 g_print("tethering_client_clone is failed\n");
385 /* Get information */
386 if (tethering_client_get_tethering_type(clone, &type) != TETHERING_ERROR_NONE)
387 g_print("tethering_client_get_type is failed\n");
389 if (tethering_client_get_ip_address(clone, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address) != TETHERING_ERROR_NONE)
390 g_print("tethering_client_get_ip_address is failed\n");
392 if (tethering_client_get_mac_address(clone, &mac_address) != TETHERING_ERROR_NONE)
393 g_print("tethering_client_get_mac_address is failed\n");
395 if (tethering_client_get_name(clone, &hostname) != TETHERING_ERROR_NONE)
396 g_print("tethering_client_get_hostname is failed\n");
398 /* End of getting information */
400 g_print("\n< Client Info. >\n");
401 g_print("\tType %s\n", __convert_tethering_type_to_str(type));
402 g_print("\tIP Address %s\n", ip_address);
403 g_print("\tMAC Address : %s\n", mac_address);
404 g_print("\tHostname : %s\n", hostname);
406 /* Destroy cloned objects */
414 tethering_client_destroy(clone);
416 /* Continue iteration */
420 static void __security_type_changed_cb(tethering_wifi_security_type_e changed_type, void *user_data)
422 g_print("Wi-Fi Tethering Security type is changed to [%s]\n",
423 changed_type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
424 "open" : "wpa2-psk");
428 static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
430 g_print("SSID visibility for Wi-Fi tethering changed to [%s]\n",
431 changed_visible ? "visible" : "invisible");
435 static void __passphrase_changed_cb(void *user_data)
437 g_print("Wi-Fi Tethering passphrase is changed\n");
440 /* End of tethering callbacks */
442 static void __print_interface_info(tethering_h th, tethering_type_e type)
444 char *interface = NULL;
445 char *mac_address = NULL;
446 char *ip_address = NULL;
447 char *gateway_address = NULL;
448 char *subnet_mask = NULL;
450 if (tethering_is_enabled(th, type) == FALSE) {
451 g_print("%s is not enabled\n",
452 __convert_tethering_type_to_str(type));
456 tethering_get_network_interface_name(th, type, &interface);
457 tethering_get_mac_address(th, type, &mac_address);
458 tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
460 tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
462 tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
465 g_print("interface name : %s\n", interface);
466 g_print("mac address : %s\n", mac_address);
467 g_print("ip address : %s\n", ip_address);
468 g_print("gateway address: %s\n", gateway_address);
469 g_print("subnet mask : %s\n", subnet_mask);
478 free(gateway_address);
485 static void __print_wifi_tethering_setting(tethering_h th)
488 char *passphrase = NULL;
489 bool visibility = false;
492 tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
493 tethering_wifi_mode_type_e hw_mode = TETHERING_WIFI_MODE_TYPE_G;
495 int error = TETHERING_ERROR_NONE;
497 error = tethering_wifi_get_ssid(th, &ssid);
498 if (error != TETHERING_ERROR_NONE)
501 g_print("\n\t** WiFi tethering SSID : %s\n", ssid);
503 error = tethering_wifi_get_passphrase(th, &passphrase);
504 if (error != TETHERING_ERROR_NONE)
507 g_print("\t** WiFi tethering passphrase : %s\n", passphrase);
509 error = tethering_wifi_get_ssid_visibility(th, &visibility);
510 if (error != TETHERING_ERROR_NONE)
513 g_print("\t** WiFi tethering ssid visibility : %s\n",
514 visibility ? "visible" : "invisible");
516 error = tethering_wifi_get_security_type(th, &security_type);
517 if (error != TETHERING_ERROR_NONE)
520 g_print("\t** WiFi tethering security_type : %s\n",
522 TETHERING_WIFI_SECURITY_TYPE_NONE ?
523 "open" : "wpa2-psk");
525 error = tethering_wifi_get_mac_filter(th, &mac_filter);
526 if (error != TETHERING_ERROR_NONE)
529 g_print("\t** WiFi tethering mac filter : %s\n",
530 mac_filter ? "enable" : "disable");
532 error = tethering_wifi_get_mode(th, &hw_mode);
533 if (error != TETHERING_ERROR_NONE)
536 g_print("\t** WiFi tethering mode : %d\n", hw_mode);
538 error = tethering_wifi_get_channel(th, &channel);
539 if (error != TETHERING_ERROR_NONE)
542 g_print("\t** WiFi tethering channel : %d\n", channel);
552 static void __print_wifi_ap_setting(tethering_h th)
555 char *passphrase = NULL;
556 bool visibility = false;
557 tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
559 int error = TETHERING_ERROR_NONE;
561 error = tethering_wifi_ap_get_ssid(th, &ssid);
562 if (error != TETHERING_ERROR_NONE)
565 g_print("\n\t** WiFi AP SSID : %s\n", ssid);
567 error = tethering_wifi_ap_get_passphrase(th, &passphrase);
568 if (error != TETHERING_ERROR_NONE)
571 g_print("\t** WiFi AP passphrase : %s\n", passphrase);
573 error = tethering_wifi_ap_get_ssid_visibility(th, &visibility);
574 if (error != TETHERING_ERROR_NONE)
577 g_print("\t** WiFi AP ssid visibility : %s\n",
578 visibility ? "visible" : "invisible");
580 error = tethering_wifi_ap_get_security_type(th, &security_type);
581 if (error != TETHERING_ERROR_NONE)
584 g_print("\t** WiFi AP security_type : %s\n",
586 TETHERING_WIFI_SECURITY_TYPE_NONE ?
587 "open" : "wpa2-psk");
597 bool __get_tethering_type(tethering_type_e *type)
602 printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:WiFi AP, 5:ALL)\n");
603 ret = scanf("%9d", &sel);
605 printf("scanf is failed!!\n");
611 *type = TETHERING_TYPE_WIFI;
614 *type = TETHERING_TYPE_BT;
617 *type = TETHERING_TYPE_USB;
620 *type = TETHERING_TYPE_RESERVED;
623 *type = TETHERING_TYPE_ALL;
626 printf("Invalid input!!\n");
633 static int test_tethering_create(void)
635 int ret = tethering_create(&th);
636 __tethering_cbs cbs = {
637 __enabled_cb, __disabled_cb,
638 __connection_state_changed_cb, __security_type_changed_cb,
639 __ssid_visibility_changed_cb, __passphrase_changed_cb};
641 if (__is_err(ret) == false) __register_cbs(th, &cbs, NULL);
643 printf("Tethering create is failed\n");
646 printf("Tethering create and register callback success\n");
651 static int test_tethering_destroy(void)
653 int ret = TETHERING_ERROR_NONE;
655 __deregister_cbs(th);
657 ret = tethering_destroy(th);
658 if (__is_err(ret) == true) {
659 printf("Tethering destroy is failed\n");
666 static int test_tethering_enable(void)
668 int ret = TETHERING_ERROR_NONE;
669 tethering_type_e type;
671 if (!__get_tethering_type(&type))
674 ret = tethering_enable(th, type);
675 if (__is_err(ret) == true) {
676 printf("Fail to enable tethering\n");
682 static int test_tethering_disable(void)
684 int ret = TETHERING_ERROR_NONE;
685 tethering_type_e type;
687 if (!__get_tethering_type(&type))
690 ret = tethering_disable(th, type);
691 if (__is_err(ret) == true) {
692 printf("Fail to disable tethering\n");
698 static int test_tethering_get_client_info(void)
701 tethering_type_e type;
703 if (!__get_tethering_type(&type))
706 ret = tethering_foreach_connected_clients(th, type,
707 __clients_foreach_cb, NULL);
708 if (__is_err(ret) == true) {
709 printf("Fail to disable tethering\n");
716 static int test_tethering_get_interface_info(void)
718 tethering_type_e type;
720 if (!__get_tethering_type(&type))
723 __print_interface_info(th, type);
728 static int test_tethering_get_data_usage(void)
730 int ret = tethering_get_data_usage(th, __data_usage_cb, NULL);
732 if (__is_err(ret) == true) {
733 printf("Fail to get data usage!!\n");
740 static int test_tethering_wifi_get_setting(void)
742 __print_wifi_tethering_setting(th);
746 static int test_tethering_wifi_ap_get_setting(void)
748 __print_wifi_ap_setting(th);
752 static int test_tethering_wifi_set_ssid(void)
757 printf("Input SSID for Wi-Fi tethering: ");
758 ret = scanf("%99s", ssid);
760 printf("scanf is failed!!\n");
764 ret = tethering_wifi_set_ssid(th, ssid);
765 if (__is_err(ret) == true) {
766 printf("Fail to set wifi ssid!!\n");
773 static int test_tethering_wifi_set_security_type(void)
778 printf("Input security type for Wi-Fi tethering (0:NONE, 1:WPA2_PSK)");
779 ret = scanf("%9d", &security_type);
781 printf("scanf is failed!!\n");
785 ret = tethering_wifi_set_security_type(th, security_type);
786 if (__is_err(ret) == true) {
787 printf("Fail to set security type!!\n");
794 int test_tethering_wifi_set_visibility(void)
799 printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
800 ret = scanf("%9d", &visibility);
802 printf("scanf is failed!!\n");
806 ret = tethering_wifi_set_ssid_visibility(th, visibility);
807 if (__is_err(ret) == true) {
808 printf("Fail to set visibility!!\n");
815 static int test_tethering_wifi_set_passphrase(void)
818 char passphrase[100];
820 printf("Input passphrase for Wi-Fi tethering: ");
821 ret = scanf("%99s", passphrase);
823 printf("scanf is failed!!\n");
827 ret = tethering_wifi_set_passphrase(th, passphrase);
828 if (__is_err(ret) == true) {
829 printf("Fail to set passphrase!!\n");
836 static int test_tethering_wifi_set_channel(void)
841 printf("Input channel for Wi-Fi tethering: ");
842 ret = scanf("%d", &channel);
844 ret = tethering_wifi_set_channel(th, channel);
845 if (__is_err(ret) == true) {
846 printf("Fail to set channel!!\n");
853 static int test_tethering_wifi_set_mode(void)
858 printf("Input hw_mode for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
859 ret = scanf("%d", &type);
861 ret = tethering_wifi_set_mode(th, type);
862 if (__is_err(ret) == true) {
863 printf("Fail to set mode!!\n");
870 static int test_tethering_wifi_enable_dhcp(void)
875 printf("Input (0-Disable, 1-Enable): ");
876 ret = scanf("%d", &enable);
878 ret = tethering_wifi_enable_dhcp(th, enable);
879 if (__is_err(ret) == true) {
880 printf("Fail to enable dhcp server!!\n");
887 static int test_tethering_wifi_set_dhcp_range(void)
890 char rangestart[16], rangestop[16];
892 printf("Input range (ex: 192.168.0.50 192.168.0.150): ");
894 ret = scanf("%s %s", rangestart, rangestop);
896 ret = tethering_wifi_set_dhcp_range(th, rangestart, rangestop);
897 if (__is_err(ret) == true) {
898 printf("Fail to set dhcp range and enable dhcp server!!\n");
905 static int test_tethering_wifi_is_dhcp_enabled(void)
910 ret = tethering_wifi_is_dhcp_enabled(th, &enabled);
912 if (__is_err(ret) == true) {
913 printf("Fail to get dhcp server status!!\n");
917 printf("DHCP server is %s\n", enabled? "enabled": "disabled");
923 static int test_tethering_wifi_set_mac_filtering(void)
928 printf("Input mac filtering option (0: disable, 1: enable): ");
929 ret = scanf("%d", &enable);
931 ret = tethering_wifi_set_mac_filter(th, enable);
932 if (__is_err(ret) == true) {
933 printf("Fail to set mac filtering!!\n");
940 static int test_tethering_manage_mac_list(void)
946 printf("Select MAC list to modify (0: allowed mac list, 1: blocked mac list): ");
947 ret = scanf("%d", &list);
949 printf("Select option (0: Add, 1: Remove): ");
950 ret = scanf("%d", &option);
952 printf("Input MAC Address to add/remove allowed/blocked mac list: ");
953 ret = scanf("%99s", mac);
955 printf("scanf is failed!!\n");
959 if (!list && !option) {
960 /* Add to allowed mac list*/
961 ret = tethering_wifi_add_allowed_mac_list(th, mac);
962 } else if (!list && option) {
963 /* Remove from allowed mac list */
964 ret = tethering_wifi_remove_allowed_mac_list(th, mac);
965 } else if (list && !option) {
966 /* Add to blocked mac list */
967 ret = tethering_wifi_add_blocked_mac_list(th, mac);
968 } else if (list && option) {
969 /* Remove from blocked mac list */
970 ret = tethering_wifi_remove_blocked_mac_list(th, mac);
972 printf("Input Failed!!\n");
982 static int test_tethering_wifi_ap_set_ssid(void)
987 printf("Input SSID for Wi-Fi AP tethering: ");
988 ret = scanf("%99s", ssid);
990 printf("scanf is failed!!\n");
994 ret = tethering_wifi_ap_set_ssid(th, ssid);
995 if (__is_err(ret) == true) {
996 printf("Fail to set wifi ap ssid!!\n");
1002 static int test_tethering_wifi_ap_set_security_type(void)
1007 printf("Input security type for Wi-Fi AP tethering (0:NONE, 1:WPA2_PSK)");
1008 ret = scanf("%9d", &security_type);
1010 printf("scanf is failed!!\n");
1014 ret = tethering_wifi_ap_set_security_type(th, security_type);
1015 if (__is_err(ret) == true) {
1016 printf("Fail to set security type!!\n");
1022 static int test_tethering_wifi_ap_set_visibility(void)
1027 printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
1028 ret = scanf("%9d", &visibility);
1030 printf("scanf is failed!!\n");
1034 ret = tethering_wifi_ap_set_ssid_visibility(th, visibility);
1035 if (__is_err(ret) == true) {
1036 printf("Fail to set visibility!!\n");
1042 static int test_tethering_wifi_ap_set_passphrase(void)
1045 char passphrase[100];
1047 printf("Input passphrase for Wi-Fi tethering: ");
1048 ret = scanf("%99s", passphrase);
1050 printf("scanf is failed!!\n");
1054 ret = tethering_wifi_ap_set_passphrase(th, passphrase);
1055 if (__is_err(ret) == true) {
1056 printf("Fail to set passphrase!!\n");
1062 static int test_tethering_wifi_reload_settings(void)
1064 int ret = tethering_wifi_reload_settings(th, __settings_reloaded_cb, NULL);
1066 if (__is_err(ret) == true) {
1067 printf("Fail to reload wifi tethering!!\n");
1073 static int test_tethering_wifi_ap_reload_settings(void)
1075 int ret = tethering_wifi_ap_reload_settings(th, __settings_reloaded_cb, NULL);
1077 if (__is_err(ret) == true) {
1078 printf("Fail to reload wifi tethering!!\n");
1084 int main(int argc, char **argv)
1086 GMainLoop *mainloop;
1088 #if !GLIB_CHECK_VERSION(2, 36, 0)
1091 mainloop = g_main_loop_new(NULL, false);
1093 GIOChannel *channel = g_io_channel_unix_new(0);
1094 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1095 printf("Test Thread created...\n");
1096 g_main_loop_run(mainloop);
1101 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1106 printf("Event received from stdin\n");
1108 rv = read(0, a, 10);
1110 if (rv <= 0 || a[0] == '0')
1113 if (a[0] == '\n' || a[0] == '\r') {
1114 printf("\n\n Network Connection API Test App\n\n");
1115 printf("Options..\n");
1116 printf("1 - Tethering create and set callbacks\n");
1117 printf("2 - Tethering destroy\n");
1118 printf("3 - Enable Tethering\n");
1119 printf("4 - Disable Tethering\n");
1120 printf("5 - Get client information\n");
1121 printf("6 - Get interface information\n");
1122 printf("7 - Get data usage\n");
1123 printf("8 - Get Wi-Fi tethering setting\n");
1124 printf("9 - Get Wi-Fi AP setting\n");
1125 printf("a - Set Wi-Fi tethering SSID\n");
1126 printf("b - Set Wi-Fi tethering security type\n");
1127 printf("c - Set Wi-Fi tethering visibility\n");
1128 printf("d - Set Wi-Fi tethering passphrase\n");
1129 printf("e - Set Wi-Fi tethering mac filtering\n");
1130 printf("f - Add/Remove MAC adress to/from allowed/blocked list\n");
1131 printf("g - Set Wi-Fi AP SSID\n");
1132 printf("h - Set Wi-Fi AP security type\n");
1133 printf("i - Set Wi-Fi AP visibility\n");
1134 printf("j - Set Wi-Fi AP passphrase\n");
1135 printf("k - Reload Wi-Fi tethering\n");
1136 printf("l - Reload Wi-Fi AP\n");
1137 printf("m - Set Wi-Fi channel\n");
1138 printf("n - Set Wi-Fi hw_mode\n");
1139 printf("o - Enable dhcp server\n");
1140 printf("p - Enable dhcp server with range\n");
1141 printf("q - Is dhcp server enabled?\n");
1142 printf("0 - Exit \n");
1143 printf("ENTER - Show options menu.......\n");
1148 rv = test_tethering_create();
1151 rv = test_tethering_destroy();
1154 rv = test_tethering_enable();
1157 rv = test_tethering_disable();
1160 rv = test_tethering_get_client_info();
1163 rv = test_tethering_get_interface_info();
1166 rv = test_tethering_get_data_usage();
1169 rv = test_tethering_wifi_get_setting();
1172 rv = test_tethering_wifi_ap_get_setting();
1175 rv = test_tethering_wifi_set_ssid();
1178 rv = test_tethering_wifi_set_security_type();
1181 rv = test_tethering_wifi_set_visibility();
1184 rv = test_tethering_wifi_set_passphrase();
1187 rv = test_tethering_wifi_set_mac_filtering();
1190 rv = test_tethering_manage_mac_list();
1193 rv = test_tethering_wifi_ap_set_ssid();
1196 rv = test_tethering_wifi_ap_set_security_type();
1199 rv = test_tethering_wifi_ap_set_visibility();
1202 rv = test_tethering_wifi_ap_set_passphrase();
1205 rv = test_tethering_wifi_reload_settings();
1208 rv = test_tethering_wifi_ap_reload_settings();
1211 rv = test_tethering_wifi_set_channel();
1214 rv = test_tethering_wifi_set_mode();
1217 rv = test_tethering_wifi_enable_dhcp();
1220 rv = test_tethering_wifi_set_dhcp_range();
1223 rv = test_tethering_wifi_is_dhcp_enabled();
1228 printf("Operation succeeded!\n");
1230 printf("Operation failed!\n");