#include "tethering.h"
-#define INPUT_BUF_LEN 32
+#define INPUT_BUF_LEN 128
#define DISABLE_REASON_TEXT_LEN 64
#define COMMON_STR_BUF_LEN 32
switch (type) {
case TETHERING_TYPE_USB:
- g_strlcpy(str_buf, "USB", sizeof(str_buf));
+ g_strlcpy(str_buf, "USB Tethering", sizeof(str_buf));
break;
case TETHERING_TYPE_WIFI:
- g_strlcpy(str_buf, "Wi-Fi", sizeof(str_buf));
+ g_strlcpy(str_buf, "Wi-Fi Tethering", sizeof(str_buf));
break;
case TETHERING_TYPE_BT:
- g_strlcpy(str_buf, "Bluetooth", sizeof(str_buf));
+ g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf));
+ break;
+
+ case TETHERING_TYPE_RESERVED:
+ g_strlcpy(str_buf, "Wi-Fi AP", sizeof(str_buf));
break;
default:
strncpy(str_buf, "disabled due to timeout", sizeof(str_buf));
break;
- case TETHERING_DISABLED_BY_MDM_ON:
- strncpy(str_buf, "disabled due to mdm on", sizeof(str_buf));
- break;
-
case TETHERING_DISABLED_BY_OTHERS:
strncpy(str_buf, "disabled by other apps", sizeof(str_buf));
break;
g_print("tethering_set_enabled_cb is failed\n");
}
+ ret = tethering_set_enabled_cb(th, TETHERING_TYPE_RESERVED,
+ cbs->enabled_cb, user_data);
+ if (__is_err(ret) == true) {
+ g_print("tethering_set_enabled_cb is failed\n");
+ }
+
ret = tethering_set_disabled_cb(th, TETHERING_TYPE_ALL,
cbs->disabled_cb, user_data);
if (__is_err(ret) == true) {
g_print("tethering_set_disabled_cb is failed\n");
}
+ ret = tethering_set_disabled_cb(th, TETHERING_TYPE_RESERVED,
+ cbs->disabled_cb, user_data);
+ if (__is_err(ret) == true) {
+ g_print("tethering_set_disabled_cb is failed\n");
+ }
+
ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_ALL,
cbs->changed_cb, user_data);
if (__is_err(ret) == true) {
g_print("tethering_set_connection_state_changed_cb is failed\n");
}
+ ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED,
+ cbs->changed_cb, user_data);
+ if (__is_err(ret) == true) {
+ g_print("tethering_set_connection_state_changed_cb is failed\n");
+ }
+
ret = tethering_wifi_set_security_type_changed_cb(th,
cbs->security_type_changed_cb, user_data);
if (__is_err(ret) == true) {
g_print("tethering_unset_enabled_cb is failed\n");
}
+ ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_RESERVED);
+ if (__is_err(ret) == true) {
+ g_print("tethering_unset_enabled_cb is failed\n");
+ }
+
ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_ALL);
if (__is_err(ret) == true) {
g_print("tethering_unset_disabled_cb is failed\n");
}
+ ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_RESERVED);
+ if (__is_err(ret) == true) {
+ g_print("tethering_unset_disabled_cb is failed\n");
+ }
+
ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_ALL);
if (__is_err(ret) == true) {
g_print("tethering_unset_connection_state_changed_cb is failed\n");
}
+ ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED);
+ if (__is_err(ret) == true) {
+ g_print("tethering_unset_connection_state_changed_cb is failed\n");
+ }
+
ret = tethering_wifi_unset_security_type_changed_cb(th);
if (__is_err(ret) == true) {
g_print("tethering_wifi_unset_security_type_changed_cb is failed\n");
return;
}
- g_print("## %s tethering is not enabled. error code[0x%X]\n",
+ g_print("## %s is not enabled. error code[0x%X]\n",
__convert_tethering_type_to_str(type),
error);
return;
}
if (is_requested)
- g_print("## %s tethering is enabled successfully\n",
+ g_print("## %s is enabled successfully\n",
__convert_tethering_type_to_str(type));
else
- g_print("## %s tethering is enabled by other app\n",
+ g_print("## %s is enabled by other app\n",
__convert_tethering_type_to_str(type));
return;
return;
}
- g_print("## %s tethering is not disabled. error code[0x%X]\n",
+ g_print("## %s is not disabled. error code[0x%X]\n",
__convert_tethering_type_to_str(type), error);
return;
}
- g_print("## %s tethering is %s\n",
+ g_print("## %s is %s\n",
__convert_tethering_type_to_str(type),
__convert_disabled_code_to_str(code));
return;
}
+static void __settings_reloaded_cb(tethering_error_e result, void *user_data)
+{
+ g_print("__settings_reloaded_cb\n");
+
+ if (result != TETHERING_ERROR_NONE) {
+ g_print("tethering_wifi_reload_settings is failed. error[0x%X]\n", result);
+ return;
+ }
+
+ g_print("## Wi-Fi tethering setting is reloaded\n");
+
+ return;
+}
+
static bool __clients_foreach_cb(tethering_client_h client, void *data)
{
tethering_client_h clone = NULL;
char *subnet_mask = NULL;
if (tethering_is_enabled(th, type) == FALSE) {
- g_print("%s tethering is not enabled\n",
+ g_print("%s is not enabled\n",
__convert_tethering_type_to_str(type));
return;
}
return;
}
+static void __print_wifi_ap_setting(tethering_h th)
+{
+ char *ssid = NULL;
+ char *passphrase = NULL;
+ bool visibility = false;
+ tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE;
+
+ int error = TETHERING_ERROR_NONE;
+
+ error = tethering_wifi_ap_get_ssid(th, &ssid);
+ if (error != TETHERING_ERROR_NONE)
+ __is_err(error);
+ else
+ g_print("\n\t** WiFi AP SSID : %s\n", ssid);
+
+ error = tethering_wifi_ap_get_passphrase(th, &passphrase);
+ if (error != TETHERING_ERROR_NONE)
+ __is_err(error);
+ else
+ g_print("\t** WiFi AP passphrase : %s\n", passphrase);
+
+ error = tethering_wifi_ap_get_ssid_visibility(th, &visibility);
+ if (error != TETHERING_ERROR_NONE)
+ __is_err(error);
+ else
+ g_print("\t** WiFi AP ssid visibility : %s\n",
+ visibility ? "visible" : "invisible");
+
+ error = tethering_wifi_ap_get_security_type(th, &security_type);
+ if (error != TETHERING_ERROR_NONE)
+ __is_err(error);
+ else
+ g_print("\t** WiFi AP security_type : %s\n",
+ security_type ==
+ TETHERING_WIFI_SECURITY_TYPE_NONE ?
+ "open" : "wpa2-psk");
+
+ if (ssid)
+ free(ssid);
+ if (passphrase)
+ free(passphrase);
+
+ return;
+}
+
void print_menu(void)
{
- g_print("\nTo get client information, enter 'clients [USB | WIFI | BT | ALL]'");
- g_print("\nTo get interface information, enter 'info [USB | WIFI | BT]'");
+ g_print("\nTo get client information, enter 'clients [USB | WIFI | BT | AP | ALL]'");
+ g_print("\nTo get interface information, enter 'info [USB | WIFI | BT | AP]'");
g_print("\nTo get data usage, enter 'get data_usage'");
- g_print("\nTo enable tethering, enter 'enable [USB | WIFI | BT | ALL]'");
- g_print("\nTo disable tethering, enter 'disable [USB | WIFI | BT | ALL]'");
+ g_print("\nTo enable tethering, enter 'enable [USB | WIFI | BT | AP | ALL]'");
+ g_print("\nTo disable tethering, enter 'disable [USB | WIFI | BT | AP | ALL]'");
g_print("\nTo get Wi-Fi tethering setting, enter 'get wifi_setting'");
+ g_print("\nTo get Wi-Fi AP setting, enter 'get wifi_ap_setting'");
+ g_print("\nTo reload Wi-Fi tethering setting, enter 'reload wifi_setting'");
+ g_print("\nTo reload Wi-Fi AP setting, enter 'reload wifi_ap_setting'");
g_print("\nTo set Wi-Fi tethering setting, enter '[set_security_type | set_visibility] [0 | 1]'");
+ g_print("\nTo set Wi-Fi AP setting, enter '[set_ap_security_type | set_ap_visibility] [0 | 1]'");
g_print("\nTo set Wi-Fi tethering passphrase, enter 'set_passphrase [passphrase]'");
+ g_print("\nTo set Wi-Fi AP passphrase, enter 'set_ap_passphrase [passphrase]'");
+ g_print("\nTo set Wi-Fi tethering SSID, enter 'set_ssid [SSID]'");
+ g_print("\nTo set Wi-Fi AP SSID, enter 'set_ap_ssid [SSID]'");
+ g_print("\nTo do testing multiple time to create and destroy tethering enter 'do handle_creation_test [number_of_times]'");
g_print("\nTo quit, enter 'quit'\n> ");
return;
gchar *cmd = NULL;
gchar *param = NULL;
gsize read = 0;
+ __tethering_cbs cbs = {
+ __enabled_cb, __disabled_cb,
+ __connection_state_changed_cb, __security_type_changed_cb,
+ __ssid_visibility_changed_cb, __passphrase_changed_cb};
#if !GLIB_CHECK_VERSION(2, 31, 0)
if (g_io_channel_read(channel, buf, INPUT_BUF_LEN, &read) != G_IO_ERROR_NONE) {
}
#else
GError *err = NULL;
+ GIOStatus ios;
- g_io_channel_read_chars(channel, buf, INPUT_BUF_LEN, &read, &err);
+ ios = g_io_channel_read_chars(channel, buf, INPUT_BUF_LEN, &read, &err);
if (err != NULL) {
- g_print("g_io_channel_read is failed : %s\n", err->message);
+ g_print("g_io_channel_read_chars is failed : %s\n",
+ err->message);
g_error_free(err);
return FALSE;
+ } else if (ios != G_IO_STATUS_NORMAL) {
+ g_print("g_io_channel_read_chars is failed : %d\n", ios);
+ return FALSE;
}
#endif
goto DONE;
}
+ if (!strcmp(cmd, "get") && !strcmp(param, "wifi_ap_setting")) {
+ __print_wifi_ap_setting(th);
+ goto DONE;
+ }
+
+ if (!strcmp(cmd, "reload") && !strcmp(param, "wifi_setting")) {
+ error = tethering_wifi_reload_settings(th, __settings_reloaded_cb, NULL);
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_reload_settings is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
+ if (!strcmp(cmd, "reload") && !strcmp(param, "wifi_ap_setting")) {
+ error = tethering_wifi_ap_reload_settings(th, __settings_reloaded_cb, NULL);
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_ap_reload_settings is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
if (!strcmp(cmd, "set_visibility")) {
error = tethering_wifi_set_ssid_visibility(th, atoi(param));
if (error != TETHERING_ERROR_NONE)
goto DONE;
}
+ if (!strcmp(cmd, "set_ap_visibility")) {
+ error = tethering_wifi_ap_set_ssid_visibility(th, atoi(param));
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_ap_set_ssid_visibility is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
if (!strcmp(cmd, "set_security_type")) {
error = tethering_wifi_set_security_type(th, atoi(param));
if (error != TETHERING_ERROR_NONE)
goto DONE;
}
+ if (!strcmp(cmd, "set_ap_security_type")) {
+ error = tethering_wifi_ap_set_security_type(th, atoi(param));
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_ap_set_security_type is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
/* This should be removed */
if (!strcmp(cmd, "set_passphrase")) {
error = tethering_wifi_set_passphrase(th, param);
goto DONE;
}
+ if (!strcmp(cmd, "set_ap_passphrase")) {
+ error = tethering_wifi_ap_set_passphrase(th, param);
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_ap_set_passphrase is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
+ if (!strcmp(cmd, "set_ssid")) {
+ error = tethering_wifi_set_ssid(th, param);
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_set_ssid is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
+ if (!strcmp(cmd, "set_ap_ssid")) {
+ error = tethering_wifi_ap_set_ssid(th, param);
+ if (error != TETHERING_ERROR_NONE)
+ g_print("tethering_wifi_ap_set_ssid is failed [0x%X]\n",
+ error);
+ goto DONE;
+ }
+
+ if (!strcmp(cmd, "do handle_creation_test")) {
+ int count = 0;
+ int i = 0;
+ count = atoi(param);
+ g_print("testing %d times....\n", count);
+ while (count > 0) {
+ sleep(3);
+ g_print("Destroying tethering %dth time\n", i);
+ if (NULL != th) {
+ __deregister_cbs(th);
+
+ error = tethering_destroy(th);
+
+ if (__is_err(error) == true) {
+ return 0;
+ }
+ }
+ sleep(3);
+ g_print("Creating tethering %dth time\n", i);
+ error = tethering_create(&th);
+ if (__is_err(error) == true) {
+ return 0;
+ }
+ __register_cbs(th, &cbs, NULL);
+ i++;
+ count--;
+ }
+ goto DONE;
+ }
+
/* One parameter(type) */
if (!strcmp(param, "USB"))
type = TETHERING_TYPE_USB;
type = TETHERING_TYPE_WIFI;
else if (!strcmp(param, "BT"))
type = TETHERING_TYPE_BT;
+ else if (!strcmp(param, "AP"))
+ type = TETHERING_TYPE_RESERVED;
else if (!strcmp(param, "ALL"))
type = TETHERING_TYPE_ALL;
else {
__connection_state_changed_cb, __security_type_changed_cb,
__ssid_visibility_changed_cb, __passphrase_changed_cb};
+#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init();
+#endif
/* Create tethering handle */
ret = tethering_create(&th);
return 0;
}
-