From ec5a2f9ede42cbe0db24b604b40cb6f8905ee913 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:16:23 -0647 Subject: [PATCH 01/10] omamobile-modem-sit 0.3.5: no PDU session ID on cellular bearers, as stock The palmtop's first SIM test registered on LTE and then got status 36 (REGULAR_DEACTIVATION) for the internet bearer, twice. Our setup differed from stock's in the PDU session ID: sitd reserved one with ALLOC_PDU_SESSION and sent it at 0xf6, but Android allocates one only for a bearer over Wi-Fi (IWLAN), and the 9a's own protocol library copies the framework's value, 0 on LTE and NR, into the request. Both bearers now send 0 and the modem picks the ID; an older ownership record with an allocated ID is still released on deactivation. sit-sim logs the ID it receives and the simulator test checks for 0 with no ALLOC or REL. The 0xf1 comment now says what stock puts there: the APN-type bitmap, not an MTU. It still sends zero. --- device/cheetah/MODEM-CLIENT.md | 2 +- packages/omamobile-modem-sit/lib/data_call.py | 50 ++++++++------- packages/omamobile-modem-sit/lib/ims.py | 2 +- .../test/test_data_call.py | 64 +++++++++++++------ packages/omamobile-modem-sit/test/test_sim.py | 4 ++ packages/omamobile-modem-sit/version | 2 +- tools/sit-sim | 4 +- 7 files changed, 79 insertions(+), 49 deletions(-) diff --git a/device/cheetah/MODEM-CLIENT.md b/device/cheetah/MODEM-CLIENT.md index 07ab68723..a1f504861 100644 --- a/device/cheetah/MODEM-CLIENT.md +++ b/device/cheetah/MODEM-CLIENT.md @@ -36,7 +36,7 @@ Two packages: | `sit.py` | ported | The single-owner IPC0 transport: framing, token matching, indication queue (signal and physical-channel snapshots coalesced so telemetry can't crowd out an SMS reply). Two guards: the allow-list of requests this stack sends, and our do-not-send list (NV, identity, carrier lock, AT forwarding, VSIM, satellite) checked first, so an edit to the allow-list can't let one through. Dial and SMS sends need the owner's flags | | `sit_names.py` | ours | The 602 message names, for logs | | `bringup.py` | ported, carrier values moved to the config | The start-up order (section 1.1) | -| `data_call.py` | ported, APN from the config | Setup (983 bytes), initial attach (251), data profile (246), PDU sessions; bearer ownership recorded in RAM before each setup, never retried blindly | +| `data_call.py` | ported, APN from the config | Setup (983 bytes; no PDU session ID on cellular, as stock), initial attach (251), data profile (246); bearer ownership recorded in RAM before each setup, never retried blindly | | `ims.py` | ported (identity strings ours) | IMS stack start, hidden-menu configuration, ADD_PDN_INFO from the IMS bearer, the registration indication | | `radio_settings.py` | ported | NR mode byte (3 -> 0 keeps LTE; the original kept in RAM) | | `sms_codec.py` | ported | GSM 7-bit / UCS-2 SMS-SUBMIT with concatenation, SMS-DELIVER with the SMSC prefix the modem adds, WAP push kept as bytes | diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index b271a97c2..868482a3e 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -4,7 +4,14 @@ The APN comes from /etc/omamobile/modem-sit.conf. Ownership is recorded in RAM before a setup is sent: a setup or release with an unknown outcome -keeps its record and its PDU session, and nothing is retried blindly. +keeps its record, and nothing is retried blindly. + +A cellular setup carries no PDU session ID (0), as stock's does: Android's +data stack reserves one (ALLOC_PDU_SESSION) only for a bearer carried over +Wi-Fi (IWLAN), and stock's builder copies the framework's value into the +request unchanged, so on LTE and NR the modem picks the ID itself. Records +from 0.3.4 and earlier hold an allocated ID, which deactivate() still +releases. """ import json import os @@ -62,7 +69,8 @@ def owned_ids(): state, _ = paths(cid) if state.exists(): owned = json.loads(state.read_text()) - if owned.get('cid') != cid or not 1 <= owned.get('session', 0) <= 15: + # session 0: no PDU session ID was sent (the modem chose one). + if owned.get('cid') != cid or not 0 <= owned.get('session', -1) <= 15: raise RuntimeError('invalid bearer ownership record') result.add(cid) return result @@ -88,8 +96,11 @@ def setup_payload(cid, radio_technology, pdu_session, apn, *, ims=False, ip_type full[0xda] = IP_TYPES['ipv6'] if ims else IP_TYPES[ip_type] full[0xdb] = 2 if ims else 0 # IPv6 P-CSCF request # No handover addresses, roaming override or slice. - # MTU at 0xf1 stays zero (network/default choice). + # 0xf1 (u32) is not an MTU: stock's builder writes the APN-type bitmap + # there (the field ApnSetting::CanHandleType tests). It stays zero, as + # the stack this was ported from sent it. full[0xf5] = 2 # stock caller selects the v3/983-byte form + # 0 on cellular: no PDU session ID, the modem picks one (module docstring). struct.pack_into(' Date: Mon, 2 Nov 2026 15:16:23 -0647 Subject: [PATCH 02/10] MODEM-PLAN: status 36 is a regular deactivation, not a refused APN The modem reports Android DataFailCause numbers, which stock's RIL passes through unchanged. A refused APN is 27 or 33. 36 is REGULAR_DEACTIVATION. The 9a's runbook pointed at the APN for the status it got on 2026-11-02. --- device/cheetah/MODEM-PLAN.md | 3 ++- device/tegu/MODEM-PLAN.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/device/cheetah/MODEM-PLAN.md b/device/cheetah/MODEM-PLAN.md index a0b1a3c56..417a82c15 100644 --- a/device/cheetah/MODEM-PLAN.md +++ b/device/cheetah/MODEM-PLAN.md @@ -2605,7 +2605,8 @@ tools/phone-ssh 'omamobile-sit status; systemctl is-active omamobile-sitd; /usr/ # stop: the unit fails before "ready". The journal names the step: "SIM not usable: ..." (S1); # "No ready USIM within 120 s (...)"; "Modem registration deadline exceeded" (no service, the APN, or # the SIM not activated: check coverage and activation in the other phone); "data call did not become -# active" with its status (36 = APN refused: check the APN); a CP crash (the watcher writes +# active" with its status (Android DataFailCause numbers: 27 or 33 is a refused APN, 36 +# REGULAR_DEACTIVATION); a CP crash (the watcher writes # /var/log/omamobile/modem-crashes.log). Record step and status, then reboot before another try # rollback: `omamobile-sit radio off` (AT+CFUN=0: deregisters; on again may stall until a reboot), then # `systemctl stop omamobile-sitd`; or reboot (one UFS pass) diff --git a/device/tegu/MODEM-PLAN.md b/device/tegu/MODEM-PLAN.md index ff631ed46..f3d95ae17 100644 --- a/device/tegu/MODEM-PLAN.md +++ b/device/tegu/MODEM-PLAN.md @@ -1905,7 +1905,8 @@ tools/phone-ssh 'omamobile-sit status; systemctl is-active omamobile-sitd; /usr/ # Not the PLMN, the carrier or any number. # stop: the unit fails before "ready"; the journal names the step ("No ready USIM within 120 s", "Modem # registration deadline exceeded": coverage, activation or the APN; "data call did not become active" with -# its status, 36 = APN refused; a CP crash). Record step and code, reboot before another try (SIM-5). +# its status (Android DataFailCause numbers: 36 is REGULAR_DEACTIVATION, not a refused APN, which is 27 +# or 33); a CP crash). Record step and code, reboot before another try (SIM-5). # rollback: omamobile-sit radio off (deregisters; the radio may not come back until a reboot), then # systemctl stop omamobile-sitd; or the reboot From 7a79fb67697dccc4a2235d6c7d75bdf697a5c351 Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:27:47 -0647 Subject: [PATCH 03/10] omamobile-modem-sit 0.3.6: keep a refused setup's record, listen after it, and snapshot around the NR change A refused SETUP_DATA_CALL answered "36" three times on the palmtop on 2026-11-02 and nothing else was kept: the record beyond its first five bytes was dropped, and the two or three messages the modem sent about a second later were lost because sitd had already closed the channel. Now the whole record goes to a private file in RAM, the channel stays open five seconds while each indication is logged by name and length (a data-call list change decoded to status, CID, active and PDP type), and the registration state and data-call count are logged before and after the NR change, so the next refusal says more than a number. The probe's first request waits 20 s: the CP answered GET_SIM_STATUS 9.4 s after ONLINE. --- packages/omamobile-modem-sit/lib/bringup.py | 19 +++++++++ packages/omamobile-modem-sit/lib/data_call.py | 40 +++++++++++++++++++ packages/omamobile-modem-sit/lib/service.py | 3 +- .../omamobile-modem-sit/test/test_bringup.py | 1 + .../test/test_data_call.py | 26 ++++++++++++ packages/omamobile-modem-sit/version | 2 +- 6 files changed, 89 insertions(+), 2 deletions(-) diff --git a/packages/omamobile-modem-sit/lib/bringup.py b/packages/omamobile-modem-sit/lib/bringup.py index 718e7054b..9be800d65 100644 --- a/packages/omamobile-modem-sit/lib/bringup.py +++ b/packages/omamobile-modem-sit/lib/bringup.py @@ -58,6 +58,23 @@ def sim_lock(payload): return LOCKS.get(app[1]) + +def data_snapshot(client, label): + """Registration and the data-call list, as the modem reports them, before + and after the NR change: whether a bearer is ever listed before the + setup, and whether the change makes one appear or disappear. States, + codes and counts only.""" + try: + reg = client.request(0x0701) + calls = client.request(0x0602) + except (TimeoutError, RuntimeError) as error: + print(f'{label}: snapshot unavailable: {error}', flush=True) + return + state = (reg[0], reg[1], reg[3]) if len(reg) >= 4 else tuple(reg[:4]) + print(f'{label}: PS state, reject, RAT {state}; data calls listed {calls[0] if calls else "none"}', + flush=True) + + def packet_registered(payload, *, lte=False): return len(payload) >= 4 and payload[0] in (1, 5) and (not lte or payload[3] == 14) @@ -137,9 +154,11 @@ def usim_ready(): print('Startup: waiting for packet registration', flush=True) timeout = net.getint('register_timeout', 180) wait_for(service, lambda: packet_registered(client.request(0x0701)), timeout, stopped) + data_snapshot(client, 'before the NR change') if net.get('nr', 'off') == 'off': nr_mode(client) wait_for(service, lambda: packet_registered(client.request(0x0701), lte=True), 120, stopped) + data_snapshot(client, 'after the NR change') service.stage('data') activate(client, apn, ip_type=ip_type) service.pump() diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index 868482a3e..04a08d562 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -18,8 +18,10 @@ from pathlib import Path import re import struct +import time from paths import RUN +from sit_names import NAMES STATE = RUN / 'data-session.json' RESPONSE = RUN / 'data-call-response.bin' @@ -142,6 +144,38 @@ def provision_default_profile(client, apn, ip_type='ipv4v6'): print('default data profile accepted', flush=True) + +def listen_after_failure(client, seconds=5): + """After a refused setup, keep the channel open a few seconds and log + what the modem sends next: on 2026-11-02 two or three messages arrived + about a second after each status 36 and were dropped because the channel + had already closed. Message names and lengths only; for a data-call list + change, the per-record status, CID, active and PDP type, nothing else.""" + deadline = time.monotonic() + seconds + seen = 0 + while True: + remaining = deadline - time.monotonic() + if remaining <= 0: + break + packet = client.next_indication(min(1, remaining)) + if packet is None: + continue + seen += 1 + message, length = struct.unpack_from(' 1: + count = payload[0] + size = (len(payload) - 1) // count + records = [] + for index in range(count): + record = payload[1 + index * size:1 + (index + 1) * size] + if len(record) >= 5: + records.append(struct.unpack_from('= 3 and sim[2] <= 8 and len(sim) >= 3 + sim[2] * 63: print('SIM card state', sim[0], 'applications', [(sim[i], sim[i + 1]) for i in range(3, 3 + sim[2] * 63, 63)], flush=True) diff --git a/packages/omamobile-modem-sit/test/test_bringup.py b/packages/omamobile-modem-sit/test/test_bringup.py index e8f3e1911..a347908b7 100644 --- a/packages/omamobile-modem-sit/test/test_bringup.py +++ b/packages/omamobile-modem-sit/test/test_bringup.py @@ -52,6 +52,7 @@ def test_failed_data_setup_never_attempts_ims(self): with patch.object(bringup, 'wait_for'), patch.object(bringup, 'radio'), \ patch.object(bringup, 'initial_attach'), patch.object(bringup, 'provision_default_profile'), \ patch.object(bringup, 'nr_mode'), patch.object(bringup, 'activate', side_effect=TimeoutError), \ + patch.object(bringup, 'data_snapshot'), \ patch.object(bringup, 'start_stack') as stack, patch.object(bringup, 'register') as register: with self.assertRaises(TimeoutError): bringup.start(service, SETTINGS) diff --git a/packages/omamobile-modem-sit/test/test_data_call.py b/packages/omamobile-modem-sit/test/test_data_call.py index 278a9b5e3..a5214248a 100644 --- a/packages/omamobile-modem-sit/test/test_data_call.py +++ b/packages/omamobile-modem-sit/test/test_data_call.py @@ -19,6 +19,9 @@ def __init__(self, status=0, fail_release=False): self.status = status self.fail_release = fail_release + def next_indication(self, timeout=1): + return None + def request(self, ident, payload=b'', **kwargs): self.sent.append((ident, payload)) if ident == 0x0701: @@ -63,6 +66,29 @@ def test_rejected_setup_leaves_no_ownership(self): self.assertFalse(self.state.exists()) self.assertFalse(self.response.exists()) + def test_rejected_setup_keeps_the_record_and_listens(self): + # The refused record goes to a private file, and the modem's next + # messages are logged by name with a data-call list decoded to + # status, CID, active and PDP type. + modem = Modem(status=36) + record = bytearray(292) + struct.pack_into(' Date: Mon, 2 Nov 2026 15:29:52 -0647 Subject: [PATCH 04/10] omamobile-modem-sit 0.3.7: send the APN-type bitmap in SETUP_DATA_CALL, as stock The 983-byte setup request carries the APN's supported-types bitmap as a u32 at 0xf1: the Pixel 9a's stock builder copies ApnSetting's mask there (vendor.radio.base ApnSetting::SetSupportedTypesBitmask, member +0x160; the stream library's builders write it at 0xf1). Ours sent 0 there, under a comment calling it an MTU, and the 9a's modem answered every internet setup with status 36 (REGULAR_DEACTIVATION) on 2026-11-02, three times, with the session ID fixed in between. The internet bearer now sends DEFAULT (1) and the IMS bearer IMS (0x40). The attach request copies the setup's first 233 bytes, so it keeps bytes 0xf1 to 0xf4 zero explicitly: stock's 251-byte attach builder leaves them zero. Its roaming PDP type at 0xf8 is now named for what it is. --- packages/omamobile-modem-sit/lib/data_call.py | 16 +++++++++++----- .../omamobile-modem-sit/test/test_data_call.py | 11 +++++++++++ packages/omamobile-modem-sit/version | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index 04a08d562..65a5e0c75 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -98,9 +98,13 @@ def setup_payload(cid, radio_technology, pdu_session, apn, *, ims=False, ip_type full[0xda] = IP_TYPES['ipv6'] if ims else IP_TYPES[ip_type] full[0xdb] = 2 if ims else 0 # IPv6 P-CSCF request # No handover addresses, roaming override or slice. - # 0xf1 (u32) is not an MTU: stock's builder writes the APN-type bitmap - # there (the field ApnSetting::CanHandleType tests). It stays zero, as - # the stack this was ported from sent it. + # 0xf1 (u32): the APN-type bitmap, as stock's builder copies it from + # ApnSetting's supported types (vendor.radio.base + # ApnSetting::SetSupportedTypesBitmask, member +0x160; the 983-byte + # builder writes it at 0xf1). DEFAULT for the internet bearer, IMS for + # the IMS one. Until 0.3.6 this was sent as 0 (taken for an MTU), and + # the 9a's modem answered every internet setup with status 36. + struct.pack_into(' Date: Mon, 2 Nov 2026 15:38:31 -0647 Subject: [PATCH 05/10] omamobile-modem-sit 0.3.8: let the modem settle after the data permission before the setup On 2026-11-02 five setups in a row were answered with status 36 within 150 ms, each followed within a second by three IND_REG_FAILED, two IND_NTW_STATE_CHANGED and an empty data-call list: the modem was re-attaching around the request, whatever its cause. The setup now waits until the modem has sent nothing for three seconds after the data permission (at most twenty), logging each indication by name and keeping the raw packets in a private file for decoding, then reads the registration again and waits up to a minute for it if it was lost, and only then sends the setup. --- packages/omamobile-modem-sit/lib/data_call.py | 83 ++++++++++++++++--- .../test/test_data_call.py | 27 +++++- packages/omamobile-modem-sit/version | 2 +- 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index 65a5e0c75..5a74f0114 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -151,6 +151,61 @@ def provision_default_profile(client, apn, ip_type='ipv4v6'): + +# After the data permission is switched on, the modem is given time to say +# what it does about it before the setup goes out: on 2026-11-02 every setup +# was answered 36 within 150 ms and was followed within a second by three +# IND_REG_FAILED and two IND_NTW_STATE_CHANGED, so the modem was re-attaching +# around the request. The wait ends after SETTLE_QUIET seconds without an +# indication, or at SETTLE_LIMIT. +SETTLE_QUIET = 3 +SETTLE_LIMIT = 20 + + +def keep_packet(packet): + """Append a raw indication to a private file in RAM (it may carry the + PLMN or cell identity), length-prefixed, for decoding later.""" + path = RESPONSE.with_name('indications.bin') + fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0o600) + try: + os.write(fd, struct.pack(' 1: + count = payload[0] + size = (len(payload) - 1) // count + records = [] + for index in range(count): + record = payload[1 + index * size:1 + (index + 1) * size] + if len(record) >= 5: + records.append(struct.unpack_from('= deadline or now - last >= SETTLE_QUIET: + break + packet = client.next_indication(min(.5, deadline - now)) + if packet is None: + continue + seen += 1 + last = time.monotonic() + keep_packet(packet) + print(f'{label}: {describe(packet)}', flush=True) + print(f'{label}: {seen} indication(s), then quiet' if seen else f'{label}: quiet', flush=True) + def listen_after_failure(client, seconds=5): """After a refused setup, keep the channel open a few seconds and log what the modem sends next: on 2026-11-02 two or three messages arrived @@ -167,19 +222,8 @@ def listen_after_failure(client, seconds=5): if packet is None: continue seen += 1 - message, length = struct.unpack_from(' 1: - count = payload[0] - size = (len(payload) - 1) // count - records = [] - for index in range(count): - record = payload[1 + index * size:1 + (index + 1) * size] - if len(record) >= 5: - records.append(struct.unpack_from('= 4 and state[0] in (1, 5): + break + if second == 0: + print('registration lost after allowing data; waiting for it', flush=True) + time.sleep(1) + else: + raise RuntimeError('PS network is not registered after allowing data') + print('registration before the setup: PS state, reject, RAT', (state[0], state[1], state[3]), flush=True) # No ALLOC_PDU_SESSION on cellular (module docstring): session 0. session = 0 # Persist ownership before setup. A timeout has an unknown outcome: the diff --git a/packages/omamobile-modem-sit/test/test_data_call.py b/packages/omamobile-modem-sit/test/test_data_call.py index f1128b3fa..e7858c38d 100644 --- a/packages/omamobile-modem-sit/test/test_data_call.py +++ b/packages/omamobile-modem-sit/test/test_data_call.py @@ -48,7 +48,9 @@ def setUp(self): self.state = root / 'owned.json' self.response = root / 'response.bin' self.patches = [patch.object(data_call, 'STATE', self.state), - patch.object(data_call, 'RESPONSE', self.response)] + patch.object(data_call, 'RESPONSE', self.response), + patch.object(data_call, 'SETTLE_QUIET', 0), + patch.object(data_call, 'SETTLE_LIMIT', 0)] for item in self.patches: item.start() @@ -76,7 +78,8 @@ def test_rejected_setup_keeps_the_record_and_listens(self): indication = struct.pack(' Date: Mon, 2 Nov 2026 16:00:15 -0647 Subject: [PATCH 06/10] device/tegu MODEM-PLAN, DEVICES: the SIM test passed on 2026-11-02 Six CP starts over six boots, all attended: the SIM read, LTE registration every time, five data requests refused with status 36, then, with the RIL letting the modem settle after the data permission, the internet and IMS bearers up, mobile data over rmnet0, and texts both ways. The record is under the runbook; the Modem cell stays WIP with what works on the owner's kernel. --- device/tegu/MODEM-PLAN.md | 78 ++++++++++++++++++++++++++++++++++++++- docs/DEVICES.md | 2 +- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/device/tegu/MODEM-PLAN.md b/device/tegu/MODEM-PLAN.md index f3d95ae17..58009f050 100644 --- a/device/tegu/MODEM-PLAN.md +++ b/device/tegu/MODEM-PLAN.md @@ -20,8 +20,12 @@ SoC within minutes. Kept on (), five sessions ran with no reset, the longest 30 minutes and 3759 link cycles (G3-L1). -Left: the GNSS and CPIF drivers aren't in the published kernel, and GNSS -still starts by hand. Next: the SIM. +**The SIM (2026-11-02): registered on LTE, mobile data up, texts both +ways** on the owner's kernel, with `omamobile-modem-sit` 0.3.8 (its first +five data requests were refused with status 36 until the RIL let the +modem settle after the data permission; "SIM test results" below). +Left: the GNSS and CPIF drivers aren't in the published kernel, GNSS and +the modem still start by hand, and calls have no audio route. The staged plan (sections F, K, U and runbooks M0.2-M6, G1-G4) is below, with each step's results under it. Kernel branches `omamobile-tegu-modem` and `omamobile-tegu-gnssif` (section K). @@ -1952,6 +1956,76 @@ tools/phone-ssh 'test -d /sys/module/cpif && echo cpif-loaded || echo cpif-not-l # pass: cpif-not-loaded; the SIM can stay in the tray ``` +#### SIM test results (2026-11-02, `7.3.0-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty`) + +The prepaid nano-SIM arrived a day early and the test ran the same +afternoon, six CP starts over six boots, all attended on the charger, with +`omamobile-modem` 0.1.10 (installed with `pacman -U -dd`: the package +depends on `omamobile-device-cheetah`, which conflicts with +`omamobile-device-tegu`; the `omamobile-modem-policy` virtual planned in +raven's plan is the fix) and the carrier's published APN, IPv4v6, no +authentication, `ims = yes`, `nr = off`. No identifiers here: the carrier +is a US MVNO on a large LTE network. + +- **SIM-0 to SIM-4 passed.** The NV partitions matched the 2026-10-28 + backup and read `ro=1`, unmounted, before and after every boot. +- **SIM-5 passed six times:** CP ONLINE in about 9 s, UFS error handler 0. +- **SIM-6:** the first probe timed out on GET_SIM_STATUS and the CP + answered it 9.4 s later, so the probe's first request now waits 20 s + (0.3.6). Then: card state 1, applications (2, 5) and (5, 5) (a USIM and an + ISIM, both ready), radio state 10, SMSC present. +- **SIM-7 failed five times the same way, then passed.** Each time: PS + registration state 1, reject 0, RAT 14 (LTE, at home) within a few + seconds; `SET_INITIAL_ATTACH_APN` and `SET_DATA_PROFILE` error 0; NR mode + set to 0; then `SETUP_DATA_CALL` answered within 150 ms with status 36 + (Android's REGULAR_DEACTIVATION, not "APN refused"), CID 1, active 0, + and `GET_DATA_CALL_LIST` empty before and after. Three changes were + tried one at a time, each on its own boot: + 1. 0.3.5: no PDU session ID on cellular bearers (stock sends 0; sitd + reserved one). Still 36. + 2. 0.3.7: the APN-type bitmap at 0xf1 of the setup request (stock sends + the APN's types; sitd sent 0, taken for an MTU). Still 36. + 3. 0.3.8: the recording build (0.3.6) had shown that about a second + after every refusal the modem sent three IND_REG_FAILED, two + IND_NTW_STATE_CHANGED and an empty data-call list, and that it was + quiet before the data permission: it re-attaches when + SET_MOBILE_DATA_STATE and SET_PS_SERVICE are written, and the setup + always landed inside that. The RIL now waits until the modem has + been quiet for 3 s after the permission (at most 20 s), reads the + registration again, and then sends the setup. On its first run the + six indications came and went in the wait, the registration read 1, + 0, 14 again, and the setup answered status 0, CID 1, active 1, PDP + type 3 (IPv4v6). The IMS bearer followed (status 0, CID 2, PDP type + 2), AIMS registration came back "LTE, IMS voice and SMS registered", + and the RIL reported "Calls and SMS service ready". + The first two changes stay in: they match stock's requests, and the + 9a's stock libraries (verified against the owner's `vendor_a.img`) write + both fields that way. +- **SIM-8 passed:** `omamobile-sit data on` brought `rmnet0` up with an + address and the default route at metric 700; three pings over it to + 9.9.9.9 answered (78 ms average); an HTTPS GET over it returned 200. +- **SIM-9 passed:** the carrier's welcome text had already arrived during + SIM-7 ("SMS stored and acknowledged"), the owner's text from another + phone arrived within seconds, and a text sent from the palmtop + (`omamobile-sit sms send`) reached the owner's phone. A text sent to + the palmtop's own number was accepted ("sent") and never came back, + which is common on this network. +- **SIM-10:** no call; the 9a has no audio route. +- **SIM-11 passed:** radio off, the RIL stopped, an attended reboot + (the unit's stop powered the CP off during shutdown), then M0.1: the + six partitions unchanged, `cpif` not loaded, UFS error handler 0. + +The run kept the full refused record (292 bytes: status 36, CID 1, the +IPC extension version at 132-133, the suggested retry time at 235-242 as +an s64) and the raw indications of the passing run in +`logs/tegu-sim-20261102/private/` (off the repository). The one open +question is what the modem's re-attach after the data permission is +about: the IND_REG_FAILED causes are in that file, decodable with the +layout from the stock library (domain at 0x0e, main cause 0x0f, +additional cause 0x10). Stock sends the data permission at radio-on, long +before any setup, so the better fix may be to move those two requests +earlier and keep the wait as a safety net. + **Unqualified after a passing run:** suspend with the modem on (the inhibitor stays; M6, two reboots with the CP up: this runbook's attended reboots count toward it but don't pass it; a power-off from Linux with the diff --git a/docs/DEVICES.md b/docs/DEVICES.md index 4f4adbbd4..d480b273c 100644 --- a/docs/DEVICES.md +++ b/docs/DEVICES.md @@ -25,7 +25,7 @@ The status of each device, as verified on real hardware. Rows in the matrix have | Pixel 6 | oriole | gs101 (Tensor G1) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); native test image on one phone; slot B marked successful and `vbmeta_b` verification turned off, both without project approval; see notes) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); guarded `userdata` root on test image) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); connected output on test image) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); Panfrost render node present) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); touchscreen detected; input not checked by smoke) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); gpio-keys detected; input not checked by smoke) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); USB network and SSH on test image) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); link up; traffic not checked by smoke) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); controller powered; pairing not checked) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); charge and temperature reported) | WIP ([unpublished kernel/packages](../device/oriole/NOTES.md#2026-10-31-build-provenance-and-recovery-limits); charging reported; control not checked) | no | no | no | no | no | no | no | no | no | no | no | | Pixel 4 | flame | SM8150 (Snapdragon 855) | testing (temporary RAM boot; [notes](../device/flame/BRINGUP-M1.md)) | testing (RAM probe; all UFS read-only) | testing (1080x2280 console; software desktop in separate Arch payload) | testing (separate Arch payload; FD640 contexts, llvmpipe desktop) | testing (separate Arch payload; events and PIN unlock verified) | no | testing (NCM + ACM + SSH; sustained transfers can disconnect) | testing (guarded RAM scan; association untested) | no | no | no | no | no | no | - | no | no | no | no | no | no | - | | Pixel 4 XL ([notes](../device/coral/NOTES.md)) | coral | SM8150 (Snapdragon 855) | WIP (direct ABL v2 boot on the test handset's slot A; slot-B install and §3.1 entry pending; [notes](../device/coral/BRINGUP-M1.md)) | testing (read-only `blockdev` guard + RAM `overlayfs`) | testing (1440x3040@60Hz S6E3HC2 DSC 1.1 KMS, DPMS, brightness) | testing (Adreno 640 / FD640 Mesa Freedreno, Hyprland) | testing (FTS SPI multitouch + read-only flash guard) | testing (power via `qcom-pon` + volume via `gpio-keys`) | testing (CDC ECM + ACM + SSH; stays up with host USB switched off) | testing (`WCN3990` `ath10k_snoc` + `rmtfs -r`, WPA2/DHCP/HTTPS; radio sessions ran before the modem baseline) | WIP (`WCN3990` `hci_qca` `hci0` up + BLE scan; audio/pairing open) | WIP (PM8150B ADC `VBAT_SNS` voltage + FG temp; aftermarket pack on test unit: no reply from `1-0036`) | testing (PM8150B SMB5 charger with `4.20 V` / `500 mA` kernel clamp) | testing (`CS40L25A` I2C click waveform) | testing (PM8150L flash LEDs + quick-settings tile) | no | - | testing (QDSP6 + dual `CS35L36` amps capped at `-26 dB` + `IA8508` SPI mic DSP) | testing (`SLPI` + `fastrpc` + RAM-backed `hexagonrpcd` + QMI SSC: 7 sensors + Soli radar) | WIP (`MPSS` boots with `rmtfs -r` + patched `tqftpserv`, SIM detected; no IPA/voice yet; radio sessions ran before the modem baseline) | no | testing (`CAMSS` + `IMX363`, `IMX481`, `IMX520`, dual `OV7251` NIR; `libcamera` softISP) | no | - | -| Pixel 9a ([notes](../device/tegu/NOTES.md)) | tegu | zumapro (Tensor G4) | works ([#28](https://github.com/derekross/omarchy-mobile/issues/28): native boot from slot B, the Arch root on `userdata`, `omamobile-device-tegu`; slot B was marked successful by hand on 2026-10-28 with the `devinfo` write approved on 2026-10-22, now on hold ([#125](https://github.com/derekross/omarchy-mobile/pull/125)), unmarked by the 10-31 fastboot recovery and marked again on 2026-10-31 during the hold ([record](../device/tegu/NOTES.md#2026-10-31-a-fastboot-flash-of-slot-b-cleared-its-successful-mark-and-b-was-marked-again)), and the package does not mark it; unpublished kernel: the SoC and board device tree is [kernel #81](https://github.com/derekross/linux-omarchy-mobile/pull/81), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (UFS behind the read-only guard; unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (120 Hz through gs-decon; the panel driver [kernel #89](https://github.com/derekross/linux-omarchy-mobile/pull/89), 120 Hz [kernel #88](https://github.com/derekross/linux-omarchy-mobile/pull/88), merged, the display DT, merged with [kernel #96](https://github.com/derekross/linux-omarchy-mobile/pull/96); brightness, DPMS off and on and the 60/120 Hz switch on the boot of [kernel #125](https://github.com/derekross/linux-omarchy-mobile/pull/125), merged, which also checks the panel's ID; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on), [brightness record](../device/tegu/NOTES.md#2026-11-01-afternoon-and-evening-wi-fi-from-the-package-the-wake-and-the-replug-storage-idle-the-panel-id)) | works (Panthor, the desktop renders, runtime suspend when idle; this boot runs at a fixed 160 MHz, so frequency scaling and the GPU thermal zone count as in review, [kernel #85](https://github.com/derekross/linux-omarchy-mobile/pull/85) in review, [kernel #87](https://github.com/derekross/linux-omarchy-mobile/pull/87) in review; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (Synaptics S3908 over SPI, [kernel #81](https://github.com/derekross/linux-omarchy-mobile/pull/81), merged; survives sleep, [kernel #82](https://github.com/derekross/linux-omarchy-mobile/pull/82), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (gpio-keys: power and volume; the power key wakes from sleep; unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (CDC NCM and SSH; reconnects after a replug, `omamobile-tegu-usb-rescue`, also after a replug the gadget didn't see ([#280](https://github.com/derekross/omarchy-mobile/pull/280); [the replug record](../device/tegu/NOTES.md#2026-10-28-what-the-device-tables-claims-rest-on)); [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (BCM4383 on PCIe channel 1 through the shared gs201 host and zuma PHY, [kernel #178](https://github.com/derekross/linux-omarchy-mobile/pull/178) on [kernel #156](https://github.com/derekross/linux-omarchy-mobile/pull/156), in review, and brcmfmac, [kernel #56](https://github.com/derekross/linux-omarchy-mobile/pull/56) in review; started at boot by `omamobile-device-tegu` 0.2.4 ([#238](https://github.com/derekross/omarchy-mobile/pull/238)) with the extractor's firmware; WPA2 with iwd, kept loaded across sleep by the package's sleep hook; [record](../device/tegu/NOTES.md#2026-11-01-afternoon-and-evening-wi-fi-from-the-package-the-wake-and-the-replug-storage-idle-the-panel-id)) | works (hci_uart on the bootloader's address, BlueZ, A2DP; [kernel #94](https://github.com/derekross/linux-omarchy-mobile/pull/94); unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (MAX77779 gauge with temperature, current and time estimates through UPower; [kernel #66](https://github.com/derekross/linux-omarchy-mobile/pull/66); unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (the MAX77779 charger binds from the device tree, [kernel #161](https://github.com/derekross/linux-omarchy-mobile/pull/161), merged, built by [#227](https://github.com/derekross/omarchy-mobile/pull/227); the charge limit in `omamobile-device-tegu` 0.2.3 holds charging off at the limit through `charge_behaviour` and lets it run again 5 below; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (CS40L26A through feedbackd, with brownout prevention, [kernel #95](https://github.com/derekross/linux-omarchy-mobile/pull/95); its DT [kernel #96](https://github.com/derekross/linux-omarchy-mobile/pull/96), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (LM3644, 25 steps to 75 mA, quick-settings tile; its DT [kernel #96](https://github.com/derekross/linux-omarchy-mobile/pull/96), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | testing (Omarchy's Location switch serves fixes from GPS, Galileo, BeiDou and GLONASS once the modem is up, started by hand: a 30-minute session through the switch on 2026-11-01 (omamobile-gnss 0.2.5's start, the modem link left to cycle) ran clean, 1763 of 1765 GGA sentences fixed, first fix 37 s after a client connected; needs [kernel #150](https://github.com/derekross/linux-omarchy-mobile/pull/150), merged, the PERIC0 clock fix [kernel #172](https://github.com/derekross/linux-omarchy-mobile/pull/172) in review (without it the modem link hung the palmtop within minutes) and [#114](https://github.com/derekross/omarchy-mobile/pull/114); [plan](../device/tegu/MODEM-PLAN.md), record with [#202](https://github.com/derekross/omarchy-mobile/pull/202)) | works (audio and sensor DSP through the GSA and Trusty, 93 services, started at boot by `omamobile-device-tegu` 0.2.3 from the device tree, [kernel #162](https://github.com/derekross/linux-omarchy-mobile/pull/162) in review; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (the TAS2572 amplifiers and the microphone through the AoC card and PipeWire, at boot with the AoC: a tone from the speaker, the microphone at -32 dBFS; speakers at a -10 dB ceiling; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (accelerometer, light, proximity, compass and gyroscope through the AoC and the sensor proxy, at boot with the AoC; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | WIP (ONLINE with IPC on an unpublished kernel, no SIM yet; [plan](../device/tegu/MODEM-PLAN.md)) | works (NXP ST54L through nxp-nci, its clock pad from the PMU ([kernel #104](https://github.com/derekross/linux-omarchy-mobile/pull/104) and [kernel #105](https://github.com/derekross/linux-omarchy-mobile/pull/105), merged, with [kernel #131](https://github.com/derekross/linux-omarchy-mobile/pull/131), merged), loaded at boot by `omamobile-device-tegu` 0.2.3 with neard and the link opener: polls with no I2C errors and read a payment card; polling stops before sleep; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (main, ultrawide and front from the device tree, [kernel #164](https://github.com/derekross/linux-omarchy-mobile/pull/164) in review, with [kernel #63](https://github.com/derekross/linux-omarchy-mobile/pull/63) and [kernel #103](https://github.com/derekross/linux-omarchy-mobile/pull/103) in review: their drivers load at boot with nothing by hand, libcamera lists all three, and each streams, main at 19 fps and the others at 30 fps at 1280x960; basic picture quality through libcamera's software ISP; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | testing (s2idle when asked for, or through the shell's auto-sleep with the `omamobile-sleep` toggle on, which ships off; the power key lights the lock screen on the first press ([#268](https://github.com/derekross/omarchy-mobile/pull/268), [#275](https://github.com/derekross/omarchy-mobile/pull/275)), and the RTC wakes it; on 2026-11-01 thirty attended 120 s sleeps ([plan](../device/tegu/SLEEP-PLAN.md) S1) and a day of real use with auto-sleep on ([record](../device/tegu/NOTES.md#2026-11-01-afternoon-and-evening-wi-fi-from-the-package-the-wake-and-the-replug-storage-idle-the-panel-id)) all woke, but five test sleeps from 10-28 to the morning of 11-01 did not (one in 21 on the clock-fix kernel), so sleep tests stay attended ([plan](../device/tegu/SLEEP-PLAN.md) S1); the drain is about 300 mA asleep, the same as awake with the screen off, because nothing below the CPUs sleeps yet; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (opt-in) (enrolls, matches, refuses other fingers and unlocks the lock screen through Trusty and `omamobile-fingerprint`, 2026-10-29; the sensor binds from the device tree, [kernel #165](https://github.com/derekross/linux-omarchy-mobile/pull/165) in review, with [kernel #126](https://github.com/derekross/linux-omarchy-mobile/pull/126), merged; opt-in as on the 7 Pro, because the service's first run writes Trusty's secure storage; [plan](../device/tegu/FINGERPRINT-PLAN.md), [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | +| Pixel 9a ([notes](../device/tegu/NOTES.md)) | tegu | zumapro (Tensor G4) | works ([#28](https://github.com/derekross/omarchy-mobile/issues/28): native boot from slot B, the Arch root on `userdata`, `omamobile-device-tegu`; slot B was marked successful by hand on 2026-10-28 with the `devinfo` write approved on 2026-10-22, now on hold ([#125](https://github.com/derekross/omarchy-mobile/pull/125)), unmarked by the 10-31 fastboot recovery and marked again on 2026-10-31 during the hold ([record](../device/tegu/NOTES.md#2026-10-31-a-fastboot-flash-of-slot-b-cleared-its-successful-mark-and-b-was-marked-again)), and the package does not mark it; unpublished kernel: the SoC and board device tree is [kernel #81](https://github.com/derekross/linux-omarchy-mobile/pull/81), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (UFS behind the read-only guard; unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (120 Hz through gs-decon; the panel driver [kernel #89](https://github.com/derekross/linux-omarchy-mobile/pull/89), 120 Hz [kernel #88](https://github.com/derekross/linux-omarchy-mobile/pull/88), merged, the display DT, merged with [kernel #96](https://github.com/derekross/linux-omarchy-mobile/pull/96); brightness, DPMS off and on and the 60/120 Hz switch on the boot of [kernel #125](https://github.com/derekross/linux-omarchy-mobile/pull/125), merged, which also checks the panel's ID; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on), [brightness record](../device/tegu/NOTES.md#2026-11-01-afternoon-and-evening-wi-fi-from-the-package-the-wake-and-the-replug-storage-idle-the-panel-id)) | works (Panthor, the desktop renders, runtime suspend when idle; this boot runs at a fixed 160 MHz, so frequency scaling and the GPU thermal zone count as in review, [kernel #85](https://github.com/derekross/linux-omarchy-mobile/pull/85) in review, [kernel #87](https://github.com/derekross/linux-omarchy-mobile/pull/87) in review; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (Synaptics S3908 over SPI, [kernel #81](https://github.com/derekross/linux-omarchy-mobile/pull/81), merged; survives sleep, [kernel #82](https://github.com/derekross/linux-omarchy-mobile/pull/82), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (gpio-keys: power and volume; the power key wakes from sleep; unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (CDC NCM and SSH; reconnects after a replug, `omamobile-tegu-usb-rescue`, also after a replug the gadget didn't see ([#280](https://github.com/derekross/omarchy-mobile/pull/280); [the replug record](../device/tegu/NOTES.md#2026-10-28-what-the-device-tables-claims-rest-on)); [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (BCM4383 on PCIe channel 1 through the shared gs201 host and zuma PHY, [kernel #178](https://github.com/derekross/linux-omarchy-mobile/pull/178) on [kernel #156](https://github.com/derekross/linux-omarchy-mobile/pull/156), in review, and brcmfmac, [kernel #56](https://github.com/derekross/linux-omarchy-mobile/pull/56) in review; started at boot by `omamobile-device-tegu` 0.2.4 ([#238](https://github.com/derekross/omarchy-mobile/pull/238)) with the extractor's firmware; WPA2 with iwd, kept loaded across sleep by the package's sleep hook; [record](../device/tegu/NOTES.md#2026-11-01-afternoon-and-evening-wi-fi-from-the-package-the-wake-and-the-replug-storage-idle-the-panel-id)) | works (hci_uart on the bootloader's address, BlueZ, A2DP; [kernel #94](https://github.com/derekross/linux-omarchy-mobile/pull/94); unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (MAX77779 gauge with temperature, current and time estimates through UPower; [kernel #66](https://github.com/derekross/linux-omarchy-mobile/pull/66); unpublished kernel; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (the MAX77779 charger binds from the device tree, [kernel #161](https://github.com/derekross/linux-omarchy-mobile/pull/161), merged, built by [#227](https://github.com/derekross/omarchy-mobile/pull/227); the charge limit in `omamobile-device-tegu` 0.2.3 holds charging off at the limit through `charge_behaviour` and lets it run again 5 below; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (CS40L26A through feedbackd, with brownout prevention, [kernel #95](https://github.com/derekross/linux-omarchy-mobile/pull/95); its DT [kernel #96](https://github.com/derekross/linux-omarchy-mobile/pull/96), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (LM3644, 25 steps to 75 mA, quick-settings tile; its DT [kernel #96](https://github.com/derekross/linux-omarchy-mobile/pull/96), merged; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | testing (Omarchy's Location switch serves fixes from GPS, Galileo, BeiDou and GLONASS once the modem is up, started by hand: a 30-minute session through the switch on 2026-11-01 (omamobile-gnss 0.2.5's start, the modem link left to cycle) ran clean, 1763 of 1765 GGA sentences fixed, first fix 37 s after a client connected; needs [kernel #150](https://github.com/derekross/linux-omarchy-mobile/pull/150), merged, the PERIC0 clock fix [kernel #172](https://github.com/derekross/linux-omarchy-mobile/pull/172) in review (without it the modem link hung the palmtop within minutes) and [#114](https://github.com/derekross/omarchy-mobile/pull/114); [plan](../device/tegu/MODEM-PLAN.md), record with [#202](https://github.com/derekross/omarchy-mobile/pull/202)) | works (audio and sensor DSP through the GSA and Trusty, 93 services, started at boot by `omamobile-device-tegu` 0.2.3 from the device tree, [kernel #162](https://github.com/derekross/linux-omarchy-mobile/pull/162) in review; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (the TAS2572 amplifiers and the microphone through the AoC card and PipeWire, at boot with the AoC: a tone from the speaker, the microphone at -32 dBFS; speakers at a -10 dB ceiling; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (accelerometer, light, proximity, compass and gyroscope through the AoC and the sensor proxy, at boot with the AoC; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | WIP (on the owner's kernel, 2026-11-02: registered on LTE, mobile data over `rmnet0` and texts both ways with `omamobile-modem-sit` 0.3.8 ([#356](https://github.com/derekross/omarchy-mobile/pull/356)); the package doesn't start the modem, CPIF isn't in the published kernel, and calls have no audio route; [plan](../device/tegu/MODEM-PLAN.md), [record](../device/tegu/MODEM-PLAN.md#sim-test-results-2026-11-02-730-rc6-omamobile-tegu-s2mpg15-m1-g991042e2eff3-dirty)) | works (NXP ST54L through nxp-nci, its clock pad from the PMU ([kernel #104](https://github.com/derekross/linux-omarchy-mobile/pull/104) and [kernel #105](https://github.com/derekross/linux-omarchy-mobile/pull/105), merged, with [kernel #131](https://github.com/derekross/linux-omarchy-mobile/pull/131), merged), loaded at boot by `omamobile-device-tegu` 0.2.3 with neard and the link opener: polls with no I2C errors and read a payment card; polling stops before sleep; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | works (main, ultrawide and front from the device tree, [kernel #164](https://github.com/derekross/linux-omarchy-mobile/pull/164) in review, with [kernel #63](https://github.com/derekross/linux-omarchy-mobile/pull/63) and [kernel #103](https://github.com/derekross/linux-omarchy-mobile/pull/103) in review: their drivers load at boot with nothing by hand, libcamera lists all three, and each streams, main at 19 fps and the others at 30 fps at 1280x960; basic picture quality through libcamera's software ISP; [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | testing (s2idle when asked for, or through the shell's auto-sleep with the `omamobile-sleep` toggle on, which ships off; the power key lights the lock screen on the first press ([#268](https://github.com/derekross/omarchy-mobile/pull/268), [#275](https://github.com/derekross/omarchy-mobile/pull/275)), and the RTC wakes it; on 2026-11-01 thirty attended 120 s sleeps ([plan](../device/tegu/SLEEP-PLAN.md) S1) and a day of real use with auto-sleep on ([record](../device/tegu/NOTES.md#2026-11-01-afternoon-and-evening-wi-fi-from-the-package-the-wake-and-the-replug-storage-idle-the-panel-id)) all woke, but five test sleeps from 10-28 to the morning of 11-01 did not (one in 21 on the clock-fix kernel), so sleep tests stay attended ([plan](../device/tegu/SLEEP-PLAN.md) S1); the drain is about 300 mA asleep, the same as awake with the screen off, because nothing below the CPUs sleeps yet; [record](../device/tegu/NOTES.md#2026-10-29-the-device-package-boot-and-what-this-row-rests-on)) | works (opt-in) (enrolls, matches, refuses other fingers and unlocks the lock screen through Trusty and `omamobile-fingerprint`, 2026-10-29; the sensor binds from the device tree, [kernel #165](https://github.com/derekross/linux-omarchy-mobile/pull/165) in review, with [kernel #126](https://github.com/derekross/linux-omarchy-mobile/pull/126), merged; opt-in as on the 7 Pro, because the service's first run writes Trusty's secure storage; [plan](../device/tegu/FINGERPRINT-PLAN.md), [record](../device/tegu/NOTES.md#2026-10-31-and-11-01-every-testing-row-on-a-published-style-kernel)) | | Pixel 8 Pro ([notes](../device/husky/NOTES.md)) | husky | zuma (Tensor G3) | WIP ([#1](https://github.com/derekross/omarchy-mobile/issues/1): slot B, not marked successful; Omarchy's image from the signed repository boots to the lock screen; the zuma device tree is merged ([kernel #13](https://github.com/derekross/linux-omarchy-mobile/pull/13), [#53](https://github.com/derekross/linux-omarchy-mobile/pull/53))) | testing (UFS at HS-G4 behind the read-only guard; Arch on `userdata`; [UFS-PLAN](../device/husky/UFS-PLAN.md)) | WIP (simple-framebuffer: console and Omarchy's lock screen) | no | testing (ST FTM5 over SPI, merged, [kernel #153](https://github.com/derekross/linux-omarchy-mobile/pull/153); [NOTES](../device/husky/NOTES.md)) | testing (power and volume through `gpio-keys`, merged, [kernel #148](https://github.com/derekross/linux-omarchy-mobile/pull/148); [NOTES](../device/husky/NOTES.md)) | testing (USB and SSH) | testing (BCM4398 on a test kernel, [kernel #156](https://github.com/derekross/linux-omarchy-mobile/pull/156); firmware from the owner's image, [#214](https://github.com/derekross/omarchy-mobile/pull/214); [NOTES](../device/husky/NOTES.md)) | no | testing (gauge with Google's ATL model through a bring-up overlay, temperature, MFD, on a test kernel, [kernel #163](https://github.com/derekross/linux-omarchy-mobile/pull/163); [notes](../device/husky/BATTERY-NOTES.md)) | testing (the charger driver by hand under a dead-man tool, slow on plain 5 V, on a test kernel, [kernel #163](https://github.com/derekross/linux-omarchy-mobile/pull/163); [notes](../device/husky/BATTERY-NOTES.md)) | no | no | no | no | no | no | no | no | no | no | no | | Pixel 7 ([notes](../device/panther/NOTES.md)) | panther | gs201 (Tensor G2) | WIP (slot B, not marked successful; Arch and Hyprland boot; [BRINGUP-M1](../device/panther/BRINGUP-M1.md); board file merged, [kernel #108](https://github.com/derekross/linux-omarchy-mobile/pull/108)) | testing (UFS behind the read-only guard; Arch on `userdata`; merged, [kernel #108](https://github.com/derekross/linux-omarchy-mobile/pull/108)) | WIP (simple-framebuffer: console and the Hyprland desktop; brightness and display off/on over DCS through the S6E3FC3 panel driver and device-panther 0.1.4, in review, [kernel #177](https://github.com/derekross/linux-omarchy-mobile/pull/177); [DISPLAY-PLAN](../device/panther/DISPLAY-PLAN.md)) | testing (Panthor on the Mali-G710; Hyprland renders on it; merged through [kernel #134](https://github.com/derekross/linux-omarchy-mobile/pull/134), with the always-on rule in device-panther 0.1.1, [#145](https://github.com/derekross/omarchy-mobile/pull/145); [notes](../device/panther/NOTES.md#2026-10-28-the-gpu-and-the-haptics-power-off-and-usb-after-a-replug)) | WIP (FocalTech FT3658: touches drive Hyprland and unlock the PIN screen on a test kernel; the driver, [kernel #109](https://github.com/derekross/linux-omarchy-mobile/pull/109), and the touch node, [kernel #134](https://github.com/derekross/linux-omarchy-mobile/pull/134), are merged; stock's interrupt pull-up and CS delay, [kernel #166](https://github.com/derekross/linux-omarchy-mobile/pull/166), the driver's review fixes, [kernel #133](https://github.com/derekross/linux-omarchy-mobile/pull/133), and the kernel option with the touch notes, [#149](https://github.com/derekross/omarchy-mobile/pull/149), are merged) | testing (gpio-keys: power, volume; merged, [kernel #108](https://github.com/derekross/linux-omarchy-mobile/pull/108)) | testing (USB and SSH; merged, [kernel #108](https://github.com/derekross/linux-omarchy-mobile/pull/108); a replug comes back through `omamobile-usb-rescue` in device-panther 0.1.3, on the MAX77759's I2C bus, merged, [kernel #167](https://github.com/derekross/linux-omarchy-mobile/pull/167); [notes](../device/panther/NOTES.md#2026-10-29-usb-comes-back-after-a-replug-u1)) | no | no | WIP (MAX77759 fuel gauge with stock's battery model on a test kernel: percentage, capacity and temperature in upower and the bar; in review, [kernel #171](https://github.com/derekross/linux-omarchy-mobile/pull/171) and the driver fix [#170](https://github.com/derekross/linux-omarchy-mobile/pull/170); [BATTERY-PLAN](../device/panther/BATTERY-PLAN.md)) | no | testing (CS40L26 with the phone's own firmware, `tools/extract-vendor-firmware -d panther`; merged through [kernel #134](https://github.com/derekross/linux-omarchy-mobile/pull/134), with the feedbackd rule in device-panther 0.1.1, [#145](https://github.com/derekross/omarchy-mobile/pull/145); [notes](../device/panther/NOTES.md#2026-10-28-the-gpu-and-the-haptics-power-off-and-usb-after-a-replug)) | no | no | no | no | no | no | no | no | no (s2idle by default since [kernel #134](https://github.com/derekross/linux-omarchy-mobile/pull/134) and device-panther 0.1.1; not run yet) | no | | OnePlus 13 ([notes](../device/dodge/NOTES.md)) | dodge | sm8750 (Snapdragon 8 Elite) | testing (kernel [mrlund/linux-omarchy-mobile `dodge-v3-20261101`](https://github.com/mrlund/linux-omarchy-mobile/tree/dodge-v3-20261101); [kernel #115](https://github.com/derekross/linux-omarchy-mobile/pull/115) closed; [BRINGUP](../device/dodge/BRINGUP-M1.md), [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing ([notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (msm/dpu; warm-boot drop fixed; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (Adreno 830 / gpu2; Vulkan untested; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing ([notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing ([notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (CDC NCM + SSH; gadget stuck after replug until reboot; kernel [mrlund/linux-omarchy-mobile `dodge-v3-20261101`](https://github.com/mrlund/linux-omarchy-mobile/tree/dodge-v3-20261101); [kernel #115](https://github.com/derekross/linux-omarchy-mobile/pull/115) closed; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (WCN7860 / ath12k; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (pairing; A2DP untested; kernel [mrlund/linux-omarchy-mobile `dodge-v3-20261101`](https://github.com/mrlund/linux-omarchy-mobile/tree/dodge-v3-20261101); [kernel #115](https://github.com/derekross/linux-omarchy-mobile/pull/115) closed; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (gauge; charging path not claimed; kernel [mrlund/linux-omarchy-mobile `dodge-v3-20261101`](https://github.com/mrlund/linux-omarchy-mobile/tree/dodge-v3-20261101); [kernel #115](https://github.com/derekross/linux-omarchy-mobile/pull/115) closed; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | no | no | no | no | - | testing (speakers, earpiece, mics; headset plug untested; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (accel, prox, compass; autorotate; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | testing (LTE data; calls/SMS untested; opt-in flag; [modem](../device/dodge/modem/README.md), [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | no | no | WIP (s2idle not default; [notes](../device/dodge/NOTES.md#2026-10-28-matrix-evidence)) | no | From 395ab10bd98e7dd06a4f2b94e68ceddffaceaa1a Mon Sep 17 00:00:00 2001 From: W4HO <87742609+W4HO-ham@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:23:19 -0647 Subject: [PATCH 07/10] omamobile-modem-sit 0.3.9: indications seen during the setup's wait reach the service 0.3.6 and 0.3.8 read indications themselves while the setup waited and after a refusal, and only logged and kept them: an SMS arriving in that window got neither stored nor acknowledged. They're now handed to the service's own handler as well, as everywhere else, with a test for an SMS in both windows. MODEM-PLAN now says what the run showed and no more: the three IND_REG_FAILED were LTE cause 10 (implicitly detached), whether the data permission triggers it isn't proven, and only byte 132 of the refused record is the IPC extension version. --- device/tegu/MODEM-PLAN.md | 28 ++++++++++--------- packages/omamobile-modem-sit/lib/bringup.py | 4 +-- packages/omamobile-modem-sit/lib/data_call.py | 26 ++++++++++------- .../test/test_data_call.py | 27 ++++++++++++++++++ packages/omamobile-modem-sit/version | 2 +- 5 files changed, 61 insertions(+), 26 deletions(-) diff --git a/device/tegu/MODEM-PLAN.md b/device/tegu/MODEM-PLAN.md index 58009f050..1ad0c50db 100644 --- a/device/tegu/MODEM-PLAN.md +++ b/device/tegu/MODEM-PLAN.md @@ -1987,10 +1987,13 @@ is a US MVNO on a large LTE network. the APN's types; sitd sent 0, taken for an MTU). Still 36. 3. 0.3.8: the recording build (0.3.6) had shown that about a second after every refusal the modem sent three IND_REG_FAILED, two - IND_NTW_STATE_CHANGED and an empty data-call list, and that it was - quiet before the data permission: it re-attaches when - SET_MOBILE_DATA_STATE and SET_PS_SERVICE are written, and the setup - always landed inside that. The RIL now waits until the modem has + IND_NTW_STATE_CHANGED and an empty data-call list. With 0.3.8 the + same indications arrived after the data permission + (SET_MOBILE_DATA_STATE, SET_PS_SERVICE) and before the setup; the + three IND_REG_FAILED read domain CS+PS, PS, PS, each with LTE cause + 10 (implicitly detached) and additional cause 0 (decoded with the + stock library's layout). Whether the permission writes trigger the + detach isn't proven; the setup succeeds once it is over. The RIL now waits until the modem has been quiet for 3 s after the permission (at most 20 s), reads the registration again, and then sends the setup. On its first run the six indications came and went in the wait, the registration read 1, @@ -2016,15 +2019,14 @@ is a US MVNO on a large LTE network. six partitions unchanged, `cpif` not loaded, UFS error handler 0. The run kept the full refused record (292 bytes: status 36, CID 1, the -IPC extension version at 132-133, the suggested retry time at 235-242 as -an s64) and the raw indications of the passing run in -`logs/tegu-sim-20261102/private/` (off the repository). The one open -question is what the modem's re-attach after the data permission is -about: the IND_REG_FAILED causes are in that file, decodable with the -layout from the stock library (domain at 0x0e, main cause 0x0f, -additional cause 0x10). Stock sends the data permission at radio-on, long -before any setup, so the better fix may be to move those two requests -earlier and keep the wait as a safety net. +IPC extension version at 132, an unidentified extension byte at 133, the +suggested retry time at 235-242 as an s64) and the raw indications of the passing run in +`logs/tegu-sim-20261102/private/` (off the repository). The open +question is what triggers the implicit detach. Stock's handlers send the +two permission requests separately (SET_PS_SERVICE's success path then +sleeps 500 ms) and its setup path doesn't send them; the libraries don't +show when Android's callers do. Sending them earlier, before the last +registration check, is a reasonable next try, with the wait kept. **Unqualified after a passing run:** suspend with the modem on (the inhibitor stays; M6, two reboots with the CP up: this runbook's attended diff --git a/packages/omamobile-modem-sit/lib/bringup.py b/packages/omamobile-modem-sit/lib/bringup.py index 9be800d65..45e2a98aa 100644 --- a/packages/omamobile-modem-sit/lib/bringup.py +++ b/packages/omamobile-modem-sit/lib/bringup.py @@ -160,7 +160,7 @@ def usim_ready(): wait_for(service, lambda: packet_registered(client.request(0x0701), lte=True), 120, stopped) data_snapshot(client, 'after the NR change') service.stage('data') - activate(client, apn, ip_type=ip_type) + activate(client, apn, ip_type=ip_type, on_event=service.event) service.pump() if not net.getboolean('ims', True): service.ims_state = 'off' @@ -170,7 +170,7 @@ def usim_ready(): service.stage('ims') try: start_stack(client) - activate(client, net.get('ims_apn', 'ims'), ims=True) + activate(client, net.get('ims_apn', 'ims'), ims=True, on_event=service.event) register(client) print('Startup: waiting for IMS voice and SMS registration', flush=True) wait_for(service, lambda: service.registration().get('state') == 2 and diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index 5a74f0114..25302561d 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -152,11 +152,11 @@ def provision_default_profile(client, apn, ip_type='ipv4v6'): -# After the data permission is switched on, the modem is given time to say -# what it does about it before the setup goes out: on 2026-11-02 every setup -# was answered 36 within 150 ms and was followed within a second by three -# IND_REG_FAILED and two IND_NTW_STATE_CHANGED, so the modem was re-attaching -# around the request. The wait ends after SETTLE_QUIET seconds without an +# After the data permission is switched on, the modem is given time to settle +# before the setup goes out: on 2026-11-02 every setup was answered 36 within +# 150 ms and was followed within a second by three IND_REG_FAILED (LTE cause +# 10, implicitly detached) and two IND_NTW_STATE_CHANGED; with this wait the +# same indications came and went before the setup, and it succeeded. The wait ends after SETTLE_QUIET seconds without an # indication, or at SETTLE_LIMIT. SETTLE_QUIET = 3 SETTLE_LIMIT = 20 @@ -189,7 +189,7 @@ def describe(packet): return line -def settle(client, label): +def settle(client, label, on_event=None): deadline = time.monotonic() + SETTLE_LIMIT last = time.monotonic() seen = 0 @@ -204,9 +204,13 @@ def settle(client, label): last = time.monotonic() keep_packet(packet) print(f'{label}: {describe(packet)}', flush=True) + if on_event: + # Handled as the service handles any indication (an SMS arriving + # now is stored and acknowledged), not only recorded. + on_event(packet) print(f'{label}: {seen} indication(s), then quiet' if seen else f'{label}: quiet', flush=True) -def listen_after_failure(client, seconds=5): +def listen_after_failure(client, seconds=5, on_event=None): """After a refused setup, keep the channel open a few seconds and log what the modem sends next: on 2026-11-02 two or three messages arrived about a second after each status 36 and were dropped because the channel @@ -224,9 +228,11 @@ def listen_after_failure(client, seconds=5): seen += 1 keep_packet(packet) print(f'after the failure: {describe(packet)}', flush=True) + if on_event: + on_event(packet) print(f'after the failure: {seen} indication(s) in {seconds} s', flush=True) -def activate(client, apn, *, ims=False, ip_type='ipv4v6', lte_access=False): +def activate(client, apn, *, ims=False, ip_type='ipv4v6', lte_access=False, on_event=None): requested_cid = 2 if ims else 1 state_path, response_path = paths(requested_cid) state = client.request(0x0701) @@ -237,7 +243,7 @@ def activate(client, apn, *, ims=False, ip_type='ipv4v6', lte_access=False): if state_path.exists() or requested_cid in calls or calls != owned: raise RuntimeError('existing target or unresolved bearer ownership') allow_data(client) - settle(client, 'after allowing data') + settle(client, 'after allowing data', on_event) # The registration as it stands now, not before the permission: the # modem may have re-attached meanwhile. for second in range(60): @@ -274,7 +280,7 @@ def activate(client, apn, *, ims=False, ip_type='ipv4v6', lte_access=False): failed_path = response_path.with_name(f'failed-setup-cid{requested_cid}.bin') private_write(failed_path, result) print(f'failed setup response kept privately: {len(result)} bytes', flush=True) - listen_after_failure(client) + listen_after_failure(client, on_event=on_event) raise RuntimeError('data call did not become active') private_write(response_path, result) print('owned data bearer active; private IP configuration retained in RAM', flush=True) diff --git a/packages/omamobile-modem-sit/test/test_data_call.py b/packages/omamobile-modem-sit/test/test_data_call.py index e7858c38d..27ebf1e23 100644 --- a/packages/omamobile-modem-sit/test/test_data_call.py +++ b/packages/omamobile-modem-sit/test/test_data_call.py @@ -133,6 +133,33 @@ def test_setup_waits_for_the_modem_to_go_quiet_and_rereads_registration(self): self.assertLess(idents.index(0x0710), idents.index(0x0600)) self.assertEqual(idents.count(0x0701), 2) + def test_indications_during_the_wait_reach_the_service(self): + # An SMS that arrives while the setup waits (or after a refusal) is + # handed to the service, which stores and acknowledges it, not only + # recorded. + sms = struct.pack(' Date: Mon, 2 Nov 2026 23:00:46 -0500 Subject: [PATCH 08/10] omamobile-modem-sit 0.3.16, omamobile-mmd 0.1.1: register on Verizon's network in seconds, carry data, and show the modem in the shell Tested on a Pixel 7 Pro with a Verizon-network MVNO SIM on 2026-11-02. On top of #356 (0.3.9). - [network] attach_apn: some networks attach only on their IMS APN. Verizon's never registered while the internet APN was the attach APN, and registered once the IMS APN was. Empty means "same as apn". - [profiles]: every modem-managed data profile in stock's SET_DATA_PROFILE layout (IDs, APN-type bits, PDP types), so the modem has the carrier's full table before radio on. - Stock's order: attach APN, profiles and NR mode, then radio on once with no AT+CFUN cycle. NR mode is set right after radio on when the modem refuses it with the radio off (error 2). Registration went from 53 s to 10+ min down to 3.3 s after radio on. - omamobile-sit-data finds the rmnet device that carries the bearer by probing; it isn't rmnet once the attach is on another APN. A stop during the probe puts every candidate back. - /run/omamobile-sit stays 0710 root:wheel (SIT clients no longer chmod it to 0700), so the shell's tile can read state.json again. - IMS: P-CSCF extension decoding, the P-CSCF request in an IMS-APN attach, and [network] ims_pcscf_required (yes keeps today's behaviour). - [network] carrier_manifest: answers the modem's own carrier-config request (0x4602) with one OEM_SET_CARRIER_CONFIG_MANIFEST naming a manifest from the owner's image, and holds the IMS stack start until the modem's status. Empty by default; nothing reads SIM identities. extract-vendor-chroot copies vendor/firmware/carrierconfig for it. - Logging: runtime registration changes, IND_REG_FAILED causes, carrier-config status, IND_PHONE_RESET bytes and registration time. - Radio state 10 (Android's RadioState ON) is "on", and the LTE signal comes from IND_SIGNAL_STRENGTH. omamobile-mmd exports both, so the Mobile tile and the bar show the network. IMS still doesn't register without the carrier profile persisting in the modem's NV; that is the NV overlay's PR. device/cheetah/MODEM-PROVIDER-PROFILES.md records stock's databases, order and APNs for this SIM type. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BeEcdVeSfyLCbijF8XQF1d --- device/cheetah/MODEM-PROVIDER-PROFILES.md | 238 ++++++++++++++++++ packages/omamobile-mmd/lib/bridge.py | 6 +- packages/omamobile-mmd/test/test_bridge.py | 6 + packages/omamobile-mmd/version | 2 +- .../omamobile-modem-sit/bin/omamobile-sit | 2 +- .../bin/omamobile-sit-data | 2 +- .../etc/omamobile/modem-sit.conf | 46 +++- packages/omamobile-modem-sit/lib/at.py | 20 +- packages/omamobile-modem-sit/lib/bringup.py | 121 +++++++-- .../lib/carrier_manifest.py | 65 +++++ packages/omamobile-modem-sit/lib/data_call.py | 206 +++++++++++++-- .../omamobile-modem-sit/lib/data_network.py | 181 ++++++++++--- packages/omamobile-modem-sit/lib/ims.py | 28 ++- packages/omamobile-modem-sit/lib/paths.py | 20 +- .../omamobile-modem-sit/lib/radio_settings.py | 5 + packages/omamobile-modem-sit/lib/service.py | 121 ++++++++- packages/omamobile-modem-sit/lib/sit.py | 22 +- .../systemd/omamobile-sit-data.service | 4 +- .../omamobile-modem-sit/test/test_bringup.py | 168 ++++++++++++- .../test/test_carrier_manifest.py | 148 +++++++++++ .../test/test_data_call.py | 120 +++++++++ .../test/test_data_network.py | 125 +++++++++ packages/omamobile-modem-sit/test/test_ims.py | 37 +++ .../test/test_radio_settings.py | 15 ++ .../omamobile-modem-sit/test/test_service.py | 82 ++++++ packages/omamobile-modem-sit/test/test_sim.py | 14 +- packages/omamobile-modem-sit/version | 2 +- tools/extract-vendor-chroot | 11 + 28 files changed, 1689 insertions(+), 128 deletions(-) create mode 100644 device/cheetah/MODEM-PROVIDER-PROFILES.md create mode 100644 packages/omamobile-modem-sit/lib/carrier_manifest.py create mode 100644 packages/omamobile-modem-sit/test/test_carrier_manifest.py diff --git a/device/cheetah/MODEM-PROVIDER-PROFILES.md b/device/cheetah/MODEM-PROVIDER-PROFILES.md new file mode 100644 index 000000000..56d7dfc52 --- /dev/null +++ b/device/cheetah/MODEM-PROVIDER-PROFILES.md @@ -0,0 +1,238 @@ +# Provider profiles, APNs and the stock bring-up order (cheetah, S5300) + +Status (2026-11-02, offline research, nothing run): what stock Android does +for a SIM from modem boot to IMS registration, where its APN and carrier +data comes from, what our RIL (`omamobile-modem-sit`) does differently, and a +design for doing it the stock way on every carrier. Sources: the owner's +factory image (read on the laptop, never committed), libsitril and the SIT +stream library (function names and offsets), Shannon's IMS service APK +(class and key names), Google's CarrierSettings protobufs and the modem's +carrier-config database. Only field names and short values such as APN +names are quoted. Confidence is given per finding. + +## 1. Two separate carrier databases + +Stock keeps carrier data in two places, read by two different consumers. + +| | AP side: CarrierSettings | CP side: modem carrier config | +|---|---|---| +| Files | `product/etc/CarrierSettings/*.pb` (about 620 files) and `carrier_list.pb` | `vendor/firmware/carrierconfig/`: `cfg.db`, `manifests/`, `confseqs/` | +| Format | protobuf, one file per carrier (`_.pb`) | SQLite (matching) plus protobuf manifests and configuration sequences | +| Matched by | `carrier_list.pb`: MCC/MNC plus optional GID1, SPN, IMSI prefix | `cfg.db` `carrier_info`: MCC/MNC plus GID1, GID2, SPN, IMSI and ICCID patterns, ranked | +| Holds | APNs with types, protocols, bearers, profile IDs; Android carrier config keys (IMS settings, SIP domain, signal thresholds, 5G icons ...) | NV settings for the modem: hashed NV item IDs and values (protocol timers, CA/ENDC band combinations, SRS, PLMN mapping, carrier-specific items) | +| Consumer | Android telephony (DataProfileManager, ImsService via CarrierConfigManager) | the CP, through `OEM_SET_CARRIER_CONFIG_MANIFEST` (0x4600) and rfsd | + +**APNs are only on the AP side.** The modem's manifests and confseqs carry +no APN strings: they are NV item settings (`confseqs` decode as protobuf: +version, name such as `vzw.sim1`, then repeated `{hashed item ID, value}`). +Confidence high. + +### 1.1 This SIM's entries + +- **AP (CarrierSettings):** `carrier_list.pb` maps the SIM's MVNO GID1 on + the Verizon codes to `tracfoneverizon_us`. Its APN list is identical to + `verizon_us` (decoded, field by field): + + | APN | types | bearers | protocol (home/roaming) | profile ID | modem-cognitive | + |---|---|---|---|---|---| + | `internet` | default, mms, supl, dun, fota, cbs | CDMA/EVDO only | IPv4v6 | - | - | + | `VZWINTERNET` | default, supl, dun | GSM/UMTS/LTE/IWLAN/NR | IPv4v6 | 0 | yes | + | `VZWADMIN` | fota | as above | IPv4v6 | 3 | yes | + | `IMS` | **ia**, ims | LTE, IWLAN, NR | IPv4v6 / IPv6 | 2 | yes | + | `VZWAPP` | cbs, mms | as above | IPv4v6 | 4 | yes | + | `VZWEMERGENCY` | emergency | - | IPv4v6 / IPv6 | - | - | + + So stock's **initial attach APN is `IMS`** (the `ia` type), not `vzwims`, + and the internet APN is `VZWINTERNET`. The carrier config also sets the + IMS phone-context domain to the carrier's IMS domain and the usual + Verizon IMS keys. +- **CP (cfg.db):** the same GID1 ranks `Tracfone-VZW` (carrier ID 10008, + manifest `us_tracfone`) above plain Verizon (1839, `us_vzw`). The two + manifests share 32 configuration sequences. `us_tracfone` adds + `tracfone.sim1/sim2` (one NV item each) and drops `vzw-only.sim1/sim2/ + multislot` and `vzw-0x18F.sim1/sim2` (Verizon-only timers and items). + Neither contains APNs. + +## 2. The stock bring-up order + +From libsitril's start-up hooks (MODEM-SIT-RESEARCH section 4), the IMS +service's state names and AOSP telephony's behaviour. Order across services +is inferred, not captured (a stock radio log would settle it). + +1. **CP online** (cbd, rfsd). rild opens IPC0. +2. **Radio available** (`MiscService::OnRadioAvailable` and friends): + SET_DEBUG_TRACE off, SET_MODEM_CONFIG, SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING, + SET_SGC (`persist.vendor.radio.sgc`), the software version, SET_DEVICE_INFO, + SET_AP_SYSTEM_TIME; `PsService::OnRadioAvailable` re-applies the stored + initial attach APN; `NetworkService::OnRadioAvailable` sends + **SET_RADIO_POWER on** (unless airplane mode). The radio is turned on + once and stays on. +3. **SIM loads.** The CP sends `OEM_IND_CARRIER_CONFIG_SIM_INFO` (0x4602). + `MiscService::OnOemCpCarrierConfigSimInfoInd` (0x137c90) queues + `DoOemSetCpCarrierConfig` (0x137ed0): it matches the SIM in `cfg.db` and + sends 0x4600 (directory string `/vendor/firmware/carrierconfig`, the + manifest ID decoded from hex; built by + `ProtocolMiscBuilder::BuildSetCpCarrierConfig`). Stock never sends 0x4600 + unprompted. +4. **The CP applies the profile** and answers `OEM_IND_CARRIER_CONFIG_STATUS` + (0x4601, status and cause). `OnOemCpCarrierConfigStatusInd` (0x138e70) + logs it and forwards it to the IMS service (`RilIndCpCarrierConfigChanged`, + `MANIFEST_UPDATED` / `MANIFEST_NOT_UPDATED`). The selection is kept in + `persist.vendor.radio.config.carrier_id` on the AP and, on the CP, in its + NV. +5. **When a profile changes NV, the CP asks for a reset.** libsitril's + `PhoneResetHandler` handles `IND_PHONE_RESET` (0x0804) with reasons + including `GCONFIG`, `DEFAULT CONFIG`, `SGC CHANGE`, `UPDATE RSP`, `SIM`, + `RADIO POWER`, and sends a device reset request. On stock the reset is a + CP restart with the new NV in place; on the next start the manifest + matches what NV holds and no reset is needed. (Confidence medium: the + reasons and the handler are certain, the exact trigger after a manifest + change is inferred.) +6. **Android telephony, after the carrier config is loaded:** the initial + attach APN (`ia`: `IMS`) with SET_INITIAL_ATTACH_APN; **every + modem-cognitive data profile** (IDs 0, 2, 3, 4 above) with + SET_DATA_PROFILE; the preferred network type bitmap; data allowed + (SET_PS_SERVICE / mobile data). Setup data calls follow as Android needs + them: IMS first (by the IMS service), internet when mobile data is on. +7. **IMS:** the IMS service holds its stack start + (`mImsStackStartBlocked`, "IMS stack start has been blocked during + Carrier Config Manifest") until step 4 has reported, then + AIMS_STACK_START_REQ, the IMS PDN (on Verizon: the attach PDN, APN `IMS`), + AIMS_ADD_PDN_INFO with the P-CSCF list (from the PCO, with the ISIM's + EF_PCSCF added: `addPcscfFromSim`, `getIsimPcscf`), and the modem's IMS + stack registers. For this network the IMS service's own config + (`sim_configuration_311.xml`, MNC 480) does not block the PDN on a + missing P-CSCF (`BLOCK_PDN_BY_INVALID_PCSCF` 0) and requires a single + registration. + +## 3. What ours does differently (0.3.14) + +| Step | Stock | omamobile-modem-sit | +|---|---|---| +| Radio | on once, stays on | AT+CFUN=0, attach APN, data profile, AT+CFUN=1: a radio cycle at every start | +| Carrier profile | 0x4600 on 0x4602, then a CP reset if NV changed | none by default; `carrier_manifest` sends it, but nothing handles the reset request, and a reset can't be done in place (it needs a reboot, which discards the NV RAM copy and with it the profile) | +| Attach APN | the `ia` APN from CarrierSettings (`IMS`) | `attach_apn` by hand (`vzwims` tonight) | +| Data profiles | every modem-cognitive profile with its profile ID | one default profile (ID 0) | +| NR | per carrier config | SET_NR_MODE 3 -> 0 **after** registration, which can make the CP re-register | +| IMS stack start | after the carrier-config status | immediately (0.3.14: waits only when `carrier_manifest` is set) | +| P-CSCF | PCO, plus the ISIM | PCO only; empty on this network | +| NV | persistent | a RAM copy of the backup, dropped at stop: every boot starts from the same old state | + +0.3.15 (built offline, not yet run on a phone) takes three rows to stock's +way: it reads the radio state (AT+CFUN?) and sends the attach APN, every +profile in the new `[profiles]` section (profile 0 from `apn` unless +`[profiles]` has its own) and NR mode 0 before radio on, switching the radio +on once and never off; it logs IND_PHONE_RESET's first payload bytes raw and +the time from radio on to the first packet registration. + +## 4. Why registration takes minutes + +In order of likely weight: + +1. **The NV RAM copy is the backup's state at every boot.** The CP keeps its + acquisition data (recent PLMNs, bands, cells) and the carrier profile in + NV. Ours starts each boot from the same backup, taken without this SIM, + so the CP does a cold search every time, with whatever carrier profile + the backup holds (not Verizon's). Stock's first boot with a new SIM is + slow too; every later boot starts from the last cell. Confidence medium + (the acquisition database's location is not read; the behaviour fits + 34 s to 10+ min with the same cell). +2. **The radio cycle and the late NR change.** AT+CFUN=0/1 at start and + SET_NR_MODE after registration both make the CP search or re-register; + stock does neither at start. +3. **A profile mismatch.** Without Verizon's NV settings the CP runs a + generic profile; after the Tracfone manifest the CP applied it (status 1) + and stopped searching (CEREG 0,0), consistent with it waiting for the + reset of step 2.5 that sitd never answered (0x0804 is not logged yet). +4. **IND_REG_FAILED cause 10 after the data permission** (seen on both + phones): the network detaches the phone once around the first data + setup; the settle wait of 0.3.8 rides it out, but each costs a re-attach. + +## 5. IMS on this network + +- **The PDN:** IMS runs on the attach PDN (APN `IMS`, types `ia` and `ims`). + A second IMS setup on the same APN returns that PDN. +- **The P-CSCF:** Verizon delivers it in the PCO of the IMS PDN when the UE + asks for it; whether the CP asks, and in which PCO containers, is CP + configuration (the carrier profile). With the generic profile the PCO + comes back without it, even with the P-CSCF request bit set in our attach + (0.3.11). The ISIM's EF_PCSCF is stock's second source. +- **What is missing, most likely:** the carrier profile in effect on the CP + (step 2.3-2.5). Without it the CP's IMS stack has no carrier settings, and + ADD_PDN with an empty P-CSCF list was accepted but never led to a + registration (0.3.13). + +## 6. Design for Omarchy Mobile (every carrier) + +**Data sources (all from the owner's own factory image, extracted on the +laptop like the vendor chroot, never hosted or committed):** + +- AP: CarrierSettings protobufs, read with a small decoder for the fields we + use (APN name, types, protocols, bearer bitmask, profile ID, + modem-cognitive; a handful of carrier config keys). This is the database + stock uses; it has the `ia` APN for each carrier. +- CP: `vendor/firmware/carrierconfig` in the modem chroot (0.3.14's + extractor already copies it). +- Fallback where the image has no entry: mobile-broadband-provider-info + (no `ia` types, so its attach APN is a guess), then a small override file + in the package, then the user's own setting. + +**Matching, with minimal identity handling:** MCC/MNC, GID1 and SPN are what +both databases match on. Read them once, in sitd, keep only those fields in +memory, log only the matched carrier names. Options: GET_IMSI's first 5-6 +digits plus GID1 through SIM I/O, or the CP's 0x4602 (which carries them, but +also full identities). This needs the maintainer's decision; until then the +carrier can be chosen by hand (the 0.3.14 `carrier_manifest` setting, and the +same for the CarrierSettings name). + +**Order (stock's):** + +1. CP online. Radio stays off. +2. Wait for 0x4602; answer with the CP manifest; wait for 0x4601. +3. If the CP asks for a reset (0x0804): this needs NV persistence (below). +4. SET_INITIAL_ATTACH_APN with the `ia` APN; SET_DATA_PROFILE with every + modem-cognitive profile and its profile ID; preferred network type and NR + mode **before** radio on. +5. Radio on, once. Wait for registration. +6. Data permission, settle, internet bearer. +7. AIMS stack start, IMS bearer (the attach PDN where `ia` = `ims`), ADD_PDN + with PCO P-CSCFs, else the ISIM's. + +**NV persistence: the decision this hinges on.** Stock's carrier profile and +acquisition data live in NV. Our profile works on a RAM copy that is dropped +at stop, which keeps the partitions safe but makes every boot a first boot +with the backup's carrier. Options, for the maintainer: + +- (a) Keep RAM-only and seed NV from a stock boot with the SIM in: boot + stock once with this SIM, let it register and apply the profile, take a + fresh read-only backup (AGENTS.md section 1), update `modem-nv.sha256`. + The RAM copy then starts every boot with Verizon's profile and a recent + cell. No new write path; repeat per SIM change. +- (b) A persistent copy of the modem's NV kept off the partitions (for + example under /var/lib), checksum-verified like the RAM copy, so the CP's + changes survive reboots. The partitions are still never written; it + changes the "loses what the modem writes" rule. +- (c) Never apply a profile and live with the generic one: no IMS on + networks that need their profile. + +**Where PR #373 fits:** its carrier lookup (MCC/MNC from GET_IMSI into +mobile-broadband-provider-info plus overrides) is the fallback layer above, +and its Mobile network page is the place to show and override the matched +carrier. Changes it needs: read CarrierSettings first (it has the `ia` APN: +`IMS` for Verizon, where the override guesses `vzwims`); send every +modem-cognitive profile, not only the default; match on GID1 too (MVNOs on +shared codes, as here); and order the requests as above. + +## 7. Next steps, by expected gain + +1. **Seed NV from a stock boot with the SIM** (option a) and boot ours + without a manifest or radio cycle changes: tests whether registration + gets fast and whether IMS registers once the CP carries the profile. + Risk: medium (a stock boot rewrites efs, persist and modem_userdata; the + backup and checksum steps of AGENTS.md section 1 are mandatory). +2. **Stock's order and APNs:** attach on `IMS` (not `vzwims`), all + modem-cognitive profiles, NR mode set before radio on, no AT+CFUN cycle + when the radio is already off at start. Risk: low. +3. **Handle and log 0x0804 (IND_PHONE_RESET)** with its type and reason, so + the next manifest test shows whether the CP asked for a reset. Risk: + none (logging only). diff --git a/packages/omamobile-mmd/lib/bridge.py b/packages/omamobile-mmd/lib/bridge.py index 5dcbab777..462c7e52b 100644 --- a/packages/omamobile-mmd/lib/bridge.py +++ b/packages/omamobile-mmd/lib/bridge.py @@ -92,6 +92,8 @@ def derive(status): plmn=m.get('plmn', '') if registered else '', operator_name=m.get('operator_name', '') if registered else '', home=reg == 'home', + # sitd's LTE RSRP as 0-100 while registered; "recent" while it has one. + signal=max(0, min(100, int(m.get('signal') or 0))) if registered else 0, emergency_numbers=list(m.get('emergency_numbers') or ('112', '911')), ) return d @@ -215,7 +217,7 @@ def static_props(self, name): CurrentCapabilities=mm.CAP_GSM_UMTS | mm.CAP_LTE, MaxBearers=1, MaxActiveBearers=1, SupportedModes=[(mm.MODE_4G, mm.MODE_NONE)], CurrentModes=(mm.MODE_4G, mm.MODE_NONE), SupportedBands=[mm.BAND_UNKNOWN], CurrentBands=[mm.BAND_UNKNOWN], - SupportedIpFamilies=mm.IP_V4 | mm.IP_V6 | mm.IP_V4V6, SignalQuality=(0, False)) + SupportedIpFamilies=mm.IP_V4 | mm.IP_V6 | mm.IP_V4V6) if name == mm.MODEM_3GPP: apn, ip_type = self.settings.get('apn', ''), self.settings.get('ip_type', 'ipv4v6') settings = {'apn': GLib.Variant('s', apn), @@ -232,7 +234,7 @@ def dynamic_props(self, name, d): return dict(Sim=self.sim or '/', Bearers=[self.bearer] if self.bearer else [], State=d['state'], StateFailedReason=d['failed'], UnlockRequired=d['unlock'], UnlockRetries=d['retries'], PowerState=d['power'], - AccessTechnologies=d['access']) + AccessTechnologies=d['access'], SignalQuality=(d['signal'], d['signal'] > 0)) if name == mm.MODEM_3GPP: return dict(RegistrationState=d['registration'], OperatorCode=d['plmn'], OperatorName=d['operator_name'], PacketServiceState=d['packet']) diff --git a/packages/omamobile-mmd/test/test_bridge.py b/packages/omamobile-mmd/test/test_bridge.py index bd44a34d1..e3bcedaf4 100644 --- a/packages/omamobile-mmd/test/test_bridge.py +++ b/packages/omamobile-mmd/test/test_bridge.py @@ -40,6 +40,12 @@ def test_states(self): d = bridge.derive(status) self.assertEqual((d['state'], d['failed']), (state, failed), status['modem']['sim']) + def test_signal_only_while_registered_and_clamped(self): + self.assertEqual(bridge.derive(registered_status(signal=32))['signal'], 32) + self.assertEqual(bridge.derive(registered_status(signal=250))['signal'], 100) + self.assertEqual(bridge.derive(registered_status(signal=None))['signal'], 0) + self.assertEqual(bridge.derive(blank_status(sim='ready', radio='on', signal=40))['signal'], 0) + def test_details(self): d = bridge.derive(blank_status(sim='pin')) self.assertEqual((d['unlock'], d['emergency_only'], d['sim_object'], d['interfaces']), diff --git a/packages/omamobile-mmd/version b/packages/omamobile-mmd/version index 6e8bf73aa..17e51c385 100644 --- a/packages/omamobile-mmd/version +++ b/packages/omamobile-mmd/version @@ -1 +1 @@ -0.1.0 +0.1.1 diff --git a/packages/omamobile-modem-sit/bin/omamobile-sit b/packages/omamobile-modem-sit/bin/omamobile-sit index 4298f5e14..9b86a4185 100755 --- a/packages/omamobile-modem-sit/bin/omamobile-sit +++ b/packages/omamobile-modem-sit/bin/omamobile-sit @@ -12,7 +12,7 @@ omamobile-sit sms send NUMBER TEXT one SMS (several parts if needed) omamobile-sit sms list [--json] received, not yet deleted omamobile-sit sms delete ID - omamobile-sit data on|off the cellular fallback route (rmnet0) + omamobile-sit data on|off the cellular fallback route (rmnet) omamobile-sit radio on|off AT+CFUN 1/0 (registration and bearers go with "off"; a restart needs a reboot) diff --git a/packages/omamobile-modem-sit/bin/omamobile-sit-data b/packages/omamobile-modem-sit/bin/omamobile-sit-data index e256494af..a42aac1d2 100755 --- a/packages/omamobile-modem-sit/bin/omamobile-sit-data +++ b/packages/omamobile-modem-sit/bin/omamobile-sit-data @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: MIT -# omamobile-sit-data: the cellular fallback route on rmnet0 (lib/data_network.py). +# omamobile-sit-data: the cellular fallback route on the bearer's rmnet device (lib/data_network.py). import os import sys diff --git a/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf b/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf index a55b4fc90..69ea88bd3 100644 --- a/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf +++ b/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf @@ -6,6 +6,13 @@ # The carrier's internet APN, as the carrier publishes it. Required: without # it the start-up stops before the radio is switched on. apn = +# The APN of the initial LTE attach, if the carrier attaches on another APN +# than its internet APN (some attach only on their IMS APN, e.g. "ims"; the +# internet bearer still uses apn). Empty: the same as apn. +# The attach APN, the data profiles ([profiles] below) and the NR mode are +# sent before the radio is switched on, or with it on if it already is: the +# radio is never cycled. +attach_apn = # The internet bearer's IP type: ipv4v6, ipv4 or ipv6. The cellular route # (omamobile-sit-data) is IPv4 only for now. ip_type = ipv4v6 @@ -17,14 +24,49 @@ ims_apn = ims # without SMS or calls. ims_required = yes ends start-up instead. ims_required = no ims_timeout = 120 +# The IMS registration needs a P-CSCF from the IMS bearer. "no" registers +# without one when the bearer carries none, leaving it to the modem's IMS +# stack (some networks keep it on the ISIM, not in the bearer). +ims_pcscf_required = yes +# The modem's carrier profile: the 40-character cfg.db manifest ID for this +# SIM's carrier (a file name under the modem chroot's +# /vendor/firmware/carrierconfig/manifests). Set, it answers the modem's +# request for a carrier config once, and the IMS stack start waits up to +# carrier_manifest_timeout seconds for the modem's answer. Empty: not sent. +carrier_manifest = +carrier_manifest_timeout = 60 # nr = off keeps the modem on LTE (NR mode byte 3 -> 0; the original is kept -# in RAM). On this phone NR registered but carried no traffic. "on" leaves -# the modem's own setting alone. +# in RAM), set before the radio is switched on. On this phone NR registered +# but carried no traffic. "on" leaves the modem's own setting alone. nr = off # Seconds to wait for the SIM, then for packet registration. sim_timeout = 120 register_timeout = 180 +[profiles] +# Extra data profiles the modem manages itself (SET_DATA_PROFILE), sent with +# the attach APN before the radio is switched on, as stock sends its +# carrier's "modem-cognitive" APNs. Empty (the default): only profile 0, the +# internet APN above. One line per profile: +# +# ID = APN; types=TYPE,TYPE; ip=IP; roaming_ip=IP +# +# ID: 0 default/internet (replaces the one made from apn; the internet +# bearer still uses apn), 2 IMS, 3 FOTA, 4 CBS (1 tethered, 1000 and up +# OEM). +# types (required): default, mms, supl, dun, hipri, fota, ims, cbs, ia, +# emergency, mcx, xcap. +# ip: ipv4v6 (default), ipv4 or ipv6; roaming_ip: the same choices, default ip. +# No authentication. Each profile gets stock's limits: 20 connections in +# 300 s, no wait, enabled, any bearer. +# +# Example, a carrier that attaches on its IMS APN (with attach_apn = IMS, +# ims_apn = IMS and apn = VZWINTERNET above): +# 0 = VZWINTERNET; types=default,supl,dun; ip=ipv4v6 +# 2 = IMS; types=ia,ims; ip=ipv4v6; roaming_ip=ipv6 +# 3 = VZWADMIN; types=fota +# 4 = VZWAPP; types=cbs,mms + [data] # Reserved: the route's metric is fixed at 700 (Wi-Fi's default is 600). metric = 700 diff --git a/packages/omamobile-modem-sit/lib/at.py b/packages/omamobile-modem-sit/lib/at.py index 721453203..c51c9e132 100644 --- a/packages/omamobile-modem-sit/lib/at.py +++ b/packages/omamobile-modem-sit/lib/at.py @@ -1,9 +1,9 @@ # SPDX-License-Identifier: MIT """Fixed AT commands on CPIF's router channel (/dev/umts_router). -Only radio power goes this way: the start-up sequence that registered on -this phone switched the radio with AT+CFUN, and SIT radio power and AT CFUN -were seen to disagree. No arbitrary command can be sent from here. +Only radio power goes this way (and its read-only query): the start-up +sequence that registered on this phone switched the radio with AT+CFUN, and +SIT radio power and AT CFUN were seen to disagree. No arbitrary command can be sent from here. """ import os import re @@ -47,3 +47,17 @@ def radio(enabled): raise RuntimeError('Radio command was not accepted') finally: os.close(fd) + + +def radio_state(): + """AT+CFUN?: the functionality level (0 minimum, 1 full, 4 flight), or + None when the answer can't be read. Read-only.""" + fd = open_channel(ROUTER) + try: + response = exchange(fd, COMMANDS['radio-state'], 10) + finally: + os.close(fd) + found = re.search(r'\+CFUN:\s*(\d+)', response) + if not found or not re.search(r'(?:^|[\r\n])OK(?:[\r\n]|$)', response): + return None + return int(found.group(1)) diff --git a/packages/omamobile-modem-sit/lib/bringup.py b/packages/omamobile-modem-sit/lib/bringup.py index 45e2a98aa..bad3698f4 100644 --- a/packages/omamobile-modem-sit/lib/bringup.py +++ b/packages/omamobile-modem-sit/lib/bringup.py @@ -4,12 +4,18 @@ 1. wait for the USIM application to be READY (type 2, state 5); a PIN, PUK or network lock ends start-up at once (no PIN entry here); - 2. radio off (AT+CFUN=0), initial attach APN, the default data profile; - 3. radio on (AT+CFUN=1), wait for packet registration; - 4. NR mode 0 ([network] nr = off): stay on LTE (NR registered, but - carried no traffic on this phone), wait for LTE registration; - 5. the internet bearer (CID 1, rmnet0); - 6. IMS: stack start, the IMS bearer (CID 2, IPv6), ADD_PDN_INFO, then wait + 2. read the radio state (AT+CFUN?); then, with the radio as found, the + initial attach APN ([network] attach_apn, else apn), every data + profile (profile 0 from apn unless [profiles] has its own, then the + rest of [profiles]) and NR mode 0 ([network] nr = off: stay on LTE; NR + registered but carried no traffic on this phone); + 3. radio on (AT+CFUN=1) once, unless it was already on: stock's order, + with no radio cycle (device/cheetah/MODEM-PROVIDER-PROFILES.md + section 2). An unreadable radio state falls back to 0.3.14's cycle + (AT+CFUN=0 first). Then wait for packet registration (on LTE with + nr = off) and log how long it took; + 4. the internet bearer (CID 1; its rmnet device is found by omamobile-sit-data); + 5. IMS: stack start, the IMS bearer (CID 2, IPv6), ADD_PDN_INFO, then wait for an IMS registration with voice and SMS. No retransmission of SMS/calls and no warm CP restart. A failed or uncertain @@ -19,10 +25,11 @@ """ import time -from at import radio -from data_call import activate, initial_attach, provision_default_profile +from at import radio, radio_state +from data_call import activate, configured_profiles, initial_attach, provision_profiles from ims import register, start_stack -from radio_settings import nr_mode +from radio_settings import SAVED_NR, nr_mode +from sit import ModemError def sim_ready(payload): @@ -60,9 +67,8 @@ def sim_lock(payload): def data_snapshot(client, label): - """Registration and the data-call list, as the modem reports them, before - and after the NR change: whether a bearer is ever listed before the - setup, and whether the change makes one appear or disappear. States, + """Registration and the data-call list, as the modem reports them at + registration: whether a bearer is ever listed before the setup. States, codes and counts only.""" try: reg = client.request(0x0701) @@ -112,6 +118,16 @@ def start(service, settings, stopped=lambda: False): apn, ip_type = net.get('apn', ''), net.get('ip_type', 'ipv4v6') if not apn: raise RuntimeError('No APN configured: set [network] apn in /etc/omamobile/modem-sit.conf') + # Some networks attach only on their IMS APN (2026-11-02, cheetah: with + # the internet APN as the attach APN the modem searched for 13 minutes + # with no reject; with the IMS APN it registered on LTE in 34 s). The + # data profile and the internet bearer keep apn. Empty: the same as apn. + attach_apn = net.get('attach_apn', '').strip() or apn + try: + profiles = configured_profiles(settings) + except ValueError as error: + raise RuntimeError(f'Bad data profile in /etc/omamobile/modem-sit.conf: {error}') from None + began = time.monotonic() previous = None locked = None @@ -145,20 +161,64 @@ def usim_ready(): 2: 'card error'}.get(previous[0] if previous else None, 'unknown card state') raise TimeoutError(f'No ready USIM within {timeout} s ({card})') from None service.stage('attach') - radio(False) - initial_attach(client, apn, ip_type) - provision_default_profile(client, apn, ip_type) + level = radio_state() + if level is None: + # Unknown: 0.3.14's known-good cycle rather than a guess. + print('Startup: radio state unreadable; switching it off before the attach settings', flush=True) + radio(False) + already_on = False + else: + already_on = level == 1 + print(f'Startup: radio state {level} ({"on: no radio cycle" if already_on else "off"})', flush=True) + # Attaching on the IMS APN: ask for the P-CSCF in the attach, as stock does + # for an IMS APN, since that bearer is the one IMS then uses. + ims_attach = (attach_apn != apn and net.getboolean('ims', True) + and attach_apn == net.get('ims_apn', 'ims')) + if attach_apn != apn: + print('initial attach on attach_apn, not the internet APN' + + (' (the IMS APN: P-CSCF requested)' if ims_attach else ''), flush=True) + initial_attach(client, attach_apn, ip_type, ims=ims_attach) + if profiles[0].ident == 0 and profiles[0].apn != apn: + print('data profile 0 from [profiles], with another APN than [network] apn ' + '(the internet bearer uses apn)', flush=True) + provision_profiles(client, profiles) + lte = net.get('nr', 'off') == 'off' + nr_after_radio = False + if lte: + # Before radio on, as stock sets its network type: changed after + # registration it made the CP register again. This modem refuses + # SET_NR_MODE with the radio off (error 2, 2026-11-02), so then it is + # set right after radio on, still before registration. + try: + nr_mode(client) + except ModemError as error: + if already_on: + raise + SAVED_NR.unlink(missing_ok=True) + nr_after_radio = True + print(f'NR mode refused with the radio off ({error}); setting it after radio on', flush=True) service.pump() - radio(True) + if not already_on: + radio(True) + began = time.monotonic() + if nr_after_radio: + nr_mode(client) service.stage('registering') - print('Startup: waiting for packet registration', flush=True) + print('Startup: waiting for packet registration' + (' on LTE' if lte else ''), flush=True) timeout = net.getint('register_timeout', 180) - wait_for(service, lambda: packet_registered(client.request(0x0701)), timeout, stopped) - data_snapshot(client, 'before the NR change') - if net.get('nr', 'off') == 'off': - nr_mode(client) - wait_for(service, lambda: packet_registered(client.request(0x0701), lte=True), 120, stopped) - data_snapshot(client, 'after the NR change') + first = None + + def registered(): + nonlocal first + state = client.request(0x0701) + if first is None and packet_registered(state): + first = time.monotonic() + print(f'Registration: packet registered {first - began:.1f} s after ' + + ('start-up began (the radio was already on)' if already_on else 'radio on') + + f', RAT {state[3]}', flush=True) + return packet_registered(state, lte=lte) + wait_for(service, registered, timeout, stopped) + data_snapshot(client, 'at registration') service.stage('data') activate(client, apn, ip_type=ip_type, on_event=service.event) service.pump() @@ -169,9 +229,22 @@ def usim_ready(): service.ims_state = 'pending' service.stage('ims') try: + if net.get('carrier_manifest', '').strip(): + # As stock's IMS service: no stack start while the modem applies + # its carrier profile. The modem's 0x4602 arrives on its own after + # the SIM loads; service.event answers it and records the 0x4601. + limit = net.getint('carrier_manifest_timeout', 60) + try: + wait_for(service, lambda: service.carrier_status is not None, limit, stopped) + print('IMS stack start released (after carrier config: status', + service.carrier_status[0], 'cause', service.carrier_status[1], ')', flush=True) + except TimeoutError: + print('IMS stack start released (timeout: no carrier config status in', limit, 's;', + 'manifest sent' if service.manifest_sent else 'no request from the modem seen', ')', + flush=True) start_stack(client) activate(client, net.get('ims_apn', 'ims'), ims=True, on_event=service.event) - register(client) + register(client, pcscf_required=net.getboolean('ims_pcscf_required', True)) print('Startup: waiting for IMS voice and SMS registration', flush=True) wait_for(service, lambda: service.registration().get('state') == 2 and service.registration().get('features', 0) & 3 == 3, diff --git a/packages/omamobile-modem-sit/lib/carrier_manifest.py b/packages/omamobile-modem-sit/lib/carrier_manifest.py new file mode 100644 index 000000000..ed112119e --- /dev/null +++ b/packages/omamobile-modem-sit/lib/carrier_manifest.py @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: MIT +"""The modem's carrier profile, named by hand ([network] carrier_manifest). + +After the SIM loads, the CP sends OEM_IND_CARRIER_CONFIG_SIM_INFO (0x4602) +and waits for the AP to name a carrier manifest. Stock's libsitril answers +it with OEM_SET_CARRIER_CONFIG_MANIFEST (0x4600), only ever as that answer +(OnOemCpCarrierConfigSimInfoInd queues DoOemSetCpCarrierConfig with the +indication); the CP then reads the manifest and its configuration sequences +from the carrier-config directory through rfsd and reports the outcome in +OEM_IND_CARRIER_CONFIG_STATUS (0x4601). Stock's IMS service holds the AIMS +stack start until that status has come. + +Here the manifest ID is set by hand in the configuration, and 0x4602 is +only a trigger: its payload is never read. Empty setting: nothing is sent, +and 0x4600 stays on the transport's do-not-send list. + +0x4600 (stock ProtocolMiscBuilder::BuildSetCpCarrierConfig, 532 bytes with +the header): 0x0c u32 length and 0x10 the directory string (stock passes +CarrierConfigManager's "/vendor/firmware/carrierconfig"), 0x110 u32 length +and 0x114 the encoded manifest (CarrierManifest::getEncodedManifest: the +manifest's hex ID decoded to bytes). 0x4601 (stock +ProtocolMiscCarrierConfigStatusIndAdapter): 0x08 u32 status, 0x0c u32 cause. +""" +import os +from pathlib import Path +import re +import struct + +DIRECTORY = '/vendor/firmware/carrierconfig' +# The modem chroot's image on the host (omamobile-vendor-chroot's IMAGE). +HOST_DIRECTORY = Path(os.environ.get('OMAMOBILE_SIT_CARRIERCONFIG', + '/usr/lib/omamobile-vendor/modem/root' + DIRECTORY)) + + +def manifest_id(value, directory=None): + """The 20-byte manifest ID for a configured value, or raise ValueError + with the reason: exactly 40 hex characters, and manifests/ present + in the chroot's carrier-config directory (where the CP will read it).""" + value = (value or '').strip().lower() + if not re.fullmatch(r'[0-9a-f]{40}', value): + raise ValueError('carrier_manifest is not a 40-character hex manifest ID') + if not ((directory or HOST_DIRECTORY) / 'manifests' / value).is_file(): + raise ValueError('carrier_manifest names no manifest in the modem chroot ' + '(re-run tools/extract-vendor-chroot -p modem)') + return bytes.fromhex(value) + + +def request_payload(ident): + """The 0x4600 payload (the 532-byte request without its 12-byte header).""" + if len(ident) > 256: + raise ValueError('manifest ID too long') + payload = bytearray(0x214 - 12) + path = DIRECTORY.encode('ascii') + struct.pack_into('; data_network.find_device checks which device +really carries the internet bearer (it differed when the attach bearer was on +another APN). The APN comes from /etc/omamobile/modem-sit.conf. Ownership is recorded in RAM before a setup is sent: a setup or release with an unknown outcome @@ -37,6 +40,28 @@ def paths(cid): raise ValueError('unsupported bearer CID') +def pcscf_addresses(response): + """The P-CSCF addresses of a setup response or data-call item, as stock's + ProtocolPsSetupDataCallAdapter reads them: the base item's family byte at + 0x42 (1 IPv4, 2 IPv6, 3 both), three IPv4 at 0x43 and three IPv6 at 0x4f; + then, when the item is longer than the 132-byte base and its extension + version byte at 0x84 is 2 or more, five IPv4 at 0x86 and five IPv6 at + 0x9a (the 234-byte item). Empty slots are skipped, duplicates dropped. + Returns (IPv4 list, IPv6 list) of raw addresses; never log the values.""" + v4, v6 = [], [] + if len(response) >= 132: + family = response[0x42] + if family in (1, 3): + v4 += [bytes(response[i:i + 4]) for i in (0x43, 0x47, 0x4b)] + if family in (2, 3): + v6 += [bytes(response[i:i + 16]) for i in (0x4f, 0x5f, 0x6f)] + if len(response) >= 0xea and response[0x84] >= 2: + v4 += [bytes(response[i:i + 4]) for i in range(0x86, 0x9a, 4)] + v6 += [bytes(response[i:i + 16]) for i in range(0x9a, 0xea, 16)] + return ([a for a in dict.fromkeys(v4) if any(a)], + [a for a in dict.fromkeys(v6) if any(a)]) + + def check_apn(apn): """An APN as a carrier publishes it: labels of letters, digits and '-', joined by dots, at most 99 characters (the request's field is 100 bytes).""" @@ -115,14 +140,28 @@ def setup_payload(cid, radio_technology, pdu_session, apn, *, ims=False, ip_type return bytes(full[12:]) -def initial_attach(client, apn, ip_type='ipv4v6'): +# The P-CSCF request type, as stock's GetPcscfReqType maps the APN protocol: +# IP 1, IPV6 2, IPV4V6 3. +PCSCF_REQUEST = {'ipv4': 1, 'ipv6': 2, 'ipv4v6': 3} + + +def initial_attach(client, apn, ip_type='ipv4v6', *, ims=False): """SET_INITIAL_ATTACH_APN (251 bytes). Without it, setup requests on this - phone returned status 36 and no bearer.""" + phone returned status 36 and no bearer. + + ims: the attach APN is the IMS APN (a network that attaches only there). + Stock's builder then writes the APN type at 0x0f and asks for the P-CSCF + at 0xdb (home) and 0xf9 (roaming) with GetPcscfReqType, so the network + returns its P-CSCF addresses in the attach bearer's PCO; without the + request, IMS on that bearer has none.""" attach = bytearray(251) attach[12:245] = setup_payload(1, 14, 0, apn, ip_type=ip_type)[:233] # Stock's attach builder leaves 0xf1-0xf4 zero: no APN-type bitmap here. attach[0xf1:0xf5] = bytes(4) - attach[0xf8] = 3 # the roaming PDP type, IPv4v6 (the home type is 0xda) + attach[0xf8] = IP_TYPES[ip_type] # the roaming PDP type (the home type is 0xda) + if ims: + attach[0x0f] = 1 # IMS APN type, as in the IMS setup request + attach[0xdb] = attach[0xf9] = PCSCF_REQUEST[ip_type] client.request(0x0603, bytes(attach[12:]), timeout=30) @@ -136,20 +175,137 @@ def allow_data(client): print('PS service permission enabled', flush=True) -def provision_default_profile(client, apn, ip_type='ipv4v6'): - # Stock BuildSetDataProfile, 246-byte request. This configures the - # network APN profile, not a SIM subscription or UICC operation. - encoded = check_apn(apn).encode('ascii') +# SET_DATA_PROFILE's APN-type bitmask (Android's ApnSetting TYPE_*_BITMASK). +APN_TYPES = {'default': 1, 'mms': 2, 'supl': 4, 'dun': 8, 'hipri': 16, 'fota': 32, + 'ims': 64, 'cbs': 128, 'ia': 256, 'emergency': 512, 'mcx': 1024, 'xcap': 2048} +# Android's profile IDs: 0 default (internet), 1 tethered, 2 IMS, 3 FOTA, +# 4 CBS; OEM profiles start at 1000. +PROFILE_IDS = 'a profile ID 0-4, or 1000 and up' +PROFILE_KEYS = ('types', 'ip', 'roaming_ip') + + +class Profile: + """One modem-managed data profile, as stock's BuildSetDataProfile sends it. + The defaults are stock's: 20 connections in 300 s, no wait, enabled, any + bearer, no authentication.""" + + def __init__(self, ident, apn, types, ip='ipv4v6', roaming_ip=None, *, + max_conns=20, max_conns_time=300, wait_time=0): + if not (0 <= ident <= 4 or 1000 <= ident <= 0x7fffffff): + raise ValueError(f'profile ID {ident}: not {PROFILE_IDS}') + if not types or types & ~sum(APN_TYPES.values()): + raise ValueError(f'profile {ident}: invalid APN types') + roaming_ip = roaming_ip or ip + for value in (ip, roaming_ip): + if value not in IP_TYPES: + raise ValueError(f'profile {ident}: IP type {value!r} is not ipv4, ipv6 or ipv4v6') + self.ident, self.apn, self.types = ident, check_apn(apn), types + self.ip, self.roaming_ip = ip, roaming_ip + self.max_conns, self.max_conns_time, self.wait_time = max_conns, max_conns_time, wait_time + + def __eq__(self, other): + return isinstance(other, Profile) and vars(self) == vars(other) + + def __repr__(self): + return f'Profile({self.ident}, {self.apn!r}, types=0x{self.types:x})' + + def type_names(self): + return ','.join(n for n, bit in APN_TYPES.items() if self.types & bit) + + +def default_profile(apn, ip_type='ipv4v6'): + """Profile 0 from [network] apn, byte for byte what 0.3.14 and earlier + sent (the connection limits and wait left 0): the default profile that + registered and carried data on both phones.""" + return Profile(0, apn, APN_TYPES['default'], ip_type, max_conns=0, max_conns_time=0) + + +def parse_profile(key, value): + """A [profiles] line: "ID = APN; types=a,b; ip=TYPE; roaming_ip=TYPE". + types is required; ip defaults to ipv4v6 and roaming_ip to ip.""" + try: + ident = int(key.strip(), 10) + except ValueError: + raise ValueError(f'profile {key!r}: the key must be {PROFILE_IDS}') from None + apn, *fields = [part.strip() for part in value.split(';')] + options = {} + for field in fields: + name, sep, item = (x.strip() for x in field.partition('=')) + name = name.lower() + if not sep or name not in PROFILE_KEYS or not item: + raise ValueError(f'profile {ident}: {field!r} is not one of ' + + ', '.join(k + '=...' for k in PROFILE_KEYS)) + if name in options: + raise ValueError(f'profile {ident}: {name} given twice') + options[name] = item.lower() + if 'types' not in options: + raise ValueError(f'profile {ident}: types=... is required') + types = 0 + for name in options.pop('types').split(','): + name = name.strip() + if name not in APN_TYPES: + raise ValueError(f'profile {ident}: unknown APN type {name!r}') + types |= APN_TYPES[name] + try: + check_apn(apn) + except ValueError: + raise ValueError(f'profile {ident}: the APN is missing or not a plain carrier APN') from None + return Profile(ident, apn, types, **options) + + +def configured_profiles(settings): + """The profiles to send, in profile ID order: [profiles] as written, and + profile 0 from [network] apn unless [profiles] has its own 0. Raises + ValueError on any bad line (start-up then stops before the radio).""" + net = settings['network'] + found = {} + if settings.has_section('profiles'): + for key, value in settings.items('profiles', raw=True): + if key in settings.defaults(): + continue + profile = parse_profile(key, value) + if profile.ident in found: + raise ValueError(f'profile {profile.ident} given twice') + found[profile.ident] = profile + if 0 not in found: + found[0] = default_profile(net.get('apn', ''), net.get('ip_type', 'ipv4v6')) + return [found[i] for i in sorted(found)] + + +def profile_payload(profile): + """Stock BuildSetDataProfile (V2_0), the 246-byte request. Offsets below + include the 12-byte request header. This configures a network APN + profile, not a SIM subscription or UICC operation.""" full = bytearray(246) - struct.pack_into(' 0x84 else None, + 'P-CSCF count IPv4', len(v4), 'IPv6', len(v6), flush=True) finally: if released: state_path.unlink(missing_ok=True) @@ -303,9 +460,16 @@ def deactivate(client, cid=1): owned = json.loads(state_path.read_text()) if owned.get('cid') != cid or not 0 <= owned.get('session', -1) <= 15: raise RuntimeError('invalid bearer ownership record') - flags = int(Path(f"/sys/class/net/rmnet{owned['cid'] - 1}/flags").read_text(), 16) - if flags & 1: - raise RuntimeError('remove host data configuration first') + # rmnet, and the device omamobile-sit-data found carrying it + # (data_network.find_device), while that configuration exists. + devices = {f"rmnet{owned['cid'] - 1}"} + recorded = RUN / 'data-interface' + if cid == 1 and recorded.exists(): + devices.add(recorded.read_text().strip()) + for dev in devices: + flags = Path(f'/sys/class/net/{dev}/flags') + if flags.exists() and int(flags.read_text(), 16) & 1: + raise RuntimeError('remove host data configuration first') # Stock BuildDeactDataCall: CID and normal-release reason. client.request(0x0601, bytes([owned['cid'], 0]), timeout=30) calls = call_ids(client.request(0x0602)) diff --git a/packages/omamobile-modem-sit/lib/data_network.py b/packages/omamobile-modem-sit/lib/data_network.py index 5500b61f1..68d8d3b9d 100644 --- a/packages/omamobile-modem-sit/lib/data_network.py +++ b/packages/omamobile-modem-sit/lib/data_network.py @@ -3,12 +3,21 @@ """omamobile-sit-data: the internet bearer (CID 1) as a fallback behind Wi-Fi. CPIF's rmnet devices are raw-IP links that NetworkManager doesn't manage -(the package marks rmnet* unmanaged). This owns only rmnet0's /32 address, -a metric-700 default route (Wi-Fi's default is 600, so Wi-Fi wins while it -is up) and the carrier's DNS while rmnet0 is the only way out. All state and -rollback records stay in RAM; nothing here is logged with an address. - -The carrier's DNS is used only while rmnet0 is the only way out. A bearer +(the package marks rmnet* unmanaged). This owns only the bearer's rmnet +device: its /32 address, a metric-700 default route (Wi-Fi's default is 600, +so Wi-Fi wins while it is up) and the carrier's DNS while it is the only way +out. All state and rollback records stay in RAM; nothing here is logged with +an address. + +Which rmnet carries the bearer: stock's RIL names it rmnet +(PdpContext's "%s%d" with the RIL socket's ifprefix and ifstart), and that is +tried first. On a network that attaches on another APN than the internet one, +the attach bearer held rmnet0 and the CID 1 internet bearer came out on +rmnet1 (cheetah, 2026-11-02), so the rest are tried after it: the device +that answers a ping with the bearer's address is the one kept, and its name +is recorded in RAM (data-interface) for the bearer's release. + +The carrier's DNS is used only while the bearer is the only way out. A bearer that sends but receives nothing, and then answers no ping either, loses its default route, and gets it back as soon as nothing else is left: otherwise a dead bearer's route plus its DNS can outlive a short Wi-Fi outage, make @@ -30,6 +39,9 @@ from data_call import RESPONSE RESOLVER = Path('/etc/resolv.conf') +INTERFACE = paths.RUN / 'data-interface' +# rmnet0-rmnet7 are tried; CPIF creates 30, a phone uses a handful. +CANDIDATES = 8 def run(*args): @@ -53,7 +65,7 @@ def configuration(data): def counters(stats): - """(received bytes, sent packets) from `ip -j -s link` output for rmnet0.""" + """(received bytes, sent packets) from `ip -j -s link` output for the device.""" link = stats[0]['stats64'] return link['rx']['bytes'], link['tx']['packets'] @@ -76,10 +88,10 @@ def guarded(step): return None -def answers(): - """Whether the bearer carries anything: a ping out through rmnet0.""" +def answers(dev): + """Whether the bearer carries anything: a ping out through its device.""" for target in ('1.1.1.1', '8.8.8.8'): - p = subprocess.run(['ping', '-n', '-q', '-c', '1', '-W', '3', '-I', 'rmnet0', target], + p = subprocess.run(['ping', '-n', '-q', '-c', '1', '-W', '3', '-I', dev, target], capture_output=True, timeout=10) if p.returncode == 0: return True @@ -115,28 +127,112 @@ def restore(self): class ResolvedLink: - """The same with systemd-resolved: rmnet0's DNS servers are set once and + """The same with systemd-resolved: the device's DNS servers are set once and the link is the default DNS route only while cellular is the only way out.""" - def __init__(self, servers): - run('resolvectl', 'dns', 'rmnet0', *servers) + def __init__(self, servers, dev): + self.dev = dev + run('resolvectl', 'dns', dev, *servers) self.cellular = None def update(self, cellular, servers): if cellular != self.cellular: - run('resolvectl', 'default-route', 'rmnet0', 'yes' if cellular else 'no') + run('resolvectl', 'default-route', self.dev, 'yes' if cellular else 'no') self.cellular = cellular def restore(self): - subprocess.run(['resolvectl', 'revert', 'rmnet0'], capture_output=True, timeout=20) + subprocess.run(['resolvectl', 'revert', self.dev], capture_output=True, timeout=20) -def resolver_for(servers): +def resolver_for(servers, dev): target = str(RESOLVER.resolve()) if RESOLVER.exists() else '' if target.startswith('/run/systemd/resolve/'): - return ResolvedLink(servers) + return ResolvedLink(servers, dev) return Resolver(RESOLVER) +def candidates(cid): + """rmnet (stock's name for the bearer) first, then the others.""" + first = cid - 1 + return [f'rmnet{first}'] + [f'rmnet{i}' for i in range(CANDIDATES) if i != first] + + +def unused(dev): + """The device exists and nobody has configured it (down, no address).""" + try: + info = json.loads(run('ip', '-j', 'address', 'show', 'dev', dev))[0] + except (RuntimeError, ValueError, IndexError): + return False + return 'UP' not in info['flags'] and not info['addr_info'] + + +def put_back(dev, address=None): + """Undo a candidate's configuration, every step on its own and none + fatal: whatever was set before a failure or a stop goes. Only devices + this service records (data-interface) or is probing get here, and rmnet + devices carry nothing but this service's configuration.""" + steps = [('ip', 'route', 'del', 'default', 'dev', dev, 'metric', '700')] + steps.append(('ip', 'addr', 'del', address + '/32', 'dev', dev) if address + else ('ip', 'addr', 'flush', 'dev', dev)) + steps.append(('ip', 'link', 'set', 'dev', dev, 'down')) + for step in steps: + try: + subprocess.run(step, capture_output=True, timeout=20) + except (OSError, subprocess.SubprocessError): + pass + + +def clear_stale(): + """A device recorded by a run that ended without its cleanup (killed, or + stopped before 0.3.12 while probing): put it back before anything else.""" + try: + dev = INTERFACE.read_text().strip() + except OSError: + return + if dev.startswith('rmnet') and dev[5:].isdigit(): + put_back(dev) + print('Removed a configuration left on', dev, 'by an earlier run', flush=True) + INTERFACE.unlink(missing_ok=True) + + +def find_device(address, cid, probe=None, stopped=lambda: False): + """Bring each unused candidate up with the bearer's /32 and the metric-700 + default route until one carries it (ping -I binds to the device, so the + route through it is used even with Wi-Fi's better one present); that one + keeps its address and route. Every other one is put back as it was, also + when a step fails or the service is stopped in the middle (the record in + data-interface is written before the device is touched, so a run that is + killed outright is cleaned up by the next start).""" + probe = probe or answers + for dev in candidates(cid): + if stopped(): + break + if not unused(dev): + continue + paths.run_dir() + INTERFACE.write_text(dev + '\n') + kept = False + try: + run('ip', 'link', 'set', 'dev', dev, 'up') + run('ip', 'addr', 'add', address + '/32', 'dev', dev) + run('ip', 'route', 'add', 'default', 'dev', dev, 'src', address, 'metric', '700') + try: + kept = probe(dev) and not stopped() + except subprocess.SubprocessError: + kept = False + except RuntimeError: + kept = False + finally: + if not kept: + put_back(dev, address) + INTERFACE.unlink(missing_ok=True) + if kept: + print('Bearer CID', cid, 'carried by', dev, flush=True) + return dev + if stopped(): + raise InterruptedError('Stopped while looking for the bearer device') + raise RuntimeError('No rmnet device carries the internet bearer (no ping answered)') + + def wait_for_bearer(seconds): deadline = time.monotonic() + seconds while not RESPONSE.exists(): @@ -149,35 +245,34 @@ def main(): os.umask(0o077) lock = os.open(paths.RUN / 'data-network.lock', os.O_CREAT | os.O_RDWR, 0o600) fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) + clear_stale() wait_for_bearer(60) - address, dns = configuration(RESPONSE.read_bytes()) - info = json.loads(run('ip', '-j', 'address', 'show', 'dev', 'rmnet0'))[0] - if 'UP' in info['flags'] or info['addr_info']: - raise RuntimeError('rmnet0 already configured; refusing to replace it') - resolver = resolver_for(dns) + data = RESPONSE.read_bytes() + address, dns = configuration(data) stopping = False addressed = False + dev = None def stop(*_): nonlocal stopping stopping = True signal.signal(signal.SIGTERM, stop) signal.signal(signal.SIGINT, stop) + resolver = None try: - run('ip', 'link', 'set', 'dev', 'rmnet0', 'up') - run('ip', 'addr', 'add', address + '/32', 'dev', 'rmnet0') + dev = find_device(address, data[2], stopped=lambda: stopping) addressed = True - run('ip', 'route', 'add', 'default', 'dev', 'rmnet0', 'src', address, 'metric', '700') + resolver = resolver_for(dns, dev) print('Cellular fallback ready; Wi-Fi remains preferred', flush=True) last = None - seen = counters(json.loads(run('ip', '-j', '-s', 'link', 'show', 'dev', 'rmnet0'))) + seen = counters(json.loads(run('ip', '-j', '-s', 'link', 'show', 'dev', dev))) check_at = time.monotonic() + 30 def watch(): nonlocal last, seen, check_at routes = json.loads(run('ip', '-j', 'route', 'show', 'default')) - routed = any(r.get('dev') == 'rmnet0' for r in routes) - others = [r for r in routes if r.get('dev') != 'rmnet0'] + routed = any(r.get('dev') == dev for r in routes) + others = [r for r in routes if r.get('dev') != dev] # With Wi-Fi up but rated limited, the carrier's DNS would keep # NetworkManager's own check failing and Wi-Fi penalised. cellular = routed and not others @@ -186,14 +281,14 @@ def watch(): print('Default internet path', 'cellular' if cellular else 'Wi-Fi/other', flush=True) last = cellular if not routed and not others: - run('ip', 'route', 'add', 'default', 'dev', 'rmnet0', 'src', address, 'metric', '700') + run('ip', 'route', 'add', 'default', 'dev', dev, 'src', address, 'metric', '700') print('Nothing else leads out; the cellular default route is back', flush=True) elif time.monotonic() >= check_at: - now = counters(json.loads(run('ip', '-j', '-s', 'link', 'show', 'dev', 'rmnet0'))) - if looks_silent(routed, seen, now) and not answers(): - run('ip', 'route', 'del', 'default', 'dev', 'rmnet0', 'metric', '700') + now = counters(json.loads(run('ip', '-j', '-s', 'link', 'show', 'dev', dev))) + if looks_silent(routed, seen, now) and not answers(dev): + run('ip', 'route', 'del', 'default', 'dev', dev, 'metric', '700') print('Cellular bearer carries nothing; its default route is removed', flush=True) - now = counters(json.loads(run('ip', '-j', '-s', 'link', 'show', 'dev', 'rmnet0'))) + now = counters(json.loads(run('ip', '-j', '-s', 'link', 'show', 'dev', dev))) seen = now check_at = time.monotonic() + 30 failing = None @@ -205,14 +300,20 @@ def watch(): print('Network checks work again', flush=True) failing = error time.sleep(2 if error else .5) + except InterruptedError: + # Stopped while probing: find_device has put the candidate back. + pass finally: - resolver.restore() - routes = json.loads(run('ip', '-j', 'route', 'show', 'default')) - if any(r.get('dev') == 'rmnet0' and r.get('metric') == 700 for r in routes): - run('ip', 'route', 'del', 'default', 'dev', 'rmnet0', 'metric', '700') - if addressed: - run('ip', 'addr', 'del', address + '/32', 'dev', 'rmnet0') - run('ip', 'link', 'set', 'dev', 'rmnet0', 'down') + if resolver: + resolver.restore() + if dev: + routes = json.loads(run('ip', '-j', 'route', 'show', 'default')) + if any(r.get('dev') == dev and r.get('metric') == 700 for r in routes): + run('ip', 'route', 'del', 'default', 'dev', dev, 'metric', '700') + if addressed: + run('ip', 'addr', 'del', address + '/32', 'dev', dev) + run('ip', 'link', 'set', 'dev', dev, 'down') + INTERFACE.unlink(missing_ok=True) os.close(lock) print('Cellular fallback configuration removed', flush=True) diff --git a/packages/omamobile-modem-sit/lib/ims.py b/packages/omamobile-modem-sit/lib/ims.py index db8d02aab..2029c0127 100644 --- a/packages/omamobile-modem-sit/lib/ims.py +++ b/packages/omamobile-modem-sit/lib/ims.py @@ -10,7 +10,7 @@ import struct import time -from data_call import paths, call_ids, private_write +from data_call import paths, call_ids, pcscf_addresses, private_write from paths import RUN REGISTRATION = RUN / 'ims-registration.json' @@ -45,17 +45,25 @@ def hidden_menu(): return struct.pack(' so the group reaches state.json and the + socket; a client that reset it to 0700 hid the modem from the shell.""" + if not RUN.exists(): + return private_dir(RUN) + mode = RUN.stat().st_mode & 0o777 + if mode & ~0o710: + RUN.chmod(mode & 0o710) + return RUN diff --git a/packages/omamobile-modem-sit/lib/radio_settings.py b/packages/omamobile-modem-sit/lib/radio_settings.py index af2ac8e72..e8303914a 100644 --- a/packages/omamobile-modem-sit/lib/radio_settings.py +++ b/packages/omamobile-modem-sit/lib/radio_settings.py @@ -22,6 +22,11 @@ def nr_mode(client, restore=False): raise RuntimeError('invalid saved NR mode') else: if SAVED_NR.exists(): + # An earlier start-up on this CP (sitd started again in the same + # boot) already set mode 0 and kept the original: nothing to do. + if current == b'\0': + print('verified NR mode 0 (set by an earlier start-up this boot)', flush=True) + return raise RuntimeError('NR experiment already active') private_write(SAVED_NR, current) target = b'\0' diff --git a/packages/omamobile-modem-sit/lib/service.py b/packages/omamobile-modem-sit/lib/service.py index 23de551fb..f62572428 100644 --- a/packages/omamobile-modem-sit/lib/service.py +++ b/packages/omamobile-modem-sit/lib/service.py @@ -48,6 +48,7 @@ from inbox import persist_sms from sit import Sit, ModemError from sms_codec import submit, received_pdu, number +import carrier_manifest from voice_audio import VoiceAudio, aoc_card STATES = {0: 'active', 1: 'held', 2: 'dialing', 3: 'ringing-out', 4: 'ringing-in', 5: 'waiting', @@ -57,8 +58,29 @@ SOCKET = paths.RUN / 'socket' # GET_RADIO_POWER / IND_RADIO_STATE_CHANGED (MODEM-SIT-RESEARCH 3.1): # INITIALIZED and STOP_NETWORK are off, START_NETWORK on, POWER_OFF is the -# state without a SIM (M4.1i), RESET is unavailable. -RADIO = {0: 'off', 1: 'off', 2: 'on', 3: 'off', 4: 'unavailable'} +# state without a SIM (M4.1i), RESET is unavailable. GET_RADIO_POWER answers +# 10 with the radio on (cheetah and tegu, 2026-11-02): Android's RadioState +# ON (OFF 0, UNAVAILABLE 1, ON 10). +RADIO = {0: 'off', 1: 'off', 2: 'on', 3: 'off', 4: 'unavailable', 10: 'on'} + + +def lte_rsrp(payload): + """LTE RSRP in dBm from a GET_SIGNAL_STRENGTH or IND_SIGNAL_STRENGTH + payload, or None. Stock's SignalStrengthParserV4: a u16 RAT mask (bit 2 + LTE), then a 196-byte block whose LTE part starts at +0x3c (signal + strength, RSRP, RSRQ, RSSNR as u32); RSRP is positive (110 is -110 dBm), + valid 44-140, INT_MAX when unknown.""" + if len(payload) < 2 + 0xc4 or not struct.unpack_from('= 4: @@ -387,7 +498,8 @@ def status(self, *, public=False): registration=self.net['reg'], tech=self.net['rat'], operator=self.net['operator'] or self.net['plmn'], plmn=self.net['plmn'], operator_name=self.net['operator'], - voice=voice, sms=sms, data=data, signal=0, audio=True, + voice=voice, sms=sms, data=data, + signal=self.signal if self.net['reg'] in ('home', 'roaming') else 0, audio=True, radio=self.radio, sim=dict(self.sim), ims='registered' if voice or sms else self.ims_state, emergency_numbers=list(EMERGENCY + (EMERGENCY_NO_SIM if self.sim['state'] == 'absent' else ()))) @@ -703,7 +815,8 @@ def main(): raise SystemExit('CP is not ONLINE: start omamobile-modem.service first') if args.probe: return probe() - client = Sit(allow_sms=True, allow_calls=True) + client = Sit(allow_sms=True, allow_calls=True, + allow_manifest=bool(settings['network'].get('carrier_manifest', '').strip())) server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) service = None stopping = False diff --git a/packages/omamobile-modem-sit/lib/sit.py b/packages/omamobile-modem-sit/lib/sit.py index 0f3a38abb..2ec62b73f 100644 --- a/packages/omamobile-modem-sit/lib/sit.py +++ b/packages/omamobile-modem-sit/lib/sit.py @@ -16,7 +16,7 @@ import struct import time -from paths import IPC, RUN, open_channel, private_dir +from paths import IPC, RUN, open_channel, run_dir from sit_names import NAMES # Data/radio/IMS lifecycle, display state, read-only status, and incoming SMS @@ -55,7 +55,15 @@ def __init__(self, error, payload): self.payload = payload # private; never include payload in str/repr -def check(ident, *, sms=False, calls=False): +# OEM_SET_CARRIER_CONFIG_MANIFEST stays on the do-not-send list; the one +# exception is the reply to the modem's own request, sent by an owner opened +# with a manifest configured (carrier_manifest.py). +MANIFEST = 0x4600 + + +def check(ident, *, sms=False, calls=False, manifest=False): + if manifest and ident == MANIFEST: + return if ident in DENIED or (ident >> 8) in DENIED_FAMILIES: raise ValueError('request on the do-not-send list') if not (ident in ALLOWED or (sms and ident in SMS) or (calls and ident in CALLS)): @@ -63,10 +71,11 @@ def check(ident, *, sms=False, calls=False): class Sit: - def __init__(self, *, allow_sms=False, allow_calls=False, device=None): + def __init__(self, *, allow_sms=False, allow_calls=False, allow_manifest=False, device=None): self.allow_sms = allow_sms self.allow_calls = allow_calls - private_dir(RUN) + self.allow_manifest = allow_manifest + run_dir() self.lock = os.open(RUN / 'ipc0.lock', os.O_CREAT | os.O_RDWR | os.O_CLOEXEC, 0o600) try: fcntl.flock(self.lock, fcntl.LOCK_EX | fcntl.LOCK_NB) @@ -109,9 +118,10 @@ def read_packet(self, timeout): if len(self.buffer) > 65536: raise RuntimeError('SIT receive limit exceeded') - def request(self, ident, payload=b'', timeout=8): + def request(self, ident, payload=b'', timeout=8, *, manifest_reply=False): check(ident, sms=getattr(self, 'allow_sms', False), - calls=getattr(self, 'allow_calls', False)) + calls=getattr(self, 'allow_calls', False), + manifest=manifest_reply and getattr(self, 'allow_manifest', False)) self.token = (self.token + 1) & 0xffffffff data = struct.pack('&2; fi +done for b in "${SYSTEM_BINS[@]}" "${SYSTEM_FILES[@]}"; do put "$WORK/s/$b" "$b"; done for d in "${SYSTEM_DIRS[@]}"; do mkdir -p "$root/$d"; cp -a "$WORK/s/$d/." "$root/$d/"; done for f in "${RUNTIME_FILES[@]}"; do put "$WORK/r/$f" "apex/com.android.runtime/$f"; done From 88515f92a207dabf0defb53f189f2c62114c22f4 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Mon, 2 Nov 2026 23:39:13 -0500 Subject: [PATCH 09/10] omamobile-modem-sit 0.3.19: the carrier profile before radio on, the ISIM's P-CSCF, IMS failure logging Tested on the reference Pixel 7 Pro on 2026-11-02 (Verizon-network SIM). - With carrier_manifest set, the radio goes on only after the modem's carrier config status (0x4601), as stock orders it. Before, the status came 11 s after radio on and the modem stopped searching; now it registers in 3.3 s with the profile in place. - [network] ims_pcscf_from_isim (default yes): when the IMS bearer's PCO has no P-CSCF, read the ISIM's EF_PCSCF (6F09) through SIM_IO. The transport allows SIM_IO only for GET RESPONSE / READ RECORD of that one file on the ISIM AID; nothing else of the ISIM is read or logged. FQDN entries are resolved over the IMS bearer, then the host resolver; IPv6 results fill ADD_PDN's list. On this network the entry is an FQDN that resolves only on the carrier's IMS DNS, which the host can't reach (the modem owns that bearer), so IMS still doesn't register. - omamobile-sitd.service also allows AF_INET/AF_INET6, for that lookup. - IND_AIMS_REGISTRATION is logged (state, features, status, the stack's reason text; never the URI). - NR mode is set right after radio on when the modem refuses it with the radio off (error 2). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BeEcdVeSfyLCbijF8XQF1d --- device/cheetah/MODEM-SIT-RESEARCH.md | 2 +- .../etc/omamobile/modem-sit.conf | 5 + packages/omamobile-modem-sit/lib/bringup.py | 28 +- packages/omamobile-modem-sit/lib/ims.py | 28 +- packages/omamobile-modem-sit/lib/isim.py | 335 ++++++++++++++++++ packages/omamobile-modem-sit/lib/paths.py | 1 + packages/omamobile-modem-sit/lib/service.py | 3 +- packages/omamobile-modem-sit/lib/sit.py | 23 +- .../systemd/omamobile-sitd.service | 2 +- .../omamobile-modem-sit/test/test_bringup.py | 27 ++ .../test/test_carrier_manifest.py | 7 +- .../omamobile-modem-sit/test/test_isim.py | 235 ++++++++++++ packages/omamobile-modem-sit/version | 2 +- 13 files changed, 681 insertions(+), 17 deletions(-) create mode 100644 packages/omamobile-modem-sit/lib/isim.py create mode 100644 packages/omamobile-modem-sit/test/test_isim.py diff --git a/device/cheetah/MODEM-SIT-RESEARCH.md b/device/cheetah/MODEM-SIT-RESEARCH.md index a4427e09e..637e41016 100644 --- a/device/cheetah/MODEM-SIT-RESEARCH.md +++ b/device/cheetah/MODEM-SIT-RESEARCH.md @@ -207,7 +207,7 @@ START_NETWORK, 1 for STOP_NETWORK. | 0x0202 / 0x0204 | VERIFY_SIM_PUK / PUK2 | not read; same family as above | low | names | | 0x0210 | IND_SIM_STATUS_CHANGED | re-read GET_SIM_STATUS | medium | name | | 0x0400 | GET_IMSI | request len 29: 0x0c u8 AID length, 0x0d AID (16 bytes). Response: 0x0c u8 IMSI length (at most 15), 0x0d IMSI as ASCII digits | high | `ProtocolSimBuilder::BuildGetImsi`, `ProtocolSimImsiAdapter::Init` | -| 0x0208 | SIM_IO | ICCID is read the Android way, through SIM_IO on EF_ICCID (2FE2); layout not read yet | low | name; `SimIoService` in libsitril | +| 0x0208 | SIM_IO | request len 572: 0x0c u8 command (B0/B2/C0/D6/DC/F2), 0x0d u8 application type (RIL_AppType, from the AID's entry in the SIM status; ISIM 5), 0x0e u16 file ID (LE), 0x10 u8 path length in bytes, 0x11 path (12 bytes, each 16-bit ID little-endian: 3F007FFF is 00 3F FF 7F), 0x1d P1, 0x1e P2, 0x1f P3, 0x20 u16 data length, 0x22 data (512), 0x222 u8 PIN2 length, 0x223 PIN2 (8), 0x22b u8 AID length, 0x22c AID (16). Response: 0x0c SW1, 0x0d SW2, 0x0e s16 response length (at most 512), 0x10 response. omamobile-modem-sit 0.3.18 sends only GET RESPONSE and READ RECORD on the ISIM's EF_PCSCF (6F09), checked in `sit.check` | high (offsets), medium (application type values, the GET RESPONSE format the CP returns) | `ProtocolSimBuilder::BuildSimIO`, `ProtocolSimIOAdapter::GetSw1/GetSw2/GetResponseLength/GetResponse`, `SimIoService::DoSimIo` | | 0x0401 / 0x0402 | GET_IMEI / GET_IMEISV | bare header (len 12) | high | `ProtocolDeviceInfoBuilder::GetIMEI/GetIMEISV` | | 0x0250 | SET_LOGICAL_TO_PHYSICAL_SLOT_MAPPING | len 17: 0x0c u8 count, 0x0d.. one u8 physical slot per logical slot (4 bytes) | high (layout), medium (meaning) | `ProtocolRadioConfigBuilder::BuildSimSetLogicalSlotMapping` | diff --git a/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf b/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf index 69ea88bd3..b4996d613 100644 --- a/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf +++ b/packages/omamobile-modem-sit/etc/omamobile/modem-sit.conf @@ -28,6 +28,11 @@ ims_timeout = 120 # without one when the bearer carries none, leaving it to the modem's IMS # stack (some networks keep it on the ISIM, not in the bearer). ims_pcscf_required = yes +# When the IMS bearer carries no P-CSCF, read it from the ISIM's EF_PCSCF +# (one read-only file; nothing else on the ISIM is read), as stock does. +# A name there is resolved to IPv6 over the IMS bearer, else through the +# host's resolver. +ims_pcscf_from_isim = yes # The modem's carrier profile: the 40-character cfg.db manifest ID for this # SIM's carrier (a file name under the modem chroot's # /vendor/firmware/carrierconfig/manifests). Set, it answers the modem's diff --git a/packages/omamobile-modem-sit/lib/bringup.py b/packages/omamobile-modem-sit/lib/bringup.py index bad3698f4..bad44abf5 100644 --- a/packages/omamobile-modem-sit/lib/bringup.py +++ b/packages/omamobile-modem-sit/lib/bringup.py @@ -15,8 +15,10 @@ (AT+CFUN=0 first). Then wait for packet registration (on LTE with nr = off) and log how long it took; 4. the internet bearer (CID 1; its rmnet device is found by omamobile-sit-data); - 5. IMS: stack start, the IMS bearer (CID 2, IPv6), ADD_PDN_INFO, then wait - for an IMS registration with voice and SMS. + 5. IMS: stack start, the IMS bearer (CID 2, IPv6), ADD_PDN_INFO (its + P-CSCF from the bearer's PCO, else from the ISIM's EF_PCSCF with + [network] ims_pcscf_from_isim = yes), then wait for an IMS + registration with voice and SMS. No retransmission of SMS/calls and no warm CP restart. A failed or uncertain step up to the internet bearer ends start-up; the service exits and the @@ -28,6 +30,7 @@ from at import radio, radio_state from data_call import activate, configured_profiles, initial_attach, provision_profiles from ims import register, start_stack +from isim import ipv6_pcscf from radio_settings import SAVED_NR, nr_mode from sit import ModemError @@ -198,6 +201,19 @@ def usim_ready(): nr_after_radio = True print(f'NR mode refused with the radio off ({error}); setting it after radio on', flush=True) service.pump() + if not already_on and net.get('carrier_manifest', '').strip(): + # Stock applies the carrier profile before the radio comes on; with + # the radio switched on first (2026-11-02) the modem confirmed the + # profile 11 s later and then stopped searching. Wait for its status + # here, so registration starts with the profile in place. + limit = net.getint('carrier_manifest_timeout', 60) + try: + wait_for(service, lambda: service.carrier_status is not None, limit, stopped) + print('Radio on after carrier config: status', service.carrier_status[0], + 'cause', service.carrier_status[1], flush=True) + except TimeoutError: + print('Radio on without carrier config status after', limit, 's;', + 'manifest sent' if service.manifest_sent else 'no request from the modem seen', flush=True) if not already_on: radio(True) began = time.monotonic() @@ -244,7 +260,13 @@ def registered(): flush=True) start_stack(client) activate(client, net.get('ims_apn', 'ims'), ims=True, on_event=service.event) - register(client, pcscf_required=net.getboolean('ims_pcscf_required', True)) + fallback = None + if net.getboolean('ims_pcscf_from_isim', True): + # The ISIM's EF_PCSCF when the PCO has none (one read-only file). + def fallback(bearer): + return ipv6_pcscf(client, client.request(0x0200), bearer) + register(client, pcscf_required=net.getboolean('ims_pcscf_required', True), + pcscf_fallback=fallback) print('Startup: waiting for IMS voice and SMS registration', flush=True) wait_for(service, lambda: service.registration().get('state') == 2 and service.registration().get('features', 0) & 3 == 3, diff --git a/packages/omamobile-modem-sit/lib/ims.py b/packages/omamobile-modem-sit/lib/ims.py index 2029c0127..2545e84b2 100644 --- a/packages/omamobile-modem-sit/lib/ims.py +++ b/packages/omamobile-modem-sit/lib/ims.py @@ -6,6 +6,7 @@ modem's own IMS stack registers. This announces ordinary voice/SMS capability; it does not originate a call. """ +import re import json import struct import time @@ -22,6 +23,12 @@ def record_registration(packet): state, features, mask, status, uri_len, reason_len = struct.unpack_from(' 1000 or reason_len > 256 or len(packet) < 20 + uri_len + reason_len: raise ValueError('truncated IMS registration indication') + # The reason is the IMS stack's own words (a SIP or stack failure); the + # URI before it is the subscriber's identity and is never logged. + reason = packet[20 + uri_len:20 + uri_len + reason_len].decode('ascii', 'replace').strip('\0 ') + reason = re.sub(r'\d{7,}', '', re.sub(r'(sip|tel):\S+', '', reason)) + print(f'IMS registration indication: state {state}, features {features}, status {status}' + + (f', reason "{reason}"' if reason else ''), flush=True) if REGISTRATION.exists(): private_write(REGISTRATION, json.dumps({'state': state, 'features': features, 'feature_mask': mask, 'status': status}).encode()) @@ -45,7 +52,7 @@ def hidden_menu(): return struct.pack(' IPv6 P-CSCF addresses, called only + when the bearer's PCO has none (isim.ipv6_pcscf).""" state_path, response_path = paths(2) owned = json.loads(state_path.read_text()) if owned.get('cid') != 2 or not 0 <= owned.get('session', -1) <= 15: raise RuntimeError('IMS bearer ownership missing') if 2 not in call_ids(client.request(0x0602)): raise RuntimeError('IMS bearer no longer listed') - body = add_pdn_payload(response_path.read_bytes(), pcscf_required=pcscf_required) + response = response_path.read_bytes() + fallback = () + if pcscf_fallback is not None and len(response) >= 132 and not pcscf_addresses(response)[1]: + print('IMS bearer PCO carries no IPv6 P-CSCF; reading the ISIM\'s EF_PCSCF', flush=True) + try: + fallback = pcscf_fallback(response) + except (RuntimeError, TimeoutError, ValueError) as error: + # ModemError is a RuntimeError: a card that refuses the read. + print('P-CSCF from ISIM unavailable:', type(error).__name__, error, flush=True) + body = add_pdn_payload(response, pcscf_required=pcscf_required, fallback=fallback) if REGISTRATION.exists(): raise RuntimeError('IMS registration already attempted; inspect before retry') client.request(0x0d07, hidden_menu(), timeout=30) diff --git a/packages/omamobile-modem-sit/lib/isim.py b/packages/omamobile-modem-sit/lib/isim.py new file mode 100644 index 000000000..ce09c8076 --- /dev/null +++ b/packages/omamobile-modem-sit/lib/isim.py @@ -0,0 +1,335 @@ +# SPDX-License-Identifier: MIT +"""The IMS P-CSCF from the ISIM's EF_PCSCF (3GPP TS 31.103 4.2.8), for +networks whose IMS bearer carries none in its PCO: stock's IMS service does +the same (addPcscfFromSim, getIsimPcscf). + +Read-only and limited to that one file: SIM_IO GET RESPONSE (for the record +size) and READ RECORD on EF_PCSCF (6F09) under the ISIM's ADF (path +3F007FFF). sit.check refuses every other SIM_IO request, at the transport. +No other ISIM file is read (never IMPI, IMPU or the domain), and the AID is +never logged. + +SIM_IO request (stock ProtocolSimBuilder::BuildSimIO, 560 bytes after the +12-byte header): +0 u8 command, +1 u8 application type (RIL_AppType; ISIM +5), +2 u16 file ID (little-endian), +4 u8 path length in bytes, +5 path (12 +bytes; each 16-bit file ID stored little-endian, so 3F00 7FFF is 00 3F FF +7F), +17 P1, +18 P2, +19 P3, +20 u16 data length, +22 data (512), +534 u8 +PIN2 length, +535 PIN2 (8), +543 u8 AID length, +544 AID (16). Response +(ProtocolSimIOAdapter): +0 SW1, +1 SW2, +2 s16 response length (at most +512), +4 response. +""" +import ipaddress +import os +import re +import socket +import struct +import threading + +SIM_IO = 0x0208 +READ_RECORD, GET_RESPONSE = 0xB2, 0xC0 +APP_ISIM = 5 +EF_PCSCF = 0x6F09 +PATH = bytes([0x00, 0x3F, 0xFF, 0x7F]) # 3F00 7FFF, as BuildSimIO stores it +# 3GPP's RID and the ISIM application code (TS 31.103 annex, ETSI TS 101 220). +ISIM_AID_PREFIX = bytes.fromhex('A0000000871004') +REQUEST_LENGTH = 560 +MAX_RECORDS = 8 +FQDN = re.compile(r'(?=.{1,253}$)([A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)*' + r'[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.?') + + +def request(command, aid, p1, p2, p3): + """A SIM_IO request on EF_PCSCF; check_request decides whether it may go.""" + if not 1 <= len(aid) <= 16: + raise ValueError('ISIM AID length') + body = bytearray(REQUEST_LENGTH) + body[0], body[1] = command, APP_ISIM + struct.pack_into(' 8 or len(status) < 3 + status[2] * 63: + raise ValueError('Unexpected SIM status layout') + for i in range(3, 3 + status[2] * 63, 63): + app = status[i:i + 63] + if app[0] == APP_ISIM and app[1] == 5 and 1 <= app[3] <= 16: + aid = bytes(app[4:4 + app[3]]) + if aid.startswith(ISIM_AID_PREFIX): + return aid + return None + + +def response(payload): + """(SW1, SW2, data) of a SIM_IO response.""" + if len(payload) < 4: + raise ValueError('short SIM_IO response') + length = struct.unpack_from(' len(data): + raise ValueError('truncated TLV') + tag, length = data[offset], data[offset + 1] + start = offset + 2 + if length == 0x81: + if start >= len(data): + raise ValueError('truncated TLV') + length, start = data[start], start + 1 + elif length > 0x7f: + raise ValueError('unsupported TLV length') + if start + length > len(data): + raise ValueError('truncated TLV') + return tag, data[start:start + length], start + length + + +def record_layout(data): + """(record length, record count) from a GET RESPONSE: a UICC FCP template + (tag 62, file descriptor 82: descriptor, coding, u16 record length, count) + or the 2G-style 15-byte answer Android's IccFileHandler reads (file size + at 2, record length at 14).""" + if data[:1] == b'\x62': + _, fcp, _ = tlv(data, 0) + offset = 0 + while offset < len(fcp): + tag, value, offset = tlv(fcp, offset) + if tag == 0x82 and len(value) >= 5: + size, count = struct.unpack_from('>H', value, 2)[0], value[4] + if 1 <= size <= 255 and count: + return size, count + break + raise ValueError('EF_PCSCF is not a linear fixed file') + if len(data) >= 15 and data[14]: + size = struct.unpack_from('>H', data, 2)[0] + if size >= data[14]: + return data[14], size // data[14] + raise ValueError('unexpected GET RESPONSE layout') + + +def parse_record(record): + """One EF_PCSCF record: tag 80, length, address type (00 FQDN, 01 IPv4, + 02 IPv6), address. Returns ('fqdn', str), ('ipv4', bytes4), ('ipv6', + bytes16) or None for an empty (FF-filled) or unusable record. IPv4/IPv6 + are taken binary, or as a text literal (cards differ).""" + record = bytes(record) + if not record or record[0] == 0xFF or not record.strip(b'\xff'): + return None + try: + tag, value, _ = tlv(record, 0) + except ValueError: + return None + if tag != 0x80 or len(value) < 2: + return None + kind, address = value[0], value[1:] + text = address.rstrip(b'\x00\xff').decode('ascii', 'replace') + try: + if kind == 0x01: + return 'ipv4', (address if len(address) == 4 else ipaddress.IPv4Address(text).packed) + if kind == 0x02: + return 'ipv6', (address if len(address) == 16 else ipaddress.IPv6Address(text).packed) + except ValueError: + return None + if kind == 0x00 and FQDN.fullmatch(text): + return 'fqdn', text.rstrip('.').lower() + return None + + +def read_pcscf(client, aid): + """The EF_PCSCF entries, in record order, deduplicated.""" + sw1, sw2, data = response(client.request(SIM_IO, request(GET_RESPONSE, aid, 0, 0, 15), timeout=10)) + if not ok(sw1): + raise RuntimeError(f'EF_PCSCF GET RESPONSE status {sw1:02X}{sw2:02X}') + size, count = record_layout(data) + entries = [] + for number in range(1, min(count, MAX_RECORDS) + 1): + sw1, sw2, record = response(client.request( + SIM_IO, request(READ_RECORD, aid, number, 4, size), timeout=10)) + if not ok(sw1): + break + entry = parse_record(record) + if entry and entry not in entries: + entries.append(entry) + return entries + + +def dns_query(name, qtype=28): + ident = int.from_bytes(os.urandom(2), 'big') + labels = b''.join(bytes([len(l)]) + l.encode('ascii') for l in name.split('.') if l) + return ident, struct.pack('>HHHHHH', ident, 0x0100, 1, 0, 0, 0) + labels + b'\0' \ + + struct.pack('>HH', qtype, 1) + + +def skip_name(data, offset): + while True: + if offset >= len(data): + raise ValueError('truncated DNS name') + length = data[offset] + if length & 0xc0 == 0xc0: + return offset + 2 + if length == 0: + return offset + 1 + offset += 1 + length + + +def dns_answers(data, ident, qtype=28): + """The addresses of type qtype in a DNS reply (CNAMEs are followed by the + server in the same answer section).""" + if len(data) < 12: + raise ValueError('short DNS reply') + rid, flags, qd, an = struct.unpack_from('>HHHH', data) + if rid != ident or not flags & 0x8000 or flags & 0xf: + return [] + offset = 12 + for _ in range(qd): + offset = skip_name(data, offset) + 4 + found = [] + for _ in range(an): + offset = skip_name(data, offset) + if offset + 10 > len(data): + break + rtype, _, _, length = struct.unpack_from('>HHIH', data, offset) + offset += 10 + value = data[offset:offset + length] + offset += length + if rtype == qtype and len(value) == (16 if qtype == 28 else 4): + found.append(bytes(value)) + return found + + +def resolve_on_bearer(name, source, servers, timeout=3): + """AAAA over the IMS bearer: UDP from the bearer's own address to its DNS + servers. Fails where the host has no such address (the modem's IMS stack + owns the bearer).""" + for server in servers: + try: + sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + except OSError: + return [] + with sock: + sock.settimeout(timeout) + try: + sock.bind((source, 0)) + ident, query = dns_query(name) + sock.sendto(query, (server, 53)) + data, _ = sock.recvfrom(4096) + except OSError: + continue + found = dns_answers(data, ident) + if found: + return found + return [] + + +def resolve_system(name, timeout=5): + """AAAA through the host's resolver (the internet bearer or Wi-Fi), with a + deadline: getaddrinfo has none of its own.""" + result = [] + + def lookup(): + try: + for info in socket.getaddrinfo(name, None, socket.AF_INET6, socket.SOCK_DGRAM): + result.append(ipaddress.IPv6Address(info[4][0].split('%')[0]).packed) + except (OSError, ValueError): + pass + worker = threading.Thread(target=lookup, daemon=True) + worker.start() + worker.join(timeout) + return list(dict.fromkeys(result)) if not worker.is_alive() else [] + + +def bearer_dns(bearer): + """The IMS bearer's own IPv6 address and IPv6 DNS servers (setup response: + address at 9, DNS at 0x1e and 0x32), as text.""" + source = str(ipaddress.IPv6Address(bytes(bearer[9:25]))) + servers = [str(ipaddress.IPv6Address(bytes(bearer[i:i + 16]))) + for i in (0x1e, 0x32) if any(bearer[i:i + 16])] + return source, list(dict.fromkeys(servers)) + + +def ipv6_pcscf(client, status, bearer, *, resolve_bearer=resolve_on_bearer, + resolve_host=resolve_system): + """IPv6 P-CSCF addresses from the ISIM, for ADD_PDN (its list is IPv6, as + the IMS bearer). FQDNs are resolved (AAAA) over the IMS bearer first, then + through the host's resolver. Returns [] when there is no ready ISIM or + nothing usable; logs counts and the FQDNs (carrier server names), never + the AID or any other ISIM content.""" + aid = isim_aid(status) + if aid is None: + print('P-CSCF from ISIM: no ready ISIM application', flush=True) + return [] + entries = read_pcscf(client, aid) + kinds = [kind for kind, _ in entries] + print(f'P-CSCF from ISIM: {len(entries)} addresses (' + + ', '.join(f'{kinds.count(k)} {label}' for k, label in + (('fqdn', 'FQDN'), ('ipv4', 'IPv4'), ('ipv6', 'IPv6')) if k in kinds) + + ')', flush=True) + addresses = [value for kind, value in entries if kind == 'ipv6'] + if 'ipv4' in kinds: + print('P-CSCF from ISIM: IPv4 entries not used (the IMS bearer and ADD_PDN list are IPv6)', + flush=True) + names = [value for kind, value in entries if kind == 'fqdn'] + if names: + source, servers = bearer_dns(bearer) + for name in names: + print(f'P-CSCF from ISIM: FQDN {name}', flush=True) + try: + found = resolve_bearer(name, source, servers) if servers else [] + except (OSError, ValueError): + found = [] + how = 'over the IMS bearer' + if not found: + found = resolve_host(name) + how = 'through the host resolver' + if found: + print(f'P-CSCF from ISIM: {name} resolved {how}: {len(found)} IPv6', flush=True) + else: + print(f'P-CSCF from ISIM: {name} did not resolve to IPv6', flush=True) + addresses += found + return list(dict.fromkeys(a for a in addresses if any(a))) diff --git a/packages/omamobile-modem-sit/lib/paths.py b/packages/omamobile-modem-sit/lib/paths.py index 7ee5bfb4c..63d1421ad 100644 --- a/packages/omamobile-modem-sit/lib/paths.py +++ b/packages/omamobile-modem-sit/lib/paths.py @@ -29,6 +29,7 @@ DEFAULTS = { 'network': {'apn': '', 'attach_apn': '', 'ip_type': 'ipv4v6', 'ims': 'yes', 'ims_apn': 'ims', 'ims_required': 'no', 'ims_pcscf_required': 'yes', + 'ims_pcscf_from_isim': 'yes', 'carrier_manifest': '', 'carrier_manifest_timeout': '60', 'ims_timeout': '120', 'nr': 'off', 'sim_timeout': '120', 'register_timeout': '180'}, # Extra modem-managed data profiles, one per line (data_call.parse_profile). diff --git a/packages/omamobile-modem-sit/lib/service.py b/packages/omamobile-modem-sit/lib/service.py index f62572428..8b6372bb1 100644 --- a/packages/omamobile-modem-sit/lib/service.py +++ b/packages/omamobile-modem-sit/lib/service.py @@ -816,7 +816,8 @@ def main(): if args.probe: return probe() client = Sit(allow_sms=True, allow_calls=True, - allow_manifest=bool(settings['network'].get('carrier_manifest', '').strip())) + allow_manifest=bool(settings['network'].get('carrier_manifest', '').strip()), + allow_isim_pcscf=settings['network'].getboolean('ims_pcscf_from_isim', True)) server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) service = None stopping = False diff --git a/packages/omamobile-modem-sit/lib/sit.py b/packages/omamobile-modem-sit/lib/sit.py index 2ec62b73f..371764c10 100644 --- a/packages/omamobile-modem-sit/lib/sit.py +++ b/packages/omamobile-modem-sit/lib/sit.py @@ -7,7 +7,8 @@ the do-not-send list of device/cheetah/MODEM-SIT-RESEARCH.md section 5 (NV, identity, carrier lock, AT forwarding, VSIM and satellite), so an edit to the allow-list can't let one of those through. Dial and outgoing SMS are -refused unless the owner was opened for them. +refused unless the owner was opened for them. SIM_IO is refused too, +except the read-only ISIM EF_PCSCF read of isim.py, checked byte by byte. """ from collections import deque import fcntl @@ -16,11 +17,12 @@ import struct import time +from isim import SIM_IO, check_request as check_sim_io from paths import IPC, RUN, open_channel, run_dir from sit_names import NAMES # Data/radio/IMS lifecycle, display state, read-only status, and incoming SMS -# ACK. No SIM I/O, PIN, subscription, APDU or vendor NV requests. +# ACK. No SIM I/O (but the one ISIM file below), PIN, subscription, APDU or vendor NV requests. ALLOWED = {0x0000, 0x0102, 0x0108, 0x0200, 0x0600, 0x0601, 0x0602, 0x0603, 0x0613, 0x061a, 0x061b, 0x0625, 0x0700, 0x0701, 0x0702, 0x0703, 0x0704, 0x070a, 0x070b, 0x0710, 0x0711, 0x0800, 0x0801, 0x0748, 0x0749, 0x0750, 0x0902, @@ -61,9 +63,17 @@ def __init__(self, error, payload): MANIFEST = 0x4600 -def check(ident, *, sms=False, calls=False, manifest=False): +def check(ident, *, sms=False, calls=False, manifest=False, isim_pcscf=False, payload=b''): if manifest and ident == MANIFEST: return + # SIM_IO (0x0208) is outside the allow-list; the one exception, for an + # owner opened for it, is GET RESPONSE / READ RECORD on the ISIM's + # EF_PCSCF (isim.check_request raises for anything else). + if ident == SIM_IO: + if not isim_pcscf: + raise ValueError('request outside the allow-list') + check_sim_io(payload) + return if ident in DENIED or (ident >> 8) in DENIED_FAMILIES: raise ValueError('request on the do-not-send list') if not (ident in ALLOWED or (sms and ident in SMS) or (calls and ident in CALLS)): @@ -71,10 +81,12 @@ def check(ident, *, sms=False, calls=False, manifest=False): class Sit: - def __init__(self, *, allow_sms=False, allow_calls=False, allow_manifest=False, device=None): + def __init__(self, *, allow_sms=False, allow_calls=False, allow_manifest=False, + allow_isim_pcscf=False, device=None): self.allow_sms = allow_sms self.allow_calls = allow_calls self.allow_manifest = allow_manifest + self.allow_isim_pcscf = allow_isim_pcscf run_dir() self.lock = os.open(RUN / 'ipc0.lock', os.O_CREAT | os.O_RDWR | os.O_CLOEXEC, 0o600) try: @@ -121,7 +133,8 @@ def read_packet(self, timeout): def request(self, ident, payload=b'', timeout=8, *, manifest_reply=False): check(ident, sms=getattr(self, 'allow_sms', False), calls=getattr(self, 'allow_calls', False), - manifest=manifest_reply and getattr(self, 'allow_manifest', False)) + manifest=manifest_reply and getattr(self, 'allow_manifest', False), + isim_pcscf=getattr(self, 'allow_isim_pcscf', False), payload=payload) self.token = (self.token + 1) & 0xffffffff data = struct.pack('H', size) + bytes([len(self.records)]) + return sim_io_reply(bytes([0x62, len(fcp)]) + fcp) + two_g = bytearray(15) + struct.pack_into('>H', two_g, 2, size * len(self.records)) + two_g[14] = size + return sim_io_reply(bytes(two_g)) + if p1 > len(self.records): + return sim_io_reply(b'', 0x6a, 0x83) + return sim_io_reply(self.records[p1 - 1][:p3]) + + +class GuardTests(unittest.TestCase): + def test_the_two_reads_pass(self): + isim.check_request(isim.request(isim.GET_RESPONSE, AID, 0, 0, 15)) + isim.check_request(isim.request(isim.READ_RECORD, AID, 1, 4, 40)) + sit.check(0x0208, isim_pcscf=True, payload=isim.request(isim.READ_RECORD, AID, 2, 4, 40)) + + def test_sim_io_needs_the_owner_flag(self): + with self.assertRaises(ValueError): + sit.check(0x0208, payload=isim.request(isim.READ_RECORD, AID, 1, 4, 40)) + + def refused(self, payload): + with self.assertRaises(ValueError): + sit.check(0x0208, isim_pcscf=True, payload=bytes(payload)) + + def test_everything_else_is_refused(self): + good = bytearray(isim.request(isim.READ_RECORD, AID, 1, 4, 40)) + for command in (0xB0, 0xD6, 0xDC, 0xF2, 0xA4, 0x88): # binary, updates, status... + bad = bytearray(good) + bad[0] = command + self.refused(bad) + for offset, value in ((1, 2), (2, 0x02), (3, 0x2F), (4, 2), (9, 1), (18, 2), (17, 0)): + bad = bytearray(good) + bad[offset] = value + self.refused(bad) + # Other ISIM files: IMPI 6F02, IMPU 6F04, domain 6F03. + for fid in (0x6F02, 0x6F03, 0x6F04, 0x2FE2): + bad = bytearray(good) + struct.pack_into('H', two_g, 2, 120) + two_g[14] = 40 + self.assertEqual(isim.record_layout(bytes(two_g)), (40, 3)) + + +class ReadTests(unittest.TestCase): + def test_reads_only_ef_pcscf_and_resolves_names(self): + for fcp in (True, False): + card = FakeCard([record(0, b'pcscf.ims.example.net'), record(2, V6), + record(1, bytes([192, 0, 2, 7])), b'\xff' * 40], fcp=fcp) + asked = [] + + def on_bearer(name, source, servers): + asked.append((name, source, servers)) + return [V6B] + with patch('builtins.print') as out: + found = isim.ipv6_pcscf(card, card.request(0x0200), bearer(), resolve_bearer=on_bearer, + resolve_host=lambda name: self.fail('host resolver used')) + self.assertEqual(found, [V6, V6B]) + self.assertEqual(asked, [('pcscf.ims.example.net', '2001:db8::2', ['2001:db8::53'])]) + lines = [' '.join(map(str, c.args)) for c in out.call_args_list] + self.assertIn('P-CSCF from ISIM: 3 addresses (1 FQDN, 1 IPv4, 1 IPv6)', lines) + self.assertFalse(any(AID.hex() in l.lower() for l in lines)) + sim_io = [p for i, p in card.sent if i == 0x0208] + self.assertEqual([p[0] for p in sim_io], [0xC0, 0xB2, 0xB2, 0xB2, 0xB2]) + self.assertEqual({struct.unpack_from('HHIH', 28, 1, 60, 16) + V6 + reply = struct.pack('>HHHHHH', ident, 0x8180, 1, 1, 0, 0) + query[12:] + answer + self.assertEqual(isim.dns_answers(reply, ident), [V6]) + self.assertEqual(isim.dns_answers(reply, ident ^ 1), []) + + +class AddPdnTests(unittest.TestCase): + def test_add_pdn_filled_from_the_isim_only_when_the_pco_has_none(self): + body = ims.add_pdn_payload(bearer(), fallback=[V6, V6B, V6, b'\0' * 16]) + self.assertEqual(body[39:41], bytes([0, 2])) + self.assertEqual(body[41:73], V6 + V6B) + with_pco = bytearray(bearer()) + with_pco[0x42] = 2 + with_pco[0x4f:0x5f] = ipaddress.IPv6Address('2001:db8::1').packed + body = ims.add_pdn_payload(bytes(with_pco), fallback=[V6]) + self.assertEqual(body[39:57], bytes([0, 1]) + ipaddress.IPv6Address('2001:db8::1').packed) + with self.assertRaises(ValueError): + ims.add_pdn_payload(bearer(), fallback=[]) + + def test_register_calls_the_fallback_on_an_empty_pco(self): + with tempfile.TemporaryDirectory() as tmp: + tmp = Path(tmp) + state, response = tmp / 'ims-session.json', tmp / 'ims-response.bin' + state.write_text(json.dumps({'cid': 2, 'session': 0})) + response.write_bytes(bearer()) + + class Client: + bodies = [] + + def request(self, ident, payload=b'', timeout=8): + if ident == 0x0602: + item = bytearray(132) + item[2] = 2 + return bytes([1]) + bytes(item) + self.bodies.append((ident, payload)) + return b'' + client = Client() + seen = [] + with patch.object(ims, 'paths', return_value=(state, response)), \ + patch.object(ims, 'REGISTRATION', tmp / 'reg.json'), patch('builtins.print'): + ims.register(client, pcscf_fallback=lambda b: seen.append(b) or [V6]) + self.assertEqual(seen, [bearer()]) + add_pdn = [p for i, p in client.bodies if i == 0x0d08][0] + self.assertEqual(add_pdn[39:57], bytes([0, 1]) + V6) + + +if __name__ == '__main__': + unittest.main() diff --git a/packages/omamobile-modem-sit/version b/packages/omamobile-modem-sit/version index ec96a6218..9ec8136c2 100644 --- a/packages/omamobile-modem-sit/version +++ b/packages/omamobile-modem-sit/version @@ -1 +1 @@ -0.3.16 +0.3.19 From 7c978da4eb7bc919c25e163d2cdf82354fa8391a Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Tue, 3 Nov 2026 00:07:34 -0500 Subject: [PATCH 10/10] omamobile-modem-sit 0.3.20: request the IMS bearer as stock does, and IMS-SHANNON.md From a read of stock's IMS service (ShannonIms) on the owner's image, recorded in device/cheetah/IMS-SHANNON.md (request layouts, the order of AIMS requests, the registration state and reason values): - The IMS bearer takes the home IP type of the [profiles] entry typed ims for ims_apn (IPv4v6 on Verizon's network: 0xda=3, 0xdb=3), else IPv6 as before. - ADD_PDN carries IP type 3, the IPv4 address, IPv4 P-CSCFs and IPv4 DNS for an IPv4v6 bearer; an IPv6-only bearer gives the same bytes as 0.3.19. - Stock's OMA-DM hidden-menu item goes out before ADD_PDN. - The ISIM's P-CSCF FQDN is also resolved through the internet bearer's DNS, as stock resolves it on the default network. - Registration indications log the state and reason names. Stock never sends ADD_PDN for IMS without a P-CSCF, and status 5 is IMS_SERVICE_REGISTER_FAIL, its answer to an empty list. On the 7 Pro (2026-11-03) the IPv4v6 IMS bearer still carried no P-CSCF and the ISIM's FQDN didn't resolve on the internet bearer's DNS, so with ims_pcscf_required = yes sitd now skips IMS like stock. Whether the line is provisioned for VoLTE is the open question. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BeEcdVeSfyLCbijF8XQF1d --- device/cheetah/IMS-SHANNON.md | 377 ++++++++++++++++++ packages/omamobile-modem-sit/lib/bringup.py | 54 ++- packages/omamobile-modem-sit/lib/data_call.py | 13 +- packages/omamobile-modem-sit/lib/ims.py | 93 +++-- .../omamobile-modem-sit/test/test_bringup.py | 27 ++ .../test/test_data_call.py | 3 + packages/omamobile-modem-sit/test/test_ims.py | 42 +- packages/omamobile-modem-sit/version | 2 +- 8 files changed, 572 insertions(+), 39 deletions(-) create mode 100644 device/cheetah/IMS-SHANNON.md diff --git a/device/cheetah/IMS-SHANNON.md b/device/cheetah/IMS-SHANNON.md new file mode 100644 index 000000000..56444429d --- /dev/null +++ b/device/cheetah/IMS-SHANNON.md @@ -0,0 +1,377 @@ +# IMS-SHANNON: how stock's IMS service drives the CP's IMS stack + +Status: research note, 2026-11-02 (offline). Source: Shannon's IMS service +APK from the cheetah vendor tree (`system_ext/priv-app/ShannonIms`, +versionName `000000.000000.b9d325b79`, sha256 prefix `dd3889d95e280717`), +decompiled with jadx 1.5.1 on the laptop. Nothing of it is in the +repository; this note gives class and method names, request IDs, field names +and offsets only. Consumer: `packages/omamobile-modem-sit` (`lib/ims.py`, +`lib/bringup.py`, `lib/data_call.py`). + +Question this answers: why cheetah's CP answers our ADD_PDN_INFO on +Tracfone/Straight Talk on Verizon (311480) with IND_AIMS_REGISTRATION state +1, features 0, status 5 and never registers, while the same sequence +registers on T-Mobile. + +**Short answer.** Status 5 is `IMS_SERVICE_REGISTER_FAIL`, the permanent +registration failure. Stock never puts the CP in that position on this +path: it **never sends AIMS_ADD_PDN_INFO for IMS without a P-CSCF**. When +the IMS PDN's link properties carry none and no ISIM P-CSCF resolved, stock +stops ("stop registration for invalid pcscf", reason `NO_PCSCF`) and tears +the PDN down; `BLOCK_PDN_BY_INVALID_PCSCF` (0 for Verizon) only decides +whether the PDN is also blocked until a power cycle. ADD_PDN_INFO has no +FQDN field and no "P-CSCF from SIM" flag: the list is binary IPv4 and IPv6 +addresses only, so the CP doesn't resolve or discover anything itself. On +Verizon stock's P-CSCF comes from the IMS PDN's PCO (the RIL's data-call +response), or from the ISIM's EF_PCSCF name resolved **on the default +network** (the internet APN without Wi-Fi). Our IMS bearer request differs +from stock's for Verizon's IPv4v6 IMS APN; see section 7. + +## 1. Where things live + +| Role | Class (package `com.shannon.imsservice`) | +| --- | --- | +| Stack start/stop, hidden menu, ADD_PDN order | `conn.StackControl` (`startCpModules`, `startCpImsModules`, `sendHiddenMenu`, `sendPdnInfo`, `isRequiredOmaDmHiddenMenu`, `updateNtpTime`) | +| Request encoders | `network.adaptor.RegistrationAdaptor` (`sendStackStartReq`, `sendHiddenMenu`, `sendHiddenMenuCpImsConfiguration`, `sendHiddenMenuOmaDm`, `sendAddPdnInfo`, `sendDelPdnInfo`, `sendDeregistration`, `sendSetHiddenMenuItem`, `sendImsTestModeState`, `sendSetPdnEstStatus`, `sendRegistrationState`, `updateNtpTime`) | +| Hidden-menu TLVs | `network.adaptor.HiddenMenuBuilder` (and its enum `CpImsConfiguration`) | +| Wire layouts | `network.adaptor.data.RilReq*` / `RilInd*` (`getBytes`, `update`) | +| P-CSCF selection | `conn.ApnEntity.updatePcscfAddresses`, its network callback `handleNetworkAvailable`; `conn.ImsConnectivityMgr.getPcscfAddressFromSim` / `addPcscfFromSim` / `getHostNameFromSim`; `conn.DefaultNetworkCallback.onAvailable` | +| Registration indication | `network.adaptor.data.RilIndRegistration` (`RegState`, `RegFeature`), `conn.RegistrationReason` | +| Per-carrier policy | assets `sim_configurations/sim_configuration_311.xml`, `sim_operator_list.xml`, `operator_config.xml`; defaults `config.configuration.ImsSimConfigDefaults` | +| Message IDs | `network.oem.helper.ImsRilHelper.RilMessageId` (RIL-OEM numbers; the RIL maps them to SIT IDs) | + +The service talks to the RIL with RIL-OEM message numbers, not SIT IDs. The +payloads are the RIL-OEM structures below (little-endian, `DataWriter`). +Our daemon sends these structures as the SIT payloads of the IDs in +`lib/sit_names.py`; for HIDDEN_MENU and ADD_PDN_INFO that is proven on the +phone (T-Mobile registered). For the others the pass-through is assumed, +not verified in the RIL. + +| RIL-OEM name (number) | SIT ID / `sit_names.py` | +| --- | --- | +| `RILC_REQ_AIMS_STACK_START_REQ` (137) | 0x0d39 AIMS_STACK_START_REQ | +| `RILC_REQ_AIMS_XCAPM_START_REQ` (139) | 0x0d3b AIMS_XCAPM_START_REQ | +| `RILC_REQ_AIMS_SET_FRAME_TIME` (108) | 0x0d0b AIMS_SET_FRAME_TIME | +| `RILC_REQ_AIMS_HIDDEN_MENU` (104) | 0x0d07 AIMS_HIDDEN_MENU | +| `RILC_REQ_AIMS_ADD_PDN_INFO` (105) | 0x0d08 AIMS_ADD_PDN_INFO | +| `RILC_REQ_AIMS_DEL_PDN_INFO` (136) | 0x0d38 AIMS_DEL_PDN_INFO | +| `RILC_REQ_AIMS_SET_HIDDEN_MENU_ITEM` (146) | 0x0d36 | +| `RILC_REQ_AIMS_SET_PDN_EST_STATUS` (145) | 0x0d71 | +| `RILC_REQ_AIMS_SET_SELF_CAPABILITY` (129) | 0x0d27 | +| `RILC_REQ_AIMS_COMMON_IMS_SVC_INFO` (161) | 0x0d88 | +| `RILC_REQ_SET_IMS_TEST_MODE` (38) | 0x0614 SET_IMS_TEST_MODE | +| `RILC_REQ_SET_IMS_REGISTRATION_STATE` (48) | not in `sit_names.py` | +| `RILC_REQ_MISC_SET_PREFERRED_CALL_CAPA` (20) / `SET_VOICE_OPERATION` (45) | 0x092f / 0x091a | +| `RILC_UNSOL_AIMS_REGISTRATION` (3012) | 0x0d05 IND_AIMS_REGISTRATION | +| `RILC_UNSOL_CP_CARRIER_CONFIG_CHANGED` (9000) | the 0x4601 status (u32 status, u32 cause; status 1 releases the stack start) | + +## 2. The sequence, stack start to registered (cellular) + +1. SIM loaded, carrier config status received (`onCarrierConfigManifestStatusReceived`) + → `StackControl.startCpModules(slot, simReady)`: + - **AIMS_STACK_STOP_REQ** first if a previous stop failed, 50 ms; + - **AIMS_STACK_START_REQ** `[u8 sim status (1 ready), u8 stack type (slot + 1)]` = `01 01`; + - **AIMS_XCAPM_START_REQ** (same two bytes), when the XCAP stack may start; + - **AIMS_SET_FRAME_TIME** (`updateNtpTime`): `[u8 call id 0, u8 operation 2, u64 time]`, the time being the AP's wall clock in milliseconds since 1970. +2. The service asks Android for the IMS network (APN `IMS` on Verizon, the + attach PDN). On `handleNetworkAvailable`: `updatePcscfAddresses(linkProperties)`. + Link properties' P-CSCF list empty → the list resolved from the ISIM + (section 4); still empty → **stop: no ADD_PDN**, `NO_PCSCF`, PDN + disconnected. Otherwise → `updateStartImsStack`, then + `onApnEnabled` → `StackControl.sendPdnInfo`. +3. `sendPdnInfo`, first IMS PDN after a stack start: + - **AIMS_HIDDEN_MENU** part 1, more-expected 1 (section 5); + - **AIMS_HIDDEN_MENU** CP IMS configuration segments, only when the + carrier config enables AOSP IMS configuration (section 6); + - **AIMS_HIDDEN_MENU** part 2, more-expected 0: the video media + description (`MediaConfig.getMediaInfo`, else a built-in default); + - then `RegistrationAdaptor.sendAddPdnInfo`, which first sends the + **OMA-DM AIMS_HIDDEN_MENU** (more-expected 0) once after SIM load, when + no ADD_PDN has been sent yet (`isRequiredOmaDmHiddenMenu`, static + `setOmaDm`); + - **AIMS_ADD_PDN_INFO** (section 3). +4. The CP registers and sends IND_AIMS_REGISTRATION (section 8). On state 2 + the service sends SET_IMS_REGISTRATION_STATE `[u32 1, u32 RAT]` (a + report to the RIL, not a precondition) and, with RCS, SET_SELF_CAPABILITY. +5. Later, only on events: SET_HIDDEN_MENU_ITEM 519 (the user agent, when it + changes), SET_PDN_EST_STATUS `[u8 status]` (2 when the IMS registration + timer expires or Verizon's throttling outlasts it; 1 for AT&T's + not-subscribed), COMMON_IMS_SVC_INFO (Wi-Fi calling button, VoLTE switch), + SET_IMS_TEST_MODE `[u32]` (only when the `IMS_TEST_MODE` policy changes; + default 0, never sent at start-up). + +Our sequence (0.3.19) was: STACK_START `01 01` → SETUP_DATA_CALL (IMS, IPv6) → +HIDDEN_MENU (one segment, more-expected 0) → ADD_PDN_INFO (empty list) → +status 5. Missing against stock: XCAPM_START, SET_FRAME_TIME, the OMA-DM +menu, hidden-menu part 2, and above all a P-CSCF. + +## 3. AIMS_ADD_PDN_INFO (0x0d08) layout + +`RilReqAddPdnInfo.getBytes`, filled by `RegistrationAdaptor.sendAddPdnInfo`. +Offsets for a cellular PDN with `n4` IPv4 and `n6` IPv6 P-CSCF addresses +(the list position makes everything after it move). + +| Offset | Size | Field | Stock value on cellular IMS | +| --- | --- | --- | --- | +| 0 | 1 | PDN type | `ApnNetType.getApnCategory`: IMS 2 | +| 1 | 1 | IP type | `ApnEntity.getIpType`: bit 0 IPv4, bit 1 IPv6 (3 for both) | +| 2 | 4 | PDN IPv4 address | 0.0.0.0 when none | +| 6 | 16 | PDN IPv6 address | :: when none | +| 22 | 1 | HD internet enabled | 17 | +| 23 | 1 | operator ID | 0 | +| 24 | 1 | registration style | `getRegStyle`: 0 normal, 1 for handover/re-registration | +| 25 | 1 | PDN new | 1 new, 0 for handover/re-registration | +| 26 | 1 | VoLTE auto-config | 0 | +| 27 | 1 | RCS auto-config | 0 | +| 28 | 2 | offering type | `getOfferingType`: capability bits (VoLTE 1, SMS-IP 2, RCS 4, PSVT 8, RTT 16, mobile data 32, Wi-Fi data 64, ViCE 256) | +| 30 | 1 | registration type | `ApnNetType.getRegType` (IMS 0; 3 with RCS on) | +| 31 | 1 | init type | 0, 1 handover, 2 re-registration | +| 32 | 1 | IMS net type | transport: 1 cellular, 2 Wi-Fi | +| 33 | 6 | Wi-Fi MAC | zero on cellular | +| 39 | 1 | IPv4 P-CSCF count `n4` | at most 8 | +| 40 | 4·n4 | IPv4 P-CSCF addresses | | +| 40+4n4 | 1 | IPv6 P-CSCF count `n6` | at most 8 | +| 41+4n4 | 16·n6 | IPv6 P-CSCF addresses | | +| then | 4, 16, 4, 16 | primary DNS IPv4, IPv6; secondary DNS IPv4, IPv6 | from the link properties | +| then | 23 | last access network, two 8-byte timestamps, TAC (u16), cell ID (u32) | Wi-Fi only; zero on cellular | +| then | 4 | remaining emergency registration timer | 0 | +| then | 10 | network MCC/MNC digits (6), country code (2), MTU (2) | Wi-Fi only; zero on cellular | +| then | 4, 2, 4 | RCS capability mask, vendor capability mask, extended RCS mask | 0 without RCS | +| then | 1 + 32 | VoWiFi E911 AID length and text | empty | +| then | 2 | additional-field length | 12 on cellular | +| then | 500 | additional fields, fixed buffer: TLV `u16 tag 1, u16 len 8, u64 SIP delegate capability`; on Wi-Fi also band (tag 2), cell ID (4), TAC (5), interface index (6) | | + +There is **no FQDN, domain or "from SIM" field**. Every P-CSCF is a binary +address the AP resolved. Compared with our `add_pdn_payload` (0.3.19): the +layout matches field for field; differences were IP type fixed at 2 (IPv6 +only, IPv4 address and IPv4 DNS always zero), at most 3 IPv6 P-CSCFs (stock 8) +and, by configuration, an empty list (stock: never). 0.3.20 announces an +IPv4v6 bearer with both families as stock does (section 9). + +AIMS_DEL_PDN_INFO (0x0d38): `[u8 IMS net type, u8 PDN type, u8 reason]`. +AIMS_DEREGISTRATION (0x0d06): `[u8 PDN type, u16 feature 126, u8 cause 0]`. + +## 4. P-CSCF handling in stock + +`ApnEntity.updatePcscfAddresses(LinkProperties)`, for IMS, emergency and +RCS PDNs: + +1. `linkProperties.getPcscfServers()`: the P-CSCF list Android's data stack + got from the RIL's data-call response, which the CP fills from the PDN's + PCO. +2. If empty: `ImsConnectivityMgr.mPcscfAddressFromSim`. That list is built by + `getHostNameFromSim` (`TelephonyManager.getIsimPcscf()`: the ISIM's + EF_PCSCF, non-alphanumeric characters stripped) and + `getPcscfAddressFromSim`, which resolves each name with + `InetAddress.getByName` on its own thread. That runs when the **default + network** becomes available (`DefaultNetworkCallback.onAvailable`), so the + name is resolved by the default network's DNS: the internet APN's DNS + servers when there is no Wi-Fi, never the IMS PDN's. `getByName` returns + one address per name, IPv4 or IPv6, whichever the resolver puts first. +3. Split into IPv4 and IPv6 lists by address family. Both empty → return + false → `handleNetworkAvailable` logs "stop registration for invalid + pcscf", sets `DeregiImsReasonInfo.NO_PCSCF` and disconnects; with + `BLOCK_PDN_BY_INVALID_PCSCF` = 1 it also blocks the PDN + (`blockPdnByInvalidPcscfIfNeeded`, `RETRY_COUNT_FOR_INVALID_PCSCF`). + Verizon's 311480 entry sets it to 0, so stock just waits for the next PDN + or default-network event; it still sends no ADD_PDN. + +So for this SIM stock registers only if (a) the IMS PDN's PCO carries a +P-CSCF, or (b) `pcscf1.anyims.vzims.com` resolves through the internet APN's +DNS. Which of the two it is on this line can only be read from a stock +logcat (section 10, step 0). + +## 5. AIMS_HIDDEN_MENU (0x0d07) and the provisioning requests + +Request (`RilReqHiddenMenu`): `[u8 more-expected, u16 data length, data]`. +Data is a list of items (`HiddenMenuBuilder`): `u16 tag` then either a u32 +integer (integers of -1 are skipped), or a string/byte string followed by +`##` (0x23 0x23). Segments at most 900 data bytes. + +Part 1 (`RegistrationAdaptor.sendHiddenMenu`, more-expected 1): + +| Tag | Value | +| --- | --- | +| 523, 527, 529, 531, 533 | 30 each (SIP timers A, E, G, I, K) | +| 772 / 773 / 774 / 775 / 776 | manufacturer / model / build ID / product name / OS version (`DeviceInfoUtil`) | +| 519 | the user agent (`SIP_USER_AGENT` template; Verizon `#MANUFACTURE#---#MODEL#---#BUILD#`) | +| 1044, 1045 | geolocation PIDF for VoWiFi / VoLTE emergency calls (Verizon: 1045 = 1) | +| 1080, 1081, 1082 | EPS-fallback silent-retry error code, VoLTE/VoWiFi silent-retry policy and codes (default 0) | +| 1084 | RTT supported | + +Part 2 (more-expected 0): the video media description (`SetVideoMediaInfo`: +bandwidth, CVO, ECN, H.264/H.265 fmtp lines), a binary structure, not TLVs. +It configures video calls, not registration. Our single segment with +more-expected 0 registered on T-Mobile, so the CP accepts the menu without it. + +OMA-DM menu (`sendHiddenMenuOmaDm`, more-expected 0, once before the first +ADD_PDN after SIM load, on every carrier): tag **777 = 1** (is-OMA-DM-update), +then the provisioned `OmaDmProvisionedDataType` values: 778 domain name +(skipped while it is the default "IMS"), 779 T1, 780 TF, 781 T2, 782 AMR-NB +mode set, 783 AMR-WB mode set, 784 session expiry, 785 Min-SE, 786 +cancellation timer ("HVOLTE TVZW"), 787 Tdelay, 788 silent redial. Defaults +are -1 (skipped) for the integers and empty strings for 782/783 (sent as +`tag ##`). With nothing provisioned the menu is `777=1` plus the two empty +AMR items. + +SET_HIDDEN_MENU_ITEM (0x0d36): `[u16 tag, u16 length, data padded to 100]`. +GET_HIDDEN_MENU_ITEM (0x0d37): the tag. + +None of these carry a P-CSCF, domain, IMPI/IMPU or transport. The CP's IMS +stack reads IMPI, IMPU and the home domain from the ISIM itself (the service +only checks the ISIM domain isn't the placeholder "IMS", +`isValidIsimDomain`), and its SIP settings come from the CP's carrier +profile (the 0x4600 manifest), unless section 6 applies. + +"VoLTE enabled", "SMS over IMS enabled": no request carries them at +registration. They become the offering type in ADD_PDN_INFO (VoLTE 1, +SMS-IP 2; `CapabilityManager`), and later SET_SELF_CAPABILITY +(`[u8 version 1, u16 feature, u32 mask, u32 extended mask, u64 delegate mask]`). + +## 6. Carrier config: what reaches the CP + +`sim_configuration_311.xml`, MNC 480 (Verizon; Tracfone-VZW matches it by +MCC/MNC, no MVNO override except Cellcom's GID). Keys there that change what +the CP sees or whether stock registers: + +| Key | Verizon value | Effect | +| --- | --- | --- | +| `BLOCK_PDN_BY_INVALID_PCSCF` | 0 | no PDN block after a P-CSCF-less PDN; still no ADD_PDN | +| `SIP_USER_AGENT` | `#MANUFACTURE#---#MODEL#---#BUILD#` | hidden-menu tag 519 | +| `GEOLOCATION_PIDF_FOR_VOLTE_EMERGENCY_CALL` | 1 | tag 1045 | +| `IMS_SINGLE_REGISTRATION_REQUIRED` | 1 | RCS on the IMS registration (RCS off by default) | +| `SMS_FORMAT` | 1 (3GPP) | SMS over IMS format | +| `LTE_VOPS_POLICY`, `USE_VOPS_STATUS_ROAM` | 1, 0 | whether stock requests the IMS PDN without VoPS | +| `IMS_PDN_ACTIVATION_TIMEOUT`, `NR_TIMER_WAIT_IMS_REGISTRATION` | 120, 120 | timers that end in SET_PDN_EST_STATUS 2 | +| `ALLOWED_RAT` | LTE, LTE_CA, NR, IWLAN | | +| `DATA_CALL_PERMANENT_FAILURE_FOR_IMS` | causes 0x8, 0x1B-0x1D, 0x20, 0x23, 0x32, 0x33 | PDN causes that stop IMS on cellular | + +The CP IMS configuration menu (`HiddenMenuBuilder.CpImsConfiguration`: SIP +port tag 10, registration expiry 11, retry timers 20/21, T1/T2/T4 534-536, +timers B-J, preferred transport 1049, IPsec 15/16 and 1031, phone-context +1025, URI type 1026, MTUs 1028/1029, GRUU 1046, reg-event 1047/1048, codecs +258 and 1060-1062, ...) is sent only when +`CarrierConfigManagerReceiver.isSupportAospImsConfiguration` holds: the +carrier config key `vendor.ims.carrier_config_use_aosp_ims_config_bool` (or a +persist property) and `UPDATE_IMSCONFIG_BY_CARRIERCONFIG`. Values come from +the `vendor.ims.*`/AOSP IMS keys. Whether Verizon's CarrierSettings sets the +key wasn't checked here (the decoded CarrierSettings in +MODEM-PROVIDER-PROFILES.md is the place). Without it the CP uses its own +carrier profile for all of these, which is the profile the 0x4600 manifest +selects (`us_tracfone`). + +## 7. Status 5 and the other registration values + +`RilIndRegistration.update`: `u8 state, u8 feature, u32 feature mask, u16 +status, u16 URI length (≤1000), u16 reason length (≤256), URI + reason text, +[u32 feature mask ext], [u64 SIP delegate mask], [u16 feature ext]`. Our +`record_registration` reads the same fields. + +States (`RegState`): 1 VoLTE not registered, 2 VoLTE registered, 3 VoLTE +limited, 4 E911 not registered, 5 E911 registered, 6 RCS not registered, 7 RCS +registered, 8 E911 pseudo-registered. Features (`RegFeature`): 0 unknown, 1 +VoLTE, 2 SMS-IP, 3 RCS, 4 PSVT. + +Status (`RegistrationReason`, its CP reason; ImsReasonInfo code, extra): + +| Status | Name | Code / extra | Stock reaction | +| --- | --- | --- | --- | +| 0 | REGISTER_SUCCESS | 132 | | +| 1 | DEREGISTER_FEATURE_MISMATCH | 132 | | +| 2 | DEREGISTER_NETWORK_TRIGGERED | 132 / 1513 | keep waiting | +| 3 | DEREGISTER_NO_RESP_FROM_NETWORK | 132 / 1503 | PDN torn down | +| 4 | DEREGISTER_INTERNAL | 132 / 131 | | +| **5** | **REGISTER_FAIL** | **1000 / 61442** | **PDN torn down (`isNeedPdnDeactivationReason`); not a CP retry reason** | +| 6 | REGISTER_FAIL_500 | 1000 / 352 | | +| 7 | REGISTER_FAIL_403 | 1000 / 332 | CP retries; PDN down unless 403 retry applies | +| 8 | REGISTER_FAIL_RETRY | 1000 / 61441 | CP retries, keep waiting | +| 9 | REGISTER_LIMITED | 132 / 121 | SMS-IP feature cleared | +| 10 | FAIL_TRY_AFTER_CELL_CHANGE | 1000 / 61442 | | +| 11 | FAIL_PLMN_BARR | 132 / 1000 | keep waiting | +| 12 | FAIL_FRESH_REG_START | 132 / 1000 | keep waiting | +| 13 | DEREGISTER_FAIL_ONGOING_CALL | 1000 | | +| 14 | FAIL_START_TIMER | | | +| 15 | FAIL_TRY_AFTER_WIFI_REASSOCIATE | 1000 | | +| 16 | FAIL_TRY_AFTER_RAT_CHANGE | 132 | | +| 18 | FAIL_SILENT_RETRY_FOR_CALL | 132 | | +| 254 | FAIL_NO_VALID_SIM | 1000 / 1501 | | +| 512 | RETRY_AFTER_PLMN_CHANGE | 132 / 1000 | | +| 255 | unspecified | | | + +Status 5 arriving immediately after ADD_PDN, with no SIP exchange in +between, fits a stack with no P-CSCF to send REGISTER to: the CP gives up +for that PDN at once. A SIP failure would come back as 6, 7 or 8 after +seconds, usually with reason text. + +## 8. Requests the AP owes the CP + +- **No AP-answered identity requests.** The CP never asks the service for + IMEI/IMEISV; the IMEISV only goes into the user agent if the template has + `#IMEISV#` (Verizon's doesn't). `RILC_REQ_IMS_SIM_AUTH` and + `GET_GBA_AUTH` are AP-to-CP requests for XCAP/GBA, not something the CP + waits for. +- **Time:** AIMS_SET_FRAME_TIME operation 2 with the wall clock, right after + stack start. We don't send it (0x0d0b isn't on `sit.py`'s allow-list). + Registration doesn't obviously depend on it (T-Mobile registered without + it), but it is the one start-up handshake we skip. +- **Carrier-config handshake:** the 0x4601 status before stack start; done + since 0.3.19. +- **Location/country:** only for Wi-Fi registration (ADD_PDN's Wi-Fi fields, + AIMS_SET_GEO_LOCATION_INFO for emergency); nothing on cellular. + +## 9. omamobile-modem-sit 0.3.20 (implemented, uncommitted, tested offline) + +- `data_call.setup_payload(..., ims=True, ip_type=...)`: the IMS bearer's PDP + type and P-CSCF request now follow `ip_type` (0xda = IP type, 0xdb = + `PCSCF_REQUEST`: IPv6 2, IPv4v6 3). `ip_type=None` keeps 0.3.19's IPv6/2. +- `bringup.ims_ip_type`: the IMS bearer uses the home IP type of the + `[profiles]` entry with the `ims` type for `ims_apn` (read only), else IPv6. + With the Verizon example profile (`2 = IMS; types=ia,ims; ip=ipv4v6; + roaming_ip=ipv6`) the IMS setup becomes PDP type 3 with P-CSCF request 3, + the same as the attach on that APN and as stock asks for Verizon's IMS APN + at home. T-Mobile (no such profile) is unchanged. +- `ims.add_pdn_payload`: IP type from the bearer's addresses (stock's + `getIpType`), so an IPv4v6 bearer is announced with its IPv4 address, + IPv4 P-CSCFs (at 39) and IPv4 DNS. An IPv6 bearer gives the same bytes as + 0.3.19 (tested). The empty-list path stays behind `ims_pcscf_required = no`, + now documented as something stock never does. +- `ims.oma_dm_menu` sent before ADD_PDN: `00 06 00 | 09 03 01 00 00 00` + (tag 777 = 1). Stock's empty AMR items 782/783 are left out on purpose. +- ISIM name resolution adds stock's path: the **internet bearer's own DNS + servers** (from its setup response, bound to its IPv6 address), after the + IMS bearer and before the host resolver + (`bringup.resolve_default_network`). The host resolver may be the USB + link to the laptop, which is not what stock would ask. +- IND_AIMS_REGISTRATION is logged with the state and status names. +- `packages/omamobile-modem-sit/test/all` passes (unit tests and the RIL + against `tools/sit-sim`). + +## 10. Ranked changes and runbook + +| # | Change | Why | Risk | +| --- | --- | --- | --- | +| 0 | **Read stock's answer first** (human's call: needs a stock boot of slot A, and then a fresh read-only NV backup per AGENTS.md). With this SIM on stock, `adb logcat -b all` filtered for `ShannonIms`/`SLogger`: "Sending AddPdn Info IpType [...]", "P-CSCF address of LinkProperties is invalid. Use P-CSCF address received from SIM", "P-CSCF Address:", "stop registration for invalid pcscf", "pcscf-ip-address-6-num". Tells whether Verizon's PCO carries the P-CSCF on stock and whether the SIM name resolves | removes guessing | stock boot: medium (rewrites `efs`/`persist`/`modem_userdata`) | +| 1 | Set `ims_pcscf_required = yes` on the phone (the package default) | an empty list gets status 5 by construction; stock never sends it | none | +| 2 | 0.3.20: IMS bearer IPv4v6 from the IMS profile (SETUP_DATA_CALL `0xda=3, 0xdb=3`), and ADD_PDN with IP type 3 | matches stock's request on Verizon's IPv4v6 IMS APN, which is also the attach APN (attach already asks 3/3); a mismatched IPv6-only request on the attach PDN's APN may be why the CP reports no PCO P-CSCF | medium: changes the IMS bearer request on Verizon only | +| 3 | 0.3.20: resolve the ISIM's FQDN through the internet bearer's DNS | stock's `getPcscfAddressFromSim` path | low (DNS queries only) | +| 4 | 0.3.20: OMA-DM menu (777 = 1) before ADD_PDN | stock always sends it; a Verizon-profile CP may expect it | low | +| 5 | Log what the CP sends after attach: P-CSCF family/counts of every entry of GET_DATA_CALL_LIST (not only CID 2), and IND_PCO_DATA (0x060d) container IDs and lengths only | shows whether the attach PDN's PCO has a P-CSCF the CID 2 response drops | none (read-only) | +| 6 | AIMS_SET_FRAME_TIME `00 02 ` after STACK_START (needs 0x0d0b on the allow-list: maintainer's call) | stock's start-up handshake | low | +| 7 | Verizon user agent `Google---Pixel 7 Pro---` in tag 519 | Verizon's template; matters only once SIP REGISTER goes out | low | +| 8 | Hidden-menu part 2 (video media) and XCAPM_START | completeness; not needed for registration | low | + +Runbook for 0.3.20 on the phone (human approves each step; no reboot needed +beyond restarting the service, which the phone's owner should know about): + +1. Read-only: confirm `[profiles]` has the IMS entry with `ip=ipv4v6` and + `ims_pcscf_required = yes` in `/etc/omamobile/modem-sit.conf`. + Pass: both present. Stop: no IMS profile (0.3.20 then behaves as 0.3.19). +2. Install 0.3.20 (`tools/phone-install-package` from this worktree), restart + `omamobile-sitd` after an IMS-free boot (the daemon refuses a second IMS + attempt in one boot). Expect in the journal: "IMS bearer PDP type ipv4v6", + "data-call status 0 ... PDP type 3", "P-CSCF count IPv4 n IPv6 m". + Pass: a count above 0, ADD_PDN sent, then IND_AIMS_REGISTRATION state 2. + Stop: setup status non-zero, or counts 0 and the ISIM name unresolved + (ADD_PDN is then not sent; no status 5). Rollback: reinstall 0.3.19. + Risk: medium (new IMS bearer request; internet bearer untouched). +3. If counts stay 0: change 5 (logging), then step 0. diff --git a/packages/omamobile-modem-sit/lib/bringup.py b/packages/omamobile-modem-sit/lib/bringup.py index bad44abf5..3368d09ef 100644 --- a/packages/omamobile-modem-sit/lib/bringup.py +++ b/packages/omamobile-modem-sit/lib/bringup.py @@ -15,10 +15,13 @@ (AT+CFUN=0 first). Then wait for packet registration (on LTE with nr = off) and log how long it took; 4. the internet bearer (CID 1; its rmnet device is found by omamobile-sit-data); - 5. IMS: stack start, the IMS bearer (CID 2, IPv6), ADD_PDN_INFO (its - P-CSCF from the bearer's PCO, else from the ISIM's EF_PCSCF with - [network] ims_pcscf_from_isim = yes), then wait for an IMS - registration with voice and SMS. + 5. IMS: stack start, the IMS bearer (CID 2; IPv6, or the IMS profile's + home IP type, as stock takes it from the IMS APN), the hidden menu and + the OMA-DM menu, ADD_PDN_INFO (its P-CSCF from the bearer's PCO, else + from the ISIM's EF_PCSCF with [network] ims_pcscf_from_isim = yes, a + name resolved over the IMS bearer, the internet bearer's DNS or the + host resolver), then wait for an IMS registration with voice and SMS. + The stock IMS service and its requests: device/cheetah/IMS-SHANNON.md. No retransmission of SMS/calls and no warm CP restart. A failed or uncertain step up to the internet bearer ends start-up; the service exits and the @@ -28,13 +31,44 @@ import time from at import radio, radio_state -from data_call import activate, configured_profiles, initial_attach, provision_profiles +from data_call import APN_TYPES, activate, configured_profiles, initial_attach, provision_profiles +from data_call import paths as bearer_paths from ims import register, start_stack -from isim import ipv6_pcscf +from isim import bearer_dns, ipv6_pcscf, resolve_on_bearer, resolve_system from radio_settings import SAVED_NR, nr_mode from sit import ModemError +def ims_ip_type(profiles, ims_apn): + """The IMS bearer's PDP type: the home protocol of the [profiles] entry + with the ims type for ims_apn, as stock takes it from the IMS APN + (Verizon's IMS APN is IPv4v6 at home), else IPv6 (unchanged from 0.3.19).""" + for profile in profiles: + if profile.types & APN_TYPES['ims'] and profile.apn.lower() == ims_apn.lower(): + return profile.ip + return 'ipv6' + + +def resolve_default_network(name): + """AAAA as stock's IMS service resolves an ISIM P-CSCF name + (InetAddress.getByName on the default network: the internet bearer + without Wi-Fi): the internet bearer's own DNS servers from its setup + response, then the host resolver, which may be another link.""" + found = [] + response = bearer_paths(1)[1] + if response.exists(): + bearer = response.read_bytes() + if len(bearer) >= 132 and any(bearer[9:25]): + source, servers = bearer_dns(bearer) + try: + found = resolve_on_bearer(name, source, servers) if servers else [] + except (OSError, ValueError): + found = [] + if found: + print(f'P-CSCF from ISIM: {name} resolved through the internet bearer\'s DNS', flush=True) + return found or resolve_system(name) + + def sim_ready(payload): if len(payload) < 3 or payload[2] > 8 or len(payload) < 3 + payload[2] * 63: raise ValueError('Unexpected SIM status layout') @@ -259,12 +293,16 @@ def registered(): 'manifest sent' if service.manifest_sent else 'no request from the modem seen', ')', flush=True) start_stack(client) - activate(client, net.get('ims_apn', 'ims'), ims=True, on_event=service.event) + ims_apn = net.get('ims_apn', 'ims') + ims_ip = ims_ip_type(profiles, ims_apn) + print('IMS bearer PDP type', ims_ip, '(from the IMS profile)' if ims_ip != 'ipv6' else '', flush=True) + activate(client, ims_apn, ims=True, ip_type=ims_ip, on_event=service.event) fallback = None if net.getboolean('ims_pcscf_from_isim', True): # The ISIM's EF_PCSCF when the PCO has none (one read-only file). def fallback(bearer): - return ipv6_pcscf(client, client.request(0x0200), bearer) + return ipv6_pcscf(client, client.request(0x0200), bearer, + resolve_host=resolve_default_network) register(client, pcscf_required=net.getboolean('ims_pcscf_required', True), pcscf_fallback=fallback) print('Startup: waiting for IMS voice and SMS registration', flush=True) diff --git a/packages/omamobile-modem-sit/lib/data_call.py b/packages/omamobile-modem-sit/lib/data_call.py index 465469db3..c9de8d012 100644 --- a/packages/omamobile-modem-sit/lib/data_call.py +++ b/packages/omamobile-modem-sit/lib/data_call.py @@ -109,8 +109,13 @@ def private_write(path, data): out.write(data) -def setup_payload(cid, radio_technology, pdu_session, apn, *, ims=False, ip_type='ipv4v6'): +def setup_payload(cid, radio_technology, pdu_session, apn, *, ims=False, ip_type=None): # Absolute request offsets below include the 12-byte request header. + # ip_type None: IPv6 for IMS (what every IMS setup used until 0.3.19), + # IPv4v6 otherwise. For IMS, stock takes the PDP type from the IMS APN's + # protocol and the P-CSCF request from it (GetPcscfReqType). + if ip_type is None: + ip_type = 'ipv6' if ims else 'ipv4v6' check_apn(apn) full = bytearray(983) full[12] = cid @@ -120,8 +125,8 @@ def setup_payload(cid, radio_technology, pdu_session, apn, *, ims=False, ip_type encoded = apn.encode('ascii') full[16:16 + len(encoded)] = encoded full[0xd9] = 0 # no authentication - full[0xda] = IP_TYPES['ipv6'] if ims else IP_TYPES[ip_type] - full[0xdb] = 2 if ims else 0 # IPv6 P-CSCF request + full[0xda] = IP_TYPES[ip_type] + full[0xdb] = PCSCF_REQUEST[ip_type] if ims else 0 # P-CSCF request (IPv6 2, both 3) # No handover addresses, roaming override or slice. # 0xf1 (u32): the APN-type bitmap, as stock's builder copies it from # ApnSetting's supported types (vendor.radio.base @@ -388,7 +393,7 @@ def listen_after_failure(client, seconds=5, on_event=None): on_event(packet) print(f'after the failure: {seen} indication(s) in {seconds} s', flush=True) -def activate(client, apn, *, ims=False, ip_type='ipv4v6', lte_access=False, on_event=None): +def activate(client, apn, *, ims=False, ip_type=None, lte_access=False, on_event=None): requested_cid = 2 if ims else 1 state_path, response_path = paths(requested_cid) state = client.request(0x0701) diff --git a/packages/omamobile-modem-sit/lib/ims.py b/packages/omamobile-modem-sit/lib/ims.py index 2545e84b2..dd72b77b9 100644 --- a/packages/omamobile-modem-sit/lib/ims.py +++ b/packages/omamobile-modem-sit/lib/ims.py @@ -16,6 +16,22 @@ REGISTRATION = RUN / 'ims-registration.json' +# IND_AIMS_REGISTRATION's state byte and status code, as the stock IMS +# service names them (RilIndRegistration.RegState, RegistrationReason's CP +# reason). Status 5 is a permanent failure: stock tears the IMS PDN down +# after it (isNeedPdnDeactivationReason) and doesn't retry on that PDN. +REG_STATES = {1: 'VoLTE not registered', 2: 'VoLTE registered', 3: 'VoLTE limited', + 4: 'E911 not registered', 5: 'E911 registered', 6: 'RCS not registered', + 7: 'RCS registered', 8: 'E911 pseudo-registered'} +REG_STATUS = {0: 'success', 1: 'feature mismatch', 2: 'network-triggered deregistration', + 3: 'no response from the network', 4: 'internal deregistration', + 5: 'registration failed', 6: 'failed with 500', 7: 'failed with 403', + 8: 'failed, CP retrying', 9: 'limited registration', 10: 'failed, retry after cell change', + 11: 'PLMN barred', 12: 'fresh registration starting', 13: 'deregistration failed, call ongoing', + 14: 'failed, start timer', 15: 'failed, retry after Wi-Fi reassociation', + 16: 'failed, retry after RAT change', 18: 'failed, silent retry for a call', + 254: 'no valid SIM', 255: 'unspecified', 512: 'retry after PLMN change'} + def record_registration(packet): if len(packet) < 20: @@ -27,7 +43,8 @@ def record_registration(packet): # URI before it is the subscriber's identity and is never logged. reason = packet[20 + uri_len:20 + uri_len + reason_len].decode('ascii', 'replace').strip('\0 ') reason = re.sub(r'\d{7,}', '', re.sub(r'(sip|tel):\S+', '', reason)) - print(f'IMS registration indication: state {state}, features {features}, status {status}' + print(f'IMS registration indication: state {state} ({REG_STATES.get(state, "unknown")}), ' + f'features {features}, status {status} ({REG_STATUS.get(status, "unknown")})' + (f', reason "{reason}"' if reason else ''), flush=True) if REGISTRATION.exists(): private_write(REGISTRATION, json.dumps({'state': state, 'features': features, @@ -52,38 +69,62 @@ def hidden_menu(): return struct.pack('