From 39c1211c56c3a990d22d848a3ee98a280c395b79 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Thu, 7 Jan 2016 19:14:31 +0900 Subject: [PATCH] Add APIs to support DHCP setting, managing channel and mode Change-Id: I4369aaad3a6323b59eb128062f2ac1967ce84e18 Signed-off-by: Seonah Moon --- include/tethering.h | 113 +++++++++++++++++++++++++++++++++- include/tethering_private.h | 6 ++ packaging/capi-network-tethering.spec | 2 +- src/tethering.c | 106 ++++++++++++++++++++++++++++--- test/tethering_test.c | 39 ++++++++++++ 5 files changed, 257 insertions(+), 9 deletions(-) diff --git a/include/tethering.h b/include/tethering.h index c768ca5..aba8f71 100644 --- a/include/tethering.h +++ b/include/tethering.h @@ -105,6 +105,17 @@ typedef enum { } tethering_wifi_security_type_e; /** + * @brief Enumeration for the Wi-Fi mode + * @since_tizen 3.0 + */ +typedef enum { + TETHERING_WIFI_MODE_TYPE_B = 0, /**< mode b */ + TETHERING_WIFI_MODE_TYPE_G, /**< mode g */ + TETHERING_WIFI_MODE_TYPE_A, /**< mode a */ + TETHERING_WIFI_MODE_TYPE_AD, /**< mode ad */ +} tethering_wifi_mode_type_e; + +/** * @} */ @@ -922,6 +933,107 @@ int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char *ma int tethering_wifi_get_blocked_mac_list(tethering_h tethering, void **blocked_mac_list); /** + * @brief Enables/disables the dhcp server. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @details Enable/disable the dhcp server. + * @param[in] tethering The handle of tethering + * @param[in] enable Enable/disable the dhcp server + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + */ +int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable); + +/** + * @brief Enables the dhcp server with the address range. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @details Enable the dhcp server with the address range. + * @param[in] tethering The handle of tethering + * @param[in] rangestart Start address range + * @param[in] rangestop End address range + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + */ +int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop); + +/** + * @brief Checks whether the dhcp is enabled or not. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @param[in] tethering The tethering handle + * @param[out] dhcp_enabled @c true if dhcp is enabled, \n @c false if dhcp is disabled + * @return 0 on success, otherwise a negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + */ +int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled); + +/** + * @brief Sets the Channel for Wi-Fi. + * @details The Channel should be in between 1-14. If channel is not set, Wi-Fi sets default channel. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @param[in] tethering The tethering handle + * @param[in] channel The channel number + * @return 0 on success, otherwise negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + */ +int tethering_wifi_set_channel(tethering_h tethering, int channel); + +/** + * @brief Gets the channel for Wi-Fi. + * @details If channel is not set, Wi-Fi gets default channel. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @param[in] tethering The tethering handle + * @param[out] channel The channel number + * @return 0 on success, otherwise negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @see tethering_wifi_ap_set_channel() + */ +int tethering_wifi_get_channel(tethering_h tethering, int *channel); + +/** + * @brief Sets the mode for Wi-Fi. + * @details The mobile AP mode (ex: b only, g only, ad, a). If mode is not set, Wi-Fi sets default mode. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @param[in] tethering The tethering handle + * @param[in] type The mobile AP mode + * @return 0 on success, otherwise negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + */ +int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type); + +/** + * @brief Gets the mode for Wi-Fi. + * @details If the mode is not set, Wi-Fi gets default mode. + * @since_tizen 3.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/tethering.admin + * @remarks @a mode must be released using free(). + * @param[in] tethering The tethering handle + * @param[out] type The mode of Wi-Fi AP + * @return 0 on success, otherwise negative error value + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @see tethering_wifi_set_mode() + */ +int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type); + +/** * @brief Sets the security type of Wi-Fi AP. * @details If security type is not set, WPA2_PSK is used. * @since_tizen 2.3 @@ -1064,7 +1176,6 @@ int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase); * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed */ int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data); - /** * @} */ diff --git a/include/tethering_private.h b/include/tethering_private.h index aa84fce..d82c263 100644 --- a/include/tethering_private.h +++ b/include/tethering_private.h @@ -239,6 +239,8 @@ typedef enum { #define TETHERING_WIFI_KEY_MAX_LEN 64 /**< Maximum length of wifi key */ #define TETHERING_WIFI_HASH_KEY_MAX_LEN 64 +#define TETHERING_WIFI_MODE_MAX_LEN 10 /**< Maximum length of mode */ + #define VCONFKEY_MOBILE_HOTSPOT_SSID "memory/private/mobileap-agent/ssid" #define TETHERING_PASSPHRASE_PATH "wifi_tethering.txt" #define TETHERING_WIFI_PASSPHRASE_STORE_KEY "tethering_wifi_passphrase" @@ -293,6 +295,8 @@ typedef struct { char passphrase[TETHERING_WIFI_KEY_MAX_LEN + 1]; tethering_wifi_security_type_e sec_type; bool visibility; + int channel; + tethering_wifi_mode_type_e mode_type; } __tethering_h; typedef struct { @@ -314,8 +318,10 @@ typedef struct { typedef struct { char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1]; char key[TETHERING_WIFI_KEY_MAX_LEN + 1]; + char mode[TETHERING_WIFI_MODE_MAX_LEN + 1]; tethering_wifi_security_type_e sec_type; bool visibility; + int channel; } _softap_settings_t; #ifdef __cplusplus diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index 31066b2..92beaaf 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.0.29 +Version: 1.0.30 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/tethering.c b/src/tethering.c index f51ccd2..2efc80b 100755 --- a/src/tethering.c +++ b/src/tethering.c @@ -1325,12 +1325,37 @@ static int __get_common_ssid(char *ssid, unsigned int size) return TETHERING_ERROR_NONE; } +static bool __get_wifi_mode_type(tethering_wifi_mode_type_e type, char **buf) +{ + _retvm_if(buf == NULL, false, "parameter(buf) is NULL\n"); + + switch (type) { + case TETHERING_WIFI_MODE_TYPE_B: + *buf = g_strdup("b"); + break; + case TETHERING_WIFI_MODE_TYPE_G: + *buf = g_strdup("g"); + break; + case TETHERING_WIFI_MODE_TYPE_A: + *buf = g_strdup("a"); + break; + case TETHERING_WIFI_MODE_TYPE_AD: + *buf = g_strdup("ad"); + break; + default: + ERR("Not supported type : %d\n", type); + return false; + } + return true; +} + static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set) { DBG("+\n"); __tethering_h *th = (__tethering_h *)tethering; tethering_error_e ret = TETHERING_ERROR_NONE; + char *ptr = NULL; if (th == NULL || set == NULL) { ERR("null parameter\n-\n"); @@ -1350,6 +1375,16 @@ static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *se if (ret != TETHERING_ERROR_NONE) set->visibility = th->visibility; + set->channel = th->channel; + + __get_wifi_mode_type (th->mode_type, &ptr); + if (ptr == NULL) { + g_strlcpy(set->mode, "", sizeof(set->mode)); + } else { + g_strlcpy(set->mode, ptr, sizeof(set->mode)); + free(ptr); + } + if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) { g_strlcpy(set->key, "", sizeof(set->key)); } else { @@ -1474,6 +1509,8 @@ API int tethering_create(tethering_h *tethering) memset(th, 0x00, sizeof(__tethering_h)); th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK; th->visibility = true; + th->channel = 6; + th->mode_type = TETHERING_WIFI_MODE_TYPE_G; if (__generate_initial_passphrase(th->passphrase, sizeof(th->passphrase)) == 0) { @@ -1621,7 +1658,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) break; case TETHERING_TYPE_WIFI: { - _softap_settings_t set = {"", "", 0, false}; + _softap_settings_t set = {"", "", "", 0, false}; ret = __prepare_wifi_settings(tethering, &set); if (ret != TETHERING_ERROR_NONE) { @@ -1633,7 +1670,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id); g_dbus_proxy_call(proxy, "enable_wifi_tethering", - g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + g_variant_new("(sssiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.sec_type), G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering); break; @@ -1650,7 +1687,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) break; case TETHERING_TYPE_RESERVED: { - _softap_settings_t set = {"", "", 0, false}; + _softap_settings_t set = {"", "", "", 0, false}; ret = __prepare_wifi_ap_settings(tethering, &set); if (ret != TETHERING_ERROR_NONE) { @@ -1667,7 +1704,7 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) break; } case TETHERING_TYPE_ALL: { - _softap_settings_t set = {"", "", 0, false}; + _softap_settings_t set = {"", "", "", 0, false}; ret = __prepare_wifi_settings(tethering, &set); if (ret != TETHERING_ERROR_NONE) { @@ -3056,6 +3093,61 @@ API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase) return TETHERING_ERROR_NONE; } +API int tethering_wifi_set_channel(tethering_h tethering, int channel) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + th->channel = channel; + + return TETHERING_ERROR_NONE; +} + +API int tethering_wifi_get_channel(tethering_h tethering, int *channel) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + _retvm_if(channel == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(channel) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + *channel = th->channel; + + return TETHERING_ERROR_NONE; +} + +API int tethering_wifi_set_mode(tethering_h tethering, tethering_wifi_mode_type_e type) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + + th->mode_type = type; + + return TETHERING_ERROR_NONE; +} + +API int tethering_wifi_get_mode(tethering_h tethering, tethering_wifi_mode_type_e *type) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(type) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + *type = th->mode_type; + + return TETHERING_ERROR_NONE; +} + + /** * @internal * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility). @@ -3082,7 +3174,7 @@ API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_set "parameter(callback) is NULL\n"); __tethering_h *th = (__tethering_h *)tethering; - _softap_settings_t set = {"", "", 0, false}; + _softap_settings_t set = {"", "", "", 0, false}; GDBusProxy *proxy = th->client_bus_proxy; int ret = 0; @@ -3103,7 +3195,7 @@ API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_set th->settings_reloaded_user_data = user_data; g_dbus_proxy_call(proxy, "reload_wifi_settings", - g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + g_variant_new("(sssiii)", set.ssid, set.key, set.mode, set.channel, set.visibility, set.sec_type), G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering); @@ -3405,7 +3497,7 @@ API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ "parameter(callback) is NULL\n"); __tethering_h *th = (__tethering_h *)tethering; - _softap_settings_t set = {"", "", 0, false}; + _softap_settings_t set = {"", "", "", 0, false}; GDBusProxy *proxy = th->client_bus_proxy; int ret = 0; diff --git a/test/tethering_test.c b/test/tethering_test.c index 9c21a4e..e29182c 100755 --- a/test/tethering_test.c +++ b/test/tethering_test.c @@ -811,6 +811,37 @@ static int test_tethering_wifi_set_passphrase(void) return 1; } +static int test_tethering_wifi_set_channel(void){ + int ret; + int channel; + + printf("Input channel for Wi-Fi tethering: "); + ret = scanf("%d", &channel); + + ret = tethering_wifi_set_channel(th, channel); + if (__is_err(ret) == true) { + printf("Fail to set channel!!\n"); + return -1; + } + + return 1; +} + +static int test_tethering_wifi_set_mode(void) { + int ret; + int type; + + printf("Input hw_mode for Wi-Fi tethering(0-b, 1-g, 2-a, 3-ad): "); + ret = scanf("%d", &type); + + ret = tethering_wifi_set_mode(th, type); + if (__is_err(ret) == true) { + printf("Fail to set mode!!\n"); + return -1; + } + return 1; +} + static int test_tethering_wifi_ap_set_ssid(void) { int ret; @@ -964,6 +995,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("h - Set Wi-Fi AP passphrase\n"); printf("i - Reload Wi-Fi tethering\n"); printf("j - Reload Wi-Fi AP\n"); + printf("m - Set Wi-Fi channel\n"); + printf("n - Set Wi-Fi hw_mode\n"); printf("0 - Exit \n"); printf("ENTER - Show options menu.......\n"); } @@ -1026,6 +1059,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'j': rv = test_tethering_wifi_ap_reload_settings(); break; + case 'm': + rv = test_tethering_wifi_set_channel(); + break; + case 'n': + rv = test_tethering_wifi_set_mode(); + break; } if (rv == 1) -- 2.7.4