Add new APIs for dhcp server 79/149079/1 accepted/tizen/unified/20170913.071029 submit/tizen/20170911.125730
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 11 Sep 2017 11:26:17 +0000 (20:26 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 11 Sep 2017 11:26:27 +0000 (20:26 +0900)
Change-Id: Ibda3b6e6fe78d611c3654b253062457196d4c8de
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 584fce982b84bba94a4c87f484d0b5a0fd97f420..9440227dfb26abbf325a4f93c93c61a5c3e9b7a7 100644 (file)
@@ -780,6 +780,52 @@ int softap_set_channel(softap_h softap, int channel);
  */
 int softap_get_channel(softap_h softap, int *channel);
 
+/**
+ * @brief Enables the dhcp server.
+ * @since_tizen 4.0
+ * @details Enable/disable the dhcp server.
+ * @param[in]  softap   The softap handle
+ * @return 0 on success, otherwise negative error value.
+ * @retval  #SOFTAPERROR_NONE  Successful
+ * @retval  #SOFTAPERROR_INVALID_PARAMETER  Invalid parameter
+ */
+int softap_enable_dhcp(softap_h softap);
+
+/**
+ * @brief Disables the dhcp server.
+ * @since_tizen 4.0
+ * @details Enable/disable the dhcp server.
+ * @param[in]  softap   The softap handle
+ * @return 0 on success, otherwise negative error value.
+ * @retval  #SOFTAPERROR_NONE  Successful
+ * @retval  #SOFTAPERROR_INVALID_PARAMETER  Invalid parameter
+ */
+int softap_disable_dhcp(softap_h softap);
+
+/**
+ * @brief Checks whether the dhcp is enabled or not.
+ * @since_tizen 4.0
+ * @param[in]  softap  The softap 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  #SOFTAP_ERROR_NONE  Successful
+ * @retval  #SOFTAP_ERROR_INVALID_PARAMETER  Invalid parameter
+ **/
+int softap_is_dhcp_enabled(softap_h softap, bool *dhcp_enabled);
+
+/**
+ * @brief Enables the dhcp server with the address range.
+ * @since_tizen 4.0
+ * @details Enable the dhcp server with the address range.
+ * @param[in]  softap  The handle of softap
+ * @param[in]  rangestart Start address range
+ * @param[in]  rangestop  End address range
+ * @return 0 on success, otherwise negative error value.
+ * @retval  #SOFTAP_ERROR_NONE  Successful
+ * @retval  #SOFTAP_ERROR_INVALID_PARAMETER  Invalid parameter
+ **/
+int softap_enable_dhcp_with_range(softap_h softap, char *rangestart, char *rangestop);
+
 /**
  * @}
  */
index 478a8abac5967931edfbf7fbd6421102aaf7b60b..97a3703f7a6ef53ca84c992e5a37db8cb789327a 100644 (file)
@@ -237,6 +237,7 @@ typedef struct {
        char passphrase[SOFTAP_KEY_MAX_LEN + 1];
        char vendor[SOFTAP_VENDOR_MAX_LEN + 1];
        bool visibility;
+       bool dhcp_enabled;
        softap_security_type_e sec_type;
        int channel;
 } __softap_h;
index fc0a2bb656749e9f08c7c47e3271dcfbb2af047a..6f5718249bd283d21b82180527b94961e41b2ff7 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-softap
 Summary:       Softap Framework
-Version:       0.0.14
+Version:       0.0.15
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index b90e4d2b710c04836c2d444780f8325803713f68..2a9b7ddb96c2bcce0207fab5349cbefaa02f8df8 100755 (executable)
@@ -804,6 +804,7 @@ API int softap_create(softap_h *softap)
        }
 
        sa->channel = channel;
+       sa->dhcp_enabled = false;
 
        /* GDbus Setting */
 #if !GLIB_CHECK_VERSION(2, 36, 0)
@@ -1625,7 +1626,7 @@ API int softap_push_wps_button(softap_h softap)
                        NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
 
        if (error) {
-               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+               ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
 
                if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
                        ret = SOFTAP_ERROR_PERMISSION_DENIED;
@@ -1755,3 +1756,153 @@ API int softap_get_channel(softap_h softap, int *channel)
        return __get_channel(channel);
 }
 
+API int softap_enable_dhcp(softap_h softap)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+       GError *error = NULL;
+       GVariant *parameters = NULL;
+       GDBusProxy *proxy = sa->client_bus_proxy;
+       guint result;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       result = SOFTAP_ERROR_PERMISSION_DENIED;
+               else
+                       result = SOFTAP_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               sa->dhcp_enabled = false;
+
+               return result;
+       }
+
+       g_variant_get(parameters, "(u)", &result);
+       g_variant_unref(parameters);
+
+       sa->dhcp_enabled = true;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_disable_dhcp(softap_h softap)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+       GError *error = NULL;
+       GVariant *parameters = NULL;
+       GDBusProxy *proxy = sa->client_bus_proxy;
+       guint result;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "disable_dhcp",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       result = SOFTAP_ERROR_PERMISSION_DENIED;
+               else
+                       result = SOFTAP_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               return result;
+       }
+
+       g_variant_get(parameters, "(u)", &result);
+       g_variant_unref(parameters);
+
+       sa->dhcp_enabled = false;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_is_dhcp_enabled(softap_h softap, bool *dhcp_enabled)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(dhcp_enabled == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(dhcp_enabled) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+       GError *error = NULL;
+       GVariant *parameters = NULL;
+       GDBusProxy *proxy = sa->client_bus_proxy;
+       int ret = SOFTAP_ERROR_NONE;
+       bool enabled = false;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "get_dhcp_state",
+                       NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed becuase %s\n", error->message);
+
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       ret = SOFTAP_ERROR_PERMISSION_DENIED;
+               else
+                       ret = SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       if (parameters != NULL) {
+               g_variant_get(parameters, "(b)", &enabled);
+               g_variant_unref(parameters);
+       }
+
+       sa->dhcp_enabled = enabled;
+       *dhcp_enabled = sa->dhcp_enabled;
+
+       return ret;
+}
+
+API int softap_enable_dhcp_with_range(softap_h softap, char *rangestart, char *rangestop)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(rangestart == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(rangestart) is NULL\n");
+       _retvm_if(rangestop == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(rangestop) is NULL\n");
+
+       GVariant *parameters;
+       GError *error = NULL;
+       guint result;
+
+       __softap_h *sa = (__softap_h *)softap;
+       GDBusProxy *proxy = sa->client_bus_proxy;
+
+       parameters = g_dbus_proxy_call_sync(proxy, "enable_dhcp_with_range",
+                       g_variant_new("(ss)", rangestart, rangestop),
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (error) {
+               ERR("g_dbus_proxy_call_sync failed because  %s\n", error->message);
+
+               if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       result = SOFTAP_ERROR_PERMISSION_DENIED;
+               else
+                       result = SOFTAP_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               sa->dhcp_enabled = false;
+
+               return result;
+       }
+
+       g_variant_get(parameters, "(u)", &result);
+       g_variant_unref(parameters);
+
+       sa->dhcp_enabled = true;
+
+       return SOFTAP_ERROR_NONE;
+}
index 57c730e443f6956b759791bf2c29e74925e4a56e..1539777295f79c563a5289420d9817ae996865b1 100755 (executable)
@@ -349,54 +349,58 @@ static int test_softap_get_settings(void)
        char *gateway_address = NULL;
        char *subnet_mask = NULL;
        char *vendor = NULL;
-       bool visible = 0;
+       bool visible = false;
+       bool dhcp_enabled = false;
        softap_security_type_e security_type = SOFTAP_SECURITY_TYPE_NONE;
        int channel;
 
        ret = softap_get_ssid(sa, &ssid);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get ssid\n");
 
        ret = softap_get_passphrase(sa, &passphrase);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get passphrase\n");
 
        ret = softap_get_ssid_visibility(sa, &visible);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get ssid visibility\n");
 
        ret = softap_get_security_type(sa, &security_type);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get security type\n");
 
        ret = softap_get_channel(sa, &channel);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get channel\n");
 
        ret = softap_get_mac_address(sa, &mac_address);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get mac address\n");
 
        ret = softap_get_network_interface_name(sa, &interface_name);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get interface name\n");
 
        ret = softap_get_ip_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get IP address\n");
 
        ret = softap_get_gateway_address(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &gateway_address);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get gateway address\n");
 
        ret = softap_get_subnet_mask(sa, SOFTAP_ADDRESS_FAMILY_IPV4, &subnet_mask);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get subnet mask\n");
 
        ret = softap_get_vendor_element(sa, &vendor);
        if (ret != SOFTAP_ERROR_NONE)
-               return 0;
+               printf("Failed to get vendor element\n");
 
+       ret = softap_is_dhcp_enabled(sa, &dhcp_enabled);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Failed to get dhcp state\n");
 
        printf("* SSID: %s\n", ssid);
        printf("* SSID visibility: %d\n", visible);
@@ -409,6 +413,7 @@ static int test_softap_get_settings(void)
        printf("* Ggateway address: %s\n", gateway_address);
        printf("* subnetmask: %s\n", subnet_mask);
        printf("* vendor element: %s\n", vendor);
+       printf("* DHCP: %s\n", (dhcp_enabled ? "enabled" : "disabled"));
 
        if (ssid) g_free(ssid);
        if (passphrase) g_free(passphrase);
@@ -585,6 +590,59 @@ static int test_softap_set_wps_pin(void)
        return 1;
 }
 
+static int test_softap_enable_dhcp(void)
+{
+       int ret;
+       int enable_type;
+       char rangestart[16];
+       char rangestop[16];
+
+       printf("Enable with range? (0. no, 1. yes): ");
+       ret = scanf("%d", &enable_type);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       if (enable_type) {
+               printf("Input DHCP range\n");
+               printf("Start: ");
+               ret = scanf("%15s", rangestart);
+               if (ret < 0) {
+                       printf("scanf is failed!!\n");
+                       return 0;
+               }
+
+               printf("Stop: ");
+               ret = scanf("%15s", rangestop);
+               if (ret < 0) {
+                       printf("scanf is failed!!\n");
+                       return 0;
+               }
+
+               ret = softap_enable_dhcp_with_range(sa, rangestart, rangestop);
+               if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+       } else {
+               ret = softap_enable_dhcp(sa);
+               if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+       }
+
+       return 1;
+}
+
+static int test_softap_disable_dhcp(void)
+{
+       int ret;
+
+       ret = softap_disable_dhcp(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -633,6 +691,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("e       - SoftAP reload settings\n");
                printf("f       - Push WPS Button (WPS PBC)\n");
                printf("g       - Set WPS PIN\n");
+               printf("h       - Enable DHCP Server\n");
+               printf("i       - Disable DHCP Server\n");
                printf("0       - Exit \n");
                printf("ENTER  - Show options menu.......\n");
        }
@@ -686,6 +746,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'g':
                rv = test_softap_set_wps_pin();
                break;
+       case 'h':
+               rv = test_softap_enable_dhcp();
+               break;
+       case 'i':
+               rv = test_softap_disable_dhcp();
+               break;
        }
 
        if (rv == 1)