#!/bin/sh # Open/close the QMI BAM-DMUX data port. Keep it open during normal operation # so bam-dmux exposes net/wwan0 for ModemManager's qcom-soc plugin (bam-dmux # runtime-suspends after 1000 ms of inactivity with pc_state=0). DPM_ARGS="hw-data-ep-type=bam-dmux,hw-data-ep-iface-number=1,hw-data-rx-id=1,hw-data-tx-id=1" case "${1:-}" in open) had_wwan0=0 [ -d /sys/class/net/wwan0 ] && had_wwan0=1 if ! timeout 4 qmicli --silent -pd qrtr://0 --dpm-open-port="$DPM_ARGS" >/dev/null 2>&1; then timeout 4 qmicli --silent -d qrtr://0 --dpm-open-port="$DPM_ARGS" >/dev/null 2>&1 || true fi if [ "$had_wwan0" -eq 0 ]; then w=0 while [ "$w" -lt 25 ] && [ ! -d /sys/class/net/wwan0 ]; do sleep 0.1 w=$((w + 1)) done if [ -d /sys/class/net/wwan0 ] && command -v mmcli >/dev/null 2>&1; then if ! timeout 2 mmcli -L 2>/dev/null | grep -q '/Modem/'; then timeout 3 mmcli -S >/dev/null 2>&1 || true fi fi fi ;; close) if ! timeout 4 qmicli --silent -pd qrtr://0 --dpm-close-port="$DPM_ARGS" >/dev/null 2>&1; then timeout 4 qmicli --silent -d qrtr://0 --dpm-close-port="$DPM_ARGS" >/dev/null 2>&1 || true fi ;; *) printf 'Usage: %s [open|close]\n' "${0##*/}" >&2 exit 1 ;; esac