Added CAPI to get DHCP Server Address 22/123622/3
authortaesub kim <taesub.kim@samsung.com>
Thu, 6 Apr 2017 08:44:40 +0000 (17:44 +0900)
committertaesub kim <taesub.kim@samsung.com>
Tue, 11 Apr 2017 10:00:54 +0000 (19:00 +0900)
Change-Id: I1a4e86966f27961a1df4ceaeda972bc933862b60
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
include/network_config.h
include/wifi-manager.h
src/network_interface.c
src/wifi_ap.c
test/wifi_manager_test.c

index ba0dde9..6150642 100755 (executable)
@@ -106,6 +106,8 @@ typedef struct {
        int PrefixLen;                                                                  /** IPv4 Prefix Length for the connection link */
        char BDefGateway;                                                               /** Whether gateway address present or not */
        net_addr_s GatewayAddr;                                                 /** Gateway address */
+       char BServerAddr;                                                               /** Whether DHCP Server address present or not */
+       net_addr_s ServerAddr;                                                  /** DHCP Server 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 */
index b7cc2db..554733e 100755 (executable)
@@ -1874,6 +1874,23 @@ int wifi_manager_ap_set_gateway_address(wifi_manager_ap_h ap,
                wifi_manager_address_family_e address_family, const char *gateway_address);
 
 /**
+ * @brief Gets the DHCP Server address.
+ * @since_tizen 4.0
+ * @remarks You must release @a dhcp_server using g_free(). Currently it is only
+ *          supported for IPv4 Address Family.
+ * @param[in] ap                The access point handle
+ * @param[in] address_family    The address family
+ * @param[out] server_address   The DHCP server address
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_OUT_OF_MEMORY        Out of memory
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Operation not Supported
+ */
+int wifi_manager_ap_get_dhcp_server_address(wifi_manager_ap_h ap,
+               wifi_manager_address_family_e address_family, char **dhcp_server);
+
+/**
  * @brief Gets the proxy address.
  * @since_tizen 3.0
  * @remarks You must release @a proxy_address using free().
index d558cf7..3c14eb4 100755 (executable)
@@ -272,6 +272,12 @@ static int __net_extract_common_info(const char *key, GVariant *variant, net_pro
                                else if (g_strcmp0(value, "off") == 0)
                                        net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF;
 
+                               if (net_info->IpConfigType != NET_IP_CONFIG_TYPE_DYNAMIC) {
+                                       net_info->BServerAddr = FALSE;
+                                       net_info->ServerAddr.Type = NET_ADDR_IPV4;
+                                       net_info->ServerAddr.Data.Ipv4.s_addr = 0;
+                               }
+
                        } else if (g_strcmp0(subKey, "Address") == 0) {
                                value = g_variant_get_string(var, NULL);
 
@@ -287,6 +293,11 @@ static int __net_extract_common_info(const char *key, GVariant *variant, net_pro
 
                                __net_extract_ip(value, &net_info->GatewayAddr);
                                net_info->BDefGateway = TRUE;
+                       } else if (g_strcmp0(subKey, "DHCPServerIP") == 0) {
+                               value = g_variant_get_string(var, NULL);
+
+                               __net_extract_ip(value, &net_info->ServerAddr);
+                               net_info->BServerAddr = TRUE;
                        }
                }
                g_variant_iter_free(iter);
@@ -1314,6 +1325,9 @@ int net_init_profile_info(net_profile_info_s *ProfInfo)
        net_info->BDefGateway = FALSE;
        net_info->GatewayAddr.Type = NET_ADDR_IPV4;
        net_info->GatewayAddr.Data.Ipv4.s_addr = 0;
+       net_info->BServerAddr = FALSE;
+       net_info->ServerAddr.Type = NET_ADDR_IPV4;
+       net_info->ServerAddr.Data.Ipv4.s_addr = 0;
 
        net_info->IpConfigType6 = 0;
        net_info->IpAddr6.Type = NET_ADDR_IPV6;
index 5ad2ecf..8c1c39e 100755 (executable)
@@ -869,6 +869,42 @@ EXPORT_API int wifi_manager_ap_set_gateway_address(wifi_manager_ap_h ap,
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+
+EXPORT_API int wifi_manager_ap_get_dhcp_server_address(wifi_manager_ap_h ap,
+               wifi_manager_address_family_e address_family, char** dhcp_server)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       if (_wifi_check_ap_validity(ap) == false ||
+           (address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV4 &&
+            address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV6)) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       if (address_family == WIFI_MANAGER_ADDRESS_FAMILY_IPV6) {
+               WIFI_LOG(WIFI_ERROR, "Not supported"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_NOT_SUPPORTED; //LCOV_EXCL_LINE
+       }
+
+       net_profile_info_s *profile_info = ap;
+
+       WIFI_LOG(WIFI_INFO, "IP Config %d, DHCP Server Address %s",
+                       profile_info->net_info.IpConfigType,
+                       profile_info->net_info.BServerAddr ? "TRUE" : "FALSE");
+
+       *dhcp_server = __ap_convert_ip_to_string(
+                       &profile_info->net_info.ServerAddr,
+                       address_family);
+
+       if (*dhcp_server == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Out of memory\n");
+               return WIFI_MANAGER_ERROR_OUT_OF_MEMORY;
+       }
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 EXPORT_API int wifi_manager_ap_get_proxy_address(wifi_manager_ap_h ap,
                wifi_manager_address_family_e address_family, char **proxy_address)
 {
index aa35e4f..949b6f2 100755 (executable)
@@ -943,6 +943,15 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user
                } else
                        printf("Fail to get Gateway\n");
 
+               if (address_type == 0) {
+                       if (wifi_manager_ap_get_dhcp_server_address(ap, address_type, &str_value) ==
+                                       WIFI_MANAGER_ERROR_NONE) {
+                               printf("DHCP Server : %s\n", str_value);
+                               g_free(str_value);
+                       } else
+                               printf("Fail to get DHCP Server\n");
+               }
+
                if (wifi_manager_ap_get_proxy_type(ap, &proxy_type) == WIFI_MANAGER_ERROR_NONE)
                        printf("Proxy type : %d\n", proxy_type);
                else