From: Florian Eckert Date: Wed, 6 Nov 2024 13:28:57 +0000 (+0100) Subject: modemmanager: check during SIM unlocking whether initialization has been completed X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=24d2ba0ba88043dbe7f116d07aa26b3a841877dc;p=openwrt-packages.git modemmanager: check during SIM unlocking whether initialization has been completed 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 --- diff --git a/net/modemmanager/files/lib/netifd/proto/modemmanager.sh b/net/modemmanager/files/lib/netifd/proto/modemmanager.sh index 0aacc9f90..715178f71 100644 --- a/net/modemmanager/files/lib/netifd/proto/modemmanager.sh +++ b/net/modemmanager/files/lib/netifd/proto/modemmanager.sh @@ -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() {