From aa3c39404184446b86cae744f6c1493dbc641a91 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Fri, 16 Oct 2026 23:30:25 +0200 Subject: [PATCH] imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the modem's own IMS client off, a carrier that carries SMS over IMS only leaves the phone no path for texts but imsd; on one with SMS over NAS the +g.3gpp.smsip tag may take them off a path that works (the order is operator policy, TS 24.341 5.3.3.4.2 NOTE 2). So the knob is the user's and off by default: SMS_OVER_IMS=1 advertises the tag (Context::smsOverIp), reads the service centre from EF_SMSP record 1 at bring-up — SMSC= instead — and opens Send on a second interface, net.catcrafts.IMS1.Messaging, beside the frozen one, gated by a polkit action of its own (Gated's Action parameter; the Voice action's callers are unchanged). The shell keeps one message in flight on the flow and queues the rest, routes the in-flight MESSAGE's final to it (OnSmsResponse; a submit report reaches it through OnSmsMessage), seeds and advances the TP-MR, RP-MR and concatenation counters, answers an inbound MESSAGE outside a call through OnSmsMessage (one inside the call's dialog stays the CallMachine's, and is not the MESSAGE of any sentence below) — the message to the bus as Received, the delivery report on the flow with its final logged, a status report matched by TP-MR and recipient to the message that asked for one — and reports a message's fate as StateChanged. A Send is judged when the engine takes its command up: unregistered or with the flow down then, it fails with that reason. The journal names a delivered message's sender, size and time — a text reaches it only as the body of a MESSAGE whose Content-Type does not contain application/vnd.3gpp.sms or as the hex of a body that is no RP message or of an unusable TPDU; DUMP_SIP adds the two MESSAGE dumps. While the knob is off a network may deliver a short message over IP regardless; answering it 200 and acknowledging it would count it delivered to nobody, so it is refused with 480 Temporarily Unavailable, which lets the IP-SM-GW try the modem's path where the network has one (TS 24.341 5.3.3.4.2 NOTE 2); a MESSAGE outside a call's dialog whose Content-Type does not contain application/vnd.3gpp.sms (letter case ignored) is still answered 200 and logged with its body — the 200 in BuildResponse's shape now, the line with the content type. A retransmitted MESSAGE — the same Call-ID, CSeq and Via branch (the value of the first `branch=` of its first Via line; a MESSAGE with none or an empty one is never taken for a copy) within 32 s of our final, in the same run of the daemon — is answered again and not handled again (the engine's RecentTransactions, a table in memory), where a repeated RP-DATA would otherwise, with SMS over IP on, be handled again: a second delivery report where the first got one and, of a text in one segment, a second text. The Messaging signals carry a text's content, and a D-Bus broadcast reaches every account the bus policy lets receive from imsd — which polkit cannot narrow — so they are never broadcast: Subscribe, behind the same action as Send, records the caller's unique name, and Received and StateChanged go unicast to each subscriber (the submission's sent or failed also to the Send caller), which the bus delivers to those connections — root's busctl monitor sees them as well. A subscription ends with its connection; a consumer subscribes at start and again when imsd's name reappears. GetStatus answers `enabled` from the daemon's configuration, not from the registration snapshot, so an asker before the first registration reads the truth. A message's id holds the run's token, eight hex digits drawn from std::random_device at the daemon's start, ahead of a second and a count: `ims-sms---` for a sent text, with the start second and a counter, and `ims-sms-in---` for a received one, with its second. A counter starts over with the daemon, and the phone's wall clock reads 1970 until the first time sync, so a second repeats across runs: the token is what tells one run's ids from another's, and a client keys by id (RunToken, SentSmsId and ReceivedSmsId, pinned by tests/Engine). Tested on the dev phone on KPN (2026-10-17; the fp6 journal's 2026-10-17-sms-over-ip-bench capture) on sms-branch builds ahead of this history (195e91b, then c57765a with the retransmission absorption): the tag on a resumed and on a fresh registration, Sends to 202 and their submit reports in one and two segments and in UCS-2, texts received in one and two segments and in UCS-2, every delivery report answered 202 but one of the two for the 01:23 text, refused 488 on the build before the absorption, and a same-second retransmission absorbed under c57765a (01:44) — AGENTS.md §5 has the record and §13 the network facts, among them that the modem was CS-detached that night. On the host's session bus in dev mode: two Sends answered with ids and failed "imsd is not registered" (2026-10-16), and three connections — a subscriber, a match-rule-only listener, an unsubscribed sender — where only the subscriber and the sender heard the StateChanged and the subscription ended with its connection (2026-10-17); with the knob off, GetStatus's `enabled` false, Send refused NotSupported and Subscribe answered (a private session bus, this commit's host build, 2026-11-19; its sha256 begins 98e30a9522409d99). The SMSC= override ran on 2026-10-18 from 02:17 (smsc-override-2026-10-18-0217): the EF_SMSP number as an override and a Send through it to sent, and SMSC=abc stopped at bring-up with "is not a number" (ForNumber dials digits, * and # only; the bench's first run, on a build outside this history that dialled the BCD table's a, b and c, submitted with them and got an RP-ERROR back, RP cause 28). A status report is matched to the message that asked for one by its TP-MR and the recipient's number — among this run's messages: the book is in memory — and the message gets a word for the whole (StatusReportBook, pinned), by TS 23.040 9.2.3.15's classes of TP-ST: delivery-failed at the first report in which the SC is not making any more transfer attempts (a permanent error or a temporary one; a reserved value too, read as "Service Rejected" as the clause has the MS read it), delivered when the last of its segments is reported in the completed class (the SC's word in the reason) — never a later segment's word over an earlier failure. The next TP-MR is kept in /sms-tpmr across restarts, so the TP-MRs continue instead of starting over at random: a reuse needs a full 256-segment wrap, not a restart (a report can be days late) — as long as the file's last write reached the disk: it is neither checked nor synced. One message's StateChanged words come in the order they mean, which is not the order imsd learns them: the service centre can deliver and report on segment 1 while segment 2 is still on its way. SmsWordOrder (Imsd:Engine, pure) gives the order §8.4 states: the submission's word first — `sent`, or `failed`, after which nothing follows — and a report's only after `sent`. A report's word on the message in flight is held until the submission ends (the latest word; one message is in flight at a time) and posted after `sent`. A submission that fails after the centre reported every segment delivered posts `sent`, the failure in its reason, and then `delivered`. A `failed` otherwise drops the held word and StatusReportBook::ForgetMessage forgets the message's TP-MRs, so a later report on a part that went matches nothing and is logged. tests/Engine pins the book's forgetting and each of these orders. BuildResponse (the messages commit) is the final of the inbound MESSAGE path from here on — the 200, the 480 and the 488; BuildResponse200's hop-by-hop shape stays for the other answers that had it. The reassembler's 30-minute age-out is judged in the run loop beside the SMS deadline, whether or not another MESSAGE ever comes. The MESSAGE's target is the service centre's own international number (ScPsi), not RuriFor's dialled-number guess, whose trunk-0 rule is Dutch: a national SMSC= of nine or more characters starting with 0 would have become a +31 number, a 00-prefixed one +, any other non-international value a phone-context URI at the home domain; a service centre ScPsi makes nothing of (national, 00-prefixed, or a '*' or '#' among the digits, which ForNumber dials) is refused at bring-up on that same predicate with a journal line, never announced, and Send then fails with no service centre. A failed submission's StateChanged reason can hold the network's text (a refused final's, RefusalSummary); a D-Bus string must be valid UTF-8, so the emission makes it so (g_utf8_make_valid: bytes that are not become U+FFFD, and a NUL byte ends the string). --- .gitignore | 3 + AGENTS.md | 475 +++++++++++++++++++++++++-- README.md | 33 +- implementations/main.cpp | 478 ++++++++++++++++++++++++++-- interfaces/Imsd-Engine.cppm | 167 +++++++++- interfaces/Imsd-Messages.cppm | 4 +- interfaces/ImsdBus.cppm | 48 +-- packaging/APKBUILD.binary | 2 +- packaging/net.catcrafts.IMS1.conf | 4 +- packaging/net.catcrafts.IMS1.policy | 23 +- tests/Engine/main.cpp | 108 ++++++- 11 files changed, 1268 insertions(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index 51b3a5d..37456a2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ imsd-*.tar.gz *.rtp *.stats imsreg.state + +# SMS over IP's state: the next TP-MR (and its .tmp) +sms-tpmr* diff --git a/AGENTS.md b/AGENTS.md index 2e07848..b356948 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,9 @@ firmware on such phones brings up the IMS PDN but cannot carry call audio, so imsd does the whole IMS client itself: SIP registration with USIM AKA authentication over kernel IPsec (ESP), call signalling for outgoing and incoming calls, and the RTP media plane (AMR-WB, AMR, G.711) wired into -PipeWire. A stock mobile dialer — Plasma Dialer, or GNOME Calls under Phosh +PipeWire, and since 1.2.0 short messages over IMS (TS 24.341: the SIP MESSAGE +carrying an RP-DATA, the Messaging interface — +§7.9). A stock mobile dialer — Plasma Dialer, or GNOME Calls under Phosh and GNOME Mobile — places and receives real VoLTE calls on a commercial network through it. @@ -44,10 +46,10 @@ PipeWire. The verified device/carrier combinations are in the README. | `interfaces/Imsd-Sms.cppm` | `imsd::sms` — the short message codecs SMS over IP rides on (TS 24.341 carries the bytes a 2G/3G phone puts in an RP-DATA, in a SIP MESSAGE body): the GSM 7-bit default alphabet with its extension table and the septet packing, UCS-2 (TS 23.038); the SM-TL PDUs (TS 23.040: SMS-SUBMIT built, one per segment with the concatenation header when the text needs more than one; SMS-DELIVER, SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed; the SMS-DELIVER-REPORT that acknowledges a delivery; the user-data header — concatenation, application ports — and the `Reassembler` of a concatenated message); the SM-RL messages (TS 24.011: RP-DATA, RP-ACK, RP-ERROR in both directions, the cause values); EF_SMSP (TS 31.102 §4.2.27), where the (U)SIM names the service centre, and qmicli's hex dump of it. Byte-level only: no SIP, no clock, no I/O. | | `interfaces/Imsd-Aka.cppm` | `imsd::aka` — USIM AKA glue: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response. | | `interfaces/Imsd-Ipsec.cppm` | `imsd::ipsec` — the two ESP SA pairs (TS 33.203) as `ip xfrm` argv lists, the Security-Server mechanism selection, and the reader that reconstructs SPIs/ports from `ip xfrm state`/`policy` text for a warm resume, and (1.0.0) `SaPeer`, the P-CSCF the kernel's pair is to, read from the `dir out` policies that carry imsd's fingerprint, `OwnXfrmDeleteCommands`, the deletes by exact key of what two rules select — the policies carrying imsd's fingerprint and the reqid-1/2 transport-mode ESP states in their direction or on the UE's ims-PDN address, whoever installed them (§12), and `FileNamesAnotherPair`, whether a state file's `spi_uc`/`spi_us` name the kernel's pair (unknown on either side decides nothing). | -| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite, which calls every builder but `BuildInviteResponse` (`tests/Engine` checks the responses `CallMachine` builds with it). Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final `OnSmsMessage` builds for the MESSAGE it is handed (the 200, the 488): each `Via:` line echoed in order (the text layer reads long header names only, not RFC 3261 7.3.3's compact forms) and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. | -| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (TS 24.341): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (the final remembered for an inbound request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first `Via:` line; nothing is remembered for a request with none or an empty one — for 32 s (`TimerJ`), for a caller to answer a retransmission with it and not handle it again). | +| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite, which calls every builder but `BuildInviteResponse` (`tests/Engine` checks the responses `CallMachine` builds with it). Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each `Via:` line echoed in order (the text layer reads long header names only, not RFC 3261 7.3.3's compact forms) and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. | +| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (TS 24.341): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first `Via:` line and a request with none or an empty one never matched — answered with the same final and not handled again); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4). | | `interfaces/Imsd-Qmi.cppm` | `imsd::qmi` — the QMI WDS request bytes `imsd-pcscf` sends (Bind Mux Data Port, Set IP Family, Get Packet Service Status, Get Current Settings, Get Profile Settings), the message/TLV parser, the P-CSCF list readers (0x22 flag, 0x23 IPv4, 0x24 FQDN, 0x2E IPv6 — the last one libqmi does not model). | -| `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control, shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. | +| `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control and messaging (`Gated`'s `Action` parameter names the action), shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. | | `implementations/main.cpp` | The `imsd` daemon shell: GLib main loop, GDBus service, sockets, subprocesses, the registration sequence and the run loop that pumps the core. | | `implementations/media.cpp` | `imsd-media`, the per-call RTP leg, DTMF included (RFC 4733 events out, queued by `dtmf ` lines on its stdin; the far end's events in, played as tones). Pure std + POSIX, dlopen's the AMR codecs. | | `implementations/pcscf.cpp` | `imsd-pcscf`, the P-CSCF reader: the AF_QIPCRTR socket, the WDS service lookup and the Bind Mux Data Port / Set IP Family / Get Current Settings sequence around `Imsd:Qmi` (plus Get Profile Settings with `--profile`, Get Packet Service Status with `-v`). std + POSIX + the Linux QRTR UAPI (``), no GLib; never Start/Stop Network. | @@ -60,7 +62,8 @@ PipeWire. The verified device/carrier combinations are in the README. Also ignored by `.gitignore`, and never to be committed: `*.raw`, `*.rtp`, `*.stats`, `imsreg.state`, `imsd-*.tar.gz` — captures and runtime state carry -the subscriber's IMSI/MSISDN and network addresses. +the subscriber's IMSI/MSISDN and network addresses — and, of SMS over IP's +state, `sms-tpmr*` (the next TP-MR). ## 3. Build products @@ -71,7 +74,7 @@ in every source but the re-exporting `Imsd.cppm`, clang + libc++ + lld. |---|---|---|---|---| | `imsd-core` | static library | the `Imsd` module and its nine partitions | — | Pure `import std` C++, no GLib, no I/O side effects: every message, digest, SA command and call-state decision is here and unit-testable on any dev box without a bus, a modem or a phone. | | `imsd` | executable | `implementations/main.cpp` | `imsd-core`, `imsd-bus`, gio-2.0, pthread | The daemon. Default product. | -| `imsd-bus` | static library | `interfaces/ImsdBus.cppm` | gio-2.0 | The polkit gate (`net.catcrafts.IMS1.Voice`) imsd and imsd-ofonod both link. A translation daemon that runs as root on the system bus reaches imsd as root, which polkit always allows, so it gates its own callers through this or it is a bypass. | +| `imsd-bus` | static library | `interfaces/ImsdBus.cppm` | gio-2.0 | The polkit gate (`net.catcrafts.IMS1.Voice`; since 1.2.0 `net.catcrafts.IMS1.Messaging` too) imsd and imsd-ofonod both link. A translation daemon that runs as root on the system bus reaches imsd as root, which polkit always allows, so it gates its own callers through this or it is a bypass. | | `imsd-media` | executable | `implementations/media.cpp` | `-ldl -lpthread` | The RTP/AMR data plane, spawned once per call. No GLib, no core. A separate process for crash isolation and for the far-end-hangup exit-code contract (§7.6). `-- --product=media`. | | `imsd-dialerd` | executable | `implementations/dialerd.cpp` | gio-2.0 | Plasma Mobile integration: a session daemon owning `org.kde.telephony.{CallUtils,DeviceUtils,UssdUtils}`, bridging to imsd. GDBus translation only. A separate process because those are per-user session-bus names a root system daemon cannot own. `-- --product=dialerd`. | | `imsd-ofonod` | executable | `implementations/ofonod.cpp` | `imsd-bus`, gio-2.0 | GNOME Calls integration: a system daemon owning `org.ofono`, presenting imsd as an oFono modem. GDBus translation plus the polkit gate on its own callers. `-- --product=ofonod`. | @@ -82,7 +85,7 @@ that every decision in it has a unit test.** New protocol logic goes into a partition with a test. The shell (`main.cpp`; from 1.0.0 also `pcscf.cpp`'s QRTR control lookup and its matching of answers by type, transaction and message id) holds protocol decisions no -test reaches — some older than 0.3.10, some added by 0.3.10, 0.3.11, 0.3.12 or 1.0.0: the P-CSCF in +test reaches — some older than 0.3.10, some added by a release since: the P-CSCF in use (`pcscf_`: the kernel's SA peer at a resume, `PCSCF=` or the first of `PCSCF_DISCOVERED=` at a fresh registration, the move between them and back — §7.2); the reg-event @@ -135,7 +138,27 @@ both sides (1.0.0) is unbenched: no capture stages a holds file whose `pdn` is spelled unlike `LOCAL`). For the schedule, a reducer next to `RegRecovery`, with a Subscription-State parser in `Imsd:Sip` pinned by `tests/Sip`, is the follow-up that moves it; a pure format/parse pair in -`Imsd:Engine` is the holds file's. +`Imsd:Engine` is the holds file's. SMS over IP (1.2.0, §7.9) keeps in the +shell, among others, the service centre's source (`SMSC=` over EF_SMSP, `LoadSmsParameters`), +the three counters (TP-MR, RP-MR, the concatenation reference), their +seeding and the TP-MR file, the routing of an inbound MESSAGE +(`DispatchRequest`: to the call when it carries the live call's Call-ID, +else through `OnInboundMessage` to `OnSmsMessage`), the one-at-a-time +queue, a `Send` failed when the engine takes it up unregistered or with +the flow down, a queued message started without that check, the +status-report book's entries (made at a message's start, and only for one +that asked for a report: `StartNextSms`), the routing of a MESSAGE +final to the message in flight (`OnSmsResponse` — ahead of the reg-event +subscription's handler in the run loop, after it inside `AwaitFinal`), the +judgement of the final's wait and of the report's after the server ports' drain, the reassembler's +30-minute age-out in the run loop, the retransmission check around +`OnSmsMessage`, the delivery reports' finals (`reportCallIds_`), a send +failure attributed by Call-ID, and the forwarding of a status report's +word to the bus — the transactions themselves are `SmsOutbound` and +`OnSmsMessage` (a submit report's routing to the message in flight, by +In-Reply-To, else RP-MR, is theirs), and the report's match to the message +that asked for one `SameRecipient` +and `StatusReportBook`, all with tests. ## 4. Building @@ -341,12 +364,30 @@ What the suites pin: ended; ours once its segment was superseded), 200 for one without In-Reply-To for no message, an unusable TPDU acknowledged with an RP-ERROR, a body that is no RP message, a page-mode text 200'd and - logged; + logged, a short message while SMS over IP is off refused with 480; a submit report before the MESSAGE's own final taken — the message sent and the late final nobody's; with two segments the second goes out under its own Call-ID — a text past 255 segments failed at once naming the fit, a delivery with no gateway for its report handed over with the absence logged; + `StatusReportBook` and `SameRecipient`: a two-segment message delivered + with its last segment, a delivered TP-MR forgotten, another recipient no + match, a temporary status pending with the entry kept, a permanent + failure the message's last word (a later segment finds nothing), a + reused TP-MR forgetting the older message whole, a message forgotten + whole by its id (`ForgetMessage`) with the other left on record; a number dialled + with a trunk 0, with `00` or — a US number — without its country code + matched against its international form; another number, `+31612345678` + against `+49612345678`, a short code against a longer number that ends in + it and an empty one not; + `SmsWordOrder`: a report on a message whose submission ended posted at + once, one on the message in flight held and posted after `sent`, a + `failed` after a held `delivered` posted as `sent` then `delivered`, any + other `failed` posted alone with the message to forget, another + message's submission leaving the held word alone; the ids (`RunToken`, + `SentSmsId`, `ReceivedSmsId`): eight zero-padded hex digits, the sent + and the received shape, two tokens' ids apart at the same second and + counter; and `RecentTransactions`: a retransmitted request gets its final again, for 32 s (`TimerJ`); no branch, no match. @@ -535,6 +576,84 @@ Rules: clock stands), and an answer that renumbers telephone-event or gives the audio our number (`DTMF_RX_PT` — KPN echoes our numbers; pinned in `tests/Engine` and by the loopback's collision arm). +- SMS over IP (§7.9) ran on the dev phone on KPN on 2026-10-17 (the fp6 + journal's `2026-10-17-sms-over-ip-bench` capture; §13 has the network + facts): the EF_SMSP read at bring-up and the + `+g.3gpp.smsip` tag on a resumed and on a fresh registration (echoed in + the reg-event reginfo); three `Send`s over `busctl` (one segment each: + MESSAGE → 202, the submit report → `sent`; the dump of the 00:53 one shows + a GSM 7-bit RP-DATA, its report's In-Reply-To naming our Call-ID); five + texts received at 01:17 (one segment each, GSM 7-bit: + parsed, the RP-ACK delivery report sent and answered 202); a sixth + (SC time stamp 01:23:10, logged at 01:23:12) that arrived twice within a second + (`journal-0123-duplicate`; the dump that survives, + `mt-0123-duplicate-message-in`, came over UDP from the P-CSCF) and was + handled twice, two delivery reports, one of them refused 488, which is where the retransmission + absorption (`RecentTransactions`) came from; a + 240-character text (01:33) sent as two segments (consecutive + RP-MR/TP-MR, both 202 + RP-ACK) and received back (01:40) as two + segments (set 174, 159 + 102 bytes) reassembled (SC time stamp 01:40:26, the whole logged at 01:40:28: 240 bytes of + text in 2 segments, `journal-0133-mo-benches-and-0140-mt-concat`); a UCS-2 + text with ü and ß, ❤, an emoji (surrogate pair) and Ω sent + (35 units, TP-UDL 70) and received back decoded (DCS 08) — its trailing + ✓ missing in the copy that came back (34 of its 35 units: the text sent, + `r22-sent-texts-2026-10-17-from-the-session-transcript`, against the + MESSAGE dump `mt-0140-last-segment-message-in`; origin open); sent on its + own, a one-character UCS-2 text arrived at 01:44 (3 bytes of text, + `journal-0144-checkmark-and-absorbed-retransmission`); that one-character text's MESSAGE + retransmitted (01:44:24) and absorbed: answered again, not handled again + — one delivery report, 202; a text from the alphanumeric + sender AUTHMSG at 01:47 (55 bytes, its report answered 202; the day's every + arrival and report: `r24-phone-journal-authmsg-status-reports-2306`); and a + text at 23:08 under a build whose 200, by the capture's heading, echoes + every Via and carries a To tag (`mt-2308-new-final-shape`): the + same-second retransmission was answered again and absorbed, the delivery + report answered 202. No capture of the benches on + hardware holds a journal line of one of these arms (each arm's line is searched in them in the + fp6 journal's `2026-11-19-imsd-1.2.0-r32-cut` capture, `searches/arms.out`): a refused final to a submission's MESSAGE, an RP-ERROR this + code sends (the cause-96 unusable-TPDU path; an RP-ERROR that came in was + reached: `smsc-override-2026-10-18-0217`, 02:19:41, RP cause 28 + TP-FCS + 0xc1, through `OnReport`), the final's wait and the report's + running out, a dead flow under a `Send`, a status report (one requested + at 01:33 with TP-SRR; none came in the following 11 minutes — the + unfiltered journal of 01:33:30–01:45:00, + `r23-phone-journal-2026-10-17-precise-and-modem-sms`; whether KPN's SC + sends them over this path is unknown), 8-bit data (an MMS + notification), a message while SMS over IP is off (the 480), a submit + report In-Reply-To no MESSAGE of ours in flight (the 488) or one without + In-Reply-To for no message in flight (the 200), a page-mode MESSAGE, a + body that is no RP message, a delivery that names no gateway, a text + past 255 segments, an EF_SMSP + record 1 that cannot be read or holds no service centre, or one whose + service centre is not an international number, a + delivery report the flow could not + send, a concatenated set aged out after its 30 min, a bus object or + interface that does not register (§7.8). Not searched for, as they write no journal line of their own: a submit report without + In-Reply-To taken by its RP-MR (the one dumped carries In-Reply-To) or one whose In-Reply-To + lists ours among several Call-IDs, a delivered MESSAGE whose + Call-ID holds an ASCII control character or a space, or whose P-Asserted-Identity lists several + identities in one row or begins with a quoted display name, a MESSAGE final arriving inside a REGISTER wait + (`AwaitFinal` → `OnSmsResponse`), a queued message started inside a REGISTER wait, a MESSAGE + inside a call's dialog, a stop with a message queued or in flight. The reducers for the arms of both sentences but the shell + paths — the final's routing inside `AwaitFinal`, the delivery report the + flow could not send, `LoadSmsParameters`' refusals, the MESSAGE + inside a call's dialog, the queue's two + and the bus object's registration — are pinned in + `tests/Engine` — but for EF_SMSP's parser and the reassembler's age-out (`Purge`, given an age), which `tests/Sms` pins, and `HeaderUri`'s reading of a header's value, which `tests/Sip` pins; the Messaging + interface's `Send`, `GetStatus`, `Subscribe` and `StateChanged` ran on + the host's session bus in dev mode (2026-10-16: two `Send`s answered + with ids and failed `imsd is not registered`; 2026-10-17: three + connections — a subscriber, a match-rule-only listener, an unsubscribed + sender — where only the subscriber and the sender heard the + `StateChanged`; 2026-11-19, on a private session bus with the setting + off: `enabled` false, `Send` refused with `NotSupported`, `Subscribe` + answered). + Reached from 2026-10-18 02:17 (`smsc-override-2026-10-18-0217`): the + `SMSC=` override — `SMSC=+31653131313` gives `service centre +31653131313 + (SMSC=)` and a `Send` through it reaches `sent`; `SMSC=abc` gives + `SMSC='abc' is not a number` (`ForNumber` dials digits, `*` and `#` only; + the bench's first run, on a build outside this history that dialled a, b + and c, submitted with them and got an RP-ERROR back, RP cause 28). - `imsd-pcscf` ran on the dev phone (KPN) on 2026-10-11 against the live ims bearer: the `--mux 1 --profile 2 -v` sequence, a plain run, and `OutOfCall` on an unbound mux (the fp6 journal's `2026-10-11-pcscf-pco-probe` capture, @@ -609,10 +728,14 @@ Beyond the rules: `/net/catcrafts/IMS1`, interface `net.catcrafts.IMS1`; the frozen ABI, §8). The bus policy `packaging/net.catcrafts.IMS1.conf` lets any local account reach it; placing, answering and ending a call is polkit's -`net.catcrafts.IMS1.Voice` (`packaging/net.catcrafts.IMS1.policy`, shaped like +`net.catcrafts.IMS1.Voice`, sending a short message over IP and subscribing +to the message signals `net.catcrafts.IMS1.Messaging` +(`packaging/net.catcrafts.IMS1.policy`, both +shaped like ModemManager's Voice action: the active local session and root — not an ssh login, an inactive session or a system service account). Reads (`GetStatus`, -`GetCalls`) stay open, as ModemManager's are to every local account: the call +`GetCalls`, the Messaging interface's `GetStatus`) stay open, as +ModemManager's are to every local account: the call signals reach them all anyway, the status (the address, the P-CSCF, the phone number) travels in no signal. @@ -621,7 +744,8 @@ receive on the protected client flow, the protected-port listeners for terminating requests, media reaping, the keepalive refresh); the GLib main loop owns the bus. D-Bus method calls push commands to the engine queue; engine events reach the bus through `g_idle_add`, where the calls table and -the status snapshot live (main thread only). +the status snapshot live (main thread only). The Messaging interface's +`Subscribe` keeps its subscriber set on the main thread as well (§7.9). Per answered call imsd forks `imsd-media` (`IMSD_MEDIA`, default next to the `imsd` binary, else `/usr/libexec/imsd-media`) with the addresses, ports and @@ -690,7 +814,9 @@ The daemon's own bring-up (`BringUp()` in `main.cpp`): 2. `qmicli -d qrtr://0 --uim-get-card-status` finds the ready USIM (slot, AID); `mmcli -m any` gives the primary SIM path and the IMEI (for the `+sip.instance` URN); `mmcli -i ` gives IMSI and MCC/MNC, from which - the IMPI/IMPU/realm are derived. `mmcli --location-get` fills + the IMPI/IMPU/realm are derived; with SMS over IP on and `SMSC=` unset, + `qmicli --uim-read-record` of EF_SMSP record 1 names the service centre + (§7.9). `mmcli --location-get` fills `P-Access-Network-Info`. 3. **Warm resume** when an SA pair is already in the kernel and the state file (`STATE_FILE`, default `/var/lib/imsd/imsreg.state`) describes the @@ -1020,8 +1146,10 @@ When nothing is held the file is removed — when it is a regular file; `/dev/null` switches the knob off and anything that is not a regular file is emptied, never unlinked. The recovery policy's waits and the holds are measured on the boot clock (`CLOCK_BOOTTIME`), so a suspend counts; the -keepalive refresh gate, the CRLF keepalive and the reg-event retry and -renewal timers run on the steady clock and count awake seconds only. +keepalive refresh gate, the CRLF keepalive, the reg-event retry and +renewal timers and the times SMS over IP measures (§7.9: its two waits, +the 30-minute age-out, the retransmission table's 32 s) run on the steady +clock and count awake seconds only. The **reg-event subscription** (RFC 3680; the network's own view of the binding) is one live dialog per registration, subscribed anew ahead of the @@ -1230,6 +1358,7 @@ account `user`, its old default. | `/run/imsd-ofonod.started` | `imsd-ofono-restart-calls.sh` | marker: imsd-ofonod has started once since boot | | `/var/lib/imsd/imsreg.state` (`STATE_FILE`) | imsd | the registration context for a warm resume | | `/var/lib/imsd/*.stats`, `*.rtp`, `*.raw` | imsd, imsd-media | per-call media stats, raw RTP (`RTP_DUMP`), SIP dumps (`DUMP_SIP`; mode 0600 — they carry the IMSI/MSISDN) | +| `/var/lib/imsd/sms-tpmr` | imsd | the next TP-MR, one decimal number, written when a message's segments take their TP-MRs (§7.9) | | `$XDG_STATE_HOME/imsd/` (else `~/.local/state/imsd/`), `$XDG_RUNTIME_DIR/imsd.holds` (else `/tmp/imsd.holds`) | imsd | the same files for a non-root (`--session`) run | ### 7.8 Journal vocabulary @@ -1326,7 +1455,62 @@ Lines the operator (and the scripts) look for, all prefixed `imsd: `: Security-Verify rebuilt from the SA as one mechanism` at every resume. - `connect: no answer from the P-CSCF N times (…)` when the protected connect series ends unanswered. +- SMS over IP (§7.9): `SMS over IP: off (SMS_OVER_IMS=1 enables it)` at + start, or at bring-up `sms: service centre +… (EF_SMSP[ 'alpha'])[, + validity period 0xnn]` / `sms: service centre +… (SMSC=)` / `sms: no + service centre: EF_SMSP record 1 unreadable or without one; …` / `sms: + SMSC='…' is not a number; …` / `sms: SMSC='…' is not an international + number (+ and digits); …` / `sms: EF_SMSP's service centre '…' is not an + international number (+ and digits); …` and `SMS over IP: on (+g.3gpp.smsip + advertised: …)`; per message of ours `sms : segment i/n to + via : MESSAGE sent (RP-MR a, TP-MR b, N bytes)`, `sms : segment + i/n -> ; awaiting the submit report`, then `sms : sent: …` or + `sms : failed: …` (the reason: `'…' is not a number`, `no service + centre …`, `the text does not fit 255 segments`, `imsd is not registered`, `the flow to the P-CSCF is down`, + `segment i/n refused: `, `segment i/n refused + by the SC: RP cause N (…)[, TP-FCS 0xNN (…)]`, `no answer to the MESSAGE + of segment i/n within 32 s`, `no submit report for segment i/n within + 40 s of the final`, `segment i/n not sent: the flow to the P-CSCF is + down`) and, after a status report, `sms : delivered|delivery-pending| + delivery-failed: ` or `sms : a segment delivered + (TP-MR n); k still to be reported`, and for a report's word on the + message still in flight `sms : delivered|delivery-pending| + delivery-failed: — held until the submission ends`; per delivery `short message from + via at