Fix SIM2 QMI UIM provisioning, auto-enable ModemManager, PIN auto-prompt, call audio, and Dunst clearing
This commit is contained in:
@@ -3,61 +3,42 @@
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
ca_dbus_get_prop() {
|
||||
dbus-send --session --print-reply --dest=org.mobian_project.CallAudio \
|
||||
--reply-timeout=2500 /org/mobian_project/CallAudio org.freedesktop.DBus.Properties.Get \
|
||||
string:org.mobian_project.CallAudio string:"$1"
|
||||
}
|
||||
|
||||
ca_dbus_set_prop() {
|
||||
dbus-send --session --print-reply --type=method_call \
|
||||
--reply-timeout=2500 --dest=org.mobian_project.CallAudio \
|
||||
/org/mobian_project/CallAudio org.mobian_project.CallAudio."$1" "$2" |\
|
||||
grep -q "boolean true" && return 0 || return 1
|
||||
}
|
||||
|
||||
enable_call_audio_mode() {
|
||||
if pactl -f json info 2>/dev/null | jq -r .server_name | grep -q PipeWire; then
|
||||
sxmo_audio.sh device set Earpiece
|
||||
sxmo_log "Successfully enabled call audio mode (Earpiece)."
|
||||
sxmo_hook_statusbar.sh volume
|
||||
return 0
|
||||
fi
|
||||
if ca_dbus_set_prop SelectMode uint32:1; then
|
||||
sxmo_log "Successfully enabled call audio mode."
|
||||
sxmo_hook_statusbar.sh volume
|
||||
else
|
||||
sxmo_notify_user.sh "Failed to enable call audio mode."
|
||||
return 1
|
||||
fi
|
||||
if command -v amixer >/dev/null 2>&1; then
|
||||
amixer -c 0 sset 'PRI_MI2S_RX Voice Mixer VoiceMMode1' on >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'VoiceMMode1 Capture Mixer TERT_MI2S_TX' on >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'RX1 MIX1 INP1' 'RX1' >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'RDAC2 MUX' 'RX1' >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'EAR_S' 'Switch' >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'DEC1 MUX' 'ADC1' >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'ADC1 Volume' 100% >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'RX1 Digital Volume' 84 >/dev/null 2>&1 || true
|
||||
fi
|
||||
sxmo_audio.sh device set Earpiece >/dev/null 2>&1 || true
|
||||
sxmo_log "Enabled ALSA voice call audio mode (Earpiece)."
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
return 0
|
||||
}
|
||||
|
||||
disable_call_audio_mode() {
|
||||
if pactl -f json info 2>/dev/null | jq -r .server_name | grep -q PipeWire; then
|
||||
sxmo_audio.sh device set Speaker
|
||||
sxmo_log "Successfully disabled call audio mode (Speaker)."
|
||||
sxmo_hook_statusbar.sh volume
|
||||
return 0
|
||||
fi
|
||||
if ca_dbus_set_prop SelectMode uint32:0; then
|
||||
sxmo_log "Successfully disabled call audio mode."
|
||||
sxmo_hook_statusbar.sh volume
|
||||
else
|
||||
sxmo_notify_user.sh "Failed to disable call audio mode."
|
||||
return 1
|
||||
fi
|
||||
if command -v amixer >/dev/null 2>&1; then
|
||||
amixer -c 0 sset 'PRI_MI2S_RX Voice Mixer VoiceMMode1' off >/dev/null 2>&1 || true
|
||||
amixer -c 0 sset 'VoiceMMode1 Capture Mixer TERT_MI2S_TX' off >/dev/null 2>&1 || true
|
||||
fi
|
||||
sxmo_audio.sh device set Speaker >/dev/null 2>&1 || true
|
||||
sxmo_log "Disabled ALSA voice call audio mode (Speaker)."
|
||||
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_audio() {
|
||||
if ! enable_call_audio_mode; then
|
||||
return 1
|
||||
fi
|
||||
enable_call_audio_mode
|
||||
return 0
|
||||
}
|
||||
|
||||
reset_audio() {
|
||||
if ! disable_call_audio_mode; then
|
||||
return 1
|
||||
fi
|
||||
disable_call_audio_mode
|
||||
return 0
|
||||
}
|
||||
|
||||
"$@"
|
||||
|
||||
@@ -36,7 +36,7 @@ pickup() {
|
||||
NUM="$(vid_to_number "$CALLID" 2>/dev/null || true)"
|
||||
|
||||
DIRECTION="$(
|
||||
mmcli --voice-status -o "$CALLID" -K |
|
||||
(mmcli -m any -o "$CALLID" -K 2>/dev/null || mmcli -o "$CALLID" -K 2>/dev/null || mmcli --voice-status -o "$CALLID" -K 2>/dev/null) |
|
||||
grep call.properties.direction |
|
||||
cut -d: -f2 |
|
||||
tr -d " "
|
||||
@@ -53,11 +53,12 @@ pickup() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
sxmo_notify_user.sh "Started call"
|
||||
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.initiatedcall"
|
||||
log_event "call_start" "$CALLID"
|
||||
if command -v xcallscreen >/dev/null 2>&1; then
|
||||
xcallscreen outgoing "$CALLID" "$NUM" >/dev/null 2>&1 || true
|
||||
else
|
||||
sxmo_notify_user.sh "Started call"
|
||||
fi
|
||||
;;
|
||||
incoming)
|
||||
@@ -74,11 +75,12 @@ pickup() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
sxmo_notify_user.sh "Picked up call"
|
||||
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.pickedupcall"
|
||||
log_event "call_pickup" "$CALLID"
|
||||
if command -v xcallscreen >/dev/null 2>&1; then
|
||||
xcallscreen active "$CALLID" "$NUM" >/dev/null 2>&1 || true
|
||||
else
|
||||
sxmo_notify_user.sh "Picked up call"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
|
||||
@@ -16,15 +16,16 @@ dial_number() {
|
||||
return 0
|
||||
fi
|
||||
|
||||
NUMBER="$1"
|
||||
NUMBER="$(printf "%s" "$1" | tr -cd '+0-9*#')"
|
||||
if [ -z "$NUMBER" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
CLEANEDNUMBER="$(pnc find ${DEFAULT_COUNTRY:+-c "$DEFAULT_COUNTRY"} "$1" 2>/dev/null || true)"
|
||||
if [ -n "$CLEANEDNUMBER" ] && [ "$NUMBER" != "$CLEANEDNUMBER" ]; then
|
||||
NUMBER="$(cat <<EOF | sxmo_dmenu.sh -p "Rewrite ?"
|
||||
$NUMBER
|
||||
$CLEANEDNUMBER
|
||||
EOF
|
||||
)"
|
||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.generic.state" {print $2; exit}')"
|
||||
if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then
|
||||
mmcli -m any -e >/dev/null 2>&1 || true
|
||||
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
sxmo_log "Attempting to dial: $NUMBER"
|
||||
@@ -33,7 +34,7 @@ EOF
|
||||
fi
|
||||
|
||||
if ! CALLID="$(
|
||||
mmcli -m any --voice-create-call "number=$NUMBER" |
|
||||
mmcli -m any --voice-create-call="number=$NUMBER" 2>/dev/null |
|
||||
grep -Eo "Call/[0-9]+" |
|
||||
grep -oE "[0-9]+"
|
||||
)"; then
|
||||
@@ -79,16 +80,22 @@ EOF
|
||||
}
|
||||
|
||||
dial_ussd() {
|
||||
|
||||
USSD="$1"
|
||||
DBUS_MODEM=$(mmcli -J -L | jq -r '."modem-list"[]')
|
||||
MM_BUS="org.freedesktop.ModemManager1"
|
||||
USSD_IFACE="org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd"
|
||||
|
||||
sxmo_log "Dialling USSD: $USSD"
|
||||
OUTPUT=$(busctl --json=short call "$MM_BUS" "$DBUS_MODEM" "$USSD_IFACE" Initiate "s" "$USSD" | jq -r '.data[]')
|
||||
|
||||
sxmo_terminal.sh sxmo_ussd.sh "$DBUS_MODEM" "Unknown" "$OUTPUT" &
|
||||
OUTPUT="$(doas -n /usr/libexec/msm-modem-uim-selection ussd initiate "$USSD" 2>/dev/null || /usr/libexec/msm-modem-uim-selection ussd initiate "$USSD" 2>/dev/null || true)"
|
||||
if [ -z "$OUTPUT" ]; then
|
||||
DBUS_MODEM="$(mmcli -J -L 2>/dev/null | jq -r '."modem-list"[]' 2>/dev/null | head -n1)"
|
||||
MM_BUS="org.freedesktop.ModemManager1"
|
||||
USSD_IFACE="org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd"
|
||||
if [ -n "$DBUS_MODEM" ]; then
|
||||
OUTPUT="$(busctl --json=short call "$MM_BUS" "$DBUS_MODEM" "$USSD_IFACE" Initiate "s" "$USSD" 2>/dev/null | jq -r '.data[]' 2>/dev/null || true)"
|
||||
fi
|
||||
fi
|
||||
if [ -n "$OUTPUT" ]; then
|
||||
sxmo_notify_user.sh "USSD ($USSD): $OUTPUT"
|
||||
else
|
||||
sxmo_notify_user.sh --urgency=critical "USSD request failed ($USSD)"
|
||||
fi
|
||||
}
|
||||
|
||||
dial_menu() {
|
||||
|
||||
Executable
+174
@@ -0,0 +1,174 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
# Copyright 2022 Sxmo Contributors
|
||||
|
||||
# include common definitions
|
||||
# shellcheck source=scripts/core/sxmo_common.sh
|
||||
. sxmo_common.sh
|
||||
|
||||
# see networkmanager documentation for these state names
|
||||
statenumtoname() {
|
||||
case "$1" in
|
||||
"int32 -1") printf "failed" ;;
|
||||
"int32 0") printf "unknown" ;;
|
||||
"int32 1") printf "initializing" ;;
|
||||
"int32 2") printf "locked" ;;
|
||||
"int32 3") printf "disabled" ;;
|
||||
"int32 4") printf "disabling" ;;
|
||||
"int32 5") printf "enabling" ;;
|
||||
"int32 6") printf "enabled" ;;
|
||||
"int32 7") printf "searching" ;;
|
||||
"int32 8") printf "registered" ;;
|
||||
"int32 9") printf "disconnecting" ;;
|
||||
"int32 10") printf "connecting" ;;
|
||||
"int32 11") printf "connected" ;;
|
||||
*) printf "ERROR" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
mainloop() {
|
||||
# get initial modem state and handle SIM2/QMI PIN lock or unprovisioned slot
|
||||
(
|
||||
tries=0
|
||||
newstate=""
|
||||
while [ "$tries" -lt 15 ]; do
|
||||
newstate="$(mmcli -m any -K 2>/dev/null | grep "^modem.generic.state " | cut -d':' -f2 | sed 's/^ //')"
|
||||
if [ -n "$newstate" ]; then
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
tries=$((tries + 1))
|
||||
done
|
||||
|
||||
uim_st="$(doas -n /usr/libexec/msm-modem-uim-selection status 2>/dev/null || /usr/libexec/msm-modem-uim-selection status 2>/dev/null || true)"
|
||||
if printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_PIN1_STATE=(enabled-not-verified|blocked)|SLOT[12]_APP_STATE=(pin1|puk1)"; then
|
||||
newstate="locked"
|
||||
elif printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_STATE=present" && printf "%s\n" "$uim_st" | grep -q "^PRIMARY_GW_SLOT=0$"; then
|
||||
doas -n /usr/libexec/msm-modem-uim-selection boot >/dev/null 2>&1 || true
|
||||
newstate="$(mmcli -m any -K 2>/dev/null | grep "^modem.generic.state " | cut -d':' -f2 | sed 's/^ //')"
|
||||
fi
|
||||
|
||||
if [ -n "$newstate" ]; then
|
||||
# fake oldstate (boot) and reason (0)
|
||||
sxmo_hook_modem.sh "boot" "$newstate" "0"
|
||||
sxmo_hook_statusbar.sh modem
|
||||
fi
|
||||
) &
|
||||
|
||||
# Monitor for incoming calls
|
||||
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Voice',type='signal',member='CallAdded'" |
|
||||
while read -r line; do
|
||||
echo "$line" | grep -qE "^signal" && sxmo_modem.sh checkforincomingcalls
|
||||
done &
|
||||
|
||||
# Monitor for incoming texts
|
||||
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem.Messaging',type='signal',member='Added'" |
|
||||
while read -r line; do
|
||||
echo "$line" | grep -qE "^signal" && sxmo_modem.sh checkfornewtexts
|
||||
done &
|
||||
|
||||
# Check for new texts periodically
|
||||
sxmo_run_aligned.sh 300 sxmo_modem.sh checkfornewtexts &
|
||||
|
||||
# Monitor for finished calls
|
||||
dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Call'" |
|
||||
while read -r line; do
|
||||
echo "$line" | grep -qE "^signal" && sxmo_modem.sh checkforfinishedcalls
|
||||
done &
|
||||
|
||||
# Periodically remove finished calls
|
||||
sxmo_run_aligned.sh 300 sxmo_modem.sh checkforfinishedcalls &
|
||||
|
||||
# Monitor for modem state change
|
||||
dbus-monitor --system "interface='org.freedesktop.ModemManager1.Modem',type='signal',member='StateChanged'" |
|
||||
while read -r line; do
|
||||
if echo "$line" | grep -qE "^signal.*StateChanged"; then
|
||||
read -r oldstate
|
||||
read -r newstate
|
||||
read -r reason
|
||||
sxmo_hook_modem.sh "$(statenumtoname "$oldstate")" \
|
||||
"$(statenumtoname "$newstate")" \
|
||||
"$(echo "$reason" | sed 's/uint32 //')"
|
||||
sxmo_hook_statusbar.sh modem
|
||||
fi
|
||||
done &
|
||||
|
||||
# Monitor for 3GPP USSD
|
||||
dbus-monitor --system "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',arg0='org.freedesktop.ModemManager1.Modem.Modem3gpp.Ussd'" |
|
||||
while read -r line; do
|
||||
case "$line" in
|
||||
*"/org/freedesktop/ModemManager1/Modem"*)
|
||||
MODEM=$(echo "$line" | awk -F'[;=]' '{print $6}')
|
||||
CHANGED=0
|
||||
;;
|
||||
*"string \"NetworkNotification"*)
|
||||
TYPE="NetworkNotification"
|
||||
CHANGED=1
|
||||
;;
|
||||
*"string \"NetworkRequest"*)
|
||||
TYPE="NetworkRequest"
|
||||
CHANGED=1
|
||||
;;
|
||||
*)
|
||||
CHANGED=0
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$CHANGED" = "1" ]; then
|
||||
# Fetch message (third argument) in sxmo_ussd.sh to save time in this loop
|
||||
sxmo_terminal.sh sxmo_ussd.sh "$MODEM" "$TYPE" "" &
|
||||
fi
|
||||
|
||||
done &
|
||||
|
||||
if [ -f "${SXMO_MMS_BASE_DIR:-"$HOME"/.mms/modemmanager}/mms" ]; then
|
||||
# monitor for received mms
|
||||
dbus-monitor "interface='org.ofono.mms.Service',type='signal',member='MessageAdded'" |
|
||||
while read -r line; do
|
||||
if echo "$line" | grep -q '^object path'; then
|
||||
MESSAGE_PATH="$(echo "$line" | cut -d\" -f2)"
|
||||
fi
|
||||
if echo "$line" | grep -q 'string "received"'; then
|
||||
sxmo_mms.sh processmms "$MESSAGE_PATH"
|
||||
fi
|
||||
done &
|
||||
fi
|
||||
|
||||
if [ -f "${SXMO_VVM_BASE_DIR:-"$HOME"/.vvm/modemmanager}/vvm" ]; then
|
||||
# monitor for vvm (Visual Voice Mail)
|
||||
VVM_START=0
|
||||
dbus-monitor "interface='org.kop316.vvm.Service',type='signal',member='MessageAdded'" |
|
||||
while read -r line; do
|
||||
if echo "$line" | grep -q '^object path'; then
|
||||
VVM_ID="$(echo "$line" | cut -d\" -f2 | rev | cut -d'/' -f1 | rev)"
|
||||
VVM_START=1
|
||||
fi
|
||||
|
||||
if echo "$line" | grep -q '^]'; then
|
||||
VVM_START=0
|
||||
sxmo_vvm.sh processvvm "$VVM_DATE" "$VVM_SENDER" "$VVM_ID" "$VVM_ATTACHMENT"
|
||||
fi
|
||||
|
||||
if [ "$VVM_START" -eq 1 ]; then
|
||||
if echo "$line" | grep -q '^string "Date"'; then
|
||||
read -r line
|
||||
VVM_DATE="$(echo "$line" | cut -d\" -f2)"
|
||||
elif echo "$line" | grep -q '^string "Sender"'; then
|
||||
read -r line
|
||||
VVM_SENDER="$(echo "$line" | cut -d\" -f2)"
|
||||
elif echo "$line" | grep -q '^string "Attachments"'; then
|
||||
read -r line
|
||||
VVM_ATTACHMENT="$(echo "$line" | cut -d\" -f2)"
|
||||
fi
|
||||
fi
|
||||
done &
|
||||
fi
|
||||
|
||||
wait
|
||||
}
|
||||
|
||||
# new session, clean up all phone related files
|
||||
rm "$XDG_RUNTIME_DIR/sxmo_calls/"* 2>/dev/null || true
|
||||
rm -f "$XDG_RUNTIME_DIR"/sxmo.ring.pid 2>/dev/null
|
||||
rm -f "$SXMO_NOTIFDIR"/incomingcall* 2>/dev/null
|
||||
mainloop
|
||||
@@ -12,189 +12,209 @@ SXMO_NOTIFDIR="${SXMO_NOTIFDIR:-${XDG_DATA_HOME:-$HOME/.local/share}/sxmo/notifi
|
||||
[ -z "$SXMO_NOTIFDIR" ] || [ "$SXMO_NOTIFDIR" = "/" ] && SXMO_NOTIFDIR="$HOME/.local/share/sxmo/notifications"
|
||||
|
||||
_clear_notif_group() {
|
||||
find "$SXMO_NOTIFDIR" -type f | while read -r file; do
|
||||
if awk NR==1 "$file" | grep -lxq "$1"; then
|
||||
rm "$file"
|
||||
fi
|
||||
done
|
||||
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
|
||||
if [ -f "$file" ] && awk NR==1 "$file" 2>/dev/null | grep -lxq "$1"; then
|
||||
rm -f "$file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
_handle_new_notif_file(){
|
||||
file="$1"
|
||||
clear_all() {
|
||||
rm -f "$SXMO_NOTIFDIR"/* 2>/dev/null || true
|
||||
dunstctl close-all >/dev/null 2>&1 || true
|
||||
dunstctl history-clear >/dev/null 2>&1 || true
|
||||
pkill -x dunstify >/dev/null 2>&1 || true
|
||||
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
if [ "$(wc -l "$file" | cut -d' ' -f1)" -lt 3 ]; then
|
||||
sxmo_log "Invalid notification file $file found, deleting!"
|
||||
rm -f "$file"
|
||||
return
|
||||
fi
|
||||
_handle_new_notif_file() {
|
||||
file="$1"
|
||||
[ -f "$file" ] || return 0
|
||||
|
||||
sxmo_hook_notification.sh "$file" &
|
||||
if [ "$(wc -l < "$file" 2>/dev/null || echo 0)" -lt 3 ]; then
|
||||
sxmo_log "Invalid notification file $file found, deleting!"
|
||||
rm -f "$file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
group="$(awk NR==1 "$file")"
|
||||
action="$(awk NR==2 "$file")"
|
||||
msg="$(tail -n+3 "$file" | cut -c1-70)"
|
||||
sxmo_hook_notification.sh "$file" &
|
||||
|
||||
case "$(dunstify --action="default,Open" "$msg")" in
|
||||
"2")
|
||||
#
|
||||
# _clear_notif_group "$group"
|
||||
#
|
||||
;;
|
||||
"default")
|
||||
_clear_notif_group "$group"
|
||||
setsid -f sh -c "$action" > /dev/null 2>&1
|
||||
;;
|
||||
esac
|
||||
group="$(awk NR==1 "$file" 2>/dev/null)"
|
||||
action="$(awk NR==2 "$file" 2>/dev/null)"
|
||||
msg="$(tail -n+3 "$file" 2>/dev/null | cut -c1-70)"
|
||||
|
||||
(
|
||||
case "$(dunstify --action="default,Open" "$msg" 2>/dev/null)" in
|
||||
"2")
|
||||
;;
|
||||
"default")
|
||||
_clear_notif_group "$group"
|
||||
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
|
||||
if [ -n "$action" ] && [ "$action" != "none" ]; then
|
||||
setsid -f sh -c "$action" > /dev/null 2>&1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
) &
|
||||
}
|
||||
|
||||
_notifications_hook() {
|
||||
_cnt=0
|
||||
for _nf in "$SXMO_NOTIFDIR"/*; do
|
||||
[ -f "$_nf" ] && _cnt=$((_cnt + 1))
|
||||
done
|
||||
sxmo_hook_notifications.sh "$_cnt"
|
||||
_cnt=0
|
||||
for _nf in "$SXMO_NOTIFDIR"/*; do
|
||||
[ -f "$_nf" ] && _cnt=$((_cnt + 1))
|
||||
done
|
||||
sxmo_hook_notifications.sh "$_cnt"
|
||||
}
|
||||
|
||||
monitor() {
|
||||
mkdir -p "$SXMO_NOTIFDIR"
|
||||
mkdir -p "$SXMO_NOTIFDIR"
|
||||
|
||||
find "$SXMO_NOTIFDIR" -type f | while read -r file; do
|
||||
_handle_new_notif_file "$file"
|
||||
done
|
||||
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
|
||||
_handle_new_notif_file "$file"
|
||||
done
|
||||
|
||||
_notifications_hook
|
||||
_notifications_hook
|
||||
|
||||
fifo="$(mktemp -u)"
|
||||
mkfifo "$fifo"
|
||||
inotifywait -mq -e attrib,move,delete "$SXMO_NOTIFDIR" >> "$fifo" &
|
||||
inotif_pid=$!
|
||||
fifo="$(mktemp -u)"
|
||||
mkfifo "$fifo"
|
||||
inotifywait -mq -e close_write,moved_to,delete "$SXMO_NOTIFDIR" >> "$fifo" &
|
||||
inotif_pid=$!
|
||||
|
||||
finish() {
|
||||
kill "$inotif_pid"
|
||||
rm "$fifo"
|
||||
exit
|
||||
}
|
||||
trap 'finish' TERM INT EXIT
|
||||
finish() {
|
||||
kill "$inotif_pid" 2>/dev/null || true
|
||||
rm -f "$fifo"
|
||||
exit
|
||||
}
|
||||
trap 'finish' TERM INT EXIT
|
||||
|
||||
while read -r notif_folder notif_type notif_file; do
|
||||
if echo "$notif_type" | grep -qE "CREATE|MOVED_TO|ATTRIB"; then
|
||||
_handle_new_notif_file "$notif_folder$notif_file"
|
||||
fi
|
||||
_notifications_hook
|
||||
done < "$fifo"
|
||||
while read -r notif_folder notif_type notif_file; do
|
||||
if echo "$notif_type" | grep -qE "CLOSE_WRITE|MOVED_TO"; then
|
||||
_handle_new_notif_file "$notif_folder$notif_file"
|
||||
fi
|
||||
_notifications_hook
|
||||
done < "$fifo"
|
||||
|
||||
wait "$inotif_pid"
|
||||
wait "$inotif_pid"
|
||||
}
|
||||
|
||||
_menu_lines() {
|
||||
find "$SXMO_NOTIFDIR" -type f | while read -r file; do
|
||||
msg="$(tail -n+3 "$file" | tr "\n^" " ")"
|
||||
hrandmin="$(stat --printf %y "$file" | grep -oE '[0-9]{2}:[0-9]{2}')"
|
||||
cat <<EOF
|
||||
find "$SXMO_NOTIFDIR" -type f 2>/dev/null | while read -r file; do
|
||||
[ -f "$file" ] || continue
|
||||
msg="$(tail -n+3 "$file" 2>/dev/null | tr "\n^" " ")"
|
||||
hrandmin="$(stat -c %y "$file" 2>/dev/null | grep -oE '[0-9]{2}:[0-9]{2}' | head -n1)"
|
||||
cat <<EOF
|
||||
$hrandmin $msg^$file
|
||||
EOF
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
menu() {
|
||||
choices="$(cat <<EOF
|
||||
$icon_cls Close Menu
|
||||
choices="$(cat <<EOF
|
||||
$icon_del Clear Notifications
|
||||
$(_menu_lines)
|
||||
$icon_cls Close Menu
|
||||
EOF
|
||||
)"
|
||||
)"
|
||||
|
||||
picked="$(
|
||||
printf "%b" "$choices" |
|
||||
cut -d^ -f1 |
|
||||
sxmo_dmenu.sh -i -p "Notifs"
|
||||
)"
|
||||
picked="$(
|
||||
printf "%b" "$choices" |
|
||||
cut -d^ -f1 |
|
||||
sxmo_dmenu.sh -i -p "Notifs"
|
||||
)"
|
||||
|
||||
case "$picked" in
|
||||
"$icon_cls Close Menu"|"")
|
||||
exit
|
||||
;;
|
||||
"$icon_del Clear Notifications")
|
||||
rm "$SXMO_NOTIFDIR"/*
|
||||
# we must update statusbar here because this function depends
|
||||
# on number of files in $SXMO_NOTIFDIR
|
||||
sxmo_hook_statusbar.sh notifications
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
file="$(
|
||||
printf "%b" "$choices" |
|
||||
grep -F "$picked" |
|
||||
cut -d^ -f2
|
||||
)"
|
||||
group="$(awk NR==1 "$file")"
|
||||
action="$(awk NR==2 "$file")"
|
||||
_clear_notif_group "$group"
|
||||
setsid -f sh -c "$action" > /dev/null 2>&1
|
||||
;;
|
||||
esac
|
||||
case "$picked" in
|
||||
"$icon_cls Close Menu"|"")
|
||||
exit
|
||||
;;
|
||||
"$icon_del Clear Notifications")
|
||||
clear_all
|
||||
exit
|
||||
;;
|
||||
*)
|
||||
file="$(
|
||||
printf "%b" "$choices" |
|
||||
grep -F "$picked" |
|
||||
cut -d^ -f2 |
|
||||
head -n1
|
||||
)"
|
||||
if [ -n "$file" ] && [ -f "$file" ]; then
|
||||
group="$(awk NR==1 "$file" 2>/dev/null)"
|
||||
action="$(awk NR==2 "$file" 2>/dev/null)"
|
||||
_clear_notif_group "$group"
|
||||
rm -f "$file" 2>/dev/null || true
|
||||
dunstctl close-all >/dev/null 2>&1 || true
|
||||
sxmo_hook_statusbar.sh notifications >/dev/null 2>&1 || true
|
||||
if [ -n "$action" ] && [ "$action" != "none" ]; then
|
||||
setsid -f sh -c "$action" > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
new() {
|
||||
while : ; do
|
||||
case "$1" in
|
||||
-i)
|
||||
id="$2"
|
||||
shift 2
|
||||
;;
|
||||
-g)
|
||||
group="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
while : ; do
|
||||
case "$1" in
|
||||
-i)
|
||||
id="$2"
|
||||
shift 2
|
||||
;;
|
||||
-g)
|
||||
group="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
if [ "$#" -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$id" ]; then
|
||||
id="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
|
||||
fi
|
||||
if [ -z "$group" ]; then
|
||||
group="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
|
||||
fi
|
||||
if [ -z "$id" ]; then
|
||||
id="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
|
||||
fi
|
||||
if [ -z "$group" ]; then
|
||||
group="$(tr -dc 'a-zA-Z0-9' < /dev/urandom 2>/dev/null | head -c 10)"
|
||||
fi
|
||||
|
||||
action="$1"
|
||||
msg="$2"
|
||||
action="$1"
|
||||
msg="$2"
|
||||
|
||||
touch "$SXMO_NOTIFDIR/$id"
|
||||
printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$SXMO_NOTIFDIR/$id"
|
||||
mkdir -p "$SXMO_NOTIFDIR"
|
||||
printf "%s\n%s\n%b\n" "$group" "$action" "$msg" > "$SXMO_NOTIFDIR/$id"
|
||||
|
||||
sxmo_hook_statusbar.sh notifications
|
||||
sxmo_hook_statusbar.sh notifications
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
cat <<EOF
|
||||
$(basename "$0"): manage sxmo notifications
|
||||
|
||||
Subcommands:
|
||||
monitor
|
||||
Watch for new notification, dispatch libnotify events, handle actions
|
||||
menu
|
||||
Open a menu to dismiss notifications
|
||||
new [-i id] [-g group] <action> <message...>
|
||||
Register a new notification
|
||||
monitor
|
||||
Watch for new notification, dispatch libnotify events, handle actions
|
||||
menu
|
||||
Open a menu to dismiss notifications
|
||||
clear
|
||||
Clear all notifications and close active Dunst popups
|
||||
new [-i id] [-g group] <action> <message...>
|
||||
Register a new notification
|
||||
EOF
|
||||
}
|
||||
|
||||
cmd="$1"
|
||||
shift
|
||||
shift 2>/dev/null || true
|
||||
case "$cmd" in
|
||||
monitor) monitor "$@";;
|
||||
menu) menu "$@";;
|
||||
new) new "$@";;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
monitor) monitor "$@" ;;
|
||||
menu) menu "$@" ;;
|
||||
clear) clear_all ;;
|
||||
new) new "$@" ;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,7 @@ if [ -r "$CONF_FILE" ]; then
|
||||
. "$CONF_FILE"
|
||||
fi
|
||||
|
||||
SIM_WAIT_TIME="${SIM_WAIT_TIME:-${sim_wait_time:-4}}"
|
||||
SIM_WAIT_TIME="${SIM_WAIT_TIME:-${sim_wait_time:-10}}"
|
||||
PREFERRED_SIM_SLOT="${PREFERRED_SIM_SLOT:-${preferred_sim_slot:-1}}"
|
||||
QMICLI_MODEM=""
|
||||
|
||||
@@ -16,15 +16,25 @@ detect_qmicli_modem() {
|
||||
if ! command -v qmicli >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if [ -e "/dev/modem" ]; then
|
||||
QMICLI_MODEM="qmicli --silent -d /dev/modem"
|
||||
return 0
|
||||
elif [ -e "/dev/wwan0qmi0" ]; then
|
||||
QMICLI_MODEM="qmicli --silent -d /dev/wwan0qmi0 --device-open-qmi"
|
||||
return 0
|
||||
elif qmicli --silent -pd qrtr://0 --uim-noop >/dev/null 2>&1; then
|
||||
if qmicli --silent -pd qrtr://0 --uim-noop >/dev/null 2>&1; then
|
||||
QMICLI_MODEM="qmicli --silent -pd qrtr://0"
|
||||
return 0
|
||||
elif [ -e "/dev/wwan0qmi0" ]; then
|
||||
if qmicli --silent -pd /dev/wwan0qmi0 --device-open-qmi --uim-noop >/dev/null 2>&1; then
|
||||
QMICLI_MODEM="qmicli --silent -pd /dev/wwan0qmi0 --device-open-qmi"
|
||||
return 0
|
||||
elif qmicli --silent -d /dev/wwan0qmi0 --device-open-qmi --uim-noop >/dev/null 2>&1; then
|
||||
QMICLI_MODEM="qmicli --silent -d /dev/wwan0qmi0 --device-open-qmi"
|
||||
return 0
|
||||
fi
|
||||
elif [ -e "/dev/modem" ]; then
|
||||
if qmicli --silent -pd /dev/modem --uim-noop >/dev/null 2>&1; then
|
||||
QMICLI_MODEM="qmicli --silent -pd /dev/modem"
|
||||
return 0
|
||||
elif qmicli --silent -d /dev/modem --uim-noop >/dev/null 2>&1; then
|
||||
QMICLI_MODEM="qmicli --silent -d /dev/modem"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
@@ -64,6 +74,8 @@ parse_uim_card_status() {
|
||||
pin1_state[s] = "not-initialized"
|
||||
pin1_ret[s] = 0
|
||||
puk1_ret[s] = 0
|
||||
want_aid[s] = 0
|
||||
need_aid_line[s] = 0
|
||||
}
|
||||
}
|
||||
/Primary GW:/ {
|
||||
@@ -95,7 +107,7 @@ parse_uim_card_status() {
|
||||
}
|
||||
if (!in_app && $0 ~ /Card state:/) {
|
||||
line = $0
|
||||
sub(/.*Card state: \x27/, "", line)
|
||||
sub(/.*Card state:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
rawstate[cur_slot] = line
|
||||
if (line == "present") cstate[cur_slot] = "present"
|
||||
@@ -104,25 +116,25 @@ parse_uim_card_status() {
|
||||
}
|
||||
if (!in_app && $0 ~ /UPIN state:/) {
|
||||
line = $0
|
||||
sub(/.*UPIN state: \x27/, "", line)
|
||||
sub(/.*UPIN state:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
upin_state[cur_slot] = line
|
||||
}
|
||||
if (!in_app && $0 ~ /UPIN retries:/) {
|
||||
line = $0
|
||||
sub(/.*UPIN retries: \x27/, "", line)
|
||||
sub(/.*UPIN retries:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
upin_ret[cur_slot] = line + 0
|
||||
}
|
||||
if (!in_app && $0 ~ /UPUK retries:/) {
|
||||
line = $0
|
||||
sub(/.*UPUK retries: \x27/, "", line)
|
||||
sub(/.*UPUK retries:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
upuk_ret[cur_slot] = line + 0
|
||||
}
|
||||
if (in_app && $0 ~ /Application type:/) {
|
||||
line = $0
|
||||
sub(/.*Application type: \x27/, "", line)
|
||||
sub(/.*Application type:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
if (line ~ /^usim/) {
|
||||
app_type[cur_slot] = "usim"
|
||||
@@ -130,13 +142,16 @@ parse_uim_card_status() {
|
||||
} else if (line ~ /^sim/ && app_type[cur_slot] != "usim") {
|
||||
app_type[cur_slot] = "sim"
|
||||
want_aid[cur_slot] = 1
|
||||
} else if (app_type[cur_slot] == "none") {
|
||||
app_type[cur_slot] = "sim"
|
||||
want_aid[cur_slot] = 1
|
||||
} else {
|
||||
want_aid[cur_slot] = 0
|
||||
}
|
||||
}
|
||||
if (in_app && $0 ~ /Application state:/ && want_aid[cur_slot] > 0) {
|
||||
line = $0
|
||||
sub(/.*Application state: \x27/, "", line)
|
||||
sub(/.*Application state:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
app_state[cur_slot] = line
|
||||
}
|
||||
@@ -147,26 +162,26 @@ parse_uim_card_status() {
|
||||
if (in_app && need_aid_line[cur_slot] == 1) {
|
||||
line = $0
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", line)
|
||||
if (line != "") {
|
||||
if (line != "" && line !~ /:.*\x27/) {
|
||||
aid[cur_slot] = line
|
||||
}
|
||||
need_aid_line[cur_slot] = 0
|
||||
}
|
||||
if (in_app && $0 ~ /PIN1 state:/ && want_aid[cur_slot] > 0) {
|
||||
line = $0
|
||||
sub(/.*PIN1 state: \x27/, "", line)
|
||||
sub(/.*PIN1 state:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
pin1_state[cur_slot] = line
|
||||
}
|
||||
if (in_app && $0 ~ /PIN1 retries:/ && want_aid[cur_slot] > 0) {
|
||||
line = $0
|
||||
sub(/.*PIN1 retries: \x27/, "", line)
|
||||
sub(/.*PIN1 retries:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
pin1_ret[cur_slot] = line + 0
|
||||
}
|
||||
if (in_app && $0 ~ /PUK1 retries:/ && want_aid[cur_slot] > 0) {
|
||||
line = $0
|
||||
sub(/.*PUK1 retries: \x27/, "", line)
|
||||
sub(/.*PUK1 retries:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
puk1_ret[cur_slot] = line + 0
|
||||
}
|
||||
@@ -192,8 +207,116 @@ parse_uim_card_status() {
|
||||
'
|
||||
}
|
||||
|
||||
parse_nas_serving_system() {
|
||||
raw_nas="$1"
|
||||
printf "%s\n" "$raw_nas" | awk '
|
||||
BEGIN {
|
||||
reg_state = "unknown"
|
||||
cs_state = "unknown"
|
||||
ps_state = "unknown"
|
||||
rat = ""
|
||||
mcc = ""
|
||||
mnc = ""
|
||||
op_desc = ""
|
||||
roam = "off"
|
||||
in_rat = 0
|
||||
in_plmn = 0
|
||||
in_roam = 0
|
||||
}
|
||||
/^[[:space:]]*Registration state:/ {
|
||||
line = $0
|
||||
sub(/.*Registration state:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
reg_state = line
|
||||
in_rat = 0; in_plmn = 0; in_roam = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CS:/ {
|
||||
line = $0
|
||||
sub(/.*CS:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
cs_state = line
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*PS:/ {
|
||||
line = $0
|
||||
sub(/.*PS:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
ps_state = line
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*Radio interfaces:/ {
|
||||
in_rat = 1; in_plmn = 0; in_roam = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*Data service capabilities:/ {
|
||||
in_rat = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*Current PLMN:/ {
|
||||
in_plmn = 1; in_rat = 0; in_roam = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*Roaming indicators:/ {
|
||||
in_roam = 1; in_plmn = 0; in_rat = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*Default roaming status:/ {
|
||||
line = $0
|
||||
sub(/.*Default roaming status:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
roam = line
|
||||
in_roam = 0
|
||||
next
|
||||
}
|
||||
in_rat && /^[[:space:]]*\[[0-9]+\]:/ {
|
||||
line = $0
|
||||
sub(/.*\[[0-9]+\]:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
if (line != "" && line != "none" && rat == "") rat = line
|
||||
}
|
||||
in_plmn && /MCC:/ {
|
||||
line = $0
|
||||
sub(/.*MCC:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
mcc = line
|
||||
}
|
||||
in_plmn && /MNC:/ {
|
||||
line = $0
|
||||
sub(/.*MNC:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
mnc = line
|
||||
}
|
||||
in_plmn && /Description:/ {
|
||||
line = $0
|
||||
sub(/.*Description:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
gsub(/[\r\n\t]/, " ", line)
|
||||
op_desc = line
|
||||
in_plmn = 0
|
||||
}
|
||||
in_roam && /^[[:space:]]*\[[0-9]+\]:/ {
|
||||
line = $0
|
||||
sub(/.*\[[0-9]+\]:[[:space:]]*\x27/, "", line)
|
||||
sub(/\x27.*/, "", line)
|
||||
if (line == "on") roam = "on"
|
||||
}
|
||||
END {
|
||||
printf "NAS_REG_STATE=%s\n", reg_state
|
||||
printf "NAS_CS_STATE=%s\n", cs_state
|
||||
printf "NAS_PS_STATE=%s\n", ps_state
|
||||
printf "NAS_RAT=%s\n", rat
|
||||
printf "NAS_MCC=%s\n", mcc
|
||||
printf "NAS_MNC=%s\n", mnc
|
||||
printf "NAS_OPERATOR=%s\n", op_desc
|
||||
printf "NAS_ROAMING=%s\n", roam
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
save_preferred_slot() {
|
||||
target_slot="$1"
|
||||
PREFERRED_SIM_SLOT="$target_slot"
|
||||
if [ -f "$CONF_FILE" ]; then
|
||||
if grep -q "^preferred_sim_slot=" "$CONF_FILE"; then
|
||||
sed -i "s/^preferred_sim_slot=.*/preferred_sim_slot=$target_slot/" "$CONF_FILE"
|
||||
@@ -201,7 +324,7 @@ save_preferred_slot() {
|
||||
printf "\npreferred_sim_slot=%s\n" "$target_slot" >> "$CONF_FILE"
|
||||
fi
|
||||
else
|
||||
printf "sim_wait_time=4\npreferred_sim_slot=%s\n" "$target_slot" > "$CONF_FILE"
|
||||
printf "sim_wait_time=10\npreferred_sim_slot=%s\n" "$target_slot" > "$CONF_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -214,52 +337,154 @@ provision_slot() {
|
||||
return 2
|
||||
fi
|
||||
|
||||
$QMICLI_MODEM --dms-set-operating-mode=online >/dev/null 2>&1 || true
|
||||
|
||||
QMI_CARDS="$($QMICLI_MODEM --uim-get-card-status 2>/dev/null || true)"
|
||||
count=0
|
||||
while ! printf "%s" "$QMI_CARDS" | grep -Fq "Card state: 'present'"; do
|
||||
while : ; do
|
||||
if [ -n "$QMI_CARDS" ]; then
|
||||
eval "$(parse_uim_card_status "$QMI_CARDS" "$req_slot")"
|
||||
if [ "$req_slot" = "2" ] && [ "$SLOT2_STATE" = "present" ] && [ "$SLOT2_APP_TYPE" != "none" ]; then
|
||||
break
|
||||
elif [ "$req_slot" != "2" ] && [ "$SLOT1_STATE" = "present" ] && [ "$SLOT1_APP_TYPE" != "none" ]; then
|
||||
break
|
||||
elif [ "$count" -ge 3 ] && { { [ "$SLOT1_STATE" = "present" ] && [ "$SLOT1_APP_TYPE" != "none" ]; } || { [ "$SLOT2_STATE" = "present" ] && [ "$SLOT2_APP_TYPE" != "none" ]; }; }; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
if [ "$count" -ge "$SIM_WAIT_TIME" ]; then
|
||||
echo "No SIM detected after $SIM_WAIT_TIME seconds."
|
||||
return 0
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
count=$((count + 1))
|
||||
QMI_CARDS="$($QMICLI_MODEM --uim-get-card-status 2>/dev/null || true)"
|
||||
done
|
||||
|
||||
if [ -z "$QMI_CARDS" ]; then
|
||||
echo "No SIM card status returned."
|
||||
return 0
|
||||
fi
|
||||
|
||||
eval "$(parse_uim_card_status "$QMI_CARDS" "$req_slot")"
|
||||
|
||||
chosen_slot=""
|
||||
chosen_aid=""
|
||||
if [ "$req_slot" = "2" ]; then
|
||||
if [ "$SLOT2_STATE" = "present" ] && [ -n "$SLOT2_AID" ]; then
|
||||
if [ "$SLOT2_STATE" = "present" ]; then
|
||||
chosen_slot="2"
|
||||
chosen_aid="$SLOT2_AID"
|
||||
elif [ "$SLOT1_STATE" = "present" ] && [ -n "$SLOT1_AID" ]; then
|
||||
elif [ "$SLOT1_STATE" = "present" ]; then
|
||||
chosen_slot="1"
|
||||
chosen_aid="$SLOT1_AID"
|
||||
fi
|
||||
else
|
||||
if [ "$SLOT1_STATE" = "present" ] && [ -n "$SLOT1_AID" ]; then
|
||||
if [ "$SLOT1_STATE" = "present" ]; then
|
||||
chosen_slot="1"
|
||||
chosen_aid="$SLOT1_AID"
|
||||
elif [ "$SLOT2_STATE" = "present" ] && [ -n "$SLOT2_AID" ]; then
|
||||
elif [ "$SLOT2_STATE" = "present" ]; then
|
||||
chosen_slot="2"
|
||||
chosen_aid="$SLOT2_AID"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$chosen_slot" ] || [ -z "$chosen_aid" ]; then
|
||||
echo "No valid USIM/SIM application found on any slot."
|
||||
if [ -z "$chosen_slot" ]; then
|
||||
echo "No SIM detected after $SIM_WAIT_TIME seconds."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$PRIMARY_GW_SLOT" != "0" ]; then
|
||||
if [ "$chosen_slot" != "$PREFERRED_SIM_SLOT" ]; then
|
||||
save_preferred_slot "$chosen_slot"
|
||||
fi
|
||||
|
||||
# If already provisioned on the chosen slot and application is ready, keep session intact
|
||||
eval "chosen_app_state=\$SLOT${chosen_slot}_APP_STATE"
|
||||
if [ "$PRIMARY_GW_SLOT" = "$chosen_slot" ] && [ "$chosen_app_state" = "ready" ]; then
|
||||
echo "Slot $chosen_slot already active and ready."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$PRIMARY_GW_SLOT" != "0" ] && [ "$PRIMARY_GW_SLOT" != "$chosen_slot" ]; then
|
||||
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning' >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
echo "Selecting AID $chosen_aid on slot $chosen_slot"
|
||||
$QMICLI_MODEM --uim-change-provisioning-session="slot=$chosen_slot,activate=yes,session-type=primary-gw-provisioning,aid=$chosen_aid" >/dev/null
|
||||
return $?
|
||||
if [ -n "$chosen_aid" ]; then
|
||||
echo "Selecting AID $chosen_aid on slot $chosen_slot"
|
||||
if ! $QMICLI_MODEM --uim-change-provisioning-session="slot=$chosen_slot,activate=yes,session-type=primary-gw-provisioning,aid=$chosen_aid" >/dev/null 2>&1; then
|
||||
$QMICLI_MODEM --uim-change-provisioning-session="slot=$chosen_slot,activate=yes,session-type=primary-gw-provisioning" >/dev/null 2>&1 || true
|
||||
fi
|
||||
else
|
||||
echo "Selecting slot $chosen_slot"
|
||||
$QMICLI_MODEM --uim-change-provisioning-session="slot=$chosen_slot,activate=yes,session-type=primary-gw-provisioning" >/dev/null 2>&1 || true
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
enable_and_register_modem() {
|
||||
target_slot="${1:-$PREFERRED_SIM_SLOT}"
|
||||
if detect_qmicli_modem; then
|
||||
$QMICLI_MODEM --dms-set-operating-mode=online >/dev/null 2>&1 || true
|
||||
$QMICLI_MODEM --nas-initiate-network-register >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
i=0
|
||||
mm_state=""
|
||||
while [ "$i" -lt 12 ]; do
|
||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '/^modem\.generic\.state / {print $2; exit}' || true)"
|
||||
if [ -n "$mm_state" ]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
if [ "$mm_state" = "failed" ]; then
|
||||
if command -v rc-service >/dev/null 2>&1; then
|
||||
rc-service modemmanager restart >/dev/null 2>&1 || true
|
||||
elif command -v systemctl >/dev/null 2>&1; then
|
||||
systemctl restart ModemManager >/dev/null 2>&1 || true
|
||||
fi
|
||||
i=0
|
||||
mm_state=""
|
||||
while [ "$i" -lt 12 ]; do
|
||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '/^modem\.generic\.state / {print $2; exit}' || true)"
|
||||
if [ -n "$mm_state" ] && [ "$mm_state" != "failed" ]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$mm_state" ] || [ "$mm_state" = "locked" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
i=0
|
||||
while [ "$i" -lt 10 ]; do
|
||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '/^modem\.generic\.state / {print $2; exit}' || true)"
|
||||
case "$mm_state" in
|
||||
disabled)
|
||||
mmcli -m any -e >/dev/null 2>&1 || true
|
||||
;;
|
||||
enabled)
|
||||
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
||||
break
|
||||
;;
|
||||
searching|registered|connected|connecting)
|
||||
break
|
||||
;;
|
||||
locked)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
sleep 1
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
||||
if command -v sxmo_hook_statusbar.sh >/dev/null 2>&1; then
|
||||
DISPLAY="${DISPLAY:-:0}" sxmo_hook_statusbar.sh modem >/dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
|
||||
cmd="${1:-boot}"
|
||||
@@ -276,7 +501,8 @@ case "$cmd" in
|
||||
;;
|
||||
esac
|
||||
provision_slot "$PREFERRED_SIM_SLOT" 45
|
||||
exit $?
|
||||
( enable_and_register_modem "$PREFERRED_SIM_SLOT" ) >/dev/null 2>&1 </dev/null &
|
||||
exit 0
|
||||
;;
|
||||
|
||||
status)
|
||||
@@ -293,6 +519,10 @@ case "$cmd" in
|
||||
fi
|
||||
echo "MODEM_AVAILABLE=1"
|
||||
parse_uim_card_status "$QMI_CARDS" "$PREFERRED_SIM_SLOT"
|
||||
QMI_NAS="$($QMICLI_MODEM --nas-get-serving-system 2>/dev/null || true)"
|
||||
if [ -n "$QMI_NAS" ]; then
|
||||
parse_nas_serving_system "$QMI_NAS"
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
|
||||
@@ -303,13 +533,14 @@ case "$cmd" in
|
||||
exit 1
|
||||
fi
|
||||
save_preferred_slot "$target"
|
||||
SIM_WAIT_TIME=2
|
||||
SIM_WAIT_TIME=3
|
||||
provision_slot "$target" 5
|
||||
if command -v rc-service >/dev/null 2>&1; then
|
||||
rc-service modemmanager restart >/dev/null 2>&1 || true
|
||||
elif command -v systemctl >/dev/null 2>&1; then
|
||||
systemctl restart ModemManager >/dev/null 2>&1 || true
|
||||
fi
|
||||
( enable_and_register_modem "$target" ) >/dev/null 2>&1 </dev/null &
|
||||
exit 0
|
||||
;;
|
||||
|
||||
@@ -320,18 +551,27 @@ case "$cmd" in
|
||||
echo "Missing PIN" >&2
|
||||
exit 1
|
||||
fi
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ] && mmcli -i "$sim_id" --pin="$pin" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
verified=0
|
||||
if detect_qmicli_modem; then
|
||||
if $QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if $QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=card-slot-$slot" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
verified=1
|
||||
elif $QMICLI_MODEM --uim-verify-pin="PIN1,$pin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
verified=1
|
||||
fi
|
||||
fi
|
||||
if [ "$verified" = "0" ]; then
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ] && mmcli -i "$sim_id" --pin="$pin" >/dev/null 2>&1; then
|
||||
verified=1
|
||||
fi
|
||||
fi
|
||||
if [ "$verified" = "1" ]; then
|
||||
save_preferred_slot "$slot"
|
||||
SIM_WAIT_TIME=2
|
||||
provision_slot "$slot" 3 >/dev/null 2>&1 || true
|
||||
( enable_and_register_modem "$slot" ) >/dev/null 2>&1 </dev/null &
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
|
||||
@@ -343,18 +583,27 @@ case "$cmd" in
|
||||
echo "Missing PUK or new PIN" >&2
|
||||
exit 1
|
||||
fi
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ] && mmcli -i "$sim_id" --puk="$puk" --pin="$newpin" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
unblocked=0
|
||||
if detect_qmicli_modem; then
|
||||
if $QMICLI_MODEM --uim-unblock-pin="PIN1,$puk,$newpin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if $QMICLI_MODEM --uim-unblock-pin="PIN1,$puk,$newpin,session-type=card-slot-$slot" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
unblocked=1
|
||||
elif $QMICLI_MODEM --uim-unblock-pin="PIN1,$puk,$newpin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
unblocked=1
|
||||
fi
|
||||
fi
|
||||
if [ "$unblocked" = "0" ]; then
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ] && mmcli -i "$sim_id" --puk="$puk" --pin="$newpin" >/dev/null 2>&1; then
|
||||
unblocked=1
|
||||
fi
|
||||
fi
|
||||
if [ "$unblocked" = "1" ]; then
|
||||
save_preferred_slot "$slot"
|
||||
SIM_WAIT_TIME=2
|
||||
provision_slot "$slot" 3 >/dev/null 2>&1 || true
|
||||
( enable_and_register_modem "$slot" ) >/dev/null 2>&1 </dev/null &
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
|
||||
@@ -366,6 +615,14 @@ case "$cmd" in
|
||||
echo "Usage: $0 set-pin-lock <1|2> <enable|disable> <pin>" >&2
|
||||
exit 1
|
||||
fi
|
||||
if detect_qmicli_modem; then
|
||||
if $QMICLI_MODEM --uim-set-pin-protection="PIN1,$mode,$pin,session-type=card-slot-$slot" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if $QMICLI_MODEM --uim-set-pin-protection="PIN1,$mode,$pin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ]; then
|
||||
if [ "$mode" = "enable" ] && mmcli -i "$sim_id" --enable-pin --pin="$pin" >/dev/null 2>&1; then
|
||||
@@ -374,14 +631,6 @@ case "$cmd" in
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if detect_qmicli_modem; then
|
||||
if $QMICLI_MODEM --uim-set-pin-protection="PIN1,$mode,$pin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if $QMICLI_MODEM --uim-set-pin-protection="PIN1,$mode,$pin,session-type=card-slot-$slot" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
|
||||
@@ -393,17 +642,17 @@ case "$cmd" in
|
||||
echo "Usage: $0 change-pin <1|2> <oldpin> <newpin>" >&2
|
||||
exit 1
|
||||
fi
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ] && mmcli -i "$sim_id" --change-pin="$newpin" --pin="$oldpin" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if detect_qmicli_modem; then
|
||||
if $QMICLI_MODEM --uim-change-pin="PIN1,$oldpin,$newpin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if $QMICLI_MODEM --uim-change-pin="PIN1,$oldpin,$newpin,session-type=card-slot-$slot" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
if $QMICLI_MODEM --uim-change-pin="PIN1,$oldpin,$newpin,session-type=primary-gw-provisioning" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
sim_id="$(mmcli -m any 2>/dev/null | grep -oE 'SIM/[0-9]+' | head -n1 | cut -d'/' -f2 || true)"
|
||||
if [ -n "$sim_id" ] && mmcli -i "$sim_id" --change-pin="$newpin" --pin="$oldpin" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
@@ -505,7 +754,12 @@ case "$cmd" in
|
||||
exit 1
|
||||
fi
|
||||
resp=""
|
||||
for candidate in "$port" /dev/wwan0at1 /dev/wwan0at0; do
|
||||
if [ "$PREFERRED_SIM_SLOT" = "2" ]; then
|
||||
at_candidates="$port /dev/wwan0at1 /dev/wwan0at0"
|
||||
else
|
||||
at_candidates="$port /dev/wwan0at0 /dev/wwan0at1"
|
||||
fi
|
||||
for candidate in $at_candidates; do
|
||||
case "$candidate" in
|
||||
wwan0at0|wwan0at1)
|
||||
dev="/dev/$candidate"
|
||||
@@ -518,7 +772,7 @@ case "$cmd" in
|
||||
;;
|
||||
esac
|
||||
if [ -n "$dev" ] && [ -c "$dev" ]; then
|
||||
resp="$(timeout 2 sh -c '
|
||||
resp="$(timeout 3 sh -c '
|
||||
dev="$1"
|
||||
cmd="$2"
|
||||
tmpf="/tmp/at_resp_$$.txt"
|
||||
@@ -528,7 +782,7 @@ case "$cmd" in
|
||||
sleep 0.04
|
||||
printf "%s\r\n" "$cmd" > "$dev" 2>/dev/null || true
|
||||
i=0
|
||||
while [ "$i" -lt 12 ]; do
|
||||
while [ "$i" -lt 16 ]; do
|
||||
if grep -qE "(^|[[:space:]])(OK|ERROR|\+CME ERROR|\+CMS ERROR)([[:space:]]|$)" "$tmpf" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
@@ -558,6 +812,84 @@ case "$cmd" in
|
||||
exit 1
|
||||
;;
|
||||
|
||||
ussd)
|
||||
ussd_mode="${2:-initiate}"
|
||||
shift 2 2>/dev/null || true
|
||||
ussd_code="$*"
|
||||
if [ "$ussd_mode" = "cancel" ]; then
|
||||
mmcli -m any --3gpp-ussd-cancel >/dev/null 2>&1 || true
|
||||
"$0" at auto 'AT+CUSD=2' >/dev/null 2>&1 || true
|
||||
echo "USSD session cancelled."
|
||||
exit 0
|
||||
fi
|
||||
if [ -z "$ussd_code" ]; then
|
||||
echo "ERROR: Empty USSD code"
|
||||
exit 1
|
||||
fi
|
||||
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F': ' '$1 == "modem.generic.state" {print $2; exit}')"
|
||||
if [ "$mm_state" = "disabled" ] || [ -z "$mm_state" ]; then
|
||||
mmcli -m any -e >/dev/null 2>&1 || true
|
||||
sleep 1
|
||||
fi
|
||||
if [ "$ussd_mode" = "respond" ]; then
|
||||
mm_out="$(mmcli -m any --3gpp-ussd-respond="$ussd_code" 2>&1)"
|
||||
mm_rc=$?
|
||||
else
|
||||
mmcli -m any --3gpp-ussd-cancel >/dev/null 2>&1 || true
|
||||
mm_out="$(mmcli -m any --3gpp-ussd-initiate="$ussd_code" 2>&1)"
|
||||
mm_rc=$?
|
||||
fi
|
||||
if [ "$mm_rc" -eq 0 ] && [ -n "$mm_out" ]; then
|
||||
printf "%s\n" "$mm_out" | sed -e "s/^USSD session initiated; new reply from network: '\(.*\)'$/\1/" -e "s/^USSD response sent; new reply from network: '\(.*\)'$/\1/"
|
||||
exit 0
|
||||
fi
|
||||
# Fallback to direct AT+CUSD on the active SIM AT port
|
||||
if [ "$PREFERRED_SIM_SLOT" = "2" ]; then
|
||||
at_candidates="/dev/wwan0at1 /dev/wwan0at0"
|
||||
else
|
||||
at_candidates="/dev/wwan0at0 /dev/wwan0at1"
|
||||
fi
|
||||
for dev in $at_candidates; do
|
||||
[ -c "$dev" ] || continue
|
||||
cusd_out="$(timeout 12 sh -c '
|
||||
dev="$1"
|
||||
code="$2"
|
||||
tmpf="/tmp/ussd_resp_$$.txt"
|
||||
rm -f "$tmpf"
|
||||
cat "$dev" > "$tmpf" 2>/dev/null &
|
||||
rpid=$!
|
||||
sleep 0.05
|
||||
printf "AT+CSCS=\"GSM\";+CUSD=1,\"%s\",15\r\n" "$code" > "$dev" 2>/dev/null || true
|
||||
i=0
|
||||
while [ "$i" -lt 80 ]; do
|
||||
if grep -qE "\+CUSD:[[:space:]]*[0-9]+" "$tmpf" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
if grep -qE "(^|[[:space:]])(\+CME ERROR|\+CMS ERROR|ERROR)([[:space:]]|$)" "$tmpf" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
i=$((i + 1))
|
||||
done
|
||||
kill "$rpid" 2>/dev/null || true
|
||||
wait "$rpid" 2>/dev/null || true
|
||||
tr -d "\r" < "$tmpf" 2>/dev/null || true
|
||||
rm -f "$tmpf"
|
||||
' _ "$dev" "$ussd_code" 2>/dev/null || true)"
|
||||
cusd_msg="$(printf "%s\n" "$cusd_out" | sed -n 's/.*+CUSD:[[:space:]]*[0-9]*,[[:space:]]*"\([^"]*\)".*/\1/p' | tail -n1)"
|
||||
if [ -n "$cusd_msg" ]; then
|
||||
printf "%s\n" "$cusd_msg"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
if [ -n "$mm_out" ]; then
|
||||
printf "%s\n" "$mm_out"
|
||||
else
|
||||
echo "ERROR: USSD request failed"
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
|
||||
sim-contacts-import)
|
||||
req_slot="${2:-auto}"
|
||||
if ! wait_for_qmicli_modem 3; then
|
||||
@@ -688,8 +1020,8 @@ case "$cmd" in
|
||||
# Method 2: Direct QMI UIM EF_ADN (3F00:7F10:6F3A) record fallback
|
||||
if [ ! -s "$tmp_contacts" ]; then
|
||||
adn_attr="$($QMICLI_MODEM --uim-get-file-attributes=0x3F00,0x7F10,0x6F3A 2>/dev/null || true)"
|
||||
reclen="$(printf "%s\n" "$adn_attr" | awk -F"'" '/Record length:/ {print $2 + 0; exit}')"
|
||||
reccount="$(printf "%s\n" "$adn_attr" | awk -F"'" '/Record count:/ {print $2 + 0; exit}')"
|
||||
reclen="$(printf "%s\n" "$adn_attr" | awk '/Record (size|length):/ {gsub(/[^0-9]/, "", $NF); print $NF + 0; exit}')"
|
||||
reccount="$(printf "%s\n" "$adn_attr" | awk '/Record count:/ {gsub(/[^0-9]/, "", $NF); print $NF + 0; exit}')"
|
||||
if [ -n "$reclen" ] && [ -n "$reccount" ] && [ "$reclen" -ge 14 ] 2>/dev/null && [ "$reccount" -ge 1 ] 2>/dev/null; then
|
||||
if [ "$reccount" -gt 250 ]; then
|
||||
reccount=250
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
horizontal_padding = 6
|
||||
frame_width = 2
|
||||
frame_color = "#005577"
|
||||
idle_threshold = 120
|
||||
idle_threshold = 0
|
||||
font = Fira Code 9.5
|
||||
markup = full
|
||||
max_icon_size = 24
|
||||
@@ -22,16 +22,16 @@
|
||||
[urgency_low]
|
||||
background = "#222222"
|
||||
foreground = "#cccccc"
|
||||
timeout = 8
|
||||
timeout = 5
|
||||
|
||||
[urgency_normal]
|
||||
background = "#1c1c1c"
|
||||
foreground = "#ffffff"
|
||||
frame_color = "#005577"
|
||||
timeout = 12
|
||||
timeout = 8
|
||||
|
||||
[urgency_critical]
|
||||
background = "#900000"
|
||||
foreground = "#ffffff"
|
||||
frame_color = "#ff0000"
|
||||
timeout = 0
|
||||
timeout = 10
|
||||
|
||||
@@ -15,22 +15,68 @@ newstate="$2"
|
||||
|
||||
sxmo_debug "$2 (old: $1 [reason: $3])"
|
||||
|
||||
case "$newstate" in
|
||||
"locked")
|
||||
sxmo_log "State is locked. Opening SIM PIN/PUK unlock dialog."
|
||||
open_sim_unlock_ui() {
|
||||
(
|
||||
i=0
|
||||
while [ "$i" -lt 40 ] && [ ! -p /tmp/dwm_plugin_modem.fifo ]; do
|
||||
sleep 0.2
|
||||
i=$((i + 1))
|
||||
done
|
||||
if command -v xmodem >/dev/null 2>&1; then
|
||||
xmodem unlock >/dev/null 2>&1 &
|
||||
DISPLAY="${DISPLAY:-:0}" xmodem unlock >/dev/null 2>&1 &
|
||||
elif ! pgrep -f "sxmo_unlocksim.sh" >/dev/null; then
|
||||
sxmo_unlocksim.sh &
|
||||
fi
|
||||
) &
|
||||
}
|
||||
|
||||
case "$newstate" in
|
||||
"locked")
|
||||
sxmo_log "State is locked. Opening SIM PIN/PUK unlock dialog."
|
||||
open_sim_unlock_ui
|
||||
;;
|
||||
"failed")
|
||||
sxmo_log "State is failed. Checking QMI UIM status for SIM2/PIN lock."
|
||||
(
|
||||
uim_st="$(doas -n /usr/libexec/msm-modem-uim-selection status 2>/dev/null || /usr/libexec/msm-modem-uim-selection status 2>/dev/null || true)"
|
||||
if printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_PIN1_STATE=(enabled-not-verified|blocked)|SLOT[12]_APP_STATE=(pin1|puk1)"; then
|
||||
sxmo_log "QMI UIM reports locked SIM while ModemManager state is failed; opening unlock UI."
|
||||
open_sim_unlock_ui
|
||||
elif printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_STATE=present" && printf "%s\n" "$uim_st" | grep -q "^PRIMARY_GW_SLOT=0$"; then
|
||||
now_ts="$(date +%s 2>/dev/null || echo 0)"
|
||||
last_ts="$(cat /tmp/sxmo_modem_reprov.stamp 2>/dev/null || echo 0)"
|
||||
if [ $((now_ts - last_ts)) -ge 25 ]; then
|
||||
echo "$now_ts" > /tmp/sxmo_modem_reprov.stamp
|
||||
sxmo_log "Unprovisioned SIM detected in failed state; running msm-modem-uim-selection boot."
|
||||
doas -n /usr/libexec/msm-modem-uim-selection boot >/dev/null 2>&1 || true
|
||||
sxmo_hook_statusbar.sh modem >/dev/null 2>&1 || true
|
||||
fi
|
||||
fi
|
||||
) &
|
||||
;;
|
||||
"disabled")
|
||||
sxmo_log "State is disabled. Enabling modem and registering on network."
|
||||
(
|
||||
mmcli -m any -e >/dev/null 2>&1 || true
|
||||
sleep 1
|
||||
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
||||
sxmo_hook_statusbar.sh modem >/dev/null 2>&1 || true
|
||||
) &
|
||||
;;
|
||||
"enabling")
|
||||
sxmo_log "State is enabling. Clearing stale call files."
|
||||
rm "$XDG_RUNTIME_DIR"/sxmo_calls/* 2>/dev/null || true
|
||||
rm -f "$SXMO_NOTIFDIR"/incomingcall* 2>/dev/null || true
|
||||
;;
|
||||
"registered")
|
||||
sxmo_log "State is registered. Checking for calls and messages."
|
||||
"enabled")
|
||||
sxmo_log "State is enabled. Requesting 3GPP network registration."
|
||||
(
|
||||
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
|
||||
sxmo_hook_statusbar.sh modem >/dev/null 2>&1 || true
|
||||
) &
|
||||
;;
|
||||
"registered"|"connected")
|
||||
sxmo_log "State is $newstate. Checking for calls and messages."
|
||||
|
||||
# kill the pin-entry dmenu if still open
|
||||
pkill -f sxmo_unlocksim.sh 2>/dev/null || true
|
||||
|
||||
@@ -59,6 +59,13 @@ set_modem() {
|
||||
MODEMSTATE="$(printf %s "$MMCLI" | jq -r .modem.generic.state)"
|
||||
fi
|
||||
|
||||
if [ "$MODEMSTATE" = "failed" ] || [ "$MODEMSTATE" = "nomodem" ]; then
|
||||
uim_st="$(doas -n /usr/libexec/msm-modem-uim-selection status 2>/dev/null || /usr/libexec/msm-modem-uim-selection status 2>/dev/null || true)"
|
||||
if printf "%s\n" "$uim_st" | grep -qE "SLOT[12]_PIN1_STATE=(enabled-not-verified|blocked)|SLOT[12]_APP_STATE=(pin1|puk1)"; then
|
||||
MODEMSTATE="locked"
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$MODEMSTATE" in
|
||||
nomodem)
|
||||
fgcolor=red
|
||||
@@ -119,7 +126,7 @@ set_modem() {
|
||||
sxmobar -a -f "$fgcolor" -b "$bgcolor" -t "$style" \
|
||||
modem-state 10 "$MODEMSTATECMP"
|
||||
|
||||
if [ "$MODEMSTATE" = nomodem ]; then
|
||||
if [ "$MODEMSTATE" = nomodem ] || [ "$MODEMSTATE" = locked ] || [ "$MODEMSTATE" = failed ] || [ "$MODEMSTATE" = unknown ]; then
|
||||
sxmobar -d modem-tech
|
||||
sxmobar -d modem-signal
|
||||
return
|
||||
@@ -131,7 +138,7 @@ set_modem() {
|
||||
style=normal
|
||||
|
||||
# see https://www.freedesktop.org/software/ModemManager/api/latest/ModemManager-Flags-and-Enumerations.html#MMModemAccessTechnology
|
||||
USEDTECHS="$(printf %s "$MMCLI" | jq -r '.modem.generic."access-technologies"[]')"
|
||||
USEDTECHS="$(printf %s "$MMCLI" | jq -r '.modem.generic."access-technologies"[]? // empty' 2>/dev/null)"
|
||||
case "$USEDTECHS" in
|
||||
*5gnr*)
|
||||
MODEMTECHCMP="$icon_modem_fiveg"
|
||||
@@ -178,7 +185,10 @@ set_modem() {
|
||||
|
||||
case "$MODEMSTATE" in
|
||||
registered|connected|connecting|disconnecting)
|
||||
MODEMSIGNAL="$(printf %s "$MMCLI" | jq -r '.modem.generic."signal-quality".value')"
|
||||
MODEMSIGNAL="$(printf %s "$MMCLI" | jq -r '.modem.generic."signal-quality".value // 0' 2>/dev/null)"
|
||||
case "$MODEMSIGNAL" in
|
||||
''|*[!0-9]*) MODEMSIGNAL=0 ;;
|
||||
esac
|
||||
if [ "$MODEMSIGNAL" -lt 33 ]; then
|
||||
MODEMSIGNALCMP="$icon_modem_signal_1"
|
||||
elif [ "$MODEMSIGNAL" -lt 66 ]; then
|
||||
|
||||
Reference in New Issue
Block a user