From: Florian Eckert Date: Thu, 26 Sep 2024 08:14:16 +0000 (+0200) Subject: modemmanager: move modemmanager_check_state failed and locked into sub functions X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=64bd9e9d08040fa2d280d9c10536c58f47c3d87d;p=feed%2Fpackages.git 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 --- diff --git a/net/modemmanager/files/lib/netifd/proto/modemmanager.sh b/net/modemmanager/files/lib/netifd/proto/modemmanager.sh index 9da65935cf..a0bc232aad 100644 --- a/net/modemmanager/files/lib/netifd/proto/modemmanager.sh +++ b/net/modemmanager/files/lib/netifd/proto/modemmanager.sh @@ -308,45 +308,73 @@ modemmanager_set_allowed_mode() { } } +modemmanager_check_state_failed() { + local device="$1" + local interface="$2" + local modemstatus="$3" + + local reason + + reason="$(modemmanager_get_field "${modemstatus}" "modem.generic.state-failed-reason")" + + 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 +} + +modemmanager_check_state_locked() { + local device="$1" + local interface="$2" + local modemstatus="$3" + local pincode="$4" + + if [ -n "$pincode" ]; then + mmcli --modem="${device}" -i any --pin=${pincode} || { + proto_notify_error "${interface}" MM_PINCODE_WRONG + proto_block_restart "${interface}" + return 1 + } + return 0 + else + echo "PIN required" + proto_notify_error "${interface}" MM_PINCODE_REQUIRED + proto_block_restart "${interface}" + return 1 + fi +} + modemmanager_check_state() { local device="$1" local modemstatus="$2" local pincode="$3" - local state reason + local state state="$(modemmanager_get_field "${modemstatus}" "modem.generic.state")" case "$state" in "failed") - reason="$(modemmanager_get_field "${modemstatus}" "modem.generic.state-failed-reason")" - 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 + modemmanager_check_state_failed "$device" \ + "$interface" \ + "$modemstatus" + [ "$?" -ne "0" ] && return 1 ;; "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 + modemmanager_check_state_locked "$device" \ + "$interface" \ + "$modemstatus" \ + "$pincode" + [ "$?" -ne "0" ] && return 1 ;; esac }