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 INPUT_BUF_LEN 128
32 #define DISABLE_REASON_TEXT_LEN 64
33 #define COMMON_STR_BUF_LEN 32
36 tethering_enabled_cb enabled_cb;
37 tethering_disabled_cb disabled_cb;
38 tethering_connection_state_changed_cb changed_cb;
39 tethering_wifi_security_type_changed_cb security_type_changed_cb;
40 tethering_wifi_ssid_visibility_changed_cb ssid_visibility_changed_cb;
41 tethering_wifi_passphrase_changed_cb passphrase_changed_cb;
44 static GMainLoop *mainloop = NULL;
46 static bool __is_err(tethering_error_e ret)
51 case TETHERING_ERROR_INVALID_PARAMETER:
52 err_msg = "Wrong parameter is used";
55 case TETHERING_ERROR_OUT_OF_MEMORY:
56 err_msg = "Memory is not enough";
59 case TETHERING_ERROR_NONE:
62 case TETHERING_ERROR_NOT_ENABLED:
63 err_msg = "Tethering is not enabled";
66 case TETHERING_ERROR_OPERATION_FAILED:
67 err_msg = "Operation is failed";
70 case TETHERING_ERROR_RESOURCE_BUSY:
71 err_msg = "Resource is busy";
75 err_msg = "This should not be happened";
79 g_print("%s\n", err_msg);
84 static const char *__convert_tethering_type_to_str(const tethering_type_e type)
86 static char str_buf[COMMON_STR_BUF_LEN] = {0, };
89 case TETHERING_TYPE_USB:
90 g_strlcpy(str_buf, "USB Tethering", sizeof(str_buf));
93 case TETHERING_TYPE_WIFI:
94 g_strlcpy(str_buf, "Wi-Fi Tethering", sizeof(str_buf));
97 case TETHERING_TYPE_BT:
98 g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf));
101 case TETHERING_TYPE_RESERVED:
102 g_strlcpy(str_buf, "Wi-Fi AP", sizeof(str_buf));
106 g_strlcpy(str_buf, "Unknown", sizeof(str_buf));
113 static const char *__convert_disabled_code_to_str(const tethering_disabled_cause_e code)
115 static char str_buf[DISABLE_REASON_TEXT_LEN] = {0, };
118 case TETHERING_DISABLED_BY_USB_DISCONNECTION:
119 strncpy(str_buf, "disabled due to usb disconnection", sizeof(str_buf));
122 case TETHERING_DISABLED_BY_FLIGHT_MODE:
123 strncpy(str_buf, "disabled due to flight mode on", sizeof(str_buf));
126 case TETHERING_DISABLED_BY_LOW_BATTERY:
127 strncpy(str_buf, "disabled due to low battery", sizeof(str_buf));
130 case TETHERING_DISABLED_BY_NETWORK_CLOSE:
131 strncpy(str_buf, "disabled due to pdp network close", sizeof(str_buf));
134 case TETHERING_DISABLED_BY_TIMEOUT:
135 strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
138 case TETHERING_DISABLED_BY_OTHERS:
139 strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
142 case TETHERING_DISABLED_BY_REQUEST:
143 strncpy(str_buf, "disabled by my request", sizeof(str_buf));
146 case TETHERING_DISABLED_BY_WIFI_ON:
147 strncpy(str_buf, "disabled by Wi-Fi station on", sizeof(str_buf));
150 case TETHERING_DISABLED_BY_BT_OFF:
151 strncpy(str_buf, "disabled by bluetooth off", sizeof(str_buf));
155 strncpy(str_buf, "disabled by unknown reason", sizeof(str_buf));
162 static void __register_cbs(tethering_h th, __tethering_cbs *cbs, void *user_data)
164 tethering_error_e ret = TETHERING_ERROR_NONE;
166 ret = tethering_set_enabled_cb(th, TETHERING_TYPE_ALL,
167 cbs->enabled_cb, user_data);
168 if (__is_err(ret) == true) {
169 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");
178 ret = tethering_set_disabled_cb(th, TETHERING_TYPE_ALL,
179 cbs->disabled_cb, user_data);
180 if (__is_err(ret) == true) {
181 g_print("tethering_set_disabled_cb is failed\n");
184 ret = tethering_set_disabled_cb(th, TETHERING_TYPE_RESERVED,
185 cbs->disabled_cb, user_data);
186 if (__is_err(ret) == true) {
187 g_print("tethering_set_disabled_cb is failed\n");
190 ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_ALL,
191 cbs->changed_cb, user_data);
192 if (__is_err(ret) == true) {
193 g_print("tethering_set_connection_state_changed_cb is failed\n");
196 ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED,
197 cbs->changed_cb, user_data);
198 if (__is_err(ret) == true) {
199 g_print("tethering_set_connection_state_changed_cb is failed\n");
202 ret = tethering_wifi_set_security_type_changed_cb(th,
203 cbs->security_type_changed_cb, user_data);
204 if (__is_err(ret) == true) {
205 g_print("tethering_wifi_set_security_type_changed_cb is failed\n");
208 ret = tethering_wifi_set_ssid_visibility_changed_cb(th,
209 cbs->ssid_visibility_changed_cb, user_data);
210 if (__is_err(ret) == true) {
211 g_print("tethering_wifi_set_ssid_visibility_changed_cb is failed\n");
214 ret = tethering_wifi_set_passphrase_changed_cb(th,
215 cbs->passphrase_changed_cb, user_data);
216 if (__is_err(ret) == true) {
217 g_print("tethering_wifi_set_passphrase_changed_cb is failed\n");
223 static void __deregister_cbs(tethering_h th)
225 tethering_error_e ret = TETHERING_ERROR_NONE;
227 ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_ALL);
228 if (__is_err(ret) == true) {
229 g_print("tethering_unset_enabled_cb is failed\n");
232 ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_RESERVED);
233 if (__is_err(ret) == true) {
234 g_print("tethering_unset_enabled_cb is failed\n");
237 ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_ALL);
238 if (__is_err(ret) == true) {
239 g_print("tethering_unset_disabled_cb is failed\n");
242 ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_RESERVED);
243 if (__is_err(ret) == true) {
244 g_print("tethering_unset_disabled_cb is failed\n");
247 ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_ALL);
248 if (__is_err(ret) == true) {
249 g_print("tethering_unset_connection_state_changed_cb is failed\n");
252 ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED);
253 if (__is_err(ret) == true) {
254 g_print("tethering_unset_connection_state_changed_cb is failed\n");
257 ret = tethering_wifi_unset_security_type_changed_cb(th);
258 if (__is_err(ret) == true) {
259 g_print("tethering_wifi_unset_security_type_changed_cb is failed\n");
262 ret = tethering_wifi_unset_ssid_visibility_changed_cb(th);
263 if (__is_err(ret) == true) {
264 g_print("tethering_wifi_unset_ssid_visibility_changed_cb is failed\n");
267 ret = tethering_wifi_unset_passphrase_changed_cb(th);
268 if (__is_err(ret) == true) {
269 g_print("tethering_wifi_unset_passphrase_changed_cb is failed\n");
275 /* Tethering callbacks */
276 static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is_requested, void *data)
278 if (error != TETHERING_ERROR_NONE) {
283 g_print("## %s is not enabled. error code[0x%X]\n",
284 __convert_tethering_type_to_str(type),
290 g_print("## %s is enabled successfully\n",
291 __convert_tethering_type_to_str(type));
293 g_print("## %s is enabled by other app\n",
294 __convert_tethering_type_to_str(type));
299 static void __disabled_cb(tethering_error_e error, tethering_type_e type, tethering_disabled_cause_e code, void *data)
301 if (error != TETHERING_ERROR_NONE) {
302 if (code != TETHERING_DISABLED_BY_REQUEST) {
306 g_print("## %s is not disabled. error code[0x%X]\n",
307 __convert_tethering_type_to_str(type), error);
311 g_print("## %s is %s\n",
312 __convert_tethering_type_to_str(type),
313 __convert_disabled_code_to_str(code));
318 static void __connection_state_changed_cb(tethering_client_h client, bool open, void *data)
320 tethering_client_h clone = NULL;
321 tethering_type_e type;
322 char *ip_address = NULL;
323 char *mac_address = NULL;
324 char *hostname = NULL;
326 tethering_client_clone(&clone, client);
328 g_print("tetheirng_client_clone is failed\n");
332 tethering_client_get_tethering_type(clone, &type);
333 tethering_client_get_ip_address(clone,
334 TETHERING_ADDRESS_FAMILY_IPV4, &ip_address);
335 tethering_client_get_mac_address(clone, &mac_address);
336 tethering_client_get_name(clone, &hostname);
339 g_print("## New station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
340 __convert_tethering_type_to_str(type),
341 ip_address, mac_address, hostname);
343 g_print("## Disconnected station Type [%s], IP [%s], MAC [%s], hostname [%s]\n",
344 __convert_tethering_type_to_str(type),
345 ip_address, mac_address, hostname);
355 tethering_client_destroy(clone);
360 static void __data_usage_cb(tethering_error_e result, unsigned long long received_data,
361 unsigned long long sent_data, void *user_data)
363 g_print("__data_usage_cb\n");
365 if (result != TETHERING_ERROR_NONE) {
366 g_print("tethering_get_data_usage is failed. error[0x%X]\n", result);
370 g_print("## Received data : %llu bytes\n", received_data);
371 g_print("## Sent data : %llu bytes\n", sent_data);
376 static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
378 g_print("__settings_reloaded_cb\n");
380 if (result != TETHERING_ERROR_NONE) {
381 g_print("tethering_wifi_reload_settings is failed. error[0x%X]\n", result);
385 g_print("## Wi-Fi tethering setting is reloaded\n");
390 static bool __clients_foreach_cb(tethering_client_h client, void *data)
392 tethering_client_h clone = NULL;
393 tethering_type_e type;
394 char *ip_address = NULL;
395 char *mac_address = NULL;
396 char *hostname = NULL;
398 /* Clone internal information */
399 if (tethering_client_clone(&clone, client) != TETHERING_ERROR_NONE) {
400 g_print("tethering_client_clone is failed\n");
404 /* Get information */
405 if (tethering_client_get_tethering_type(clone, &type) != TETHERING_ERROR_NONE) {
406 g_print("tethering_client_get_type is failed\n");
409 if (tethering_client_get_ip_address(clone, TETHERING_ADDRESS_FAMILY_IPV4, &ip_address) != TETHERING_ERROR_NONE) {
410 g_print("tethering_client_get_ip_address is failed\n");
413 if (tethering_client_get_mac_address(clone, &mac_address) != TETHERING_ERROR_NONE) {
414 g_print("tethering_client_get_mac_address is failed\n");
417 if (tethering_client_get_name(clone, &hostname) != TETHERING_ERROR_NONE) {
418 g_print("tethering_client_get_hostname is failed\n");
420 /* End of getting information */
422 g_print("\n< Client Info. >\n");
423 g_print("\tType %s\n", __convert_tethering_type_to_str(type));
424 g_print("\tIP Address %s\n", ip_address);
425 g_print("\tMAC Address : %s\n", mac_address);
426 g_print("\tHostname : %s\n", hostname);
428 /* Destroy cloned objects */
436 tethering_client_destroy(clone);
438 /* Continue iteration */
442 static void __security_type_changed_cb(tethering_wifi_security_type_e changed_type, void *user_data)
444 g_print("Wi-Fi Tethering Security type is changed to [%s]\n",
445 changed_type == TETHERING_WIFI_SECURITY_TYPE_NONE ?
446 "open" : "wpa2-psk");
450 static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
452 g_print("SSID visibility for Wi-Fi tethering changed to [%s]\n",
453 changed_visible ? "visible" : "invisible");
457 static void __passphrase_changed_cb(void *user_data)
459 g_print("Wi-Fi Tethering passphrase is changed\n");
462 /* End of tethering callbacks */
464 static void __enable_tethering(tethering_h th, tethering_type_e type)
469 tethering_error_e error = TETHERING_ERROR_NONE;
471 error = tethering_enable(th, type);
477 static void __disable_tethering(tethering_h th, tethering_type_e type)
482 tethering_error_e error = TETHERING_ERROR_NONE;
484 error = tethering_disable(th, type);
490 static void __print_interface_info(tethering_h th, tethering_type_e type)
492 char *interface = NULL;
493 char *mac_address = NULL;
494 char *ip_address = NULL;
495 char *gateway_address = NULL;
496 char *subnet_mask = NULL;
498 if (tethering_is_enabled(th, type) == FALSE) {
499 g_print("%s is not enabled\n",
500 __convert_tethering_type_to_str(type));
504 tethering_get_network_interface_name(th, type, &interface);
505 tethering_get_mac_address(th, type, &mac_address);
506 tethering_get_ip_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
508 tethering_get_gateway_address(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
510 tethering_get_subnet_mask(th, type, TETHERING_ADDRESS_FAMILY_IPV4,
513 g_print("interface name : %s\n", interface);
514 g_print("mac address : %s\n", mac_address);
515 g_print("ip address : %s\n", ip_address);
516 g_print("gateway address: %s\n", gateway_address);
517 g_print("subnet mask : %s\n", subnet_mask);
526 free(gateway_address);
533 static void __print_wifi_tethering_setting(tethering_h th)
536 char *passphrase = NULL;
537 bool visibility = false;
538 tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
540 int error = TETHERING_ERROR_NONE;
542 error = tethering_wifi_get_ssid(th, &ssid);
543 if (error != TETHERING_ERROR_NONE)
546 g_print("\n\t** WiFi tethering SSID : %s\n", ssid);
548 error = tethering_wifi_get_passphrase(th, &passphrase);
549 if (error != TETHERING_ERROR_NONE)
552 g_print("\t** WiFi tethering passphrase : %s\n", passphrase);
554 error = tethering_wifi_get_ssid_visibility(th, &visibility);
555 if (error != TETHERING_ERROR_NONE)
558 g_print("\t** WiFi tethering ssid visibility : %s\n",
559 visibility ? "visible" : "invisible");
561 error = tethering_wifi_get_security_type(th, &security_type);
562 if (error != TETHERING_ERROR_NONE)
565 g_print("\t** WiFi tethering security_type : %s\n",
567 TETHERING_WIFI_SECURITY_TYPE_NONE ?
568 "open" : "wpa2-psk");
578 static void __print_wifi_ap_setting(tethering_h th)
581 char *passphrase = NULL;
582 bool visibility = false;
583 tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
585 int error = TETHERING_ERROR_NONE;
587 error = tethering_wifi_ap_get_ssid(th, &ssid);
588 if (error != TETHERING_ERROR_NONE)
591 g_print("\n\t** WiFi AP SSID : %s\n", ssid);
593 error = tethering_wifi_ap_get_passphrase(th, &passphrase);
594 if (error != TETHERING_ERROR_NONE)
597 g_print("\t** WiFi AP passphrase : %s\n", passphrase);
599 error = tethering_wifi_ap_get_ssid_visibility(th, &visibility);
600 if (error != TETHERING_ERROR_NONE)
603 g_print("\t** WiFi AP ssid visibility : %s\n",
604 visibility ? "visible" : "invisible");
606 error = tethering_wifi_ap_get_security_type(th, &security_type);
607 if (error != TETHERING_ERROR_NONE)
610 g_print("\t** WiFi AP security_type : %s\n",
612 TETHERING_WIFI_SECURITY_TYPE_NONE ?
613 "open" : "wpa2-psk");
623 void print_menu(void)
625 g_print("\nTo get client information, enter 'clients [USB | WIFI | BT | AP | ALL]'");
626 g_print("\nTo get interface information, enter 'info [USB | WIFI | BT | AP]'");
627 g_print("\nTo get data usage, enter 'get data_usage'");
628 g_print("\nTo enable tethering, enter 'enable [USB | WIFI | BT | AP | ALL]'");
629 g_print("\nTo disable tethering, enter 'disable [USB | WIFI | BT | AP | ALL]'");
630 g_print("\nTo get Wi-Fi tethering setting, enter 'get wifi_setting'");
631 g_print("\nTo get Wi-Fi AP setting, enter 'get wifi_ap_setting'");
632 g_print("\nTo reload Wi-Fi tethering setting, enter 'reload wifi_setting'");
633 g_print("\nTo reload Wi-Fi AP setting, enter 'reload wifi_ap_setting'");
634 g_print("\nTo set Wi-Fi tethering setting, enter '[set_security_type | set_visibility] [0 | 1]'");
635 g_print("\nTo set Wi-Fi AP setting, enter '[set_ap_security_type | set_ap_visibility] [0 | 1]'");
636 g_print("\nTo set Wi-Fi tethering passphrase, enter 'set_passphrase [passphrase]'");
637 g_print("\nTo set Wi-Fi AP passphrase, enter 'set_ap_passphrase [passphrase]'");
638 g_print("\nTo set Wi-Fi tethering SSID, enter 'set_ssid [SSID]'");
639 g_print("\nTo set Wi-Fi AP SSID, enter 'set_ap_ssid [SSID]'");
640 g_print("\nTo do testing multiple time to create and destroy tethering enter 'do handle_creation_test [number_of_times]'");
641 g_print("\nTo quit, enter 'quit'\n> ");
646 gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data)
648 tethering_h th = (tethering_h)data;
649 tethering_type_e type = 0;
650 tethering_error_e error = 0;
651 gchar buf[INPUT_BUF_LEN] = {0, };
655 __tethering_cbs cbs = {
656 __enabled_cb, __disabled_cb,
657 __connection_state_changed_cb, __security_type_changed_cb,
658 __ssid_visibility_changed_cb, __passphrase_changed_cb};
660 #if !GLIB_CHECK_VERSION(2, 31, 0)
661 if (g_io_channel_read(channel, buf, INPUT_BUF_LEN, &read) != G_IO_ERROR_NONE) {
662 g_print("g_io_channel_read is failed\n");
669 ios = g_io_channel_read_chars(channel, buf, INPUT_BUF_LEN, &read, &err);
671 g_print("g_io_channel_read_chars is failed : %s\n",
675 } else if (ios != G_IO_STATUS_NORMAL) {
676 g_print("g_io_channel_read_chars is failed : %d\n", ios);
685 param = strrchr(buf, ' ');
688 if (!strcmp(cmd, "quit")) {
689 g_main_loop_quit(mainloop);
700 /* One parameter except type */
701 if (!strcmp(cmd, "get") && !strcmp(param, "data_usage")) {
702 error = tethering_get_data_usage(th, __data_usage_cb, NULL);
703 if (error != TETHERING_ERROR_NONE)
704 g_print("tethering_get_data_usage is failed [0x%X]\n",
709 if (!strcmp(cmd, "get") && !strcmp(param, "wifi_setting")) {
710 __print_wifi_tethering_setting(th);
714 if (!strcmp(cmd, "get") && !strcmp(param, "wifi_ap_setting")) {
715 __print_wifi_ap_setting(th);
719 if (!strcmp(cmd, "reload") && !strcmp(param, "wifi_setting")) {
720 error = tethering_wifi_reload_settings(th, __settings_reloaded_cb, NULL);
721 if (error != TETHERING_ERROR_NONE)
722 g_print("tethering_wifi_reload_settings is failed [0x%X]\n",
727 if (!strcmp(cmd, "reload") && !strcmp(param, "wifi_ap_setting")) {
728 error = tethering_wifi_ap_reload_settings(th, __settings_reloaded_cb, NULL);
729 if (error != TETHERING_ERROR_NONE)
730 g_print("tethering_wifi_ap_reload_settings is failed [0x%X]\n",
735 if (!strcmp(cmd, "set_visibility")) {
736 error = tethering_wifi_set_ssid_visibility(th, atoi(param));
737 if (error != TETHERING_ERROR_NONE)
738 g_print("tethering_wifi_set_ssid_visibility is failed [0x%X]\n",
743 if (!strcmp(cmd, "set_ap_visibility")) {
744 error = tethering_wifi_ap_set_ssid_visibility(th, atoi(param));
745 if (error != TETHERING_ERROR_NONE)
746 g_print("tethering_wifi_ap_set_ssid_visibility is failed [0x%X]\n",
751 if (!strcmp(cmd, "set_security_type")) {
752 error = tethering_wifi_set_security_type(th, atoi(param));
753 if (error != TETHERING_ERROR_NONE)
754 g_print("tethering_wifi_set_security_type is failed [0x%X]\n",
759 if (!strcmp(cmd, "set_ap_security_type")) {
760 error = tethering_wifi_ap_set_security_type(th, atoi(param));
761 if (error != TETHERING_ERROR_NONE)
762 g_print("tethering_wifi_ap_set_security_type is failed [0x%X]\n",
767 /* This should be removed */
768 if (!strcmp(cmd, "set_passphrase")) {
769 error = tethering_wifi_set_passphrase(th, param);
770 if (error != TETHERING_ERROR_NONE)
771 g_print("tethering_wifi_set_passphrase is failed [0x%X]\n",
776 if (!strcmp(cmd, "set_ap_passphrase")) {
777 error = tethering_wifi_ap_set_passphrase(th, param);
778 if (error != TETHERING_ERROR_NONE)
779 g_print("tethering_wifi_ap_set_passphrase is failed [0x%X]\n",
784 if (!strcmp(cmd, "set_ssid")) {
785 error = tethering_wifi_set_ssid(th, param);
786 if (error != TETHERING_ERROR_NONE)
787 g_print("tethering_wifi_set_ssid is failed [0x%X]\n",
792 if (!strcmp(cmd, "set_ap_ssid")) {
793 error = tethering_wifi_ap_set_ssid(th, param);
794 if (error != TETHERING_ERROR_NONE)
795 g_print("tethering_wifi_ap_set_ssid is failed [0x%X]\n",
800 if (!strcmp(cmd, "do handle_creation_test")) {
804 g_print("testing %d times....\n", count);
807 g_print("Destroying tethering %dth time\n", i);
809 __deregister_cbs(th);
811 error = tethering_destroy(th);
813 if (__is_err(error) == true) {
818 g_print("Creating tethering %dth time\n", i);
819 error = tethering_create(&th);
820 if (__is_err(error) == true) {
823 __register_cbs(th, &cbs, NULL);
830 /* One parameter(type) */
831 if (!strcmp(param, "USB"))
832 type = TETHERING_TYPE_USB;
833 else if (!strcmp(param, "WIFI"))
834 type = TETHERING_TYPE_WIFI;
835 else if (!strcmp(param, "BT"))
836 type = TETHERING_TYPE_BT;
837 else if (!strcmp(param, "AP"))
838 type = TETHERING_TYPE_RESERVED;
839 else if (!strcmp(param, "ALL"))
840 type = TETHERING_TYPE_ALL;
845 if (!strcmp(cmd, "clients")) {
846 error = tethering_foreach_connected_clients(th, type,
847 __clients_foreach_cb, NULL);
848 if (error != TETHERING_ERROR_NONE)
849 g_print("tethering_get_data_usage is failed [0x%X]\n",
851 } else if (!strcmp(cmd, "info")) {
852 __print_interface_info(th, type);
853 } else if (!strcmp(cmd, "enable")) {
854 __enable_tethering(th, type);
855 } else if (!strcmp(cmd, "disable")) {
856 __disable_tethering(th, type);
866 int main(int argc, char *argv[])
868 tethering_h th = NULL;
869 GIOChannel *stdin_channel = NULL;
870 tethering_error_e ret = TETHERING_ERROR_NONE;
871 __tethering_cbs cbs = {
872 __enabled_cb, __disabled_cb,
873 __connection_state_changed_cb, __security_type_changed_cb,
874 __ssid_visibility_changed_cb, __passphrase_changed_cb};
876 #if !GLIB_CHECK_VERSION(2,36,0)
880 /* Create tethering handle */
881 ret = tethering_create(&th);
882 if (__is_err(ret) == true)
886 __register_cbs(th, &cbs, NULL);
888 stdin_channel = g_io_channel_unix_new(0);
889 if (stdin_channel == NULL)
892 g_io_channel_set_encoding(stdin_channel, NULL, NULL);
893 g_io_channel_set_flags(stdin_channel,
894 G_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK, NULL);
896 g_io_add_watch(stdin_channel, G_IO_IN, input, (gpointer)th);
900 mainloop = g_main_loop_new (NULL, 0);
902 g_main_loop_run(mainloop);
903 g_main_loop_unref(mainloop);
906 __deregister_cbs(th);
908 /* Destroy tethering handle */
909 ret = tethering_destroy(th);