uqmi: add illegal SIM state recovery
authorDavid Bauer <mail@david-bauer.net>
Sat, 7 Oct 2023 20:27:03 +0000 (22:27 +0200)
committerDavid Bauer <mail@david-bauer.net>
Mon, 9 Oct 2023 01:36:03 +0000 (03:36 +0200)
On some network-triggered disconnections the UIM state might end up in
"illegal". This prevents the modem from attaching to any network in
non-restricted service modes.

Detect this state and reset the SIM card. This way, the modem can attach
to networks again.

Signed-off-by: David Bauer <mail@david-bauer.net>
package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh

index f4432b4fa33676e0bacc7e7e6e7a0244cc11c37d..e89d5a43a1de9fdcc90c0191cc8c411494de5d37 100755 (executable)
@@ -98,6 +98,32 @@ proto_qmi_setup() {
                fi
        done
 
+       # Check if UIM application is stuck in illegal state
+       local uim_state_timeout=0
+       while true; do
+               json_load "$(uqmi -s -d "$device" --uim-get-sim-state)"
+               json_get_var card_application_state card_application_state
+               if [ "$card_application_state" = "illegal" ]; then
+                       echo "SIM in illegal state"
+
+                       # Try to reset SIM application
+                       uqmi -d "$device" --uim-power-off --uim-slot 1
+                       sleep 3
+                       uqmi -d "$device" --uim-power-on --uim-slot 1
+
+                       if [ "$uim_state_timeout" -lt "$timeout" ] || [ "$timeout" = "0" ]; then
+                               let uim_state_timeout++
+                               sleep 1
+                               continue
+                       fi
+
+                       proto_notify_error "$interface" SIM_ILLEGAL_STATE
+                       return 1
+               else
+                       break
+               fi
+       done
+
        if uqmi -s -d "$device" --uim-get-sim-state | grep -q '"Not supported"\|"Invalid QMI command"' &&
           uqmi -s -d "$device" --get-pin-status | grep -q '"Not supported"\|"Invalid QMI command"' ; then
                [ -n "$pincode" ] && {