+static int __netconfig_telephony_get_modem_object_path(GSList **modem_path_list)
+{
+ GVariant *result;
+ GVariantIter *iter_modem = NULL;
+ GVariantIter *modem_properties = NULL;
+ const char *modem_path;
+
+ result = netconfig_invoke_dbus_method(TELEPHONY_SERVICE, TELEPHONY_MASTER_PATH,
+ TELEPHONY_MASTER_INTERFACE, "GetModems", NULL);
+ if (result == NULL) {
+ ERR("Failed to get modem path list");
+ return -1;
+ }
+
+ g_variant_get(result, "(a{sa{ss}})", &iter_modem);
+ while (g_variant_iter_loop(iter_modem, "{sa{ss}}", &modem_path, &modem_properties)) {
+ *modem_path_list = g_slist_append(*modem_path_list, g_strdup(modem_path));
+ DBG("modem object path: %s", modem_path);
+ }
+
+ g_variant_iter_free(iter_modem);
+ g_variant_unref(result);
+
+ return 0;
+}
+
+static int __netconfig_telephony_get_profile_list(net_profile_name_t **profile_list,
+ int *profile_count)
+{
+ int ret = 0;
+ int count = 0, i = 0;
+ const char *str = NULL;
+ GVariant *result;
+ GVariantIter *iter = NULL;
+ GSList *profiles = NULL, *list = NULL;
+ net_profile_name_t *plist = NULL;
+
+ GSList *modem_path_list = NULL;
+ const char *path = NULL;
+
+ ret = __netconfig_telephony_get_modem_object_path(&modem_path_list);
+ if (ret < 0) {
+ ERR("Failed to get modems path list");
+
+ g_slist_free_full(modem_path_list, g_free);
+ return ret;
+ }
+
+ for (list = modem_path_list; list != NULL; list = list->next) {
+ path = (const char *)list->data;
+
+ DBG("path: %s", path);
+ result = netconfig_invoke_dbus_method(TELEPHONY_SERVICE, path,
+ TELEPHONY_MODEM_INTERFACE, "GetProfileList", NULL);
+ if (result == NULL) {
+ DBG("Failed to get profiles: %s", path);
+ continue;
+ }
+
+ g_variant_get(result, "(as)", &iter);
+ while (g_variant_iter_loop(iter, "s", &str))
+ profiles = g_slist_append(profiles, g_strdup(str));
+
+ g_variant_iter_free(iter);
+ g_variant_unref(result);
+ }
+
+ g_slist_free_full(modem_path_list, g_free);
+
+ count = g_slist_length(profiles);
+ if (count > 0) {
+ plist = (net_profile_name_t*)malloc(sizeof(net_profile_name_t) * count);
+ } else {
+ *profile_count = 0;
+ goto out;
+ }
+
+ if (plist == NULL) {
+ ERR("Failed to allocate memory");
+ *profile_count = 0;
+ ret = -1;
+ goto out;
+ }
+
+ for (list = profiles, i = 0; list != NULL; list = list->next, i++)
+ g_strlcpy(plist[i].profile_name,
+ (const char *)list->data, NET_PROFILE_NAME_LEN_MAX);
+
+ *profile_list = plist;
+ *profile_count = count;
+
+out:
+ g_slist_free_full(profiles, g_free);
+
+ return ret;
+}
+
+static int __netconfig_telephony_search_pdp_profile(const char* profile_name, net_profile_name_t* pdp_name)
+{
+ int ret;
+ net_profile_name_t* profile_list = NULL;
+ char* prof_name = NULL;
+ char* tel_prof_name = NULL;
+ char* found_ptr = NULL;
+ int profile_count = 0;
+ int i;
+
+ /* Get pdp profile list from telephony service */
+ ret = __netconfig_telephony_get_profile_list(&profile_list, &profile_count);
+ if (ret < 0) {
+ ERR("Failed to get profile list from telephony service");
+ g_free(profile_list);
+ return ret;
+ }
+
+ if (profile_list == NULL || profile_count <= 0) {
+ ERR("There is no PDP profiles");
+ g_free(profile_list);
+ return -1;
+ }
+
+ /* Find matching profile */
+ prof_name = strrchr(profile_name, '/') + 1;
+ for (i = 0; i < profile_count; i++) {
+ tel_prof_name = strrchr(profile_list[i].profile_name, '/') + 1;
+ found_ptr = strstr(prof_name, tel_prof_name);
+
+ if (found_ptr != NULL && g_strcmp0(found_ptr, tel_prof_name) == 0) {
+ g_strlcpy(pdp_name->profile_name,
+ profile_list[i].profile_name, NET_PROFILE_NAME_LEN_MAX);
+
+ DBG("PDP profile name found in cellular profile: %s", pdp_name->profile_name);
+ break;
+ }
+ }
+
+ if (i >= profile_count) {
+ ERR("There is no matching PDP profiles");
+ g_free(profile_list);
+ return -1;
+ }
+
+ g_free(profile_list);
+
+ return ret;
+}
+
+static gboolean __netconfig_telephony_get_metered_info(net_profile_name_t* pdp_name)
+{
+ GVariant *result;
+ GVariantIter *iter;
+ const gchar *key = NULL;
+ const gchar *value = NULL;
+ gboolean ret = FALSE;
+
+ if (pdp_name == NULL) {
+ ERR("Invalid parameter!");
+ return ret;
+ }
+
+ result = netconfig_invoke_dbus_method(TELEPHONY_SERVICE, pdp_name->profile_name,
+ TELEPHONY_PROFILE_INTERFACE, "GetProfile", NULL);
+ if (result == NULL) {
+ ERR("_net_invoke_dbus_method failed");
+ return ret;
+ }
+
+ g_variant_get(result, "(a{ss})", &iter);
+ while (g_variant_iter_next(iter, "{ss}", &key, &value)) {
+ if (g_strcmp0(key, "is_metered") == 0) {
+ if (value == NULL)
+ continue;
+
+ if (g_strcmp0(value, "TRUE") == 0)
+ ret = TRUE;
+ }
+ }
+
+ g_variant_iter_free(iter);
+ g_variant_unref(result);
+
+ DBG("is_metered = %s", ret ? "TRUE" : "FALSE");
+
+ return ret;
+}
+