}
//LCOV_EXCL_STOP
-static int __profile_convert_netmask_to_prefix_len(const char *netmask)
+static unsigned char __profile_convert_netmask_to_prefix_len(const char *netmask)
{
if (netmask == NULL)
return 0;
in_addr_t mask = inet_network(netmask);
- int prefix_len = 0;
+ in_addr_t host = ~mask;
+ unsigned char prefix_len = 0;
+
+ /* a valid netmask must be 2^n - 1 */
+ if ((host & (host + 1)) != 0)
+ return -1;
for (; mask; mask <<= 1)
++prefix_len;
if (profile_info == NULL)
return CONNECTION_ERROR_OUT_OF_MEMORY;
- switch (type) {
- case CONNECTION_PROFILE_TYPE_CELLULAR:
+ if (type == CONNECTION_PROFILE_TYPE_CELLULAR) {
if (keyword == NULL) {
CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
g_free(profile_info);
return CONNECTION_ERROR_INVALID_PARAMETER;
}
__profile_init_cellular_profile(profile_info, keyword);
- break;
- case CONNECTION_PROFILE_TYPE_WIFI:
+ } else if (type == CONNECTION_PROFILE_TYPE_WIFI) {
__profile_init_wifi_profile(profile_info);
- break;
- default:
- break;
}
*profile = (connection_profile_h)profile_info;
if (net_info == NULL)
return CONNECTION_ERROR_OPERATION_FAILED;
- if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6)
- *ip_address = __profile_convert_ip_to_string(&net_info->IpAddr6,
- address_family);
- else
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4) {
*ip_address = __profile_convert_ip_to_string(&net_info->IpAddr,
address_family);
+ } else {
+ if (net_get_preferred_ipv6_address(net_info->ProfileName, ip_address) != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get preferred ipv6 address");
+ *ip_address = __profile_convert_ip_to_string(&net_info->IpAddr,
+ address_family);
+ }
+ }
if (*ip_address == NULL)
return CONNECTION_ERROR_OUT_OF_MEMORY;
EXPORT_API int connection_profile_get_subnet_mask(connection_profile_h profile,
connection_address_family_e address_family, char** subnet_mask)
{
- char* prefixlen;
-
CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
if (!(_connection_libnet_check_profile_validity(profile)) ||
return CONNECTION_ERROR_INVALID_PARAMETER;
}
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) {
+ CONNECTION_LOG(CONNECTION_ERROR,
+ "Please uses connection_profile_get_prefix_length()");
+ return CONNECTION_ERROR_NOT_SUPPORTED;
+ }
+
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_IPV6) {
- //LCOV_EXCL_START
- prefixlen = g_try_malloc0(MAX_PREFIX_LENGTH);
- if (prefixlen != NULL) {
- snprintf(prefixlen, MAX_PREFIX_LENGTH, "%d", net_info->PrefixLen6);
- *subnet_mask = prefixlen;
- } else
- *subnet_mask = NULL;
- //LCOV_EXCL_STOP
- } else
- *subnet_mask = __profile_convert_ip_to_string(&net_info->SubnetMask,
+ *subnet_mask = __profile_convert_ip_to_string(&net_info->SubnetMask,
address_family);
if (*subnet_mask == NULL)
return CONNECTION_ERROR_NONE;
}
+EXPORT_API int connection_profile_get_dhcp_lease_duration(
+ connection_profile_h profile,
+ connection_address_family_e address_family, int* dhcp_lease_duration)
+{
+ 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) ||
+ dhcp_lease_duration == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Not supported");
+ return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED;
+ }
+
+ 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;
+
+ CONNECTION_LOG(CONNECTION_INFO, "Lease duration : %d",
+ net_info->DHCPLeaseDuration);
+
+ *dhcp_lease_duration = net_info->DHCPLeaseDuration;
+
+ return CONNECTION_ERROR_NONE;
+}
+
EXPORT_API int connection_profile_get_dns_address(connection_profile_h profile, int order,
connection_address_family_e address_family, char** dns_address)
{
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)) {
+ (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
+ address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) {
CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
return CONNECTION_ERROR_INVALID_PARAMETER;
}
+ if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) {
+ CONNECTION_LOG(CONNECTION_ERROR,
+ "Please uses connection_profile_set_prefix_length()");
+ return CONNECTION_ERROR_NOT_SUPPORTED;
+ }
+
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_IPV6) {
- //LCOV_EXCL_START
- if (subnet_mask == NULL)
- net_info->PrefixLen6 = 0 ;
- else
- net_info->PrefixLen6 = atoi(subnet_mask) ;
- //LCOV_EXCL_STOP
- } else {
- if (subnet_mask == NULL)
- net_info->SubnetMask.Data.Ipv4.s_addr = 0;
- else if (inet_pton(AF_INET, subnet_mask , &net_info->SubnetMask.Data.Ipv4) < 1)
- return CONNECTION_ERROR_INVALID_PARAMETER;
+ if (subnet_mask == NULL)
+ net_info->SubnetMask.Data.Ipv4.s_addr = 0;
+ else if (inet_pton(AF_INET, subnet_mask , &net_info->SubnetMask.Data.Ipv4) < 1)
+ return CONNECTION_ERROR_INVALID_PARAMETER;
- net_info->PrefixLen = __profile_convert_netmask_to_prefix_len(subnet_mask);
+ net_info->PrefixLen = __profile_convert_netmask_to_prefix_len(subnet_mask);
+ if (net_info->PrefixLen <= 0 || net_info->PrefixLen > 31) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid Prefix length: %d", net_info->PrefixLen);
+ return CONNECTION_ERROR_INVALID_PARAMETER;
}
return CONNECTION_ERROR_NONE;
profile_info->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_IPV4_IPV6;
CONNECTION_LOG(CONNECTION_WARN, "DEPRECATION WARNINIG: CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6 " \
"from next release. Use CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPV6 instead");
- break
+ break;
case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPV6:
profile_info->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_IPV4_IPV6;
break;