diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2022-05-16 13:34:54 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2022-05-20 09:03:54 +0000 |
commit | b497de325a15700612e7bc83be238204f41153e6 (patch) | |
tree | 52f748b99c8577ddd37561cec0763c42ef07e18e /src/mm-broadband-modem.c | |
parent | c987757a2c133f2e3be89c3a7590b8538f4bbe18 (diff) |
iface-modem: common SIM event reporting logic
We no longer have separate mm_base_modem_process_sim_event() and
mm_broadband_modem_sim_hot_swap_detected() methods. The only
difference between both of them was that one of them would attempt to
cleanup the ports context associated to the SIM hot swap event logic
as soon as a swap was detected, in order to avoid queueing up multiple
such events.
The previous logic wasn't working well, though, as there could be
mixed AT+QMI or AT+MBIM devices that would also require that same
cleanup and so we didn't always know which one should have been
called.
Now we have a single mm_iface_modem_process_sim_event() method, which
will trigger the reprobe and disabling, but which will also perform
the cleanup of the SIM ports swap setup as specified by the
implementation.
So, if a plugin explicitly initializes the serial ports context for
SIM hot swap handling, it should also explicitly clean it up.
Also, the initialization of the serial ports context for SIM hot swap
handling is no longer done automatically for all modems, it will be
done only for those modems using it; i.e. the modems that explicitly
report support SIM hot swap handling using AT URCs.
Diffstat (limited to 'src/mm-broadband-modem.c')
-rw-r--r-- | src/mm-broadband-modem.c | 111 |
1 files changed, 43 insertions, 68 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index f38e6b86..02fd0e2d 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -475,6 +475,37 @@ modem_create_sim (MMIfaceModem *self, } /*****************************************************************************/ +/* Helper to manage AT-based SIM hot swap ports context */ + +gboolean +mm_broadband_modem_sim_hot_swap_ports_context_init (MMBroadbandModem *self, + GError **error) +{ + PortsContext *ports; + + mm_obj_dbg (self, "creating serial ports context for SIM hot swap..."); + ports = ports_context_new (); + if (!ports_context_open (self, ports, FALSE, FALSE, FALSE, error)) { + ports_context_unref (ports); + return FALSE; + } + + g_assert (!self->priv->sim_hot_swap_ports_ctx); + self->priv->sim_hot_swap_ports_ctx = ports; + return TRUE; +} + +void +mm_broadband_modem_sim_hot_swap_ports_context_reset (MMBroadbandModem *self) +{ + if (self->priv->sim_hot_swap_ports_ctx) { + mm_obj_dbg (self, "releasing serial ports context for SIM hot swap"); + ports_context_unref (self->priv->sim_hot_swap_ports_ctx); + self->priv->sim_hot_swap_ports_ctx = NULL; + } +} + +/*****************************************************************************/ /* Capabilities loading (Modem interface) */ typedef struct { @@ -4156,7 +4187,7 @@ load_sim_identifier_ready (MMBaseSim *sim, if (g_strcmp0 (current_simid, cached_simid) != 0) { 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); + mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self)); } g_task_return_boolean (task, TRUE); @@ -4208,7 +4239,7 @@ modem_check_for_sim_swap (MMIfaceModem *self, if (modem_state == MM_MODEM_STATE_FAILED) { mm_obj_info (self, "new SIM detected, handle as SIM hot-swap"); - mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); + mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self)); g_task_return_boolean (task, TRUE); } else { g_task_return_new_error (task, @@ -4230,7 +4261,7 @@ modem_check_for_sim_swap (MMIfaceModem *self, mm_obj_info (self, "detected ICCID change (%s -> %s), handle as SIM hot-swap", cached_simid ? cached_simid : "<none>", iccid); - mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); + mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self)); } else mm_obj_dbg (self, "ICCID not changed"); @@ -12268,7 +12299,6 @@ typedef enum { INITIALIZE_STEP_FALLBACK_LIMITED, INITIALIZE_STEP_IFACE_VOICE, INITIALIZE_STEP_IFACE_FIRMWARE, - INITIALIZE_STEP_SIM_HOT_SWAP, INITIALIZE_STEP_IFACE_SIMPLE, INITIALIZE_STEP_LAST, } InitializeStep; @@ -12625,37 +12655,6 @@ initialize_step (GTask *task) task); return; - case INITIALIZE_STEP_SIM_HOT_SWAP: - /* Create the SIM hot swap ports context only if not already done before - * (we may be re-running the initialization step after SIM-PIN unlock) */ - if (!ctx->self->priv->sim_hot_swap_ports_ctx) { - gboolean is_sim_hot_swap_supported = FALSE; - - g_object_get (ctx->self, - MM_IFACE_MODEM_SIM_HOT_SWAP_SUPPORTED, &is_sim_hot_swap_supported, - NULL); - - if (is_sim_hot_swap_supported) { - PortsContext *ports; - g_autoptr(GError) error = NULL; - - mm_obj_dbg (ctx->self, "creating ports context for SIM hot swap"); - ports = ports_context_new (); - if (!ports_context_open (ctx->self, ports, FALSE, FALSE, FALSE, &error)) { - mm_obj_warn (ctx->self, "couldn't open ports during modem SIM hot swap enabling: %s", - error ? error->message : "unknown reason"); - } else { - ctx->self->priv->sim_hot_swap_ports_ctx = ports_context_ref (ports); - } - - ports_context_unref (ports); - } - } else - mm_obj_dbg (ctx->self, "ports context for SIM hot swap already available"); - - ctx->step++; - /* fall through */ - case INITIALIZE_STEP_IFACE_SIMPLE: if (ctx->self->priv->modem_state != MM_MODEM_STATE_FAILED) mm_iface_modem_simple_initialize (MM_IFACE_MODEM_SIMPLE (ctx->self)); @@ -12664,16 +12663,9 @@ initialize_step (GTask *task) case INITIALIZE_STEP_LAST: if (ctx->self->priv->modem_state == MM_MODEM_STATE_FAILED) { - GError *error; + GError *error = NULL; - if (!ctx->self->priv->modem_dbus_skeleton) { - /* Error setting up ports. Abort without even exporting the - * Modem interface */ - error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_ABORTED, - "Modem is unusable, " - "cannot fully initialize"); - } else { + if (ctx->self->priv->modem_dbus_skeleton) { /* Fatal SIM, firmware, or modem failure :-( */ gboolean is_sim_hot_swap_supported = FALSE; MMModemStateFailedReason reason; @@ -12687,25 +12679,17 @@ initialize_step (GTask *task) if (reason == MM_MODEM_STATE_FAILED_REASON_SIM_MISSING) { if (!is_sim_hot_swap_supported) { mm_obj_dbg (ctx->self, "SIM is missing, but this modem does not support SIM hot swap."); - } else if (!ctx->self->priv->sim_hot_swap_ports_ctx) { - mm_obj_err (ctx->self, "SIM is missing and SIM hot swap is configured, but ports are not opened."); } else { mm_obj_dbg (ctx->self, "SIM is missing, but SIM hot swap is enabled; waiting for SIM..."); error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, "Modem is unusable due to SIM missing, " "cannot fully initialize, waiting for SIM insertion."); - goto sim_hot_swap_enabled; } } - error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_WRONG_STATE, - "Modem is unusable, " - "cannot fully initialize"); -sim_hot_swap_enabled: - /* Ensure we only leave the Modem and Firmware interfaces - * around. A failure could be caused by firmware issues, which + /* Ensure we only leave the Modem, Voice and Firmware interfaces + * around. A failure could be caused by firmware issues, which * a firmware update, switch, or provisioning could fix. We also * leave the Voice interface around so that we can attempt * emergency voice calls. @@ -12721,6 +12705,11 @@ sim_hot_swap_enabled: mm_iface_modem_simple_shutdown (MM_IFACE_MODEM_SIMPLE (ctx->self)); } + if (!error) + error = g_error_new (MM_CORE_ERROR, + MM_CORE_ERROR_ABORTED, + "Modem is unusable, cannot fully initialize"); + g_task_return_error (task, error); g_object_unref (task); return; @@ -12873,20 +12862,6 @@ mm_broadband_modem_create_device_identifier (MMBroadbandModem *self, /*****************************************************************************/ -void -mm_broadband_modem_sim_hot_swap_detected (MMBroadbandModem *self) -{ - if (self->priv->sim_hot_swap_ports_ctx) { - mm_obj_dbg (self, "releasing SIM hot swap ports context"); - ports_context_unref (self->priv->sim_hot_swap_ports_ctx); - self->priv->sim_hot_swap_ports_ctx = NULL; - } - - mm_base_modem_process_sim_event (MM_BASE_MODEM (self)); -} - -/*****************************************************************************/ - MMBroadbandModem * mm_broadband_modem_new (const gchar *device, const gchar **drivers, |