modemmanager: check during SIM unlocking whether initialization has been completed
authorFlorian Eckert <fe@dev.tdt.de>
Wed, 6 Nov 2024 13:28:57 +0000 (14:28 +0100)
committerFlorian Eckert <Eckert.Florian@googlemail.com>
Fri, 15 Nov 2024 10:17:05 +0000 (11:17 +0100)
After the SIM has been successfully unlocked, it is initialized. This can
take longer on some modems, so we must wait until the modem is ready to
execute the next commands.

Otherwise the modem cannot be enabled and aborts with the following
error message:

error: couldn't enable the modem: 'GDBus.Error:org.freedesktop.ModemManager1.Error.Core.WrongState: modem in initializing state'

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
net/modemmanager/files/lib/netifd/proto/modemmanager.sh

index 0aacc9f907de5c602866cfbb4f785efae63a55db..715178f71e4d0451a960303ec7cda054a3f282e9 100644 (file)
@@ -435,6 +435,10 @@ modemmanager_check_state_locked() {
                return 1
        }
 
+       # Give the modem time to change to the initializing state after
+       # unlocking 
+       sleep 1
+
        return 0
 }
 
@@ -444,7 +448,10 @@ modemmanager_check_pin_state() {
        local modemstatus="$3"
        local pincode="$4"
 
-       local state
+       local state modemstatus
+
+       local timeout=20
+       local count=0
 
        state="$(modemmanager_get_field "${modemstatus}" "modem.generic.state")"
 
@@ -463,6 +470,19 @@ modemmanager_check_pin_state() {
                        [ "$?" -ne "0" ] && return 1
                        ;;
        esac
+
+       # After the SIM has been successfully unlocked, it is initialized.
+       # This can take longer on some modems, so we must wait until the
+       # modem is ready to execute the next commands.
+       while [ $count -lt "$timeout" ]; do
+               modemstatus=$(mmcli --modem="${device}" --output-keyvalue)
+               state="$(modemmanager_get_field "${modemstatus}" "modem.generic.state")"
+
+               [ "$state" != "initializing" ] && return 0
+               count=$((count + 1))
+               echo "waiting for SIM initializing (${count}s)"
+               sleep 1
+       done
 }
 
 modemmanager_set_preferred_mode() {