sim-mbim,broadband-modem-mbim: store number of remaining attempts

On MBIM modems the type of PIN cannot be specified in MBIM_CID_PIN query
command and the modem responds only remaining attempts for the currently
active lock.
If PIN1 is unlocked and user tries to disable (or enable) it, MM won't
get an update of remaining attempts in response to PIN Query. This value
is returned only after the Set command and MM need to store it in
all (pin/puk)_set_(enter/enable/change)_ready functions.

Previous solution was to call the mm_iface_modem_update_unlock_retries
directly from these functions but it caused the notification to be send
too early and invalid number was displayed to user sometimes.
Instead of this MM will store numbers of remaining attempts and send
them in a single notification from modem_load_unlock_retries.
This commit is contained in:
Michal Mazur
2022-01-30 13:48:48 +00:00
committed by Aleksander Morgado
parent ee87a68532
commit 5d4957935b
3 changed files with 33 additions and 49 deletions
+26 -41
View File
@@ -169,6 +169,8 @@ struct _MMBroadbandModemMbimPrivate {
/* Multi-SIM support */
guint32 executor_index;
guint active_slot_index;
MMUnlockRetries *unlock_retries;
};
/*****************************************************************************/
@@ -1654,51 +1656,14 @@ pin_query_unlock_retries_ready (MbimDevice *device,
NULL,
&remaining_attempts,
&error)) {
MMIfaceModem *self;
MMBroadbandModemMbim *self;
MMModemLock lock;
MMUnlockRetries *retries;
self = g_task_get_source_object (task);
self = MM_BROADBAND_MODEM_MBIM (g_task_get_source_object (task));
lock = mm_modem_lock_from_mbim_pin_type (pin_type);
retries = mm_unlock_retries_new ();
/* If PIN1 is disabled and we have tried to enable it with a wrong PIN,
* the modem would have indicated the number of remaining attempts for
* PIN1 (unless PUK1 is engaged) in the response to the failed
* MBIM_CID_PIN set operation. Thus, MMSimMbim would have updated
* MMIfaceModem's MMUnlockRetries with information about PIN1.
*
* However, a MBIM_CID_PIN query may be issued (e.g. MMBaseSim calls
* mm_iface_modem_update_lock_info()) after the MBIM_CID_PIN set
* operation to query the number of remaining attempts for a PIN type.
* Unfortunately, we can't specify a particular PIN type in a
* MBIM_CID_PIN query. The modem may not reply with information about
* PIN1 if PIN1 is disabled. When that happens, we would like to
* preserve our knowledge about the number of remaining attempts for
* PIN1. Here we thus carry over any existing information on PIN1 from
* MMIfaceModem's MMUnlockRetries if the MBIM_CID_PIN query reports
* something other than PIN1. */
if (lock != MM_MODEM_LOCK_SIM_PIN) {
MMUnlockRetries *previous_retries;
guint previous_sim_pin_retries;
previous_retries = mm_iface_modem_get_unlock_retries (self);
previous_sim_pin_retries = mm_unlock_retries_get (previous_retries,
MM_MODEM_LOCK_SIM_PIN);
if (previous_sim_pin_retries != MM_UNLOCK_RETRIES_UNKNOWN) {
mm_unlock_retries_set (retries,
MM_MODEM_LOCK_SIM_PIN,
previous_sim_pin_retries);
}
g_object_unref (previous_retries);
}
/* According to the MBIM specification, RemainingAttempts is set to
* 0xffffffff if the device does not support this information. */
if (remaining_attempts != G_MAXUINT32)
mm_unlock_retries_set (retries, lock, remaining_attempts);
g_task_return_pointer (task, retries, g_object_unref);
mm_broadband_modem_mbim_set_unlock_retries (self, lock, remaining_attempts);
g_task_return_pointer (task, g_object_ref (self->priv->unlock_retries), g_object_unref);
} else
g_task_return_error (task, error);
@@ -1732,6 +1697,24 @@ modem_load_unlock_retries (MMIfaceModem *self,
mbim_message_unref (message);
}
void
mm_broadband_modem_mbim_set_unlock_retries (MMBroadbandModemMbim *self,
MMModemLock lock_type,
guint32 remaining_attempts)
{
g_assert (MM_IS_BROADBAND_MODEM_MBIM (self));
if (!self->priv->unlock_retries)
self->priv->unlock_retries = mm_unlock_retries_new ();
/* According to the MBIM specification, RemainingAttempts is set to
* 0xffffffff if the device does not support this information. */
if (remaining_attempts != G_MAXUINT32)
mm_unlock_retries_set (self->priv->unlock_retries,
lock_type,
remaining_attempts);
}
/*****************************************************************************/
/* Own numbers loading */
@@ -8992,6 +8975,8 @@ dispose (GObject *object)
mm_port_mbim_close (mbim, NULL, NULL);
}
g_clear_object (&self->priv->unlock_retries);
G_OBJECT_CLASS (mm_broadband_modem_mbim_parent_class)->dispose (object);
}
+4
View File
@@ -62,4 +62,8 @@ MMPortMbim *mm_broadband_modem_mbim_get_port_mbim (MMBroadbandModemMbi
MMPortMbim *mm_broadband_modem_mbim_get_port_mbim_for_data (MMBroadbandModemMbim *self,
MMPort *data,
GError **error);
void mm_broadband_modem_mbim_set_unlock_retries (MMBroadbandModemMbim *self,
MMModemLock lock_type,
guint32 remaining_attempts);
#endif /* MM_BROADBAND_MODEM_MBIM_H */
+3 -8
View File
@@ -84,20 +84,15 @@ update_modem_unlock_retries (MMSimMbim *self,
guint32 remaining_attempts)
{
MMBaseModem *modem = NULL;
MMUnlockRetries *unlock_retries;
g_object_get (G_OBJECT (self),
MM_BASE_SIM_MODEM, &modem,
NULL);
g_assert (MM_IS_BASE_MODEM (modem));
unlock_retries = mm_unlock_retries_new ();
mm_unlock_retries_set (unlock_retries,
mm_modem_lock_from_mbim_pin_type (pin_type),
remaining_attempts);
mm_iface_modem_update_unlock_retries (MM_IFACE_MODEM (modem),
unlock_retries);
g_object_unref (unlock_retries);
mm_broadband_modem_mbim_set_unlock_retries (MM_BROADBAND_MODEM_MBIM (modem),
mm_modem_lock_from_mbim_pin_type (pin_type),
remaining_attempts);
g_object_unref (modem);
}