Add set/get channel API 43/148243/2
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 7 Sep 2017 07:29:44 +0000 (16:29 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 7 Sep 2017 07:31:10 +0000 (16:31 +0900)
Change-Id: I7275ca3216a38a5e66615e23983f80e9c13ea03a
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
include/softap.h
include/softap_private.h
packaging/capi-network-softap.spec
src/softap.c
test/softap_test.c

index 696c8e3305042c75b6b3adb65193e3140b082514..9ca1e7cdd21655265accc4b8150e667d5ce531df 100644 (file)
@@ -755,6 +755,34 @@ int softap_set_vendor_element(softap_h softap, const char *vendor_element);
  * @retval  #SOFTAP_ERROR_NOT_SUPPORTED  API is not supported
  */
 int softap_get_vendor_element(softap_h softap, char **vendor_element);
+
+/**
+ * @brief Sets the channel for Soft AP.
+ * @details If channel is not set, Wi-Fi sets default channel.
+ * @since_tizen 4.0
+ * @param[in]  softap   The softap handle
+ * @param[in]  channel  The channel number
+ * @return 0 on success, otherwise negative error value
+ * @retval  #SOFTAP_ERROR_NONE  Successful
+ * @retval  #SOFTAP_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #SOFTAP_ERROR_NOT_SUPPORTED  API is not supported
+ */
+int softap_set_channel(softap_h softap, int channel);
+
+/**
+ * @brief Gets the channel for Soft AP.
+ * details If channel is not set, it gets default channel.
+ * @since_tizen 4.0
+ * @param[in]   softap   The softap handle
+ * @param[out]  channel  The channel number
+ * @return 0 on success, otherwise negative error value
+ * @retval  #SOFTAP_ERROR_NONE  Successful
+ * @retval  #SOFTAP_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #SOFTAP_ERROR_NOT_SUPPORTED  API is not supported
+ * @see  softap_set_channel()
+ */
+int softap_get_channel(softap_h softap, int *channel);
+
 /**
  * @}
  */
index 24f8de8279745ab390abf83779119828425afe56..f880a8465c89b2f6bd98797bab84df81f9281fbf 100644 (file)
@@ -238,6 +238,7 @@ typedef struct {
        char vendor[SOFTAP_VENDOR_MAX_LEN + 1];
        bool visibility;
        softap_security_type_e sec_type;
+       int channel;
 } __softap_h;
 
 typedef struct {
@@ -253,6 +254,7 @@ typedef struct {
        char vendor[SOFTAP_VENDOR_MAX_LEN + 1];
        softap_security_type_e sec_type;
        bool visibility;
+       int channel;
 } _softap_settings_t;
 
 void _softap_add_handle(softap_h handle);
index c3d50fdd06f36174a59f7556a7662cc3deab42ae..fc0a2bb656749e9f08c7c47e3271dcfbb2af047a 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-softap
 Summary:       Softap Framework
-Version:       0.0.13
+Version:       0.0.14
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 3ec843fa52ddb65aba46972b3c7a369f0cb481fa..f3ec9d66a34d95d4e9a764599055cbb4cc77aa0f 100755 (executable)
@@ -181,6 +181,31 @@ static softap_error_e __get_vsie(char *vsie, unsigned int size)
        return SOFTAP_ERROR_NONE;
 }
 
+static softap_error_e __set_channel(int channel)
+{
+       if (vconf_set_int(VCONFKEY_SOFTAP_CHANNEL, channel) < 0) {
+               ERR("vconf_set_int is failed\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+static softap_error_e __get_channel(int *channel)
+{
+       if (channel == NULL) {
+               ERR("Invalid param\n");
+               return SOFTAP_ERROR_INVALID_PARAMETER;
+       }
+
+       if (vconf_get_int(VCONFKEY_SOFTAP_CHANNEL, channel) < 0) {
+               ERR("vconf_get_int is failed\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
 static int __get_initial_passphrase(char *passphrase, unsigned int size)
 {
        if (passphrase == NULL ||
@@ -644,6 +669,7 @@ static int __prepare_softap_settings(softap_h softap, _softap_settings_t *set)
        g_strlcpy(set->ssid, sa->ssid, sizeof(set->ssid));
        set->sec_type = sa->sec_type;
        set->visibility = sa->visibility;
+       set->channel = sa->channel;
 
        if (set->sec_type == SOFTAP_SECURITY_TYPE_NONE)
                g_strlcpy(set->key, "", sizeof(set->key));
@@ -739,6 +765,7 @@ API int softap_create(softap_h *softap)
        __softap_h *sa = NULL;
        GError *error = NULL;
        char ssid[SOFTAP_SSID_MAX_LEN + 1] = {0, };
+       int channel;
 
        sa = (__softap_h *) malloc(sizeof(__softap_h));
 
@@ -753,19 +780,31 @@ API int softap_create(softap_h *softap)
                return SOFTAP_ERROR_OPERATION_FAILED;
        }
 
-       if (__get_initial_passphrase(sa->passphrase, sizeof(sa->passphrase)) == 0) {
-               ERR("Fail to generate random passphrase!!");
+       sa->ssid = g_strdup(ssid);
+       if (sa->ssid == NULL) {
+               ERR("Fail to get default ssid!!");
                free(sa);
                return SOFTAP_ERROR_OPERATION_FAILED;
        }
 
-       sa->ssid = g_strdup(ssid);
-       if (sa->ssid == NULL) {
-               ERR("Fail to get default ssid!!");
+       if (__get_initial_passphrase(sa->passphrase, sizeof(sa->passphrase)) == 0) {
+               ERR("Fail to generate random passphrase!!");
                free(sa);
                return SOFTAP_ERROR_OPERATION_FAILED;
        }
 
+       if (__get_channel(&channel) != SOFTAP_ERROR_NONE) {
+               ERR("Fail to get saved channel!!");
+               if (__set_channel(1) != SOFTAP_ERROR_NONE) {
+                       ERR("Fail to set channel");
+                       free(sa);
+                       return SOFTAP_ERROR_OPERATION_FAILED;
+               }
+               channel = 1;
+       }
+
+       sa->channel = channel;
+
        /* GDbus Setting */
 #if !GLIB_CHECK_VERSION(2, 36, 0)
        g_type_init();
@@ -851,7 +890,7 @@ API int softap_enable(softap_h softap)
 
         g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE);
 
-       _softap_settings_t set = {"", "", "", 0, false};
+       _softap_settings_t set = {"", "", "", 0, false, 0};
 
        ret = __prepare_softap_settings(softap, &set);
        if (ret != SOFTAP_ERROR_NONE) {
@@ -862,7 +901,7 @@ API int softap_enable(softap_h softap)
        g_dbus_connection_signal_unsubscribe(connection, sigs[E_SIGNAL_SOFTAP_ON].sig_id);
 
        g_dbus_proxy_call(proxy, "enable",
-       g_variant_new("(sssii)", set.ssid, set.key, set.vendor, set.visibility, set.sec_type),
+       g_variant_new("(sssiii)", set.ssid, set.key, set.vendor, set.visibility, set.sec_type, set.channel),
                G_DBUS_CALL_FLAGS_NONE, -1, sa->cancellable, (GAsyncReadyCallback) __enabled_cfm_cb, (gpointer)softap);
 
        g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT);
@@ -901,7 +940,7 @@ API int softap_reload_settings(softap_h softap, softap_settings_reloaded_cb call
                        "parameter(callback) is NULL\n");
 
        __softap_h *sa = (__softap_h *)softap;
-       _softap_settings_t set = {"", "", "", 0, false};
+       _softap_settings_t set = {"", "", "", 0, false, 0};
        GDBusProxy *proxy = sa->client_bus_proxy;
        int ret = 0;
 
@@ -922,7 +961,7 @@ API int softap_reload_settings(softap_h softap, softap_settings_reloaded_cb call
        sa->settings_reloaded_user_data = user_data;
 
        g_dbus_proxy_call(proxy, "reload_settings",
-                       g_variant_new("(sssii)", set.ssid, set.key, set.vendor, set.visibility, set.sec_type),
+                       g_variant_new("(sssiii)", set.ssid, set.key, set.vendor, set.visibility, set.sec_type, set.channel),
                        G_DBUS_CALL_FLAGS_NONE, -1, sa->cancellable,
                        (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)softap);
 
@@ -1402,7 +1441,6 @@ API int softap_set_security_type(softap_h softap, softap_security_type_e type)
 
        ret = __set_security_type(type);
        if (ret == SOFTAP_ERROR_NONE) {
-
                __send_dbus_signal(sa->client_bus,
                                SIGNAL_NAME_SECURITY_TYPE_CHANGED, sec_str);
        }
@@ -1692,3 +1730,28 @@ API int softap_set_vendor_element(softap_h softap, const char *vendor_element)
 
        return SOFTAP_ERROR_NONE;
 }
+
+API int softap_set_channel(softap_h softap, int channel)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *) softap;
+       sa->channel = channel;
+
+       return __set_channel(channel);
+}
+
+
+API int softap_get_channel(softap_h softap, int *channel)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                               "parameter(softap) is NULL\n");
+       _retvm_if(channel == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                               "parameter(channel) is NULL\n");
+
+       return __get_channel(channel);
+}
+
index 4c07a4c7eab2f2cdb0ba8b38fce4e5241b44f282..57c730e443f6956b759791bf2c29e74925e4a56e 100755 (executable)
@@ -351,6 +351,7 @@ static int test_softap_get_settings(void)
        char *vendor = NULL;
        bool visible = 0;
        softap_security_type_e security_type = SOFTAP_SECURITY_TYPE_NONE;
+       int channel;
 
        ret = softap_get_ssid(sa, &ssid);
        if (ret != SOFTAP_ERROR_NONE)
@@ -368,6 +369,10 @@ static int test_softap_get_settings(void)
        if (ret != SOFTAP_ERROR_NONE)
                return 0;
 
+       ret = softap_get_channel(sa, &channel);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
        ret = softap_get_mac_address(sa, &mac_address);
        if (ret != SOFTAP_ERROR_NONE)
                return 0;
@@ -397,6 +402,7 @@ static int test_softap_get_settings(void)
        printf("* SSID visibility: %d\n", visible);
        printf("* Security type: %d\n", security_type);
        printf("* Passphrase: %s\n", passphrase);
+       printf("* Channel: %d\n", channel);
        printf("* MAC address: %s\n", mac_address);
        printf("* Network Interface: %s\n", interface_name);
        printf("* IP address: %s\n", ip_address);
@@ -507,6 +513,25 @@ static int test_softap_set_vendor_element(void)
        return 1;
 }
 
+static int test_softap_set_channel(void)
+{
+       int ret;
+       int channel;
+
+       printf("Input channel for Soft AP: ");
+       ret = scanf("%9d", &channel);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return -1;
+       }
+
+       ret = softap_set_channel(sa, channel);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
 static int test_softap_reload_settings(void)
 {
        int ret = softap_reload_settings(sa, __settings_reloaded_cb, NULL);
@@ -603,10 +628,11 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("9       - Set Soft AP security type\n");
                printf("a       - Set Soft AP passpharse\n");
                printf("b       - Set Soft AP vendor element\n");
-               printf("c       - Get Soft AP client information\n");
-               printf("d       - SoftAP reload settings\n");
-               printf("e       - Push WPS Button (WPS PBC)\n");
-               printf("f       - Set WPS PIN\n");
+               printf("c       - Set Soft AP channel\n");
+               printf("d       - Get Soft AP client information\n");
+               printf("e       - SoftAP reload settings\n");
+               printf("f       - Push WPS Button (WPS PBC)\n");
+               printf("g       - Set WPS PIN\n");
                printf("0       - Exit \n");
                printf("ENTER  - Show options menu.......\n");
        }
@@ -646,15 +672,18 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                rv = test_softap_set_vendor_element();
                break;
        case 'c':
-               rv = test_softap_get_client_info();
+               rv = test_softap_set_channel();
                break;
        case 'd':
-               rv = test_softap_reload_settings();
+               rv = test_softap_get_client_info();
                break;
        case 'e':
-               rv = test_softap_push_wps_button();
+               rv = test_softap_reload_settings();
                break;
        case 'f':
+               rv = test_softap_push_wps_button();
+               break;
+       case 'g':
                rv = test_softap_set_wps_pin();
                break;
        }