From: Niraj Kumar Goit Date: Thu, 9 Aug 2018 12:34:46 +0000 (+0530) Subject: Added config CAPIs to get IP configuration details. X-Git-Tag: accepted/tizen/unified/20180907.211654~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=487e98ec3400c0c32fcd748b3751088a547bf336;p=platform%2Fcore%2Fapi%2Fwifi-manager.git Added config CAPIs to get IP configuration details. Added below config CAPIs to get IP configuration details for Hidden AP connection with static IP setting. - wifi_manager_config_get_ip_config_type() - wifi_manager_config_get_ip_address() - wifi_manager_config_get_subnet_mask() - wifi_manager_config_get_gateway_address() - wifi_manager_config_get_dns_config_type() - wifi_manager_config_get_dns_address() Change-Id: I1659f82be81725b1da1d7217a0dbfe8081d394d7 Signed-off-by: Niraj Kumar Goit --- diff --git a/include/network_dbus.h b/include/network_dbus.h index bd5bb2e..9c4f23a 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -136,7 +136,8 @@ int _net_dbus_config_save_eap_configurations(const gchar *config_id, const gchar *proxy_address, net_eap_config_s *eap_config, gboolean is_hidden); int _net_dbus_config_remove_configurations(const gchar *config_id); int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, - net_wifi_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, void *last_error); + net_wifi_security_type_e *security_type, gchar **proxy_address, + gboolean *is_hidden, net_ip_info_config_s **ip_info, void *last_error); int _net_dbus_config_load_eap_configurations(const gchar *config_id, gchar **name, net_wifi_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, net_eap_config_s **eap_config, void *last_error); diff --git a/include/network_interface.h b/include/network_interface.h index 378acb7..88df089 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -343,7 +343,8 @@ int net_config_save_eap_configurations(const gchar *config_id, const gchar *proxy_address, void *eap_config, gboolean is_hidden); int net_config_remove_configurations(const gchar *config_id); int net_config_load_configurations(const gchar *config_id, gchar **name, - void *security_type, gchar **proxy_address, gboolean *is_hidden, void *last_error); + void *security_type, gchar **proxy_address, gboolean *is_hidden, + net_ip_info_config_s **ip_info, void *last_error); int net_config_load_eap_configurations(const gchar *config_id, gchar **name, void *security_type, gchar **proxy_address, gboolean *is_hidden, void **eap_config, void *last_error); diff --git a/src/network_dbus.c b/src/network_dbus.c index f172c54..bf57a26 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -3033,7 +3033,8 @@ int _net_dbus_config_remove_configurations(const gchar *config_id) } int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, - net_wifi_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, void *last_error) + net_wifi_security_type_e *security_type, gchar **proxy_address, + gboolean *is_hidden, net_ip_info_config_s **ip_info, void *last_error) { __NETWORK_FUNC_ENTER__; @@ -3043,6 +3044,7 @@ int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, gchar *field; GVariant *value; int *wifi_last_error = (int *)last_error; + int order = 0; message = _net_invoke_dbus_method( NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, @@ -3074,6 +3076,34 @@ int _net_dbus_config_load_configurations(const gchar *config_id, gchar **name, *proxy_address = NULL; else *proxy_address = g_strdup(r_proxy_address); + } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_METHOD) == 0) { + const gchar *type = g_variant_get_string(value, NULL); + if (g_strcmp0(type, "manual") == 0) + (*ip_info)->ip_type = NET_IP_CONFIG_TYPE_STATIC; + else if (g_strcmp0(type, "dhcp") == 0) + (*ip_info)->ip_type = NET_IP_CONFIG_TYPE_DYNAMIC; + } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_ADDRESS) == 0) { + const gchar *ip_address = g_variant_get_string(value, NULL); + (*ip_info)->ip_address = g_strdup(ip_address); + } 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_IPV4_GATEWAY_ADDRESS) == 0) { + const gchar *gateway_address = g_variant_get_string(value, NULL); + (*ip_info)->gateway_address = g_strdup(gateway_address); + } else if (g_strcmp0(field, WIFI_CONFIG_IPV4_DNS_METHOD) == 0) { + const gchar *type = g_variant_get_string(value, NULL); + if (g_strcmp0(type, "manual") == 0) + (*ip_info)->dns_type = NET_DNS_CONFIG_TYPE_STATIC; + else if (g_strcmp0(type, "dhcp") == 0) + (*ip_info)->dns_type = NET_DNS_CONFIG_TYPE_DYNAMIC; + } else if (g_strcmp0(field, WIFI_CONFIG_DNS_ADDRESS) == 0) { + const gchar *dns_address = g_variant_get_string(value, NULL); + (*ip_info)->dns_address[order] = g_strdup(dns_address); + order += 1; + (*ip_info)->dns_count = order > NET_DNS_ADDR_MAX ? + NET_DNS_ADDR_MAX : order; + order %= NET_DNS_ADDR_MAX; } else if (g_strcmp0(field, WIFI_CONFIG_FAILURE) == 0) { *wifi_last_error = __net_wifi_last_error_to_enum(g_variant_get_string(value, NULL)); } diff --git a/src/network_interface.c b/src/network_interface.c index 8a1cea6..141fbca 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -3470,7 +3470,8 @@ int net_config_remove_configurations(const gchar *config_id) } int net_config_load_configurations(const gchar *config_id, gchar **name, - void *security_type, gchar **proxy_address, gboolean *is_hidden, void *last_error) + void *security_type, gchar **proxy_address, gboolean *is_hidden, + net_ip_info_config_s **ip_info, void *last_error) { __NETWORK_FUNC_ENTER__; @@ -3484,7 +3485,7 @@ int net_config_load_configurations(const gchar *config_id, gchar **name, } Error = _net_dbus_config_load_configurations(config_id, name, sec_type, - proxy_address, is_hidden, last_error); + proxy_address, is_hidden, ip_info, last_error); if (Error != NET_ERR_NONE) WIFI_LOG(WIFI_ERROR, //LCOV_EXCL_LINE "Failed to load configurations. Error [%s]", diff --git a/src/wifi_config.c b/src/wifi_config.c index 29bbf96..383c36c 100755 --- a/src/wifi_config.c +++ b/src/wifi_config.c @@ -485,6 +485,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_get_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 || type == NULL || + (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 + } + + *type = h->ip_info->ip_type; + + __NETWORK_CAPI_FUNC_EXIT__; + + 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) @@ -510,6 +535,34 @@ EXPORT_API int wifi_manager_config_set_ip_config_type(wifi_manager_config_h conf return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_config_get_ip_address(wifi_manager_config_h config, + wifi_manager_address_family_e address_family, char **ip_address) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_config_s *h = (wifi_config_s *)config; + + if (_wifi_check_config_validity(config) == false || ip_address == NULL || + (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 + } + + *ip_address = strdup(h->ip_info->ip_address); + if (*ip_address == NULL) { + __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE + } + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + EXPORT_API int wifi_manager_config_set_ip_address(wifi_manager_config_h config, wifi_manager_address_family_e address_family, const char *ip_address) { @@ -534,6 +587,34 @@ EXPORT_API int wifi_manager_config_set_ip_address(wifi_manager_config_h config, return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_config_get_subnet_mask(wifi_manager_config_h config, + wifi_manager_address_family_e address_family, char **subnet_mask) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + 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)) { + 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 + } + + *subnet_mask = strdup(h->ip_info->subnet_mask); + if (*subnet_mask == NULL) { + __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE + } + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + EXPORT_API int wifi_manager_config_set_subnet_mask(wifi_manager_config_h config, wifi_manager_address_family_e address_family, const char *subnet_mask) { @@ -558,6 +639,34 @@ EXPORT_API int wifi_manager_config_set_subnet_mask(wifi_manager_config_h config, return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_config_get_gateway_address(wifi_manager_config_h config, + wifi_manager_address_family_e address_family, char **gateway_address) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_config_s *h = (wifi_config_s *)config; + + if (_wifi_check_config_validity(config) == false || gateway_address == NULL || + (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 + } + + *gateway_address = strdup(h->ip_info->gateway_address); + if (*gateway_address == NULL) { + __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE + } + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + EXPORT_API int wifi_manager_config_set_gateway_address(wifi_manager_config_h config, wifi_manager_address_family_e address_family, const char *gateway_address) { @@ -582,6 +691,31 @@ EXPORT_API int wifi_manager_config_set_gateway_address(wifi_manager_config_h con return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_config_get_dns_config_type(wifi_manager_config_h config, + wifi_manager_address_family_e address_family, + wifi_manager_dns_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 || type == NULL || + (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 + } + + *type = h->ip_info->dns_type; + + __NETWORK_CAPI_FUNC_EXIT__; + + return WIFI_MANAGER_ERROR_NONE; +} + EXPORT_API int wifi_manager_config_set_dns_config_type(wifi_manager_config_h config, wifi_manager_address_family_e address_family, wifi_manager_dns_config_type_e type) @@ -607,6 +741,41 @@ EXPORT_API int wifi_manager_config_set_dns_config_type(wifi_manager_config_h con return WIFI_MANAGER_ERROR_NONE; } +EXPORT_API int wifi_manager_config_get_dns_address(wifi_manager_config_h config, + int order, wifi_manager_address_family_e address_family, + char **dns_address) +{ + __NETWORK_CAPI_FUNC_ENTER__; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + wifi_config_s *h = (wifi_config_s *)config; + + if (_wifi_check_config_validity(config) == false || dns_address == NULL || + (address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_MANAGER_ADDRESS_FAMILY_IPV6) || + order <= 0 || order > NET_DNS_ADDR_MAX) { + 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 + } + + if (order > h->ip_info->dns_count) { + WIFI_LOG(WIFI_ERROR, "DNS Address of order %d doesn't exist", order); //LCOV_EXCL_LINE + __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE + } + + *dns_address = strdup(h->ip_info->dns_address[order-1]); + if (*dns_address == NULL) { + __NETWORK_CAPI_FUNC_EXIT__; //LCOV_EXCL_LINE + return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE + } + + __NETWORK_CAPI_FUNC_EXIT__; + return WIFI_MANAGER_ERROR_NONE; +} + EXPORT_API int wifi_manager_config_set_dns_address(wifi_manager_config_h config, int order, wifi_manager_address_family_e address_family, const char *dns_address) diff --git a/src/wifi_internal.c b/src/wifi_internal.c index d1a73c2..c923918 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -533,13 +533,15 @@ static int __connect_with_wifi_info(net_profile_info_s *ap_info) } static int __load_configurations(const gchar *config_id, gchar **name, - wifi_manager_security_type_e *security_type, gchar **proxy_address, gboolean *is_hidden, + wifi_manager_security_type_e *security_type, gchar **proxy_address, + gboolean *is_hidden, wifi_config_ip_info_s **ip_info, wifi_manager_error_e *last_error) { int rv; rv = net_config_load_configurations(config_id, name, security_type, - proxy_address, is_hidden, last_error); + proxy_address, is_hidden, (net_ip_info_config_s **)ip_info, + last_error); if (rv == NET_ERR_ACCESS_DENIED) { WIFI_LOG(WIFI_ERROR, "Access denied"); //LCOV_EXCL_LINE return WIFI_MANAGER_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE @@ -2833,6 +2835,7 @@ int _wifi_load_configurations(void) { int rv; GSList *config_ids = NULL; + int i; __clear_config_list(&config_iterator); @@ -2865,8 +2868,14 @@ int _wifi_load_configurations(void) rv = __load_eap_configurations(id, &h->name, &h->security_type, &h->proxy_address, &h->is_hidden, &h->eap_config, &h->last_error); } else { - rv = __load_configurations(id, &h->name, - &h->security_type, &h->proxy_address, &h->is_hidden, &h->last_error); + h->ip_info = g_new0(wifi_config_ip_info_s, 1); + if (h->ip_info == NULL) { + g_free(h);//LCOV_EXCL_LINE + break;//LCOV_EXCL_LINE + } + rv = __load_configurations(id, &h->name, &h->security_type, + &h->proxy_address, &h->is_hidden, &h->ip_info, + &h->last_error); } if (rv != WIFI_MANAGER_ERROR_NONE) { @@ -2874,6 +2883,15 @@ int _wifi_load_configurations(void) 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); + for (i = 0; i < h->ip_info->dns_count; i++) + g_free(h->ip_info->dns_address[i]); + g_free(h->ip_info); + } + if (h->eap_config) { g_free(h->eap_config->ca_cert); g_free(h->eap_config->client_cert);