From dc0985cd9462eb30fec8464e4fc3e701c70230b5 Mon Sep 17 00:00:00 2001 From: Marsel Nenaj <201385099+marselnenaj@users.noreply.github.com> Date: Mon, 9 Nov 2026 18:39:47 +0100 Subject: [PATCH] omamobile-modem-sit: fail status probes with incomplete replies The read-only probe previously exited successfully after missing status replies. Return failure for malformed SIM status, malformed mandatory states, empty replies and request errors while always closing the client. Keep the legitimate no-SIM SMSC error 11 exception and the existing first USIM timeout. Add eight tests against the real service.probe with inert replies and advance the package version. Co-Authored-By: OpenAI Codex --- packages/omamobile-modem-sit/lib/service.py | 13 ++++ .../omamobile-modem-sit/test/test_probe.py | 74 +++++++++++++++++++ packages/omamobile-modem-sit/version | 2 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 packages/omamobile-modem-sit/test/test_probe.py diff --git a/packages/omamobile-modem-sit/lib/service.py b/packages/omamobile-modem-sit/lib/service.py index a7967edd1..df2dc7dfb 100644 --- a/packages/omamobile-modem-sit/lib/service.py +++ b/packages/omamobile-modem-sit/lib/service.py @@ -844,6 +844,7 @@ def probe(): states, radio state, packet registration, NR mode, whether an SMSC is set. No identifiers are printed; nothing is changed.""" client = Sit() + failed = False try: # The CP answered the first request 9.4 s after ONLINE on 2026-11-02. sim = client.request(0x0200, timeout=20) @@ -852,6 +853,7 @@ def probe(): [(sim[i], sim[i + 1]) for i in range(3, 3 + sim[2] * 63, 63)], flush=True) else: print('SIM status layout unexpected, length', len(sim), flush=True) + raise SystemExit(1) for ident, label in ((0x0801, 'radio state'), (0x0701, 'packet registration'), (0x0749, 'NR mode'), (0x0711, 'PS service')): try: @@ -862,16 +864,27 @@ def probe(): print(label, 'state', value[0], 'reject', value[1], 'RAT', value[3], flush=True) else: print(label, list(value[:4]), flush=True) + if ident in (0x0801, 0x0701) or not value: + failed = True except (ModemError, TimeoutError) as error: print(label, 'unavailable:', error, flush=True) + failed = True try: smsc = client.request(0x0108) print('SMSC present', bool(smsc and smsc[0]), flush=True) + if not smsc: + failed = True except (ModemError, TimeoutError) as error: print('SMSC unavailable:', error, flush=True) + # Without a SIM the CP legitimately rejects the SMSC request. + if not (sim[0] == 0 and isinstance(error, ModemError) and error.error == 11): + failed = True finally: client.close() + if failed: + raise SystemExit(1) + def main(): parser = argparse.ArgumentParser(description='Omarchy Mobile SIT RIL: calls, SMS and data registration') diff --git a/packages/omamobile-modem-sit/test/test_probe.py b/packages/omamobile-modem-sit/test/test_probe.py new file mode 100644 index 000000000..a6ccb1551 --- /dev/null +++ b/packages/omamobile-modem-sit/test/test_probe.py @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: MIT +import env # noqa: F401 (private paths before imports) +import contextlib +import io +import struct +import unittest +from unittest.mock import patch +import service + + +class ProbeTests(unittest.TestCase): + def execute(self, overrides=None, present=False): + sim = bytes([1, 0, 1, 2, 5] + [0] * 61) if present else bytes(3) + replies = {0x0200: sim, 0x0801: struct.pack('