diff --git a/dongle_apn.c b/dongle_apn.c index 6273ac25490af321bd2d17852b6168bcf36e6be5..dda1bd998caf1d6ecb1e4df9ce88038b12064355 100644 --- a/dongle_apn.c +++ b/dongle_apn.c @@ -140,7 +140,7 @@ int show_current_apn(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct json_object *response = mobile_get_wan_apn(); + struct json_object *response = mobile_get_current_apn(); if (!response) goto fail_unknown; diff --git a/libmobile.c b/libmobile.c index c8928564f95c9cb135dbfb7ccf0cd6532e7b5f74..bb1be016a0752db0f666db635bc4ca83b9f364cd 100644 --- a/libmobile.c +++ b/libmobile.c @@ -428,6 +428,42 @@ struct json_object *mobile_get_roam_status(void) return prepare_request("roam_setting_option", GET); } +struct json_object *mobile_get_current_apn(void) +{ + struct json_object *idx_json, *apn_profiles, *tmp, *current_profile; + int idx, counter = 0; + + idx_json = prepare_request("Current_index", GET); + if (!idx_json) { + debug_print("couldn't find index\n"); + goto fail; + } + + //tmp = json_object_object_get_ex(idx_json, "Current_index", &tmp); + + idx = json_object_get_int(idx_json); + if (idx < 0 || idx > 9) { + debug_print("Something is very wrong!\n"); + goto fail_idx; + } + apn_profiles = mobile_get_apn_profiles(); + + json_object_object_foreach(apn_profiles, key, val) { + counter++; + if (counter < idx) + continue; + current_profile = json_object_get(val); + break; + } + json_object_put_(idx_json); + json_object_put(apn_profiles); + return current_profile; +fail_idx: + json_object_put(idx_json); +fail: + return NULL; +} + struct json_object *mobile_get_wan_apn(void) { return prepare_request("wan_apn", GET); diff --git a/libmobile.h b/libmobile.h index 9c3e8a2ce6012b872bda856bcc2da78eb2153882..5e7fb7566f7b284be417a2c5b2dac7346568cf5d 100644 --- a/libmobile.h +++ b/libmobile.h @@ -118,6 +118,17 @@ struct json_object *mobile_disable_roaming(void); */ struct json_object *mobile_get_roam_status(void); +/** + * Function: mobile_get_current_apn + * + * Gets the currently active APN profile. + * + * Returns: + * A pointer to a json_object containing the JSON profile on success. + * NULL on failure. + */ +struct json_object *mobile_get_current_apn(void); + /** * Function: mobile_get_wan_apn *