broadband-modem,iface-modem: don't treat SIM unlocks as hot-swaps

If the old IMSI was unavailable because the SIM was locked, but now
is available because the SIM was unlocked, don't treat the SIM
properties change as a hotswap that may trigger dropping and re-probing
the modem.

Signed-off-by: Dan Williams <dan@ioncontrol.co>
This commit is contained in:
Dan Williams
2025-03-23 09:04:42 -05:00
parent 3b4bb45442
commit 57d1f21b36
2 changed files with 34 additions and 8 deletions
+17 -5
View File
@@ -4545,6 +4545,8 @@ complete_sim_swap_check (GTask *task,
SimSwapContext *ctx;
const gchar *cached;
const gchar *str;
gboolean ignore_sim_event = FALSE;
gboolean same;
self = MM_BROADBAND_MODEM (g_task_get_source_object (task));
ctx = g_task_get_task_data (task);
@@ -4557,20 +4559,30 @@ complete_sim_swap_check (GTask *task,
ctx->imsi_check_done = TRUE;
cached = mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (ctx->sim));
str = "imsi";
/* If the modem is locked and we couldn't previously read the IMSI
* (because it was locked) then the IMSI change is probably not a swap.
*/
ignore_sim_event = (self->priv->modem_state == MM_MODEM_STATE_LOCKED && !cached);
} else
g_assert_not_reached();
if (g_strcmp0 (current, cached) != 0) {
same = (g_strcmp0 (current, cached) == 0);
if (same) {
mm_obj_info (self, "SIM %s has not changed: %s",
str, mm_log_str_personal_info (current));
} else {
mm_obj_msg (self, "SIM %s has changed: '%s' -> '%s'",
str,
mm_log_str_personal_info (cached ? cached : ""),
mm_log_str_personal_info (current ? current : ""));
}
if (same || ignore_sim_event) {
ctx->step++;
} else {
mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
ctx->step = SIM_SWAP_CHECK_STEP_LAST;
} else {
mm_obj_info (self, "SIM %s has not changed: %s",
str, mm_log_str_personal_info (current));
ctx->step++;
}
sim_swap_check_step (task);
+17 -3
View File
@@ -160,6 +160,8 @@ check_basic_sim_details_ready (MMIfaceModem *self,
g_autofree gchar *current_iccid = NULL;
g_autofree gchar *current_imsi = NULL;
gboolean sim_inserted;
gboolean iccid_changed;
gboolean imsi_changed;
if (!MM_IFACE_MODEM_GET_IFACE (self)->check_basic_sim_details_finish (
self, res, &sim_inserted, &current_iccid, &current_imsi, &error)) {
@@ -175,6 +177,9 @@ check_basic_sim_details_ready (MMIfaceModem *self,
old_imsi = mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (sim));
}
iccid_changed = (g_strcmp0 (current_iccid, old_iccid) != 0);
imsi_changed = (g_strcmp0 (current_imsi, old_imsi) != 0);
if (!sim && !sim_inserted) {
mm_obj_info (self, "No SIM inserted before and after");
} else if (sim && !sim_inserted) {
@@ -183,8 +188,9 @@ check_basic_sim_details_ready (MMIfaceModem *self,
} else if (!sim && sim_inserted) {
mm_obj_info (self, "SIM inserted");
mm_iface_modem_process_sim_event (self);
} else if ((g_strcmp0 (current_iccid, old_iccid) != 0) ||
(g_strcmp0 (current_imsi, old_imsi) != 0)) {
} else if (iccid_changed || imsi_changed) {
MMModemState state = MM_MODEM_STATE_UNKNOWN;
mm_obj_info (self, "new SIM detected");
mm_obj_info (self, "ICCID: %s -> %s",
mm_log_str_personal_info (old_iccid),
@@ -192,7 +198,15 @@ check_basic_sim_details_ready (MMIfaceModem *self,
mm_obj_info (self, "IMSI: %s -> %s",
mm_log_str_personal_info (old_imsi),
mm_log_str_personal_info (current_imsi));
mm_iface_modem_process_sim_event (self);
g_object_get (self,
MM_IFACE_MODEM_STATE, &state,
NULL);
if (state == MM_MODEM_STATE_LOCKED && !old_imsi && imsi_changed) {
/* Don't treat SIM unlocks as SIM swaps */
} else {
mm_iface_modem_process_sim_event (self);
}
} else {
mm_obj_info (self, "SIM not changed. ICCID: %s, IMSI: %s",
mm_log_str_personal_info (current_iccid),