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;
491 tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
493 int error = TETHERING_ERROR_NONE;
495 error = tethering_wifi_get_ssid(th, &ssid);
496 if (error != TETHERING_ERROR_NONE)
499 g_print("\n\t** WiFi tethering SSID : %s\n", ssid);
501 error = tethering_wifi_get_passphrase(th, &passphrase);
502 if (error != TETHERING_ERROR_NONE)
505 g_print("\t** WiFi tethering passphrase : %s\n", passphrase);
507 error = tethering_wifi_get_ssid_visibility(th, &visibility);
508 if (error != TETHERING_ERROR_NONE)
511 g_print("\t** WiFi tethering ssid visibility : %s\n",
512 visibility ? "visible" : "invisible");
514 error = tethering_wifi_get_security_type(th, &security_type);
515 if (error != TETHERING_ERROR_NONE)
518 g_print("\t** WiFi tethering security_type : %s\n",
520 TETHERING_WIFI_SECURITY_TYPE_NONE ?
521 "open" : "wpa2-psk");
523 error = tethering_wifi_get_mac_filter(th, &mac_filter);
524 if (error != TETHERING_ERROR_NONE)
527 g_print("\t** WiFi tethering mac filter : %s\n",
528 mac_filter ? "enable" : "disable");
538 static void __print_wifi_ap_setting(tethering_h th)
541 char *passphrase = NULL;
542 bool visibility = false;
543 tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
545 int error = TETHERING_ERROR_NONE;
547 error = tethering_wifi_ap_get_ssid(th, &ssid);
548 if (error != TETHERING_ERROR_NONE)
551 g_print("\n\t** WiFi AP SSID : %s\n", ssid);
553 error = tethering_wifi_ap_get_passphrase(th, &passphrase);
554 if (error != TETHERING_ERROR_NONE)
557 g_print("\t** WiFi AP passphrase : %s\n", passphrase);
559 error = tethering_wifi_ap_get_ssid_visibility(th, &visibility);
560 if (error != TETHERING_ERROR_NONE)
563 g_print("\t** WiFi AP ssid visibility : %s\n",
564 visibility ? "visible" : "invisible");
566 error = tethering_wifi_ap_get_security_type(th, &security_type);
567 if (error != TETHERING_ERROR_NONE)
570 g_print("\t** WiFi AP security_type : %s\n",
572 TETHERING_WIFI_SECURITY_TYPE_NONE ?
573 "open" : "wpa2-psk");
583 bool __get_tethering_type(tethering_type_e *type)
588 printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:WiFi AP, 5:ALL)\n");
589 ret = scanf("%9d", &sel);
591 printf("scanf is failed!!\n");
597 *type = TETHERING_TYPE_WIFI;
600 *type = TETHERING_TYPE_BT;
603 *type = TETHERING_TYPE_USB;
606 *type = TETHERING_TYPE_RESERVED;
609 *type = TETHERING_TYPE_ALL;
612 printf("Invalid input!!\n");
619 static int test_tethering_create(void)
621 int ret = tethering_create(&th);
622 __tethering_cbs cbs = {
623 __enabled_cb, __disabled_cb,
624 __connection_state_changed_cb, __security_type_changed_cb,
625 __ssid_visibility_changed_cb, __passphrase_changed_cb};
627 if (__is_err(ret) == false) __register_cbs(th, &cbs, NULL);
629 printf("Tethering create is failed\n");
632 printf("Tethering create and register callback success\n");
637 static int test_tethering_destroy(void)
639 int ret = TETHERING_ERROR_NONE;
641 __deregister_cbs(th);
643 ret = tethering_destroy(th);
644 if (__is_err(ret) == true) {
645 printf("Tethering destroy is failed\n");
652 static int test_tethering_enable(void)
654 int ret = TETHERING_ERROR_NONE;
655 tethering_type_e type;
657 if (!__get_tethering_type(&type))
660 ret = tethering_enable(th, type);
661 if (__is_err(ret) == true) {
662 printf("Fail to enable tethering\n");
668 static int test_tethering_disable(void)
670 int ret = TETHERING_ERROR_NONE;
671 tethering_type_e type;
673 if (!__get_tethering_type(&type))
676 ret = tethering_disable(th, type);
677 if (__is_err(ret) == true) {
678 printf("Fail to disable tethering\n");
684 static int test_tethering_get_client_info(void)
687 tethering_type_e type;
689 if (!__get_tethering_type(&type))
692 ret = tethering_foreach_connected_clients(th, type,
693 __clients_foreach_cb, NULL);
694 if (__is_err(ret) == true) {
695 printf("Fail to disable tethering\n");
702 static int test_tethering_get_interface_info(void)
704 tethering_type_e type;
706 if (!__get_tethering_type(&type))
709 __print_interface_info(th, type);
714 static int test_tethering_get_data_usage(void)
716 int ret = tethering_get_data_usage(th, __data_usage_cb, NULL);
718 if (__is_err(ret) == true) {
719 printf("Fail to get data usage!!\n");
726 static int test_tethering_wifi_get_setting(void)
728 __print_wifi_tethering_setting(th);
732 static int test_tethering_wifi_ap_get_setting(void)
734 __print_wifi_ap_setting(th);
738 static int test_tethering_wifi_set_ssid(void)
743 printf("Input SSID for Wi-Fi tethering: ");
744 ret = scanf("%99s", ssid);
746 printf("scanf is failed!!\n");
750 ret = tethering_wifi_set_ssid(th, ssid);
751 if (__is_err(ret) == true) {
752 printf("Fail to set wifi ssid!!\n");
759 static int test_tethering_wifi_set_security_type(void)
764 printf("Input security type for Wi-Fi tethering (0:NONE, 1:WPA2_PSK)");
765 ret = scanf("%9d", &security_type);
767 printf("scanf is failed!!\n");
771 ret = tethering_wifi_set_security_type(th, security_type);
772 if (__is_err(ret) == true) {
773 printf("Fail to set security type!!\n");
780 int test_tethering_wifi_set_visibility(void)
785 printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
786 ret = scanf("%9d", &visibility);
788 printf("scanf is failed!!\n");
792 ret = tethering_wifi_set_ssid_visibility(th, visibility);
793 if (__is_err(ret) == true) {
794 printf("Fail to set visibility!!\n");
801 static int test_tethering_wifi_set_passphrase(void)
804 char passphrase[100];
806 printf("Input passphrase for Wi-Fi tethering: ");
807 ret = scanf("%99s", passphrase);
809 printf("scanf is failed!!\n");
813 ret = tethering_wifi_set_passphrase(th, passphrase);
814 if (__is_err(ret) == true) {
815 printf("Fail to set passphrase!!\n");
822 static int test_tethering_wifi_set_channel(void)
827 printf("Input channel for Wi-Fi tethering: ");
828 ret = scanf("%d", &channel);
830 ret = tethering_wifi_set_channel(th, channel);
831 if (__is_err(ret) == true) {
832 printf("Fail to set channel!!\n");
839 static int test_tethering_wifi_set_mode(void)
844 printf("Input hw_mode for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): ");
845 ret = scanf("%d", &type);
847 ret = tethering_wifi_set_mode(th, type);
848 if (__is_err(ret) == true) {
849 printf("Fail to set mode!!\n");
856 static int test_tethering_wifi_set_mac_filtering(void)
861 printf("Input mac filtering option (0: disable, 1: enable): ");
862 ret = scanf("%d", &enable);
864 ret = tethering_wifi_set_mac_filter(th, enable);
865 if (__is_err(ret) == true) {
866 printf("Fail to set mac filtering!!\n");
873 static int test_tethering_manage_mac_list(void)
879 printf("Select MAC list to modify (0: allowed mac list, 1: blocked mac list): ");
880 ret = scanf("%d", &list);
882 printf("Select option (0: Add, 1: Remove): ");
883 ret = scanf("%d", &option);
885 printf("Input MAC Address to add/remove allowed/blocked mac list: ");
886 ret = scanf("%99s", mac);
888 printf("scanf is failed!!\n");
892 if (!list && !option) {
893 /* Add to allowed mac list*/
894 ret = tethering_wifi_add_allowed_mac_list(th, mac);
895 } else if (!list && option) {
896 /* Remove from allowed mac list */
897 ret = tethering_wifi_remove_allowed_mac_list(th, mac);
898 } else if (list && !option) {
899 /* Add to blocked mac list */
900 ret = tethering_wifi_add_blocked_mac_list(th, mac);
901 } else if (list && option) {
902 /* Remove from blocked mac list */
903 ret = tethering_wifi_remove_blocked_mac_list(th, mac);
905 printf("Input Failed!!\n");
915 static int test_tethering_wifi_ap_set_ssid(void)
920 printf("Input SSID for Wi-Fi AP tethering: ");
921 ret = scanf("%99s", ssid);
923 printf("scanf is failed!!\n");
927 ret = tethering_wifi_ap_set_ssid(th, ssid);
928 if (__is_err(ret) == true) {
929 printf("Fail to set wifi ap ssid!!\n");
935 static int test_tethering_wifi_ap_set_security_type(void)
940 printf("Input security type for Wi-Fi AP tethering (0:NONE, 1:WPA2_PSK)");
941 ret = scanf("%9d", &security_type);
943 printf("scanf is failed!!\n");
947 ret = tethering_wifi_ap_set_security_type(th, security_type);
948 if (__is_err(ret) == true) {
949 printf("Fail to set security type!!\n");
955 static int test_tethering_wifi_ap_set_visibility(void)
960 printf("Input security type for Wi-Fi tethering (0:invisible, 1:visible)");
961 ret = scanf("%9d", &visibility);
963 printf("scanf is failed!!\n");
967 ret = tethering_wifi_ap_set_ssid_visibility(th, visibility);
968 if (__is_err(ret) == true) {
969 printf("Fail to set visibility!!\n");
975 static int test_tethering_wifi_ap_set_passphrase(void)
978 char passphrase[100];
980 printf("Input passphrase for Wi-Fi tethering: ");
981 ret = scanf("%99s", passphrase);
983 printf("scanf is failed!!\n");
987 ret = tethering_wifi_ap_set_passphrase(th, passphrase);
988 if (__is_err(ret) == true) {
989 printf("Fail to set passphrase!!\n");
995 static int test_tethering_wifi_reload_settings(void)
997 int ret = tethering_wifi_reload_settings(th, __settings_reloaded_cb, NULL);
999 if (__is_err(ret) == true) {
1000 printf("Fail to reload wifi tethering!!\n");
1006 static int test_tethering_wifi_ap_reload_settings(void)
1008 int ret = tethering_wifi_ap_reload_settings(th, __settings_reloaded_cb, NULL);
1010 if (__is_err(ret) == true) {
1011 printf("Fail to reload wifi tethering!!\n");
1017 int main(int argc, char **argv)
1019 GMainLoop *mainloop;
1021 #if !GLIB_CHECK_VERSION(2, 36, 0)
1024 mainloop = g_main_loop_new(NULL, false);
1026 GIOChannel *channel = g_io_channel_unix_new(0);
1027 g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL);
1028 printf("Test Thread created...\n");
1029 g_main_loop_run(mainloop);
1034 gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
1039 printf("Event received from stdin\n");
1041 rv = read(0, a, 10);
1043 if (rv <= 0 || a[0] == '0')
1046 if (a[0] == '\n' || a[0] == '\r') {
1047 printf("\n\n Network Connection API Test App\n\n");
1048 printf("Options..\n");
1049 printf("1 - Tethering create and set callbacks\n");
1050 printf("2 - Tethering destroy\n");
1051 printf("3 - Enable Tethering\n");
1052 printf("4 - Disable Tethering\n");
1053 printf("5 - Get client information\n");
1054 printf("6 - Get interface information\n");
1055 printf("7 - Get data usage\n");
1056 printf("8 - Get Wi-Fi tethering setting\n");
1057 printf("9 - Get Wi-Fi AP setting\n");
1058 printf("a - Set Wi-Fi tethering SSID\n");
1059 printf("b - Set Wi-Fi tethering security type\n");
1060 printf("c - Set Wi-Fi tethering visibility\n");
1061 printf("d - Set Wi-Fi tethering passphrase\n");
1062 printf("e - Set Wi-Fi tethering mac filtering\n");
1063 printf("f - Add/Remove MAC adress to/from allowed/blocked list\n");
1064 printf("g - Set Wi-Fi AP SSID\n");
1065 printf("h - Set Wi-Fi AP security type\n");
1066 printf("i - Set Wi-Fi AP visibility\n");
1067 printf("j - Set Wi-Fi AP passphrase\n");
1068 printf("k - Reload Wi-Fi tethering\n");
1069 printf("l - Reload Wi-Fi AP\n");
1070 printf("m - Set Wi-Fi channel\n");
1071 printf("n - Set Wi-Fi hw_mode\n");
1072 printf("0 - Exit \n");
1073 printf("ENTER - Show options menu.......\n");
1078 rv = test_tethering_create();
1081 rv = test_tethering_destroy();
1084 rv = test_tethering_enable();
1087 rv = test_tethering_disable();
1090 rv = test_tethering_get_client_info();
1093 rv = test_tethering_get_interface_info();
1096 rv = test_tethering_get_data_usage();
1099 rv = test_tethering_wifi_get_setting();
1102 rv = test_tethering_wifi_ap_get_setting();
1105 rv = test_tethering_wifi_set_ssid();
1108 rv = test_tethering_wifi_set_security_type();
1111 rv = test_tethering_wifi_set_visibility();
1114 rv = test_tethering_wifi_set_passphrase();
1117 rv = test_tethering_wifi_set_mac_filtering();
1120 rv = test_tethering_manage_mac_list();
1123 rv = test_tethering_wifi_ap_set_ssid();
1126 rv = test_tethering_wifi_ap_set_security_type();
1129 rv = test_tethering_wifi_ap_set_visibility();
1132 rv = test_tethering_wifi_ap_set_passphrase();
1135 rv = test_tethering_wifi_reload_settings();
1138 rv = test_tethering_wifi_ap_reload_settings();
1141 rv = test_tethering_wifi_set_channel();
1144 rv = test_tethering_wifi_set_mode();
1149 printf("Operation succeeded!\n");
1151 printf("Operation failed!\n");