Skip to content
Snippets Groups Projects
Commit ddb0345b authored by Jakob Olsson's avatar Jakob Olsson
Browse files

dongle_infrastructure: add functionality to activate sim through ubus

parent c25f678d
No related branches found
No related tags found
No related merge requests found
...@@ -51,6 +51,64 @@ const struct blobmsg_policy create_apn_policy_huawei[__CREATE_MAX_H] = { ...@@ -51,6 +51,64 @@ const struct blobmsg_policy create_apn_policy_huawei[__CREATE_MAX_H] = {
[PASS_H] = {.name = "password", .type = BLOBMSG_TYPE_STRING} [PASS_H] = {.name = "password", .type = BLOBMSG_TYPE_STRING}
}; };
int activate_sim(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
struct blob_attr *tb[__PIN_MAX];
char *pin;
int rv;
struct json_object *response;
struct dongle *usb;
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 == 2) {
ubus_print_key_val(ctx, req, "Failure", "No SIM card detected");
debug_print("No SIM card detected\n");
goto fail;
}
blobmsg_parse(pin_policy, __PIN_MAX, tb, blob_data(msg), blob_len(msg));
if (!tb[PIN]) {
ubus_print_key_val(ctx, req, "Failure", "Provide a pin");
debug_print("Please enter a pin!\n");
goto fail;
}
pin = (char *)blobmsg_data(tb[PIN]);
rv = validate_pin_format(pin);
if (rv < 0) {
ubus_print_key_val(ctx, req, "Failure", "Invalid pin format");
debug_print("invalid pin format!\n");
goto fail;
}
response = mobile_activate_sim(*usb, pin);
if (!response) {
debug_print("error disabling pin!\n");
ubus_print_key_val(ctx, req, "Failure", "No valid response received from dongle");
goto fail;
}
rv = check_response(response, usb->if_name);
if (rv < 0)
ubus_print_key_val(ctx, req, "Failure", "Incorrect pin");
else
ubus_print_key_val(ctx, req, "Success", "SIM activated");
json_object_put(response);
fail:
return UBUS_STATUS_OK;
}
int set_pin(struct ubus_context *ctx, struct ubus_object *obj, int set_pin(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
...@@ -1101,6 +1159,7 @@ fail: ...@@ -1101,6 +1159,7 @@ fail:
} }
struct ubus_method obj_methods[] = { struct ubus_method obj_methods[] = {
UBUS_METHOD("activate_sim", activate_sim, pin_policy),
UBUS_METHOD("set_pin", set_pin, set_pin_policy), //pin UBUS_METHOD("set_pin", set_pin, set_pin_policy), //pin
UBUS_METHOD("disable_pin", disable_pin, pin_policy), UBUS_METHOD("disable_pin", disable_pin, pin_policy),
UBUS_METHOD("enable_pin", enable_pin, pin_policy), UBUS_METHOD("enable_pin", enable_pin, pin_policy),
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment