Quectel: Modem is released and forced to reconnect after PIN entry
Hi, There's an issue at least in ModemManager 1.20.0, which shows the following symptoms on a Pinephone & Pro, but I'm pretty sure it will affect any other Qualcomm modem:
With the modem booted and asking for a SIM PIN, after unlocking it ModemManager will release all the ports and disconnect all QMI sessions, then reconnect again. This makes the modem disappear for about 5 seconds from the UI.
If you enter the pin with mmcli
, mmcli will hang retrying to verify the SIM lock status until it times out.
The problem lays with the IMSI. As the PIN is sim-locked, the IMSI is not available at the start. When the SIM is unlocked the IMSI can be read, the sim hot-swap code in ModemManager thinks the card has been switched and it disconnects from the modem to reread everything:
dic 11 06:26:12 pipro ModemManager[1031]: <info> [1670736372.390103] [modem19] SIM imsi has changed: <none> -> XXXXXXXXXXXXXX
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.390195] [modem19] releasing serial ports context for SIM hot swap
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.390269] [ttyUSB2/at] device open count is 0 (close)
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.390344] [ttyUSB2/at] closing serial port...
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.405920] [ttyUSB2/at] serial port closed
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.406160] [modem19] (quectel) check SIM swap completed
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.406906] [device /sys/devices/platform/fe3c0000.usb/usb2/2-1] unexported modem from path '/org/freedesktop/ModemManager1/Modem/19'
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.407080] [cdc-wdm0/qmi] Releasing client for service 'sar'...
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.407177] [/dev/cdc-wdm0] releasing 'sar' client with flags 'release-cid'...
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.407258] [/dev/cdc-wdm0] unregistered 'sar' client with ID '1'
dic 11 06:26:12 pipro ModemManager[1031]: <debug> [1670736372.407405] [/dev/cdc-wdm0] sent message...
I don't know ModemManager's code well enough to make a proper fix, but here's an example patch:
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c
index a9d4cd73..fa3d3709 100644
--- a/src/mm-broadband-modem.c
+++ b/src/mm-broadband-modem.c
@@ -4195,6 +4195,10 @@ complete_sim_swap_check (GTask *task,
} else if (ctx->step == SIM_SWAP_CHECK_STEP_IMSI_CHANGED) {
ctx->imsi_check_done = TRUE;
cached = mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (ctx->sim));
+ if (!cached) {
+ mm_gdbus_sim_set_imsi (MM_GDBUS_SIM (ctx->sim), current);
+ cached = mm_gdbus_sim_get_imsi (MM_GDBUS_SIM (ctx->sim));
+ }
str = "imsi";
} else
g_assert_not_reached();
I understand the IMSI going from NULL to a string should never trigger a hot-swap event, so this does just that. This example prevent mm_broadband_modem_sim_hot_swap_ports_context_reset
from being called when the IMSI was null, so everything works as before hot-swap was used (Seems like this commit is where it was enabled)