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.
This commit is contained in:
Aleksander Morgado
2022-05-20 09:03:54 +00:00
parent c987757a2c
commit b497de325a
16 changed files with 185 additions and 138 deletions
@@ -2639,7 +2639,7 @@ cinterion_scks_unsolicited_handler (MMPortSerialAt *port,
break;
}
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self));
mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
}
static gboolean
@@ -2651,18 +2651,18 @@ modem_setup_sim_hot_swap_finish (MMIfaceModem *self,
}
static void
cinterion_hot_swap_init_ready (MMBaseModem *_self,
cinterion_hot_swap_init_ready (MMBaseModem *_self,
GAsyncResult *res,
GTask *task)
GTask *task)
{
MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self);
GError *error = NULL;
MMPortSerialAt *primary;
MMPortSerialAt *secondary;
g_autoptr(GError) error = NULL;
MMPortSerialAt *primary;
MMPortSerialAt *secondary;
if (!mm_base_modem_at_command_finish (_self, res, &error)) {
g_prefix_error (&error, "Could not enable SCKS: ");
g_task_return_error (task, error);
g_task_return_error (task, g_steal_pointer (&error));
g_object_unref (task);
return;
}
@@ -2686,6 +2686,9 @@ cinterion_hot_swap_init_ready (MMBaseModem *_self,
self,
NULL);
if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error))
mm_obj_warn (self, "failed to initialize SIM hot swap ports context: %s", error->message);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
@@ -2709,6 +2712,15 @@ modem_setup_sim_hot_swap (MMIfaceModem *self,
task);
}
/*****************************************************************************/
/* SIM hot swap cleanup (Modem interface) */
static void
modem_cleanup_sim_hot_swap (MMIfaceModem *self)
{
mm_broadband_modem_sim_hot_swap_ports_context_reset (MM_BROADBAND_MODEM (self));
}
/*****************************************************************************/
/* Create Bearer (Modem interface) */
@@ -2972,6 +2984,7 @@ iface_modem_init (MMIfaceModem *iface)
iface->modem_power_off_finish = modem_power_off_finish;
iface->setup_sim_hot_swap = modem_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = modem_cleanup_sim_hot_swap;
}
static MMIfaceModem *
@@ -73,6 +73,7 @@ iface_modem_init (MMIfaceModem *iface)
iface->setup_sim_hot_swap = mm_shared_quectel_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = mm_shared_quectel_cleanup_sim_hot_swap;
}
static MMIfaceModem *
@@ -71,6 +71,7 @@ iface_modem_init (MMIfaceModem *iface)
iface->setup_sim_hot_swap = mm_shared_quectel_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = mm_shared_quectel_cleanup_sim_hot_swap;
}
static MMIfaceModem *
+18 -5
View File
@@ -435,11 +435,12 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
Private *priv;
MMPortSerialAt *ports[2];
GTask *task;
GRegex *pattern;
guint i;
Private *priv;
MMPortSerialAt *ports[2];
GTask *task;
GRegex *pattern;
guint i;
g_autoptr(GError) error = NULL;
priv = get_private (MM_SHARED_QUECTEL (self));
@@ -464,6 +465,9 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
g_regex_unref (pattern);
mm_obj_dbg (self, "+QUSIM detection set up");
if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error))
mm_obj_warn (self, "failed to initialize SIM hot swap ports context: %s", error->message);
/* Now, if available, setup parent logic */
if (priv->iface_modem_parent->setup_sim_hot_swap &&
priv->iface_modem_parent->setup_sim_hot_swap_finish) {
@@ -478,6 +482,15 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
g_object_unref (task);
}
/*****************************************************************************/
/* SIM hot swap cleanup (Modem interface) */
void
mm_shared_quectel_cleanup_sim_hot_swap (MMIfaceModem *self)
{
mm_broadband_modem_sim_hot_swap_ports_context_reset (MM_BROADBAND_MODEM (self));
}
/*****************************************************************************/
/* GPS trace received */
+7 -7
View File
@@ -54,13 +54,13 @@ MMFirmwareUpdateSettings *mm_shared_quectel_firmware_load_update_settings_finish
GAsyncResult *res,
GError **error);
void mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
void mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self,
GAsyncResult *res,
GError **error);
void mm_shared_quectel_cleanup_sim_hot_swap (MMIfaceModem *self);
void mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self,
GAsyncReadyCallback callback,
+19 -4
View File
@@ -474,7 +474,7 @@ telit_qss_unsolicited_handler (MMPortSerialAt *port,
if ((prev_qss_status == QSS_STATUS_SIM_REMOVED && cur_qss_status != QSS_STATUS_SIM_REMOVED) ||
(prev_qss_status > QSS_STATUS_SIM_REMOVED && cur_qss_status == QSS_STATUS_SIM_REMOVED)) {
mm_obj_info (self, "QSS handler: SIM swap detected");
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self));
mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
}
}
@@ -649,14 +649,19 @@ qss_setup_step (GTask *task)
case QSS_SETUP_STEP_LAST:
/* If all enabling actions failed (either both, or only primary if
* there is no secondary), then we return an error */
if (ctx->primary_error &&
(ctx->secondary_error || !ctx->secondary))
if (ctx->primary_error && (ctx->secondary_error || !ctx->secondary)) {
g_task_return_new_error (task,
MM_CORE_ERROR,
MM_CORE_ERROR_FAILED,
"QSS: couldn't enable unsolicited");
else
} else {
g_autoptr(GError) error = NULL;
if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error))
mm_obj_warn (self, "failed to initialize SIM hot swap ports context: %s", error->message);
g_task_return_boolean (task, TRUE);
}
g_object_unref (task);
break;
@@ -684,6 +689,15 @@ modem_setup_sim_hot_swap (MMIfaceModem *self,
qss_setup_step (task);
}
/*****************************************************************************/
/* SIM hot swap cleanup (Modem interface) */
static void
modem_cleanup_sim_hot_swap (MMIfaceModem *self)
{
mm_broadband_modem_sim_hot_swap_ports_context_reset (MM_BROADBAND_MODEM (self));
}
/*****************************************************************************/
/* Load unlock retries (Modem interface)
*
@@ -1408,6 +1422,7 @@ iface_modem_init (MMIfaceModem *iface)
iface->set_current_modes_finish = mm_shared_telit_set_current_modes_finish;
iface->setup_sim_hot_swap = modem_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = modem_cleanup_sim_hot_swap;
}
static void
+21 -6
View File
@@ -1079,7 +1079,7 @@ common_voice_enable_disable_unsolicited_events (MMBroadbandModemUblox *self,
}
/*****************************************************************************/
/* Hotplug configure (Modem interface) */
/* SIM hot swap setup (Modem interface) */
typedef enum {
CIEV_SIM_STATUS_UNKNOWN = -1,
@@ -1110,7 +1110,7 @@ ublox_ciev_unsolicited_handler (MMPortSerialAt *port,
mm_obj_info (self, "CIEV: sim hot swap detected '%d'", sim_insert_status);
if (sim_insert_status == CIEV_SIM_STATUS_INSERTED ||
sim_insert_status == CIEV_SIM_STATUS_REMOVED) {
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self));
mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
} else {
mm_obj_warn (self, "(%s) CIEV: unable to determine sim insert status: %d",
mm_port_get_device (MM_PORT (port)),
@@ -1155,21 +1155,26 @@ ublox_setup_ciev_handler (MMIfaceModem *self,
}
static void
process_cind_verbosity_response (MMBaseModem *self,
process_cind_verbosity_response (MMBaseModem *self,
GAsyncResult *res,
GTask *task)
GTask *task)
{
GError *error = NULL;
g_autoptr(GError) error = NULL;
mm_base_modem_at_command_finish (self, res, &error);
if (error) {
mm_obj_warn (self, "CIND: verbose mode is not configured: %s", error->message);
g_task_return_error (task, error);
g_task_return_error (task, g_steal_pointer (&error));
g_object_unref (task);
return;
}
mm_obj_info (self, "CIND unsolicited response codes processing verbosity configured successfully");
if (!mm_broadband_modem_sim_hot_swap_ports_context_init (MM_BROADBAND_MODEM (self), &error))
mm_obj_warn (self, "failed to initialize SIM hot swap ports context: %s", error->message);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
@@ -1239,6 +1244,15 @@ modem_setup_sim_hot_swap (MMIfaceModem *self,
task);
}
/*****************************************************************************/
/* SIM hot swap cleanup (Modem interface) */
static void
modem_cleanup_sim_hot_swap (MMIfaceModem *self)
{
mm_broadband_modem_sim_hot_swap_ports_context_reset (MM_BROADBAND_MODEM (self));
}
/*****************************************************************************/
/* Enabling unsolicited events (Voice interface) */
@@ -2031,6 +2045,7 @@ iface_modem_init (MMIfaceModem *iface)
iface->set_current_bands_finish = common_set_current_modes_bands_finish;
iface->setup_sim_hot_swap = modem_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = modem_cleanup_sim_hot_swap;
}
static void