modemmanager: check modem state before establishing a connection
authorFlorian Eckert <fe@dev.tdt.de>
Wed, 8 Nov 2023 12:08:05 +0000 (13:08 +0100)
committerFlorian Eckert <fe@dev.tdt.de>
Mon, 4 Dec 2023 10:37:06 +0000 (11:37 +0100)
With this change the following modem 'state' are checked before a
connection attempt setup.
* failed: Stop connection attempt because of sim-missing
* locked: Stop connection attempt if no pincode is set

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

index e484b7fbd00add0e10fd068146bc47298fff5cb6..fdd7a0c3ed8049d8c3b8aa0e53fb79bf7ecbf315 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=modemmanager
 PKG_SOURCE_VERSION:=1.22.0
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL:=https://gitlab.freedesktop.org/mobile-broadband/ModemManager.git
index a4d837c1e51420f25bb1babe9ca28ba331e30d90..7572a477c2f97db309cdf4f3248aeba714a0f8ec 100755 (executable)
@@ -364,6 +364,50 @@ modemmanager_set_allowed_mode() {
        }
 }
 
+modemmanager_check_state() {
+       local device="$1"
+       local modemstatus="$2"
+       local pincode="$3"
+
+       local state reason
+
+       state="$(modemmanager_get_field "${modemstatus}" "state")"
+       state="${state%% *}"
+       reason="$(modemmanager_get_field "${modemstatus}" "state-failed-reason")"
+
+       case "$state" in
+               "failed")
+                       case "$reason" in
+                               "sim-missing")
+                                       echo "SIM missing"
+                                       proto_notify_error "${interface}" MM_FAILED_REASON_SIM_MISSING
+                                       proto_block_restart "${interface}"
+                                       return 1
+                                       ;;
+                               *)
+                                       proto_notify_error "${interface}" MM_FAILED_REASON_UNKNOWN
+                                       proto_block_restart "${interface}"
+                                       return 1
+                                       ;;
+                       esac
+                       ;;
+               "locked")
+                       if [ -n "$pincode" ]; then
+                               mmcli --modem="${device}" -i any --pin=${pincode} || {
+                                       proto_notify_error "${interface}" MM_PINCODE_WRONG
+                                       proto_block_restart "${interface}"
+                                       return 1
+                               }
+                       else
+                               echo "PIN required"
+                               proto_notify_error "${interface}" MM_PINCODE_REQUIRED
+                               proto_block_restart "${interface}"
+                               return 1
+                       fi
+                       ;;
+       esac
+}
+
 modemmanager_set_preferred_mode() {
        local device="$1"
        local interface="$2"
@@ -430,6 +474,9 @@ proto_modemmanager_setup() {
        }
        echo "modem available at ${modempath}"
 
+       modemmanager_check_state "$device" "${modemstatus}" "$pincode"
+       [ "$?" -ne "0" ] && return 1
+
        [ -z "${allowedmode}" ] || {
                case "$allowedmode" in
                        "2g")
@@ -485,7 +532,6 @@ proto_modemmanager_setup() {
        append_param "${cliauth:+allowed-auth=${cliauth}}"
        append_param "${username:+user=${username}}"
        append_param "${password:+password=${password}}"
-       append_param "${pincode:+pin=${pincode}}"
 
        mmcli --modem="${device}" --timeout 120 --simple-connect="${connectargs}" || {
                proto_notify_error "${interface}" MM_CONNECT_FAILED