[capi-tethering] Add APIs for dhcp feature 59/59259/4
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 12 Feb 2016 02:14:24 +0000 (11:14 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Fri, 12 Feb 2016 06:10:59 +0000 (15:10 +0900)
Change-Id: I85e2b0e81ccc643dbd2e261300923511a2085af6
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
include/tethering_private.h
packaging/capi-network-tethering.spec
src/tethering.c
test/tethering_test.c

index f2b78b3..0190036 100644 (file)
@@ -294,10 +294,11 @@ typedef struct {
        char *ap_ssid;
        char passphrase[TETHERING_WIFI_KEY_MAX_LEN + 1];
        tethering_wifi_security_type_e sec_type;
+       tethering_wifi_mode_type_e mode_type;
        bool visibility;
        bool mac_filter;
+       bool dhcp_enabled;
        int channel;
-       tethering_wifi_mode_type_e mode_type;
 } __tethering_h;
 
 typedef struct {
index 92beaaf..9c1a172 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-tethering
 Summary:       Tethering Framework
-Version:       1.0.30
+Version:       1.0.31
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 684290e..5c39b85 100755 (executable)
@@ -3343,6 +3343,108 @@ API int tethering_wifi_remove_blocked_mac_list(tethering_h tethering, const char
        return __remove_mac_from_file(BLOCKED_LIST, mac);
 }
 
+API int tethering_wifi_enable_dhcp(tethering_h tethering, bool enable)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+
+       GVariant *parameters;
+       GError *error = NULL;
+       guint result;
+
+       __tethering_h *th = (__tethering_h *)tethering;
+
+       GDBusProxy *proxy = th->client_bus_proxy;
+
+       parameters = g_dbus_proxy_call_sync (proxy, "enable_dhcp",
+                       g_variant_new("(b)", enable),
+                       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 = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       result = TETHERING_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               th->dhcp_enabled = false;
+
+               return result;
+       }
+
+       g_variant_get (parameters, "(u)", &result);
+       g_variant_unref(parameters);
+
+       if (enable) {
+               th->dhcp_enabled = true;
+       } else {
+               th->dhcp_enabled = false;
+       }
+
+       return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_set_dhcp_range(tethering_h tethering, char *rangestart, char *rangestop)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+       _retvm_if(rangestart == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(rangestart) is NULL\n");
+       _retvm_if(rangestop == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(rangestop) is NULL\n");
+
+       GVariant *parameters;
+       GError *error = NULL;
+       guint result;
+
+       __tethering_h *th = (__tethering_h *)tethering;
+
+       GDBusProxy *proxy = th->client_bus_proxy;
+
+       parameters = g_dbus_proxy_call_sync (proxy, "dhcp_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 = TETHERING_ERROR_PERMISSION_DENIED;
+               else
+                       result = TETHERING_ERROR_OPERATION_FAILED;
+
+               g_error_free(error);
+               th->dhcp_enabled = false;
+
+               return result;
+       }
+
+       g_variant_get (parameters, "(u)", &result);
+       g_variant_unref(parameters);
+
+       th->dhcp_enabled = true;
+
+       return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_is_dhcp_enabled(tethering_h tethering, bool *dhcp_enabled)
+{
+       CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE);
+       _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(tethering) is NULL\n");
+       _retvm_if(dhcp_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+                       "parameter(dhcp_enabled) is NULL\n");
+
+       __tethering_h *th = (__tethering_h *)tethering;
+       *dhcp_enabled = th->dhcp_enabled;
+
+       return TETHERING_ERROR_NONE;
+}
+
 /**
  * @internal
  * @brief Sets the security type of Wi-Fi AP.
index e2481be..d55ec55 100755 (executable)
@@ -853,6 +853,59 @@ static int test_tethering_wifi_set_mode(void)
        return 1;
 }
 
+static int test_tethering_wifi_enable_dhcp(void)
+{
+       int ret;
+       int enable;
+
+       printf("Input (0-Disable, 1-Enable): ");
+       ret = scanf("%d", &enable);
+
+       ret = tethering_wifi_enable_dhcp(th, enable);
+       if (__is_err(ret) == true) {
+               printf("Fail to enable dhcp server!!\n");
+               return -1;
+       }
+
+       return 1;
+}
+
+static int test_tethering_wifi_set_dhcp_range(void)
+{
+       int ret;
+       char rangestart[16], rangestop[16];
+
+       printf("Input range (ex: 192.168.0.50 192.168.0.150): ");
+
+       ret = scanf("%s %s", rangestart, rangestop);
+
+       ret = tethering_wifi_set_dhcp_range(th, rangestart, rangestop);
+       if (__is_err(ret) == true) {
+               printf("Fail to set dhcp range and enable dhcp server!!\n");
+               return -1;
+       }
+
+       return 1;
+}
+
+static int test_tethering_wifi_is_dhcp_enabled(void)
+{
+       int ret;
+       bool enabled;
+
+       ret = tethering_wifi_is_dhcp_enabled(th, &enabled);
+
+       if (__is_err(ret) == true) {
+               printf("Fail to get dhcp server status!!\n");
+               return -1;
+       }
+       else {
+               printf("DHCP server is %s\n", enabled? "enabled": "disabled");
+       }
+
+       return 1;
+}
+
 static int test_tethering_wifi_set_mac_filtering(void)
 {
        int ret;
@@ -1069,6 +1122,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("l       - Reload Wi-Fi AP\n");
                printf("m       - Set Wi-Fi channel\n");
                printf("n       - Set Wi-Fi hw_mode\n");
+               printf("o       - Enable dhcp server\n");
+               printf("p       - Enable dhcp server with range\n");
+               printf("q       - Is dhcp server enabled?\n");
                printf("0       - Exit \n");
                printf("ENTER  - Show options menu.......\n");
        }
@@ -1143,6 +1199,15 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'n':
                rv = test_tethering_wifi_set_mode();
                break;
+       case 'o':
+               rv = test_tethering_wifi_enable_dhcp();
+               break;
+       case 'p':
+               rv = test_tethering_wifi_set_dhcp_range();
+               break;
+       case 'q':
+               rv = test_tethering_wifi_is_dhcp_enabled();
+               break;
        }
 
        if (rv == 1)