Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/omamobile-modem-sit/lib/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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')
Expand Down
74 changes: 74 additions & 0 deletions packages/omamobile-modem-sit/test/test_probe.py
Original file line number Diff line number Diff line change
@@ -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('<I', 1), 0x0701: bytes(4),
0x0749: bytes([3]), 0x0711: bytes([1]), 0x0108: bytes([0])}
replies.update(overrides or {})
calls, closed = [], []

class Client:
def request(self, ident, **kwargs):
calls.append((ident, kwargs))
value = replies[ident]
if isinstance(value, BaseException):
raise value
return value

def close(self):
closed.append(True)

code = 0
with patch.object(service, 'Sit', Client), contextlib.redirect_stdout(io.StringIO()):
try:
service.probe()
except SystemExit as error:
code = error.code
self.assertEqual(closed, [True])
return code, calls

def test_complete_six_gets_and_first_usim_timeout(self):
code, calls = self.execute()
self.assertEqual(code, 0)
self.assertEqual([item[0] for item in calls], [0x0200, 0x0801, 0x0701, 0x0749, 0x0711, 0x0108])
self.assertEqual(calls[0][1], {'timeout': 20})

def test_malformed_sim_stops_and_closes(self):
for value in [b'', b'\0', bytes([0, 0, 1]), bytes([0, 0, 9])]:
code, calls = self.execute({0x0200: value})
self.assertEqual(code, 1)
self.assertEqual(len(calls), 1)

def test_malformed_radio_and_packet_registration_fail(self):
for ident in [0x0801, 0x0701]:
self.assertEqual(self.execute({ident: b'\1'})[0], 1)

def test_empty_replies_fail(self):
for ident in [0x0749, 0x0711, 0x0108]:
self.assertEqual(self.execute({ident: b''})[0], 1)

def test_unavailable_status_fails_but_closes(self):
for ident in [0x0801, 0x0701, 0x0749, 0x0711, 0x0108]:
self.assertEqual(self.execute({ident: TimeoutError('synthetic')})[0], 1)

def test_absent_sim_smsc_error_11_is_expected(self):
self.assertEqual(self.execute({0x0108: service.ModemError(11, b'')})[0], 0)

def test_present_sim_smsc_error_11_fails(self):
self.assertEqual(self.execute({0x0108: service.ModemError(11, b'')}, present=True)[0], 1)

def test_other_absent_sim_smsc_error_fails(self):
self.assertEqual(self.execute({0x0108: service.ModemError(2, b'')})[0], 1)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion packages/omamobile-modem-sit/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.32
0.3.33