modemmanager: check modem state before establishing a connection

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>
This commit is contained in:
Florian Eckert 2023-11-08 13:08:05 +01:00
parent 56e29ed7da
commit 7b4d82c58f
2 changed files with 48 additions and 2 deletions

View 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

View File

@ -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