modemmanager: move modemmanager_check_state failed and locked into sub functions

To make the source clearer, the program parts for the 'locked' and 'failed'
cases are outsourced to sub-functions.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert
2024-09-26 10:14:16 +02:00
committed by Robert Marko
parent dced576bfe
commit 64bd9e9d08

View File

@@ -308,18 +308,15 @@ modemmanager_set_allowed_mode() {
} }
} }
modemmanager_check_state() { modemmanager_check_state_failed() {
local device="$1" local device="$1"
local modemstatus="$2" local interface="$2"
local pincode="$3" local modemstatus="$3"
local state reason local reason
state="$(modemmanager_get_field "${modemstatus}" "modem.generic.state")"
case "$state" in
"failed")
reason="$(modemmanager_get_field "${modemstatus}" "modem.generic.state-failed-reason")" reason="$(modemmanager_get_field "${modemstatus}" "modem.generic.state-failed-reason")"
case "$reason" in case "$reason" in
"sim-missing") "sim-missing")
echo "SIM missing" echo "SIM missing"
@@ -333,20 +330,51 @@ modemmanager_check_state() {
return 1 return 1
;; ;;
esac esac
;; }
"locked")
modemmanager_check_state_locked() {
local device="$1"
local interface="$2"
local modemstatus="$3"
local pincode="$4"
if [ -n "$pincode" ]; then if [ -n "$pincode" ]; then
mmcli --modem="${device}" -i any --pin=${pincode} || { mmcli --modem="${device}" -i any --pin=${pincode} || {
proto_notify_error "${interface}" MM_PINCODE_WRONG proto_notify_error "${interface}" MM_PINCODE_WRONG
proto_block_restart "${interface}" proto_block_restart "${interface}"
return 1 return 1
} }
return 0
else else
echo "PIN required" echo "PIN required"
proto_notify_error "${interface}" MM_PINCODE_REQUIRED proto_notify_error "${interface}" MM_PINCODE_REQUIRED
proto_block_restart "${interface}" proto_block_restart "${interface}"
return 1 return 1
fi fi
}
modemmanager_check_state() {
local device="$1"
local modemstatus="$2"
local pincode="$3"
local state
state="$(modemmanager_get_field "${modemstatus}" "modem.generic.state")"
case "$state" in
"failed")
modemmanager_check_state_failed "$device" \
"$interface" \
"$modemstatus"
[ "$?" -ne "0" ] && return 1
;;
"locked")
modemmanager_check_state_locked "$device" \
"$interface" \
"$modemstatus" \
"$pincode"
[ "$?" -ne "0" ] && return 1
;; ;;
esac esac
} }