Added new CAPI to get IPv4 details 62/145462/1
authorsaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:23:06 +0000 (19:23 +0900)
committersaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:23:06 +0000 (19:23 +0900)
This patch adds new CAPI to get below IPv4 details:
1. IPv4 Config Type
2. IPv4 Address
3. IPv4 Subnet Mask

Change-Id: I092931b8d5d007ceaca76a8eaec71380b33828c7
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/wifi-mesh.h
include/wifi-mesh_private.h
src/wifi-mesh-dbus.c
src/wifi-mesh.c
test/wifi-mesh-network.c

index fbfea1500a23c2b27a5a03986635e1227e87b3bc..7c73c5b28890a9a23ea77d97c2b6ace295467967 100644 (file)
@@ -95,6 +95,13 @@ typedef enum {
  */
 #define MAX_PASSPHRASE_LEN (64+1)
 
+/**
+ * @brief The maximum length of IPv4 Address
+ *
+ * @since_tizen 4.0
+ */
+#define MAX_IPV4_ADDRESS_LEN 16
+
 /**
  * @brief Enumeration for the security type of the Wi-Fi Mesh network.
  * @since_tizen 4.0
@@ -115,6 +122,25 @@ typedef enum {
        WIFI_MESH_CONNECTION_STATE_CONNECTED /**< Wi-Fi Mesh network is connected */
 } wifi_mesh_connection_state_e;
 
+/**
+ * @brief Enumeration for address family of the Wi-Fi Mesh network.
+ * @since_tizen 4.0
+*/
+typedef enum {
+       WIFI_MESH_ADDRESS_FAMILY_IPV4 = 0,    /**< IPV4 Address type */
+       WIFI_MESH_ADDRESS_FAMILY_IPV6 = 1,    /**< IPV6 Address type */
+} wifi_mesh_address_family_e;
+
+/**
+ * @brief Enumeration for the IP Config Type of the Wi-Fi Mesh network.
+ * @since_tizen 4.0
+ */
+typedef enum {
+       WIFI_MESH_IP_CONFIG_TYPE_UNKNOWN = 0, /**< Unknown IP Config Type */
+       WIFI_MESH_IP_CONFIG_TYPE_DYNAMIC, /**< DHCP IP Config Type */
+       WIFI_MESH_IP_CONFIG_TYPE_STATIC /**< Static IP Config Type */
+} wifi_mesh_ip_config_type_e;
+
 /**
  * @brief The events for wifi_mesh_event_cb
  *
@@ -507,6 +533,61 @@ int wifi_mesh_network_set_passphrase(wifi_mesh_network_h network, const char* pa
  */
 int wifi_mesh_network_get_connection_state(wifi_mesh_network_h network, wifi_mesh_connection_state_e *state);
 
+/**
+ * @brief Gets the IP Config Type
+ * @details This function is to gets the IP Config Type
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] network The Wi-Fi mesh network information handle.
+ * @param[in] address_family Address Family
+ * @param[out] ip_type The IP Config Type
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_MESH_ERROR_NONE Successful
+ * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int wifi_mesh_network_get_ip_config_type(wifi_mesh_network_h network,
+               wifi_mesh_address_family_e address_family,
+               wifi_mesh_ip_config_type_e *ip_type);
+
+/**
+ * @brief Gets the IP Address
+ * @details This function is to gets the IP Address
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] network The Wi-Fi mesh network information handle.
+ * @param[in] address_family Address Family
+ * @param[out] ip_address The IP Address
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_MESH_ERROR_NONE Successful
+ * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int wifi_mesh_network_get_ip_address(wifi_mesh_network_h network,
+               wifi_mesh_address_family_e address_family, char **ip_address);
+
+/**
+ * @brief Gets the Subnet Mask
+ * @details This function is to gets the subnet mask
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] network The Wi-Fi mesh network information handle.
+ * @param[in] address_family Address Family
+ * @param[out] subnet_mask The Subnet Mask
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_MESH_ERROR_NONE Successful
+ * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ */
+int wifi_mesh_network_get_subnet_mask(wifi_mesh_network_h network,
+               wifi_mesh_address_family_e address_family, char **subnet_mask);
+
 /**
  * @brief Gets address from the Wi-Fi mesh peer.
  * @details This function is to return mesh network id
index 049ebfcd272c0788f9116ae54b54a9990a2b5b9b..d7b975c0222f3d1c87eb2c354b3cdf421b7a761d 100644 (file)
@@ -81,6 +81,9 @@ struct mesh_network_s {
        wifi_mesh_security_type_e security; /**< Security type */
        char passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase */
        wifi_mesh_connection_state_e state; /**< Connection state */
+       wifi_mesh_ip_config_type_e ipv4_type; /**< IPv4 Config Type */
+       char ipv4_address[MAX_IPV4_ADDRESS_LEN]; /**< IPv4 Address */
+       char ipv4_netmask[MAX_IPV4_ADDRESS_LEN]; /**< IPv4 Netmask */
 };
 
 struct mesh_station_info_s {
index aa7711f5e76692363d16f78271829103aaa219e7..d3674db3c170382528af16e00d2c17fdce9192ec 100644 (file)
@@ -1124,10 +1124,14 @@ int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _netw
                int channel = -1;
                int security = -1;
                int state = 0;
+               int ipv4_type = 0;
+               char *ipv4_address = NULL;
+               char *ipv4_netmask = NULL;
                int svc_result = 0;
 
-               g_variant_get(variant, "(ssiiii)", &meshid, &bssid, &channel,
-                       &security, &state, &svc_result);
+               g_variant_get(variant, "(ssiiiissi)", &meshid, &bssid, &channel,
+                       &security, &state, &ipv4_type, &ipv4_address, &ipv4_netmask,
+                       &svc_result);
                LOGD("get_joined_mesh_network status 0x%x", svc_result);
                result = __convert_service_error_type(svc_result);
 
@@ -1139,6 +1143,9 @@ int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _netw
                g_joined_network.data_rate = 0;
                g_joined_network.security = MESH_SECURITY_NONE;
                g_joined_network.state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED;
+               g_joined_network.ipv4_type = WIFI_MESH_IP_CONFIG_TYPE_UNKNOWN;
+               memset(g_joined_network.ipv4_address, 0, MAX_IPV4_ADDRESS_LEN);
+               memset(g_joined_network.ipv4_netmask, 0, MAX_IPV4_ADDRESS_LEN);
 
                if (SERVICE_ERROR_NO_DATA == svc_result) {
                        *_network = NULL;
@@ -1160,6 +1167,17 @@ int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _netw
                g_joined_network.rssi = -1;
                g_joined_network.security = security;
                g_joined_network.state = state;
+               g_joined_network.ipv4_type = ipv4_type;
+               if (ipv4_address) {
+                       LOGD("  IPv4 Address : %s", ipv4_address);
+                       snprintf(g_joined_network.ipv4_address, MAX_IPV4_ADDRESS_LEN, "%s",
+                                        ipv4_address);
+               }
+               if (ipv4_netmask) {
+                       LOGD("  IPv4 Netmask : %s", ipv4_netmask);
+                       snprintf(g_joined_network.ipv4_netmask, MAX_IPV4_ADDRESS_LEN, "%s",
+                                        ipv4_netmask);
+               }
 
                *_network = &g_joined_network;
        } else if (error) {
index b5de9fd48a8df4c46851f1dd29500f278a2fed0c..c7658bcb76049d7c22af31e7f6a526b1cd7d60ce 100644 (file)
@@ -354,6 +354,79 @@ EXPORT_API int wifi_mesh_network_get_connection_state(wifi_mesh_network_h networ
        return WIFI_MESH_ERROR_NONE;
 }
 
+EXPORT_API int wifi_mesh_network_get_ip_config_type(wifi_mesh_network_h network,
+               wifi_mesh_address_family_e address_family,
+               wifi_mesh_ip_config_type_e *ip_type)
+{
+       struct mesh_network_s *net = (struct mesh_network_s *)network;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (NULL == network || ip_type == NULL) {
+               /* LCOV_EXCL_START */
+               LOGE("Invalid parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (address_family != WIFI_MESH_ADDRESS_FAMILY_IPV4) {
+               LOGE("Invalid Address Family %d", address_family);
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+       }
+
+       *ip_type = net->ipv4_type;
+
+       return WIFI_MESH_ERROR_NONE;
+}
+
+EXPORT_API int wifi_mesh_network_get_ip_address(wifi_mesh_network_h network,
+               wifi_mesh_address_family_e address_family, char **ip_address)
+{
+       struct mesh_network_s *net = (struct mesh_network_s *)network;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (NULL == network || ip_address == NULL) {
+               /* LCOV_EXCL_START */
+               LOGE("Invalid parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (address_family != WIFI_MESH_ADDRESS_FAMILY_IPV4) {
+               LOGE("Invalid Address Family %d", address_family);
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+       }
+
+       *ip_address = strdup(net->ipv4_address);
+
+       return WIFI_MESH_ERROR_NONE;
+}
+
+EXPORT_API int wifi_mesh_network_get_subnet_mask(wifi_mesh_network_h network,
+               wifi_mesh_address_family_e address_family, char **subnet_mask)
+{
+       struct mesh_network_s *net = (struct mesh_network_s *)network;
+
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (NULL == network || subnet_mask == NULL) {
+               /* LCOV_EXCL_START */
+               LOGE("Invalid parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (address_family != WIFI_MESH_ADDRESS_FAMILY_IPV4) {
+               LOGE("Invalid Address Family %d", address_family);
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+       }
+
+       *subnet_mask = strdup(net->ipv4_netmask);
+
+       return WIFI_MESH_ERROR_NONE;
+}
+
 EXPORT_API int wifi_mesh_peer_get_address(wifi_mesh_peer_h peer, char **address)
 {
        struct mesh_peer_s *peer_info = (struct mesh_peer_s *)peer;
index 0d6b153d3934ce06cca48a9d6361b88a2348c926..fa8b7084d6e11352e7e5e14c37bd080165e7f033 100644 (file)
@@ -461,6 +461,9 @@ static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
        bool joined = false;
        wifi_mesh_connection_state_e _state = WIFI_MESH_CONNECTION_STATE_DISCONNECTED;
        wifi_mesh_security_type_e _security = MESH_SECURITY_NONE;
+       wifi_mesh_ip_config_type_e _ipv4_type = WIFI_MESH_IP_CONFIG_TYPE_UNKNOWN;
+       char *_ipv4_address = NULL;
+       char *_ipv4_netmask = NULL;
        wifi_mesh_network_h network = NULL;
 
        msg("Get Joined Mesh Network Information");
@@ -491,9 +494,20 @@ static int run_get_joined_mesh_network(MManager *mm, struct menu_data *menu)
                        (MESH_SECURITY_SAE == _security) ? "SAE" : "NONE");
                wifi_mesh_network_get_connection_state(network, &_state);
                msgb("  State    = %s", wifi_mesh_connection_event_to_string(_state));
+               wifi_mesh_network_get_ip_config_type(network,
+                                                               WIFI_MESH_ADDRESS_FAMILY_IPV4, &_ipv4_type);
+               msgb("  IPv4 Config Type  = %d", _ipv4_type);
+               wifi_mesh_network_get_ip_address(network, WIFI_MESH_ADDRESS_FAMILY_IPV4,
+                                                               &_ipv4_address);
+               msgb("  IPv4 Address  = %s", _ipv4_address);
+               wifi_mesh_network_get_subnet_mask(network,
+                                                               WIFI_MESH_ADDRESS_FAMILY_IPV4, &_ipv4_netmask);
+               msgb("  IPv4 Subnet Mask  = %s", _ipv4_netmask);
 
                if (_meshid) free(_meshid);
                if (_bssid) free(_bssid);
+               if (_ipv4_address) free(_ipv4_address);
+               if (_ipv4_netmask) free(_ipv4_netmask);
        }
        msg("");
        msg(" - wifi_mesh_get_joined_network() ret: [0x%X] [%s]",