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; break;
} }
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
} }
static gboolean static gboolean
@@ -2651,18 +2651,18 @@ modem_setup_sim_hot_swap_finish (MMIfaceModem *self,
} }
static void static void
cinterion_hot_swap_init_ready (MMBaseModem *_self, cinterion_hot_swap_init_ready (MMBaseModem *_self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self); MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self);
GError *error = NULL; g_autoptr(GError) error = NULL;
MMPortSerialAt *primary; MMPortSerialAt *primary;
MMPortSerialAt *secondary; MMPortSerialAt *secondary;
if (!mm_base_modem_at_command_finish (_self, res, &error)) { if (!mm_base_modem_at_command_finish (_self, res, &error)) {
g_prefix_error (&error, "Could not enable SCKS: "); 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); g_object_unref (task);
return; return;
} }
@@ -2686,6 +2686,9 @@ cinterion_hot_swap_init_ready (MMBaseModem *_self,
self, self,
NULL); 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_task_return_boolean (task, TRUE);
g_object_unref (task); g_object_unref (task);
} }
@@ -2709,6 +2712,15 @@ modem_setup_sim_hot_swap (MMIfaceModem *self,
task); 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) */ /* Create Bearer (Modem interface) */
@@ -2972,6 +2984,7 @@ iface_modem_init (MMIfaceModem *iface)
iface->modem_power_off_finish = modem_power_off_finish; iface->modem_power_off_finish = modem_power_off_finish;
iface->setup_sim_hot_swap = modem_setup_sim_hot_swap; iface->setup_sim_hot_swap = modem_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish; iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = modem_cleanup_sim_hot_swap;
} }
static MMIfaceModem * 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 = mm_shared_quectel_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish; 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 * 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 = mm_shared_quectel_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = mm_shared_quectel_setup_sim_hot_swap_finish; 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 * static MMIfaceModem *
+18 -5
View File
@@ -435,11 +435,12 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
Private *priv; Private *priv;
MMPortSerialAt *ports[2]; MMPortSerialAt *ports[2];
GTask *task; GTask *task;
GRegex *pattern; GRegex *pattern;
guint i; guint i;
g_autoptr(GError) error = NULL;
priv = get_private (MM_SHARED_QUECTEL (self)); priv = get_private (MM_SHARED_QUECTEL (self));
@@ -464,6 +465,9 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
g_regex_unref (pattern); g_regex_unref (pattern);
mm_obj_dbg (self, "+QUSIM detection set up"); 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 */ /* Now, if available, setup parent logic */
if (priv->iface_modem_parent->setup_sim_hot_swap && if (priv->iface_modem_parent->setup_sim_hot_swap &&
priv->iface_modem_parent->setup_sim_hot_swap_finish) { 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); 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 */ /* GPS trace received */
+7 -7
View File
@@ -54,13 +54,13 @@ MMFirmwareUpdateSettings *mm_shared_quectel_firmware_load_update_settings_finish
GAsyncResult *res, GAsyncResult *res,
GError **error); GError **error);
void mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self, void mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self,
gboolean mm_shared_quectel_setup_sim_hot_swap_finish (MMIfaceModem *self, GAsyncResult *res,
GAsyncResult *res, GError **error);
GError **error); void mm_shared_quectel_cleanup_sim_hot_swap (MMIfaceModem *self);
void mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self, void mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *self,
GAsyncReadyCallback callback, 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) || 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)) { (prev_qss_status > QSS_STATUS_SIM_REMOVED && cur_qss_status == QSS_STATUS_SIM_REMOVED)) {
mm_obj_info (self, "QSS handler: SIM swap detected"); 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: case QSS_SETUP_STEP_LAST:
/* If all enabling actions failed (either both, or only primary if /* If all enabling actions failed (either both, or only primary if
* there is no secondary), then we return an error */ * there is no secondary), then we return an error */
if (ctx->primary_error && if (ctx->primary_error && (ctx->secondary_error || !ctx->secondary)) {
(ctx->secondary_error || !ctx->secondary))
g_task_return_new_error (task, g_task_return_new_error (task,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_FAILED, MM_CORE_ERROR_FAILED,
"QSS: couldn't enable unsolicited"); "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_task_return_boolean (task, TRUE);
}
g_object_unref (task); g_object_unref (task);
break; break;
@@ -684,6 +689,15 @@ modem_setup_sim_hot_swap (MMIfaceModem *self,
qss_setup_step (task); 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) /* 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->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 = modem_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish; iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = modem_cleanup_sim_hot_swap;
} }
static void 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 { typedef enum {
CIEV_SIM_STATUS_UNKNOWN = -1, 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); mm_obj_info (self, "CIEV: sim hot swap detected '%d'", sim_insert_status);
if (sim_insert_status == CIEV_SIM_STATUS_INSERTED || if (sim_insert_status == CIEV_SIM_STATUS_INSERTED ||
sim_insert_status == CIEV_SIM_STATUS_REMOVED) { 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 { } else {
mm_obj_warn (self, "(%s) CIEV: unable to determine sim insert status: %d", mm_obj_warn (self, "(%s) CIEV: unable to determine sim insert status: %d",
mm_port_get_device (MM_PORT (port)), mm_port_get_device (MM_PORT (port)),
@@ -1155,21 +1155,26 @@ ublox_setup_ciev_handler (MMIfaceModem *self,
} }
static void static void
process_cind_verbosity_response (MMBaseModem *self, process_cind_verbosity_response (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
GError *error = NULL; g_autoptr(GError) error = NULL;
mm_base_modem_at_command_finish (self, res, &error); mm_base_modem_at_command_finish (self, res, &error);
if (error) { if (error) {
mm_obj_warn (self, "CIND: verbose mode is not configured: %s", error->message); 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); g_object_unref (task);
return; return;
} }
mm_obj_info (self, "CIND unsolicited response codes processing verbosity configured successfully"); 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_task_return_boolean (task, TRUE);
g_object_unref (task); g_object_unref (task);
} }
@@ -1239,6 +1244,15 @@ modem_setup_sim_hot_swap (MMIfaceModem *self,
task); 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) */ /* 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->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 = modem_setup_sim_hot_swap;
iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish; iface->setup_sim_hot_swap_finish = modem_setup_sim_hot_swap_finish;
iface->cleanup_sim_hot_swap = modem_cleanup_sim_hot_swap;
} }
static void static void
-22
View File
@@ -1681,28 +1681,6 @@ mm_base_modem_get_product_id (MMBaseModem *self)
/*****************************************************************************/ /*****************************************************************************/
static void
after_sim_switch_disable_ready (MMBaseModem *self,
GAsyncResult *res)
{
g_autoptr(GError) error = NULL;
mm_base_modem_disable_finish (self, res, &error);
if (error)
mm_obj_err (self, "failed to disable after SIM switch event: %s", error->message);
else
mm_base_modem_set_valid (self, FALSE);
}
void
mm_base_modem_process_sim_event (MMBaseModem *self)
{
mm_base_modem_set_reprobe (self, TRUE);
mm_base_modem_disable (self, (GAsyncReadyCallback) after_sim_switch_disable_ready, NULL);
}
/*****************************************************************************/
static gboolean static gboolean
base_modem_invalid_idle (MMBaseModem *self) base_modem_invalid_idle (MMBaseModem *self)
{ {
-2
View File
@@ -254,6 +254,4 @@ gboolean mm_base_modem_sync_finish (MMBaseModem *self,
#endif #endif
void mm_base_modem_process_sim_event (MMBaseModem *self);
#endif /* MM_BASE_MODEM_H */ #endif /* MM_BASE_MODEM_H */
+2 -2
View File
@@ -98,7 +98,7 @@ reprobe_if_puk_discovered (MMBaseSim *self,
MM_MOBILE_EQUIPMENT_ERROR, MM_MOBILE_EQUIPMENT_ERROR,
MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK)) { MM_MOBILE_EQUIPMENT_ERROR_SIM_PUK)) {
mm_obj_dbg (self, "Discovered PUK lock, discarding old modem..."); mm_obj_dbg (self, "Discovered PUK lock, discarding old modem...");
mm_base_modem_process_sim_event (self->priv->modem); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self->priv->modem));
} }
} }
@@ -905,7 +905,7 @@ handle_send_puk_ready (MMBaseSim *self,
if (sim_error) { if (sim_error) {
mm_obj_info (self, "Received critical sim error. SIM might be permanently blocked. Reprobing..."); mm_obj_info (self, "Received critical sim error. SIM might be permanently blocked. Reprobing...");
mm_base_modem_process_sim_event (self->priv->modem); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self->priv->modem));
} }
handle_send_puk_context_free (ctx); handle_send_puk_context_free (ctx);
+3 -4
View File
@@ -4712,7 +4712,7 @@ basic_connect_notification_subscriber_ready_status (MMBroadbandModemMbim *self,
ready_state != MBIM_SUBSCRIBER_READY_STATE_NO_ESIM_PROFILE)) { ready_state != MBIM_SUBSCRIBER_READY_STATE_NO_ESIM_PROFILE)) {
/* eSIM profiles have been added or removed, re-probe to ensure correct interfaces are exposed */ /* eSIM profiles have been added or removed, re-probe to ensure correct interfaces are exposed */
mm_obj_dbg (self, "eSIM profile updates detected"); mm_obj_dbg (self, "eSIM profile updates detected");
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
} }
if ((self->priv->last_ready_state != MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED && if ((self->priv->last_ready_state != MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED &&
@@ -4721,7 +4721,7 @@ basic_connect_notification_subscriber_ready_status (MMBroadbandModemMbim *self,
ready_state != MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED)) { ready_state != MBIM_SUBSCRIBER_READY_STATE_SIM_NOT_INSERTED)) {
/* SIM has been removed or reinserted, re-probe to ensure correct interfaces are exposed */ /* SIM has been removed or reinserted, re-probe to ensure correct interfaces are exposed */
mm_obj_dbg (self, "SIM hot swap detected"); mm_obj_dbg (self, "SIM hot swap detected");
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
} }
self->priv->last_ready_state = ready_state; self->priv->last_ready_state = ready_state;
@@ -5227,11 +5227,10 @@ ms_basic_connect_extensions_notification_slot_info_status (MMBroadbandModemMbim
return; return;
} }
if (self->priv->active_slot_index == slot_index + 1) { if (self->priv->active_slot_index == slot_index + 1) {
/* Major SIM event on the active slot, will request reprobing the /* Major SIM event on the active slot, will request reprobing the
* modem from scratch. */ * modem from scratch. */
mm_base_modem_process_sim_event (MM_BASE_MODEM (self)); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
} else { } else {
/* Modifies SIM object at the given slot based on the reported state, /* Modifies SIM object at the given slot based on the reported state,
* when the slot is not the active one. */ * when the slot is not the active one. */
+43 -68
View File
@@ -474,6 +474,37 @@ modem_create_sim (MMIfaceModem *self,
user_data); user_data);
} }
/*****************************************************************************/
/* 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) */ /* Capabilities loading (Modem interface) */
@@ -4156,7 +4187,7 @@ load_sim_identifier_ready (MMBaseSim *sim,
if (g_strcmp0 (current_simid, cached_simid) != 0) { if (g_strcmp0 (current_simid, cached_simid) != 0) {
mm_obj_info (self, "sim identifier has changed: %s -> %s - possible SIM swap", mm_obj_info (self, "sim identifier has changed: %s -> %s - possible SIM swap",
cached_simid, current_simid); 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); g_task_return_boolean (task, TRUE);
@@ -4208,7 +4239,7 @@ modem_check_for_sim_swap (MMIfaceModem *self,
if (modem_state == MM_MODEM_STATE_FAILED) { if (modem_state == MM_MODEM_STATE_FAILED) {
mm_obj_info (self, "new SIM detected, handle as SIM hot-swap"); 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); g_task_return_boolean (task, TRUE);
} else { } else {
g_task_return_new_error (task, 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", mm_obj_info (self, "detected ICCID change (%s -> %s), handle as SIM hot-swap",
cached_simid ? cached_simid : "<none>", cached_simid ? cached_simid : "<none>",
iccid); iccid);
mm_broadband_modem_sim_hot_swap_detected (MM_BROADBAND_MODEM (self)); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
} else } else
mm_obj_dbg (self, "ICCID not changed"); mm_obj_dbg (self, "ICCID not changed");
@@ -12268,7 +12299,6 @@ typedef enum {
INITIALIZE_STEP_FALLBACK_LIMITED, INITIALIZE_STEP_FALLBACK_LIMITED,
INITIALIZE_STEP_IFACE_VOICE, INITIALIZE_STEP_IFACE_VOICE,
INITIALIZE_STEP_IFACE_FIRMWARE, INITIALIZE_STEP_IFACE_FIRMWARE,
INITIALIZE_STEP_SIM_HOT_SWAP,
INITIALIZE_STEP_IFACE_SIMPLE, INITIALIZE_STEP_IFACE_SIMPLE,
INITIALIZE_STEP_LAST, INITIALIZE_STEP_LAST,
} InitializeStep; } InitializeStep;
@@ -12625,37 +12655,6 @@ initialize_step (GTask *task)
task); task);
return; 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: case INITIALIZE_STEP_IFACE_SIMPLE:
if (ctx->self->priv->modem_state != MM_MODEM_STATE_FAILED) if (ctx->self->priv->modem_state != MM_MODEM_STATE_FAILED)
mm_iface_modem_simple_initialize (MM_IFACE_MODEM_SIMPLE (ctx->self)); mm_iface_modem_simple_initialize (MM_IFACE_MODEM_SIMPLE (ctx->self));
@@ -12664,16 +12663,9 @@ initialize_step (GTask *task)
case INITIALIZE_STEP_LAST: case INITIALIZE_STEP_LAST:
if (ctx->self->priv->modem_state == MM_MODEM_STATE_FAILED) { if (ctx->self->priv->modem_state == MM_MODEM_STATE_FAILED) {
GError *error; GError *error = NULL;
if (!ctx->self->priv->modem_dbus_skeleton) { 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 {
/* Fatal SIM, firmware, or modem failure :-( */ /* Fatal SIM, firmware, or modem failure :-( */
gboolean is_sim_hot_swap_supported = FALSE; gboolean is_sim_hot_swap_supported = FALSE;
MMModemStateFailedReason reason; MMModemStateFailedReason reason;
@@ -12687,25 +12679,17 @@ initialize_step (GTask *task)
if (reason == MM_MODEM_STATE_FAILED_REASON_SIM_MISSING) { if (reason == MM_MODEM_STATE_FAILED_REASON_SIM_MISSING) {
if (!is_sim_hot_swap_supported) { if (!is_sim_hot_swap_supported) {
mm_obj_dbg (ctx->self, "SIM is missing, but this modem does not support SIM hot swap."); 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 { } else {
mm_obj_dbg (ctx->self, "SIM is missing, but SIM hot swap is enabled; waiting for SIM..."); mm_obj_dbg (ctx->self, "SIM is missing, but SIM hot swap is enabled; waiting for SIM...");
error = g_error_new (MM_CORE_ERROR, error = g_error_new (MM_CORE_ERROR,
MM_CORE_ERROR_WRONG_STATE, MM_CORE_ERROR_WRONG_STATE,
"Modem is unusable due to SIM missing, " "Modem is unusable due to SIM missing, "
"cannot fully initialize, waiting for SIM insertion."); "cannot fully initialize, waiting for SIM insertion.");
goto sim_hot_swap_enabled;
} }
} }
error = g_error_new (MM_CORE_ERROR, /* Ensure we only leave the Modem, Voice and Firmware interfaces
MM_CORE_ERROR_WRONG_STATE, * around. A failure could be caused by firmware issues, which
"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
* a firmware update, switch, or provisioning could fix. We also * a firmware update, switch, or provisioning could fix. We also
* leave the Voice interface around so that we can attempt * leave the Voice interface around so that we can attempt
* emergency voice calls. * emergency voice calls.
@@ -12721,6 +12705,11 @@ sim_hot_swap_enabled:
mm_iface_modem_simple_shutdown (MM_IFACE_MODEM_SIMPLE (ctx->self)); 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_task_return_error (task, error);
g_object_unref (task); g_object_unref (task);
return; 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 * MMBroadbandModem *
mm_broadband_modem_new (const gchar *device, mm_broadband_modem_new (const gchar *device,
const gchar **drivers, const gchar **drivers,
+3 -1
View File
@@ -122,6 +122,8 @@ void mm_broadband_modem_unlock_sms_storages (MMBroadbandModem *self,
gboolean mem1, gboolean mem1,
gboolean mem2); gboolean mem2);
/* Helper to update SIM hot swap */ /* Helper to update SIM hot swap */
void mm_broadband_modem_sim_hot_swap_detected (MMBroadbandModem *self); gboolean mm_broadband_modem_sim_hot_swap_ports_context_init (MMBroadbandModem *self,
GError **error);
void mm_broadband_modem_sim_hot_swap_ports_context_reset (MMBroadbandModem *self);
#endif /* MM_BROADBAND_MODEM_H */ #endif /* MM_BROADBAND_MODEM_H */
+35 -1
View File
@@ -209,6 +209,8 @@ mm_iface_modem_check_for_sim_swap (MMIfaceModem *self,
g_object_unref (task); g_object_unref (task);
} }
/*****************************************************************************/
static void static void
sim_slot_free (MMBaseSim *sim) sim_slot_free (MMBaseSim *sim)
{ {
@@ -277,6 +279,34 @@ mm_iface_modem_modify_sim (MMIfaceModem *self,
/*****************************************************************************/ /*****************************************************************************/
static void
after_sim_event_disable_ready (MMBaseModem *self,
GAsyncResult *res)
{
g_autoptr(GError) error = NULL;
mm_base_modem_disable_finish (self, res, &error);
if (error)
mm_obj_err (self, "failed to disable after SIM switch event: %s", error->message);
/* set invalid either way, so that it's reprobed */
mm_base_modem_set_valid (self, FALSE);
}
void
mm_iface_modem_process_sim_event (MMIfaceModem *self)
{
if (MM_IFACE_MODEM_GET_INTERFACE (self)->cleanup_sim_hot_swap)
MM_IFACE_MODEM_GET_INTERFACE (self)->cleanup_sim_hot_swap (self);
mm_base_modem_set_reprobe (MM_BASE_MODEM (self), TRUE);
mm_base_modem_disable (MM_BASE_MODEM (self),
(GAsyncReadyCallback) after_sim_event_disable_ready,
NULL);
}
/*****************************************************************************/
void void
mm_iface_modem_bind_simple_status (MMIfaceModem *self, mm_iface_modem_bind_simple_status (MMIfaceModem *self,
MMSimpleStatus *status) MMSimpleStatus *status)
@@ -1234,7 +1264,7 @@ set_primary_sim_slot_ready (MMIfaceModem *self,
/* Notify about the SIM swap, which will disable and reprobe the device. /* Notify about the SIM swap, which will disable and reprobe the device.
* There is no need to update the PrimarySimSlot property, as this value will be * There is no need to update the PrimarySimSlot property, as this value will be
* reloaded automatically during the reprobe. */ * reloaded automatically during the reprobe. */
mm_base_modem_process_sim_event (MM_BASE_MODEM (self)); mm_iface_modem_process_sim_event (self);
} }
mm_gdbus_modem_complete_set_primary_sim_slot (ctx->skeleton, ctx->invocation); mm_gdbus_modem_complete_set_primary_sim_slot (ctx->skeleton, ctx->invocation);
@@ -6109,6 +6139,10 @@ mm_iface_modem_shutdown (MMIfaceModem *self)
/* Remove running restart initialization idle, if any */ /* Remove running restart initialization idle, if any */
restart_initialize_idle_disable (self); restart_initialize_idle_disable (self);
/* Cleanup SIM hot swap, if any */
if (MM_IFACE_MODEM_GET_INTERFACE (self)->cleanup_sim_hot_swap)
MM_IFACE_MODEM_GET_INTERFACE (self)->cleanup_sim_hot_swap (self);
/* Remove SIM object */ /* Remove SIM object */
g_object_set (self, g_object_set (self,
MM_IFACE_MODEM_SIM, NULL, MM_IFACE_MODEM_SIM, NULL,
+11 -8
View File
@@ -376,14 +376,14 @@ struct _MMIfaceModem {
/* Create new bearer list object */ /* Create new bearer list object */
MMBearerList * (* create_bearer_list) (MMIfaceModem *self); MMBearerList * (* create_bearer_list) (MMIfaceModem *self);
/* Setup SIM hot swap */ /* Setup/cleanup SIM hot swap */
void (*setup_sim_hot_swap) (MMIfaceModem *self, void (* setup_sim_hot_swap) (MMIfaceModem *self,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data); gpointer user_data);
gboolean (* setup_sim_hot_swap_finish) (MMIfaceModem *self,
gboolean (*setup_sim_hot_swap_finish) (MMIfaceModem *self, GAsyncResult *res,
GAsyncResult *res, GError **error);
GError **error); void (* cleanup_sim_hot_swap) (MMIfaceModem *self);
/* Load carrier config */ /* Load carrier config */
void (* load_carrier_config) (MMIfaceModem *self, void (* load_carrier_config) (MMIfaceModem *self,
@@ -609,4 +609,7 @@ void mm_iface_modem_modify_sim (MMIfaceModem *self,
guint slot_index, guint slot_index,
MMBaseSim *new_sim); MMBaseSim *new_sim);
void mm_iface_modem_process_sim_event (MMIfaceModem *self);
#endif /* MM_IFACE_MODEM_H */ #endif /* MM_IFACE_MODEM_H */
+1 -1
View File
@@ -3817,7 +3817,7 @@ uim_slot_status_indication_cb (QmiClientUim *client,
* active slot's status changed */ * active slot's status changed */
if (!slot_array_status_equal (priv->slots_status, new_slots_status, TRUE)) { if (!slot_array_status_equal (priv->slots_status, new_slots_status, TRUE)) {
mm_obj_dbg (self, "An active slot had a status change, will reprobe the modem"); mm_obj_dbg (self, "An active slot had a status change, will reprobe the modem");
mm_base_modem_process_sim_event (MM_BASE_MODEM (self)); mm_iface_modem_process_sim_event (MM_IFACE_MODEM (self));
return; return;
} }