From 4d7f1432fd8ccd6cc845175f46f452d130c8600a Mon Sep 17 00:00:00 2001 From: Seungyoun Ju Date: Sat, 16 Feb 2013 13:52:23 +0900 Subject: [PATCH] Add API : tethering_wifi_set_ssid() - Issues There is no way to set SSID. - Fix description SSID is saved in Tethering handle and when Wi-Fi tethering is enabled, the saved SSID is used. Because basic concept of SSID is the use of system's device name (e.g. Redwood), so per-handle SSID implementation is required. If application sets SSID and enables tethering, given SSID is used. Otherwise, system's device name is used as SSID. Change-Id: I751cc59b7eba8219b86a2e7cf1ebf11e282ad7fc --- include/tethering.h | 13 +++++++++ include/tethering_private.h | 6 ++++ src/tethering.c | 69 +++++++++++++++++++++++++++++++++++++++++++-- test/tethering_test.c | 11 +++++++- 4 files changed, 95 insertions(+), 4 deletions(-) diff --git a/include/tethering.h b/include/tethering.h index 253c5f5..f68dc5e 100644 --- a/include/tethering.h +++ b/include/tethering.h @@ -549,6 +549,19 @@ int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_secur int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type); /** + * @brief Sets the SSID (service set identifier). + * @details If SSID is not set, Device name is used as SSID + * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle + * @param[in] tethering The handle of tethering + * @param[out] ssid The SSID + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory + */ +int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid); + +/** * @brief Gets the SSID (service set identifier). * @remarks @a ssid must be released with free() by you. * @param[in] tethering The handle of tethering diff --git a/include/tethering_private.h b/include/tethering_private.h index 85297e5..8ad1150 100644 --- a/include/tethering_private.h +++ b/include/tethering_private.h @@ -195,6 +195,10 @@ typedef enum { #define TETHERING_BT_IF "bnep0" #define TETHERING_BT_GATEWAY "192.168.130.1" + +#define TETHERING_WIFI_SSID_MAX_LEN 31 /**< Maximum length of ssid */ +#define TETHERING_WIFI_KEY_MIN_LEN 8 /**< Minimum length of wifi key */ +#define TETHERING_WIFI_KEY_MAX_LEN 63 /**< Maximum length of wifi key */ /** * End of mobileap-agent common values */ @@ -229,6 +233,8 @@ typedef struct { void *ssid_visibility_user_data; tethering_wifi_passphrase_changed_cb passphrase_changed_cb; void *passphrase_user_data; + + char *ssid; } __tethering_h; typedef struct { diff --git a/src/tethering.c b/src/tethering.c index 43b9eb4..d75692e 100644 --- a/src/tethering.c +++ b/src/tethering.c @@ -889,6 +889,8 @@ API int tethering_destroy(tethering_h tethering) org_tizen_tethering_deinit_async(th->client_bus_proxy, __deinit_cb, (gpointer)tethering); + if (th->ssid) + free(th->ssid); g_object_unref(th->client_bus_proxy); dbus_g_connection_unref(th->client_bus); memset(th, 0x00, sizeof(__tethering_h)); @@ -931,7 +933,8 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON, G_CALLBACK(__handle_wifi_tether_on), (gpointer)tethering); - org_tizen_tethering_enable_wifi_tethering_async(proxy, "", "", false, + org_tizen_tethering_enable_wifi_tethering_async(proxy, + th->ssid ? th->ssid : "", "", false, __cfm_cb, (gpointer)tethering); break; @@ -956,7 +959,8 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON, G_CALLBACK(__handle_wifi_tether_on), (gpointer)tethering); - org_tizen_tethering_enable_wifi_tethering_async(proxy, "", "", false, + org_tizen_tethering_enable_wifi_tethering_async(proxy, + th->ssid ? th->ssid : "", "", false, __cfm_cb, (gpointer)tethering); /* TETHERING_TYPE_BT */ @@ -1851,6 +1855,45 @@ API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_s } /** + * @brief Sets the SSID (service set identifier). + * @details If SSID is not set, Device name is used as SSID + * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle + * @param[in] tethering The handle of tethering + * @param[out] ssid The SSID + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory + */ +int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid) +{ + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(ssid) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + char *p_ssid; + int ssid_len; + + ssid_len = strlen(ssid); + if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) { + ERR("parameter(ssid) is too long"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + p_ssid = strdup(ssid); + _retvm_if(p_ssid == NULL, TETHERING_ERROR_OUT_OF_MEMORY, + "strdup is failed\n"); + + if (th->ssid) + free(th->ssid); + th->ssid = p_ssid; + + return TETHERING_ERROR_NONE; +} + +/** * @brief Gets the SSID (service set identifier). * @remarks @a ssid must be released with free() by you. * @param[in] tethering The handle of tethering @@ -1874,6 +1917,18 @@ API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid) GError *error = NULL; char *ssid_buf = NULL; + if (tethering_is_enabled(NULL, TETHERING_TYPE_WIFI) == false && + th->ssid != NULL) { + DBG("Private SSID is set : %s\n", th->ssid); + *ssid = strdup(th->ssid); + if (*ssid == NULL) { + ERR("Memory allocation failed\n"); + return TETHERING_ERROR_OUT_OF_MEMORY; + } + DBG("-\n"); + return TETHERING_ERROR_NONE; + } + org_tizen_tethering_get_wifi_tethering_ssid(proxy, &ssid_buf, &error); if (error != NULL) { ERR("dbus fail : %s\n", error->message); @@ -1996,13 +2051,21 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr __tethering_h *th = (__tethering_h *)tethering; DBusGProxy *proxy = th->client_bus_proxy; + int passphrase_len; + + passphrase_len = strlen(passphrase); + if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN || + passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) { + ERR("parameter(passphrase) is too short or long\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED, G_CALLBACK(__handle_passphrase_changed), (gpointer)tethering); org_tizen_tethering_set_wifi_tethering_passphrase_async(proxy, - passphrase, strlen(passphrase), + passphrase, passphrase_len, __wifi_set_passphrase_cb, (gpointer)tethering); DBG("-\n"); diff --git a/test/tethering_test.c b/test/tethering_test.c index 026400b..33578c6 100644 --- a/test/tethering_test.c +++ b/test/tethering_test.c @@ -28,7 +28,7 @@ #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 @@ -538,6 +538,7 @@ void print_menu(void) g_print("\nTo get Wi-Fi tethering setting, enter 'get wifi_setting'"); g_print("\nTo set Wi-Fi tethering setting, enter '[set_security_type | set_visibility] [0 | 1]'"); g_print("\nTo set Wi-Fi tethering passphrase, enter 'set_passphrase [passphrase]'"); + g_print("\nTo set Wi-Fi tethering SSID, enter 'set_ssid [SSID]'"); g_print("\nTo quit, enter 'quit'\n> "); return; @@ -632,6 +633,14 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) 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; + } + /* One parameter(type) */ if (!strcmp(param, "USB")) type = TETHERING_TYPE_USB; -- 2.7.4