From 1b49fec64d044d39aa94bf06112447b10bea557f Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Tue, 14 Mar 2017 16:49:21 +0900 Subject: [PATCH] Implement APIs for IPv6 and DNS configuration Change-Id: If049a154b9cdbbdaf03173f441cb3602b13fc72c Signed-off-by: Seonah Moon --- include/connection_profile.h | 3 +- packaging/capi-network-connection.spec | 2 +- src/connection_profile.c | 147 +++++++++++++++++++++++++ src/libnetwork.c | 4 +- test/connection_test.c | 118 +++++++++++++++----- 5 files changed, 243 insertions(+), 31 deletions(-) diff --git a/include/connection_profile.h b/include/connection_profile.h index 77b37ac..411c79c 100755 --- a/include/connection_profile.h +++ b/include/connection_profile.h @@ -180,8 +180,7 @@ typedef enum { * @brief Enumeration for DNS configuration type. * @since_tizen 4.0 */ -typedef enum -{ +typedef enum { CONNECTION_DNS_CONFIG_TYPE_NONE = 0, /**< Not defined */ CONNECTION_DNS_CONFIG_TYPE_STATIC = 1, /**< Manual DNS configuration */ CONNECTION_DNS_CONFIG_TYPE_DYNAMIC = 2, /**< Config DNS using DHCP client*/ diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 7dc4bc1..8402876 100755 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 1.0.96 +Version: 1.0.97 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/connection_profile.c b/src/connection_profile.c index 29b9b3a..39fbc8c 100755 --- a/src/connection_profile.c +++ b/src/connection_profile.c @@ -1812,3 +1812,150 @@ EXPORT_API int connection_profile_set_cellular_roam_pdn_type(connection_profile_ return CONNECTION_ERROR_NONE; } + +EXPORT_API int connection_profile_get_ipv6_state(connection_profile_h profile, connection_profile_state_e *state) +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, + TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (!(_connection_libnet_check_profile_validity(profile)) || + state == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + *state = _profile_convert_to_cp_state(profile_info->ProfileState6); + if (*state < 0) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; +} + +EXPORT_API int connection_profile_set_dns_config_type(connection_profile_h profile, + connection_address_family_e address_family, connection_dns_config_type_e type) +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, + TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if ((address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + (type != CONNECTION_DNS_CONFIG_TYPE_STATIC && + type != CONNECTION_DNS_CONFIG_TYPE_DYNAMIC)) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_dns_config_type_t *profileType = NULL; + net_dns_config_type_t *profileType6 = NULL; + net_profile_info_t *profile_info = profile; + + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) { + profileType = &net_info->DnsConfigType; + net_info->DnsAddr[0].Data.Ipv4.s_addr = 0; + net_info->DnsAddr[1].Data.Ipv4.s_addr = 0; + *profileType = type; + } else { + profileType6 = &net_info->DnsConfigType6; + inet_pton(AF_INET6, "::", &net_info->DnsAddr6[0].Data.Ipv6); + inet_pton(AF_INET6, "::", &net_info->DnsAddr6[1].Data.Ipv6); + *profileType6 = type; + } + + return CONNECTION_ERROR_NONE; +} + +EXPORT_API int connection_profile_get_dns_config_type(connection_profile_h profile, + connection_address_family_e address_family, connection_dns_config_type_e *type) +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, + TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_dns_config_type_t profileType; + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) + profileType = net_info->DnsConfigType; + else + profileType = net_info->DnsConfigType6; + + switch (profileType) { + case NET_DNS_CONFIG_TYPE_STATIC: + *type = CONNECTION_DNS_CONFIG_TYPE_STATIC; + break; + case NET_DNS_CONFIG_TYPE_DYNAMIC: + *type = CONNECTION_DNS_CONFIG_TYPE_DYNAMIC; + break; + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +EXPORT_API int connection_profile_set_prefix_length(connection_profile_h profile, + connection_address_family_e address_family, int prefix_len) +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, + TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + net_info->PrefixLen6 = prefix_len; + + return CONNECTION_ERROR_NONE; +} + +EXPORT_API int connection_profile_get_prefix_length(connection_profile_h profile, + connection_address_family_e address_family, int *prefix_len) +{ + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, + TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + prefix_len == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + *prefix_len = net_info->PrefixLen6; + + return CONNECTION_ERROR_NONE; +} diff --git a/src/libnetwork.c b/src/libnetwork.c index efd5cf6..9925292 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -746,7 +746,7 @@ int _connection_libnet_get_bluetooth_state(connection_bt_state_e *state) } //LCOV_EXCL_STOP -done : +done: __libnet_clear_profile_list(&bluetooth_profiles); return CONNECTION_ERROR_NONE; @@ -1101,7 +1101,7 @@ int _connection_libnet_get_cellular_service_profile( } //LCOV_EXCL_STOP -done : +done: __libnet_clear_profile_list(&cellular_profiles); prof_handle_list = g_slist_append(prof_handle_list, *profile); diff --git a/test/connection_test.c b/test/connection_test.c index 1c53099..38ab325 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -533,9 +533,35 @@ static int test_update_wifi_info(connection_profile_h profile) return 1; } +static int test_update_dns_info(connection_profile_h profile, + connection_address_family_e address_family) +{ + int rv = 0; + char input_str[100] = {0,}; + if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) { + rv = connection_profile_set_dns_address(profile, + 1, + address_family, + input_str); + if (rv != CONNECTION_ERROR_NONE) + return -1; + + if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) { + rv = connection_profile_set_dns_address(profile, + 2, + address_family, + input_str); + if (rv != CONNECTION_ERROR_NONE) + return -1; + } + } + return 1; +} + static int test_update_ip_info(connection_profile_h profile, connection_address_family_e address_family) { int rv = 0; + int input_int = 0; char input_str[100] = {0,}; if (test_get_user_string("Input IP Address - (Enter for skip) :", input_str, 100)) { @@ -554,32 +580,25 @@ static int test_update_ip_info(connection_profile_h profile, connection_address_ return -1; } - if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) { - rv = connection_profile_set_gateway_address(profile, + if (test_get_user_int("Input Prefix Length - (Enter for skip) :", &input_int)) { + rv = connection_profile_set_prefix_length(profile, address_family, - input_str); + input_int); if (rv != CONNECTION_ERROR_NONE) return -1; } - if (test_get_user_string("Input DNS 1 Address - (Enter for skip) :", input_str, 100)) { - rv = connection_profile_set_dns_address(profile, - 1, + if (test_get_user_string("Input Gateway - (Enter for skip) :", input_str, 100)) { + rv = connection_profile_set_gateway_address(profile, address_family, input_str); if (rv != CONNECTION_ERROR_NONE) return -1; - - if (test_get_user_string("Input DNS 2 Address - (Enter for skip) :", input_str, 100)) { - rv = connection_profile_set_dns_address(profile, - 2, - address_family, - input_str); - if (rv != CONNECTION_ERROR_NONE) - return -1; - } } + if (test_update_dns_info(profile, address_family) < 0) + return -1; + return 1; } @@ -630,10 +649,13 @@ static int test_update_proxy_info(connection_profile_h profile, connection_addre return 1; } + + static int test_update_network_info(connection_profile_h profile) { int rv = 0; int input_int = 0; + int dns_input = 0; int address_family = 0; test_get_user_int("Input Address Family (0:IPv4 1:IPv6) :", &address_family); @@ -643,8 +665,32 @@ static int test_update_network_info(connection_profile_h profile) switch (input_int) { case 1: rv = connection_profile_set_ip_config_type(profile, - address_family, - CONNECTION_IP_CONFIG_TYPE_DYNAMIC); + address_family, + CONNECTION_IP_CONFIG_TYPE_DYNAMIC); + if (test_get_user_int("Input DNS Address Type (Static:1, DHCP:2)" + " - (Enter for skip) :", &dns_input)) { + switch (dns_input) { + case CONNECTION_DNS_CONFIG_TYPE_STATIC: + rv = connection_profile_set_dns_config_type( + profile, + address_family, + CONNECTION_DNS_CONFIG_TYPE_STATIC); + if (rv != CONNECTION_ERROR_NONE) + return -1; + if (test_update_dns_info(profile, + address_family) == -1) + return -1; + break; + case CONNECTION_DNS_CONFIG_TYPE_DYNAMIC: + rv = connection_profile_set_dns_config_type( + profile, + address_family, + CONNECTION_DNS_CONFIG_TYPE_DYNAMIC); + if (rv != CONNECTION_ERROR_NONE) + return -1; + break; + } + } break; case 2: rv = connection_profile_set_ip_config_type(profile, @@ -810,14 +856,16 @@ static void test_print_wifi_info(connection_profile_h profile) static void test_print_network_info(connection_profile_h profile, connection_address_family_e address_family) { char *interface_name = NULL; - connection_ip_config_type_e ip_type; char *ip = NULL; char *subnet = NULL; char *gateway = NULL; char *dns1 = NULL; char *dns2 = NULL; - connection_proxy_type_e proxy_type; char *proxy = NULL; + int prefix_len; + connection_ip_config_type_e ip_type; + connection_proxy_type_e proxy_type; + connection_dns_config_type_e dns_type; if (connection_profile_get_network_interface_name(profile, &interface_name) != CONNECTION_ERROR_NONE) printf("Fail to get interface name!\n"); @@ -838,6 +886,13 @@ static void test_print_network_info(connection_profile_h profile, connection_add g_free(ip); } + if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE) + printf("Fail to get gateway!\n"); + else { + printf("Gateway : %s\n", gateway); + g_free(gateway); + } + if (connection_profile_get_subnet_mask(profile, address_family, &subnet) != CONNECTION_ERROR_NONE) printf("Fail to get subnet mask!\n"); else { @@ -845,12 +900,15 @@ static void test_print_network_info(connection_profile_h profile, connection_add g_free(subnet); } - if (connection_profile_get_gateway_address(profile, address_family, &gateway) != CONNECTION_ERROR_NONE) - printf("Fail to get gateway!\n"); - else { - printf("Gateway : %s\n", gateway); - g_free(gateway); - } + if (connection_profile_get_prefix_length(profile, address_family, &prefix_len) != CONNECTION_ERROR_NONE) + printf("Fail to get prefix length!\n"); + else + printf("Prefix length : %d\n", prefix_len); + + if (connection_profile_get_dns_config_type(profile, address_family, &dns_type) != CONNECTION_ERROR_NONE) + printf("Fail to get DNS configuration type!\n"); + else + printf("DNS configuration type : %d\n", dns_type); if (connection_profile_get_dns_address(profile, 1, address_family, &dns1) != CONNECTION_ERROR_NONE) printf("Fail to get DNS1!\n"); @@ -1416,6 +1474,7 @@ int test_get_profile_info(void) { connection_profile_type_e prof_type; connection_profile_state_e profile_state; + connection_profile_state_e profile_ipv6_state; connection_profile_h profile; char *profile_name = NULL; int address_family = 0; @@ -1433,11 +1492,18 @@ int test_get_profile_info(void) } if (connection_profile_get_state(profile, &profile_state) != CONNECTION_ERROR_NONE) { - printf("Fail to get profile state\n"); + printf("Fail to get profile IPv4 state\n"); return -1; } else printf("Profile State : %s\n", test_print_state(profile_state)); + if (connection_profile_get_ipv6_state(profile, &profile_ipv6_state) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile IPv6 state\n"); + return -1; + } else + printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state)); + + if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE) return -1; -- 2.34.1