#!/bin/sh # SPDX-License-Identifier: AGPL-3.0-only # Copyright 2022 Sxmo Contributors export HOME="${HOME:-/home/user}" export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}" export PATH="${XDG_CONFIG_HOME:-$HOME/.config}/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin:$PATH" # include common definitions # shellcheck source=scripts/core/sxmo_common.sh . sxmo_common.sh set -e REQ_SIM_SLOT="${SXMO_SIM_SLOT:-}" if [ "${1:-}" = "--sim" ] && [ -n "${2:-}" ]; then REQ_SIM_SLOT="$2" shift 2 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)" 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}')" DUAL_ACTIVE="$(printf "%s\n" "$UIM_ST" | awk -F= '/^DUAL_SIM_ACTIVE=/ {print $2; exit}')" [ -n "$PRIM_SLOT" ] || PRIM_SLOT="1" [ -n "$SEC_SLOT" ] || SEC_SLOT="0" [ -n "$PREF_SLOT" ] || PREF_SLOT="$PRIM_SLOT" [ -n "$DUAL_ACTIVE" ] || DUAL_ACTIVE="0" } 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 resolve_sim_state 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 printf "PROMPT_SIM %s\n" "$NUMBER" > /tmp/dwm_plugin_callscreen.fifo 2>/dev/null || true xcallscreen >/dev/null 2>&1 || true return 0 fi TARGET_SIM="$PREF_SLOT" fi [ -n "$TARGET_SIM" ] || TARGET_SIM="$PRIM_SLOT" # Secondary GW SIM call via QMI VOICE sub=1 if [ "$TARGET_SIM" = "$SEC_SLOT" ] && [ "$SEC_SLOT" != "0" ]; then sxmo_log "Attempting to dial on Secondary GW (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 elif command -v xcallscreen >/dev/null 2>&1; then 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 fi sxmo_notify_user.sh --urgency=critical "We failed to initiate call on SIM $TARGET_SIM" return 1 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 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_jobs.sh start proximity_lock sxmo_proximitylock.sh 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 elif command -v xcallscreen >/dev/null 2>&1; then xcallscreen outgoing "-" "$NUMBER" >/dev/null 2>&1 || true fi if ! 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 fi sxmo_notify_user.sh --urgency=critical "We failed to initiate call" return 1 fi # cleanup all dangling event files, ignore errors rm "$XDG_RUNTIME_DIR/sxmo_calls/$CALLID."* 2>/dev/null || true 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 elif command -v xcallscreen >/dev/null 2>&1; then xcallscreen outgoing "$CALLID" "$NUMBER" >/dev/null 2>&1 || true fi 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_jobs.sh start proximity_lock sxmo_proximitylock.sh sxmo_hook_statusbar.sh state & sxmo_jobs.sh start incall_menu sxmo_modemcall.sh incall_menu } dial_ussd() { USSD="$1" sxmo_log "Dialling USSD: $USSD" SIM_ARG="" if [ -n "$REQ_SIM_SLOT" ]; then SIM_ARG="--sim $REQ_SIM_SLOT" fi # shellcheck disable=SC2086 OUTPUT="$(doas -n /usr/libexec/msm-modem-uim-selection ussd initiate $SIM_ARG "$USSD" 2>/dev/null || /usr/libexec/msm-modem-uim-selection ussd initiate $SIM_ARG "$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() { if [ -n "${DISPLAY:-}" ] && command -v xdialer >/dev/null 2>&1; then exec xdialer fi # Initial menu with recently contacted people NUMBER="$( grep . <