From 49586aa2baca979d09a7ba69e054b34073c6b248 Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Fri, 18 Sep 2020 03:23:35 +0530 Subject: [PATCH] Replace usage of enum 'TETHERING_TYPE_WIFI_SHARING' As wifi-sharing is the property of wifi tethering (TETHERING_TYPE_WIFI), so use API 'tethering_wifi_set_sharing' to enable wifi-sharing instead of using enum 'TETHERING_TYPE_WIFI_SHARING'. Change-Id: I6624cc57758eecdc7210f5ff8c6bc36976968bec Signed-off-by: Niraj Kumar Goit --- include/tethering.h | 1 - include/tethering_private.h | 4 -- packaging/capi-network-tethering.spec | 2 +- src/tethering.c | 100 +++++++++++----------------------- tools/tethering_test.c | 47 +++++++++++----- 5 files changed, 66 insertions(+), 88 deletions(-) diff --git a/include/tethering.h b/include/tethering.h index fb9d874..999c17f 100644 --- a/include/tethering.h +++ b/include/tethering.h @@ -66,7 +66,6 @@ typedef enum { TETHERING_TYPE_WIFI, /**< Wi-Fi type */ TETHERING_TYPE_BT, /**< BT type */ TETHERING_TYPE_P2P, /**< P2P type */ - TETHERING_TYPE_WIFI_SHARING, /**< Wi-Fi Sharing */ TETHERING_TYPE_MAX, /**< Maximum */ } tethering_type_e; diff --git a/include/tethering_private.h b/include/tethering_private.h index 1f87420..e5797c1 100644 --- a/include/tethering_private.h +++ b/include/tethering_private.h @@ -335,10 +335,6 @@ typedef struct { unsigned int txpower; } _softap_settings_t; -typedef struct { - bool flag; -} tethering_request_table_t; - void _tethering_add_handle(tethering_h handle); void _tethering_remove_handle(tethering_h handle); bool _tethering_check_handle(tethering_h handle); diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index c7aa33b..bc7a90f 100644 --- a/packaging/capi-network-tethering.spec +++ b/packaging/capi-network-tethering.spec @@ -1,6 +1,6 @@ Name: capi-network-tethering Summary: Tethering Framework -Version: 1.1.3 +Version: 1.1.4 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/tethering.c b/src/tethering.c index 8f0b034..0fca757 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -144,7 +144,6 @@ static __tethering_sig_t sigs[] = { static int retry = 0; static int is_dualband_support = DUAL_BAND_NONE; -static __thread tethering_request_table_t request_table[TETHERING_TYPE_MAX]; static void __reset_dualband_support(void) { @@ -184,7 +183,6 @@ static bool __any_tethering_is_enabled(tethering_h tethering) { if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) || tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) || - tethering_is_enabled(tethering, TETHERING_TYPE_WIFI_SHARING) || tethering_is_enabled(tethering, TETHERING_TYPE_BT) || tethering_is_enabled(tethering, TETHERING_TYPE_P2P)) return true; @@ -395,12 +393,9 @@ static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name, if (ap_type == MOBILE_AP_TYPE_USB) type = TETHERING_TYPE_USB; - else if (ap_type == MOBILE_AP_TYPE_WIFI) { - if (request_table[TETHERING_TYPE_WIFI_SHARING].flag) - type = TETHERING_TYPE_WIFI_SHARING; - else - type = TETHERING_TYPE_WIFI; - } else if (ap_type == MOBILE_AP_TYPE_BT) + else if (ap_type == MOBILE_AP_TYPE_WIFI) + type = TETHERING_TYPE_WIFI; + else if (ap_type == MOBILE_AP_TYPE_BT) type = TETHERING_TYPE_BT; else if (ap_type == MOBILE_AP_TYPE_P2P) type = TETHERING_TYPE_P2P; @@ -797,15 +792,10 @@ static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, GError *g_error = NULL; GVariant *g_var; guint info; - tethering_type_e type = 0; + tethering_type_e type = TETHERING_TYPE_WIFI; tethering_error_e error; __tethering_h *th = (__tethering_h *)user_data; - if (request_table[TETHERING_TYPE_WIFI_SHARING].flag) - type = TETHERING_TYPE_WIFI_SHARING; - else - type = TETHERING_TYPE_WIFI; - tethering_enabled_cb ecb = th->enabled_cb[type]; void *data = th->enabled_user_data[type]; @@ -1406,7 +1396,7 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se return TETHERING_ERROR_NONE; } -static bool __check_precondition(tethering_type_e type) +static bool __check_precondition(__tethering_h *th, tethering_type_e type) { int dnet_status = 0; int cellular_state = 0; @@ -1422,8 +1412,9 @@ static bool __check_precondition(tethering_type_e type) vconf_get_int(VCONFKEY_NETWORK_STATUS, &dnet_status); if ((dnet_status == VCONFKEY_NETWORK_WIFI && type != TETHERING_TYPE_WIFI) - || (dnet_status == VCONFKEY_NETWORK_ETHERNET - && type != TETHERING_TYPE_WIFI_SHARING)) + || (th->wifi_sharing && dnet_status == VCONFKEY_NETWORK_WIFI + && type == TETHERING_TYPE_WIFI) + || dnet_status == VCONFKEY_NETWORK_ETHERNET) return TRUE; ERR("Network is not available!"); @@ -1613,8 +1604,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) INFO("+ type : %d\n", type); CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1631,7 +1621,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE); #endif /* TIZEN_TV_EXT */ - if (__check_precondition(type) == FALSE) { + if (__check_precondition(th, type) == FALSE) { INFO("-\n"); g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); return TETHERING_ERROR_OPERATION_FAILED; @@ -1648,8 +1638,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering); break; - case TETHERING_TYPE_WIFI: - case TETHERING_TYPE_WIFI_SHARING: { + case TETHERING_TYPE_WIFI: { _softap_settings_t set = {"", "", "", 0, false}; ret = __prepare_wifi_settings(tethering, &set); @@ -1665,15 +1654,11 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type, set.max_connected); - char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; - if (type == TETHERING_TYPE_WIFI_SHARING) { - g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN); - request_table[TETHERING_TYPE_WIFI_SHARING].flag = true; - } else { - g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN); - request_table[TETHERING_TYPE_WIFI].flag = true; - } + char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = "wifi_tether"; + if (th->wifi_sharing) + g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1); + SINFO("enable_wifi_tethering key: %s", key); g_dbus_proxy_call(proxy, "enable_wifi_tethering", g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, @@ -1783,7 +1768,7 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type) g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE); - if (__check_precondition(type) == FALSE) { + if (__check_precondition(th, type) == FALSE) { DBG("-\n"); g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); return TETHERING_ERROR_OPERATION_FAILED; @@ -1801,8 +1786,7 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type) break; } - case TETHERING_TYPE_WIFI: - case TETHERING_TYPE_WIFI_SHARING: { + case TETHERING_TYPE_WIFI: { _softap_settings_t set = {"", "", "", 0, false, false, 0, 0}; ret = __prepare_wifi_settings(tethering, &set); @@ -1819,15 +1803,11 @@ API int tethering_ipv6_enable(tethering_h tethering, tethering_type_e type) set.ssid, set.key, set.channel, set.mode, set.txpower, set.sec_type, set.max_connected); - char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; - if (type == TETHERING_TYPE_WIFI_SHARING) { - g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN); - request_table[TETHERING_TYPE_WIFI_SHARING].flag = true; - } else { - g_strlcpy(key, "wifi_tether", TETHERING_WIFI_KEY_MAX_LEN); - request_table[TETHERING_TYPE_WIFI].flag = true; - } + char key[TETHERING_WIFI_KEY_MAX_LEN + 1] = "wifi_tether"; + if (th->wifi_sharing) + g_strlcpy(key, "wifi_sharing", TETHERING_WIFI_KEY_MAX_LEN + 1); + SINFO("enable_wifi_tethering key: %s", key); g_dbus_proxy_call(proxy, "enable_wifi_tethering", g_variant_new("(ssssiiiiiii)", key, set.ssid, set.key, set.mode, set.channel, set.visibility, set.mac_filter, set.max_connected, @@ -1891,7 +1871,6 @@ API int tethering_ipv6_disable(tethering_h tethering, tethering_type_e type) break; case TETHERING_TYPE_WIFI: - case TETHERING_TYPE_WIFI_SHARING: DBG("Disable wifi tethering.."); g_dbus_connection_signal_unsubscribe(connection, sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id); @@ -1963,8 +1942,6 @@ API int tethering_disable(tethering_h tethering, tethering_type_e type) break; case TETHERING_TYPE_WIFI: - case TETHERING_TYPE_WIFI_SHARING: - g_dbus_connection_signal_unsubscribe(connection, sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id); @@ -2055,7 +2032,6 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type) break; case TETHERING_TYPE_WIFI: - case TETHERING_TYPE_WIFI_SHARING: vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI; break; @@ -2407,8 +2383,7 @@ API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb API int tethering_is_dualband_supported(tethering_h tethering, tethering_type_e type, bool *supported) { CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); - if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -2474,8 +2449,7 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ { CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2520,13 +2494,9 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ interface = g_variant_get_int32(value); if (interface == MOBILE_AP_TYPE_USB) client.interface = TETHERING_TYPE_USB; - else if (interface == MOBILE_AP_TYPE_WIFI) { - if (request_table[TETHERING_TYPE_WIFI_SHARING].flag) - client.interface = TETHERING_TYPE_WIFI_SHARING; - else - client.interface = TETHERING_TYPE_WIFI; - - } else if (interface == MOBILE_AP_TYPE_BT) + else if (interface == MOBILE_AP_TYPE_WIFI) + client.interface = TETHERING_TYPE_WIFI; + else if (interface == MOBILE_AP_TYPE_BT) client.interface = TETHERING_TYPE_BT; else if (interface == MOBILE_AP_TYPE_P2P) client.interface = TETHERING_TYPE_P2P; @@ -2618,8 +2588,7 @@ API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, t INFO("+ type: %d\n", type); CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2663,8 +2632,7 @@ API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type) { CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2708,8 +2676,7 @@ API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, INFO("+ type: %d\n", type); CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2752,8 +2719,7 @@ API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type { CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2797,8 +2763,7 @@ API int tethering_set_connection_state_changed_cb(tethering_h tethering, tetheri INFO("+ type: %d\n", type); CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2841,8 +2806,7 @@ API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethe { CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); - else if (type == TETHERING_TYPE_WIFI || type == TETHERING_TYPE_WIFI_SHARING) - CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, diff --git a/tools/tethering_test.c b/tools/tethering_test.c index ba522c7..7f2c231 100755 --- a/tools/tethering_test.c +++ b/tools/tethering_test.c @@ -143,10 +143,6 @@ static const char *__convert_tethering_type_to_str(const tethering_type_e type) g_strlcpy(str_buf, "P2P Tethering", sizeof(str_buf)); break; - case TETHERING_TYPE_WIFI_SHARING: - g_strlcpy(str_buf, "Wi-Fi Sharing", sizeof(str_buf)); - break; - default: g_strlcpy(str_buf, "Unknown", sizeof(str_buf)); break; @@ -640,7 +636,7 @@ bool __get_tethering_type(tethering_type_e *type) int sel; int ret; - printf("Select tethering type (1:Wi-Fi, 2:Wi-Fi Sharing, 3:BT, 4:USB 5:P2P 6:ALL)\n"); + printf("Select tethering type (1:Wi-Fi, 2:BT, 3:USB 4:P2P 5:ALL)\n"); ret = scanf("%9d", &sel); if (ret < 0) { printf("scanf is failed!!\n"); @@ -652,18 +648,15 @@ bool __get_tethering_type(tethering_type_e *type) *type = TETHERING_TYPE_WIFI; break; case 2: - *type = TETHERING_TYPE_WIFI_SHARING; - break; - case 3: *type = TETHERING_TYPE_BT; break; - case 4: + case 3: *type = TETHERING_TYPE_USB; break; - case 5: + case 4: *type = TETHERING_TYPE_P2P; break; - case 6: + case 5: *type = TETHERING_TYPE_ALL; break; default: @@ -745,6 +738,8 @@ static int test_tethering_enable(void) int ret = TETHERING_ERROR_NONE; tethering_type_e type; int address_type = 0; + bool supported = false; + int choice = 0; tethering_h handle = _get_tethering_handle(); @@ -754,9 +749,13 @@ static int test_tethering_enable(void) if (!__get_tethering_type(&type)) return -1; - if (type == TETHERING_TYPE_WIFI_SHARING) { - bool supported = false; + if (type != TETHERING_TYPE_WIFI) + return -1; + + printf("Select 1: Wi-Fi sharing, 2: Dual band hotspot\n"); + ret = scanf("%d", &choice); + if (choice == 1) { ret = tethering_wifi_is_sharing_supported(th, &supported); if (__is_err(ret) == true) { @@ -767,9 +766,26 @@ static int test_tethering_enable(void) if (!supported) { printf("wifi_sharing is not supported.\n"); return -1; + } else { + + printf("wifi_sharing is supported.\n"); + ret = tethering_wifi_set_sharing(th, true); + if (__is_err(ret) == true) { + printf("Fail to set wifi sharing\n"); + return -1; + } } + } else if (choice == 2) { + ret = tethering_is_dualband_supported(handle, type, &supported); - printf("wifi_sharing is supported.\n"); + if (__is_err(ret) == true) { + printf("Fail to get is dubalband supported\n"); + return -1; + } else + printf("DualBand is %s\n", supported ? "Supported" : "Not Supported"); + } else { + printf("Invalid!!\n"); + return -1; } if (address_type) @@ -807,6 +823,9 @@ static int test_tethering_disable(void) printf("Fail to disable tethering\n"); return -1; } + + tethering_wifi_set_sharing(th, false); + return 1; } -- 2.7.4