Added config API to set and get prefix length. 65/189265/2 accepted/tizen/unified/20180918.152333 submit/tizen/20180918.053753
authorNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 14 Sep 2018 15:25:54 +0000 (20:55 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Sat, 15 Sep 2018 08:25:17 +0000 (13:55 +0530)
Change-Id: I1c6a0542896331b55950bb45b60ade2d35cdcafe
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/wifi_internal.h
src/network_dbus.c
src/wifi_ap.c
src/wifi_config.c
test/wifi_manager_test.c

index 59eb0f6..bcf835f 100755 (executable)
@@ -50,6 +50,7 @@ extern "C" {
 #define WIFI_CONFIG_IPV6_METHOD                        "IPv6.method"
 #define WIFI_CONFIG_IPV4_ADDRESS                       "IPv4.local_address"
 #define WIFI_CONFIG_IPV4_SUBNET_MASK           "IPv4.netmask_prefixlen"
+#define WIFI_CONFIG_IPV6_PREFIX_LEN            "IPv6.netmask_prefixlen"
 #define WIFI_CONFIG_IPV4_GATEWAY_ADDRESS       "IPv4.gateway"
 #define WIFI_CONFIG_IPV4_DNS_METHOD                    "Nameservers.IPv4method"
 #define WIFI_CONFIG_DNS_ADDRESS                                "Nameservers"
@@ -294,6 +295,7 @@ int _wifi_forget_ap(wifi_manager_ap_h ap);
 int _wifi_forget_ap_async(wifi_manager_h wifi, wifi_manager_ap_h ap,
                          wifi_manager_forget_ap_finished_cb callback,
                          void* user_data);
+int __ap_convert_netmask_to_prefix_len(const char *netmask);
 
 void _wifi_rssi_level_changed_cb(keynode_t *node, void *user_data);
 
index 1ceb659..a5f90e3 100755 (executable)
@@ -2853,6 +2853,10 @@ int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *na
                        g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_SUBNET_MASK,
                                                  g_variant_new_string(ip_info->subnet_mask));
 
+               if (ip_info->prefix_length > 0)
+                       g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV6_PREFIX_LEN,
+                                                 g_variant_new_int32(ip_info->prefix_length));
+
                if (ip_info->gateway_address)
                        g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_GATEWAY_ADDRESS,
                                          g_variant_new_string(ip_info->gateway_address));
@@ -3088,6 +3092,9 @@ int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name,
                        } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_SUBNET_MASK) == 0) {
                                const gchar *subnet_mask = g_variant_get_string(value, NULL);
                                (*ip_info)->subnet_mask = g_strdup(subnet_mask);
+                       } else if (g_strcmp0(field, WIFI_CONFIG_IPV6_PREFIX_LEN) == 0) {
+                               int prefix_len = g_variant_get_int32(value);
+                               (*ip_info)->prefix_length = prefix_len;
                        } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_GATEWAY_ADDRESS) == 0) {
                                const gchar *gateway_address = g_variant_get_string(value, NULL);
                                (*ip_info)->gateway_address = g_strdup(gateway_address);
index ebcaaf6..dcdaebe 100755 (executable)
@@ -134,7 +134,7 @@ static char *__wifi_create_profile_name(const char *ssid,
        return buf;
 }
 
-static int __ap_convert_netmask_to_prefix_len(const char *netmask)
+int __ap_convert_netmask_to_prefix_len(const char *netmask)
 {
        if (netmask == NULL)
                return 0;
index 04911ec..3037525 100755 (executable)
@@ -597,8 +597,7 @@ EXPORT_API int wifi_manager_config_get_subnet_mask(wifi_manager_config_h config,
        wifi_config_s *h = (wifi_config_s *)config;
 
        if (_wifi_check_config_validity(config) == false || subnet_mask == NULL ||
-                       (address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV4 &&
-                        address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV6)) {
+                       address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV4) {
                WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
                __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
                return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
@@ -625,6 +624,29 @@ EXPORT_API int wifi_manager_config_set_subnet_mask(wifi_manager_config_h config,
        wifi_config_s *h = (wifi_config_s *)config;
 
        if (_wifi_check_config_validity(config) == false ||
+                       address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV4) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       h->ip_info->subnet_mask = g_strdup(subnet_mask);
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int wifi_manager_config_get_prefix_length(wifi_manager_config_h config,
+               wifi_manager_address_family_e address_family, int *prefix_len)
+{
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       wifi_config_s *h = (wifi_config_s *)config;
+
+       if (_wifi_check_config_validity(config) == false || prefix_len == NULL ||
                        (address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV4 &&
                         address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV6)) {
                WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
@@ -632,7 +654,33 @@ EXPORT_API int wifi_manager_config_set_subnet_mask(wifi_manager_config_h config,
                return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
-       h->ip_info->subnet_mask = g_strdup(subnet_mask);
+       if (address_family == WIFI_MANAGER_ADDRESS_FAMILY_IPV4)
+               *prefix_len = __ap_convert_netmask_to_prefix_len(h->ip_info->subnet_mask);
+       else
+               *prefix_len = h->ip_info->prefix_length;
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
+EXPORT_API int wifi_manager_config_set_prefix_length(wifi_manager_config_h config,
+               wifi_manager_address_family_e address_family, int prefix_len)
+{
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       wifi_config_s *h = (wifi_config_s *)config;
+
+       if (_wifi_check_config_validity(config) == false ||
+                       address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV6) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       h->ip_info->prefix_length = prefix_len;
 
        __NETWORK_CAPI_FUNC_EXIT__;
 
index 4af7d58..8da2109 100755 (executable)
@@ -2089,6 +2089,7 @@ int test_wifi_manager_config_save(void)
        int hidden = 0;
        int address_type = 0;
        char ip_addr[40] = { 0, };
+       int prefix_len;
        wifi_manager_config_h config;
        int ip_update = 0;
 
@@ -2157,26 +2158,43 @@ int test_wifi_manager_config_save(void)
                        }
                }
 
-               printf("Input new subnet mask (x:skip, 0:clear) :\n");
-               rv = scanf("%39s", ip_addr);
-               if (rv > 0) {
-                       switch (ip_addr[0]) {
-                       case 'x':
-                               rv = WIFI_MANAGER_ERROR_NONE;
-                               break;
-                       case '0':
-                               rv = wifi_manager_config_set_subnet_mask(config, address_type,
-                                                                                                                NULL);
-                               break;
-                       default:
-                               rv = wifi_manager_config_set_subnet_mask(config, address_type,
-                                                                                                                ip_addr);
+               if (address_type == 0) {
+                       printf("Input new subnet mask (x:skip, 0:clear) :\n");
+                       rv = scanf("%39s", ip_addr);
+                       if (rv > 0) {
+                               switch (ip_addr[0]) {
+                                       case 'x':
+                                               rv = WIFI_MANAGER_ERROR_NONE;
+                                               break;
+                                       case '0':
+                                               rv = wifi_manager_config_set_subnet_mask(config, address_type,
+                                                               NULL);
+                                               break;
+                                       default:
+                                               rv = wifi_manager_config_set_subnet_mask(config, address_type,
+                                                               ip_addr);
+                               }
+
+                               if (rv != WIFI_MANAGER_ERROR_NONE) {
+                                       printf("Fail to set subnet mask[%s]\n",
+                                                       __test_convert_error_to_string(rv));
+                                       return -1;
+                               }
                        }
+               } else {
+                       printf("Input new prefix length (x:skip) :\n");
+                       rv = scanf("%d", &prefix_len);
+                       if (rv > 0) {
+                               if (prefix_len == 'x')
+                                       rv = WIFI_MANAGER_ERROR_NONE;
+                               else
+                                       rv = wifi_manager_config_set_prefix_length(config, address_type, prefix_len);
 
-                       if (rv != WIFI_MANAGER_ERROR_NONE) {
-                               printf("Fail to set subnet mask[%s]\n",
-                                          __test_convert_error_to_string(rv));
-                               return -1;
+                               if (rv != WIFI_MANAGER_ERROR_NONE) {
+                                       printf("Fail to set prefix length[%s]\n",
+                                                       __test_convert_error_to_string(rv));
+                                       return -1;
+                               }
                        }
                }