diff --git a/dongle_infrastructure.c b/dongle_infrastructure.c index d89e1a6468ebda66eb0dd513c2023e4834eb792d..4616fbe9d9ee7adc5e75f984e863ea1eb4bdcba7 100644 --- a/dongle_infrastructure.c +++ b/dongle_infrastructure.c @@ -1171,6 +1171,58 @@ fail: return UBUS_STATUS_OK; } +int network_provider(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct dongle *usb; + int rv; + struct json_object *response; + + usb = get_dongle_by_obj_name(obj->name); + if (!usb) { + ubus_print_key_val(ctx, req, "failure", "no device configured with this object"); + debug_print("no device configured with this object\n"); + goto fail; + } + + rv = sim_state(usb); + if (rv == 1) { + ubus_print_key_val(ctx, req, "failure", "please activate sim"); + debug_print("sim card not activated!\n"); + goto fail; + } else if (rv == 2) { + ubus_print_key_val(ctx, req, "failure", "no sim card detected"); + debug_print("no sim card detected\n"); + goto fail; + } else if (rv == 3) { + ubus_print_key_val(ctx, req, "failure", "sim locked"); + debug_print("sim locked\n"); + goto fail; + } else if (rv == -1) { + ubus_print_key_val(ctx, req, "failure", "unknown error"); + debug_print("unknown error, probably curl error"); + goto fail; + } + + response = mobile_get_network_type(usb); + if (!response) + goto fail; + print_to_ubus(response, ctx, req); + /*if (rv < 0) { + ubus_print_key_val(ctx, req, "failure", "unknown connection status"); + goto fail; + } else if (rv == 1) { + ubus_print_key_val(ctx, req, NETWORK_STATUS, "connected"); + } else if (rv == 0) { + ubus_print_key_val(ctx, req, NETWORK_STATUS, "not found"); + debug_print("network_type not found"); + }*/ + +fail: + return UBUS_STATUS_OK; +} + int connection_status(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -1670,6 +1722,7 @@ struct ubus_method obj_methods[] = { UBUS_METHOD("create_apn_profile", create_apn_profile, create_apn_policy), UBUS_METHOD("delete_apn_profile", delete_apn_profile, apn_policy), UBUS_METHOD("set_apn_profile", set_apn_profile, apn_policy), + UBUS_METHOD_NOARG("network_provider", network_provider), //network UBUS_METHOD_NOARG("connection_status", connection_status), //network UBUS_METHOD_NOARG("network_status", network_status), UBUS_METHOD_NOARG("connect_network", connect_network),