Fix instant QMI call hangup, eliminate post-call dialer/callscreen popups and desktop clock flicker

This commit is contained in:
Luxferre committed 2026-11-05 09:51:53 +02:00
1 parent 1d71bc81d8
commit c9c870c3bb
27 files changed
+867 -308

No files matched your search

Binary file not shown.
+1 -5
View File
@@ -60,25 +60,21 @@ checkforfinishedcalls() {
if [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.discardedcall" ]; then
#this call was discarded
STATE=discarded
sxmo_notify_user.sh "Call with $CONTACT terminated"
stderr "Discarded call from $FINISHEDNUMBER"
printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv"
elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.pickedupcall" ]; then
#this call was picked up
STATE=pickedup
sxmo_notify_user.sh "Call with $CONTACT terminated"
stderr "Finished call from $FINISHEDNUMBER"
printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv"
elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.hangedupcall" ]; then
elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.hangedupcall" ] || [ -f /tmp/sxmo_hangup_requested ]; then
#this call was hung up by the user
STATE=wehangedup
sxmo_notify_user.sh "Call with $CONTACT terminated"
stderr "Finished call from $FINISHEDNUMBER"
printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv"
elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.initiatedcall" ]; then
STATE=theyhangedup
#this call was hung up by the contact
sxmo_notify_user.sh "Call with $CONTACT terminated"
stderr "Finished call from $FINISHEDNUMBER"
printf %b "$TIME\tcall_finished\t$FINISHEDNUMBER\n" >> "$SXMO_LOGDIR/modemlog.tsv"
elif [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${FINISHEDCALLID}.blockedcall" ]; then
+41 -23
View File
@@ -41,6 +41,8 @@ switch_bt_card_a2dp() {
}
enable_call_audio_mode() {
exec 9>/tmp/sxmo_modemaudio.lock
flock -x 9
printf "1\n" > /tmp/sxmo_in_call 2>/dev/null || true
cur_out="$(sxmo_audio.sh device get 2>/dev/null || printf "Speaker")"
@@ -56,13 +58,15 @@ enable_call_audio_mode() {
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
sxmo_audio.sh device setinput Bluetooth >/dev/null 2>&1 || true
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cset "name='INT_BT_SCO_RX Audio Mixer MultiMedia1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='INT_BT_SCO_RX Voice Mixer VoiceMMode1'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX'" 1 >/dev/null 2>&1 || true
amixer -c 0 -s >/dev/null 2>&1 <<'EOF' || true
cset name='INT_BT_SCO_RX Audio Mixer MultiMedia1' 0
cset name='MultiMedia2 Mixer INT_BT_SCO_TX' 0
cset name='MultiMedia2 Mixer TERT_MI2S_TX' 0
cset name='PRI_MI2S_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer TERT_MI2S_TX' 0
cset name='INT_BT_SCO_RX Voice Mixer VoiceMMode1' 1
cset name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX' 1
EOF
fi
else
if [ "$jack_plugged" = "1" ] || [ "$cur_out" = "Headphones" ]; then
@@ -72,21 +76,28 @@ enable_call_audio_mode() {
fi
sxmo_audio.sh device set "$target_out" >/dev/null 2>&1 || true
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cset "name='INT_BT_SCO_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='RX1 Mute Switch'" 0 >/dev/null 2>&1 || true
amixer -c 0 -s >/dev/null 2>&1 <<'EOF' || true
cset name='INT_BT_SCO_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX' 0
cset name='PRI_MI2S_RX Voice Mixer VoiceMMode1' 1
cset name='VoiceMMode1 Capture Mixer TERT_MI2S_TX' 1
cset name='MultiMedia2 Mixer TERT_MI2S_TX' 0
cset name='RX1 Mute Switch' 0
EOF
fi
fi
sxmo_log "Enabled ALSA voice call audio mode ($target_out)."
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
return 0
}
disable_call_audio_mode() {
exec 9>/tmp/sxmo_modemaudio.lock
flock -x 9
if [ ! -e /tmp/sxmo_in_call ]; then
rm -f /tmp/sxmo_call_vol 2>/dev/null || true
return 0
fi
rm -f /tmp/sxmo_in_call /tmp/sxmo_call_vol 2>/dev/null || true
bt_card="$(find_bt_card)"
@@ -96,18 +107,26 @@ disable_call_audio_mode() {
fi
if command -v amixer >/dev/null 2>&1; then
amixer -c 0 cset "name='INT_BT_SCO_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='PRI_MI2S_RX Voice Mixer VoiceMMode1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='VoiceMMode1 Capture Mixer TERT_MI2S_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='INT_BT_SCO_RX Audio Mixer MultiMedia1'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer INT_BT_SCO_TX'" 0 >/dev/null 2>&1 || true
amixer -c 0 cset "name='PRI_MI2S_RX Audio Mixer MultiMedia1'" 1 >/dev/null 2>&1 || true
amixer -c 0 cset "name='MultiMedia2 Mixer TERT_MI2S_TX'" 1 >/dev/null 2>&1 || true
amixer -c 0 -s >/dev/null 2>&1 <<'EOF' || true
cset name='INT_BT_SCO_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer INT_BT_SCO_TX' 0
cset name='PRI_MI2S_RX Voice Mixer VoiceMMode1' 0
cset name='VoiceMMode1 Capture Mixer TERT_MI2S_TX' 0
cset name='INT_BT_SCO_RX Audio Mixer MultiMedia1' 0
cset name='MultiMedia2 Mixer INT_BT_SCO_TX' 0
cset name='PRI_MI2S_RX Audio Mixer MultiMedia1' 1
cset name='MultiMedia2 Mixer TERT_MI2S_TX' 1
EOF
fi
if [ -n "$bt_card" ]; then
target_out="Bluetooth"
if [ -r /tmp/sxmo_bt_sco_keepalive.pid ]; then
read -r kpid < /tmp/sxmo_bt_sco_keepalive.pid 2>/dev/null || kpid=""
rm -f /tmp/sxmo_bt_sco_keepalive.pid 2>/dev/null || true
[ -n "$kpid" ] && kill -TERM "$kpid" 2>/dev/null || true
fi
pkill -TERM -f "pacat --playback --device=bluez_output" 2>/dev/null || true
switch_bt_card_a2dp "$bt_card" || true
sxmo_audio.sh device setinput Mic1 >/dev/null 2>&1 || true
sxmo_audio.sh device set Bluetooth >/dev/null 2>&1 || true
@@ -122,7 +141,6 @@ disable_call_audio_mode() {
fi
sxmo_log "Disabled ALSA voice call audio mode ($target_out)."
sxmo_hook_statusbar.sh volume >/dev/null 2>&1 || true
return 0
}
+16 -4
View File
@@ -132,13 +132,25 @@ pickup() {
hangup() {
CALLID="${1:-all}"
touch /tmp/sxmo_hangup_requested 2>/dev/null || true
pkill -TERM -f sxmo_modemdial.sh 2>/dev/null || true
case "$CALLID" in
""|"-"|"all")
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/"* /tmp/sxmo_call_ringing /tmp/sxmo_active_call 2>/dev/null || true
mmcli -m any --voice-hangup-all >/dev/null 2>&1 || true
for f in "$XDG_RUNTIME_DIR"/sxmo_calls/*.initiatedcall "$XDG_RUNTIME_DIR"/sxmo_calls/*.pickedupcall; do
[ -e "$f" ] || continue
base="${f%.*}"
rm -f "$f" 2>/dev/null || true
touch "${base}.hangedupcall" 2>/dev/null || true
done
rm -f "$XDG_RUNTIME_DIR"/sxmo_calls/sub1_* "$XDG_RUNTIME_DIR"/sxmo_calls/sub0_* /tmp/sxmo_call_ringing /tmp/sxmo_active_call 2>/dev/null || true
doas -n /usr/libexec/msm-modem-uim-selection call-hangup all >/dev/null 2>&1 || \
/usr/libexec/msm-modem-uim-selection call-hangup all >/dev/null 2>&1 || true
mmcli -m any --voice-hangup-all >/dev/null 2>&1 || true
for cid in $(mmcli -m any --voice-list-calls 2>/dev/null | grep -oE 'Call/[0-9]+' | cut -d/ -f2); do
mmcli -m any -o "$cid" --hangup >/dev/null 2>&1 || true
mmcli -m any --voice-delete-call="$cid" >/dev/null 2>&1 || true
done
doas -n dbus-send --system --type=signal / org.ofono.VoiceCallManager.CallRemoved >/dev/null 2>&1 || true
sxmo_hook_hangup.sh || true
return 0
@@ -176,6 +188,7 @@ hangup() {
! mmcli -m any --voice-hangup-all 2>/dev/null && \
! doas -n /usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1 && \
! doas -n /usr/libexec/msm-modem-uim-selection call-hangup all >/dev/null 2>&1; then
mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true
# we ignore already closed calls
if list_active_calls | grep -q "/$CALLID "; then
HANGUP_FAILED=1
@@ -203,6 +216,7 @@ list_active_calls() {
mmcli -m any --voice-list-calls 2>/dev/null | \
awk '$1=$1' | \
grep -v terminated | \
grep -v "(unknown)" | \
grep -v "No calls were found" | while read -r line; do
CALLID="$(printf "%s\n" "$line" | awk '$1=$1' | cut -d" " -f1 | xargs basename)"
if [ -e "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.mutedring" ]; then
@@ -242,8 +256,6 @@ incall_menu() {
xcallscreen active "$CALLID" "$NUMBER" >/dev/null 2>&1 || true
;;
esac
else
xcallscreen >/dev/null 2>&1 || true
fi
return 0
fi
+90 -59
View File
@@ -19,7 +19,13 @@ if [ "${1:-}" = "--sim" ] && [ -n "${2:-}" ]; then
fi
resolve_sim_state() {
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)"
UIM_ST=""
if [ -r /tmp/sxmo_sim_slots ]; then
UIM_ST="$(cat /tmp/sxmo_sim_slots 2>/dev/null || true)"
fi
if [ -z "$UIM_ST" ]; then
UIM_ST="$(doas -n /usr/libexec/msm-modem-uim-selection slots 2>/dev/null || /usr/libexec/msm-modem-uim-selection slots 2>/dev/null || true)"
fi
PRIM_SLOT="$(printf "%s\n" "$UIM_ST" | awk -F= '/^PRIMARY_GW_SLOT=/ {print $2; exit}')"
SEC_SLOT="$(printf "%s\n" "$UIM_ST" | awk -F= '/^SECONDARY_GW_SLOT=/ {print $2; exit}')"
PREF_SLOT="$(printf "%s\n" "$UIM_ST" | awk -F= '/^PREFERRED_SLOT=/ {print $2; exit}')"
@@ -31,24 +37,29 @@ resolve_sim_state() {
}
dial_number() {
# on pinephone if you attempt to make a call while in a call, modem crashes
if sxmo_modemcall.sh list_active_calls | grep -q .; then
sxmo_notify_user.sh "Cannot make call while in a call (for now)."
return 0
fi
NUMBER="$(printf "%s" "$1" | tr -cd '+0-9*#')"
if [ -z "$NUMBER" ]; then
return 1
fi
rm -f /tmp/sxmo_hangup_requested 2>/dev/null || true
# on pinephone if you attempt to make a call while in a call, modem crashes
if [ "$(cat /tmp/sxmo_active_call 2>/dev/null)" = "1" ] && sxmo_modemcall.sh list_active_calls | grep -q .; then
sxmo_notify_user.sh "Cannot make call while in a call (for now)."
return 0
fi
resolve_sim_state
[ -f /tmp/sxmo_hangup_requested ] && return 0
TARGET_SIM="$REQ_SIM_SLOT"
# If 2 SIMs are active and no SIM was chosen yet, prompt via xcallscreen
if [ -z "$TARGET_SIM" ] && [ "$DUAL_ACTIVE" = "1" ]; then
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ] && command -v xcallscreen >/dev/null 2>&1; then
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "PROMPT_SIM %s\n" "$NUMBER" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
return 0
elif command -v xcallscreen >/dev/null 2>&1; then
xcallscreen >/dev/null 2>&1 || true
return 0
fi
@@ -65,39 +76,32 @@ dial_number() {
xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true
fi
if ! CALLID="$(doas -n /usr/libexec/msm-modem-uim-selection call-dial "$TARGET_SIM" "$NUMBER" 2>/dev/null || /usr/libexec/msm-modem-uim-selection call-dial "$TARGET_SIM" "$NUMBER" 2>/dev/null)"; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
if [ ! -f /tmp/sxmo_hangup_requested ]; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
fi
sxmo_notify_user.sh --urgency=critical "We failed to initiate call on SIM $TARGET_SIM"
return 1
fi
sxmo_notify_user.sh --urgency=critical "We failed to initiate call on SIM $TARGET_SIM"
return 1
return 0
fi
if [ -f /tmp/sxmo_hangup_requested ]; then
doas -n /usr/libexec/msm-modem-uim-selection call-hangup "$CALLID" >/dev/null 2>&1 || true
return 0
fi
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.terminated" \
"$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.hangedupcall" \
"$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.discardedcall" 2>/dev/null || true
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.initiatedcall"
doas -n dbus-send --system --type=signal / org.ofono.VoiceCallManager.CallAdded >/dev/null 2>&1 || true
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
fi
sxmo_hook_dial.sh || true
sxmo_modemaudio.sh setup_audio || true
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
if [ -f "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.active" ]; then
printf "ACTIVE %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
else
printf "OUTGOING %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
fi
elif command -v xcallscreen >/dev/null 2>&1; then
xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true
fi
sxmo_hook_statusbar.sh state &
return 0
fi
mm_state="$(mmcli -m any -K 2>/dev/null | awk -F':[[:space:]]*' '{gsub(/[[:space:]]+$/, "", $1); if ($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 (SIM $TARGET_SIM): $NUMBER"
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING - %s SIM%s\n" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
@@ -105,20 +109,42 @@ dial_number() {
xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true
fi
if ! CALLID="$(
CALLID="$(
mmcli -m any --voice-create-call="number=$NUMBER" 2>/dev/null |
grep -Eo "Call/[0-9]+" |
grep -oE "[0-9]+"
)"; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
grep -oE "[0-9]+" || true
)"
if [ -z "$CALLID" ]; then
mmcli -m any -e >/dev/null 2>&1 || true
mmcli -m any --3gpp-register-home >/dev/null 2>&1 || true
sleep 1
[ -f /tmp/sxmo_hangup_requested ] && return 0
CALLID="$(
mmcli -m any --voice-create-call="number=$NUMBER" 2>/dev/null |
grep -Eo "Call/[0-9]+" |
grep -oE "[0-9]+" || true
)"
fi
if [ -z "$CALLID" ]; then
if [ ! -f /tmp/sxmo_hangup_requested ]; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
fi
sxmo_notify_user.sh --urgency=critical "We failed to initiate call"
return 1
fi
sxmo_notify_user.sh --urgency=critical "We failed to initiate call"
return 1
return 0
fi
if [ -f /tmp/sxmo_hangup_requested ]; then
mmcli -m any -o "$CALLID" --hangup >/dev/null 2>&1 || true
mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true
return 0
fi
# cleanup all dangling event files, ignore errors
rm "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true
touch "$XDG_RUNTIME_DIR/sxmo_calls/${CALLID}.initiatedcall"
sxmo_log "Starting call with CALLID: $CALLID"
if [ -p "/tmp/dwm_plugin_callscreen.fifo" ]; then
printf "OUTGOING %s %s SIM%s\n" "$CALLID" "$NUMBER" "$TARGET_SIM" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true
@@ -126,30 +152,35 @@ dial_number() {
xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true
fi
if ! mmcli -m any -o "$CALLID" --start >/dev/null 2>&1; then
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true
mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true
if [ ! -f /tmp/sxmo_hangup_requested ]; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
fi
sxmo_notify_user.sh --urgency=critical "We failed to start the call"
return 1
fi
return 0
fi
if [ -f /tmp/sxmo_hangup_requested ]; then
mmcli -m any -o "$CALLID" --hangup >/dev/null 2>&1 || true
mmcli -m any --voice-delete-call="$CALLID" >/dev/null 2>&1 || true
rm -f "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true
return 0
fi
{
mkdir -p "$SXMO_LOGDIR" &&
printf "%s\tcall_start\t%s\t[SIM %s]\n" "$(date +%FT%H:%M:%S%z)" "$NUMBER" "$TARGET_SIM" >> "$SXMO_LOGDIR/modemlog.tsv"
} 2>/dev/null || true
sxmo_log "Invoking dial hook"
sxmo_hook_dial.sh
if ! sxmo_modemaudio.sh setup_audio; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
fi
sxmo_notify_user.sh --urgency=critical "We failed to setup call audio"
mmcli -m any --voice-delete-call="$CALLID"
return 1
fi
if ! sxmo_modemcall.sh pickup "$CALLID"; then
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
fi
sxmo_modemaudio.sh reset_audio
mmcli -m any --voice-delete-call="$CALLID"
return 1
fi
sxmo_hook_dial.sh || true
sxmo_modemaudio.sh setup_audio || true
sxmo_hook_statusbar.sh state &
sxmo_jobs.sh start incall_menu sxmo_modemcall.sh incall_menu
}
dial_ussd() {
+4 -1
View File
@@ -70,8 +70,11 @@ mainloop() {
fi
while : ; do
if [ "$(cat /tmp/sxmo_dsds_active 2>/dev/null || echo 0)" = "1" ]; then
doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || \
if command -v doas >/dev/null 2>&1; then
doas -n /usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
else
/usr/libexec/msm-modem-uim-selection dsds-daemon 2>/dev/null || true
fi
sleep 10
else
sleep 120
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -74,12 +74,12 @@ detect_qmicli_modem() {
return 0
fi
fi
if timeout 3 qmicli --silent -pd qrtr://0 --uim-noop >/dev/null 2>&1; then
QMICLI_MODEM="timeout 4 qmicli --silent -pd qrtr://0"
return 0
elif timeout 3 qmicli --silent -d qrtr://0 --uim-noop >/dev/null 2>&1; then
if timeout 3 qmicli --silent -d qrtr://0 --uim-noop >/dev/null 2>&1; then
QMICLI_MODEM="timeout 4 qmicli --silent -d qrtr://0"
return 0
elif timeout 3 qmicli --silent -pd qrtr://0 --uim-noop >/dev/null 2>&1; then
QMICLI_MODEM="timeout 4 qmicli --silent -pd qrtr://0"
return 0
elif [ -e "/dev/modem" ]; then
if timeout 3 qmicli --silent -pd /dev/modem --uim-noop >/dev/null 2>&1; then
QMICLI_MODEM="timeout 4 qmicli --silent -pd /dev/modem"
@@ -938,7 +938,7 @@ PY
fi
SIM_WAIT_TIME=2
provision_slot "$target" 4
pkill -f "msm-modem-uim-selection dsds-daemon" 2>/dev/null || true
pkill -f "dsds-daemon" 2>/dev/null || true
if [ "${3:-}" = "--swap-gw" ]; then
spawn_enable_and_register "$target" 2
else
@@ -1929,22 +1929,108 @@ PY
exit $?
;;
slots)
python3 - "$PREFERRED_SIM_SLOT" << 'PY'
import select, socket, struct, sys
pref_slot = int(sys.argv[1]) if len(sys.argv) > 1 and sys.argv[1].isdigit() else 1
prim_slot = pref_slot
sec_slot = 0
slot1_present = 0
slot2_present = 0
AF_QIPCRTR = 42
QRTR_PORT_CTRL = 0xfffffffe
QRTR_TYPE_NEW_SERVER = 4
QRTR_TYPE_NEW_LOOKUP = 10
QMI_SERVICE_UIM = 11
try:
ls = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
node, _ = ls.getsockname()
ls.sendto(struct.pack("<IIIII", QRTR_TYPE_NEW_LOOKUP, QMI_SERVICE_UIM, 0, 0, 0), (node, QRTR_PORT_CTRL))
u_addr = None
while True:
r, _, _ = select.select([ls], [], [], 0.08)
if not r:
break
data, _ = ls.recvfrom(256)
if len(data) >= 20:
cmd, srv, inst, srv_node, srv_port = struct.unpack("<IIIII", data[:20])
if cmd == QRTR_TYPE_NEW_SERVER:
if srv == QMI_SERVICE_UIM and srv_port != 0:
u_addr = (srv_node, srv_port)
if srv == 0 and srv_node == 0 and srv_port == 0:
break
ls.close()
if u_addr:
us = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
us.sendto(struct.pack("<BHHH", 0x00, 1, 0x002F, 0), u_addr)
r, _, _ = select.select([us], [], [], 0.1)
if r:
resp, _ = us.recvfrom(2048)
pos = 7
while pos + 3 <= len(resp):
tt, tl = struct.unpack("<BH", resp[pos:pos+3])
pos += 3
val = resp[pos:pos+tl]
pos += tl
if tt == 0x10 and len(val) >= 9:
gw_pri, _, gw_sec, _ = struct.unpack("<HHHH", val[:8])
if gw_pri != 0xFFFF:
prim_slot = ((gw_pri >> 8) & 0xFF) + 1
if gw_sec != 0xFFFF:
sec_slot = ((gw_sec >> 8) & 0xFF) + 1
num_slots = val[8]
off = 9
for s in range(min(num_slots, 2)):
if off + 6 > len(val):
break
cstate = val[off]
if s == 0 and cstate == 1:
slot1_present = 1
elif s == 1 and cstate == 1:
slot2_present = 1
num_apps = val[off + 5]
off += 6
for _ in range(num_apps):
if off + 7 > len(val):
break
aid_len = val[off + 6]
if off + 14 + aid_len > len(val):
break
off += 14 + aid_len
us.close()
except Exception:
pass
dual_active = 1 if (slot1_present and slot2_present and prim_slot in (1, 2) and sec_slot in (1, 2)) else 0
out = (
f"PREFERRED_SLOT={pref_slot}\n"
f"PRIMARY_GW_SLOT={prim_slot}\n"
f"SECONDARY_GW_SLOT={sec_slot}\n"
f"SLOT1_PRESENT={slot1_present}\n"
f"SLOT2_PRESENT={slot2_present}\n"
f"DUAL_SIM_ACTIVE={dual_active}\n"
)
sys.stdout.write(out)
try:
with open("/tmp/sxmo_sim_slots", "w") as f:
f.write(out)
except Exception:
pass
PY
exit 0
;;
call-dial|call-accept|call-hangup|call-dtmf|call-list)
sub_cmd="$cmd"
arg1="${2:-}"
arg2="${3:-}"
prim_slot="$PREFERRED_SIM_SLOT"
sec_slot="0"
if detect_qmicli_modem; then
QMI_CARDS="$($QMICLI_MODEM --uim-get-card-status 2>/dev/null || true)"
if [ -n "$QMI_CARDS" ]; then
eval "$(parse_uim_card_status "$QMI_CARDS" "$PREFERRED_SIM_SLOT")"
prim_slot="${PRIMARY_GW_SLOT:-$PREFERRED_SIM_SLOT}"
sec_slot="${SECONDARY_GW_SLOT:-0}"
fi
fi
python3 - "$sub_cmd" "$arg1" "$arg2" "$prim_slot" "$sec_slot" << 'PY'
import os, select, socket, struct, sys
import os, select, socket, struct, sys, time
sub_cmd = sys.argv[1]
arg1 = sys.argv[2]
@@ -1957,27 +2043,57 @@ QRTR_PORT_CTRL = 0xfffffffe
QRTR_TYPE_NEW_SERVER = 4
QRTR_TYPE_NEW_LOOKUP = 10
QMI_SERVICE_VOICE = 9
QMI_SERVICE_UIM = 11
ls = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
node, _ = ls.getsockname()
ls.sendto(struct.pack("<IIIII", QRTR_TYPE_NEW_LOOKUP, QMI_SERVICE_VOICE, 0, 0, 0), (node, QRTR_PORT_CTRL))
v_addr = None
while True:
r, _, _ = select.select([ls], [], [], 0.15)
if not r:
break
data, _ = ls.recvfrom(256)
if len(data) >= 20:
cmd, srv, inst, srv_node, srv_port = struct.unpack("<IIIII", data[:20])
if cmd == QRTR_TYPE_NEW_SERVER:
if srv == QMI_SERVICE_VOICE and srv_port != 0:
v_addr = (srv_node, srv_port)
if srv == 0 and srv_node == 0 and srv_port == 0:
break
ls.close()
def lookup_qmi_service(srv_id):
ls = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
node, _ = ls.getsockname()
ls.sendto(struct.pack("<IIIII", QRTR_TYPE_NEW_LOOKUP, srv_id, 0, 0, 0), (node, QRTR_PORT_CTRL))
addr = None
while True:
r, _, _ = select.select([ls], [], [], 0.08)
if not r:
break
data, _ = ls.recvfrom(256)
if len(data) >= 20:
cmd, srv, inst, srv_node, srv_port = struct.unpack("<IIIII", data[:20])
if cmd == QRTR_TYPE_NEW_SERVER:
if srv == srv_id and srv_port != 0:
addr = (srv_node, srv_port)
if srv == 0 and srv_node == 0 and srv_port == 0:
break
ls.close()
return addr
v_addr = lookup_qmi_service(QMI_SERVICE_VOICE)
if not v_addr:
sys.exit(1)
if sub_cmd in ("call-dial", "call-list"):
u_addr = lookup_qmi_service(QMI_SERVICE_UIM)
if u_addr:
try:
us = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
us.sendto(struct.pack("<BHHH", 0x00, 1, 0x002F, 0), u_addr)
r, _, _ = select.select([us], [], [], 0.08)
if r:
resp, _ = us.recvfrom(2048)
pos = 7
while pos + 3 <= len(resp):
tt, tl = struct.unpack("<BH", resp[pos:pos+3])
pos += 3
val = resp[pos:pos+tl]
pos += tl
if tt == 0x10 and len(val) >= 8:
gw_pri, _, gw_sec, _ = struct.unpack("<HHHH", val[:8])
if gw_pri != 0xFFFF:
prim_slot = ((gw_pri >> 8) & 0xFF) + 1
if gw_sec != 0xFFFF:
sec_slot = ((gw_sec >> 8) & 0xFF) + 1
us.close()
except Exception:
pass
def parse_tlvs(resp):
res = {}
pos = 7
@@ -2040,7 +2156,15 @@ STATE_MAP = {
10: "setup",
}
def is_hangup_requested():
try:
return (time.time() - os.path.getmtime("/tmp/sxmo_hangup_requested")) < 3.5
except Exception:
return False
if sub_cmd == "call-dial":
if is_hangup_requested():
sys.exit(1)
req_slot = int(arg1) if arg1.isdigit() else prim_slot
sub = 1 if (req_slot == sec_slot and sec_slot != 0) else 0
num = "".join(c for c in arg2 if c in "+0123456789*#").encode("ascii")
@@ -2057,12 +2181,21 @@ if sub_cmd == "call-dial":
s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
qmi_req(s, 1, 0x0044, struct.pack("<BHB", 0x01, 1, sub))
tlvs = qmi_req(s, 2, 0x0020, struct.pack("<BH", 0x01, len(num)) + num, timeout=5.0)
s.close()
res_tlv = tlvs.get(0x02, b"")
cid = tlvs.get(0x10, b"\x01")[0]
if is_hangup_requested():
qmi_req(s, 3, 0x0021, struct.pack("<BHB", 0x01, 1, cid), timeout=0.5)
s.close()
try:
if os.path.exists(dial_marker):
os.remove(dial_marker)
except Exception:
pass
sys.exit(1)
s.close()
if len(res_tlv) >= 4 and struct.unpack("<HH", res_tlv[:4]) == (0, 0):
import subprocess
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallAdded"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
cid = tlvs.get(0x10, b"\x01")[0]
prefix = f"sub{sub}_"
try:
cid_marker = os.path.join(calls_dir, f"{prefix}{cid}.initiatedcall")
@@ -2088,17 +2221,25 @@ elif sub_cmd in ("call-accept", "call-hangup", "call-dtmf"):
txn = 1
for sub in (1, 0):
s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
qmi_req(s, txn, 0x0044, struct.pack("<BHB", 0x01, 1, sub))
qmi_req(s, txn, 0x0044, struct.pack("<BHB", 0x01, 1, sub), timeout=0.4)
txn += 1
calls = parse_call_info(qmi_req(s, txn, 0x002F))
calls = parse_call_info(qmi_req(s, txn, 0x002F, timeout=0.5))
txn += 1
ended_on_sub = False
for cid, c in calls.items():
if c["state"] not in (8, 9):
tlvs = qmi_req(s, txn, 0x0021, struct.pack("<BHB", 0x01, 1, cid))
tlvs = qmi_req(s, txn, 0x0021, struct.pack("<BHB", 0x01, 1, cid), timeout=0.5)
txn += 1
ended_on_sub = True
res_tlv = tlvs.get(0x02, b"")
if len(res_tlv) >= 4 and struct.unpack("<HH", res_tlv[:4]) == (0, 0):
any_ended = True
if not ended_on_sub:
tlvs = qmi_req(s, txn, 0x0021, struct.pack("<BHB", 0x01, 1, 1), timeout=0.3)
txn += 1
res_tlv = tlvs.get(0x02, b"")
if len(res_tlv) >= 4 and struct.unpack("<HH", res_tlv[:4]) == (0, 0):
any_ended = True
s.close()
if any_ended:
subprocess.run(["dbus-send", "--system", "--type=signal", "/", "org.ofono.VoiceCallManager.CallRemoved"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
@@ -2124,9 +2265,10 @@ elif sub_cmd in ("call-accept", "call-hangup", "call-dtmf"):
target_cid = int(arg1)
s = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
qmi_req(s, 1, 0x0044, struct.pack("<BHB", 0x01, 1, target_sub))
calls = parse_call_info(qmi_req(s, 2, 0x002F))
qmi_req(s, 1, 0x0044, struct.pack("<BHB", 0x01, 1, target_sub), timeout=0.4)
calls = parse_call_info(qmi_req(s, 2, 0x002F, timeout=0.5))
if target_cid == 0 or (sub_cmd == "call-hangup" and target_cid not in calls):
fallback_cid = target_cid if target_cid > 0 else 1
target_cid = 0
for cid, c in calls.items():
if sub_cmd == "call-accept" and c["state"] in (2, 7):
@@ -2135,6 +2277,8 @@ elif sub_cmd in ("call-accept", "call-hangup", "call-dtmf"):
elif sub_cmd != "call-accept" and c["state"] not in (8, 9):
target_cid = cid
break
if target_cid == 0 and sub_cmd == "call-hangup":
target_cid = fallback_cid
if target_cid == 0:
s.close()
sys.exit(1)
@@ -2175,8 +2319,18 @@ PY
;;
dsds-daemon)
exec python3 - << 'PY'
import datetime, os, select, socket, struct, subprocess, sys, time
exec python3 - dsds-daemon << 'PY'
import datetime, fcntl, os, select, socket, struct, subprocess, sys, time
lock_fd = open("/tmp/dsds_daemon.lock", "w")
try:
fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except Exception:
sys.exit(0)
try:
os.chmod("/tmp/dsds_daemon.lock", 0o666)
except Exception:
pass
try:
while os.waitpid(-1, os.WNOHANG)[0] > 0:
@@ -2776,9 +2930,44 @@ def has_mm_call_files():
pass
return False
def sync_sub1_calls(calls, sim_slot):
def is_hangup_requested():
try:
return (time.time() - os.path.getmtime("/tmp/sxmo_hangup_requested")) < 3.5
except Exception:
return False
def query_sec_slot(uim_addr, fallback=2):
if not uim_addr:
return fallback
try:
us = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
ut = qmi_req(us, uim_addr, 1, 0x002F, timeout=0.08)
us.close()
st_val = ut.get(0x10, b"")
if len(st_val) >= 8:
_, _, sec_gw_idx, _ = struct.unpack("<HHHH", st_val[:8])
if sec_gw_idx != 0xFFFF:
return ((sec_gw_idx >> 8) & 0xFF) + 1
except Exception:
pass
return fallback
def sync_sub1_calls(calls, sim_slot, vs=None, voice_addr=None):
global active_calls
now_str = datetime.datetime.now().astimezone().isoformat(timespec="seconds")
hangup_req = is_hangup_requested()
sent_ended = False
if hangup_req:
for cid, c in list(calls.items()):
if c["state"] not in (8, 9):
if vs is not None and voice_addr is not None:
try:
qmi_req(vs, voice_addr, 55000 + (cid % 100), 0x0021, struct.pack("<BHB", 0x01, 1, cid), timeout=0.2)
except Exception:
pass
c["state"] = 9
for old_cid, old_info in list(active_calls.items()):
if old_cid not in calls:
if old_info.get("state") == "terminated":
@@ -2794,14 +2983,14 @@ def sync_sub1_calls(calls, sim_slot):
for cid, c in list(calls.items()):
st = STATE_MAP.get(c["state"], "unknown")
if st == "setup":
if c["dir"] == 1 and has_sub1_call_files():
if c["dir"] == 1 and has_sub1_call_files() and not hangup_req:
st = "dialing"
else:
continue
# Skip calls that are already managed by ModemManager / sxmo_modem.sh on Primary GW
if cid not in active_calls:
if st == "terminated":
if st == "terminated" or hangup_req:
continue
if c["dir"] == 1 and not has_sub1_call_files():
continue
@@ -2824,7 +3013,7 @@ def sync_sub1_calls(calls, sim_slot):
os.remove(os.path.join(CALLS_DIR, fn))
except Exception:
pass
if st != "terminated":
if st != "terminated" and not hangup_req:
try:
open(os.path.join(CALLS_DIR, f"{call_key}.{st}"), "w").close()
chown_user(os.path.join(CALLS_DIR, f"{call_key}.{st}"))
@@ -2863,7 +3052,9 @@ def sync_sub1_calls(calls, sim_slot):
stop_ringing_user()
evt = "call_missed" if prev == "ringing-in" else "call_hangup"
append_modemlog(f"{now_str}\t{evt}\t{num}\t[SIM {sim_slot}]\n")
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
if not hangup_req:
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
sent_ended = True
has_live = any(v["state"] in ("dialing", "ringing-out", "active", "held", "ringing-in", "waiting") for v in active_calls.values())
if not has_live:
@@ -2877,7 +3068,8 @@ def sync_sub1_calls(calls, sim_slot):
pass
if removed_stale:
stop_ringing_user()
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
if not sent_ended and not hangup_req:
send_fifo("/tmp/dwm_plugin_callscreen.fifo", "ENDED CALL ENDED")
if audio_opened:
set_q6voiced_audio(False)
@@ -2889,16 +3081,7 @@ while True:
time.sleep(3)
continue
sec_slot = 2
if uim_addr:
us = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
ut = qmi_req(us, uim_addr, 1, 0x002F)
us.close()
st_val = ut.get(0x10, b"")
if len(st_val) >= 8:
_, _, sec_gw_idx, _ = struct.unpack("<HHHH", st_val[:8])
if sec_gw_idx != 0xFFFF:
sec_slot = ((sec_gw_idx >> 8) & 0xFF) + 1
sec_slot = query_sec_slot(uim_addr, 2)
ws = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
vs = socket.socket(AF_QIPCRTR, socket.SOCK_DGRAM)
@@ -2955,6 +3138,7 @@ while True:
continue
tlvs = parse_tlvs(pkt)
if sock is ws and mid == 0x0001:
sec_slot = query_sec_slot(uim_addr, sec_slot)
# WMSEventReport indication
if 0x11 in tlvs and len(tlvs[0x11]) >= 8:
# Transfer-route MT message: [ack_ind(1), txn_id(4), format(1), len(2), data...]
@@ -2980,6 +3164,7 @@ while True:
elif sock is vs and mid == 0x002E:
# VoiceAllCallStatusIndication
got_voice_ind = True
sec_slot = query_sec_slot(uim_addr, sec_slot)
calls = parse_call_info(tlvs)
if not any(c["num"] for c in calls.values()):
full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F)
@@ -2988,17 +3173,18 @@ while True:
for cid, fc in full_calls.items():
if cid in calls and fc["num"]:
calls[cid]["num"] = fc["num"]
sync_sub1_calls(calls, sec_slot)
sync_sub1_calls(calls, sec_slot, vs, voice_addr)
if multipart_buf:
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
w_txn = flush_stale_multipart(ws, wms_addr, w_txn, sec_slot)
if not got_voice_ind and (active_calls or has_sub1_call_files()):
sec_slot = query_sec_slot(uim_addr, sec_slot)
full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F)
v_txn = (v_txn % 60000) + 1
if full_tlvs:
sync_sub1_calls(parse_call_info(full_tlvs), sec_slot)
sync_sub1_calls(parse_call_info(full_tlvs), sec_slot, vs, voice_addr)
if not os.path.exists("/tmp/bananarchy_screen_locked") and time.time() - last_poll >= 600.0:
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
@@ -3,8 +3,4 @@
# This script is executed after the last call finished
if command -v xcallscreen >/dev/null 2>&1; then
xcallscreen ended >/dev/null 2>&1 || true
fi
sxmo_playerctl.sh resume_all