Add some APIs to get and set cellular pdn type
[platform/core/api/connection.git] / src / connection_profile.c
index 8e03298..b2e95c6 100755 (executable)
@@ -79,6 +79,8 @@ static void __profile_init_cellular_profile(net_profile_info_t *profile_info, co
 
        profile_info->profile_type = NET_DEVICE_CELLULAR;
        profile_info->ProfileState = NET_STATE_TYPE_IDLE;
+       profile_info->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_UNKNOWN;
+       profile_info->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_UNKNOWN;
        profile_info->ProfileInfo.Pdp.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF;
        profile_info->ProfileInfo.Pdp.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT;
        g_strlcpy(profile_info->ProfileInfo.Pdp.Keyword, keyword, NET_PDP_APN_LEN_MAX);
@@ -1440,6 +1442,82 @@ EXPORT_API int connection_profile_get_cellular_home_url(connection_profile_h pro
        return CONNECTION_ERROR_NONE;
 }
 
+EXPORT_API int connection_profile_get_cellular_pdn_type(connection_profile_h profile, connection_cellular_pdn_type_e* type)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+       if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (profile_info->ProfileInfo.Pdp.PdnType) {
+       //LCOV_EXCL_START
+       case NET_PDN_TYPE_UNKNOWN:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN;
+               break;
+       case NET_PDN_TYPE_IPV4:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_IPV4;
+               break;
+       case NET_PDN_TYPE_IPV6:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_IPV6;
+               break;
+       case NET_PDN_TYPE_IPV4_IPV6:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6;
+               break;
+       default:
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       //LCOV_EXCL_STOP
+       }
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_get_cellular_roam_pdn_type(connection_profile_h profile, connection_cellular_pdn_type_e* type)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+       if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (profile_info->ProfileInfo.Pdp.RoamPdnType) {
+       //LCOV_EXCL_START
+       case NET_PDN_TYPE_UNKNOWN:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_UNKNOWN;
+               break;
+       case NET_PDN_TYPE_IPV4:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_IPV4;
+               break;
+       case NET_PDN_TYPE_IPV6:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_IPV6;
+               break;
+       case NET_PDN_TYPE_IPV4_IPV6:
+               *type = CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6;
+               break;
+       default:
+               return CONNECTION_ERROR_OPERATION_FAILED;
+       //LCOV_EXCL_STOP
+       }
+
+       return CONNECTION_ERROR_NONE;
+}
+
 EXPORT_API int connection_profile_is_cellular_roaming(connection_profile_h profile, bool* is_roaming)
 {
        CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
@@ -1663,3 +1741,73 @@ EXPORT_API int connection_profile_set_cellular_home_url(connection_profile_h pro
 
        return CONNECTION_ERROR_NONE;
 }
+
+EXPORT_API int connection_profile_set_cellular_pdn_type(connection_profile_h profile, connection_cellular_pdn_type_e type)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+       if (!(_connection_libnet_check_profile_validity(profile))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (type) {
+       //LCOV_EXCL_START
+       case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
+               profile_info->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_IPV4;
+               break;
+       case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
+               profile_info->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_IPV6;
+               break;
+       case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
+               profile_info->ProfileInfo.Pdp.PdnType = NET_PDN_TYPE_IPV4_IPV6;
+               break;
+       default:
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       //LCOV_EXCL_STOP
+       }
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_set_cellular_roam_pdn_type(connection_profile_h profile, connection_cellular_pdn_type_e type)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+       if (!(_connection_libnet_check_profile_validity(profile))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       net_profile_info_t *profile_info = profile;
+
+       if (profile_info->profile_type != NET_DEVICE_CELLULAR) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       switch (type) {
+       //LCOV_EXCL_START
+       case CONNECTION_CELLULAR_PDN_TYPE_IPV4:
+               profile_info->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_IPV4;
+               break;
+       case CONNECTION_CELLULAR_PDN_TYPE_IPV6:
+               profile_info->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_IPV6;
+               break;
+       case CONNECTION_CELLULAR_PDN_TYPE_IPV4_IPv6:
+               profile_info->ProfileInfo.Pdp.RoamPdnType = NET_PDN_TYPE_IPV4_IPV6;
+               break;
+       default:
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       //LCOV_EXCL_STOP
+       }
+
+       return CONNECTION_ERROR_NONE;
+}