Add converting function for netmask 26/120026/2 accepted/tizen/common/20170322.153706 accepted/tizen/ivi/20170322.235758 accepted/tizen/mobile/20170322.235624 accepted/tizen/tv/20170322.235706 accepted/tizen/unified/20170322.235827 accepted/tizen/wearable/20170322.235733 submit/tizen/20170322.011410
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 21 Mar 2017 07:08:28 +0000 (16:08 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 21 Mar 2017 07:11:14 +0000 (16:11 +0900)
Change-Id: Ic90e219ac7589918e87c2b7c3873ddf9d7214290
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
include/network_config.h
src/network_interface.c
src/wifi_ap.c

index ca8cce05abfa0a200a33ea7c57eb89d214a9e91b..ba0dde9eae220d555dfe5c310adebd6cd51a2e55 100755 (executable)
@@ -103,13 +103,14 @@ typedef struct {
        net_addr_s IpAddr;                                                              /** IP Address for the connection link */
        char BNetmask;                                                                  /** Whether subnet mask present or not. */
        net_addr_s SubnetMask;                                                  /** Subnet mask */
+       int PrefixLen;                                                                  /** IPv4 Prefix Length for the connection link */
        char BDefGateway;                                                               /** Whether gateway address present or not */
        net_addr_s GatewayAddr;                                                 /** Gateway address */
        net_proxy_type_e ProxyMethod;                                   /** Proxy Method type */
        char ProxyAddr[NET_PROXY_LEN_MAX+1];                    /** Proxy address */
        char MacAddr[NET_MAX_MAC_ADDR_LEN+1];                   /** MAC address */
        net_addr_s IpAddr6;                                                             /** IP Address for the connection link */
-       int PrefixLen6;                                                                 /** Prefix Length for the connection link */
+       int PrefixLen6;                                                                 /** IPv6 Prefix Length for the connection link */
        char BDefGateway6;                                                              /** Whether gateway address present or not */
        net_addr_s GatewayAddr6;                                                /** Gateway address */
        char Privacy6[NET_IPV6_MAX_PRIVACY_LEN+1];              /** Privacy of the connection link */
index e7fffab606a791852170a754b2403713252f0993..a3fc404d8af9629d7b7510ba97ae69441d613a9f 100755 (executable)
@@ -70,6 +70,21 @@ static int __net_check_profile_privilege()
        return Error;
 }
 
+static int __net_get_prefix_len(const char *netmask)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       in_addr_t mask = inet_network(netmask);
+       int prefix_len = 0;
+
+       for (; mask; mask <<= 1)
+               ++prefix_len;
+
+       __NETWORK_FUNC_EXIT__;
+
+       return prefix_len;
+}
+
 static net_wifi_state_e __net_get_wifi_connection_state(net_err_e *net_error)
 {
        net_err_e Error = NET_ERR_NONE;
@@ -265,6 +280,7 @@ static int __net_extract_common_info(const char *key, GVariant *variant, net_pro
                                value = g_variant_get_string(var, NULL);
 
                                __net_extract_ip(value, &net_info->SubnetMask);
+                               net_info->PrefixLen = __net_get_prefix_len(value);
                                net_info->BNetmask = TRUE;
                        } else if (g_strcmp0(subKey, "Gateway") == 0) {
                                value = g_variant_get_string(var, NULL);
@@ -304,6 +320,7 @@ static int __net_extract_common_info(const char *key, GVariant *variant, net_pro
                                        value = g_variant_get_string(var, NULL);
 
                                        __net_extract_ip(value, &net_info->SubnetMask);
+                                       net_info->PrefixLen = __net_get_prefix_len(value);
                                        net_info->BNetmask = TRUE;
                                } else if (g_strcmp0(subKey, "Gateway") == 0 &&
                                                        net_info->GatewayAddr.Data.Ipv4.s_addr == 0) {
index 59a707ddde2fd2b07754ca28ba6ec87f9dd82b44..87205bc8736d76660abad9ac334d38751faea4e2 100755 (executable)
@@ -130,6 +130,26 @@ static char *__wifi_create_profile_name(const char *ssid,
        return buf;
 }
 
+static int __ap_convert_netmask_to_prefix_len(const char *netmask)
+{
+       if (netmask == NULL)
+               return 0;
+
+       in_addr_t mask = inet_network(netmask);
+       int prefix_len = 0;
+
+       for (; mask; mask <<= 1)
+               ++prefix_len;
+
+       return prefix_len;
+}
+
+static in_addr_t __ap_convert_prefix_len_to_netmask(int prefix_len)
+{
+       return (prefix_len ? (in_addr_t) 0xFFFFFFFFu >> (32 - prefix_len) : 0);
+}
+
+
 static bool _wifi_set_profile_name_to_ap(net_profile_info_s *ap_info)
 {
        char *profile_name = NULL;
@@ -722,6 +742,8 @@ EXPORT_API int wifi_manager_ap_set_subnet_mask(wifi_manager_ap_h ap,
                else if (inet_pton(AF_INET, subnet_mask,
                                &(profile_info->net_info.SubnetMask.Data.Ipv4)) < 1)
                        return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+
+               profile_info->net_info.PrefixLen = __ap_convert_netmask_to_prefix_len(subnet_mask);
        }
 
        return WIFI_MANAGER_ERROR_NONE;
@@ -742,7 +764,10 @@ EXPORT_API int wifi_manager_ap_get_prefix_length(wifi_manager_ap_h ap,
 
        net_profile_info_s *profile_info = ap;
 
-       *prefix_len = profile_info->net_info.PrefixLen6;
+       if (address_family == WIFI_MANAGER_ADDRESS_FAMILY_IPV4)
+               *prefix_len = profile_info->net_info.PrefixLen;
+       else if (address_family == WIFI_MANAGER_ADDRESS_FAMILY_IPV6)
+               *prefix_len = profile_info->net_info.PrefixLen6;
 
        return WIFI_MANAGER_ERROR_NONE;
 }
@@ -761,7 +786,12 @@ EXPORT_API int wifi_manager_ap_set_prefix_length(wifi_manager_ap_h ap,
 
        net_profile_info_s *profile_info = ap;
 
-       profile_info->net_info.PrefixLen6 = prefix_len;
+       if (address_family == WIFI_MANAGER_ADDRESS_FAMILY_IPV4) {
+               profile_info->net_info.PrefixLen = prefix_len;
+               profile_info->net_info.SubnetMask.Data.Ipv4.s_addr =
+                       __ap_convert_prefix_len_to_netmask(prefix_len);
+       } else if (address_family == WIFI_MANAGER_ADDRESS_FAMILY_IPV6)
+               profile_info->net_info.PrefixLen6 = prefix_len;
 
        return WIFI_MANAGER_ERROR_NONE;
 }