From e52ad1cc88601b2da1946678a2743465362d88c6 Mon Sep 17 00:00:00 2001 From: Teijo Kinnunen Date: Mon, 7 Sep 2020 15:18:52 +0300 Subject: iface-modem: add an optional iccid parameter to check_for_sim_swap If the new iccid is already available, reading the iccid from the card can be skipped. --- src/mm-broadband-modem.c | 23 ++++++++++++++++++++++- src/mm-iface-modem.c | 1 + src/mm-iface-modem.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 8441a2cf..61a07406 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -4120,7 +4120,8 @@ load_sim_identifier_ready (MMBaseSim *sim, } if (g_strcmp0 (current_simid, cached_simid) != 0) { - mm_obj_info (self, "sim identifier has changed: possible SIM swap during power down/low"); + mm_obj_info (self, "sim identifier has changed: %s -> %s - possible SIM swap", + cached_simid, current_simid); mm_broadband_modem_sim_hot_swap_detected (self); } @@ -4146,6 +4147,7 @@ load_sim_identifier (GTask *task) static void modem_check_for_sim_swap (MMIfaceModem *self, + const gchar *iccid, GAsyncReadyCallback callback, gpointer user_data) { @@ -4171,6 +4173,25 @@ modem_check_for_sim_swap (MMIfaceModem *self, return; } + /* We may or may not get the new SIM identifier (iccid). In case + * we've got it, the load_sim_identifier phase can be skipped. */ + if (iccid) { + const gchar *cached_simid; + + cached_simid = mm_gdbus_sim_get_sim_identifier (MM_GDBUS_SIM (ctx->sim)); + if (!cached_simid || g_strcmp0 (iccid, cached_simid) != 0) { + mm_obj_info (self, "detected ICCID change (%s -> %s), handle as SIM hot-swap", + cached_simid ? cached_simid : "", + iccid); + mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); + } else + mm_obj_dbg (self, "ICCID not changed"); + + g_task_return_boolean (task, TRUE); + g_object_unref (task); + return; + } + if (!MM_BASE_SIM_GET_CLASS (ctx->sim)->load_sim_identifier || !MM_BASE_SIM_GET_CLASS (ctx->sim)->load_sim_identifier_finish) { g_task_return_new_error (task, diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 955453be..40a56c74 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -4040,6 +4040,7 @@ interface_enabling_step (GTask *task) MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap_finish) { MM_IFACE_MODEM_GET_INTERFACE (self)->check_for_sim_swap ( self, + NULL, (GAsyncReadyCallback)check_for_sim_swap_ready, task); return; diff --git a/src/mm-iface-modem.h b/src/mm-iface-modem.h index c40323fc..10f22d1e 100644 --- a/src/mm-iface-modem.h +++ b/src/mm-iface-modem.h @@ -290,6 +290,7 @@ struct _MMIfaceModem { * Useful for when the modem changes power states since we might * not get the relevant notifications from the modem. */ void (*check_for_sim_swap) (MMIfaceModem *self, + const gchar *iccid, GAsyncReadyCallback callback, gpointer user_data); gboolean (*check_for_sim_swap_finish) (MMIfaceModem *self, -- cgit v1.2.3-70-g09d2