Added config CAPI to set IP configuration method. 48/186148/7
authorNiraj Kumar Goit <niraj.g@samsung.com>
Tue, 7 Aug 2018 11:40:09 +0000 (17:10 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Fri, 31 Aug 2018 12:22:17 +0000 (17:52 +0530)
Added config CAPI "wifi_manager_config_set_ip_config_type" for
Hidden AP connection with static IP setting.

Change-Id: Id3b1102240b5057a451cbe98787480e4a7e1fee3
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_dbus.h
include/network_interface.h
include/wifi_internal.h
src/network_dbus.c
src/network_interface.c
src/wifi_config.c
src/wifi_internal.c

index 5f7c780..bd5bb2e 100755 (executable)
@@ -129,7 +129,8 @@ int _net_dbus_config_get_id_list(GSList **list);
 int _net_dbus_config_set_field(const gchar *config_id, const gchar *key, const gchar *value);
 int _net_dbus_config_get_passphrase(const gchar *config_id, gchar **passphrase);
 int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *name,
-               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, gboolean is_hidden);
+               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address,
+               net_ip_info_config_s *ip_info, gboolean is_hidden);
 int _net_dbus_config_save_eap_configurations(const gchar *config_id,
                const gchar *name, const gchar *ssid, const gchar *passphrase,
                const gchar *proxy_address, net_eap_config_s *eap_config, gboolean is_hidden);
index 35c4d78..2812b18 100755 (executable)
@@ -249,6 +249,16 @@ typedef struct {
        net_wifi_eap_auth_type_e eap_auth_type;
 } net_eap_config_s;
 
+typedef struct {
+       net_ip_config_type_e ip_type;
+       gchar *ip_address;
+       gchar *subnet_mask;
+       int prefix_length;
+       gchar *gateway_address;
+       net_dns_config_type_e dns_type;
+       gchar *dns_address;
+} net_ip_info_config_s;
+
 typedef void (*net_event_cb)(const net_event_info_s* net_event, void* user_data);
 
 int net_register_client_ext(net_event_cb event_cb, void *user_data);
@@ -323,8 +333,10 @@ int net_get_preferred_ipv6_address(const char *profilename, char **address);
 int net_config_get_id_list(GSList **list);
 int net_config_set_field(const gchar *config_id, const gchar *key, const gchar *value);
 int net_config_get_passphrase(const gchar *config_id, gchar **passphrase);
-int net_config_save_configurations(const gchar *config_id, const gchar *name,
-               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, gboolean is_hidden);
+int net_config_save_configurations(const gchar *config_id,
+               const gchar *name, const gchar *ssid, const gchar *passphrase,
+               const gchar *proxy_address, net_ip_info_config_s *ip_info,
+               gboolean is_hidden);
 int net_config_save_eap_configurations(const gchar *config_id,
                const gchar *name, const gchar *ssid, const gchar *passphrase,
                const gchar *proxy_address, void *eap_config, gboolean is_hidden);
index f8bcf51..470582e 100755 (executable)
@@ -46,6 +46,8 @@ extern "C" {
 #define WIFI_CONFIG_SECURITY_TYPE                      "Security"
 #define WIFI_CONFIG_PROXYADDRESS                       "ProxyAddress"
 #define WIFI_CONFIG_HIDDEN                                     "Hidden"
+#define WIFI_CONFIG_IPV4_METHOD                        "IPv4.method"
+#define WIFI_CONFIG_IPV6_METHOD                        "IPv6.method"
 #define WIFI_CONFIG_FAILURE                                    "Failure"
 #define WIFI_CONFIG_EAP_ANONYMOUS_IDENTITY     "AnonymousIdentity"
 #define WIFI_CONFIG_EAP_CACERT                         "CACertFile"
@@ -159,6 +161,16 @@ typedef struct {
 } wifi_eap_config_s;
 
 typedef struct {
+       wifi_manager_ip_config_type_e ip_type;
+       gchar *ip_address;
+       gchar *subnet_mask;
+       int prefix_length;
+       gchar *gateway_address;
+       wifi_manager_dns_config_type_e dns_type;
+       gchar *dns_address;
+} wifi_config_ip_info_s;
+
+typedef struct {
        gchar *name;
        gchar *passphrase;
        wifi_manager_security_type_e security_type;
@@ -168,6 +180,7 @@ typedef struct {
        gchar *proxy_address;
        wifi_manager_address_family_e address_family;
        wifi_eap_config_s *eap_config;
+       wifi_config_ip_info_s *ip_info;
        wifi_manager_error_e last_error;
 } wifi_config_s;
 
@@ -322,7 +335,8 @@ gchar * _wifi_config_get_config_id(const gchar *name, wifi_manager_security_type
 int _wifi_config_get_config_id_list(GSList **list);
 
 int _wifi_save_configuration(const gchar *name, const gchar *passphrase,
-               wifi_manager_security_type_e security_type, const gchar *proxy_address, gboolean is_hidden);
+               wifi_manager_security_type_e security_type, const gchar *proxy_address,
+               wifi_config_ip_info_s *ip_info, gboolean is_hidden);
 int _wifi_load_configurations(void);
 int _wifi_foreach_configuration(wifi_manager_config_list_cb callback, void *user_data);
 int _wifi_remove_configuration(const gchar *config_id);
index 2e8b5e6..859da7a 100755 (executable)
@@ -2816,7 +2816,8 @@ int _net_dbus_config_get_passphrase(const gchar *config_id, gchar **passphrase)
 }
 
 int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *name,
-               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, gboolean is_hidden)
+               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address,
+               net_ip_info_config_s *ip_info, gboolean is_hidden)
 {
        __NETWORK_FUNC_ENTER__;
 
@@ -2824,6 +2825,8 @@ int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *na
        GVariantBuilder *b = NULL;
        GVariant *params = NULL;
        GVariant *message = NULL;
+       const char *manual_method = "manual";
+       const char *dhcp_method = "dhcp";
 
        b = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        g_variant_builder_add(b, "{sv}", WIFI_CONFIG_NAME, g_variant_new_string(name));
@@ -2835,6 +2838,19 @@ int _net_dbus_config_save_configurations(const gchar *config_id, const gchar *na
        if (is_hidden == TRUE)
                g_variant_builder_add(b, "{sv}", WIFI_CONFIG_HIDDEN, g_variant_new_string("TRUE"));
 
+       switch (ip_info->ip_type) {
+       case NET_IP_CONFIG_TYPE_STATIC:
+                       g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_METHOD,
+                                                         g_variant_new_string(manual_method));
+               break;
+       case NET_IP_CONFIG_TYPE_DYNAMIC:
+                       g_variant_builder_add(b, "{sv}", WIFI_CONFIG_IPV4_METHOD,
+                                                                 g_variant_new_string(dhcp_method));
+               break;
+       default:
+               break;
+       }
+
        params = g_variant_new("(s@a{sv})", config_id, g_variant_builder_end(b));
        g_variant_builder_unref(b);
 
index e770d68..8a1cea6 100755 (executable)
@@ -3395,7 +3395,8 @@ int net_config_get_passphrase(const gchar *config_id, gchar **passphrase)
 }
 
 int net_config_save_configurations(const gchar *config_id, const gchar *name,
-               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address, gboolean is_hidden)
+               const gchar *ssid, const gchar *passphrase, const gchar *proxy_address,
+               net_ip_info_config_s *ip_info, gboolean is_hidden)
 {
        __NETWORK_FUNC_ENTER__;
 
@@ -3407,8 +3408,8 @@ int net_config_save_configurations(const gchar *config_id, const gchar *name,
                return NET_ERR_APP_NOT_REGISTERED; //LCOV_EXCL_LINE
        }
 
-       Error = _net_dbus_config_save_configurations(config_id,
-                               name, ssid, passphrase, proxy_address, is_hidden);
+       Error = _net_dbus_config_save_configurations(config_id, name, ssid,
+                       passphrase, proxy_address, ip_info, is_hidden);
        if (Error != NET_ERR_NONE)
                WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE
                                "Failed to save configurations. Error [%s]",
index c39fb42..8b1b800 100755 (executable)
@@ -46,12 +46,29 @@ EXPORT_API int wifi_manager_config_create(wifi_manager_h wifi, const char *name,
        h->proxy_address = NULL;
        h->address_family = WIFI_MANAGER_ADDRESS_FAMILY_IPV4;
        h->eap_config = NULL;
+       h->ip_info = g_new0(wifi_config_ip_info_s, 1);
+       if (h->ip_info == NULL) {
+               g_free(h->name); //LCOV_EXCL_LINE
+               g_free(h->passphrase); //LCOV_EXCL_LINE
+               g_free(h); //LCOV_EXCL_LINE
+               __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+       }
+
+       h->ip_info->ip_type = WIFI_MANAGER_IP_CONFIG_TYPE_NONE;
+       h->ip_info->ip_address = NULL;
+       h->ip_info->subnet_mask = NULL;
+       h->ip_info->prefix_length = 0;
+       h->ip_info->gateway_address = NULL;
+       h->ip_info->dns_type = WIFI_MANAGER_DNS_CONFIG_TYPE_NONE;
+       h->ip_info->dns_address = NULL;
 
        if (security_type == WIFI_MANAGER_SECURITY_TYPE_EAP) {
                h->eap_config = g_new0(wifi_eap_config_s, 1);
                if (h->eap_config == NULL) {
                        g_free(h->name); //LCOV_EXCL_LINE
                        g_free(h->passphrase); //LCOV_EXCL_LINE
+                       g_free(h->ip_info); //LCOV_EXCL_LINE
                        g_free(h); //LCOV_EXCL_LINE
                        __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
                        return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
@@ -107,12 +124,37 @@ EXPORT_API int wifi_manager_config_clone(wifi_manager_config_h origin, wifi_mana
        h->proxy_address = g_strdup(config->proxy_address);
        h->address_family = config->address_family;
 
+       if (config->ip_info) {
+               h->ip_info = g_new0(wifi_config_ip_info_s, 1);
+               if (h->ip_info == NULL) {
+                       g_free(h->name); //LCOV_EXCL_LINE
+                       g_free(h->passphrase); //LCOV_EXCL_LINE
+                       g_free(h->proxy_address); //LCOV_EXCL_LINE
+                       g_free(h); //LCOV_EXCL_LINE
+                       __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
+                       return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+               }
+
+               h->ip_info->ip_type = config->ip_info->ip_type;
+               h->ip_info->ip_address = g_strdup(config->ip_info->ip_address);
+               h->ip_info->subnet_mask = g_strdup(config->ip_info->subnet_mask);
+               h->ip_info->prefix_length = config->ip_info->prefix_length;
+               h->ip_info->gateway_address = g_strdup(config->ip_info->gateway_address);
+               h->ip_info->dns_type = config->ip_info->dns_type;
+               h->ip_info->dns_address = g_strdup(config->ip_info->dns_address);
+       }
+
        if (config->eap_config) {
                h->eap_config = g_new0(wifi_eap_config_s, 1);
                if (h->eap_config == NULL) {
                        g_free(h->name); //LCOV_EXCL_LINE
                        g_free(h->passphrase); //LCOV_EXCL_LINE
                        g_free(h->proxy_address); //LCOV_EXCL_LINE
+                       g_free(h->ip_info->ip_address); //LCOV_EXCL_LINE
+                       g_free(h->ip_info->subnet_mask); //LCOV_EXCL_LINE
+                       g_free(h->ip_info->gateway_address); //LCOV_EXCL_LINE
+                       g_free(h->ip_info->dns_address); //LCOV_EXCL_LINE
+                       g_free(h->ip_info); //LCOV_EXCL_LINE
                        g_free(h); //LCOV_EXCL_LINE
                        __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE
                        return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
@@ -154,6 +196,13 @@ EXPORT_API int wifi_manager_config_destroy(wifi_manager_config_h config)
        g_free(h->name);
        g_free(h->passphrase);
        g_free(h->proxy_address);
+       if (h->ip_info) {
+               g_free(h->ip_info->ip_address);
+               g_free(h->ip_info->subnet_mask);
+               g_free(h->ip_info->gateway_address);
+               g_free(h->ip_info->dns_address);
+               g_free(h->ip_info);
+       }
        if (h->eap_config) {
                g_free(h->eap_config->ca_cert);
                g_free(h->eap_config->client_cert);
@@ -196,8 +245,8 @@ EXPORT_API int wifi_manager_config_save(wifi_manager_h wifi,
                if (ret != WIFI_MANAGER_ERROR_NONE)
                        WIFI_LOG(WIFI_ERROR, "Fail to wifi_save_eap_configurations"); //LCOV_EXCL_LINE
        } else {
-               ret = _wifi_save_configuration(h->name,
-                                       h->passphrase, h->security_type, h->proxy_address, h->is_hidden);
+               ret = _wifi_save_configuration(h->name, h->passphrase, h->security_type,
+                               h->proxy_address, h->ip_info, h->is_hidden);
                if (ret != WIFI_MANAGER_ERROR_NONE)
                        WIFI_LOG(WIFI_ERROR, "Fail to save configurations [%d]", ret); //LCOV_EXCL_LINE
        }
@@ -430,6 +479,31 @@ EXPORT_API int wifi_manager_config_get_hidden_ap_property(wifi_manager_config_h
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+EXPORT_API int wifi_manager_config_set_ip_config_type(wifi_manager_config_h config,
+               wifi_manager_address_family_e address_family,
+               wifi_manager_ip_config_type_e type)
+{
+       __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_IPV4 &&
+                        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->ip_type = type;
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 EXPORT_API int wifi_manager_config_get_eap_anonymous_identity(wifi_manager_config_h config,
                char **anonymous_identity)
 {
index c7a5e84..d1a73c2 100755 (executable)
@@ -2793,7 +2793,8 @@ int _wifi_config_get_config_id_list(GSList **list)
 }
 
 int _wifi_save_configuration(const gchar *name, const gchar *passphrase,
-               wifi_manager_security_type_e security_type, const gchar *proxy_address, gboolean is_hidden)
+               wifi_manager_security_type_e security_type, const gchar *proxy_address,
+               wifi_config_ip_info_s *ip_info, gboolean is_hidden)
 {
        int rv;
        gchar *config_id = NULL;
@@ -2816,7 +2817,8 @@ int _wifi_save_configuration(const gchar *name, const gchar *passphrase,
        config_id = _wifi_config_get_config_id(name, security_type);
        ssid = __wifi_change_name_to_hexadecimal(name);
 
-       rv = net_config_save_configurations(config_id, name, ssid, passphrase, proxy_address, is_hidden);
+       rv = net_config_save_configurations(config_id, name, ssid, passphrase,
+                       proxy_address, (void *)ip_info, is_hidden);
        if (rv == NET_ERR_ACCESS_DENIED) {
                WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE
                return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE