Add IMS/VoLTE/VoWiFi stack and fix Dual-SIM cellular mobile data
- Add Qualcomm MCFG .mbn parser and profile store (bananarchy-imsctl), QMI_PDC/QMI_IMSDCM VoLTE daemon (bananarchy-imsd), and SWu IKEv2/EAP-AKA/ESP/SIP/AMR VoWiFi engine (bananarchy-vowifi) with disabled-by-default (auto) 4G-only activation and xmodem/xfiles/xcallscreen UI support. - Add libmm-wds-bind.so QMI_SERVICE_WDS PRIMARY subscription binding (including serialized post-mux/data-port binding), msm-modem-uim-selection DSDS PS-domain handoff, cs-only dial pause/restore (10-bananarchy-dpm.sh), cold-boot mmcli -K recovery, and networks.so connection.autoconnect no race fix. - Add offline test suites (test-ims-mbn.py, test-imsd-volte.py, test-vowifi-swu-ims.py, test-lte-mobile-data.py), update docs (CHANGELOG.md Unreleased, README.md, MANUAL.md, AGENTS.md), and pin rebuilt 4-target image SHA-256 hashes in scripts/check-rebuild.sh.
This commit is contained in:
1 parent
03bc80f267
commit
c40ec932de
65 files changed
+11916
-129
No files matched your search
Executable
+780
@@ -0,0 +1,780 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Offline host regression tests for LTE attach, PS domain recovery, WDS bind, and APN sync."""
|
||||
|
||||
import os
|
||||
import selectors
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
BASE = Path(__file__).resolve().parents[1]
|
||||
UIM_SEL = BASE / "overlay/rootfs/usr/libexec/msm-modem-uim-selection"
|
||||
IMS_BEARER_SH = BASE / "overlay/rootfs/usr/bin/bananarchy-ims-bearer.sh"
|
||||
DPM_DISP_SH = BASE / "overlay/rootfs/etc/NetworkManager/dispatcher.d/10-bananarchy-dpm.sh"
|
||||
WDS_BIND_SRC = BASE / "src/bananarchy-daemons/mm-wds-bind.c"
|
||||
NETWORKS_SRC = BASE / "src/dwm-plugins/networks_plugin.cpp"
|
||||
|
||||
MOCK_MAGIC = 0x51525452
|
||||
MSG_LOOKUP = 1
|
||||
MSG_DATA = 3
|
||||
HDR_FMT = "<9I"
|
||||
HDR_SIZE = struct.calcsize(HDR_FMT)
|
||||
SVC_NAS = 3
|
||||
SVC_DSD = 0x2A
|
||||
|
||||
|
||||
def fail(msg):
|
||||
sys.stderr.write(f"[fail] {msg}\n")
|
||||
return 1
|
||||
|
||||
|
||||
def tlv(t, val):
|
||||
return struct.pack("<BH", t, len(val)) + val
|
||||
|
||||
|
||||
def parse_tlvs(buf):
|
||||
out = {}
|
||||
pos = 0
|
||||
while pos + 3 <= len(buf):
|
||||
tt, tl = struct.unpack_from("<BH", buf, pos)
|
||||
pos += 3
|
||||
if pos + tl > len(buf):
|
||||
break
|
||||
out[tt] = buf[pos:pos + tl]
|
||||
pos += tl
|
||||
return out
|
||||
|
||||
|
||||
def pack_qmi_rsp(txn_id, msg_id, extra=b"", err=0):
|
||||
res = struct.pack("<HH", 0 if err == 0 else 1, err)
|
||||
tlvs = tlv(0x02, res) + extra
|
||||
return struct.pack("<BHHH", 0x02, txn_id, msg_id, len(tlvs)) + tlvs
|
||||
|
||||
|
||||
class MockQmiServer:
|
||||
def __init__(self, sock_path):
|
||||
self.sock_path = sock_path
|
||||
self.srv = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
|
||||
self.srv.bind(str(sock_path))
|
||||
self.srv.listen(8)
|
||||
self.srv.setblocking(False)
|
||||
self.sel = selectors.DefaultSelector()
|
||||
self.sel.register(self.srv, selectors.EVENT_READ)
|
||||
self.conn_sub = {}
|
||||
self.dsd_sub = 0
|
||||
self.dsd_data_enabled = 0
|
||||
self.dsd_switch_calls = 0
|
||||
self.stop_evt = threading.Event()
|
||||
self.lock = threading.Lock()
|
||||
self.events = []
|
||||
|
||||
self.subs = {
|
||||
0: {"reg": 1, "cs": 1, "ps": 2, "mode": 0x001C, "dom": 0},
|
||||
1: {"reg": 1, "cs": 1, "ps": 0, "mode": 0x0004, "dom": 2},
|
||||
}
|
||||
self.thread = threading.Thread(target=self._loop, daemon=True)
|
||||
|
||||
def start(self):
|
||||
self.thread.start()
|
||||
|
||||
def stop(self):
|
||||
self.stop_evt.set()
|
||||
self.thread.join(timeout=2)
|
||||
self.sel.close()
|
||||
self.srv.close()
|
||||
|
||||
def _handle_qmi(self, conn, svc, payload):
|
||||
if len(payload) < 7:
|
||||
return pack_qmi_rsp(0, 0, err=1)
|
||||
_, txn, msg_id, tlen = struct.unpack_from("<BHHH", payload, 0)
|
||||
tlvs = parse_tlvs(payload[7:7 + tlen])
|
||||
with self.lock:
|
||||
if svc == SVC_DSD:
|
||||
if msg_id == 0x0027: # BIND_SUBSCRIPTION
|
||||
if 0x01 in tlvs and len(tlvs[0x01]) >= 4:
|
||||
self.dsd_sub = struct.unpack("<I", tlvs[0x01][:4])[0]
|
||||
self.events.append(("dsd_bind", self.dsd_sub))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
if msg_id == 0x0034: # NOTIFY_DATA_SETTINGS
|
||||
if 0x10 in tlvs and len(tlvs[0x10]) >= 1:
|
||||
self.dsd_data_enabled = tlvs[0x10][0]
|
||||
self.events.append(("dsd_data", self.dsd_data_enabled))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
if msg_id == 0x004E: # SWITCH_DDS (must NOT be called)
|
||||
self.dsd_switch_calls += 1
|
||||
self.events.append(("dsd_switch_dds",))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
|
||||
sub = self.conn_sub.get(conn, 0)
|
||||
st = self.subs[sub]
|
||||
if msg_id == 0x0045: # BIND_SUBSCRIPTION
|
||||
if 0x01 in tlvs and len(tlvs[0x01]) >= 1:
|
||||
new_sub = tlvs[0x01][0]
|
||||
if new_sub in self.subs:
|
||||
self.conn_sub[conn] = new_sub
|
||||
self.events.append(("bind", new_sub))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
if msg_id == 0x0034: # GET_SYSTEM_SELECTION_PREFERENCE
|
||||
extra = (
|
||||
tlv(0x11, struct.pack("<H", st["mode"])) +
|
||||
tlv(0x18, struct.pack("<I", st["dom"]))
|
||||
)
|
||||
return pack_qmi_rsp(txn, msg_id, extra)
|
||||
if msg_id == 0x0033: # SET_SYSTEM_SELECTION_PREFERENCE
|
||||
dur = tlvs[0x17][0] if 0x17 in tlvs and len(tlvs[0x17]) >= 1 else None
|
||||
new_mode = struct.unpack("<H", tlvs[0x11][:2])[0] if 0x11 in tlvs and len(tlvs[0x11]) >= 2 else None
|
||||
new_dom = struct.unpack("<I", tlvs[0x18][:4])[0] if 0x18 in tlvs and len(tlvs[0x18]) >= 4 else None
|
||||
if new_mode is not None:
|
||||
st["mode"] = new_mode
|
||||
if new_dom is not None:
|
||||
st["dom"] = new_dom
|
||||
self.events.append(("set_ssp", sub, new_mode, new_dom, dur))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
if msg_id == 0x0024: # GET_SERVING_SYSTEM
|
||||
srv = struct.pack("<BBBBBB", st["reg"], st["cs"], st["ps"], 0, 1, 0x05)
|
||||
plmn = struct.pack("<HHB", 255, 6, 0)
|
||||
return pack_qmi_rsp(txn, msg_id, tlv(0x01, srv) + tlv(0x12, plmn))
|
||||
if msg_id == 0x0022: # INITIATE_NETWORK_REGISTER
|
||||
st["reg"] = 1
|
||||
st["cs"] = 1
|
||||
self.events.append(("reg", sub))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
if msg_id == 0x0023: # ATTACH_DETACH
|
||||
act = tlvs[0x10][0] if 0x10 in tlvs and len(tlvs[0x10]) >= 1 else 0
|
||||
if act == 1:
|
||||
st["ps"] = 1
|
||||
elif act == 2:
|
||||
st["ps"] = 2
|
||||
self.events.append(("attach", sub, act))
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
return pack_qmi_rsp(txn, msg_id)
|
||||
|
||||
def _loop(self):
|
||||
while not self.stop_evt.is_set():
|
||||
for key, _ in self.sel.select(timeout=0.05):
|
||||
if key.fileobj is self.srv:
|
||||
c, _ = self.srv.accept()
|
||||
c.setblocking(False)
|
||||
self.sel.register(c, selectors.EVENT_READ)
|
||||
with self.lock:
|
||||
self.conn_sub[c] = 0
|
||||
else:
|
||||
c = key.fileobj
|
||||
try:
|
||||
data = c.recv(4096)
|
||||
except OSError:
|
||||
data = b""
|
||||
if not data:
|
||||
self.sel.unregister(c)
|
||||
with self.lock:
|
||||
self.conn_sub.pop(c, None)
|
||||
c.close()
|
||||
continue
|
||||
if len(data) < HDR_SIZE:
|
||||
continue
|
||||
magic, mtype, sn, sp, dn, dp, svc, inst, plen = struct.unpack_from(HDR_FMT, data, 0)
|
||||
if magic != MOCK_MAGIC:
|
||||
continue
|
||||
if mtype == MSG_LOOKUP:
|
||||
rsp_p = struct.pack("<II", 2, 100 + svc) if svc in (SVC_NAS, SVC_DSD) else struct.pack("<II", 0, 0)
|
||||
hdr = struct.pack(HDR_FMT, MOCK_MAGIC, MSG_LOOKUP, 0, 0, sn, sp, svc, inst, len(rsp_p))
|
||||
c.send(hdr + rsp_p)
|
||||
elif mtype == MSG_DATA:
|
||||
payload = data[HDR_SIZE:HDR_SIZE + plen]
|
||||
qmi_rsp = self._handle_qmi(c, svc, payload)
|
||||
hdr = struct.pack(HDR_FMT, MOCK_MAGIC, MSG_DATA, dn, dp, sn, sp, svc, inst, len(qmi_rsp))
|
||||
c.send(hdr + qmi_rsp)
|
||||
|
||||
|
||||
def test_dual_and_single_sim_ps_domain(tmp):
|
||||
sock_path = tmp / "qrtr.sock"
|
||||
srv = MockQmiServer(sock_path)
|
||||
srv.start()
|
||||
try:
|
||||
# 1) Dual-SIM: sub=1 holds cs-ps and sub=0 is stuck in cs-only + PS detached.
|
||||
env = os.environ.copy()
|
||||
env["BANANARCHY_QRTR_MOCK_SOCK"] = str(sock_path)
|
||||
env["BANANARCHY_DUAL_SIM"] = "1"
|
||||
env["BANANARCHY_POWER_RUNDIR"] = str(tmp / "pp_run")
|
||||
res = subprocess.run([str(UIM_SEL), "ensure-ps-domain"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return fail(f"ensure-ps-domain dual-SIM failed: {res.stderr}")
|
||||
|
||||
with srv.lock:
|
||||
ev = list(srv.events)
|
||||
s0 = dict(srv.subs[0])
|
||||
s1 = dict(srv.subs[1])
|
||||
dsd_sub = srv.dsd_sub
|
||||
dsd_en = srv.dsd_data_enabled
|
||||
sw_calls = srv.dsd_switch_calls
|
||||
|
||||
if sw_calls != 0 or ("dsd_switch_dds",) in ev:
|
||||
return fail(f"ensure-ps-domain must never call QMI_DSD 0x004E SWITCH_DDS: ev={ev}")
|
||||
if dsd_sub != 1 or dsd_en != 1:
|
||||
return fail(f"expected DSD 0x0027=1 and 0x0034=1, got sub={dsd_sub} data={dsd_en}")
|
||||
|
||||
idx_s1_demote = next(
|
||||
(i for i, e in enumerate(ev) if e[:2] == ("set_ssp", 1) and e[3] == 0 and e[2] == 0x0004 and e[4] == 1),
|
||||
-1,
|
||||
)
|
||||
idx_s0_promote = next(
|
||||
(i for i, e in enumerate(ev) if e[:2] == ("set_ssp", 0) and e[3] == 2 and e[4] == 1),
|
||||
-1,
|
||||
)
|
||||
if idx_s1_demote < 0 or idx_s0_promote < 0 or idx_s1_demote > idx_s0_promote:
|
||||
return fail(f"expected sub=1 demoted to cs-only before sub=0 promoted to cs-ps; events={ev}")
|
||||
if ("attach", 0, 1) not in ev or s0["dom"] != 2 or s0["ps"] != 1 or s1["dom"] != 0:
|
||||
return fail(f"unexpected final dual-SIM NAS state: s0={s0} s1={s1} ev={ev}")
|
||||
|
||||
# 2a) Single-SIM with rat_parked present: promote to cs-ps, do NOT overwrite mode=0x0004.
|
||||
pp_dir = tmp / "pp_run"
|
||||
pp_dir.mkdir(parents=True, exist_ok=True)
|
||||
rat_parked = pp_dir / "rat_parked"
|
||||
rat_parked.write_text("")
|
||||
with srv.lock:
|
||||
srv.events.clear()
|
||||
srv.subs[0] = {"reg": 1, "cs": 1, "ps": 2, "mode": 0x0004, "dom": 0}
|
||||
env["BANANARCHY_DUAL_SIM"] = "0"
|
||||
res = subprocess.run([str(UIM_SEL), "ensure-ps-domain"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return fail(f"ensure-ps-domain single-SIM (parked) failed: {res.stderr}")
|
||||
with srv.lock:
|
||||
ev = list(srv.events)
|
||||
s0 = dict(srv.subs[0])
|
||||
if s0["dom"] != 2 or s0["mode"] != 0x0004 or s0["ps"] != 1:
|
||||
return fail(f"rat_parked must keep GSM mode while promoting PS domain; s0={s0} ev={ev}")
|
||||
if any(e[0] == "set_ssp" and e[1] == 1 for e in ev):
|
||||
return fail(f"single-SIM must not touch sub=1: ev={ev}")
|
||||
|
||||
# 2b) Single-SIM without rat_parked and stuck in mode=0x0004 + cs-only: restores mode=0x001C.
|
||||
rat_parked.unlink()
|
||||
with srv.lock:
|
||||
srv.events.clear()
|
||||
srv.subs[0] = {"reg": 1, "cs": 1, "ps": 2, "mode": 0x0004, "dom": 0}
|
||||
res = subprocess.run([str(UIM_SEL), "ensure-ps-domain"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return fail(f"ensure-ps-domain single-SIM (unparked) failed: {res.stderr}")
|
||||
with srv.lock:
|
||||
s0 = dict(srv.subs[0])
|
||||
if s0["dom"] != 2 or s0["mode"] != 0x001C or s0["ps"] != 1:
|
||||
return fail(f"unparked single-SIM must restore mode=0x001c and cs-ps; s0={s0}")
|
||||
|
||||
print("[ok] test-lte-mobile-data: dual-SIM cs-only handoff, single-SIM PS attach, and rat_parked guard")
|
||||
return 0
|
||||
finally:
|
||||
srv.stop()
|
||||
|
||||
|
||||
def test_wds_apn_sync_and_mobile_data_prep(tmp):
|
||||
sock_path = tmp / "qrtr_apn.sock"
|
||||
srv = MockQmiServer(sock_path)
|
||||
srv.start()
|
||||
try:
|
||||
nm_dir = tmp / "nm_cons"
|
||||
nm_dir.mkdir(parents=True, exist_ok=True)
|
||||
(nm_dir / "internet.nmconnection").write_text(
|
||||
"[connection]\nid=internet\ntype=gsm\n\n[gsm]\napn=internet\n\n[ipv4]\nmethod=auto\n"
|
||||
)
|
||||
qmi_log = tmp / "qmicli_wds.log"
|
||||
mm_log = tmp / "mmcli_wds.log"
|
||||
dpm_log = tmp / "dpm.log"
|
||||
bin_dir = tmp / "apn_bin"
|
||||
bin_dir.mkdir(parents=True, exist_ok=True)
|
||||
ssp_state_file = tmp / "ssp_dom.txt"
|
||||
ssp_state_file.write_text("cs-only\n")
|
||||
mock_qmi = bin_dir / "mock_qmicli"
|
||||
mock_qmi.write_text(f"""#!/bin/sh
|
||||
echo "$*" >> "{qmi_log}"
|
||||
for a in "$@"; do
|
||||
case "$a" in
|
||||
--wds-get-profile-list=3gpp)
|
||||
cat <<'EOF'
|
||||
Profile list retrieved:
|
||||
\t[1] 3gpp - profile1
|
||||
\t\tAPN: ''
|
||||
\t\tPDP type: 'ipv4-or-ipv6'
|
||||
\t[2] 3gpp - profile2
|
||||
\t\tAPN: 'ims'
|
||||
\t\tPDP type: 'ipv4-or-ipv6'
|
||||
\t[3] 3gpp - sos
|
||||
\t\tAPN: 'sos'
|
||||
\t\tPDP type: 'ipv4-or-ipv6'
|
||||
\t[4] 3gpp - qdp_profile_ia
|
||||
\t\tAPN: '3g.utel.ua'
|
||||
\t\tPDP type: 'ipv4'
|
||||
\t[5] 3gpp - modem_def_prof
|
||||
\t\tAPN: '3g.utel.ua'
|
||||
\t\tPDP type: 'ipv4'
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
--wds-get-lte-attach-pdn-list)
|
||||
echo "Attach PDN list retrieved:"
|
||||
echo "\tCurrent list: '4'"
|
||||
exit 0
|
||||
;;
|
||||
--wds-get-default-profile-number=3gpp)
|
||||
echo "Default profile number retrieved:"
|
||||
echo "\tDefault profile number: '5'"
|
||||
exit 0
|
||||
;;
|
||||
--nas-get-serving-system)
|
||||
echo "Registration state: 'registered'"
|
||||
echo "CS: 'attached'"
|
||||
echo "PS: 'attached'"
|
||||
echo "MCC: '255'"
|
||||
echo "MNC: '6'"
|
||||
exit 0
|
||||
;;
|
||||
--nas-get-system-selection-preference)
|
||||
echo "Service domain preference: '$(cat "{ssp_state_file}")'"
|
||||
exit 0
|
||||
;;
|
||||
--uim-get-card-status)
|
||||
cat <<'EOF'
|
||||
Provisioning applications:
|
||||
\tPrimary GW: slot '2', application '1'
|
||||
\tSecondary GW: slot '1', application '1'
|
||||
Slot [1]:
|
||||
\tCard state: 'present'
|
||||
\tApplication [1]:
|
||||
\t\tApplication type: 'usim (2)'
|
||||
\t\tApplication state: 'ready'
|
||||
\t\tApplication ID:
|
||||
\t\t\tA0:00:00:00:87:10:02:FF:FF:FF:FF:89:03:02:00:00
|
||||
Slot [2]:
|
||||
\tCard state: 'present'
|
||||
\tApplication [1]:
|
||||
\t\tApplication type: 'usim (2)'
|
||||
\t\tApplication state: 'ready'
|
||||
\t\tApplication ID:
|
||||
\t\t\tA0:00:00:00:87:10:02:FF:FF:FF:FF:89:03:02:00:00
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
--uim-change-provisioning-session=*)
|
||||
case "$a" in
|
||||
*activate=no*) echo "cs-ps" > "{ssp_state_file}" ;;
|
||||
esac
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
exit 0
|
||||
""")
|
||||
mock_qmi.chmod(0o755)
|
||||
|
||||
# Also test mmcli -K ANSI-free state: failed recovery, nmcli gsm check, and
|
||||
# --3gpp-set-initial-eps-bearer-settings skip when APN matches.
|
||||
mm_state_file = tmp / "mm_state.txt"
|
||||
mm_state_file.write_text("failed\n")
|
||||
rc_log = tmp / "rc_service.log"
|
||||
mock_rc = bin_dir / "rc-service"
|
||||
mock_rc.write_text(f"""#!/bin/sh
|
||||
echo "$*" >> "{rc_log}"
|
||||
if [ "$1" = "modemmanager" ] && [ "$2" = "restart" ]; then
|
||||
echo "disabled" > "{mm_state_file}"
|
||||
fi
|
||||
exit 0
|
||||
""")
|
||||
mock_rc.chmod(0o755)
|
||||
|
||||
nm_log = tmp / "nmcli_ops.log"
|
||||
nm_conn_state = tmp / "nm_gsm_state.txt"
|
||||
nm_conn_state.write_text("gsm:connecting (prepare)\n")
|
||||
mock_nmcli = bin_dir / "nmcli"
|
||||
mock_nmcli.write_text(f"""#!/bin/sh
|
||||
echo "$*" >> "{nm_log}"
|
||||
case "$*" in
|
||||
*"-t -f UUID,TYPE connection show"*)
|
||||
echo "0d15223d-0492-4d43-b85f-981fee0a2ff0:gsm"
|
||||
echo "83bd1823-feca-4c2b-9205-4b83dc792e1f:802-3-ethernet"
|
||||
exit 0
|
||||
;;
|
||||
*"device disconnect qrtr0"*)
|
||||
echo "gsm:disconnected" > "{nm_conn_state}"
|
||||
exit 0
|
||||
;;
|
||||
*"-t -f TYPE,STATE device status"*)
|
||||
cat "{nm_conn_state}"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
""")
|
||||
mock_nmcli.chmod(0o755)
|
||||
|
||||
mock_mm = bin_dir / "mmcli"
|
||||
mock_mm.write_text(f"""#!/bin/sh
|
||||
echo "$*" >> "{mm_log}"
|
||||
st="$(cat "{mm_state_file}" 2>/dev/null || echo failed)"
|
||||
case "$*" in
|
||||
"-L") echo "/org/freedesktop/ModemManager1/Modem/0"; exit 0 ;;
|
||||
"-m any -e")
|
||||
echo "registered" > "{mm_state_file}"
|
||||
exit 0
|
||||
;;
|
||||
*"--3gpp-set-initial-eps-bearer-settings"*) exit 0 ;;
|
||||
*"-m any -K"*)
|
||||
echo "modem.generic.state : $st"
|
||||
echo "modem.3gpp.packet-service-state : attached"
|
||||
echo "modem.3gpp.eps.initial-bearer.settings.apn : --"
|
||||
exit 0
|
||||
;;
|
||||
*"-m any"*)
|
||||
if [ "$st" = "failed" ]; then
|
||||
printf 'state: \\033[31mfailed\\033[0m\\n'
|
||||
else
|
||||
echo "state: $st"
|
||||
fi
|
||||
echo "packet service state: attached"
|
||||
echo "initial bearer apn: internet"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
""")
|
||||
mock_mm.chmod(0o755)
|
||||
|
||||
mock_dpm = tmp / "mock_dpm.sh"
|
||||
mock_dpm.write_text(f"#!/bin/sh\necho \"$*\" >> \"{dpm_log}\"\nexit 0\n")
|
||||
mock_dpm.chmod(0o755)
|
||||
|
||||
run_dir = tmp / "ba_run"
|
||||
dsds_file = tmp / "sxmo_dsds_active"
|
||||
dsds_file.write_text("1\n")
|
||||
|
||||
env = os.environ.copy()
|
||||
env.update({
|
||||
"PATH": f"{bin_dir}:{env.get('PATH', '')}",
|
||||
"BANANARCHY_QRTR_MOCK_SOCK": str(sock_path),
|
||||
"BANANARCHY_DUAL_SIM": "1",
|
||||
"BANANARCHY_USE_MM": "1",
|
||||
"BANANARCHY_QMICLI_BIN": str(mock_qmi),
|
||||
"BANANARCHY_DPM_SH": str(mock_dpm),
|
||||
"BANANARCHY_NM_CONNECTIONS_DIR": str(nm_dir),
|
||||
"BANANARCHY_POWER_RUNDIR": str(tmp / "pp_run2"),
|
||||
"BANANARCHY_RUNDIR": str(run_dir),
|
||||
"BANANARCHY_DSDS_ACTIVE_FILE": str(dsds_file),
|
||||
"BANANARCHY_UIM_SEL": str(UIM_SEL),
|
||||
})
|
||||
res = subprocess.run([str(UIM_SEL), "mobile-data-prep"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return fail(f"mobile-data-prep failed: {res.stderr}")
|
||||
if "modemmanager restart" not in rc_log.read_text():
|
||||
return fail(f"mobile-data-prep must restart failed ModemManager under mmcli -K; rc_log={rc_log.read_text()}")
|
||||
mm_pre_log = mm_log.read_text()
|
||||
if "-m any -e" not in mm_pre_log or "-m any -K" not in mm_pre_log:
|
||||
return fail(f"expected mmcli -K and -m any -e calls; mm_log:\n{mm_pre_log}")
|
||||
if "--3gpp-set-initial-eps-bearer-settings" in mm_pre_log:
|
||||
return fail(f"mobile-data-prep must skip initial-bearer write when APN matches; mm_log:\n{mm_pre_log}")
|
||||
nm_ops = nm_log.read_text()
|
||||
if "connection modify 0d15223d-0492-4d43-b85f-981fee0a2ff0 connection.autoconnect no" not in nm_ops:
|
||||
return fail(f"mobile-data-prep must disable gsm autoconnect; nm_log:\n{nm_ops}")
|
||||
if "device disconnect qrtr0" not in nm_ops:
|
||||
return fail(f"mobile-data-prep must clear connecting qrtr0 before dial; nm_log:\n{nm_ops}")
|
||||
|
||||
qlog = qmi_log.read_text()
|
||||
for pid in (1, 4, 5):
|
||||
if f"--wds-modify-profile=3gpp,{pid},apn=internet" not in qlog:
|
||||
return fail(f"expected profile {pid} modified to internet; log:\n{qlog}")
|
||||
if "--wds-modify-profile=3gpp,2" in qlog or "--wds-modify-profile=3gpp,3" in qlog:
|
||||
return fail(f"must never overwrite ims/sos profiles 2 or 3; log:\n{qlog}")
|
||||
if "activate=no,session-type=secondary-gw-provisioning" not in qlog:
|
||||
return fail(f"expected cs-only fallback pausing secondary-gw; log:\n{qlog}")
|
||||
pause_file = run_dir / "dsds_paused_for_data"
|
||||
if not pause_file.is_file() or "SLOT=1" not in pause_file.read_text():
|
||||
return fail(f"expected dsds_paused_for_data SLOT=1, got {pause_file.exists()}")
|
||||
if dsds_file.read_text().strip() != "0":
|
||||
return fail(f"expected sxmo_dsds_active=0 while paused, got {dsds_file.read_text()!r}")
|
||||
if "open" not in dpm_log.read_text().splitlines():
|
||||
return fail(f"expected bananarchy-dpm.sh open call; log={dpm_log.read_text()}")
|
||||
with srv.lock:
|
||||
s0 = dict(srv.subs[0])
|
||||
if s0["dom"] != 2 or s0["ps"] != 1:
|
||||
return fail(f"mobile-data-prep did not promote PS domain: {s0}")
|
||||
|
||||
# Test dispatcher qrtr0 down invokes restore-dsds and clears dsds_paused_for_data.
|
||||
qmi_log.write_text("")
|
||||
disp_res = subprocess.run([str(DPM_DISP_SH), "qrtr0", "down"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if disp_res.returncode != 0:
|
||||
return fail(f"10-bananarchy-dpm.sh qrtr0 down failed: {disp_res.stderr}")
|
||||
if pause_file.exists():
|
||||
return fail("dsds_paused_for_data should be removed after restore-dsds")
|
||||
if dsds_file.read_text().strip() != "1":
|
||||
return fail(f"expected sxmo_dsds_active=1 after restore-dsds, got {dsds_file.read_text()!r}")
|
||||
qlog_rest = qmi_log.read_text()
|
||||
if "slot=1,activate=yes,session-type=secondary-gw-provisioning" not in qlog_rest:
|
||||
return fail(f"expected secondary-gw reactivated by restore-dsds; log:\n{qlog_rest}")
|
||||
|
||||
# Verify sync-apn never triggers --3gpp-set-initial-eps-bearer-settings 3GPP detach.
|
||||
mm_log.write_text("")
|
||||
env["BANANARCHY_SKIP_MM"] = "0"
|
||||
res2 = subprocess.run([str(UIM_SEL), "sync-apn", "internet"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res2.returncode != 0:
|
||||
return fail(f"sync-apn failed: {res2.stderr}")
|
||||
if "--3gpp-set-initial-eps-bearer-settings" in mm_log.read_text():
|
||||
return fail(f"sync-apn must never call --3gpp-set-initial-eps-bearer-settings; log={mm_log.read_text()}")
|
||||
|
||||
print("[ok] test-lte-mobile-data: WDS profiles [1/4/5] sync, initial-bearer skip, cs-only pause & dispatcher restore-dsds")
|
||||
return 0
|
||||
finally:
|
||||
srv.stop()
|
||||
|
||||
|
||||
def test_mm_wds_bind_preload(tmp):
|
||||
# Compile mm-wds-bind.c alongside a tiny stub libqmi harness and verify via ctypes
|
||||
# that QMI_SERVICE_WDS (1) binds PRIMARY (1), post-mux/data port binds serialize a
|
||||
# fresh PRIMARY bind before firing caller callback, non-WDS services are skipped,
|
||||
# and BANANARCHY_WDS_SUBSCRIPTION=0 disables binding.
|
||||
harness_c = tmp / "wds_harness.c"
|
||||
harness_c.write_text("""
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
int service;
|
||||
unsigned int bound_sub;
|
||||
int bind_calls;
|
||||
int port_binds;
|
||||
} FakeClient;
|
||||
|
||||
static FakeClient g_clients[4];
|
||||
static int g_next = 0;
|
||||
|
||||
void *qmi_device_allocate_client_finish(void *self, void *res, void **err) {
|
||||
(void)res; (void)err;
|
||||
int idx = g_next++ & 3;
|
||||
g_clients[idx].service = (int)(long)self;
|
||||
g_clients[idx].bound_sub = 0;
|
||||
g_clients[idx].bind_calls = 0;
|
||||
g_clients[idx].port_binds = 0;
|
||||
return &g_clients[idx];
|
||||
}
|
||||
|
||||
int qmi_client_get_service(void *client) {
|
||||
return client ? ((FakeClient *)client)->service : 0;
|
||||
}
|
||||
|
||||
void *qmi_message_wds_bind_subscription_input_new(void) {
|
||||
static unsigned int inp_slot;
|
||||
inp_slot = 0;
|
||||
return &inp_slot;
|
||||
}
|
||||
|
||||
int qmi_message_wds_bind_subscription_input_set_subscription_id(void *inp, unsigned int sub, void **err) {
|
||||
(void)err;
|
||||
if (!inp) return 0;
|
||||
*(unsigned int *)inp = sub;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void qmi_message_wds_bind_subscription_input_unref(void *inp) {
|
||||
(void)inp;
|
||||
}
|
||||
|
||||
void *qmi_client_wds_bind_subscription_finish(void *client, void *res, void **err) {
|
||||
(void)client; (void)res; (void)err;
|
||||
return (void *)0x1;
|
||||
}
|
||||
|
||||
void qmi_message_wds_bind_subscription_output_unref(void *out) {
|
||||
(void)out;
|
||||
}
|
||||
|
||||
void qmi_client_wds_bind_subscription(void *client, void *inp, unsigned int timeout,
|
||||
void *canc, void (*cb)(void *, void *, void *), void *ud) {
|
||||
(void)timeout; (void)canc;
|
||||
FakeClient *fc = (FakeClient *)client;
|
||||
if (fc && inp) {
|
||||
fc->bound_sub = *(unsigned int *)inp;
|
||||
fc->bind_calls++;
|
||||
}
|
||||
if (cb) cb(client, NULL, ud);
|
||||
}
|
||||
|
||||
void qmi_client_wds_bind_mux_data_port(void *client, void *inp, unsigned int timeout,
|
||||
void *canc, void (*cb)(void *, void *, void *), void *ud) {
|
||||
(void)inp; (void)timeout; (void)canc;
|
||||
FakeClient *fc = (FakeClient *)client;
|
||||
if (fc) {
|
||||
fc->bound_sub = 2; /* simulate MPSS resetting subscription on port bind */
|
||||
fc->port_binds++;
|
||||
}
|
||||
if (cb) cb(client, (void *)0x2, ud);
|
||||
}
|
||||
|
||||
void qmi_client_wds_bind_data_port(void *client, void *inp, unsigned int timeout,
|
||||
void *canc, void (*cb)(void *, void *, void *), void *ud) {
|
||||
(void)inp; (void)timeout; (void)canc;
|
||||
FakeClient *fc = (FakeClient *)client;
|
||||
if (fc) {
|
||||
fc->bound_sub = 2;
|
||||
fc->port_binds++;
|
||||
}
|
||||
if (cb) cb(client, (void *)0x3, ud);
|
||||
}
|
||||
|
||||
int harness_get_bound_sub(void *client) {
|
||||
return client ? (int)((FakeClient *)client)->bound_sub : -1;
|
||||
}
|
||||
|
||||
int harness_get_bind_calls(void *client) {
|
||||
return client ? ((FakeClient *)client)->bind_calls : -1;
|
||||
}
|
||||
|
||||
int harness_get_port_binds(void *client) {
|
||||
return client ? ((FakeClient *)client)->port_binds : -1;
|
||||
}
|
||||
""")
|
||||
stub_so = tmp / "libfakeqmi.so"
|
||||
bind_so = tmp / "libmm_wds_bind_host.so"
|
||||
subprocess.run(
|
||||
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror", "-shared", "-fPIC",
|
||||
str(harness_c), "-o", str(stub_so)],
|
||||
check=True,
|
||||
)
|
||||
subprocess.run(
|
||||
["gcc", "-std=c11", "-O2", "-Wall", "-Wextra", "-Werror", "-shared", "-fPIC",
|
||||
str(WDS_BIND_SRC), "-ldl", "-o", str(bind_so)],
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Run in a fresh subprocess so RTLD_NEXT resolves against stub_so cleanly under LD_PRELOAD.
|
||||
py_probe = tmp / "run_wds_probe.py"
|
||||
py_probe.write_text(f"""
|
||||
import ctypes, os
|
||||
stub = ctypes.CDLL("{stub_so}", mode=ctypes.RTLD_GLOBAL)
|
||||
lib = ctypes.CDLL("{bind_so}", mode=ctypes.RTLD_GLOBAL)
|
||||
alloc_fn = lib.qmi_device_allocate_client_finish
|
||||
alloc_fn.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||
alloc_fn.restype = ctypes.c_void_p
|
||||
mux_fn = lib.qmi_client_wds_bind_mux_data_port
|
||||
mux_fn.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint,
|
||||
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||
data_fn = lib.qmi_client_wds_bind_data_port
|
||||
data_fn.argtypes = [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_uint,
|
||||
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p]
|
||||
stub.harness_get_bound_sub.argtypes = [ctypes.c_void_p]
|
||||
stub.harness_get_bind_calls.argtypes = [ctypes.c_void_p]
|
||||
stub.harness_get_port_binds.argtypes = [ctypes.c_void_p]
|
||||
|
||||
seen = []
|
||||
CB = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p)
|
||||
def on_port(src, res, ud):
|
||||
seen.append((src, res, ud, stub.harness_get_bound_sub(src), stub.harness_get_bind_calls(src)))
|
||||
cb_ref = CB(on_port)
|
||||
|
||||
c_wds = alloc_fn(1, None, None)
|
||||
assert stub.harness_get_bind_calls(c_wds) == 1, stub.harness_get_bind_calls(c_wds)
|
||||
assert stub.harness_get_bound_sub(c_wds) == 1, stub.harness_get_bound_sub(c_wds)
|
||||
|
||||
mux_fn(c_wds, None, 10, None, cb_ref, 0x1234)
|
||||
assert len(seen) == 1 and seen[-1][2] == 0x1234, seen
|
||||
assert seen[-1][3] == 1 and seen[-1][4] == 2, seen
|
||||
assert stub.harness_get_port_binds(c_wds) == 1, stub.harness_get_port_binds(c_wds)
|
||||
|
||||
data_fn(c_wds, None, 10, None, cb_ref, 0x5678)
|
||||
assert len(seen) == 2 and seen[-1][2] == 0x5678, seen
|
||||
assert seen[-1][3] == 1 and seen[-1][4] == 3, seen
|
||||
assert stub.harness_get_port_binds(c_wds) == 2, stub.harness_get_port_binds(c_wds)
|
||||
|
||||
c_nas = alloc_fn(3, None, None)
|
||||
assert stub.harness_get_bind_calls(c_nas) == 0, stub.harness_get_bind_calls(c_nas)
|
||||
|
||||
os.environ["BANANARCHY_WDS_SUBSCRIPTION"] = "0"
|
||||
c_disabled = alloc_fn(1, None, None)
|
||||
assert stub.harness_get_bind_calls(c_disabled) == 0, stub.harness_get_bind_calls(c_disabled)
|
||||
""")
|
||||
probe_env = os.environ.copy()
|
||||
probe_env["LD_PRELOAD"] = f"{bind_so}:{stub_so}"
|
||||
res = subprocess.run([sys.executable, str(py_probe)], env=probe_env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return fail(f"mm-wds-bind host preload test failed: {res.stderr}\n{res.stdout}")
|
||||
|
||||
print("[ok] test-lte-mobile-data: mm-wds-bind.c QMI_SERVICE_WDS PRIMARY bind & disable guard")
|
||||
return 0
|
||||
|
||||
|
||||
def test_ims_bearer_wwan0_isolation(tmp):
|
||||
bearer_log = tmp / "ims_bearer_ops.log"
|
||||
mock_bin = tmp / "bearer_bin"
|
||||
mock_bin.mkdir(parents=True, exist_ok=True)
|
||||
for tool in ("qmicli", "ip"):
|
||||
t = mock_bin / tool
|
||||
t.write_text(f"#!/bin/sh\necho '{tool}' \"$*\" >> '{bearer_log}'\nexit 0\n")
|
||||
t.chmod(0o755)
|
||||
|
||||
state_dir = tmp / "ims_state"
|
||||
state_dir.mkdir(parents=True, exist_ok=True)
|
||||
env = os.environ.copy()
|
||||
env.update({
|
||||
"PATH": f"{mock_bin}:{env.get('PATH', '')}",
|
||||
"BANANARCHY_IMS_STATE_DIR": str(state_dir),
|
||||
"BANANARCHY_IMS_NET_IFACE": "wwan0",
|
||||
})
|
||||
res = subprocess.run([str(IMS_BEARER_SH), "up", "ims"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode == 0 or "IP=\n" not in res.stdout:
|
||||
return fail(f"ims-bearer must refuse hijacking wwan0: rc={res.returncode} out={res.stdout!r}")
|
||||
|
||||
(state_dir / "bearer.env").write_text("IFACE=wwan0\nIP=10.0.0.1\n")
|
||||
res = subprocess.run([str(IMS_BEARER_SH), "down", "ims"], env=env,
|
||||
capture_output=True, text=True)
|
||||
if res.returncode != 0:
|
||||
return fail(f"ims-bearer down failed: {res.stderr}")
|
||||
ops = bearer_log.read_text() if bearer_log.exists() else ""
|
||||
if "wwan0" in ops:
|
||||
return fail(f"ims-bearer touched wwan0: {ops}")
|
||||
|
||||
print("[ok] test-lte-mobile-data: bananarchy-ims-bearer.sh never hijacks or flushes wwan0")
|
||||
return 0
|
||||
|
||||
|
||||
def test_networks_plugin_no_autoconnect_race(_tmp):
|
||||
src = NETWORKS_SRC.read_text()
|
||||
if "connection.autoconnect yes" in src:
|
||||
return fail("networks_plugin.cpp must not set connection.autoconnect yes on cellular profiles")
|
||||
save_idx = src.find("auto saveAndConnectApn")
|
||||
prep1 = src.find("mobile-data-prep", save_idx)
|
||||
add_idx = src.find("connection.autoconnect no", save_idx)
|
||||
if save_idx < 0 or add_idx < 0 or prep1 < 0 or not (save_idx < add_idx < prep1):
|
||||
return fail("saveAndConnectApn must create connection.autoconnect no before mobile-data-prep")
|
||||
row_idx = src.find("if (cellRowSel == 0)", save_idx)
|
||||
mod_idx = src.find("connection.autoconnect no", row_idx)
|
||||
prep2 = src.find("mobile-data-prep", row_idx)
|
||||
if row_idx < 0 or mod_idx < 0 or prep2 < 0 or not (row_idx < mod_idx < prep2):
|
||||
return fail("NetTab::Cellular row 0 must run connection modify autoconnect no before mobile-data-prep")
|
||||
print("[ok] test-lte-mobile-data: networks_plugin.cpp avoids autoconnect OutOfCall (15) race")
|
||||
return 0
|
||||
|
||||
|
||||
def main():
|
||||
with tempfile.TemporaryDirectory(prefix="bananarchy-lte-test-") as td:
|
||||
tmp = Path(td)
|
||||
for fn in (
|
||||
test_dual_and_single_sim_ps_domain,
|
||||
test_wds_apn_sync_and_mobile_data_prep,
|
||||
test_mm_wds_bind_preload,
|
||||
test_ims_bearer_wwan0_isolation,
|
||||
test_networks_plugin_no_autoconnect_race,
|
||||
):
|
||||
rc = fn(tmp)
|
||||
if rc != 0:
|
||||
return rc
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user