From b2979c63eb2d724512c7a96c071f3d4b422e79cb Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 1 Aug 2020 09:59:24 +0200 Subject: base-sim: allow explicit wait for SIM readiness during initialization Before attempting to load any SIM property value, allow checking whether the SIM is ready for operation or not. This action is implicitly done by the "unlock required check" step that is triggered before initializing the primary SIM card, but it would not be done when initializing other available SIM cards. --- src/mm-base-sim.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/mm-base-sim.c') diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index cc61a603..c9d24fbb 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -1500,6 +1500,7 @@ static void interface_initialization_step (GTask *task); typedef enum { INITIALIZATION_STEP_FIRST, + INITIALIZATION_STEP_WAIT_READY, INITIALIZATION_STEP_SIM_IDENTIFIER, INITIALIZATION_STEP_IMSI, INITIALIZATION_STEP_OPERATOR_ID, @@ -1633,6 +1634,23 @@ STR_REPLY_READY_FN (imsi, "IMSI") STR_REPLY_READY_FN (operator_identifier, "operator identifier") STR_REPLY_READY_FN (operator_name, "operator name") +static void +init_wait_sim_ready (MMBaseSim *self, + GAsyncResult *res, + GTask *task) +{ + InitAsyncContext *ctx; + g_autoptr(GError) error = NULL; + + if (!MM_BASE_SIM_GET_CLASS (self)->wait_sim_ready_finish (self, res, &error)) + mm_obj_warn (self, "couldn't wait for SIM to be ready: %s", error->message); + + /* Go on to next step */ + ctx = g_task_get_task_data (task); + ctx->step++; + interface_initialization_step (task); +} + static void interface_initialization_step (GTask *task) { @@ -1652,6 +1670,18 @@ interface_initialization_step (GTask *task) ctx->step++; /* Fall through */ + case INITIALIZATION_STEP_WAIT_READY: + if (MM_BASE_SIM_GET_CLASS (self)->wait_sim_ready && + MM_BASE_SIM_GET_CLASS (self)->wait_sim_ready_finish) { + MM_BASE_SIM_GET_CLASS (self)->wait_sim_ready ( + self, + (GAsyncReadyCallback)init_wait_sim_ready, + task); + return; + } + ctx->step++; + /* Fall through */ + case INITIALIZATION_STEP_SIM_IDENTIFIER: /* SIM ID is meant to be loaded only once during the whole * lifetime of the modem. Therefore, if we already have them loaded, -- cgit v1.2.3-70-g09d2