From 38a69011bdc26d7a9894e6b8351d780d87ed4b0a Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Fri, 20 May 2022 13:02:17 +0200 Subject: base-sim: skip loading SIM properties based on SIM type If the reported eSIM doesn't have profiles, there is no point in trying to load properties like ICCID, IMSI or operator name/id. If the reported SIM is a physical SIM, there is no point in trying to load properties like EID or eSIM status. --- src/mm-base-sim.c | 162 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c index 20955e05..7719cc5f 100644 --- a/src/mm-base-sim.c +++ b/src/mm-base-sim.c @@ -73,6 +73,18 @@ struct _MMBaseSimPrivate { static guint signals[SIGNAL_LAST] = { 0 }; +/*****************************************************************************/ +/* SIM type helpers */ + +#define IS_PSIM(self) \ + (mm_gdbus_sim_get_sim_type (MM_GDBUS_SIM (self)) == MM_SIM_TYPE_PHYSICAL) + +#define IS_ESIM(self) \ + (mm_gdbus_sim_get_sim_type (MM_GDBUS_SIM (self)) == MM_SIM_TYPE_ESIM) + +#define IS_ESIM_WITHOUT_PROFILES(self) \ + (IS_ESIM (self) && (mm_gdbus_sim_get_esim_status (MM_GDBUS_SIM (self)) == MM_SIM_ESIM_STATUS_NO_PROFILES)) + /*****************************************************************************/ void @@ -2250,15 +2262,15 @@ static void interface_initialization_step (GTask *task); typedef enum { INITIALIZATION_STEP_FIRST, INITIALIZATION_STEP_WAIT_READY, + INITIALIZATION_STEP_SIM_TYPE, + INITIALIZATION_STEP_ESIM_STATUS, INITIALIZATION_STEP_SIM_IDENTIFIER, INITIALIZATION_STEP_IMSI, - INITIALIZATION_STEP_EID, INITIALIZATION_STEP_OPERATOR_ID, INITIALIZATION_STEP_OPERATOR_NAME, INITIALIZATION_STEP_EMERGENCY_NUMBERS, INITIALIZATION_STEP_PREFERRED_NETWORKS, - INITIALIZATION_STEP_SIM_TYPE, - INITIALIZATION_STEP_ESIM_STATUS, + INITIALIZATION_STEP_EID, INITIALIZATION_STEP_REMOVABILITY, INITIALIZATION_STEP_LAST } InitializationStep; @@ -2346,8 +2358,7 @@ initable_init_finish (GAsyncInitable *initable, } UINT_REPLY_READY_FN (removability, "removability") -UINT_REPLY_READY_FN (esim_status, "esim status") -UINT_REPLY_READY_FN (sim_type, "sim type") +STR_REPLY_READY_FN (eid, "EID") static void init_load_preferred_networks_ready (MMBaseSim *self, @@ -2402,7 +2413,6 @@ init_load_emergency_numbers_ready (MMBaseSim *self, STR_REPLY_READY_FN (operator_name, "operator name") STR_REPLY_READY_FN (operator_identifier, "operator identifier") -STR_REPLY_READY_FN (eid, "EID") STR_REPLY_READY_FN (imsi, "IMSI") static void @@ -2441,6 +2451,9 @@ init_load_sim_identifier_ready (MMBaseSim *self, interface_initialization_step (task); } +UINT_REPLY_READY_FN (esim_status, "esim status") +UINT_REPLY_READY_FN (sim_type, "sim type") + static void init_wait_sim_ready (MMBaseSim *self, GAsyncResult *res, @@ -2489,39 +2502,65 @@ interface_initialization_step (GTask *task) ctx->step++; /* Fall through */ - case INITIALIZATION_STEP_SIM_IDENTIFIER: - if (mm_gdbus_sim_get_sim_identifier (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_sim_identifier && - MM_BASE_SIM_GET_CLASS (self)->load_sim_identifier_finish) { - MM_BASE_SIM_GET_CLASS (self)->load_sim_identifier ( + case INITIALIZATION_STEP_SIM_TYPE: + if (mm_gdbus_sim_get_sim_type (MM_GDBUS_SIM (self)) == MM_SIM_TYPE_UNKNOWN && + MM_BASE_SIM_GET_CLASS (self)->load_sim_type && + MM_BASE_SIM_GET_CLASS (self)->load_sim_type_finish) { + MM_BASE_SIM_GET_CLASS (self)->load_sim_type ( self, - (GAsyncReadyCallback)init_load_sim_identifier_ready, + (GAsyncReadyCallback)init_load_sim_type_ready, task); return; } ctx->step++; /* Fall through */ - case INITIALIZATION_STEP_IMSI: - if (mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_imsi && - MM_BASE_SIM_GET_CLASS (self)->load_imsi_finish) { - MM_BASE_SIM_GET_CLASS (self)->load_imsi ( + case INITIALIZATION_STEP_ESIM_STATUS: + /* Don't load eSIM status if the SIM is known to be a physical SIM */ + if (IS_PSIM (self)) + mm_obj_dbg (self, "not loading eSIM status in physical SIM"); + else if (mm_gdbus_sim_get_esim_status (MM_GDBUS_SIM (self)) == MM_SIM_ESIM_STATUS_UNKNOWN && + MM_BASE_SIM_GET_CLASS (self)->load_esim_status && + MM_BASE_SIM_GET_CLASS (self)->load_esim_status_finish) { + MM_BASE_SIM_GET_CLASS (self)->load_esim_status ( self, - (GAsyncReadyCallback)init_load_imsi_ready, + (GAsyncReadyCallback)init_load_esim_status_ready, task); return; } ctx->step++; /* Fall through */ - case INITIALIZATION_STEP_EID: - if (mm_gdbus_sim_get_eid (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_eid && - MM_BASE_SIM_GET_CLASS (self)->load_eid_finish) { - MM_BASE_SIM_GET_CLASS (self)->load_eid ( + case INITIALIZATION_STEP_SIM_IDENTIFIER: + /* Don't load SIM ICCID if the SIM is known to be an eSIM without + * profiles; otherwise (if physical SIM, or if eSIM with profile, or if + * SIM type unknown) try to load it. */ + if (IS_ESIM_WITHOUT_PROFILES (self)) + mm_obj_dbg (self, "not loading SIM identifier in eSIM without profiles"); + else if (mm_gdbus_sim_get_sim_identifier (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_sim_identifier && + MM_BASE_SIM_GET_CLASS (self)->load_sim_identifier_finish) { + MM_BASE_SIM_GET_CLASS (self)->load_sim_identifier ( self, - (GAsyncReadyCallback)init_load_eid_ready, + (GAsyncReadyCallback)init_load_sim_identifier_ready, + task); + return; + } + ctx->step++; + /* Fall through */ + + case INITIALIZATION_STEP_IMSI: + /* Don't load SIM IMSI if the SIM is known to be an eSIM without + * profiles; otherwise (if physical SIM, or if eSIM with profile, or if + * SIM type unknown) try to load it. */ + if (IS_ESIM_WITHOUT_PROFILES (self)) + mm_obj_dbg (self, "not loading IMSI in eSIM without profiles"); + else if (mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_imsi && + MM_BASE_SIM_GET_CLASS (self)->load_imsi_finish) { + MM_BASE_SIM_GET_CLASS (self)->load_imsi ( + self, + (GAsyncReadyCallback)init_load_imsi_ready, task); return; } @@ -2529,9 +2568,14 @@ interface_initialization_step (GTask *task) /* Fall through */ case INITIALIZATION_STEP_OPERATOR_ID: - if (mm_gdbus_sim_get_operator_identifier (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_operator_identifier && - MM_BASE_SIM_GET_CLASS (self)->load_operator_identifier_finish) { + /* Don't load operator ID if the SIM is known to be an eSIM without + * profiles; otherwise (if physical SIM, or if eSIM with profile, or if + * SIM type unknown) try to load it. */ + if (IS_ESIM_WITHOUT_PROFILES (self)) + mm_obj_dbg (self, "not loading operator ID in eSIM without profiles"); + else if (mm_gdbus_sim_get_operator_identifier (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_operator_identifier && + MM_BASE_SIM_GET_CLASS (self)->load_operator_identifier_finish) { MM_BASE_SIM_GET_CLASS (self)->load_operator_identifier ( self, (GAsyncReadyCallback)init_load_operator_identifier_ready, @@ -2542,9 +2586,14 @@ interface_initialization_step (GTask *task) /* Fall through */ case INITIALIZATION_STEP_OPERATOR_NAME: - if (mm_gdbus_sim_get_operator_name (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_operator_name && - MM_BASE_SIM_GET_CLASS (self)->load_operator_name_finish) { + /* Don't load operator name if the SIM is known to be an eSIM without + * profiles; otherwise (if physical SIM, or if eSIM with profile, or if + * SIM type unknown) try to load it. */ + if (IS_ESIM_WITHOUT_PROFILES (self)) + mm_obj_dbg (self, "not loading operator name in eSIM without profiles"); + else if (mm_gdbus_sim_get_operator_name (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_operator_name && + MM_BASE_SIM_GET_CLASS (self)->load_operator_name_finish) { MM_BASE_SIM_GET_CLASS (self)->load_operator_name ( self, (GAsyncReadyCallback)init_load_operator_name_ready, @@ -2555,9 +2604,14 @@ interface_initialization_step (GTask *task) /* Fall through */ case INITIALIZATION_STEP_EMERGENCY_NUMBERS: - if (mm_gdbus_sim_get_emergency_numbers (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers && - MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers_finish) { + /* Don't load emergency numbers if the SIM is known to be an eSIM without + * profiles; otherwise (if physical SIM, or if eSIM with profile, or if + * SIM type unknown) try to load it. */ + if (IS_ESIM_WITHOUT_PROFILES (self)) + mm_obj_dbg (self, "not loading emergency numbers in eSIM without profiles"); + else if (mm_gdbus_sim_get_emergency_numbers (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers && + MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers_finish) { MM_BASE_SIM_GET_CLASS (self)->load_emergency_numbers ( self, (GAsyncReadyCallback)init_load_emergency_numbers_ready, @@ -2568,9 +2622,14 @@ interface_initialization_step (GTask *task) /* Fall through */ case INITIALIZATION_STEP_PREFERRED_NETWORKS: - if (mm_gdbus_sim_get_preferred_networks (MM_GDBUS_SIM (self)) == NULL && - MM_BASE_SIM_GET_CLASS (self)->load_preferred_networks && - MM_BASE_SIM_GET_CLASS (self)->load_preferred_networks_finish) { + /* Don't load preferred networks if the SIM is known to be an eSIM without + * profiles; otherwise (if physical SIM, or if eSIM with profile, or if + * SIM type unknown) try to load it. */ + if (IS_ESIM_WITHOUT_PROFILES (self)) + mm_obj_dbg (self, "not loading preferred networks in eSIM without profiles"); + else if (mm_gdbus_sim_get_preferred_networks (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_preferred_networks && + MM_BASE_SIM_GET_CLASS (self)->load_preferred_networks_finish) { MM_BASE_SIM_GET_CLASS (self)->load_preferred_networks ( self, (GAsyncReadyCallback)init_load_preferred_networks_ready, @@ -2580,26 +2639,17 @@ interface_initialization_step (GTask *task) ctx->step++; /* Fall through */ - case INITIALIZATION_STEP_SIM_TYPE: - if (mm_gdbus_sim_get_sim_type (MM_GDBUS_SIM (self)) == MM_SIM_TYPE_UNKNOWN && - MM_BASE_SIM_GET_CLASS (self)->load_sim_type && - MM_BASE_SIM_GET_CLASS (self)->load_sim_type_finish) { - MM_BASE_SIM_GET_CLASS (self)->load_sim_type ( - self, - (GAsyncReadyCallback)init_load_sim_type_ready, - task); - return; - } - ctx->step++; - /* Fall through */ - - case INITIALIZATION_STEP_ESIM_STATUS: - if (mm_gdbus_sim_get_esim_status (MM_GDBUS_SIM (self)) == MM_SIM_ESIM_STATUS_UNKNOWN && - MM_BASE_SIM_GET_CLASS (self)->load_esim_status && - MM_BASE_SIM_GET_CLASS (self)->load_esim_status_finish) { - MM_BASE_SIM_GET_CLASS (self)->load_esim_status ( + case INITIALIZATION_STEP_EID: + /* Don't load EID if the SIM is known to be a physical SIM; otherwise + * (if eSIM with or without profiles) try to load it. */ + if (IS_PSIM (self)) + mm_obj_dbg (self, "not loading EID in physical SIM"); + else if (mm_gdbus_sim_get_eid (MM_GDBUS_SIM (self)) == NULL && + MM_BASE_SIM_GET_CLASS (self)->load_eid && + MM_BASE_SIM_GET_CLASS (self)->load_eid_finish) { + MM_BASE_SIM_GET_CLASS (self)->load_eid ( self, - (GAsyncReadyCallback)init_load_esim_status_ready, + (GAsyncReadyCallback)init_load_eid_ready, task); return; } @@ -2607,6 +2657,8 @@ interface_initialization_step (GTask *task) /* Fall through */ case INITIALIZATION_STEP_REMOVABILITY: + /* Although not very common, there are removable eSIMs, so always try to + * load it, regardless of SIM type. */ if (mm_gdbus_sim_get_removability (MM_GDBUS_SIM (self)) == MM_SIM_REMOVABILITY_UNKNOWN && MM_BASE_SIM_GET_CLASS (self)->load_removability && MM_BASE_SIM_GET_CLASS (self)->load_removability_finish) { -- cgit v1.2.3-70-g09d2