#!/bin/sh
# B3: READ-ONLY QMI queries only (DMS/UIM/NAS "get"). No scan, no registration, no set-*, no PIN ops, no reset.
# ICCID/IMSI are masked on-device before being written anywhere.
D=${1:-/dev/wwan0qmi0}
Q="qmicli -p -d $D"
mask_iccid() { sed -E "s/([0-9]{15,22})/\1\n/; s/[0-9]+([0-9]{4})\n/************\1/"; }
mask_imsi()  { sed -E "s/'([0-9]{5})[0-9]+([0-9]{3})'/'\1******\2'/"; }
run() { echo "### $*"; timeout 30 $Q "$@" 2>&1; echo "### rc=$?"; }
run --dms-get-operating-mode
run --dms-get-revision
run --dms-uim-get-state
run --uim-get-card-status
echo "### --dms-uim-get-iccid (masked)"; timeout 30 $Q --dms-uim-get-iccid 2>&1 | mask_iccid
echo "### --dms-uim-get-imsi (masked)";  timeout 30 $Q --dms-uim-get-imsi 2>&1 | mask_imsi
run --nas-get-home-network
run --nas-get-serving-system
run --nas-get-system-info
run --nas-get-signal-info
run --nas-get-system-selection-preference
run --dms-get-operating-mode
