From edc48a01d24a95226335d4d197533a7a5108af6d Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Sun, 25 Jul 2021 14:26:40 +0200 Subject: [PATCH] ModemMonitor: Periodically check whether the modem is still alive, reset it if not Signed-off-by: Stacy Harper --- configs/sudo/modem | 4 +++ scripts/core/sxmo_appmenu.sh | 1 + scripts/core/sxmo_statusbar.sh | 2 ++ scripts/modem/sxmo_modemmonitor.sh | 33 ++++++++++++++++++++++++ scripts/modem/sxmo_modemmonitortoggle.sh | 20 +++++++++++++- 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 configs/sudo/modem diff --git a/configs/sudo/modem b/configs/sudo/modem new file mode 100644 index 0000000..6df97bf --- /dev/null +++ b/configs/sudo/modem @@ -0,0 +1,4 @@ +ALL ALL=NOPASSWD: /sbin/rc-service eg25-manager restart +ALL ALL=NOPASSWD: /sbin/rc-service modemmanager stop +ALL ALL=NOPASSWD: /sbin/rc-service modemmanager start +ALL ALL=NOPASSWD: /sbin/rc-service modemmanager restart diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index 745607c..ba3f38a 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -140,6 +140,7 @@ programchoicesinit() { $icon_aru Brightness ^ 1 ^ sxmo_brightness.sh up $icon_ard Brightness ^ 1 ^ sxmo_brightness.sh down $icon_phn Modem Toggle ^ 1 ^ sxmo_modemmonitortoggle.sh + $icon_phn Modem Reset ^ 1 ^ sxmo_modemmonitortoggle.sh reset $icon_inf Modem Info ^ 0 ^ sxmo_modeminfo.sh $icon_phl Modem Log ^ 0 ^ sxmo_modemlog.sh $icon_wif Wifi $( diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index 2356192..b7b7445 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -48,6 +48,8 @@ update() { MODEMMON="" elif [ connected = "$MODEMSTATE" ]; then MODEMMON="" + elif [ failed = "$MODEMSTATE" ] || [ disconnected = "$MODEMSTATE" ]; then + MODEMMON="" else MODEMMON="" fi diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index 752647a..f2b63b3 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -295,6 +295,10 @@ mainloop() { elif echo "$newstate" | grep "int32 11"; then echo connected > "$MODEMSTATEFILE" #3G/2G/4G available + elif echo "$newstate" | grep "int32 -1"; then + echo failed > "$MODEMSTATEFILE" + elif echo "$newstate" | grep "int32 3"; then + echo disabled > "$MODEMSTATEFILE" else echo unknown > "$MODEMSTATEFILE" fi @@ -302,6 +306,35 @@ mainloop() { fi done & + ( #check whether the modem is still alive every minute, reset the modem if not + while : + do + sleep 60 + TRIES=0 + while [ "$TRIES" -lt 10 ]; do + MODEMS="$(mmcli -L)" + if echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' > /dev/null; then + break + elif grep -q rtc "$UNSUSPENDREASONFILE"; then + #don't bother checking in rtc-wake situations + TRIES=0 + break + else + TRIES=$((TRIES+1)) + echo "sxmo_modemmonitor: modem not found, waiting for modem... (try #$TRIES)">&2 + sleep 2 + if [ "$TRIES" -eq 10 ]; then + echo failed > "$MODEMSTATEFILE" + echo "sxmo_modemmonitor: forcing modem reset">&2 + sxmo_modemmonitortoggle.sh reset #will kill the modemmonitor too + break + fi + fi + done + done + ) & + + wait wait wait wait diff --git a/scripts/modem/sxmo_modemmonitortoggle.sh b/scripts/modem/sxmo_modemmonitortoggle.sh index 7dc49ee..db9efae 100755 --- a/scripts/modem/sxmo_modemmonitortoggle.sh +++ b/scripts/modem/sxmo_modemmonitortoggle.sh @@ -3,12 +3,30 @@ # This script toggles the modem monitor # It optionally takes a parameter "on" or "off" # forcing it to toggle only to that desired state if applicable. +# It may also take a "reset" parameter that forces the +# entire modem subsystem to reload # include common definitions # shellcheck source=scripts/core/sxmo_common.sh . "$(dirname "$0")/sxmo_common.sh" -if [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then +if [ "$1" = "reset" ]; then + #does a hard reset of the entire modem + echo "sxmo_modemmonitortoggle: forcing modem reset">&2 + notify-send "Resetting modem, this may take a minute..." + pkill -TERM -f sxmo_modemmonitor.sh + sudo rc-service modemmanager stop + sudo rc-service eg25-manager stop + sleep 5 + while ! rc-service eg25-manager status | grep -q started; do + sudo rc-service eg25-manager start + sleep 2 + done + sleep 5 + sudo rc-service modemmanager start + sleep 30 + setsid -f sxmo_modemmonitor.sh & +elif [ "$1" != "on" ] && pgrep -f sxmo_modemmonitor.sh; then pkill -TERM -f sxmo_modemmonitor.sh elif [ "$1" != "off" ] && ! pgrep -f sxmo_modemmonitor.sh; then setsid -f sxmo_modemmonitor.sh &