imsd/tests/Engine/main.cpp

2250 lines
171 KiB
C++
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
// Imsd:Engine unit tests — the call state machine driven through recorded
// network dialogs. Outgoing: reliable-18x PRACK, 2xx ACK + media start,
// media-plane far-end hangup, local hang-up (CANCEL before answer, BYE
// after), the CANCEL/answer race, and busy/error finals. Incoming: 100+180
// on the INVITE (reliable when the caller requires 100rel), Accept -> 200
// with the SDP answer at the offer's payload types + media, ACK silence,
// reject -> 486, remote CANCEL -> 200+487, unusable offer -> 488 (naming
// what was offered), a landline gateway's G.711-only and AMR-NB offers
// ring and are answered at the offer's own payload types, ring timeout ->
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
// 480, BYE both ways; an incoming call from an INVITE, and an outgoing
// call from responses, whose header names come in compact form (RFC 3261
// 7.3.3). DTMF: the tones reach the media leg on an active
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
// call that negotiated telephone-event, and are dropped — with the reason
// — before the answer, after the call, without the negotiation or with a
// character that is no tone. Then RegRecovery, the registration recovery policy:
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
// the refusal and silence thresholds, local refusals, the reconnect and
// fresh backoffs, the throttle schedule, Retry-After, which waits a Dial
engine: keep the reg-event subscription alive and act on a terminated binding The reg-event subscription is the network's own account of our binding (TS 24.229 5.1.1.3), and the daemon opened a new dialog for it at every refresh and reconnect and otherwise never looked back: a refused SUBSCRIBE was forgotten, an unanswered one had no timeout, an ended subscription got nothing until the next refresh's new dialog, and a NOTIFY was logged whatever it said. O2 UK, 2026-09-24: a fresh registration's SUBSCRIBE got 500, a NOTIFY arrived all the same and showed our contact active, the flow died eight seconds after the 200 and no connect over the SA succeeded after that; the 500 was logged and nothing was done about it. Keep the subscription alive: retry a refused or unanswered SUBSCRIBE on a backoff, renew one the S-CSCF ends with deactivated, timeout, giveup or probation (RFC 6665 4.1.3; after any other reason, or none, the next refresh subscribes anew), and subscribe anew ahead of the lifetime the S-CSCF granted. A refresh or a reconnect opens no dialog while imsd holds one for the registration or has a retry scheduled. Read the reginfo for our own contact and act on its state: a NOTIFY that terminates our binding schedules a fresh registration — at once for deactivated or expired, after the network's retry-after (up to an hour) for probation, on imsd's own refusal schedule (21 min, growing to 60) for rejected or unregistered (RFC 3680). A hold already running stands, and a REGISTER wait a call kept open that still gets its 200 after such a NOTIFY leaves that registration standing. The parser is in Imsd:Sip and pinned by tests/Sip with the O2 document shapes; the policy is RegRecovery's (OnBindingTerminated, added here with its tests in tests/Engine). Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-10-03 19:36:23 +02:00
// may cut short, when the old registration counts as gone, the holds a
// restart takes over (Holds/Restore), and a binding the network terminated
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
// (OnBindingTerminated). Then SMS over IP: the status-report book
// (StatusReportBook with SameRecipient — a word for the whole message: a two-segment
// message delivered with its last segment, a permanent failure the last
// word, pending kept, another recipient no match, a reused TP-MR, a
// message forgotten whole by its id), the order of one message's words
// (SmsWordOrder: the submission's first, a report's after sent) and the
// ids (RunToken, SentSmsId, ReceivedSmsId);
// SmsOutbound through a
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// submission (the MESSAGE with the RP-DATA, its 202, the RP-ACK -> sent; a
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
// refused final, an RP-ERROR with its cause, the segment's one repeat with
// TP-RD set — after the final's wait or the report's ran out, a 408 or a
// 504 final, an RP-ERROR with cause 41 or an unlisted one — taken,
// rejected as a duplicate (after a first attempt that was refused, and
// after one that was not), ended in its turn, the first attempt's report
// after it, a
// failed send, two segments with consecutive RP-MR/TP-MR, a
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// destination that is no number, no service centre, a submit report before
// the MESSAGE's own final, a text past 255 segments) and OnSmsMessage (a
// delivery with no gateway for its report, a
// delivered message to the bus and its RP-ACK to the IP-SM-GW with
// In-Reply-To, a concatenated pair whole once, a status report, a submit
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
// report routed to the message in flight, 200 for one of ours no longer in
// flight (RecentSubmissions), 488 for one that is not ours, an
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// unusable TPDU acknowledged with an RP-ERROR, a body that is no RP
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
// message, a page-mode text 200'd and logged, a short message while SMS
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
// over IP is off refused with 480, a delivered MESSAGE and a final whose
sip: a received message's header section is unfolded where it is framed RFC 3261 7.3.1 lets a header value go on over further lines, each begun with a space or a tab: "The line break and the whitespace at the beginning of the next line are treated as a single SP character." The text layer read a header from one line, so of a folded value it had the first line only. Networks fold: KPN's 401 to the unprotected REGISTER of 2026-07-18 and Odido's of 2026-07-13 had the WWW-Authenticate over four lines (AGENTS.md §13; imsd finds a 401's nonce by a search of the whole message, on a continuation line as on any other). A Security-Server folded the same way would be read by its first line alone, without the SPIs and ports on the further lines, and the bring-up deferred; a short message whose Content-Type stands on a continuation line would be taken for a page-mode text, answered 200 and never shown; a folded Content-Length on a connection would frame no body, and the body's bytes begin the next message. Unfolded takes the folds out of a header section, and the two framers — FrameBuffer::TryExtract for a stream, DatagramMessage for a datagram — hand a message on with its header section unfolded and its body as it came; the Content-Length that frames the body is read from the unfolded section. CutShortRequest reads its Content-Length so too, and the header section it gives for the 400 is unfolded. Every socket imsd reads SIP from goes through one of the two framers, so each reader of a header still reads one line. A DUMP_SIP dump of a received message holds it as framed. Jorijn's decision of 2026-11-21 ("Unfold now"). Tested by tests/Sip — Unfolded on 7.3.1's own example, a tab, a bare LF, a value begun on the next line and a line break that nothing follows; both framers on a 401 whose WWW-Authenticate goes over four lines and whose Content-Length is folded; CutShortRequest on a request cut short of a folded Content-Length; ViaResponsePort on a Via list folded after its comma, through the datagram framer — and by tests/Engine, a delivered MESSAGE whose Content-Type came folded. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, init-port, server-ports and cut-short, at this commit and at the one before): a stand-in's 401 with its Security-Server over three lines gives the whole value, where the commit before deferred the bring-up for want of SPIs; a request with its Content-Type and Content-Length on continuation lines comes out of the server ports unfolded and framed by that length, as a datagram and over a connection; a request cut short of a folded Content-Length, its Via on a continuation line, is answered 400 with its Via whole, on a server port and on the client flow, where the commit before did not read the folded length and handed the request on as it came; a request on a server port whose Via row is a list folded after its comma, `rport` on its lower value, is answered from the client-port socket, the way to the port its top value names, as at the commit before. On the dev phone the binary of this range's last commit registered fresh on KPN after a reboot; the 401 was not dumped, so whether it came folded that time is not on record. A MESSAGE the phone sent to its own protected server port, its Via row a list folded after its comma with `rport` on the lower value, was answered from the client-port socket (the capture's phone-form6, fresh-check.log and inject-bench.log).
2026-11-22 17:35:12 +01:00
// header names come in compact form, a delivered MESSAGE whose
sms, engine: a class 2 message is refused, not acknowledged, unless it is a short message type 0 OnSmsMessage acknowledged every SMS-DELIVER it could parse with an RP-ACK and handed it to the bus, whatever its class. For a class 2 message the acknowledgement said more than was done: TS 23.038 4 has the MS "ensure that the message has been transferred to the SMS data field in the (U)SIM before sending an acknowledgement to the SC", and TS 23.040 9.2.3.9 has a (U)SIM data download — TP-PID 0x7F with a class 2 coding — passed to the (U)SIM. imsd writes nothing to the card, so the network had an acknowledgement for something that had not happened (issue #4). imsd has no way to the card for such a message yet. TS 23.038 4 names the answer of an MS that cannot store a class 2 message in the (U)SIM while other storage is free, "protocol error, unspecified", and excepts only a download on an MS that supports the (U)SIM Application Toolkit, which imsd does not. The delivery report of a class 2 message, a segment of a set included, is now an RP-ERROR with that cause, 111, and the TP-FCS 0xFF, unspecified error cause; the message is neither stored nor handed to the bus, and the journal has its sender, service centre and time. A short message type 0 (TP-PID 0x40) with a class 2 coding is no part of this: 9.2.3.9 has it received "irrespective of whether there is memory available in the (U)SIM or ME or not". TP-PID 0x7F without a class 2 coding stays a message like any other, and so do classes 0, 1 and 3. What this changes for a consumer: no `Received` comes for a refused class 2 message, a text of that class among them, which 1.2.0 stored and handed over (Jorijn, 2026-11-21: the refusal is kept). The interface's members, keys and words are as they were. Still open of issue #4: the way to the card itself — TS 31.111 7.1.1's ENVELOPE (SMS-PP DOWNLOAD) for a download, an EF_SMS record for any other class 2 message — and with it an acknowledgement made from the card's answer. Read from the dev phone for it (the fp6 journal's 2026-11-20-issues-2-5 capture, phone): the KPN USIM's service table lists 28 (data download via SMS-PP) and 10 (short message storage), EF_SMS holds ten records of 176 bytes, the modem's route table has a class 2 message it receives itself stored on the card, and qmicli has the APDU route AKA takes and no toolkit command. Whether the modem lets an ENVELOPE through that route has not been tried. Tested by tests/Engine. On the dev phone the daemon, the binary of this range's last commit, refused five class 2 deliveries that the phone sent to its own protected server port — answered 200, the journal's line, nothing stored, and no report, since they named no gateway — and took six deliveries from KPN as before (the capture's phone-form6).
2026-11-22 17:35:13 +01:00
// Content-Type came folded, a class 2 message refused with an
// RP-ERROR and kept from the bus), and the store's record codec
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
// (FormatStoredSms/ParseStoredSms: a full record round trip, defaults
// for absent keys, a value that does not parse or a missing id refused) and order
// (StoredSmsBefore: the arrival second, then within a run the sequence
// number), and RecentTransactions (a retransmitted request gets its final
// again, for 32 s; no branch, no match). Pure reducers, no I/O.
import std;
import Imsd;
using namespace imsd::engine;
using imsd::msg::Context;
namespace {
int Failures = 0;
void Check(bool cond, std::string_view msg) {
if (!cond) {
std::println(std::cerr, "FAIL: {}", msg);
++Failures;
}
}
Context MakeCtx() {
Context c;
c.id = imsd::aka::MakeIdentity("001010123456789", "001", "01");
c.local = "2001:db8::db43";
c.route = "<sip:[2001:db8::105]:6000;lr>";
c.ppi = "tel:+31611111111";
c.securityServer = "ipsec-3gpp; spi-c=1; spi-s=2; port-c=3; port-s=4";
return c;
}
bool Has(const std::vector<Action>& a, Action::Type t) {
for (const auto& x : a) if (x.type == t) return true;
return false;
}
const Action* Find(const std::vector<Action>& a, Action::Type t) {
for (const auto& x : a) if (x.type == t) return &x;
return nullptr;
}
// First SendClient whose text starts with `method `.
const Action* Sent(const std::vector<Action>& a, std::string_view method) {
for (const auto& x : a)
if (x.type == Action::Type::SendClient && x.text.starts_with(method)) return &x;
return nullptr;
}
// Build a response with the machine's own Call-ID (so dialog matching in a
// real shell would hold; the reducer itself doesn't re-check).
std::string R183(std::string_view callid) {
return std::format(
"SIP/2.0 183 Session Progress\r\n"
"Via: SIP/2.0/TCP [2001:db8::db43]:45061;branch=z9hG4bKx\r\n"
"From: <sip:001010123456789@ims.mnc001.mcc001.3gppnetwork.org>;tag=it\r\n"
"To: <sip:1233@ims>;tag=remote7\r\n"
"Call-ID: {}\r\n"
"CSeq: 1 INVITE\r\n"
"Record-Route: <sip:[2001:db8::105]:6000;lr>\r\n"
"Require: 100rel\r\n"
"RSeq: 1\r\n"
"Contact: <sip:termgw@[2001:db8::9]:5060>\r\n"
"Content-Type: application/sdp\r\n"
"Content-Length: 120\r\n\r\n"
"v=0\r\no=- 1 1 IN IP6 2001:db8::9\r\ns=-\r\nc=IN IP6 2001:db8::9\r\n"
"t=0 0\r\nm=audio 6004 RTP/AVP 97\r\na=rtpmap:97 AMR-WB/16000/1\r\n", callid);
}
std::string R200(std::string_view callid) {
return std::format(
"SIP/2.0 200 OK\r\n"
"Via: SIP/2.0/TCP [2001:db8::db43]:45061;branch=z9hG4bKx\r\n"
"From: <sip:001010123456789@ims.mnc001.mcc001.3gppnetwork.org>;tag=it\r\n"
"To: <sip:1233@ims>;tag=remote7\r\n"
"Call-ID: {}\r\n"
"CSeq: 1 INVITE\r\n"
"Contact: <sip:termgw@[2001:db8::9]:5060>\r\n"
"Content-Type: application/sdp\r\n"
"Content-Length: 120\r\n\r\n"
"v=0\r\no=- 1 1 IN IP6 2001:db8::9\r\ns=-\r\nc=IN IP6 2001:db8::9\r\n"
"t=0 0\r\nm=audio 6004 RTP/AVP 97\r\na=rtpmap:97 AMR-WB/16000/1\r\n", callid);
}
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
// A 200 OK around an arbitrary SDP answer, Content-Length from it — a
// message the shell's framing would deliver whole.
std::string R200Sdp(std::string_view callid, std::string_view sdp) {
return std::format(
"SIP/2.0 200 OK\r\n"
"Via: SIP/2.0/TCP [2001:db8::db43]:45061;branch=z9hG4bKx\r\n"
"From: <sip:001010123456789@ims.mnc001.mcc001.3gppnetwork.org>;tag=it\r\n"
"To: <sip:1233@ims>;tag=remote7\r\n"
"Call-ID: {}\r\n"
"CSeq: 1 INVITE\r\n"
"Contact: <sip:termgw@[2001:db8::9]:5060>\r\n"
"Content-Type: application/sdp\r\n"
"Content-Length: {}\r\n\r\n{}", callid, sdp.size(), sdp);
}
constexpr std::string_view SdpHead = "v=0\r\no=- 1 1 IN IP6 2001:db8::9\r\ns=-\r\nc=IN IP6 2001:db8::9\r\nt=0 0\r\n";
std::string Final(std::string_view callid, int code, std::string_view text) {
return std::format(
"SIP/2.0 {} {}\r\n"
"Via: SIP/2.0/TCP [2001:db8::db43]:45061;branch=z9hG4bKx\r\n"
"From: <sip:001010123456789@ims.mnc001.mcc001.3gppnetwork.org>;tag=it\r\n"
"To: <sip:1233@ims>;tag=remote7\r\n"
"Call-ID: {}\r\nCSeq: 1 INVITE\r\nContent-Length: 0\r\n\r\n",
code, text, callid);
}
// First SendResponse whose text starts with `prefix`.
const Action* Responded(const std::vector<Action>& a, std::string_view prefix) {
for (const auto& x : a)
if (x.type == Action::Type::SendResponse && x.text.starts_with(prefix)) return &x;
return nullptr;
}
// A 380 Alternative Service final; `body` empty = no emergency
// indication (a bare redirect).
std::string Alt380(std::string_view callid, std::string_view body) {
return std::format(
"SIP/2.0 380 Alternative Service\r\n"
"Via: SIP/2.0/TCP [2001:db8::db43]:45061;branch=z9hG4bKx\r\n"
"From: <sip:001010123456789@ims.mnc001.mcc001.3gppnetwork.org>;tag=it\r\n"
"To: <sip:1233@ims>;tag=remote7\r\n"
"Call-ID: {}\r\nCSeq: 1 INVITE\r\n"
"Content-Type: application/3gpp-ims+xml\r\n"
"Content-Length: {}\r\n\r\n{}",
callid, body.size(), body);
}
constexpr std::string_view EmergencyXml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ims-3gpp version=\"1\"><alternative-service><type><emergency/></type>"
"<reason>emergency call detected</reason></alternative-service></ims-3gpp>";
// An inbound (terminating) INVITE the way KPN's P-CSCF delivers one:
// two Vias, a Record-Route pair, P-Asserted-Identity, an AMR-WB offer
// at non-default payload types (104/105) with telephone-event.
std::string MtInvite(std::string_view extraHeaders = "") {
std::string sdp =
"v=0\r\no=- 55 55 IN IP6 2001:db8::30c\r\ns=-\r\n"
"c=IN IP6 2001:db8::30c\r\nt=0 0\r\n"
"m=audio 27864 RTP/AVP 104 105\r\n"
"a=rtpmap:104 AMR-WB/16000/1\r\n"
"a=fmtp:104 octet-align=1;mode-change-capability=2\r\n"
"a=rtpmap:105 telephone-event/16000\r\n"
"a=fmtp:105 0-15\r\n"
"a=ptime:20\r\na=sendrecv\r\n";
return std::format(
"INVITE sip:001010123456789@[2001:db8::db43]:45061 SIP/2.0\r\n"
"Via: SIP/2.0/UDP [2001:db8::105]:5100;branch=z9hG4bKpcscf1\r\n"
"Via: SIP/2.0/UDP [2001:db8::9]:5060;branch=z9hG4bKscscf1\r\n"
"Record-Route: <sip:[2001:db8::105]:5100;lr>\r\n"
"Record-Route: <sip:[2001:db8::9]:5060;lr>\r\n"
"Max-Forwards: 68\r\n"
"From: <sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org;user=phone>\r\n"
"Call-ID: mt-call-abc123\r\n"
"CSeq: 1 INVITE\r\n"
"Contact: <sip:origgw@[2001:db8::9]:5060>\r\n"
"P-Asserted-Identity: <tel:+31612345678>\r\n"
"Session-Expires: 1800\r\n"
"{}"
"Content-Type: application/sdp\r\n"
"Content-Length: {}\r\n\r\n{}",
extraHeaders, sdp.size(), sdp);
}
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
// The same message with the header names that have a compact form
// written in it (RFC 3261 7.3.3: Via, From, To, Call-ID, Contact,
// Content-Type, Content-Length, Supported; Event, Session-Expires) —
// in the header section only, the start line and the body as they are.
std::string Compact(std::string_view msg) {
const std::size_t end = msg.find("\r\n\r\n");
std::string head(msg.substr(0, end));
for (auto [name, letter] : std::initializer_list<std::pair<std::string_view, std::string_view>>{
{"\r\nVia:", "\r\nv:"}, {"\r\nFrom:", "\r\nf:"}, {"\r\nTo:", "\r\nt:"}, {"\r\nCall-ID:", "\r\ni:"}, {"\r\nContact:", "\r\nm:"},
{"\r\nContent-Type:", "\r\nc:"}, {"\r\nContent-Length:", "\r\nl:"}, {"\r\nSupported:", "\r\nk:"}, {"\r\nEvent:", "\r\no:"}, {"\r\nSession-Expires:", "\r\nx:"}})
for (std::size_t at = 0; (at = head.find(name, at)) != std::string::npos; at += letter.size()) head.replace(at, name.size(), letter);
return end == std::string_view::npos ? head : head + std::string(msg.substr(end));
}
}
int main() {
Context c = MakeCtx();
// ---- full answered call: INVITE -> 100 -> 183(rel)+PRACK -> 200 -> ACK
// + media -> far-end hangup
{
imsd::util::Rng rng(42);
CallMachine m(c, rng, "ims-call-1", "1233", 50004, false);
auto start = m.Start();
Check(Sent(start, "INVITE ") != nullptr, "Start sends INVITE");
2026-09-08 20:37:47 +02:00
Check(Sent(start, "INVITE ")->text.contains("\r\nFrom: <tel:+31611111111>;tag="), "MO INVITE From is our public (tel:) identity, not the IMSI IMPU");
Check(!Sent(start, "INVITE ")->text.contains("From: <sip:001010123456789@"), "MO INVITE From never the temporary IMPU once an identity is known");
Check(Has(start, Action::Type::SetDeadline), "Start arms ring timeout");
Check(m.State() == CallState::Dialing, "starts dialing");
// 100 Trying: nothing changes
auto a100 = m.OnInviteResponse(Final(m.CallId(), 100, "Trying"));
Check(a100.empty(), "100 Trying is a no-op");
Check(m.State() == CallState::Dialing, "still dialing after 100");
// 183 with reliable 100rel + SDP: -> ringing, PRACK
auto a183 = m.OnInviteResponse(R183(m.CallId()));
Check(m.State() == CallState::Ringing, "183 -> ringing");
const Action* stAct = Find(a183, Action::Type::State);
Check(stAct && stAct->state == "ringing" && stAct->reason == "outgoing", "183 emits ringing/outgoing");
const Action* prack = Sent(a183, "PRACK ");
Check(prack != nullptr, "reliable 183 triggers PRACK");
Check(prack && prack->text.contains("RAck: 1 1 INVITE\r\n"), "PRACK RAck");
Check(prack && prack->text.contains("CSeq: 2 PRACK\r\n"), "PRACK CSeq 2");
// PRACK targets the remote Contact and routes via the Record-Route
Check(prack && prack->text.starts_with("PRACK sip:termgw@[2001:db8::9]:5060 SIP/2.0"), "PRACK targets remote Contact");
Check(prack && prack->text.contains("Route: <sip:[2001:db8::105]:6000;lr>\r\n"), "PRACK routes via reversed Record-Route");
// a second identical 183 must NOT re-PRACK the same RSeq
auto a183b = m.OnInviteResponse(R183(m.CallId()));
Check(Sent(a183b, "PRACK ") == nullptr, "duplicate RSeq not re-PRACKed");
// 200 OK: ACK + StartMedia + active
auto a200 = m.OnInviteResponse(R200(m.CallId()));
const Action* ack = Sent(a200, "ACK ");
Check(ack != nullptr, "200 -> ACK");
Check(ack && ack->text.starts_with("ACK sip:termgw@[2001:db8::9]:5060 SIP/2.0"), "ACK targets remote Contact");
Check(ack && ack->text.contains("To: <sip:1233@ims>;tag=remote7\r\n"), "ACK carries dialog To tag");
const Action* media = Find(a200, Action::Type::StartMedia);
Check(media != nullptr, "200 starts media");
Check(media && media->media.Valid(), "media leg valid");
Check(media && media->media.remoteIp == "2001:db8::9", "media remote ip");
Check(media && media->media.remotePort == 6004, "media remote port");
Check(media && media->media.payloadType == 97, "media pt");
Check(media && media->media.codec == "AMR-WB", "media codec");
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
Check(media && !media->media.dtmfPt, "an answer without telephone-event: the leg has no DTMF pt");
const Action* active = Find(a200, Action::Type::State);
Check(active && active->state == "active" && active->reason == "accepted", "200 emits active/accepted");
Check(m.State() == CallState::Active, "state active");
sip: UDP for the protected leg, TCP first with a fallback imsd's protected leg (the second REGISTER and everything after it) was TCP only. A P-CSCF that never answers the TCP connect on its protected server port (O2 UK: the SYNs leave ESP-protected, nothing comes back) left the unit looping with no way forward, although the SAs, the listener sockets and the firewall rule already covered UDP. The client flow now carries a transport. UDP binds the same protected client port and connect()s the datagram socket to the P-CSCF's protected server port, so the kernel delivers that peer's datagrams to it ahead of the unconnected listener on the same port. One datagram is one message (RFC 3261 18.3: a Content-Length that fits truncates, one that does not fit discards the datagram, none means the rest of the datagram); a receive error is logged and marks the flow dead; a message over the single-packet ESP budget at the ims PDN's MTU is logged once per flow, since the kernel fragments it and a P-CSCF may drop the fragments. Every protected request's Via follows the transport; the challenge stays UDP. SIP_TRANSPORT selects the policy: auto (default) registers over TCP and, after two unanswered connects, registers again over UDP (new challenge, new SA pair) - but only on a phone whose state file does not record a successful TCP registration, so an outage on a TCP carrier never becomes a second initial REGISTER; a phone whose last registration was UDP goes straight to UDP. tcp and udp force one. A connect refused locally (EADDRNOTAVAIL: the 4-tuple still in TIME_WAIT from the previous flow) keeps retrying and is not counted as silence; SO_ERROR results are logged by name. The registration's transport is persisted so a warm resume reconnects the same way, and the resume gives up after two silences. Two things the change exposed and fixes: an engine-fatal event exited 0 ("exiting for systemd restart" with Restart=on-failure never firing), and a fresh registration refused with the P-CSCF's fresh-SA throttle (Security-Server spi-s=0) must not be retried by a 120-s restart loop, since every attempt re-arms the ~20-min window - it is now waited out in-process, growing on repeats, with D-Bus commands still served. A resume the network refuses falls through to a fresh registration. A retransmitted 200 OK to our INVITE is ACKed again and no longer starts a second media leg. Verified on KPN: resume over TCP after a binary swap, MT and MO calls with media both ways, the throttle deferral and its self-recovery, the UDP client path up to KPN dropping the datagram. The UDP success path is a field test; SIP retransmission timers over UDP are not in this change.
2026-09-17 14:58:46 +02:00
// a retransmitted 200 (RFC 3261 13.3.1.4: the UAS repeats it until our
// ACK arrives) is ACKed again and nothing else — no second media leg
auto a200b = m.OnInviteResponse(R200(m.CallId()));
Check(Sent(a200b, "ACK ") != nullptr, "retransmitted 200 -> ACK again");
Check(!Has(a200b, Action::Type::StartMedia) && !Has(a200b, Action::Type::State), "retransmitted 200: no second media start, no state action");
Check(m.State() == CallState::Active, "state still active after the retransmit");
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
// DTMF on a call whose answer negotiated no telephone-event: dropped, said why
auto adt = m.OnDtmf("1");
Check(!Has(adt, Action::Type::SendDtmf), "no telephone-event negotiated: no SendDtmf");
const Action* dtLog = Find(adt, Action::Type::Log);
Check(dtLog && dtLog->text == "call ims-call-1: DTMF '1' dropped: no telephone-event negotiated for this call", "...and the line says so");
// media leg exits code 3 (downlink dried up) -> BYE + terminated
auto amx = m.OnMediaExit(3);
Check(Sent(amx, "BYE ") != nullptr, "media far-end hangup sends BYE");
const Action* term = Find(amx, Action::Type::State);
Check(term && term->state == "terminated" && term->reason == "remote-hangup", "media exit -> terminated/remote-hangup");
Check(Has(amx, Action::Type::StopMedia), "stops media");
Check(Has(amx, Action::Type::Deleted), "emits deleted");
Check(m.Terminated(), "terminated");
}
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
// ---- DTMF, outgoing: the answer echoes our telephone-event/16000 at pt
// 98; the tones go to the leg once active, in upper case, and are
// dropped before the answer, with a character that is no tone,
// and after the call
{
imsd::util::Rng rng(43);
CallMachine m(c, rng, "ims-call-1d", "1233", 50004, false);
m.Start();
auto early = m.OnDtmf("1");
Check(!Has(early, Action::Type::SendDtmf), "DTMF while dialing: not sent");
const Action* earlyLog = Find(early, Action::Type::Log);
Check(earlyLog && earlyLog->text == "call ims-call-1d: DTMF '1' dropped: the call is dialing", "...the line names the state");
auto a200 = m.OnInviteResponse(R200Sdp(m.CallId(), std::format("{}m=audio 6004 RTP/AVP 97 98 100\r\na=rtpmap:97 AMR-WB/16000/1\r\na=rtpmap:98 telephone-event/16000\r\na=rtpmap:100 telephone-event/8000\r\n", SdpHead)));
const Action* media = Find(a200, Action::Type::StartMedia);
Check(media && media->media.dtmfPt == 98, "the leg carries the answer's telephone-event pt at the codec's clock (98, not the narrowband 100)");
sdp, engine, imsd, media: the far end's telephone-event packets are played as the tones they stand for Keys pressed on the other phone reached imsd-media as RFC 4733 events and were dropped with every packet that is not the audio's. The playout now takes them: the gap before an event's start (a stock sender's DTX silence often precedes a key press) is filled as before an audio frame, each packet reports the event's duration so far from its start stamp, and what the clock has not covered yet is synthesized as the event's Q.23 frequency pair at the packet's volume, so a retransmitted end packet adds nothing, a lost update is caught up by the next, and a far end whose audio resumes past the event (the stock phone's does) meets the clock with the usual fill. An answer may renumber telephone-event from what we offered (RFC 3264: the answerer sends with the offer's numbers, §6.1, and the offerer with the answer's, §5.1), so the leg gets both: DTMF_PT to send with, DTMF_RX_PT to take events at as well — our own SDP's number: the offer's 98 or 100 on a call we placed, the offer's number we echoed on one we answered; when the answer gave the audio our offer's number, that number is the leg's audio and DTMF_RX_PT is the answer's telephone-event number instead — and takes events at either number, never at the audio's. --selftest pins the frequency table; the stats gain rx_dtmf, tones and dtmf_rx_pt. Tested: --selftest, tests/Sdp and tests/Engine (the eight suites pass); the loopback's --dtmf-rx arm on a host build of this commit's tree (journal/ims/captures/2026-10-15-dtmf-loopback-c3-rx.txt; the tx, both, plain and collision runs beside it); the dev phone's dtmf benches ran in builds of this series.
2026-10-15 21:18:28 +02:00
Check(media && media->media.dtmfRxPt == 98, "outgoing: the far end sends at our offer's number for that clock");
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
Check(m.State() == CallState::Active, "active");
auto sent = m.OnDtmf("12#*a");
const Action* dt = Find(sent, Action::Type::SendDtmf);
Check(dt && dt->text == "12#*A", "active + negotiated: SendDtmf with the tones, letters upper-cased");
const Action* dtLog = Find(sent, Action::Type::Log);
Check(dtLog && dtLog->text == "call ims-call-1d: DTMF '12#*A' -> media leg (telephone-event pt 98)", "...and the line names the pt");
auto bad = m.OnDtmf("1x");
Check(!Has(bad, Action::Type::SendDtmf), "a character that is no tone: nothing sent, not even the '1'");
const Action* badLog = Find(bad, Action::Type::Log);
Check(badLog && badLog->text == "call ims-call-1d: DTMF '1x' dropped: 'x' is not a tone", "...the line names the character");
Check(m.OnDtmf("").empty(), "an empty string: nothing, silently");
const std::string atMost(DtmfMaxTones, '1');
auto most = m.OnDtmf(atMost);
const Action* maxDt = Find(most, Action::Type::SendDtmf);
Check(maxDt && maxDt->text == atMost, "a string of DtmfMaxTones tones goes");
auto tooMany = m.OnDtmf(std::format("{}1", atMost));
Check(!Has(tooMany, Action::Type::SendDtmf) && Find(tooMany, Action::Type::Log) && Find(tooMany, Action::Type::Log)->text == std::format("call ims-call-1d: DTMF of {} tones dropped: more than {}", DtmfMaxTones + 1, DtmfMaxTones), "one more: dropped, the line names the bound");
m.OnHangup();
auto late = m.OnDtmf("5");
Check(!Has(late, Action::Type::SendDtmf) && Find(late, Action::Type::Log) && Find(late, Action::Type::Log)->text.ends_with("the call is terminated"), "DTMF after the call: dropped, the line names the state");
}
sdp, engine, imsd, media: the far end's telephone-event packets are played as the tones they stand for Keys pressed on the other phone reached imsd-media as RFC 4733 events and were dropped with every packet that is not the audio's. The playout now takes them: the gap before an event's start (a stock sender's DTX silence often precedes a key press) is filled as before an audio frame, each packet reports the event's duration so far from its start stamp, and what the clock has not covered yet is synthesized as the event's Q.23 frequency pair at the packet's volume, so a retransmitted end packet adds nothing, a lost update is caught up by the next, and a far end whose audio resumes past the event (the stock phone's does) meets the clock with the usual fill. An answer may renumber telephone-event from what we offered (RFC 3264: the answerer sends with the offer's numbers, §6.1, and the offerer with the answer's, §5.1), so the leg gets both: DTMF_PT to send with, DTMF_RX_PT to take events at as well — our own SDP's number: the offer's 98 or 100 on a call we placed, the offer's number we echoed on one we answered; when the answer gave the audio our offer's number, that number is the leg's audio and DTMF_RX_PT is the answer's telephone-event number instead — and takes events at either number, never at the audio's. --selftest pins the frequency table; the stats gain rx_dtmf, tones and dtmf_rx_pt. Tested: --selftest, tests/Sdp and tests/Engine (the eight suites pass); the loopback's --dtmf-rx arm on a host build of this commit's tree (journal/ims/captures/2026-10-15-dtmf-loopback-c3-rx.txt; the tx, both, plain and collision runs beside it); the dev phone's dtmf benches ran in builds of this series.
2026-10-15 21:18:28 +02:00
// ---- DTMF, outgoing, the answer renumbered telephone-event (RFC 3264
// allows it): we send with its number, the far end with our offer's
{
imsd::util::Rng rng(44);
CallMachine m(c, rng, "ims-call-1e", "1233", 50004, false);
m.Start();
auto a200 = m.OnInviteResponse(R200Sdp(m.CallId(), std::format("{}m=audio 6004 RTP/AVP 97 101\r\na=rtpmap:97 AMR-WB/16000/1\r\na=rtpmap:101 telephone-event/16000\r\n", SdpHead)));
const Action* media = Find(a200, Action::Type::StartMedia);
Check(media && media->media.dtmfPt == 101 && media->media.dtmfRxPt == 98, "renumbered answer: send with 101, listen on our 98");
// a narrowband answer: AMR at 99 with telephone-event/8000 at 102
imsd::util::Rng rng2(45);
CallMachine n(c, rng2, "ims-call-1f", "1233", 50004, false);
n.Start();
auto b200 = n.OnInviteResponse(R200Sdp(n.CallId(), std::format("{}m=audio 6004 RTP/AVP 99 102\r\na=rtpmap:99 AMR/8000/1\r\na=rtpmap:102 telephone-event/8000\r\n", SdpHead)));
const Action* nbMedia = Find(b200, Action::Type::StartMedia);
Check(nbMedia && nbMedia->media.codec == "AMR" && nbMedia->media.dtmfPt == 102 && nbMedia->media.dtmfRxPt == 100, "narrowband answer: send with its 102, listen on our offer's 100");
// an answer numbering for itself that gives the audio our offer's
// telephone-event number: the receive number is the answer's, never
// the audio's (every downlink frame would be taken for an event)
imsd::util::Rng rng3(46);
CallMachine o(c, rng3, "ims-call-1g", "1233", 50004, false);
o.Start();
auto c200 = o.OnInviteResponse(R200Sdp(o.CallId(), std::format("{}m=audio 6004 RTP/AVP 100 101\r\na=rtpmap:100 AMR/8000/1\r\na=rtpmap:101 telephone-event/8000\r\n", SdpHead)));
const Action* colMedia = Find(c200, Action::Type::StartMedia);
Check(colMedia && colMedia->media.payloadType == 100 && colMedia->media.dtmfPt == 101 && colMedia->media.dtmfRxPt == 101, "the audio at our telephone-event number: listen on the answer's 101, not the audio's 100");
auto again = m.OnInviteResponse(R200(m.CallId()));
Check(!Find(again, Action::Type::StartMedia), "a retransmitted 200 starts no second leg");
}
// ---- remote BYE mid-call
{
imsd::util::Rng rng(7);
CallMachine m(c, rng, "ims-call-2", "1233", 50004, false);
m.Start();
m.OnInviteResponse(R200(m.CallId()));
Check(m.State() == CallState::Active, "answered");
std::string bye = std::format(
"BYE sip:me SIP/2.0\r\nVia: SIP/2.0/TCP [x]:1;branch=z9hG4bKb\r\n"
"From: <sip:them>;tag=remote7\r\nTo: <sip:me>;tag=it\r\n"
"Reason: SIP;cause=503;text=\"PT: Session timer expired.\"\r\n"
"Call-ID: {}\r\nCSeq: 9 BYE\r\nContent-Length: 0\r\n\r\n", m.CallId());
auto ab = m.OnRequest(bye);
const Action* resp = Find(ab, Action::Type::SendResponse);
Check(resp && resp->text.starts_with("SIP/2.0 200 OK"), "remote BYE answered 200");
Check(resp && resp->text.contains("CSeq: 9 BYE\r\n"), "200 echoes BYE CSeq");
const Action* t = Find(ab, Action::Type::State);
Check(t && t->reason == "remote-hangup", "remote BYE -> remote-hangup");
const Action* lg = Find(ab, Action::Type::Log);
Check(lg && lg->text.contains("ended: remote-hangup") && lg->text.contains("Reason: SIP;cause=503"), "teardown log names the peer's Reason");
Check(m.Terminated(), "terminated after remote BYE");
}
// ---- local hang-up before answer sends CANCEL; the 200/487 race
{
imsd::util::Rng rng(9);
CallMachine m(c, rng, "ims-call-3", "1233", 50004, false);
m.Start();
m.OnInviteResponse(R183(m.CallId())); // ringing
auto ah = m.OnHangup();
Check(Sent(ah, "CANCEL ") != nullptr, "hangup while ringing sends CANCEL");
Check(Has(ah, Action::Type::SetDeadline), "arms 487 timeout after CANCEL");
Check(!m.Terminated(), "not terminated until 487");
// a late 200 wins the race: ACK, then BYE, then terminate local-hangup
auto ar = m.OnInviteResponse(R200(m.CallId()));
Check(Sent(ar, "ACK ") != nullptr, "race 200 is ACKed");
Check(Sent(ar, "BYE ") != nullptr, "race 200 then BYE (we cancelled)");
const Action* t = Find(ar, Action::Type::State);
Check(t && t->reason == "local-hangup", "cancel race -> local-hangup");
// no media for a cancelled call
Check(!Has(ar, Action::Type::StartMedia), "cancelled call starts no media");
}
// ---- 487 after CANCEL
{
imsd::util::Rng rng(11);
CallMachine m(c, rng, "ims-call-4", "1233", 50004, false);
m.Start();
m.OnHangup(); // CANCEL while dialing
auto a487 = m.OnInviteResponse(Final(m.CallId(), 487, "Request Terminated"));
Check(Sent(a487, "ACK ") != nullptr, "487 is ACKed (non-2xx)");
const Action* t = Find(a487, Action::Type::State);
Check(t && t->reason == "local-hangup", "487 -> local-hangup");
Check(m.Terminated(), "terminated on 487");
}
// ---- busy / declined finals
{
for (auto [code, want] : std::vector<std::pair<int, std::string>>{
{486, "refused-or-busy"}, {480, "refused-or-busy"},
{603, "refused-or-busy"}, {500, "error"}, {403, "error"}}) {
imsd::util::Rng rng(code);
CallMachine m(c, rng, "u", "1233", 50004, false);
m.Start();
auto a = m.OnInviteResponse(Final(m.CallId(), code, "x"));
Check(Sent(a, "ACK ") != nullptr, std::format("{} ACKed", code));
const Action* t = Find(a, Action::Type::State);
Check(t && t->reason == want, std::format("{} -> {}", code, want));
Check(m.Terminated(), std::format("{} terminates", code));
}
}
// ---- BYE after answer (local hangup during active call)
{
imsd::util::Rng rng(13);
CallMachine m(c, rng, "ims-call-5", "1233", 50004, false);
m.Start();
m.OnInviteResponse(R200(m.CallId()));
auto a = m.OnHangup();
const Action* bye = Sent(a, "BYE ");
Check(bye != nullptr, "active hangup sends BYE");
Check(bye && bye->text.contains("CSeq: 3 BYE\r\n"), "BYE CSeq after ACK=1");
const Action* t = Find(a, Action::Type::State);
Check(t && t->reason == "local-hangup", "active hangup -> local-hangup");
}
// ---- setup timeout -> CANCEL, then error
{
imsd::util::Rng rng(15);
CallMachine m(c, rng, "ims-call-6", "1233", 50004, false);
m.Start();
auto a1 = m.OnDeadline(); // ring timeout
Check(Sent(a1, "CANCEL ") != nullptr, "ring timeout sends CANCEL");
Check(!m.Terminated(), "not terminated after first timeout");
auto a2 = m.OnDeadline(); // 487 never came
const Action* t = Find(a2, Action::Type::State);
Check(t && t->reason == "error", "second timeout -> error");
Check(m.Terminated(), "terminated on second timeout");
}
imsd: when the client flow is found dead before any response to a call's INVITE, one reconnect and the INVITE again, else the call ends A flow that is dead in a way imsd has not seen yet, the peer having dropped the connection's state, shows itself at the next bytes sent on it, where the peer answers them with a reset. Where those bytes were an outgoing call's INVITE, imsd read the reset, marked the flow dead and did nothing more for the call: no reconnect runs while a call is up, so the attempt stayed in `dialing` until its setup deadline, 90 s, sent a CANCEL that could not go out and was given up 10 s later, where a call that is no emergency call ends (`setup deadline expired`); the flow was reconnected only once the call was gone. Against a stand-in network that forgets a flow after 20 s of silence, 1.2.3's call ended 100 s after the Dial. The engine's loop now takes such a call up (MaybeResendInvite). When the client flow is found dead under an outgoing attempt whose INVITE has had no response, a 100 included, and no CANCEL, the dead socket is closed without a FIN's exchange, the flow is reopened with one connect and the same INVITE is sent again, the setup deadline running from then. Once per attempt: an emergency call's fallback attempt has a resend of its own. The INVITE is the first one byte for byte, its branch included, so a server that did receive the first matches the second to its transaction (RFC 3261 17.2.3). No REGISTER goes first: the registration and its SAs stand, and TS 33.203 7.1 has a UE with no TCP connection towards the P-CSCF set one up before it sends a request. Where a reg-event NOTIFY has ended the binding nothing is reopened. Where nothing is reopened, the connect fails (one that gets no answer, after 12 s) or the flow dies again before a response, the call ends with `error`, an emergency call's first attempt too: there is no flow for its fallback. The recovery policy takes the flow up once the call is gone, as before. The close without a FIN's exchange is for a flow the peer closed: closed the usual way, such a socket stays in the kernel's table until the peer has acknowledged imsd's own FIN, and a connect from its port before that is refused. A reset goes out in the FIN's place there; after a reset or the kernel's own giving up the socket is closed already and nothing is sent; and the reopen runs on a flow already found dead only. The recovery's reconnect closes the usual way, as before, and connects once more 10 s after such a refusal (one is in a user's log on O2, 2026-09-24, in the second the flow was found dead). Not changed: under a call, a flow that died with no reset and no close reaching the phone is found dead only when the kernel gives up on unacknowledged bytes, 924.6 s or more after them by its default tcp_retries2, so an attempt whose own INVITE is the first such bytes gets no response and is cancelled at its setup deadline, as before; a flow found dead after a response to the INVITE is not reopened, as before; a Dial whose INVITE cannot be sent ends its call at once, as before. Tested: tests/Engine (which attempt is sent again, the same bytes, once per attempt, the deadline anew, the call's end where the flow is lost); the daemon of this commit and 1.2.3's on the workstation against a stand-in network (the fp6 journal's 2026-11-24-crlf-keepalive capture, bench-dial.sh): a flow the network forgot, reopened and the INVITE answered 486 as on a live flow, where 1.2.3's call ended after 100 s; a flow the network closed at the INVITE, with the acknowledgement of the daemon's close kept back; one that died on the daemon's side at the kernel's retransmission limit; a network that takes no new connection, one that resets the second INVITE's flow too and one that has ended the binding, where the call ended within a second; UDP. And on the dev phone on KPN, the binary of the range's tip: a call to voicemail answered and hung up, and one whose flow was made to die under the INVITE before the INVITE left the phone: reopened from the same port, the INVITE again 2.1 s after the death was found, answered 0.2 s later. By a call, no P-CSCF that had dropped a flow's state has been met, and none that had received the first INVITE before the flow died.
2026-11-25 10:24:07 +01:00
// ---- the client flow dies before any response to the INVITE: the shell
// reopens it and the same INVITE goes out again, once per attempt
{
imsd::util::Rng rng(16);
CallMachine m(c, rng, "ims-call-6b", "1233", 50004, false);
Check(!m.Unanswered() && !m.ResendDue(), "no INVITE sent yet: nothing to send again");
auto start = m.Start();
const Action* inv = Sent(start, "INVITE ");
Check(m.Unanswered() && m.ResendDue(), "an INVITE with no response: a resend is due");
auto again = m.OnFlowReopened();
const Action* inv2 = Sent(again, "INVITE ");
Check(inv && inv2 && inv2->text == inv->text, "the resent INVITE is the first one, byte for byte");
const Action* dl = Find(again, Action::Type::SetDeadline);
Check(dl && dl->seconds == imsd::engine::InviteTimeout, "the resend arms the setup deadline anew");
Check(m.State() == CallState::Dialing && !m.Terminated(), "still dialing after the resend");
Check(m.Unanswered() && !m.ResendDue(), "one resend per attempt");
Check(m.OnFlowReopened().empty(), "a second reopen sends nothing");
auto lost = m.OnFlowLost();
const Action* t = Find(lost, Action::Type::State);
Check(t && t->reason == "error" && m.Terminated(), "a flow that dies again ends the call with error");
Check(Has(lost, Action::Type::Deleted) && Sent(lost, "CANCEL ") == nullptr, "... deleted, and no CANCEL onto a dead flow");
Check(!m.Unanswered() && m.OnFlowLost().empty() && m.OnFlowReopened().empty(), "an ended call has nothing more to end or to send");
}
// ---- ... not once a response has come (a 100 is one), the user has hung
// up or a deadline has cancelled the attempt, and never for an
// incoming call
{
imsd::util::Rng rng(17);
CallMachine m(c, rng, "ims-call-6c", "1233", 50004, false);
m.Start();
m.OnInviteResponse(Final(m.CallId(), 100, "Trying"));
Check(!m.Unanswered() && !m.ResendDue(), "a 100 Trying is a response: no resend");
Check(m.OnFlowReopened().empty() && m.OnFlowLost().empty() && !m.Terminated(), "... and the flow's death is left to the deadline");
imsd::util::Rng rng2(18);
CallMachine n(c, rng2, "ims-call-6d", "1233", 50004, false);
n.Start();
n.OnHangup();
Check(!n.Unanswered() && n.OnFlowReopened().empty() && n.OnFlowLost().empty(), "an attempt the user cancelled is not sent again");
imsd::util::Rng rng3(19);
CallMachine o(c, rng3, "ims-call-6e", "1233", 50004, false);
o.Start();
o.OnDeadline(); // ring timeout: CANCEL
Check(!o.Unanswered() && o.OnFlowReopened().empty() && o.OnFlowLost().empty(), "nor one a deadline cancelled");
imsd::util::Rng rng4(20);
CallMachine p(c, rng4, "ims-call-6f", IncomingInvite{MtInvite()}, 50004);
Check(!p.Unanswered() && p.OnFlowReopened().empty() && p.OnFlowLost().empty(), "an incoming call has no INVITE of ours to send again");
}
// ================= incoming (terminating / UAS) =======================
// ---- full accepted incoming call: INVITE -> 100+180, Accept -> 200 with
// the answer at the offer's payload types + media, ACK, remote BYE
{
imsd::util::Rng rng(21);
CallMachine m(c, rng, "ims-call-7", IncomingInvite{MtInvite()}, 50004);
Check(m.Dir() == Direction::Incoming, "direction incoming");
Check(m.State() == CallState::Incoming, "starts incoming");
Check(m.Number() == "+31612345678", "caller id from P-Asserted-Identity");
Check(m.CallId() == "mt-call-abc123", "call id from INVITE");
auto ai = m.OnInvite();
const Action* trying = Responded(ai, "SIP/2.0 100 Trying");
Check(trying != nullptr, "INVITE -> 100 Trying");
Check(trying && trying->text.contains("To: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org;user=phone>\r\n"), "100 leaves To untagged");
const Action* ringing = Responded(ai, "SIP/2.0 180 Ringing");
Check(ringing != nullptr, "INVITE -> 180 Ringing");
Check(ringing && !ringing->text.contains("RSeq:"), "180 unreliable when 100rel not required");
Check(Has(ai, Action::Type::SetDeadline), "arms ring timeout");
// both Vias echoed, in order
Check(ringing && ringing->text.contains("Via: SIP/2.0/UDP [2001:db8::105]:5100") && ringing->text.contains("Via: SIP/2.0/UDP [2001:db8::9]:5060"), "180 echoes all Vias");
Check(ringing && ringing->text.find("[2001:db8::105]:5100") < ringing->text.find("[2001:db8::9]:5060"), "180 Via order preserved");
Check(ringing && ringing->text.contains("Record-Route: <sip:[2001:db8::105]:5100;lr>"), "180 returns the Record-Route set");
Check(ringing && ringing->text.contains("To: <sip:+31611111111@ims.mnc001.mcc001." "3gppnetwork.org;user=phone>;tag="), "180 mints a To tag");
// retransmitted INVITE (lost provisional): repeat the 180
auto art = m.OnRequest(MtInvite());
Check(Responded(art, "SIP/2.0 180 Ringing") != nullptr, "INVITE retransmit re-sends the 180");
Check(m.State() == CallState::Incoming, "still incoming");
auto aa = m.OnAccept();
const Action* ok = Responded(aa, "SIP/2.0 200 OK");
Check(ok != nullptr, "Accept -> 200 OK");
Check(ok && ok->text.contains("m=audio 50004 RTP/AVP 104 105\r\n"), "answer uses the offer's payload types");
Check(ok && ok->text.contains("a=rtpmap:104 AMR-WB/16000/1\r\n"), "answer keeps AMR-WB at the offer's pt");
Check(ok && ok->text.contains("a=fmtp:104 octet-align=1\r\n"), "answer mirrors octet-align");
Check(ok && ok->text.contains("a=rtpmap:105 telephone-event/16000\r\n"), "answer keeps telephone-event");
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
const Action* mtMedia = Find(aa, Action::Type::StartMedia);
Check(mtMedia && mtMedia->media.dtmfPt == 105, "incoming: the leg carries the offer's telephone-event pt");
sdp, engine, imsd, media: the far end's telephone-event packets are played as the tones they stand for Keys pressed on the other phone reached imsd-media as RFC 4733 events and were dropped with every packet that is not the audio's. The playout now takes them: the gap before an event's start (a stock sender's DTX silence often precedes a key press) is filled as before an audio frame, each packet reports the event's duration so far from its start stamp, and what the clock has not covered yet is synthesized as the event's Q.23 frequency pair at the packet's volume, so a retransmitted end packet adds nothing, a lost update is caught up by the next, and a far end whose audio resumes past the event (the stock phone's does) meets the clock with the usual fill. An answer may renumber telephone-event from what we offered (RFC 3264: the answerer sends with the offer's numbers, §6.1, and the offerer with the answer's, §5.1), so the leg gets both: DTMF_PT to send with, DTMF_RX_PT to take events at as well — our own SDP's number: the offer's 98 or 100 on a call we placed, the offer's number we echoed on one we answered; when the answer gave the audio our offer's number, that number is the leg's audio and DTMF_RX_PT is the answer's telephone-event number instead — and takes events at either number, never at the audio's. --selftest pins the frequency table; the stats gain rx_dtmf, tones and dtmf_rx_pt. Tested: --selftest, tests/Sdp and tests/Engine (the eight suites pass); the loopback's --dtmf-rx arm on a host build of this commit's tree (journal/ims/captures/2026-10-15-dtmf-loopback-c3-rx.txt; the tx, both, plain and collision runs beside it); the dev phone's dtmf benches ran in builds of this series.
2026-10-15 21:18:28 +02:00
Check(mtMedia && mtMedia->media.dtmfRxPt == 105, "incoming: the far end sends at the number we echoed");
sdp, engine, imsd: SendDtmf sends the tones as RFC 4733 events over the media leg SendDtmf was a stub: GNOME Calls' SendTones and Plasma Dialer's sendDtmf reached imsd and went nowhere. The SDP parser reads the telephone-event payload type at the chosen codec's clock into the answer, among the m-line's formats only — an rtpmap the line does not list is not negotiated, and nothing is sent with a format the answer does not carry (RFC 3264 §8.3.2); an event's rate is its rtpmap clock (RFC 4733 §2.4.1), an offer with two codec clocks lists telephone-event at each, and the name is matched as every encoding name is, case-insensitively, with the clock whole. The media leg carries it, and imsd-media gets it as DTMF_PT with its stdin on a pipe from imsd, the control pipe. The SDP answer imsd sends to an inbound offer carries telephone-event by the same rule, where it echoed any telephone-event rtpmap with a lower-case name and a clock prefix before: an rtpmap off the offer's m-line is no longer echoed, an upper-case name now is. The decision is the engine's: OnDtmf lets the tones through on an active call that negotiated telephone-event (the answer's number on a call we placed, the offer's on one we answered) and drops them otherwise with a line that says why: before the answer, after the call, no telephone-event at the codec's clock in the SDP, a character that is no tone or more than 128 tones (then the whole string, never part of what was pressed); letters are upper-cased. The shell writes one `dtmf <tones>` line per SendDtmf, whole or not at all: the bound keeps the line within one atomic pipe write, the write end is non-blocking so that a leg that stopped reading fails the write instead of holding the engine thread, and a longer line is refused; SIGPIPE is ignored so that a write after the leg died fails with EPIPE instead of ending the daemon. The command queue's one argument is `arg` now — the number to dial, or the tones. The `media …` start line gains the telephone-event pt at its end. Tested: tests/Sdp and tests/Engine (the eight suites pass); the dev phone's dtmf benches ran in builds of this series (journal/ims/captures/2026-10-14-dtmf-bench-1/ onward).
2026-10-14 15:05:24 +02:00
auto mtDtmf = m.OnDtmf("9");
const Action* mtDt = Find(mtDtmf, Action::Type::SendDtmf);
Check(mtDt && mtDt->text == "9", "incoming, accepted: the tones go to the leg");
Check(ok && ok->text.contains("Session-Expires: 1800;refresher=uac\r\n"), "200 echoes Session-Expires, caller refreshes");
Check(ok && ok->text.contains("Contact: <sip:001010123456789@"), "200 carries our Contact");
// the 180 and 200 carry the SAME To tag (one dialog)
if (ringing && ok) {
auto tag = [](const std::string& s) {
std::size_t at = s.find(";tag=", s.find("To:"));
return s.substr(at, s.find('\r', at) - at);
};
Check(tag(ringing->text) == tag(ok->text), "180/200 share the To tag");
}
const Action* media = Find(aa, Action::Type::StartMedia);
Check(media != nullptr, "Accept starts media");
Check(media && media->media.remoteIp == "2001:db8::30c", "media ip from offer");
Check(media && media->media.remotePort == 27864, "media port from offer");
Check(media && media->media.payloadType == 104, "media pt from offer");
const Action* st = Find(aa, Action::Type::State);
Check(st && st->state == "active" && st->reason == "accepted", "Accept emits active/accepted");
Check(m.State() == CallState::Active, "active after Accept");
// a second Accept is a no-op
Check(m.OnAccept().empty(), "double Accept is a no-op");
// the caller's ACK is consumed silently
std::string ack = std::format(
"ACK sip:001010123456789@[2001:db8::db43]:45061 SIP/2.0\r\n"
"Via: SIP/2.0/UDP [2001:db8::105]:5100;branch=z9hG4bKack\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>;tag=x\r\n"
"Call-ID: {}\r\nCSeq: 1 ACK\r\nContent-Length: 0\r\n\r\n", m.CallId());
Check(m.OnRequest(ack).empty(), "ACK gets no response");
// session-refresh UPDATE without a body: bodyless 200
std::string upd = std::format(
"UPDATE sip:me SIP/2.0\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKu\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>;tag=x\r\n"
"Call-ID: {}\r\nCSeq: 2 UPDATE\r\nContent-Length: 0\r\n\r\n", m.CallId());
auto au = m.OnRequest(upd);
const Action* u200 = Responded(au, "SIP/2.0 200 OK");
Check(u200 != nullptr, "bodyless UPDATE answered 200");
Check(u200 && u200->text.contains("Content-Length: 0"), "bodyless UPDATE gets a bodyless 200");
Check(u200 && !u200->text.contains("Session-Expires"), "no Session-Expires in the UPDATE -> none invented in the 200");
// session-audit UPDATE with Session-Expires (KPN B2BUA, ~55 s into
// every call): the 200 MUST echo it (RFC 4028 §9) or the network
// releases with "Session timer expired"
std::string se = std::format(
"UPDATE sip:me SIP/2.0\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKu2\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>;tag=x\r\n"
"Min-SE: 90\r\nSession-Expires: 1800;refresher=uac\r\n"
"Supported: timer\r\n"
"Call-ID: {}\r\nCSeq: 3 UPDATE\r\nContent-Length: 0\r\n\r\n", m.CallId());
auto ase = m.OnRequest(se);
const Action* se200 = Responded(ase, "SIP/2.0 200 OK");
Check(se200 != nullptr, "refresh UPDATE answered 200");
Check(se200 && se200->text.contains("Session-Expires: 1800;refresher=uac\r\n"), "200 echoes Session-Expires");
Check(se200 && se200->text.contains("Require: timer\r\n"), "200 carries Require: timer");
// remote BYE ends it
std::string bye = std::format(
"BYE sip:me SIP/2.0\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKb\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>;tag=x\r\n"
"Call-ID: {}\r\nCSeq: 4 BYE\r\nContent-Length: 0\r\n\r\n", m.CallId());
auto ab = m.OnRequest(bye);
Check(Responded(ab, "SIP/2.0 200 OK") != nullptr, "remote BYE answered");
const Action* t = Find(ab, Action::Type::State);
Check(t && t->reason == "remote-hangup", "remote BYE -> remote-hangup");
Check(m.Terminated(), "terminated");
}
// ---- reliable 180 when the caller requires 100rel; PRACK answered
{
imsd::util::Rng rng(23);
CallMachine m(c, rng, "ims-call-8", IncomingInvite{MtInvite("Require: 100rel\r\n")}, 50004);
auto ai = m.OnInvite();
const Action* ringing = Responded(ai, "SIP/2.0 180 Ringing");
Check(ringing && ringing->text.contains("Require: 100rel\r\n") && ringing->text.contains("RSeq: 1\r\n"), "Require: 100rel makes the 180 reliable");
std::string prack = std::format(
"PRACK sip:me SIP/2.0\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKp\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>;tag=x\r\n"
"Call-ID: {}\r\nCSeq: 2 PRACK\r\nRAck: 1 1 INVITE\r\n"
"Content-Length: 0\r\n\r\n", m.CallId());
auto ap = m.OnRequest(prack);
const Action* p200 = Responded(ap, "SIP/2.0 200 OK");
Check(p200 != nullptr, "PRACK answered 200");
Check(p200 && p200->text.contains("CSeq: 2 PRACK\r\n"), "PRACK 200 echoes CSeq");
Check(m.State() == CallState::Incoming, "PRACK leaves state incoming");
}
// ---- local reject: HangUp while ringing -> 486
{
imsd::util::Rng rng(25);
CallMachine m(c, rng, "ims-call-9", IncomingInvite{MtInvite()}, 50004);
m.OnInvite();
auto ah = m.OnHangup();
const Action* busy = Responded(ah, "SIP/2.0 486 Busy Here");
Check(busy != nullptr, "reject sends 486");
Check(busy && busy->text.contains("CSeq: 1 INVITE\r\n"), "486 answers the INVITE");
const Action* t = Find(ah, Action::Type::State);
Check(t && t->reason == "local-hangup", "reject -> local-hangup");
Check(m.Terminated(), "terminated after reject");
}
// ---- remote CANCEL while ringing: 200 the CANCEL, 487 the INVITE
{
imsd::util::Rng rng(27);
CallMachine m(c, rng, "ims-call-10", IncomingInvite{MtInvite()}, 50004);
m.OnInvite();
std::string cancel = std::format(
"CANCEL sip:001010123456789@[2001:db8::db43]:45061 SIP/2.0\r\n"
"Via: SIP/2.0/UDP [2001:db8::105]:5100;branch=z9hG4bKpcscf1\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>\r\n"
"Call-ID: {}\r\nCSeq: 1 CANCEL\r\nContent-Length: 0\r\n\r\n", m.CallId());
auto ac = m.OnRequest(cancel);
const Action* c200 = Responded(ac, "SIP/2.0 200 OK");
Check(c200 && c200->text.contains("CSeq: 1 CANCEL\r\n"), "CANCEL answered 200 on its own transaction");
const Action* r487 = Responded(ac, "SIP/2.0 487 Request Terminated");
Check(r487 && r487->text.contains("CSeq: 1 INVITE\r\n"), "the INVITE transaction gets the 487");
const Action* t = Find(ac, Action::Type::State);
Check(t && t->reason == "remote-hangup", "remote CANCEL -> remote-hangup");
Check(m.Terminated(), "terminated after remote CANCEL");
}
// an inbound INVITE around an arbitrary offer (the gateway shapes below)
auto MtInviteSdp = [](std::string_view callid, std::string_view sdp) {
return std::format(
"INVITE sip:me SIP/2.0\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKi\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>\r\n"
"Call-ID: {}\r\nCSeq: 1 INVITE\r\n"
"Contact: <sip:origgw@[2001:db8::9]:5060>\r\n"
"Content-Type: application/sdp\r\nContent-Length: {}\r\n\r\n{}",
callid, sdp.size(), sdp);
};
// ---- a landline caller: the PSTN gateway offers G.711 only, by static
// payload type with no rtpmap (the shape that used to be 488'd). It
// rings, and Accept answers PCMA at the offer's pt with narrowband DTMF.
{
imsd::util::Rng rng(29);
std::string sdp =
"v=0\r\no=- 5 5 IN IP6 2001:db8::30c\r\ns=-\r\n"
"c=IN IP6 2001:db8::30c\r\nt=0 0\r\n"
"m=audio 27864 RTP/AVP 8 0 101\r\na=rtpmap:101 telephone-event/8000\r\na=ptime:20\r\n";
CallMachine m(c, rng, "ims-call-11", IncomingInvite{MtInviteSdp("mt-pcma", sdp)}, 50004);
auto ai = m.OnInvite();
Check(Responded(ai, "SIP/2.0 488 Not Acceptable Here") == nullptr, "G.711 offer is not refused");
Check(Responded(ai, "SIP/2.0 180 Ringing") != nullptr, "G.711 offer rings");
Check(!m.Terminated(), "G.711 call alive after INVITE");
auto aa = m.OnAccept();
const Action* ok = Responded(aa, "SIP/2.0 200 OK");
Check(ok != nullptr, "Accept answers 200");
Check(ok && ok->text.contains("m=audio 50004 RTP/AVP 8 101\r\n"), "answer keeps the offer's PCMA + DTMF pts");
Check(ok && ok->text.contains("a=rtpmap:8 PCMA/8000/1\r\n"), "answer names PCMA");
Check(ok && ok->text.contains("a=rtpmap:101 telephone-event/8000\r\n"), "DTMF at the narrowband clock");
Check(ok && !ok->text.contains("octet-align"), "no octet-align for G.711");
const Action* med = Find(aa, Action::Type::StartMedia);
Check(med && med->media.codec == "PCMA" && med->media.payloadType == 8 && !med->media.octetAlign, "media leg starts PCMA pt 8");
Check(med && med->media.remoteIp == "2001:db8::30c" && med->media.remotePort == 27864, "media leg targets the gateway");
}
// ---- a gateway offering narrowband AMR (octet-aligned) + G.711: AMR wins
{
imsd::util::Rng rng(31);
std::string sdp =
"v=0\r\no=- 6 6 IN IP6 2001:db8::30c\r\ns=-\r\n"
"c=IN IP6 2001:db8::30c\r\nt=0 0\r\n"
"m=audio 27866 RTP/AVP 8 100 110\r\n"
"a=rtpmap:100 AMR/8000/1\r\na=fmtp:100 octet-align=1;mode-set=0,2,4,7\r\n"
"a=rtpmap:110 telephone-event/8000\r\n";
CallMachine m(c, rng, "ims-call-12", IncomingInvite{MtInviteSdp("mt-amrnb", sdp)}, 50004);
auto ai = m.OnInvite();
Check(Responded(ai, "SIP/2.0 180 Ringing") != nullptr, "AMR-NB offer rings");
auto aa = m.OnAccept();
const Action* ok = Responded(aa, "SIP/2.0 200 OK");
Check(ok && ok->text.contains("m=audio 50004 RTP/AVP 100 110\r\n"), "answer picks AMR over PCMA");
Check(ok && ok->text.contains("a=rtpmap:100 AMR/8000/1\r\n") && ok->text.contains("a=fmtp:100 octet-align=1\r\n"), "answer mirrors octet-aligned AMR");
const Action* med = Find(aa, Action::Type::StartMedia);
Check(med && med->media.codec == "AMR" && med->media.payloadType == 100 && med->media.octetAlign, "media leg starts octet-aligned AMR pt 100");
}
// ---- a mobile caller offering everything: still AMR-WB (no regression)
{
imsd::util::Rng rng(33);
std::string sdp =
"v=0\r\no=- 7 7 IN IP6 2001:db8::310\r\ns=-\r\n"
"c=IN IP6 2001:db8::310\r\nt=0 0\r\n"
"m=audio 27868 RTP/AVP 116 107 8 100 111 110 13\r\n"
"a=rtpmap:116 AMR-WB/16000/1\r\na=fmtp:116 mode-change-capability=2;max-red=0\r\n"
"a=rtpmap:107 AMR-WB/16000/1\r\na=fmtp:107 octet-align=1;mode-change-capability=2;max-red=0\r\n"
"a=rtpmap:100 AMR/8000/1\r\na=rtpmap:111 telephone-event/16000\r\n"
"a=rtpmap:110 telephone-event/8000\r\na=rtpmap:13 CN/8000\r\n";
CallMachine m(c, rng, "ims-call-13", IncomingInvite{MtInviteSdp("mt-mobile", sdp)}, 50004);
m.OnInvite();
auto aa = m.OnAccept();
const Action* ok = Responded(aa, "SIP/2.0 200 OK");
Check(ok && ok->text.contains("m=audio 50004 RTP/AVP 107 111\r\n"), "mobile caller answered with octet-aligned AMR-WB + wideband DTMF");
const Action* med = Find(aa, Action::Type::StartMedia);
Check(med && med->media.codec == "AMR-WB" && med->media.payloadType == 107, "media leg stays AMR-WB for a mobile caller");
}
// ---- offer we cannot serve (nothing we play): 488 before ringing, and
// the log names what was offered
{
imsd::util::Rng rng(35);
std::string sdp =
"v=0\r\no=- 8 8 IN IP6 2001:db8::30c\r\ns=-\r\n"
"c=IN IP6 2001:db8::30c\r\nt=0 0\r\n"
"m=audio 27864 RTP/AVP 18 101\r\na=rtpmap:18 G729/8000\r\na=rtpmap:101 telephone-event/8000\r\n";
CallMachine m(c, rng, "ims-call-14", IncomingInvite{MtInviteSdp("mt-g729", sdp)}, 50004);
auto ai = m.OnInvite();
Check(Responded(ai, "SIP/2.0 488 Not Acceptable Here") != nullptr, "G729-only offer refused with 488");
Check(Responded(ai, "SIP/2.0 180 Ringing") == nullptr, "no 180 for a 488");
Check(m.Terminated(), "terminated on 488");
bool named = false;
for (const auto& x : ai)
if (x.type == Action::Type::Log && x.text.contains("offered: 18 G729, 101 TELEPHONE-EVENT")) named = true;
Check(named, "488 log names the offered codecs");
}
// ---- no audio line at all: 488 too
{
imsd::util::Rng rng(37);
CallMachine m(c, rng, "ims-call-15", IncomingInvite{MtInviteSdp("mt-noaudio", "v=0\r\no=- 9 9 IN IP6 2001:db8::30c\r\ns=-\r\nc=IN IP6 2001:db8::30c\r\nt=0 0\r\n")}, 50004);
auto ai = m.OnInvite();
Check(Responded(ai, "SIP/2.0 488 Not Acceptable Here") != nullptr, "offer without m=audio refused with 488");
Check(m.Terminated(), "terminated on 488 (no audio line)");
}
// ---- ring timeout: 480, missed call
{
imsd::util::Rng rng(31);
CallMachine m(c, rng, "ims-call-12", IncomingInvite{MtInvite()}, 50004);
m.OnInvite();
auto ad = m.OnDeadline();
Check(Responded(ad, "SIP/2.0 480 Temporarily Unavailable") != nullptr, "ring timeout sends 480");
const Action* t = Find(ad, Action::Type::State);
Check(t && t->reason == "remote-hangup", "timeout reads as missed");
Check(m.Terminated(), "terminated on ring timeout");
}
// ---- our BYE after accepting: UAS dialog fields hold
{
imsd::util::Rng rng(33);
CallMachine m(c, rng, "ims-call-13", IncomingInvite{MtInvite()}, 50004);
m.OnInvite();
m.OnAccept();
auto ah = m.OnHangup();
const Action* bye = Sent(ah, "BYE ");
Check(bye != nullptr, "hangup after accept sends BYE");
Check(bye && bye->text.starts_with("BYE sip:origgw@[2001:db8::9]:5060 SIP/2.0"), "BYE targets the caller's Contact");
Check(bye && bye->text.contains("CSeq: 1 BYE\r\n"), "our UAS CSeq space starts at 1");
Check(bye && bye->text.contains("To: <sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone>" ";tag=caller1\r\n"), "BYE To is the caller (their tag)");
2026-09-08 20:37:47 +02:00
Check(bye && bye->text.contains("From: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org;user=phone>;tag="), "UAS BYE From is the INVITE's To URI (our tag), not the IMSI IMPU");
Check(bye && !bye->text.contains("001010123456789@ims"), "UAS BYE carries no IMSI-derived identity");
// UAS route set: Record-Route in RECEIVED order
Check(bye && bye->text.contains("Route: <sip:[2001:db8::105]:5100;lr>, " "<sip:[2001:db8::9]:5060;lr>\r\n"), "BYE routes via Record-Route in received order");
const Action* t = Find(ah, Action::Type::State);
Check(t && t->reason == "local-hangup", "active hangup -> local-hangup");
}
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
// ---- an incoming call whose INVITE carries its header names in compact
// form (RFC 3261 7.3.3: "MUST accept both the long and short forms"):
// the same dialog as from the long names
{
const std::string invite = Compact(MtInvite());
Check(!invite.contains("Via:") && !invite.contains("From:") && !invite.contains("\r\nTo:") && !invite.contains("Call-ID:") && !invite.contains("Contact:") && !invite.contains("Session-Expires:") && !invite.contains("Content-Type:") && !invite.contains("Content-Length:"), "the compact INVITE carries none of the eight long names");
Check(invite.contains("\r\nv: SIP/2.0/UDP [2001:db8::9]:5060;branch=z9hG4bKscscf1\r\n") && invite.contains("\r\ni: mt-call-abc123\r\n") && invite.contains("\r\nx: 1800\r\n") && invite.ends_with("a=ptime:20\r\na=sendrecv\r\n"), "...their compact forms instead, the body untouched");
imsd::util::Rng rng(33);
CallMachine m(c, rng, "ims-call-70", IncomingInvite{invite}, 50004);
Check(m.CallId() == "mt-call-abc123" && m.Number() == "+31612345678", "compact INVITE: the Call-ID from `i:`");
auto ai = m.OnInvite();
const Action* ringing = Responded(ai, "SIP/2.0 180 Ringing");
Check(ringing && ringing->text.contains("\r\nVia: SIP/2.0/UDP [2001:db8::105]:5100;branch=z9hG4bKpcscf1\r\nVia: SIP/2.0/UDP [2001:db8::9]:5060;branch=z9hG4bKscscf1\r\n"), "compact INVITE: the 180 echoes both `v:` rows, in order, as Via");
Check(ringing && ringing->text.contains("\r\nFrom: <sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone>;tag=caller1\r\n") && ringing->text.contains("\r\nTo: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org;user=phone>;tag=") && ringing->text.contains("\r\nCall-ID: mt-call-abc123\r\n"), "compact INVITE: the 180 echoes the `f:`, the `t:` with our tag and the `i:`");
auto aa = m.OnAccept();
const Action* ok = Responded(aa, "SIP/2.0 200 OK");
const Action* media = Find(aa, Action::Type::StartMedia);
Check(ok && ok->text.contains("Session-Expires: 1800;refresher=uac\r\n") && media && media->media.remotePort == 27864 && m.State() == CallState::Active, "compact INVITE: the 200 echoes the `x:` session timer, the offer is answered");
// a refresh whose Session-Expires comes as `x:`
const std::string upd = Compact(std::format(
"UPDATE sip:me SIP/2.0\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKu2\r\n"
"From: <sip:+31612345678@ims;user=phone>;tag=caller1\r\n"
"To: <sip:+31611111111@ims;user=phone>;tag=x\r\n"
"Min-SE: 90\r\nSession-Expires: 1800;refresher=uac\r\n"
"Call-ID: {}\r\nCSeq: 3 UPDATE\r\nContent-Length: 0\r\n\r\n", m.CallId()));
auto au = m.OnRequest(upd);
const Action* se200 = Responded(au, "SIP/2.0 200 OK");
Check(upd.contains("\r\nx: 1800;refresher=uac\r\n") && se200 && se200->text.contains("Session-Expires: 1800;refresher=uac\r\n") && se200->text.contains("\r\nVia: SIP/2.0/UDP [x]:1;branch=z9hG4bKu2\r\n") && se200->text.contains(std::format("\r\nCall-ID: {}\r\n", m.CallId())), "compact UPDATE: the 200 echoes the `x:` timer and the `v:`, `i:` rows");
// our BYE: to the caller's `m:` Contact, the `f:` From as its To, the `t:` To's URI as its From
auto ah = m.OnHangup();
const Action* bye = Sent(ah, "BYE ");
Check(bye && bye->text.starts_with("BYE sip:origgw@[2001:db8::9]:5060 SIP/2.0\r\n") && bye->text.contains("\r\nTo: <sip:+31612345678@ims.mnc001.mcc001.3gppnetwork.org;user=phone>;tag=caller1\r\n") && bye->text.contains("\r\nFrom: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org;user=phone>;tag=") && bye->text.contains("\r\nCall-ID: mt-call-abc123\r\n"), "compact INVITE: our BYE goes to the `m:` Contact with the dialog the `f:`, `t:` and `i:` rows made");
}
// ---- an outgoing call whose responses carry compact names: the dialog
// from `t:` and `m:`
{
imsd::util::Rng rng(42);
CallMachine m(c, rng, "ims-call-71", "1233", 50004, false);
m.Start();
const std::string r183 = Compact(R183(m.CallId())), r200 = Compact(R200(m.CallId()));
Check(!r183.contains("\r\nTo:") && !r183.contains("Contact:") && r183.contains("\r\nt: <sip:1233@ims>;tag=remote7\r\n") && r200.contains("\r\nm: <sip:termgw@[2001:db8::9]:5060>\r\n"), "the compact responses carry `t:` and `m:`");
auto a183 = m.OnInviteResponse(r183);
const Action* prack = Sent(a183, "PRACK ");
Check(prack && prack->text.starts_with("PRACK sip:termgw@[2001:db8::9]:5060 SIP/2.0\r\n") && prack->text.contains("\r\nTo: <sip:1233@ims>;tag=remote7\r\n"), "compact 183: the PRACK targets the `m:` Contact and carries the `t:` To");
auto a200 = m.OnInviteResponse(r200);
const Action* ack = Sent(a200, "ACK ");
Check(ack && ack->text.starts_with("ACK sip:termgw@[2001:db8::9]:5060 SIP/2.0\r\n") && ack->text.contains("\r\nTo: <sip:1233@ims>;tag=remote7\r\n") && Has(a200, Action::Type::StartMedia) && m.State() == CallState::Active, "compact 200: the ACK to the `m:` Contact with the `t:` To, the call active");
}
// ---- media death after accept releases the call
{
imsd::util::Rng rng(35);
CallMachine m(c, rng, "ims-call-14", IncomingInvite{MtInvite()}, 50004);
m.OnInvite();
m.OnAccept();
auto amx = m.OnMediaExit(3);
Check(Sent(amx, "BYE ") != nullptr, "media far-end hangup sends BYE (incoming too)");
Check(m.Terminated(), "terminated");
}
// ================= emergency (stage 1) ================================
// ---- emergency dial: the INVITE targets the sos URN over the normal
// registration; a 200 is answered like any call
{
imsd::util::Rng rng(41);
CallMachine m(c, rng, "ims-call-15", "112", 50004, false, /*emergency=*/true);
auto start = m.Start();
const Action* inv = Sent(start, "INVITE ");
Check(inv && inv->text.starts_with("INVITE urn:service:sos SIP/2.0\r\n"), "emergency R-URI is the sos URN");
Check(inv && inv->text.contains("To: <urn:service:sos>\r\n"), "emergency To carries the URN");
Check(inv && inv->text.contains("Route: <sip:[2001:db8::105]:6000;lr>\r\n"), "emergency INVITE rides the registration route");
Check(inv && inv->text.contains("m=audio"), "emergency INVITE carries an SDP offer");
Check(Has(start, Action::Type::SetDeadline), "emergency dial arms the timeout");
auto a200 = m.OnInviteResponse(R200(m.CallId()));
Check(Sent(a200, "ACK ") != nullptr, "sos 200 is ACKed");
Check(Has(a200, Action::Type::StartMedia), "sos answer starts media");
Check(m.State() == CallState::Active, "sos call active");
}
// ---- sos rejected -> one fallback: a fresh-dialog plain INVITE of the
// digits, whose answer is then taken normally
{
imsd::util::Rng rng(43);
CallMachine m(c, rng, "ims-call-16", "112", 50004, false, true);
m.Start();
std::string firstId = m.CallId();
auto a = m.OnInviteResponse(Final(m.CallId(), 500, "Server Internal Error"));
Check(Sent(a, "ACK ") != nullptr, "sos final is ACKed");
const Action* inv2 = Sent(a, "INVITE ");
Check(inv2 && inv2->text.starts_with("INVITE sip:112;phone-context="), "fallback INVITE dials the digits");
Check(m.CallId() != firstId, "fallback is a fresh dialog");
Check(inv2 && inv2->text.contains(std::format("Call-ID: {}\r\n", m.CallId())), "fallback INVITE carries the new Call-ID");
Check(inv2 && inv2->text.contains("CSeq: 1 INVITE\r\n"), "fallback INVITE restarts CSeq");
Check(Has(a, Action::Type::SetDeadline), "fallback re-arms the timeout");
Check(!m.Terminated(), "machine survives into the fallback");
auto a2 = m.OnInviteResponse(R200(m.CallId()));
Check(Has(a2, Action::Type::StartMedia), "fallback answer starts media");
Check(m.State() == CallState::Active, "active on the fallback leg");
}
imsd: when the client flow is found dead before any response to a call's INVITE, one reconnect and the INVITE again, else the call ends A flow that is dead in a way imsd has not seen yet, the peer having dropped the connection's state, shows itself at the next bytes sent on it, where the peer answers them with a reset. Where those bytes were an outgoing call's INVITE, imsd read the reset, marked the flow dead and did nothing more for the call: no reconnect runs while a call is up, so the attempt stayed in `dialing` until its setup deadline, 90 s, sent a CANCEL that could not go out and was given up 10 s later, where a call that is no emergency call ends (`setup deadline expired`); the flow was reconnected only once the call was gone. Against a stand-in network that forgets a flow after 20 s of silence, 1.2.3's call ended 100 s after the Dial. The engine's loop now takes such a call up (MaybeResendInvite). When the client flow is found dead under an outgoing attempt whose INVITE has had no response, a 100 included, and no CANCEL, the dead socket is closed without a FIN's exchange, the flow is reopened with one connect and the same INVITE is sent again, the setup deadline running from then. Once per attempt: an emergency call's fallback attempt has a resend of its own. The INVITE is the first one byte for byte, its branch included, so a server that did receive the first matches the second to its transaction (RFC 3261 17.2.3). No REGISTER goes first: the registration and its SAs stand, and TS 33.203 7.1 has a UE with no TCP connection towards the P-CSCF set one up before it sends a request. Where a reg-event NOTIFY has ended the binding nothing is reopened. Where nothing is reopened, the connect fails (one that gets no answer, after 12 s) or the flow dies again before a response, the call ends with `error`, an emergency call's first attempt too: there is no flow for its fallback. The recovery policy takes the flow up once the call is gone, as before. The close without a FIN's exchange is for a flow the peer closed: closed the usual way, such a socket stays in the kernel's table until the peer has acknowledged imsd's own FIN, and a connect from its port before that is refused. A reset goes out in the FIN's place there; after a reset or the kernel's own giving up the socket is closed already and nothing is sent; and the reopen runs on a flow already found dead only. The recovery's reconnect closes the usual way, as before, and connects once more 10 s after such a refusal (one is in a user's log on O2, 2026-09-24, in the second the flow was found dead). Not changed: under a call, a flow that died with no reset and no close reaching the phone is found dead only when the kernel gives up on unacknowledged bytes, 924.6 s or more after them by its default tcp_retries2, so an attempt whose own INVITE is the first such bytes gets no response and is cancelled at its setup deadline, as before; a flow found dead after a response to the INVITE is not reopened, as before; a Dial whose INVITE cannot be sent ends its call at once, as before. Tested: tests/Engine (which attempt is sent again, the same bytes, once per attempt, the deadline anew, the call's end where the flow is lost); the daemon of this commit and 1.2.3's on the workstation against a stand-in network (the fp6 journal's 2026-11-24-crlf-keepalive capture, bench-dial.sh): a flow the network forgot, reopened and the INVITE answered 486 as on a live flow, where 1.2.3's call ended after 100 s; a flow the network closed at the INVITE, with the acknowledgement of the daemon's close kept back; one that died on the daemon's side at the kernel's retransmission limit; a network that takes no new connection, one that resets the second INVITE's flow too and one that has ended the binding, where the call ended within a second; UDP. And on the dev phone on KPN, the binary of the range's tip: a call to voicemail answered and hung up, and one whose flow was made to die under the INVITE before the INVITE left the phone: reopened from the same port, the INVITE again 2.1 s after the death was found, answered 0.2 s later. By a call, no P-CSCF that had dropped a flow's state has been met, and none that had received the first INVITE before the flow died.
2026-11-25 10:24:07 +01:00
// ---- the emergency chain with a flow that dies: each attempt has a
// resend of its own
{
imsd::util::Rng rng(44);
CallMachine m(c, rng, "ims-call-16b", "112", 50004, false, true);
auto start = m.Start();
auto again = m.OnFlowReopened();
const Action* sos = Sent(start, "INVITE ");
const Action* sos2 = Sent(again, "INVITE ");
Check(sos && sos2 && sos2->text == sos->text && sos2->text.starts_with("INVITE urn:service:sos "), "the sos INVITE again over a reopened flow");
auto a = m.OnInviteResponse(Final(m.CallId(), 500, "Server Internal Error"));
const Action* plain = Sent(a, "INVITE ");
Check(plain && plain->text.starts_with("INVITE sip:112;phone-context="), "the fallback follows a resent sos attempt as it follows a first one");
Check(m.Unanswered() && m.ResendDue(), "the fallback attempt has a resend of its own");
auto again2 = m.OnFlowReopened();
const Action* plain2 = Sent(again2, "INVITE ");
Check(plain && plain2 && plain2->text == plain->text, "... of the fallback's INVITE");
imsd::util::Rng rng2(45);
CallMachine n(c, rng2, "ims-call-16c", "112", 50004, false, true);
n.Start();
auto lost = n.OnFlowLost();
const Action* t = Find(lost, Action::Type::State);
Check(t && t->reason == "error" && n.Terminated() && Sent(lost, "INVITE ") == nullptr, "a sos attempt whose flow is lost ends there: no fallback INVITE onto a dead flow");
}
// ---- chain exhausted: the fallback leg's final terminates, no 3rd try
{
imsd::util::Rng rng(45);
CallMachine m(c, rng, "ims-call-17", "112", 50004, false, true);
m.Start();
m.OnInviteResponse(Final(m.CallId(), 500, "x")); // sos fails
auto a = m.OnInviteResponse(Final(m.CallId(), 486, "Busy Here"));
Check(Sent(a, "INVITE ") == nullptr, "no third attempt");
const Action* t = Find(a, Action::Type::State);
Check(t && t->reason == "refused-or-busy", "fallback final keeps its own reason");
Check(m.Terminated(), "terminated when the chain is exhausted");
}
// ---- user hangup during the sos attempt kills the chain: 487 ends it
{
imsd::util::Rng rng(47);
CallMachine m(c, rng, "ims-call-18", "112", 50004, false, true);
m.Start();
auto ah = m.OnHangup();
Check(Sent(ah, "CANCEL ") != nullptr, "user hangup CANCELs the sos attempt");
auto a = m.OnInviteResponse(Final(m.CallId(), 487, "Request Terminated"));
Check(Sent(a, "INVITE ") == nullptr, "user cancel suppresses the fallback");
const Action* t = Find(a, Action::Type::State);
Check(t && t->reason == "local-hangup", "user-cancelled sos -> local-hangup");
Check(m.Terminated(), "terminated");
}
// ---- setup timeout on the sos attempt: CANCEL, then the 487 falls back
{
imsd::util::Rng rng(49);
CallMachine m(c, rng, "ims-call-19", "112", 50004, false, true);
m.Start();
auto a1 = m.OnDeadline();
Check(Sent(a1, "CANCEL ") != nullptr, "sos timeout CANCELs");
auto a2 = m.OnInviteResponse(Final(m.CallId(), 487, "Request Terminated"));
Check(Sent(a2, "INVITE sip:112;phone-context=") != nullptr, "timeout-cancelled sos falls back to the digits");
Check(!m.Terminated(), "chain continues after the timeout");
}
// ---- timeout CANCEL whose 487 never comes: second deadline falls back
{
imsd::util::Rng rng(51);
CallMachine m(c, rng, "ims-call-20", "112", 50004, false, true);
m.Start();
m.OnDeadline(); // CANCEL
auto a = m.OnDeadline(); // no 487 arrived
Check(Sent(a, "INVITE sip:112;phone-context=") != nullptr, "silent sos attempt still gets its fallback");
Check(!m.Terminated(), "not terminated while the chain has a step left");
}
// ---- answered during a DEADLINE-initiated CANCEL race: taken, not BYEd
{
imsd::util::Rng rng(53);
CallMachine m(c, rng, "ims-call-21", "112", 50004, false, true);
m.Start();
m.OnDeadline(); // CANCEL (not the user)
auto ar = m.OnInviteResponse(R200(m.CallId()));
Check(Sent(ar, "ACK ") != nullptr, "race 200 is ACKed");
Check(Sent(ar, "BYE ") == nullptr, "deadline race keeps the answered call");
Check(Has(ar, Action::Type::StartMedia), "deadline race starts media");
Check(m.State() == CallState::Active, "active after the deadline race");
}
// ---- network 380 with the emergency indication upgrades a plain call
// to sos; if that also fails the chain ends (plain already tried)
{
imsd::util::Rng rng(55);
CallMachine m(c, rng, "ims-call-22", "0612345678", 50004, false); // NOT classified
m.Start();
auto a = m.OnInviteResponse(Alt380(m.CallId(), EmergencyXml));
Check(Sent(a, "ACK ") != nullptr, "380 is ACKed");
const Action* inv = Sent(a, "INVITE ");
Check(inv && inv->text.starts_with("INVITE urn:service:sos SIP/2.0\r\n"), "emergency 380 upgrades to the sos URN");
Check(!m.Terminated(), "call survives into the sos attempt");
auto a2 = m.OnInviteResponse(Final(m.CallId(), 500, "x"));
Check(Sent(a2, "INVITE ") == nullptr, "no loop back to the already-tried plain leg");
Check(m.Terminated(), "terminated after the upgraded attempt fails");
}
// ---- a bare 380 (no emergency indication) is an error, never sos
{
imsd::util::Rng rng(57);
CallMachine m(c, rng, "ims-call-23", "0612345678", 50004, false);
m.Start();
auto a = m.OnInviteResponse(Alt380(m.CallId(), ""));
Check(Sent(a, "INVITE ") == nullptr, "bare 380 places no emergency call");
const Action* t = Find(a, Action::Type::State);
Check(t && t->reason == "error", "bare 380 -> error");
Check(m.Terminated(), "terminated on bare 380");
}
// ---- Abandon (emergency preemption): terminate bookkeeping only
{
imsd::util::Rng rng(59);
CallMachine m(c, rng, "ims-call-24", "1233", 50004, false);
m.Start();
m.OnHangup(); // CANCEL sent, awaiting 487
auto a = m.Abandon("preempted by emergency dial");
Check(Sent(a, "BYE ") == nullptr && Sent(a, "CANCEL ") == nullptr, "Abandon sends nothing further");
Check(Has(a, Action::Type::Deleted), "Abandon deletes the call");
Check(m.Terminated(), "abandoned machine is terminated");
}
// ---- CODECS override, terminating side: the transcoding gateway's
// mixed offer (KPN 2026-09-08) answered with G.711 A-law because the
// list says so — the on-air narrowband bench path
{
imsd::util::Rng rng(51);
std::string sdp =
"v=0\r\no=LucentPCSF 1 1 IN IP6 2001:db8::309\r\ns=-\r\n"
"c=IN IP6 2001:db8::309\r\nt=0 0\r\n"
"m=audio 41166 RTP/AVP 8 0 100 96 101 13 106\r\n"
"a=rtpmap:8 PCMA/8000\r\na=rtpmap:0 PCMU/8000\r\n"
"a=rtpmap:100 AMR/8000\r\na=fmtp:100 mode-change-period=2\r\n"
"a=rtpmap:96 AMR-WB/16000\r\na=fmtp:96 mode-change-period=2\r\n"
"a=rtpmap:101 telephone-event/8000\r\na=fmtp:101 0-15\r\n"
"a=rtpmap:106 telephone-event/16000\r\na=fmtp:106 0-15\r\n"
"a=sendrecv\r\na=ptime:20\r\na=maxptime:60\r\n";
CallMachine m(c, rng, "ims-call-20", IncomingInvite{MtInviteSdp("mt-kpn-pcma", sdp)}, 50004, {"PCMA"});
auto ai = m.OnInvite();
Check(Responded(ai, "SIP/2.0 180 Ringing") != nullptr, "CODECS=PCMA: mixed offer rings");
auto aa = m.OnAccept();
const Action* ok = Responded(aa, "SIP/2.0 200 OK");
Check(ok && ok->text.contains("m=audio 50004 RTP/AVP 8 101\r\n"), "CODECS=PCMA: answer is PCMA + narrowband DTMF at the offer's pts");
Check(ok && ok->text.contains("a=rtpmap:8 PCMA/8000/1\r\n") && !ok->text.contains("AMR"), "CODECS=PCMA: no AMR in the answer");
const Action* med = Find(aa, Action::Type::StartMedia);
Check(med && med->media.codec == "PCMA" && med->media.payloadType == 8 && !med->media.octetAlign, "CODECS=PCMA: media leg starts G.711 A-law");
// same offer, CODECS=AMR: narrowband AMR, bandwidth-efficient as offered
imsd::util::Rng rng2(52);
CallMachine m2(c, rng2, "ims-call-21", IncomingInvite{MtInviteSdp("mt-kpn-amr", sdp)}, 50004, {"AMR"});
m2.OnInvite();
auto aa2 = m2.OnAccept();
const Action* ok2 = Responded(aa2, "SIP/2.0 200 OK");
Check(ok2 && ok2->text.contains("m=audio 50004 RTP/AVP 100 101\r\n") && !ok2->text.contains("octet-align"), "CODECS=AMR: answer is AMR-NB BE + narrowband DTMF");
const Action* med2 = Find(aa2, Action::Type::StartMedia);
Check(med2 && med2->media.codec == "AMR" && med2->media.payloadType == 100 && !med2->media.octetAlign, "CODECS=AMR: media leg starts AMR-NB BE");
// same offer, no override: unchanged — AMR-WB
imsd::util::Rng rng3(53);
CallMachine m3(c, rng3, "ims-call-22", IncomingInvite{MtInviteSdp("mt-kpn-default", sdp)}, 50004);
m3.OnInvite();
auto aa3 = m3.OnAccept();
const Action* med3 = Find(aa3, Action::Type::StartMedia);
Check(med3 && med3->media.codec == "AMR-WB" && med3->media.payloadType == 96, "no override: the same offer still lands on AMR-WB");
}
// ---- CODECS override, originating side: the INVITE offers only what the
// list names (G.711 = a landline-shaped offer toward the network)
{
imsd::util::Rng rng(54);
CallMachine m(c, rng, "ims-call-23", "0101234567", 50004, false, false, {"PCMA", "PCMU"});
auto start = m.Start();
const Action* inv = Sent(start, "INVITE ");
Check(inv && inv->text.contains("m=audio 50004 RTP/AVP 8 0 100\r\n"), "CODECS=PCMA,PCMU: INVITE offers G.711 only");
Check(inv && !inv->text.contains("AMR"), "CODECS=PCMA,PCMU: no AMR in the offer");
Check(inv && inv->text.contains("a=rtpmap:100 telephone-event/8000\r\n") && !inv->text.contains("telephone-event/16000"), "CODECS=PCMA,PCMU: narrowband DTMF only");
}
2026-09-08 20:37:47 +02:00
// ---- MO with the registered sip: identity learned (the normal case on a
// live network): From, CANCEL and BYE all carry it, never the IMSI
{
Context ca = MakeCtx();
ca.aor = "sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org";
imsd::util::Rng rng(61);
CallMachine m(ca, rng, "ims-call-30", "1233", 50004, false);
auto start = m.Start();
const Action* inv = Sent(start, "INVITE ");
Check(inv && inv->text.contains("\r\nFrom: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org>;tag="), "MO INVITE From is the registered sip: identity");
auto cancel = m.OnHangup();
const Action* can = Sent(cancel, "CANCEL ");
Check(can && can->text.contains("\r\nFrom: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org>;tag="), "CANCEL From is the same identity");
Check(can && !can->text.contains("001010123456789@ims"), "CANCEL carries no IMSI");
}
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
// ---- RegRecovery: when a registration stops working after bring-up.
// The clock is ours: seconds, starting at 1000.
{
using F = RegRecovery::Failure;
using S = RegRecovery::Step;
auto reconnectAt = [](const RegRecovery& r, double now, double at) { auto p = r.Next(now); return p.step == S::Reconnect && p.at == at; };
auto freshAt = [](const RegRecovery& r, double now, double at) { auto p = r.Next(now); return p.step == S::Fresh && p.at == at; };
RegRecovery r;
Check(!r.Fresh() && r.Reconnectable() && reconnectAt(r, 1000, 0), "the first step is a reconnect, at once");
r.OnLocalRefusal(1000);
Check(r.refusals == 0 && r.silentCycles == 0 && r.reconnectDelay == 5 && reconnectAt(r, 1000, 1005), "a local connect refusal: retried in 5 s, not counted, backoff untouched");
// O2 2026-09-24, 09:29: the keepalive refresh refused (503), then a
// reconnect's refresh refused again -> fresh, not a third refresh
r.OnReconnectFailure(1000, F::Refused);
Check(!r.Fresh() && reconnectAt(r, 1000, 1005), "first refusal: reconnect after 5 s, not yet an escalation");
r.OnReconnectFailure(1005, F::Refused);
Check(r.Fresh() && r.refusals == 2 && freshAt(r, 1005, 1015), "second refusal: escalated, the fresh attempt after the doubled backoff");
Check(r.Reconnectable(), "…and the old SA is still there");
r.OnSuccess();
Check(!r.Fresh() && r.refusals == 0 && r.reconnectDelay == 5, "success resets the policy");
// Retry-After is the network's word: it holds every attempt for its
// own length, next to the backoff, and a Dial cuts only the backoff
r.OnReconnectFailure(1000, F::Refused, 90);
Check(r.Fresh() && r.Reconnectable() && freshAt(r, 1000, 1090), "a refusal with a Retry-After escalates at once: the fresh attempt behind the network's wait (O2 2026-10-08), the old SA kept");
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
r.OnDial();
Check(freshAt(r, 1000, 1090), "…and a Dial does not cut it");
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
r.OnReconnectFailure(1090, F::Refused, 3);
Check(r.Fresh() && freshAt(r, 1090, 1100), "a Retry-After shorter than the backoff does not shorten it");
r.OnDial();
Check(freshAt(r, 1090, 1093), "…but a Dial cuts the backoff down to it, no further");
r.OnSuccess();
// a 403 once a fresh registration is due: the old registration is gone
{
RegRecovery k;
k.OnReconnectFailure(1000, F::Refused, 0, 403);
Check(!k.Fresh() && k.Reconnectable(), "a first 403 is a refusal like the others");
k.OnReconnectFailure(1005, F::Refused, 0, 403);
Check(k.Fresh() && !k.Reconnectable() && freshAt(k, 1005, 1015), "a 403 once fresh is due: gone, the fresh attempt after the backoff");
k.OnSuccess();
Check(k.Reconnectable(), "success forgets it");
}
engine, messages, util, imsd: the reregistration carries the last challenge answer and new SA parameters The keepalive refresh and the resume's re-REGISTER carried an initial registration's first-REGISTER Authorization — an empty nonce and response — in the second REGISTER's frame, with a Security-Client naming the SPIs and ports in use. TS 24.229 5.1.1.4.2 has a reregistration carry the Authorization of the last successful authentication — the last received nonce and the last calculated response — and a Security-Client with the new parameter values for the two SA pairs a re-authentication would set up; TS 33.203 7.4.0 keeps the server ports and changes the client ports. O2 UK refused the refresh of the old shape with 503 on every occasion on record (alyx, 2026-09-24 to 10-08, a stationary phone included) and accepted the fresh registrations that followed; KPN accepted the old shape without a challenge. The fresh registration now records the 401's nonce, our cnonce and the response in the registration state (auth_nonce, auth_cnonce, auth_response in the state file); a reregistration sends them verbatim, mints new SPIs and proposes PortUcNext (45063) as the client port with the server port unchanged. A registration resumed from a state file written before this change has no answer: its reregistrations carry the empty digest, as before, until its next fresh registration, and the resume says so. A 401 to a reregistration asks for re-authentication over temporary SAs on the proposed ports (TS 24.229 5.1.1.5.1), which imsd does not implement: the refresh throws it as a refusal and RegRecovery makes the next step the fresh registration, replacing the in-place answer over the old SAs. Tested with the Messages and Engine suites and on the dev phone (KPN) with a build of this commit's tree: a resume from the previous state file, a fresh registration, a resume that sent the stored answer, three refreshes at a 120-s interval, an outgoing call to a bench line and an incoming call's ring.
2026-10-10 21:00:28 +02:00
// a 401 to a refresh asks for re-authentication over temporary SAs,
// which imsd does not do: the fresh registration at once, the old
// SA kept (the network still holds the registration)
{
RegRecovery j;
j.OnReconnectFailure(1000, F::Refused, 0, 401);
Check(j.Fresh() && j.Reconnectable() && j.refusals == 1 && freshAt(j, 1000, 1005), "a 401 on the first refusal: the fresh attempt after the backoff");
RegRecovery jr;
jr.OnReconnectFailure(1000, F::Refused, 0, 503);
Check(!jr.Fresh() && reconnectAt(jr, 1000, 1005), "a bare 503 (no Retry-After) is still the hiccup case: one more refresh first");
}
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
// O2 10:43: the flow killed 8 s after the 200, every SYN unanswered
r.OnReconnectFailure(1000, F::Silent);
Check(!r.Fresh() && reconnectAt(r, 1000, 1005), "first silent cycle: retry in 5 s");
r.OnReconnectFailure(1005, F::Silent);
Check(r.Fresh() && r.silentCycles == 2, "two silent cycles escalate");
// a mix: one refusal + one silence keeps reconnecting (neither
// threshold reached)
RegRecovery m;
m.OnReconnectFailure(1000, F::Refused);
m.OnReconnectFailure(1000, F::Silent);
Check(!m.Fresh(), "one refusal + one silence: still reconnecting");
m.OnReconnectFailure(1000, F::Silent);
Check(m.Fresh(), "…until a threshold is reached");
// the reconnect backoff caps at 5 min
RegRecovery b;
for (int i = 0; i < 10; i++) b.OnReconnectFailure(1000, F::Silent);
Check(b.reconnectDelay == 300 && b.Next(1000).at == 1300, "reconnect backoff caps at 300 s");
// fresh attempts: silence backs off 30 s -> 10 min (a Dial may cut
// it); a refusal or a throttle holds on the throttle schedule (21
// min growing to 60), the network's word, and the old SA is
// reconnected meanwhile
RegRecovery f;
f.OldGone();
Check(f.Fresh() && !f.Reconnectable() && freshAt(f, 1000, 0), "the old registration gone: fresh now, nothing to reconnect to");
f.OnFreshFailure(1000, F::Silent);
Check(freshAt(f, 1000, 1030), "silent fresh attempt: 30 s");
f.OnDial();
Check(freshAt(f, 1000, 0), "…which a Dial cuts");
f.OnFreshFailure(1030, F::Silent);
Check(freshAt(f, 1030, 1090), "…then 60 s");
double last = 0;
for (int i = 0; i < 8; i++) { f.OnFreshFailure(2000, F::Silent); last = f.Next(2000).at - 2000; }
Check(last == 600 && f.freshAttempts == 10, "silent fresh backoff caps at 600 s; attempts counted");
RegRecovery g;
g.OnReconnectFailure(1000, F::Refused); g.OnReconnectFailure(1000, F::Refused); // escalated, backoff 5 then 10
g.OnFreshFailure(1010, F::Refused);
Check(g.Reconnectable() && reconnectAt(g, 1010, 1030) && g.freshHoldUntil == 1010 + 21 * 60, "refused fresh attempt: the old SA is reconnected after the backoff, the next fresh attempt held 21 min");
Check(freshAt(g, 1010 + 21 * 60, 1010 + 21 * 60), "…and runs once the hold ends");
g.OnDial();
Check(g.Next(1010).step == S::Reconnect && g.Next(1010).at <= 1010, "a Dial meanwhile: the reconnect at once, never the held fresh attempt");
g.OnFreshFailure(2000, F::Throttled);
Check(g.freshHoldUntil == 2000 + 31 * 60, "throttled next: 31 min (×1.5)");
g.OnFreshFailure(3000, F::Refused);
Check(g.freshHoldUntil == 3000 + 46 * 60, "then 46 min");
g.OnFreshFailure(4000, F::Refused);
Check(g.freshHoldUntil == 4000 + 60 * 60, "capped at 60 min");
g.OnFreshFailure(5000, F::Refused);
Check(g.freshHoldUntil == 5000 + 60 * 60, "stays at 60 min");
g.OnFreshFailure(6000, F::Refused, 7200);
Check(g.freshHoldUntil == 6000 + 3600, "a Retry-After beyond an hour is cut to the hour, the schedule's own ceiling");
RegRecovery ra;
ra.OnFreshFailure(1000, F::Refused, 2700);
Check(ra.freshHoldUntil == 3700, "a Retry-After longer than the schedule's wait holds for its own length");
ra.OnFreshFailure(5000, F::Refused, 86400);
Check(ra.freshHoldUntil == 5000 + 3600, "…a day's for an hour: the refusal is heard again then");
RegRecovery rb;
rb.OnReconnectFailure(1000, F::Refused, 86400);
Check(freshAt(rb, 1000, 1000 + 3600), "a refresh's Retry-After is cut to the hour the same, the fresh attempt behind it");
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
RegRecovery h;
h.OnFreshFailure(1000, F::Refused, 60);
Check(h.freshHoldUntil == 1060, "a refused fresh attempt with Retry-After 60 waits 60 s, not the schedule");
h.OnFreshFailure(1000, F::Refused, 5);
Check(h.freshHoldUntil == 1030, "…but never under the 30-s floor");
Check(h.throttleMinutes == 46, "the schedule still advances underneath (21 -> 31 -> 46)");
h.OnFreshFailure(1000, F::Silent, 600);
Check(h.freshHoldUntil == 1030 && h.Next(1000).at == 1030, "Retry-After is a refusal's word; silence keeps its own backoff");
Check(g.Fresh(), "a failed fresh attempt stays on the fresh step");
g.OnSuccess();
Check(!g.Fresh() && g.throttleMinutes == 21 && g.freshDelay == 30, "success resets the fresh schedule too");
// an attempt that got past the SA setup took the old SAs with it
{
RegRecovery s;
s.OnFreshFailure(1000, F::Silent, 0, /*saReplaced=*/true);
Check(!s.Reconnectable() && freshAt(s, 1000, 1030), "no reply past the SA setup: the old registration is gone, the next fresh attempt on the short backoff");
RegRecovery t;
t.OnFreshFailure(1000, F::Refused, 0, /*saReplaced=*/true);
Check(!t.Reconnectable() && freshAt(t, 1000, 1000 + 21 * 60), "refused past the SA setup: gone, and on the schedule");
}
engine: keep the reg-event subscription alive and act on a terminated binding The reg-event subscription is the network's own account of our binding (TS 24.229 5.1.1.3), and the daemon opened a new dialog for it at every refresh and reconnect and otherwise never looked back: a refused SUBSCRIBE was forgotten, an unanswered one had no timeout, an ended subscription got nothing until the next refresh's new dialog, and a NOTIFY was logged whatever it said. O2 UK, 2026-09-24: a fresh registration's SUBSCRIBE got 500, a NOTIFY arrived all the same and showed our contact active, the flow died eight seconds after the 200 and no connect over the SA succeeded after that; the 500 was logged and nothing was done about it. Keep the subscription alive: retry a refused or unanswered SUBSCRIBE on a backoff, renew one the S-CSCF ends with deactivated, timeout, giveup or probation (RFC 6665 4.1.3; after any other reason, or none, the next refresh subscribes anew), and subscribe anew ahead of the lifetime the S-CSCF granted. A refresh or a reconnect opens no dialog while imsd holds one for the registration or has a retry scheduled. Read the reginfo for our own contact and act on its state: a NOTIFY that terminates our binding schedules a fresh registration — at once for deactivated or expired, after the network's retry-after (up to an hour) for probation, on imsd's own refusal schedule (21 min, growing to 60) for rejected or unregistered (RFC 3680). A hold already running stands, and a REGISTER wait a call kept open that still gets its 200 after such a NOTIFY leaves that registration standing. The parser is in Imsd:Sip and pinned by tests/Sip with the O2 document shapes; the policy is RegRecovery's (OnBindingTerminated, added here with its tests in tests/Engine). Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-10-03 19:36:23 +02:00
// the network terminated our binding
{
RegRecovery n;
n.OnBindingTerminated(1000, "expired");
Check(n.Fresh() && !n.Reconnectable() && freshAt(n, 1000, 0), "expired: fresh now, nothing to reconnect to");
RegRecovery o;
o.OnBindingTerminated(1000, "probation", 300);
Check(freshAt(o, 1000, 1300), "probation: after the network's retry-after");
o.OnDial();
Check(freshAt(o, 1000, 1300), "…which a Dial does not cut");
RegRecovery p;
p.OnBindingTerminated(1000, "probation");
Check(freshAt(p, 1000, 1001), "probation without a retry-after: at least 1 s");
RegRecovery q;
q.OnBindingTerminated(1000, "rejected");
Check(freshAt(q, 1000, 1000 + 21 * 60) && !q.Reconnectable(), "rejected: on the refusal schedule, a hold, the old SA not retried");
q.OnBindingTerminated(1001, "rejected");
q.OnBindingTerminated(2000, "unregistered");
Check(q.freshHoldUntil == 1000 + 21 * 60 && q.throttleMinutes == 31, "the same termination reported again (another dialog, a retransmission): counted once");
RegRecovery u;
u.OnBindingTerminated(1000, "deactivated");
u.OnFreshFailure(1000, F::Silent);
u.OnBindingTerminated(1005, "deactivated");
Check(freshAt(u, 1005, 1030), "…nor does a repeat cut the backoff of the attempt made since");
RegRecovery v;
v.OnFreshFailure(1000, F::Refused, 3000);
v.OnBindingTerminated(1010, "rejected");
Check(!v.Reconnectable() && freshAt(v, 1010, 4000) && v.throttleMinutes == 46, "a rejected binding never shortens the network's Retry-After");
RegRecovery w;
w.OnBindingTerminated(1000, "probation", 3000);
w.OnBindingTerminated(1010, "probation", 60);
Check(freshAt(w, 1010, 4000), "…nor a second probation report the first one's retry-after");
RegRecovery x;
x.OnBindingTerminated(1000, "probation", 86400);
Check(freshAt(x, 1000, 1000 + 3600), "probation's retry-after is cut to the hour like a Retry-After");
// terminated while a reconnect cycle waited for its re-REGISTER final: the cycle's failure is no news
RegRecovery y;
y.OnReconnectFailure(1000, F::Silent);
y.OnBindingTerminated(1010, "expired");
y.OnReconnectFailure(1011, F::Silent);
Check(y.silentCycles == 1 && freshAt(y, 1011, 0), "the flow closed under the cycle: not a silent cycle, the fresh registration now");
y.OnReconnectFailure(1012, F::Refused, 90, 503);
Check(y.refusals == 0 && freshAt(y, 1012, 1102), "…a refusal with a Retry-After on it: not counted, the network's hold kept");
}
// a terminated binding's verdict outlives the process with its hold
{
RegRecovery tg;
tg.OnBindingTerminated(1000, "rejected");
auto htg = tg.Holds(1100);
Check(htg.Any() && htg.oldGone && htg.freshHold == 1000 + 21 * 60 - 1100, "a terminated binding's holds carry that the old registration is gone");
RegRecovery th;
th.Restore(50, htg);
Check(!th.Reconnectable() && freshAt(th, 50, 50 + htg.freshHold), "…and the restart does not reconnect over its SAs: the fresh attempt waits what was left");
RegRecovery ti;
ti.OnBindingTerminated(1000, "probation", 1800);
RegRecovery tj;
tj.Restore(0, ti.Holds(1300));
Check(!tj.Reconnectable() && freshAt(tj, 0, 1500), "probation's retry-after survives a restart the same way");
}
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
// the network's holds outlive the process
{
RegRecovery a;
a.OnReconnectFailure(1000, F::Refused); a.OnReconnectFailure(1000, F::Refused);
a.OnFreshFailure(1010, F::Throttled);
auto h = a.Holds(1100);
Check(h.Any() && h.hold == 0 && h.freshHold == 1010 + 21 * 60 - 1100 && h.throttleMinutes == 31, "holds: the seconds still to run and the schedule's place");
RegRecovery b;
b.Restore(50, h);
Check(reconnectAt(b, 50, 0) && b.throttleMinutes == 31, "restored fresh hold: the resume (a reconnect) is free at once");
b.OldGone();
Check(freshAt(b, 50, 50 + h.freshHold), "…and the fresh step waits what was left of it");
b.OnDial();
Check(freshAt(b, 50, 50 + h.freshHold), "…which a Dial does not cut");
RegRecovery c;
c.OnReconnectFailure(1000, F::Refused, 600);
RegRecovery d;
d.Restore(10, c.Holds(1200));
Check(reconnectAt(d, 10, 10 + 400), "restored Retry-After: no step before it ends");
d.Restore(20, RegRecovery::Held{30, 0, 21});
Check(reconnectAt(d, 20, 10 + 400), "a restore never shortens a hold");
Check(!RegRecovery{}.Holds(5).Any(), "no hold, nothing to keep");
auto k = a.Holds(1010 + 21 * 60 + 5);
Check(k.Any() && k.hold == 0 && k.freshHold == 0 && k.throttleMinutes == 31, "the hold run out, the schedule's place is still kept");
RegRecovery e;
e.Restore(10, k);
Check(reconnectAt(e, 10, 0) && e.throttleMinutes == 31, "…and a restart takes it over: no wait, the next refused or throttled fresh attempt on the advanced schedule");
e.OldGone(); e.OnFreshFailure(20, F::Throttled);
Check(freshAt(e, 20, 20 + 31 * 60), "…31 min, not 21");
RegRecovery g;
g.OnReconnectFailure(1000, F::Refused); g.OnReconnectFailure(1000, F::Refused, 0, 403);
auto hg = g.Holds(1100);
Check(hg.Any() && hg.oldGone, "a 403 once fresh is due: the holds carry that the old registration is gone");
RegRecovery h2;
h2.Restore(50, hg);
Check(!h2.Reconnectable() && h2.Fresh() && freshAt(h2, 50, 0), "…and the restart does not reconnect over its SAs: fresh at once");
RegRecovery i;
i.OnFreshFailure(1000, F::Throttled, 0, true);
auto hi = i.Holds(1100);
RegRecovery j;
j.Restore(50, hi);
Check(hi.oldGone && !j.Reconnectable() && freshAt(j, 50, 50 + hi.freshHold), "an attempt past the SA setup: gone travels with the hold, the restart waits it out without resuming");
RegRecovery m;
m.OldGone();
Check(m.Holds(5).Any() && m.Holds(5).oldGone && m.Holds(5).freshHold == 0, "gone with no hold left is still kept");
RegRecovery n;
n.Restore(5, m.Holds(5));
Check(!n.Reconnectable() && freshAt(n, 5, 0), "…so the next start registers fresh at once instead of resuming");
Check(!RegRecovery::Held{0, 0, 21, false}.Any(), "nothing gone, nothing held: nothing to keep");
ipsec, engine, imsd: the state file records the P-CSCF and a resume follows the kernel's SA peer A resume compared PCSCF= against the kernel's SAs and, when they did not match, registered fresh without a word — a second initial REGISTER from an address whose registration is live; on KPN a fresh pair to the same P-CSCF meets the 21-minute refusal that costs the live registration (§13), what another P-CSCF does with it is unmeasured. The registration was made to whatever P-CSCF the SAs name (the SA setup takes imsd's previous pair out first), so that is where a resume belongs: SaPeer reads it from the dir-out transport policies — the one address a reqid-1 and a reqid-2 policy both name, each with imsd's fixed protected port as its selector's sport (reqid and mode alone are anyone's): the state text cannot tell the UE from the P-CSCF, a lone policy is not ours and a VPN's beside the pair changes nothing — TryResume resumes there, routes it, and says so when PCSCF= differs; the next fresh registration moves to PCSCF= and moves back when it fails before the SA setup and the old registration still stands (its address still on the link), as it already did between addresses, and its fallback Route is the P-CSCF it registers at, set before the 200's Service-Route is looked for — an empty Service-Route value counts as none — so a move never keeps the previous node's route. A file left by an attempt that got through the SA setup and did not live to record — to this or another P-CSCF — is recognised by its SA pair: the file's spi_uc/spi_us (a 0.3.x file carries them too) against the kernel's (FileNamesAnotherPair, Imsd:Ipsec, pinned in tests/Ipsec), instead of resumed with the wrong dialog; the state file gains pcscf, named in that line. Both fresh paths — the bring-up's and recovery's — now set their target themselves: with no PCSCF=, a bring-up that did not resume fails with its own message, and since no fresh one follows: a resumable pair whose attempt failed stays for the restart to resume, a pair nothing can resume — one the engine's rule wrote off during the attempt among them, a refresh refused with a 403 that carries a Retry-After or a binding a NOTIFY terminated under the re-REGISTER wait, decided once after both catch arms by its verdict (Reconnectable(), and with no fresh target Fresh(): a 401, a refusal with a Retry-After, the second refusal — with no fresh target every refusal reaches the reducer and its count travels in the holds, so the restart's refusal is the second, while with a target only a Retry-After does, as before — a refusal without one is not counted and the fresh registration follows at once; without the count a refused no-target resume would re-REGISTER on the same Call-ID at every RestartSec, the F16 loop) — is removed so the next bring-up finds nothing — and a recovery step that needs one restarts the daemon; the "PCSCF not set" check at the top of BringUp is gone, so a registration can be resumed with no setting at all. Three journal lines of the fresh-target path change with it: `resume connect failed; falling back to fresh` and `state file transport differs from SIP_TRANSPORT; fresh` end in `the next registration is a fresh one`, and a resume the engine writes off (a 403 with a Retry-After, a binding a NOTIFY terminated under the wait) logs `resume failed: … — written off by the network: the next registration is a fresh one` (§7.8). `no reg state file; resume falls back to fresh` keeps its text with a fresh target and ends in `nothing can resume it: the pair is removed` without one; the new `the state file names another SA pair (0x…/0x…[ to X]) than the kernel's (0x…/0x… to Y): another attempt's; …` line takes the same two tails. Tested: crafter-build test, 7 passed (tests/Engine: the refusal count's travel through the holds); the resume on the SA peer with the fresh target absent in builds of this series on the dev phone (KPN), and the no-target bring-up there with a resume that failed on a transport mismatch (the pair kept, the restart resumed) and with the state file removed (the pair removed, the next bring-up found nothing); the two dead-resume lines' no-target tail — a missing file, a file with another pair's SPIs — and the pair's removal on the tip's host build (bench 23f: a fake modem on PATH, a real xfrm in a namespace; a file with the pair's SPIs but another P-CSCF's address passes the check and the resume runs — `RESUME via existing SA`, the connect then failing in the namespace); on the dev phone (bench 41, the tip's build) a resume on a file without its pcscf key, the live pair's SPIs.
2026-10-11 15:58:49 +02:00
// the refusal count travels: a resume refused without a Retry-After at a start with no fresh target is one
// refusal, the restart's is the second — without the travel every restart would be the first (F16's loop)
RegRecovery rq;
rq.OnReconnectFailure(10, F::Refused, 0, 503);
auto hq = rq.Holds(20);
Check(hq.Any() && hq.refusals == 1 && !hq.oldGone && hq.hold == 0, "a refusal without a Retry-After is held as a count, nothing else");
RegRecovery sq;
sq.Restore(100, hq);
Check(!sq.Fresh() && sq.Reconnectable(), "the count alone gives nothing up");
sq.OnReconnectFailure(100, F::Refused, 0, 503);
Check(sq.Fresh() && sq.Reconnectable(), "the second refusal, across the restart, gives the resume up (fresh) without writing the registration off");
RegRecovery tq;
tq.OnReconnectFailure(10, F::Refused, 0, 401);
Check(tq.Fresh() && tq.Reconnectable() && tq.Holds(20).refusals == 1, "a 401 gives the resume up at once; its count travels too");
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
RegRecovery x;
x.Restore(2000, RegRecovery::Held{86400, 86400, 21});
Check(x.holdUntil == 2000 + 3600 && x.freshHoldUntil == 2000 + 3600, "a restored hold is cut to the hour like the Retry-After it came from");
}
// bring-up: a resume that failed leaves nothing to reconnect over
{
RegRecovery u;
u.OldGone();
u.OnFreshFailure(1000, F::Throttled);
Check(!u.Reconnectable() && freshAt(u, 1000, 1000 + 21 * 60), "a throttled bring-up: the next fresh attempt in 21 min, nothing meanwhile");
u.OnDial();
Check(freshAt(u, 1000, 1000 + 21 * 60), "…a Dial changes nothing");
}
}
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// ---- SMS over IP: SmsOutbound and OnSmsMessage (TS 24.341) ----------
{
using namespace imsd::sms;
auto hasSms = [](const std::vector<SmsAction>& a, SmsAction::Type t) { for (const auto& x : a) if (x.type == t) return true; return false; };
auto findSms = [](const std::vector<SmsAction>& a, SmsAction::Type t) -> const SmsAction* { for (const auto& x : a) if (x.type == t) return &x; return nullptr; };
auto bodyRp = [](std::string_view msg) {
std::string_view body = imsd::sip::Body(msg);
return ParseRp(std::span<const std::uint8_t>(reinterpret_cast<const std::uint8_t*>(body.data()), body.size()), false);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
};
auto final = [](std::string_view callid, int code, std::string_view text) { return std::format("SIP/2.0 {} {}\r\nCall-ID: {}\r\nCSeq: 1 MESSAGE\r\nContent-Length: 0\r\n\r\n", code, text, callid); };
const auto kpnSc = *imsd::util::FromHex("07911356131313f3");
Context c = MakeCtx();
c.aor = "sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org";
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
c.smsOverIp = true;
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const SmsOutbound::Params p{"+31612345678", "Hello", "sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone", kpnSc, 10, 20, 0x2A, 0xA9, false};
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
RecentSubmissions sub; // the MESSAGEs the messages below go out in; a check that needs an empty one makes its own
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// a one-segment message: MESSAGE, 202, RP-ACK -> sent
{
imsd::util::Rng rng(71);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-1", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(100.0);
const auto* sent = findSms(a, SmsAction::Type::SendClient);
Check(sent && sent->text.starts_with("MESSAGE sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone SIP/2.0\r\n"), "outbound: the MESSAGE goes to the SC's PSI");
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 100.0 + SmsSendTimeout, "outbound: sending, the 128 s wait for the final armed");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
if (!sent) return 1;
const std::string callid(imsd::sip::Header(sent->text, "Call-ID").value_or(""));
auto rp = bodyRp(sent->text);
Check(rp && rp->type == RpType::DataMo && rp->mr == 20 && rp->sc && rp->sc->Number() == "+31653131313", "outbound: the body is an RP-DATA to the SC with RP-MR 20");
Check(rp && rp->tpdu.size() > 2 && rp->tpdu[1] == 10 && (rp->tpdu[0] & 0x03) == 1 && (rp->tpdu[0] & 0x10), "outbound: an SMS-SUBMIT with TP-MR 10 and a TP-VP");
Check(m.TpMrs() == std::vector<std::uint8_t>{10} && m.Segments() == 1, "outbound: one segment");
Check(m.OwnsResponse(final(callid, 202, "Accepted")) && !m.OwnsResponse(final("other", 202, "Accepted")), "outbound: owns its own MESSAGE's final only");
auto b = m.OnResponse(final(callid, 202, "Accepted"), 202, 101.0);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(m.State() == SmsOutbound::Phase::AwaitingReport && m.Deadline() == 101.0 + SmsReportTimeout && !hasSms(b, SmsAction::Type::State), "outbound: 202 -> awaiting the submit report, its 130 s wait armed");
Check(SmsSendTimeout == 128.0 && SmsReportTimeout == 130.0, "outbound: the wait for the final is 128 s, the one for the submit report 130 s");
Check(m.ReportAttempt(callid, std::nullopt) && !m.ReportAttempt("x@y", 20) && m.ReportAttempt("", 20) && !m.ReportAttempt("", 21), "outbound: a report is matched by In-Reply-To, else by RP-MR");
Check(m.ReportAttempt(std::format("x@y, {}", callid), std::nullopt) && m.ReportAttempt(std::format("{},x@y", callid), 21) && m.ReportAttempt(std::format("z@w , {} ,x@y", callid), 21) && m.ReportAttempt(std::format("z@w\t,\t{}", callid), 21) && !m.ReportAttempt("x@y, z@w", 20) && !m.ReportAttempt(callid + "x", 20) && !m.ReportAttempt("x" + callid, 20), "outbound: of an In-Reply-To that lists Call-IDs, ours among them is ours");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
Rp ack{RpType::AckMt, 20, std::nullopt, *imsd::util::FromHex("010062016122050080"), std::nullopt, std::nullopt};
auto d = m.OnReport(ack, 102.0);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->id == "ims-sms-1" && st->reason.contains("22:50:00+02:00") && m.Done() && m.Deadline() == 0, "outbound: the RP-ACK ends the message as sent, with the SC's time stamp");
}
// the final refuses it
{
imsd::util::Rng rng(72);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-2", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
auto b = m.OnResponse(std::format("SIP/2.0 403 Forbidden\r\nCall-ID: {}\r\nCSeq: 1 MESSAGE\r\nWarning: 399 x \"no\"\r\nContent-Length: 0\r\n\r\n", callid), 403, 1.0);
const auto* st = findSms(b, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason.contains("403 Forbidden") && st->reason.contains("Warning") && m.Done(), "outbound: a refused MESSAGE fails the message with the refusal");
}
// a provisional keeps it waiting; the RP-ERROR fails it with the cause
{
imsd::util::Rng rng(73);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-3", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m.OnResponse(final(callid, 100, "Trying"), 100, 5.0);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 5.0 + SmsSendTimeout, "outbound: a provisional starts the 128 s wait over");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
m.OnResponse(final(callid, 200, "OK"), 200, 6.0);
Rp err{RpType::ErrorMt, 20, std::nullopt, *imsd::util::FromHex("01c30062016122050080"), 28, std::nullopt};
auto b = m.OnReport(err, 7.0);
const auto* st = findSms(b, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason.contains("RP cause 28 (unidentified subscriber)") && st->reason.contains("TP-FCS 0xc3 (invalid SME address)"), "outbound: an RP-ERROR fails the message with its cause and TP-FCS");
}
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
// the final's wait runs out: the segment goes out once more (TS 23.040 9.2.3.6) — the same SMS-SUBMIT with TP-RD set, in a MESSAGE of its own — and is accepted
auto logged = [](const std::vector<SmsAction>& a, std::string_view text) { for (const auto& x : a) if (x.type == SmsAction::Type::Log && x.text == text) return true; return false; };
auto callIdOf = [](const SmsAction* a) { return a ? std::string(imsd::sip::Header(a->text, "Call-ID").value_or("")) : std::string(); };
const std::string toSc = "to +31612345678 via sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone";
const Rp duplicate{RpType::ErrorMt, 21, std::nullopt, *imsd::util::FromHex("01c50062016122050080"), 21, std::nullopt}; // TP-FCS 0xC5, "SM Rejected-Duplicate SM"
const Rp temporary{RpType::ErrorMt, 20, std::nullopt, {}, 41, std::nullopt};
const Rp permanent{RpType::ErrorMt, 20, std::nullopt, *imsd::util::FromHex("01c30062016122050080"), 28, std::nullopt};
Check(SmsAttempts == 2, "outbound: a segment goes out twice at most");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
{
imsd::util::Rng rng(74);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-4", p);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
auto a = m.Start(0.0);
const auto* first = findSms(a, SmsAction::Type::SendClient);
if (!first) return 1;
const std::string callid1 = callIdOf(first);
const std::uint8_t afterFirst = m.NextRpMr();
auto b = m.OnDeadline(128.5);
const auto* again = findSms(b, SmsAction::Type::SendClient);
Check(again && !hasSms(b, SmsAction::Type::State) && m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 128.5 + SmsSendTimeout, "outbound: no final within 128 s: the segment goes out again, its own 128 s wait armed, no word to the bus");
if (!again) return 1;
const std::string callid2 = callIdOf(again);
const auto rp1 = bodyRp(first->text), rp2 = bodyRp(again->text);
Check(rp1 && rp2 && !callid2.empty() && callid2 != callid1 && rp1->mr == 20 && afterFirst == 21 && rp2->mr == 21 && m.NextRpMr() == 22 && again->text.starts_with("MESSAGE sip:+31653131313@ims.mnc001.mcc001.3gppnetwork.org;user=phone SIP/2.0\r\n"), "outbound: the repeat is a MESSAGE of its own to the SC's PSI: another Call-ID, the next RP-MR, and the counter goes on after it");
Check(rp1 && rp2 && rp1->tpdu[0] == 0x11 && rp2->tpdu[0] == 0x15 && rp2->tpdu[1] == 10 && rp1->tpdu.size() == rp2->tpdu.size() && std::equal(rp1->tpdu.begin() + 1, rp1->tpdu.end(), rp2->tpdu.begin() + 1), "outbound: the repeat carries the same SMS-SUBMIT — TP-MR 10 — with TP-RD set and no other bit changed");
Check(logged(a, std::format("sms ims-sms-4: segment 1/1 {}: MESSAGE sent (RP-MR 20, TP-MR 10, {} bytes)", toSc, rp1->tpdu.size())) && logged(b, "sms ims-sms-4: no answer to the MESSAGE of segment 1/1 within 128 s; sending the segment again, TP-RD set") && logged(b, std::format("sms ims-sms-4: segment 1/1 {}: MESSAGE sent again (RP-MR 21, TP-MR 10 with TP-RD, {} bytes)", toSc, rp2->tpdu.size())), "outbound: the journal's lines of a first attempt, of its end and of the repeat");
Check(m.OwnsResponse(final(callid2, 202, "Accepted")) && !m.OwnsResponse(final(callid1, 202, "Accepted")) && m.CallId() == callid2, "outbound: the final in flight is the repeat's; the first attempt's late final is nobody's");
Check(m.ReportAttempt(callid1, std::nullopt) == 0u && m.ReportAttempt(callid2, std::nullopt) == 1u && m.ReportAttempt(std::format("{}, {}", callid1, callid2), std::nullopt) == 1u && m.ReportAttempt("", 20) == 0u && m.ReportAttempt("", 21) == 1u && !m.ReportAttempt("", 22) && !m.ReportAttempt("x@y", 21), "outbound: a report is the first attempt's or the repeat's by In-Reply-To — the repeat's when it lists both — else by RP-MR");
m.OnResponse(final(callid2, 202, "Accepted"), 202, 129.0);
Check(m.State() == SmsOutbound::Phase::AwaitingReport && m.Deadline() == 129.0 + SmsReportTimeout, "outbound: the repeat's 202: its own 130 s wait for the report");
auto d = m.OnReport(Rp{RpType::AckMt, 21, std::nullopt, *imsd::util::FromHex("010062016122050080"), std::nullopt, std::nullopt}, 130.0);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->reason == "1 segment(s) accepted by the SC at 2026-10-16T22:50:00+02:00" && m.Done() && m.Deadline() == 0, "outbound: the repeat's RP-ACK ends the message as sent");
}
// the report's wait runs out and the repeat is rejected as a duplicate (TP-FCS 0xC5): taken for the first attempt accepted — sent
{
imsd::util::Rng rng(75);
SmsOutbound m(c, rng, sub, "ims-sms-5", p);
auto a = m.Start(0.0);
const auto* first = findSms(a, SmsAction::Type::SendClient);
const std::string callid1 = callIdOf(first);
m.OnResponse(final(callid1, 202, "Accepted"), 202, 1.0);
auto b = m.OnDeadline(131.5);
const auto* again = findSms(b, SmsAction::Type::SendClient);
const std::string callid2 = callIdOf(again);
Check(!callid2.empty() && logged(b, "sms ims-sms-5: no submit report for segment 1/1 within 130 s of the final; sending the segment again, TP-RD set") && !hasSms(b, SmsAction::Type::State), "outbound: no submit report within 130 s: the segment goes out again");
if (!first || !again) return 1;
const auto rp1 = bodyRp(first->text), rp2 = bodyRp(again->text);
Check(rp1 && rp2 && rp2->mr == 21 && rp1->tpdu[0] == 0x11 && rp2->tpdu[0] == 0x15 && rp1->tpdu.size() == rp2->tpdu.size() && std::equal(rp1->tpdu.begin() + 1, rp1->tpdu.end(), rp2->tpdu.begin() + 1), "outbound: after the report's wait too the repeat carries the same SMS-SUBMIT with TP-RD set and no other bit changed, under the next RP-MR");
m.OnResponse(final(callid2, 202, "Accepted"), 202, 132.0);
auto d = m.OnReport(duplicate, 133.0, 1);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->reason == "1 segment(s) accepted by the SC" && m.Done() && logged(d, "sms ims-sms-5: segment 1/1: the repeat was rejected as a duplicate (RP cause 21 (short message transfer rejected), TP-FCS 0xc5 (duplicate short message rejected)): the first attempt is taken for accepted"), "outbound: the repeat rejected as a duplicate: the first attempt is taken for accepted, the message is sent");
// the duplicate rejection is read before the RP cause: one that comes with cause 41 is the first attempt accepted, not the repeat refused for now
{
imsd::util::Rng rng41(175);
SmsOutbound m41(c, rng41, sub, "ims-sms-5b", p);
const std::string c1 = callIdOf(findSms(m41.Start(0.0), SmsAction::Type::SendClient));
m41.OnResponse(final(c1, 202, "Accepted"), 202, 1.0);
const std::string c2 = callIdOf(findSms(m41.OnDeadline(131.5), SmsAction::Type::SendClient));
m41.OnResponse(final(c2, 202, "Accepted"), 202, 132.0);
auto f = m41.OnReport(Rp{RpType::ErrorMt, 21, std::nullopt, duplicate.tpdu, 41, std::nullopt}, 133.0, 1);
const auto* st41 = findSms(f, SmsAction::Type::State);
Check(st41 && st41->state == "sent" && m41.Done(), "outbound: a duplicate rejection that comes with RP cause 41 is the first attempt accepted");
}
// the same RP-ERROR to a first attempt, which carried no TP-RD, is a refusal like any other
imsd::util::Rng rng2(76);
SmsOutbound m2(c, rng2, sub, "ims-sms-6", p);
m2.Start(0.0);
auto e = m2.OnReport(Rp{RpType::ErrorMt, 20, std::nullopt, duplicate.tpdu, 21, std::nullopt}, 1.0);
st = findSms(e, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "segment 1/1 refused by the SC: RP cause 21 (short message transfer rejected), TP-FCS 0xc5 (duplicate short message rejected)" && m2.Done() && !hasSms(e, SmsAction::Type::SendClient), "outbound: a duplicate rejection of a first attempt is a refusal like any other: with RP cause 21, failed");
}
// both attempts end without the SC's word: failed, the reason naming both ends
{
imsd::util::Rng rng(77);
SmsOutbound m(c, rng, sub, "ims-sms-22", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
m.Start(0.0);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
const std::string callid2 = callIdOf(findSms(m.OnDeadline(128.5), SmsAction::Type::SendClient));
m.OnResponse(final(callid2, 202, "Accepted"), 202, 129.0);
auto d = m.OnDeadline(259.5);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "no submit report for segment 1/1 within 130 s of the final; the first attempt: no answer to the MESSAGE of segment 1/1 within 128 s" && m.Done() && m.Deadline() == 0 && !hasSms(d, SmsAction::Type::SendClient), "outbound: the repeat's wait run out too: failed, the reason has the repeat's end and the first attempt's");
Check(m.OnDeadline(260.0).empty() && m.OnReport(temporary, 261.0).empty(), "outbound: an ended message takes no deadline and no report");
}
// the first attempt's RP-ACK after the repeat went out — named by In-Reply-To, or by its RP-MR: the SC has the segment
for (bool byCallId : {true, false}) {
imsd::util::Rng rng(78);
SmsOutbound m(c, rng, sub, "ims-sms-23", p);
const std::string callid1 = callIdOf(findSms(m.Start(0.0), SmsAction::Type::SendClient));
m.OnResponse(final(callid1, 202, "Accepted"), 202, 1.0);
m.OnDeadline(131.5);
const auto attempt = m.ReportAttempt(byCallId ? callid1 : std::string(), 20);
Check(attempt == 0u, "outbound: the report is the first attempt's");
auto d = m.OnReport(Rp{RpType::AckMt, 20, std::nullopt, *imsd::util::FromHex("010062016122050080"), std::nullopt, std::nullopt}, 135.0, attempt);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->reason == "1 segment(s) accepted by the SC at 2026-10-16T22:50:00+02:00" && m.Done() && logged(d, "sms ims-sms-23: segment 1/1: the first attempt's submit report came after the repeat went out: accepted"), std::format("outbound: the first attempt's RP-ACK after the repeat went out, taken by {}: sent", byCallId ? "In-Reply-To" : "RP-MR"));
}
// an RP-ERROR whose cause invites another attempt at once: the repeat; the same to the repeat: failed, both ends in the reason
{
imsd::util::Rng rng(79);
SmsOutbound m(c, rng, sub, "ims-sms-24", p);
const std::string callid1 = callIdOf(findSms(m.Start(0.0), SmsAction::Type::SendClient));
m.OnResponse(final(callid1, 202, "Accepted"), 202, 1.0);
auto b = m.OnReport(temporary, 2.0);
const std::string callid2 = callIdOf(findSms(b, SmsAction::Type::SendClient));
Check(!callid2.empty() && !hasSms(b, SmsAction::Type::State) && m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 2.0 + SmsSendTimeout && logged(b, "sms ims-sms-24: segment 1/1 refused by the SC: RP cause 41 (temporary failure); sending the segment again, TP-RD set"), "outbound: an RP-ERROR with cause 41: the segment goes out again");
auto d = m.OnReport(Rp{RpType::ErrorMt, 21, std::nullopt, {}, 41, std::nullopt}, 4.0); // no attempt named: the one in flight, the repeat
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "segment 1/1 refused by the SC: RP cause 41 (temporary failure); the first attempt: segment 1/1 refused by the SC: RP cause 41 (temporary failure)" && m.Done() && !hasSms(d, SmsAction::Type::SendClient), "outbound: cause 41 to the repeat fails the message, both ends in the reason");
// causes 38, 42 and 47 are refusals: no repeat (TS 24.011 Annex E-2 has an immediate reattempt after 38 "not likely to be successful")
for (std::uint8_t cause : {38, 42, 47}) {
imsd::util::Rng rngN(79);
SmsOutbound n(c, rngN, sub, "ims-sms-32", p);
n.Start(0.0);
auto e = n.OnReport(Rp{RpType::ErrorMt, 20, std::nullopt, {}, cause, std::nullopt}, 1.0);
st = findSms(e, SmsAction::Type::State);
Check(st && st->state == "failed" && n.Done() && !hasSms(e, SmsAction::Type::SendClient), std::format("outbound: an RP-ERROR with cause {} fails the message at once", cause));
}
// a value table 8.4's part 1 does not list is read as cause 41: the repeat follows
for (std::uint8_t cause : {0, 2}) {
imsd::util::Rng rngU(79);
SmsOutbound u(c, rngU, sub, "ims-sms-33", p);
u.Start(0.0);
auto e = u.OnReport(Rp{RpType::ErrorMt, 20, std::nullopt, {}, cause, std::nullopt}, 1.0);
Check(hasSms(e, SmsAction::Type::SendClient) && !hasSms(e, SmsAction::Type::State) && u.State() == SmsOutbound::Phase::Sending, std::format("outbound: an RP-ERROR with cause {}, which part 1 does not list, sends the segment again", cause));
}
}
// a duplicate rejection of the repeat after an RP-ERROR has refused the first attempt is a refusal: the first attempt is not what the service centre has
{
imsd::util::Rng rng(87);
SmsOutbound m(c, rng, sub, "ims-sms-33", p);
const std::string callid1 = callIdOf(findSms(m.Start(0.0), SmsAction::Type::SendClient));
m.OnResponse(final(callid1, 202, "Accepted"), 202, 1.0);
const std::string callid2 = callIdOf(findSms(m.OnReport(temporary, 2.0), SmsAction::Type::SendClient));
m.OnResponse(final(callid2, 202, "Accepted"), 202, 3.0);
auto d = m.OnReport(duplicate, 4.0, 1);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "segment 1/1 refused by the SC: RP cause 21 (short message transfer rejected), TP-FCS 0xc5 (duplicate short message rejected); the first attempt: segment 1/1 refused by the SC: RP cause 41 (temporary failure)" && m.Done() && !hasSms(d, SmsAction::Type::SendClient), "outbound: the repeat rejected as a duplicate after the first attempt's RP-ERROR: failed, both refusals in the reason");
}
// an RP-ERROR to the first attempt after its repeat went out, whatever its cause: the repeat's answer ends the segment
for (std::uint8_t cause : {41, 28}) {
const Rp refusal = cause == 41 ? temporary : permanent;
const std::string words = cause == 41 ? "RP cause 41 (temporary failure)" : "RP cause 28 (unidentified subscriber), TP-FCS 0xc3 (invalid SME address)";
auto repeated = [&](SmsOutbound& m) {
m.Start(0.0);
const std::string callid2 = callIdOf(findSms(m.OnDeadline(128.5), SmsAction::Type::SendClient));
auto late = m.OnReport(refusal, 129.0, 0);
Check(late.size() == 1 && logged(late, std::format("sms {}: segment 1/1 refused by the SC: {}, in the first attempt's report, which came after the repeat went out: the repeat's decides", m.Id(), words)) && m.State() == SmsOutbound::Phase::Sending && m.CallId() == callid2 && m.Deadline() == 128.5 + SmsSendTimeout, std::format("outbound: an RP-ERROR with cause {} to the first attempt after the repeat went out is logged and leaves the repeat in flight", cause));
return callid2;
};
// the repeat accepted: sent
imsd::util::Rng rng(88);
SmsOutbound m(c, rng, sub, "ims-sms-34", p);
repeated(m);
auto d = m.OnReport(Rp{RpType::AckMt, 21, std::nullopt, {}, std::nullopt, std::nullopt}, 130.0);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && m.Done(), std::format("outbound: the repeat's RP-ACK after the first attempt's late RP-ERROR (cause {}): sent", cause));
// the repeat's own wait run out: failed, the first attempt's refusal in the reason
imsd::util::Rng rng2(89);
SmsOutbound m2(c, rng2, sub, "ims-sms-35", p);
repeated(m2);
auto e = m2.OnDeadline(257.0);
st = findSms(e, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == std::format("no answer to the MESSAGE of segment 1/1 within 128 s; the first attempt: segment 1/1 refused by the SC: {}, in a report that came after the repeat went out", words) && m2.Done(), std::format("outbound: the repeat unanswered after the first attempt's late RP-ERROR (cause {}): failed, that refusal as the first attempt's end", cause));
// the repeat rejected as a duplicate: the first attempt has been refused, so a refusal
imsd::util::Rng rng3(90);
SmsOutbound m3(c, rng3, sub, "ims-sms-36", p);
repeated(m3);
auto f = m3.OnReport(duplicate, 130.0, 1);
st = findSms(f, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == std::format("segment 1/1 refused by the SC: RP cause 21 (short message transfer rejected), TP-FCS 0xc5 (duplicate short message rejected); the first attempt: segment 1/1 refused by the SC: {}, in a report that came after the repeat went out", words) && m3.Done(), std::format("outbound: the repeat rejected as a duplicate after the first attempt's late RP-ERROR (cause {}): failed", cause));
}
// a first attempt's RP-ERROR is forgotten with its segment: the next segment's repeat, rejected as a duplicate, is accepted
{
imsd::util::Rng rng(91);
SmsOutbound::Params two = p; two.text = std::string(200, 'x');
SmsOutbound m(c, rng, sub, "ims-sms-37", two);
m.Start(0.0);
m.OnReport(temporary, 1.0); // segment 1: refused, sent again
auto b = m.OnReport(Rp{RpType::AckMt, 21, std::nullopt, {}, std::nullopt, std::nullopt}, 2.0); // its repeat accepted: segment 2 goes out
Check(hasSms(b, SmsAction::Type::SendClient) && !hasSms(b, SmsAction::Type::State) && m.ReportAttempt("", 22) == 0u, "outbound: the first segment accepted through its repeat, the second in flight");
m.OnDeadline(130.5); // segment 2: no final, sent again
auto d = m.OnReport(Rp{RpType::ErrorMt, 23, std::nullopt, duplicate.tpdu, 21, std::nullopt}, 131.0, 1);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->reason == "2 segment(s) accepted by the SC" && m.Done(), "outbound: the second segment's repeat rejected as a duplicate is accepted: the first segment's RP-ERROR does not weigh on it");
}
// a final of 408 or 504 leaves the MESSAGE's fate as open as no final: the repeat; any other refusal fails at once
for (int code : {408, 504, 403, 480, 500, 503}) {
imsd::util::Rng rng(81);
SmsOutbound m(c, rng, sub, "ims-sms-26", p);
const std::string callid1 = callIdOf(findSms(m.Start(0.0), SmsAction::Type::SendClient));
auto b = m.OnResponse(final(callid1, code, "Refused"), code, 1.0);
const auto* st = findSms(b, SmsAction::Type::State);
if (code == 408 || code == 504)
Check(!st && hasSms(b, SmsAction::Type::SendClient) && m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 1.0 + SmsSendTimeout && logged(b, std::format("sms ims-sms-26: segment 1/1 refused: {} Refused; sending the segment again, TP-RD set", code)), std::format("outbound: a {} final: the segment goes out again", code));
else
Check(st && st->state == "failed" && st->reason == std::format("segment 1/1 refused: {} Refused", code) && m.Done() && !hasSms(b, SmsAction::Type::SendClient), std::format("outbound: a {} final fails the message at once", code));
}
// the repeat's own 408: failed; and a repeat the flow could not send
{
imsd::util::Rng rng(82);
SmsOutbound m(c, rng, sub, "ims-sms-27", p);
m.Start(0.0);
const std::string callid2 = callIdOf(findSms(m.OnDeadline(128.5), SmsAction::Type::SendClient));
auto b = m.OnResponse(final(callid2, 408, "Request Timeout"), 408, 136.0);
const auto* st = findSms(b, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "segment 1/1 refused: 408 Request Timeout; the first attempt: no answer to the MESSAGE of segment 1/1 within 128 s" && !hasSms(b, SmsAction::Type::SendClient), "outbound: the repeat's own 408 fails the message: a segment goes out twice at most");
imsd::util::Rng rng2(83);
SmsOutbound m2(c, rng2, sub, "ims-sms-28", p);
m2.Start(0.0);
m2.OnDeadline(128.5);
auto e = m2.OnSendFailed();
st = findSms(e, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "segment 1/1 not sent: the flow to the P-CSCF is down; the first attempt: no answer to the MESSAGE of segment 1/1 within 128 s" && m2.Done() && m2.Deadline() == 0, "outbound: a repeat the flow could not send fails the message");
imsd::util::Rng rng3(84);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m3(c, rng3, sub, "ims-sms-6", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
m3.Start(0.0);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
auto f = m3.OnSendFailed();
st = findSms(f, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "segment 1/1 not sent: the flow to the P-CSCF is down", "outbound: a failed send fails it");
}
// two segments, each sent again once: the four MESSAGEs take the RP-MRs in the order they go out; the second segment starts without TP-RD
{
imsd::util::Rng rng(85);
SmsOutbound::Params two = p; two.text = std::string(200, 'x');
SmsOutbound m(c, rng, sub, "ims-sms-29", two);
const auto s1 = bodyRp(findSms(m.Start(0.0), SmsAction::Type::SendClient)->text);
const auto s1again = bodyRp(findSms(m.OnDeadline(128.5), SmsAction::Type::SendClient)->text);
auto b = m.OnReport(duplicate, 129.0, 1);
const auto* seg2 = findSms(b, SmsAction::Type::SendClient);
if (!seg2) return 1;
const auto s2 = bodyRp(seg2->text);
auto b2 = m.OnDeadline(257.5);
const auto* seg2again = findSms(b2, SmsAction::Type::SendClient);
Check(seg2again != nullptr, "outbound: the second segment starts as a first attempt and is sent again in its turn");
if (!seg2again) return 1;
const auto s2again = bodyRp(seg2again->text);
Check(s1 && s1again && s2 && s2again && s1->mr == 20 && s1again->mr == 21 && s2->mr == 22 && s2again->mr == 23 && m.NextRpMr() == 24, "outbound: of two segments each sent again, the four MESSAGEs take RP-MR 20 to 23 as they go out, and the counter goes on at 24");
Check(s1->tpdu[1] == 10 && s1again->tpdu[1] == 10 && s2->tpdu[1] == 11 && s2again->tpdu[1] == 11 && !(s1->tpdu[0] & 0x04) && (s1again->tpdu[0] & 0x04) && !(s2->tpdu[0] & 0x04) && (s2again->tpdu[0] & 0x04) && (s2again->tpdu[0] & 0x40), "outbound: each repeat has its segment's TP-MR and TP-RD; the second segment's first attempt has no TP-RD");
Check(!hasSms(b, SmsAction::Type::State) && m.ReportAttempt("", 22) == 0u && m.ReportAttempt("", 23) == 1u && !m.ReportAttempt("", 20) && !m.ReportAttempt("", 21), "outbound: the first segment's RP-MRs are no longer the message's once the second is in flight");
// an attempt number past the segment's latest is taken for the latest: the duplicate rejection still counts for the repeat
auto d = m.OnReport(Rp{RpType::ErrorMt, 23, std::nullopt, duplicate.tpdu, 21, std::nullopt}, 258.0, 7);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->reason == "2 segment(s) accepted by the SC" && m.Done(), "outbound: both segments accepted through their repeats: sent");
// and with one attempt made, such a number is the first attempt's: no duplicate rule
imsd::util::Rng rng2(86);
SmsOutbound m2(c, rng2, sub, "ims-sms-31", p);
m2.Start(0.0);
auto e = m2.OnReport(Rp{RpType::ErrorMt, 20, std::nullopt, duplicate.tpdu, 21, std::nullopt}, 1.0, 7);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
st = findSms(e, SmsAction::Type::State);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(st && st->state == "failed" && m2.Done(), "outbound: a report numbered past the only attempt is that attempt's");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
}
// two segments: the second goes after the first's RP-ACK, with the next RP-MR and TP-MR
{
imsd::util::Rng rng(77);
SmsOutbound::Params pl = p;
pl.text = std::string(200, 'x');
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-7", pl);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
Check(m.Segments() == 2 && m.TpMrs() == std::vector<std::uint8_t>{10, 11}, "outbound: 200 characters are two segments with consecutive TP-MRs");
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
auto b = m.OnReport(Rp{RpType::AckMt, 20, std::nullopt, {}, std::nullopt, std::nullopt}, 2.0);
const auto* second = findSms(b, SmsAction::Type::SendClient);
Check(second && !hasSms(b, SmsAction::Type::State) && m.State() == SmsOutbound::Phase::Sending, "outbound: the first RP-ACK sends the second segment");
if (!second) return 1;
const std::string callid2(imsd::sip::Header(second->text, "Call-ID").value_or(""));
Check(callid2 != callid, "outbound: a Call-ID of its own per segment");
auto rp = bodyRp(second->text);
Check(rp && rp->mr == 21 && rp->tpdu[1] == 11 && (rp->tpdu[0] & 0x40), "outbound: segment 2 has RP-MR 21, TP-MR 11 and a user-data header");
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(m.ReportAttempt("", 21) && !m.ReportAttempt("", 20), "outbound: the report in flight is the second segment's");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
m.OnResponse(final(callid2, 202, "Accepted"), 202, 3.0);
auto d = m.OnReport(Rp{RpType::AckMt, 21, std::nullopt, {}, std::nullopt, std::nullopt}, 4.0);
const auto* st = findSms(d, SmsAction::Type::State);
Check(st && st->state == "sent" && st->reason.contains("2 segment(s)") && m.Done(), "outbound: the second RP-ACK ends the message as sent");
}
// unsendable
{
imsd::util::Rng rng(78);
SmsOutbound::Params bad = p;
bad.number = "nobody";
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-8", bad);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const auto* st = findSms(a, SmsAction::Type::State);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(st && st->state == "failed" && st->reason == "'nobody' is not a number" && m.Done() && !hasSms(a, SmsAction::Type::SendClient) && m.NextRpMr() == 20, "outbound: a destination that is no number fails at once, no RP-MR taken");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
SmsOutbound::Params longNumber = p;
longNumber.number = "+" + std::string(21, '3');
imsd::util::Rng rngL(80);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound mL(c, rngL, sub, "ims-sms-10", longNumber);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto l = mL.Start(0.0);
st = findSms(l, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason.contains("is not a number") && !hasSms(l, SmsAction::Type::SendClient), "outbound: a destination of more than 20 digits is no number, not a text that does not fit");
SmsOutbound::Params noSc = p;
noSc.scAddress.clear();
imsd::util::Rng rng2(79);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m2(c, rng2, sub, "ims-sms-9", noSc);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto b = m2.Start(0.0);
st = findSms(b, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason.contains("no service centre"), "outbound: no service centre fails at once");
}
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
// the status-report book: a word for the whole message, by TP-MR and recipient
{
using Word = StatusReportBook::Word;
StatusReportBook book;
const std::vector<std::uint8_t> two{10, 11}, one{12}, eleven{11};
book.Sent("ims-sms-1", "+31612345678", two);
book.Sent("ims-sms-2", "0612345679", one);
Check(book.Report(10, "+31612345678", 0x00).word == Word::SegmentDelivered && book.Report(11, "+31612345678", 0x00).word == Word::Delivered && book.Size() == 1, "book: a two-segment message is delivered with its last segment");
Check(book.Report(10, "+31612345678", 0x00).word == Word::NoMessage, "book: a delivered TP-MR is forgotten");
Check(book.Report(12, "+31612345670", 0x00).word == Word::NoMessage && book.Size() == 1, "book: another recipient is no match");
Check(book.Report(12, "+31612345679", 0x30).word == Word::Pending && book.Size() == 1, "book: a temporary status is pending, the entry kept");
Check(book.Report(12, "+31612345679", 0x00).word == Word::Delivered && book.Size() == 0, "book: then delivered");
book.Sent("ims-sms-3", "+31612345678", two);
const auto f = book.Report(11, "+31612345678", 0x41);
Check(f.word == Word::Failed && f.id == "ims-sms-3" && book.Size() == 0 && book.Report(10, "+31612345678", 0x00).word == Word::NoMessage, "book: a permanent failure is the message's last word; a later segment finds nothing");
book.Sent("ims-sms-4", "+31612345678", two);
book.Sent("ims-sms-5", "+31612345678", eleven);
Check(book.Report(10, "+31612345678", 0x00).word == Word::NoMessage && book.Report(11, "+31612345678", 0x00).id == "ims-sms-5" && book.Size() == 0, "book: a TP-MR reused before its word forgets the older message whole");
book.Sent("ims-sms-8", "+31612345678", one);
Check(book.Report(12, "+31612345678", 0x62).word == Word::Failed && book.Size() == 0, "book: a temporary error after which the SC has stopped trying is a failure");
book.Sent("ims-sms-9", "+31612345678", one);
Check(book.Report(12, "+31612345678", 0x80).word == Word::Failed && book.Size() == 0, "book: a status with bit 7 set is reserved, so a failure — not the delivered its low bits spell");
book.Sent("ims-sms-10", "+31612345678", one);
Check(book.Report(12, "+31612345678", 0x26).word == Word::Failed && book.Size() == 0, "book: a reserved value among the still-trying ones is a failure, not pending");
book.Sent("ims-sms-11", "+31612345678", one);
Check(book.Report(12, "+31612345678", 0x03).word == Word::Failed && book.Size() == 0, "book: a reserved value among the completed ones is a failure, not delivered");
book.Sent("ims-sms-12", "+31612345678", one);
Check(book.Report(12, "+31612345678", 0x10).word == Word::Delivered && book.Size() == 0, "book: an SC's own completed value is delivered");
}
// the book forgets a message whole when its submission failed
{
using Word = StatusReportBook::Word;
StatusReportBook book;
const std::vector<std::uint8_t> two{10, 11}, one{12};
book.Sent("ims-sms-6", "+31612345678", two);
book.Sent("ims-sms-7", "+31612345678", one);
book.ForgetMessage("ims-sms-6");
Check(book.Size() == 1 && book.Report(10, "+31612345678", 0x30).word == Word::NoMessage && book.Report(11, "+31612345678", 0x00).word == Word::NoMessage, "book: a forgotten message's reports match nothing");
book.ForgetMessage("ims-sms-99");
Check(book.Size() == 1, "book: forgetting an unknown id changes nothing");
Check(book.Report(12, "+31612345678", 0x00).word == Word::Delivered, "book: the other message is still on record");
}
// the order of one message's words: the submission's first, a report's after `sent`
{
SmsWordOrder order;
auto now = order.Report("ims-sms-1", SmsStateDelivered, "received by the SME", false);
Check(now.size() == 1 && now[0].id == "ims-sms-1" && now[0].state == "delivered" && !order.Holding(), "order: a report on a message whose submission ended is posted at once");
Check(order.Report("ims-sms-2", SmsStateDeliveryPending, "congestion", true).empty() && order.Holding(), "order: a report on the message in flight is held");
auto e = order.Submission("ims-sms-2", SmsStateSent, "2 segment(s) accepted by the SC");
Check(e.post.size() == 2 && e.post[0].state == "sent" && e.post[1].state == "delivery-pending" && e.post[1].reason == "congestion" && !e.forget && !order.Holding(), "order: sent, then the held word");
e = order.Submission("ims-sms-3", SmsStateSent, "1 segment(s) accepted by the SC");
Check(e.post.size() == 1 && e.post[0].state == "sent" && !e.forget, "order: sent with nothing held");
order.Report("ims-sms-4", SmsStateDeliveryPending, "congestion", true);
order.Report("ims-sms-4", SmsStateDelivered, "received by the SME", true);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
e = order.Submission("ims-sms-4", SmsStateFailed, "no submit report for segment 2/2 within 130 s of the final");
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
Check(e.post.size() == 2 && e.post[0].state == "sent" && e.post[0].reason.starts_with("every segment reported delivered by the SC; no submit report") && e.post[1].state == "delivered" && e.post[1].reason == "received by the SME" && !e.forget, "order: a failed after every segment was reported delivered is sent and delivered (the latest held word counts)");
order.Report("ims-sms-5", SmsStateDeliveryPending, "congestion", true);
e = order.Submission("ims-sms-5", SmsStateFailed, "segment 2/2 refused by the SC: RP cause 38");
Check(e.post.size() == 1 && e.post[0].state == "failed" && e.post[0].reason.starts_with("segment 2/2 refused") && e.forget && !order.Holding(), "order: a failed drops the held word and forgets the message's TP-MRs");
e = order.Submission("ims-sms-6", SmsStateFailed, "no service centre");
Check(e.post.size() == 1 && e.post[0].state == "failed" && e.forget, "order: a failed with nothing held is posted and forgets");
order.Report("ims-sms-7", SmsStateDelivered, "received by the SME", true);
e = order.Submission("ims-sms-8", SmsStateSent, "1 segment(s) accepted by the SC");
Check(e.post.size() == 1 && order.Holding(), "order: another message's submission leaves the held word alone");
}
// a status report's recipient against the number a message went to
Check(SameRecipient("+31612345678", "+31612345678") && SameRecipient("0612345678", "+31612345678") && SameRecipient("+31 6 1234 5678", "31612345678") && SameRecipient("0031612345678", "+31612345678") && SameRecipient("6125551234", "+16125551234"), "SameRecipient: equal digits, or a number dialled with a trunk 0, with 00 or without its country code against its international form");
Check(!SameRecipient("+31612345678", "+31687654321") && !SameRecipient("+31612345678", "+49612345678") && !SameRecipient("112", "+31612345112") && !SameRecipient("1266", "+31612341266") && !SameRecipient("", "+31612345678"), "SameRecipient: another number, +31 against +49, a short code as a suffix, an empty one");
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
// the store's order: two texts in one second by sequence number, not by the id as text
{
StoredSms nine; nine.id = "ims-sms-in-7f3a9c21-1792192663-9"; nine.receivedAt = 1792192663;
StoredSms ten; ten.id = "ims-sms-in-7f3a9c21-1792192663-10"; ten.receivedAt = 1792192663;
StoredSms later; later.id = "ims-sms-in-7f3a9c21-1792192664-1"; later.receivedAt = 1792192664;
Check(StoredSmsBefore(nine, ten) && !StoredSmsBefore(ten, nine) && StoredSmsBefore(ten, later) && !StoredSmsBefore(later, nine), "StoredSmsBefore: arrival second first, then within a run the sequence number");
}
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
// the ids of the Messaging interface: the run's token first after the prefix, so two runs with different tokens give different ids whatever the clock reads
{
Check(RunToken(0x7f3a9c21u) == "7f3a9c21" && RunToken(0) == "00000000" && RunToken(0xffffffffu) == "ffffffff", "RunToken: eight hex digits, zero-padded");
Check(SentSmsId("7f3a9c21", 1793474321, 3) == "ims-sms-7f3a9c21-1793474321-3" && ReceivedSmsId("7f3a9c21", 1793474321, 1) == "ims-sms-in-7f3a9c21-1793474321-1", "the sent and the received shape");
Check(ReceivedSmsId("7f3a9c21", 42, 1) != ReceivedSmsId("0b1d2e3f", 42, 1) && SentSmsId("7f3a9c21", 42, 1) != SentSmsId("0b1d2e3f", 42, 1), "two runs with different tokens: their ids differ at the same second and counter");
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
Check(ReceivedSmsId("ffffffff", std::numeric_limits<std::int64_t>::min(), std::numeric_limits<std::uint64_t>::max()).size() <= 64, "the longest received id is no longer than 64 bytes");
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
}
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
// the MESSAGEs our submissions went out in, on record for an hour each (the Call-ID TS 24.341 5.3.1.2 NOTE 3 has the sender store; the hour is imsd's)
{
RecentSubmissions book;
Check(RecentSubmissions::Keep == 3600.0 && book.Size() == 0 && !book.Named("a@h", 0.0), "submissions: an empty table names nothing; a MESSAGE is kept 3600 s");
book.Sent("a@h", "ims-sms-1", 1, 2, 100.0);
book.Sent("b@h", "ims-sms-1", 2, 2, 105.0);
const auto one = book.Named("a@h", 110.0);
Check(one && one->id == "ims-sms-1" && one->segment == 1 && one->segments == 2 && book.Size() == 2, "submissions: a Call-ID on record gives its message and segment");
const auto listed = book.Named(" x@y ,\tb@h , a@h", 110.0);
Check(listed && listed->segment == 2, "submissions: of a list of Call-IDs, the first that is ours");
Check(!book.Named("a@h2", 110.0) && !book.Named("", 110.0) && !book.Named("A@H", 110.0), "submissions: another Call-ID, an empty In-Reply-To and another letter case name none");
Check(book.Named("a@h", 100.0 + 3600.0) && !book.Named("a@h", 100.0 + 3600.5) && book.Named("b@h", 100.0 + 3600.5) && book.Size() == 1, "submissions: on record 3600 s after the MESSAGE went out, no longer");
book.Sent("c@h", "ims-sms-2", 1, 1, 105.0 + 3601.0);
Check(book.Size() == 1 && !book.Named("b@h", 105.0 + 3601.0) && book.Named("c@h", 105.0 + 3601.0), "submissions: a new MESSAGE's entry clears those past their hour");
// a message puts each MESSAGE it goes out in on record, with its segment
imsd::util::Rng rng(93);
SmsOutbound::Params two = p; two.text = std::string(200, 'A');
SmsOutbound m(c, rng, book, "ims-sms-21", two);
const std::string callid1(imsd::sip::Header(findSms(m.Start(4000.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
const std::string callid2(imsd::sip::Header(findSms(m.OnReport(Rp{RpType::AckMt, 20, std::nullopt, {}, std::nullopt, std::nullopt}, 4001.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
const auto first = book.Named(callid1, 4002.0), second = book.Named(callid2, 4002.0);
Check(first && first->id == "ims-sms-21" && first->segment == 1 && first->segments == 2 && first->at == 4000.0 && second && second->segment == 2 && second->at == 4001.0, "submissions: each segment's MESSAGE goes on record as it goes out");
}
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// inbound MESSAGEs, as the IP-SM-GW sends them
auto inbound = [](std::string_view bodyHex, std::string_view extraHeaders = "") {
auto b = *imsd::util::FromHex(bodyHex);
return std::format("MESSAGE sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn1\r\nFrom: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>;tag=N1\r\nTo: <sip:+31611111111@ims.mnc001.mcc001.3gppnetwork.org>\r\nCall-ID: in-{}@net\r\nCSeq: 1 MESSAGE\r\nP-Asserted-Identity: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>\r\n{}Content-Type: application/vnd.3gpp.sms\r\nContent-Length: {}\r\n\r\n{}", bodyHex.substr(0, 6), extraHeaders, b.size(), std::string(b.begin(), b.end()));
};
// a delivered short message: 200, the bus, the RP-ACK to the IP-SM-GW
{
imsd::util::Rng rng(80);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07"), re, nullptr, sub, 50.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
Check(r.response.starts_with("SIP/2.0 200 OK\r\n") && r.response.contains("Call-ID: in-011107@net\r\n"), "inbound: the MESSAGE is answered 200");
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
Check(rec && rec->received.from == "+31641600986" && rec->received.text == "How are you?" && rec->received.sc == "+31653131313" && rec->received.scts == "2002-08-26T19:37:41-00:00" && rec->received.segments == 1 && rec->received.tpdu.size() == 30, "inbound: the message reaches the bus");
Check(std::ranges::find_if(r.actions, [](const SmsAction& x) { return x.type == SmsAction::Type::Received; }) < std::ranges::find_if(r.actions, [](const SmsAction& x) { return x.type == SmsAction::Type::SendClient; }), "inbound: the message is handed over before its report leaves");
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
Check(rep && rep->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n") && rep->text.contains("\r\nIn-Reply-To: in-011107@net\r\n"), "inbound: the delivery report goes to the P-Asserted-Identity, In-Reply-To the delivered MESSAGE");
Check(rep && imsd::sip::Body(rep->text) == std::string("\x02\x11\x41\x02\x00\x00", 6) && imsd::sip::Header(rep->text, "Call-ID") == r.reportCallId, "inbound: the report is an RP-ACK with the SMS-DELIVER-REPORT, RP-MR echoed");
std::string other = inbound("011207911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
other.replace(other.find("From: <sip:ipsmgw@"), 18, "From: <sip:someone@");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto ro = OnSmsMessage(c, rng, other, re, nullptr, sub, 51.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* repo = findSms(ro.actions, SmsAction::Type::SendClient);
Check(repo && repo->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n"), "inbound: with a From that names another, the report still goes to the P-Asserted-Identity");
}
sip: a received message's header section is unfolded where it is framed RFC 3261 7.3.1 lets a header value go on over further lines, each begun with a space or a tab: "The line break and the whitespace at the beginning of the next line are treated as a single SP character." The text layer read a header from one line, so of a folded value it had the first line only. Networks fold: KPN's 401 to the unprotected REGISTER of 2026-07-18 and Odido's of 2026-07-13 had the WWW-Authenticate over four lines (AGENTS.md §13; imsd finds a 401's nonce by a search of the whole message, on a continuation line as on any other). A Security-Server folded the same way would be read by its first line alone, without the SPIs and ports on the further lines, and the bring-up deferred; a short message whose Content-Type stands on a continuation line would be taken for a page-mode text, answered 200 and never shown; a folded Content-Length on a connection would frame no body, and the body's bytes begin the next message. Unfolded takes the folds out of a header section, and the two framers — FrameBuffer::TryExtract for a stream, DatagramMessage for a datagram — hand a message on with its header section unfolded and its body as it came; the Content-Length that frames the body is read from the unfolded section. CutShortRequest reads its Content-Length so too, and the header section it gives for the 400 is unfolded. Every socket imsd reads SIP from goes through one of the two framers, so each reader of a header still reads one line. A DUMP_SIP dump of a received message holds it as framed. Jorijn's decision of 2026-11-21 ("Unfold now"). Tested by tests/Sip — Unfolded on 7.3.1's own example, a tab, a bare LF, a value begun on the next line and a line break that nothing follows; both framers on a 401 whose WWW-Authenticate goes over four lines and whose Content-Length is folded; CutShortRequest on a request cut short of a folded Content-Length; ViaResponsePort on a Via list folded after its comma, through the datagram framer — and by tests/Engine, a delivered MESSAGE whose Content-Type came folded. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, init-port, server-ports and cut-short, at this commit and at the one before): a stand-in's 401 with its Security-Server over three lines gives the whole value, where the commit before deferred the bring-up for want of SPIs; a request with its Content-Type and Content-Length on continuation lines comes out of the server ports unfolded and framed by that length, as a datagram and over a connection; a request cut short of a folded Content-Length, its Via on a continuation line, is answered 400 with its Via whole, on a server port and on the client flow, where the commit before did not read the folded length and handed the request on as it came; a request on a server port whose Via row is a list folded after its comma, `rport` on its lower value, is answered from the client-port socket, the way to the port its top value names, as at the commit before. On the dev phone the binary of this range's last commit registered fresh on KPN after a reboot; the 401 was not dumped, so whether it came folded that time is not on record. A MESSAGE the phone sent to its own protected server port, its Via row a list folded after its comma with `rport` on the lower value, was answered from the client-port socket (the capture's phone-form6, fresh-check.log and inject-bench.log).
2026-11-22 17:35:12 +01:00
// the same delivery with its Content-Type folded onto a second line (RFC 3261 7.3.1), as a framer hands it on
{
const std::string longForm = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
std::string folded = longForm;
folded.replace(folded.find("Content-Type: "), 14, "Content-Type:\r\n\t");
const auto framed = imsd::sip::DatagramMessage(folded);
Check(folded.contains("\r\nContent-Type:\r\n\tapplication/vnd.3gpp.sms\r\n") && framed == longForm, "folded MESSAGE: the datagram framer hands the long form's message on");
imsd::util::Rng rng(80), rngLong(80);
Reassembler re, reLong;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, framed.value_or(""), re, nullptr, sub, 50.0);
auto want = OnSmsMessage(c, rngLong, longForm, reLong, nullptr, sub, 50.0);
sip: a received message's header section is unfolded where it is framed RFC 3261 7.3.1 lets a header value go on over further lines, each begun with a space or a tab: "The line break and the whitespace at the beginning of the next line are treated as a single SP character." The text layer read a header from one line, so of a folded value it had the first line only. Networks fold: KPN's 401 to the unprotected REGISTER of 2026-07-18 and Odido's of 2026-07-13 had the WWW-Authenticate over four lines (AGENTS.md §13; imsd finds a 401's nonce by a search of the whole message, on a continuation line as on any other). A Security-Server folded the same way would be read by its first line alone, without the SPIs and ports on the further lines, and the bring-up deferred; a short message whose Content-Type stands on a continuation line would be taken for a page-mode text, answered 200 and never shown; a folded Content-Length on a connection would frame no body, and the body's bytes begin the next message. Unfolded takes the folds out of a header section, and the two framers — FrameBuffer::TryExtract for a stream, DatagramMessage for a datagram — hand a message on with its header section unfolded and its body as it came; the Content-Length that frames the body is read from the unfolded section. CutShortRequest reads its Content-Length so too, and the header section it gives for the 400 is unfolded. Every socket imsd reads SIP from goes through one of the two framers, so each reader of a header still reads one line. A DUMP_SIP dump of a received message holds it as framed. Jorijn's decision of 2026-11-21 ("Unfold now"). Tested by tests/Sip — Unfolded on 7.3.1's own example, a tab, a bare LF, a value begun on the next line and a line break that nothing follows; both framers on a 401 whose WWW-Authenticate goes over four lines and whose Content-Length is folded; CutShortRequest on a request cut short of a folded Content-Length; ViaResponsePort on a Via list folded after its comma, through the datagram framer — and by tests/Engine, a delivered MESSAGE whose Content-Type came folded. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, init-port, server-ports and cut-short, at this commit and at the one before): a stand-in's 401 with its Security-Server over three lines gives the whole value, where the commit before deferred the bring-up for want of SPIs; a request with its Content-Type and Content-Length on continuation lines comes out of the server ports unfolded and framed by that length, as a datagram and over a connection; a request cut short of a folded Content-Length, its Via on a continuation line, is answered 400 with its Via whole, on a server port and on the client flow, where the commit before did not read the folded length and handed the request on as it came; a request on a server port whose Via row is a list folded after its comma, `rport` on its lower value, is answered from the client-port socket, the way to the port its top value names, as at the commit before. On the dev phone the binary of this range's last commit registered fresh on KPN after a reboot; the 401 was not dumped, so whether it came folded that time is not on record. A MESSAGE the phone sent to its own protected server port, its Via row a list folded after its comma with `rport` on the lower value, was answered from the client-port socket (the capture's phone-form6, fresh-check.log and inject-bench.log).
2026-11-22 17:35:12 +01:00
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
Check(rec && rec->received.text == "How are you?" && r.response == want.response && hasSms(r.actions, SmsAction::Type::SendClient), "folded MESSAGE: taken for a short message, answered and reported on as its long form");
}
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
// the same delivery with its header names in compact form (RFC 3261 7.3.3): `c:` is the content type, `i:` the Call-ID, `v:` the Via
{
const std::string longForm = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
const std::string compact = Compact(longForm);
Check(!compact.contains("Content-Type:") && !compact.contains("Call-ID:") && !compact.contains("Via:") && compact.contains("\r\nc: application/vnd.3gpp.sms\r\n") && compact.contains("\r\ni: in-011107@net\r\n") && compact.contains("\r\nv: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn1\r\n") && compact.contains(std::format("\r\nl: {}\r\n", imsd::sip::Body(longForm).size())) && imsd::sip::Body(longForm).size() == 42 && imsd::sip::Body(compact) == imsd::sip::Body(longForm), "the compact MESSAGE carries `c:`, `i:`, `v:` and `l:`, the body of 42 bytes as it was");
imsd::util::Rng rng(80), rngLong(80);
Reassembler re, reLong;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, compact, re, nullptr, sub, 50.0);
auto want = OnSmsMessage(c, rngLong, longForm, reLong, nullptr, sub, 50.0);
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
const auto* wantRep = findSms(want.actions, SmsAction::Type::SendClient);
Check(r.response == want.response && r.response.starts_with("SIP/2.0 200 OK\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn1\r\n") && r.response.contains("\r\nCall-ID: in-011107@net\r\n"), "compact MESSAGE: the 200 of the long form, the `v:` and the `i:` echoed as Via and Call-ID");
Check(rec && rec->received.text == "How are you?" && rep && wantRep && rep->text == wantRep->text && rep->text.contains("\r\nIn-Reply-To: in-011107@net\r\n"), "compact MESSAGE: taken for a short message, and its delivery report names the `i:` Call-ID in In-Reply-To");
Check(RecentTransactions::Key(compact) == "in-011107@net|1 MESSAGE|z9hG4bKn1" && RecentTransactions::Key(compact) == RecentTransactions::Key(longForm), "compact MESSAGE: the retransmission key from `i:` and `v:`");
// the final to a MESSAGE of ours, its Call-ID as `i:`
imsd::util::Rng rngOut(81);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rngOut, sub, "ims-sms-20", p);
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
const std::string callid(imsd::sip::Header(findSms(m.Start(0.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
const std::string final202 = Compact(final(callid, 202, "Accepted"));
Check(final202.contains(std::format("\r\ni: {}\r\n", callid)) && !final202.contains("Call-ID:") && m.OwnsResponse(final202), "outbound: a final whose Call-ID comes as `i:` is the message in flight's");
}
sms, engine: a class 2 message is refused, not acknowledged, unless it is a short message type 0 OnSmsMessage acknowledged every SMS-DELIVER it could parse with an RP-ACK and handed it to the bus, whatever its class. For a class 2 message the acknowledgement said more than was done: TS 23.038 4 has the MS "ensure that the message has been transferred to the SMS data field in the (U)SIM before sending an acknowledgement to the SC", and TS 23.040 9.2.3.9 has a (U)SIM data download — TP-PID 0x7F with a class 2 coding — passed to the (U)SIM. imsd writes nothing to the card, so the network had an acknowledgement for something that had not happened (issue #4). imsd has no way to the card for such a message yet. TS 23.038 4 names the answer of an MS that cannot store a class 2 message in the (U)SIM while other storage is free, "protocol error, unspecified", and excepts only a download on an MS that supports the (U)SIM Application Toolkit, which imsd does not. The delivery report of a class 2 message, a segment of a set included, is now an RP-ERROR with that cause, 111, and the TP-FCS 0xFF, unspecified error cause; the message is neither stored nor handed to the bus, and the journal has its sender, service centre and time. A short message type 0 (TP-PID 0x40) with a class 2 coding is no part of this: 9.2.3.9 has it received "irrespective of whether there is memory available in the (U)SIM or ME or not". TP-PID 0x7F without a class 2 coding stays a message like any other, and so do classes 0, 1 and 3. What this changes for a consumer: no `Received` comes for a refused class 2 message, a text of that class among them, which 1.2.0 stored and handed over (Jorijn, 2026-11-21: the refusal is kept). The interface's members, keys and words are as they were. Still open of issue #4: the way to the card itself — TS 31.111 7.1.1's ENVELOPE (SMS-PP DOWNLOAD) for a download, an EF_SMS record for any other class 2 message — and with it an acknowledgement made from the card's answer. Read from the dev phone for it (the fp6 journal's 2026-11-20-issues-2-5 capture, phone): the KPN USIM's service table lists 28 (data download via SMS-PP) and 10 (short message storage), EF_SMS holds ten records of 176 bytes, the modem's route table has a class 2 message it receives itself stored on the card, and qmicli has the APDU route AKA takes and no toolkit command. Whether the modem lets an ENVELOPE through that route has not been tried. Tested by tests/Engine. On the dev phone the daemon, the binary of this range's last commit, refused five class 2 deliveries that the phone sent to its own protected server port — answered 200, the journal's line, nothing stored, and no report, since they named no gateway — and took six deliveries from KPN as before (the capture's phone-form6).
2026-11-22 17:35:13 +01:00
// a class 2 message is (U)SIM-specific and imsd has no way to the card: refused with an RP-ERROR of the cause TS 23.038 4 names, not stored, not handed over
{
imsd::util::Rng rng(95);
Reassembler re;
// a (U)SIM data download: TP-PID 0x7F, class 2 8-bit data (DCS 0xF6)
auto dl = OnSmsMessage(c, rng, inbound("012107911356131313F30017040B911346610089F67FF6208062917314080401020304"), re, nullptr, sub, 10.0);
const auto* rep = findSms(dl.actions, SmsAction::Type::SendClient);
Check(dl.response.starts_with("SIP/2.0 200 OK\r\n") && !hasSms(dl.actions, SmsAction::Type::Received) && rep && imsd::sip::Body(rep->text) == std::string("\x04\x21\x01\x6F\x41\x03\x00\xFF\x00", 9) && rep->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n") && rep->text.contains("\r\nIn-Reply-To: in-012107@net\r\n"), "inbound: a (U)SIM data download is refused with an RP-ERROR — cause 111, TP-FCS 0xFF — to the IP-SM-GW, nothing to the bus");
Check(RpCauseProtocolError == 111 && FcsUnspecified == 0xFF && PidSimDataDownload == 0x7F && PidShortMessageType0 == 0x40, "the refusal's cause is 111, its TP-FCS 0xFF; the download's TP-PID 0x7F, a type 0's 0x40");
Check(logged(dl.actions, "short message from +31641600986 via +31653131313 at 2002-08-26T19:37:41-00:00: class 2, a (U)SIM data download (23 bytes), which imsd cannot pass to the (U)SIM: refused") && logged(dl.actions, "delivery report RP-ERROR (RP-MR 33) -> sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org"), "inbound: the refusal's two lines");
// a class 2 text that is no download (TP-PID 0, DCS 0x12): the same answer
auto text = OnSmsMessage(c, rng, inbound("012207911356131313F3001E040B911346610089F60012208062917314080CC8F71D14969741F977FD07"), re, nullptr, sub, 11.0);
rep = findSms(text.actions, SmsAction::Type::SendClient);
Check(!hasSms(text.actions, SmsAction::Type::Received) && rep && imsd::sip::Body(rep->text) == std::string("\x04\x22\x01\x6F\x41\x03\x00\xFF\x00", 9) && logged(text.actions, "short message from +31641600986 via +31653131313 at 2002-08-26T19:37:41-00:00: class 2 (30 bytes), which imsd cannot pass to the (U)SIM: refused"), "inbound: a class 2 text that is no download is refused the same way");
// a segment of a class 2 set: refused on its own, nothing kept for a reassembly
auto seg = OnSmsMessage(c, rng, inbound("012307911356131313F3001E440B911316325476F80012620161220500800C0500037B02028442A15008"), re, nullptr, sub, 12.0);
rep = findSms(seg.actions, SmsAction::Type::SendClient);
Check(!hasSms(seg.actions, SmsAction::Type::Received) && rep && imsd::sip::Body(rep->text) == std::string("\x04\x23\x01\x6F\x41\x03\x00\xFF\x00", 9) && re.Pending() == 0 && logged(seg.actions, "short message from +31612345678 via +31653131313 at 2026-10-16T22:50:00+02:00, segment 2/2 of set 123: class 2 (30 bytes), which imsd cannot pass to the (U)SIM: refused"), "inbound: a segment of a class 2 set is refused on its own, none of it held");
// the other classes, and TP-PID 0x7F without class 2 ("handled in the normal way", TS 23.040 9.2.3.9): received and acknowledged
for (std::string_view tpdu : {"040B911346610089F60010208062917314080CC8F71D14969741F977FD07", "040B911346610089F60011208062917314080CC8F71D14969741F977FD07", "040B911346610089F60013208062917314080CC8F71D14969741F977FD07", "040B911346610089F67FF5208062917314080401020304", "040B911346610089F67F04208062917314080401020304"}) {
auto ok = OnSmsMessage(c, rng, inbound(std::format("012407911356131313F300{:02X}{}", tpdu.size() / 2, tpdu)), re, nullptr, sub, 13.0);
rep = findSms(ok.actions, SmsAction::Type::SendClient);
const auto* rec = findSms(ok.actions, SmsAction::Type::Received);
Check(rec && rec->received.msgClass != 2 && rep && imsd::sip::Body(rep->text) == std::string("\x02\x24\x41\x02\x00\x00", 6), std::format("inbound: {} is received and acknowledged", tpdu.substr(18, 4) == "0010" ? "class 0" : tpdu.substr(18, 4) == "0011" ? "class 1" : tpdu.substr(18, 4) == "0013" ? "class 3" : tpdu.substr(18, 4) == "7FF5" ? "TP-PID 0x7F with class 1" : "TP-PID 0x7F with no class"));
}
// a short message type 0 (TP-PID 0x40) with a class 2 coding (DCS 0x12) is no message for the card (TS 23.040 9.2.3.9): acknowledged, and handed over as any type 0
auto type0 = OnSmsMessage(c, rng, inbound("012607911356131313F3001E040B911346610089F64012208062917314080CC8F71D14969741F977FD07"), re, nullptr, sub, 13.5);
rep = findSms(type0.actions, SmsAction::Type::SendClient);
const auto* rec0 = findSms(type0.actions, SmsAction::Type::Received);
Check(rec0 && rec0->received.pid == 0x40 && rec0->received.msgClass == 2 && rec0->received.text == "How are you?" && rep && imsd::sip::Body(rep->text) == std::string("\x02\x26\x41\x02\x00\x00", 6), "inbound: a type 0 message with a class 2 coding is acknowledged and handed over, not refused");
// with no gateway named, the refusal cannot go anywhere either: logged, nothing handed over
std::string anon = inbound("012507911356131313F30017040B911346610089F67FF6208062917314080401020304");
const std::string pai = "P-Asserted-Identity: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>\r\n", from = "From: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>;tag=N1";
anon.erase(anon.find(pai), pai.size());
anon.replace(anon.find(from), from.size(), "From: anonymous;tag=N1");
auto none = OnSmsMessage(c, rng, anon, re, nullptr, sub, 14.0);
Check(none.response.starts_with("SIP/2.0 200 OK\r\n") && !hasSms(none.actions, SmsAction::Type::Received) && !hasSms(none.actions, SmsAction::Type::SendClient) && logged(none.actions, "no P-Asserted-Identity or From URI on the delivered MESSAGE: no delivery report RP-ERROR sent"), "inbound: a class 2 message that names no gateway: neither handed over nor refused on the wire");
}
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// a Call-ID the delivery report cannot carry — a byte up to 0x20 in it (but an LF, which ends the line) or a DEL: no In-Reply-To, the message and its report as ever
for (int b = 0; b <= 0x7F; b++) {
if ((b > 0x20 && b != 0x7F) || b == 0x0A) continue;
imsd::util::Rng rng(80);
Reassembler re;
std::string req = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
req.replace(req.find("in-011107@net"), 13, std::string("in-0111") + static_cast<char>(b) + "Route:x@net");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, req, re, nullptr, sub, 52.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
Check(rep && hasSms(r.actions, SmsAction::Type::Received) && !rep->text.contains("In-Reply-To") && !rep->text.contains("Route:x") && imsd::sip::Body(rep->text) == std::string("\x02\x11\x41\x02\x00\x00", 6), std::format("inbound: a Call-ID with the byte 0x{:02x} in it is not written into the delivery report's In-Reply-To", b));
}
// a submit report whose In-Reply-To comes in two rows, ours in the first or in the second: the rows are one list
for (bool first : {true, false}) {
imsd::util::Rng rng(92);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-19", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("0314", first ? std::format("In-Reply-To: {}\r\nIn-Reply-To: x@y\r\n", callid) : std::format("In-Reply-To: x@y\r\nIn-Reply-To: {}\r\n", callid)), re, &m, sub, 2.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* st = findSms(r.actions, SmsAction::Type::State);
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done(), std::format("inbound: a submit report whose In-Reply-To rows list ours in the {} reaches the message in flight", first ? "first" : "second"));
}
// a header name spelled inside the body (8-bit data): the report goes to the header's From, not there
{
imsd::util::Rng rng(83);
Reassembler re;
std::string req = inbound("011107911356131313F30035040B911346610089F6000420806291731408220A502D41737365727465642D4964656E746974793A203C7369703A6576696C40783E");
const auto pai = req.find("P-Asserted-Identity:"); // without the header, a body line would be the first match
if (pai != std::string::npos) req.erase(pai, req.find("\r\n", pai) + 2 - pai);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, req, re, nullptr, sub, 52.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* rec = findSms(r.actions, SmsAction::Type::Received);
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
Check(rec && rec->received.data.size() == 34 && rep && rep->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n") && !rep->text.contains("evil"), "inbound: a header name in the body picks neither the report's target nor anything else");
}
// two segments: the message only once whole, each segment acknowledged
{
imsd::util::Rng rng(81);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r2 = OnSmsMessage(c, rng, inbound("011207911356131313F3001E440B911316325476F80000620161220500800C0500037B02028442A15008"), re, nullptr, sub, 60.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
Check(!hasSms(r2.actions, SmsAction::Type::Received) && hasSms(r2.actions, SmsAction::Type::SendClient) && re.Pending() == 1, "inbound: segment 2/2 first: acknowledged, nothing to the bus yet");
const std::string seg1 = "440B911316325476F8000062016122050080A00500037B020182C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683";
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r1 = OnSmsMessage(c, rng, inbound(std::format("011307911356131313F300{:02X}{}", seg1.size() / 2, seg1)), re, nullptr, sub, 61.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* rec = findSms(r1.actions, SmsAction::Type::Received);
Check(rec && rec->received.text == std::string(153, 'A') + "BBBBB" && rec->received.segments == 2 && re.Pending() == 0, "inbound: segment 1/2 completes the message");
Check(hasSms(r1.actions, SmsAction::Type::SendClient), "inbound: segment 1/2 acknowledged too");
}
// a UCS-2 surrogate pair split across the two segments: the bus text is whole
{
auto rep = [](std::string_view x, int n) { std::string o; for (int i = 0; i < n; i++) o += x; return o; };
imsd::util::Rng rng(82);
Reassembler re;
const std::string u1 = "440B911316325476F80008620161220500808C0500032A0201" + rep("00FC", 66) + "D83D";
const std::string u2 = "440B911316325476F8000862016122050080100500032A0202DE00" + rep("0078", 4);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto a1 = OnSmsMessage(c, rng, inbound(std::format("011407911356131313F300{:02X}{}", u1.size() / 2, u1)), re, nullptr, sub, 62.0);
auto a2 = OnSmsMessage(c, rng, inbound(std::format("011507911356131313F300{:02X}{}", u2.size() / 2, u2)), re, nullptr, sub, 63.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* w = findSms(a2.actions, SmsAction::Type::Received);
Check(!hasSms(a1.actions, SmsAction::Type::Received) && w && w->received.text == rep("ü", 66) + "😀xxxx" && w->received.segments == 2 && re.Pending() == 0, "inbound: a surrogate pair split across segments reaches the bus whole");
}
// a status report
{
imsd::util::Rng rng(82);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("011207911356131313F30019062A0B911316325476F8620161220500806201612205708000"), re, nullptr, sub, 70.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* sr = findSms(r.actions, SmsAction::Type::StatusReport);
Check(sr && sr->report.mr == 0x2A && sr->report.status == 0 && !hasSms(r.actions, SmsAction::Type::Received) && hasSms(r.actions, SmsAction::Type::SendClient), "inbound: a status report is handed over and acknowledged");
}
// a submit report before the MESSAGE's own final (the IP-SM-GW's order is its own): taken, the message sent, the late final nobody's
{
imsd::util::Rng rng(84);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-11", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(m.State() == SmsOutbound::Phase::Sending && m.ReportAttempt(callid, std::nullopt), "outbound: a report is owned while the MESSAGE's final is still due");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 1.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* st = findSms(r.actions, SmsAction::Type::State);
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && !m.OwnsResponse(final(callid, 202, "Accepted")), "outbound: the early RP-ACK ends the message as sent; the late 202 is nobody's");
}
// the same with two segments: segment 1's early RP-ACK sends segment 2 under its own Call-ID
{
imsd::util::Rng rng(85);
Reassembler re;
SmsOutbound::Params two = p; two.text = std::string(200, 'A');
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-12", two);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid1(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, sub, 1.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* seg2 = findSms(r.actions, SmsAction::Type::SendClient);
const std::string callid2 = seg2 ? std::string(imsd::sip::Header(seg2->text, "Call-ID").value_or("")) : std::string();
Check(seg2 && !callid2.empty() && callid2 != callid1 && m.State() == SmsOutbound::Phase::Sending && !m.OwnsResponse(final(callid1, 202, "Accepted")) && m.OwnsResponse(final(callid2, 202, "Accepted")), "outbound: segment 1's early RP-ACK sends segment 2 under its own Call-ID; segment 1's late 202 is nobody's");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
// a second report for segment 1 once segment 2 is out: ours on record, so 200 and the journal, the message untouched
auto rs = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, sub, 2.0);
const auto* late = findSms(rs.actions, SmsAction::Type::Log);
Check(rs.response.starts_with("SIP/2.0 200 OK\r\n") && rs.actions.size() == 1 && late && late->text == std::format("submit report (RP-ACK) In-Reply-To {}: sms ims-sms-12's segment 1/2, no longer in flight; 200", callid1) && m.State() == SmsOutbound::Phase::Sending && m.OwnsResponse(final(callid2, 202, "Accepted")), "inbound: a report for segment 1 after segment 2 went out: 200 and its line, the message untouched");
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
}
// a text past 255 segments to a valid number: failed at once, naming the fit
{
imsd::util::Rng rng(86);
SmsOutbound::Params big = p; big.text = std::string(255 * 153 + 1, 'A');
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-13", big);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const auto* st = findSms(a, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason.contains("does not fit 255 segments") && m.Done() && !hasSms(a, SmsAction::Type::SendClient), "outbound: a text past 255 segments fails at once, naming the fit");
}
// a delivery with no P-Asserted-Identity and a From without a URI: handed over, no delivery report can go anywhere
{
imsd::util::Rng rng(87);
Reassembler re;
std::string msg = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
const std::string pai = "P-Asserted-Identity: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>\r\n", from = "From: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>;tag=N1";
const auto i = msg.find(pai), j = msg.find(from);
Check(i != std::string::npos && j != std::string::npos, "inbound: the fixture carries the PAI and the From");
if (i == std::string::npos || j == std::string::npos) return 1;
msg.erase(i, pai.size());
msg.replace(msg.find(from), from.size(), "From: anonymous;tag=N1");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, msg, re, nullptr, sub, 51.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
bool said = false;
for (const auto& x : r.actions) if (x.type == SmsAction::Type::Log && x.text.contains("no P-Asserted-Identity or From URI")) said = true;
Check(r.response.starts_with("SIP/2.0 200 OK") && hasSms(r.actions, SmsAction::Type::Received) && !hasSms(r.actions, SmsAction::Type::SendClient) && r.reportCallId.empty() && said, "inbound: no gateway for the delivery report — the message handed over, the absence logged");
}
// a submit report without In-Reply-To: matched by RP-MR to the message in flight
{
imsd::util::Rng rng(88);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-14", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("0314"), re, &m, sub, 2.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* st = findSms(r.actions, SmsAction::Type::State);
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && r.reportCallId.empty(), "inbound: a submit report without In-Reply-To reaches the message in flight by RP-MR");
}
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
// submit reports while a segment's repeat is in flight, through OnSmsMessage: the first attempt's RP-ACK is taken by its In-Reply-To; then the repeat's own report finds the message ended and is ours on record
{
imsd::util::Rng rng(94);
Reassembler re;
SmsOutbound m(c, rng, sub, "ims-sms-30", p);
const std::string callid1(imsd::sip::Header(findSms(m.Start(0.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m.OnResponse(final(callid1, 202, "Accepted"), 202, 1.0);
auto again = m.OnDeadline(131.5);
const std::string callid2(imsd::sip::Header(findSms(again, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid1)), re, &m, sub, 135.0);
const auto* st = findSms(r.actions, SmsAction::Type::State);
Check(r.response.starts_with("SIP/2.0 200 OK\r\n") && st && st->state == "sent" && m.Done(), "inbound: the first attempt's RP-ACK, come while the repeat is in flight, ends the message as sent");
auto r2 = OnSmsMessage(c, rng, inbound("05150115410A01C50062016122050080", std::format("In-Reply-To: {}\r\n", callid2)), re, nullptr, sub, 136.0);
const auto* l2 = findSms(r2.actions, SmsAction::Type::Log);
Check(r2.response.starts_with("SIP/2.0 200 OK\r\n") && r2.actions.size() == 1 && l2 && l2->text == std::format("submit report (RP-ERROR, RP cause 21 (short message transfer rejected), TP-FCS 0xc5 (duplicate short message rejected)) In-Reply-To {}: sms ims-sms-30's segment 1/1, no longer in flight; 200", callid2), "inbound: the repeat's duplicate rejection after the message ended: 200 and its line");
}
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// a submit report for the message in flight; one for nobody
{
imsd::util::Rng rng(83);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
SmsOutbound m(c, rng, sub, "ims-sms-10", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m.OnResponse(final(callid, 202, "Accepted"), 202, 1.0);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 2.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* st = findSms(r.actions, SmsAction::Type::State);
Check(r.response.starts_with("SIP/2.0 200 OK") && st && st->state == "sent" && m.Done() && r.reportCallId.empty(), "inbound: the submit report reaches the message in flight and is answered 200");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r2 = OnSmsMessage(c, rng, inbound("0314", "In-Reply-To: nobody@x\r\n"), re, &m, sub, 3.0);
Check(r2.response.starts_with("SIP/2.0 488 Not Acceptable Here\r\n") && r2.actions.size() == 1 && findSms(r2.actions, SmsAction::Type::Log) && findSms(r2.actions, SmsAction::Type::Log)->text == "submit report (RP-ACK) In-Reply-To nobody@x: no MESSAGE of ours on record; 488", "inbound: a report In-Reply-To a MESSAGE that is not ours: 488 and its line");
// a report for our own MESSAGE once the message has ended (here: sent): 200, nothing but the journal's line — a stranger's got 488 above
auto r4 = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 3.5);
const auto* l4 = findSms(r4.actions, SmsAction::Type::Log);
Check(r4.response.starts_with("SIP/2.0 200 OK\r\n") && r4.actions.size() == 1 && l4 && l4->text == std::format("submit report (RP-ACK) In-Reply-To {}: sms ims-sms-10's segment 1/1, no longer in flight; 200", callid), "inbound: a report for our own MESSAGE after the message ended: 200 and its line, nothing to the bus");
// and once the report's wait ended it (OnDeadline), an RP-ERROR that comes after: 200, its cause in the line
SmsOutbound m3(c, rng, sub, "ims-sms-13", p);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
auto a3 = m3.Start(10.0);
const std::string callid3(imsd::sip::Header(findSms(a3, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m3.OnResponse(final(callid3, 202, "Accepted"), 202, 11.0);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
m3.OnDeadline(141.5); // the segment goes out again
m3.OnDeadline(270.0); // and the repeat gets no final
auto r5 = OnSmsMessage(c, rng, inbound("05140126410A01C30062016122050080", std::format("In-Reply-To: {}\r\n", callid3)), re, &m3, sub, 276.0);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
const auto* l5 = findSms(r5.actions, SmsAction::Type::Log);
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set A submission whose submit report did not come in time ended as `failed`, and nothing was sent again. The service centre may have the text all the same, and a user who then sends it again delivers it twice: the second submission has a new TP-MR, and the service centre cannot tell that it is a repeat (issue #3, the second of its three cases). TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one to three times, with the same TP-MR and TP-RD set, when no response or an RP-ERROR with an appropriate cause comes, so that the service centre can discard a duplicate. SmsOutbound now sends a segment once more: when either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the server "could not produce a response within a suitable amount of time"; 21.5.5: it "did not receive a timely response from an external server") and on an RP-ERROR with cause 41, temporary failure, or with a value TS 24.011 table 8.4's part 1 does not list, which it has "treated as cause number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that the MS "may wish to try another short message transfer attempt almost immediately". The repeat is a MESSAGE of its own, under its own Call-ID and the next RP-MR — the shell's counter now goes on after the last RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT, TP-RD set by the codec's flag, which nothing set until now. The two waits are longer, so that a repeat does not overtake an answer that is only late: 128 s for the final and 130 s from the final for the report. TS 24.229 table 7.7.1 recommends a UE whose requests name one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21). The segment is accepted by an RP-ACK to either attempt — the first attempt's is taken when it comes after the repeat went out — and by the RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers the repeat and no RP-ERROR has answered the first attempt by then: the service centre is taken to have the first. An RP-ERROR to the first attempt that comes after the repeat went out leaves the segment to the repeat's answer. Any other end of the repeat fails the message, with both attempts' ends in the reason. A final refused with another status and an RP-ERROR with another cause fail the message at once, as before. What the duplicate rejection does not say is which SMS-SUBMIT the service centre holds: one of this subscription's that reached it another way under the same TP-MR can draw the rejection too, and with imsd's first attempt lost the message is then `sent` for a text that never arrived (Jorijn, 2026-11-21: taken as the clause has it). Not done of the clause's repeat: it cannot be switched off, and a failed message is not kept for a user's retransmission under its TP-MR. No member of the Messaging interface changes: `sent` and `failed` come as before, a `failed` later by the waits — with nothing answering, 256 s after the MESSAGE where 1.2.0 said it after 32 s — and texts queued behind the message wait as long. Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128 values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone against KPN with the binary of this range's last commit (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log): with the phone deaf on its protected server port a text to the own number got its 202 and no submit report, went out again 130 s after the final under the next RP-MR, with the same TP-MR and TP-RD set, and ended `sent`; the message after it took the RP-MR after the repeat's. KPN's service centre did not discard the repeat in that bench, nor in the six before it (one of them with a build that waited 40 s): the repeat got an RP-ACK under a time stamp of its own, and once the port was open again the text came twice, under the two attempts' time stamps: the recipient got the text twice without the user sending it again, and the message was `sent`. 1.2.0 ends a submission whose report does not come as `failed` and sends nothing again. The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with the first of those benches before him: the clause has the MS repeat ("shall") and the service centre discard ("should"), and Android's framework sends its own retries so (AOSP's ImsSmsDispatcher and GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's repeat-research).
2026-11-22 17:35:12 +01:00
Check(m3.Done() && r5.response.starts_with("SIP/2.0 200 OK\r\n") && r5.actions.size() == 1 && l5 && l5->text == std::format("submit report (RP-ERROR, RP cause 38 (network out of order), TP-FCS 0xc3 (invalid SME address)) In-Reply-To {}: sms ims-sms-13's segment 1/1, no longer in flight; 200", callid3), "inbound: an RP-ERROR for our own MESSAGE after both attempts' waits ended the message: 200, its cause and TP-FCS in the line");
// a repeat rejected as a duplicate ends the message as sent; the first attempt's RP-ERROR, come after that, finds it no longer in flight: 200 and its line, `sent` stands
SmsOutbound m4(c, rng, sub, "ims-sms-14", p);
const std::string callid4(imsd::sip::Header(findSms(m4.Start(300.0), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
m4.OnResponse(final(callid4, 202, "Accepted"), 202, 301.0);
const std::string repeat4(imsd::sip::Header(findSms(m4.OnDeadline(431.5), SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
auto dup4 = OnSmsMessage(c, rng, inbound("05150115410A01C50062016122050080", std::format("In-Reply-To: {}\r\n", repeat4)), re, &m4, sub, 432.0);
const auto* st4 = findSms(dup4.actions, SmsAction::Type::State);
auto r6 = OnSmsMessage(c, rng, inbound("0514011C410A01C30062016122050080", std::format("In-Reply-To: {}\r\n", callid4)), re, &m4, sub, 433.0);
const auto* l6 = findSms(r6.actions, SmsAction::Type::Log);
Check(st4 && st4->state == "sent" && m4.Done() && r6.response.starts_with("SIP/2.0 200 OK\r\n") && r6.actions.size() == 1 && l6 && l6->text == std::format("submit report (RP-ERROR, RP cause 28 (unidentified subscriber), TP-FCS 0xc3 (invalid SME address)) In-Reply-To {}: sms ims-sms-14's segment 1/1, no longer in flight; 200", callid4), "inbound: the first attempt's RP-ERROR after its repeat was rejected as a duplicate: the message stays sent, 200 and the refusal's line");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r3 = OnSmsMessage(c, rng, inbound("0314"), re, nullptr, sub, 4.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
Check(r3.response.starts_with("SIP/2.0 200 OK") && hasSms(r3.actions, SmsAction::Type::Log) && !hasSms(r3.actions, SmsAction::Type::SendClient), "inbound: a report without In-Reply-To for no message: 200 and the log");
}
// an unusable TPDU, a body that is no RP message, another content type
{
imsd::util::Rng rng(84);
Reassembler re;
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(c, rng, inbound("011507911356131313F30002FFFF"), re, nullptr, sub, 5.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* rep = findSms(r.actions, SmsAction::Type::SendClient);
Check(r.response.starts_with("SIP/2.0 200 OK") && rep && imsd::sip::Body(rep->text) == std::string("\x04\x15\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(r.actions, SmsAction::Type::Received), "inbound: an unusable TPDU is acknowledged with an RP-ERROR (cause 96, TP-FCS B0)");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto rs = OnSmsMessage(c, rng, inbound("011607911356131313F3000102"), re, nullptr, sub, 5.2);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* reps = findSms(rs.actions, SmsAction::Type::SendClient);
Check(rs.response.starts_with("SIP/2.0 200 OK") && reps && imsd::sip::Body(reps->text) == std::string("\x04\x16\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(rs.actions, SmsAction::Type::StatusReport), "inbound: a status report that does not parse gets the same RP-ERROR");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto rt = OnSmsMessage(c, rng, inbound("011707911356131313F300020100"), re, nullptr, sub, 5.4);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
const auto* rept = findSms(rt.actions, SmsAction::Type::SendClient);
Check(rt.response.starts_with("SIP/2.0 200 OK") && rept && imsd::sip::Body(rept->text) == std::string("\x04\x17\x01\x60\x41\x03\x00\xB0\x00", 9) && !hasSms(rt.actions, SmsAction::Type::Received), "inbound: a TPDU of the submit-report type gets the same RP-ERROR");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r2 = OnSmsMessage(c, rng, inbound("07"), re, nullptr, sub, 6.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
Check(r2.response.starts_with("SIP/2.0 200 OK") && !r2.rp && hasSms(r2.actions, SmsAction::Type::Log) && !hasSms(r2.actions, SmsAction::Type::SendClient), "inbound: a body that is no RP message: 200 and the log");
const std::string plain = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn2\r\nFrom: <sip:x@ims>;tag=1\r\nTo: <sip:me@ims>\r\nCall-ID: t1@net\r\nCSeq: 1 MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi";
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r3 = OnSmsMessage(c, rng, plain, re, nullptr, sub, 7.0);
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
Check(r3.response.starts_with("SIP/2.0 200 OK") && !r3.rp && hasSms(r3.actions, SmsAction::Type::Log) && findSms(r3.actions, SmsAction::Type::Log)->text.contains("hi"), "inbound: a page-mode text is 200'd and logged with its body");
}
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
// the store's record codec
{
StoredSms r;
r.id = "ims-sms-in-1792186043-7";
r.receivedAt = 1792186043;
r.to = "tel:+31612345678";
r.simOperator = "20408";
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
r.sms.from = "KPN Service=\n\"x\"";
r.sms.text = "Grüße ❤\nline two=three";
r.sms.scts = "2026-10-16T22:50:00+02:00";
r.sms.sc = "+31653131313";
r.sms.msgClass = 0;
r.sms.pid = 0x40;
r.sms.dcs = 0x08;
r.sms.segments = 2;
r.sms.messageWaiting = true;
r.sms.portDst = 2948;
r.sms.portSrc = 9200;
r.sms.data = {0xDE, 0xAD};
r.sms.tpdu = {0x04, 0x0B, 0x91};
const std::string text = FormatStoredSms(r);
Check(text.starts_with("id=ims-sms-in-1792186043-7\nreceived=1792186043\nto=tel:+31612345678\noperator=20408\nfrom=") && text.contains("\nport-dst=2948\nport-src=9200\n") && text.ends_with("\npdu=040b91\n") && !text.contains("Grüße"), "store: the record's shape, the text as hex");
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
auto back = ParseStoredSms(text);
Check(back && back->id == r.id && back->receivedAt == r.receivedAt && back->to == r.to && back->simOperator == r.simOperator && back->sms.from == r.sms.from && back->sms.text == r.sms.text && back->sms.scts == r.sms.scts && back->sms.sc == r.sms.sc && back->sms.msgClass == 0 && back->sms.pid == 0x40 && back->sms.dcs == 0x08 && back->sms.segments == 2 && back->sms.messageWaiting && back->sms.portDst == 2948 && back->sms.portSrc == 9200 && back->sms.data == r.sms.data && back->sms.tpdu == r.sms.tpdu, "store: a full record round-trips");
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
auto minimal = ParseStoredSms("id=x\n");
Check(minimal && minimal->id == "x" && minimal->receivedAt == 0 && minimal->to.empty() && minimal->simOperator.empty() && !minimal->sms.msgClass && !minimal->sms.portDst && minimal->sms.segments == 1 && minimal->sms.text.empty(), "store: absent keys read as defaults");
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface A received message went to a bus signal and nowhere else but DUMP_SIP's opt-in raw dump of the last MESSAGE outside a call's dialog, so with no app listening it was gone. It is now written to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a .tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms record codec, pinned by tests/Engine — before the signal, and stays until Delete. List hands over the records it can read, by arrival second, then within a run by sequence number. The record is named by the message's id and published with link(2), which refuses a name the store already holds, so the next number is tried and nothing is replaced. link(2) refuses only a name the store still holds: a client that deleted the daemon's copy after importing it freed the name, and the run's token in the id is what keeps a later run from giving it to another text, unless that run draws the same token and meets the same second and number. The two methods sit behind the Messaging polkit action with Send, and the policy text says so; GetStatus, the open read, does not count the store, since the count would tell any local account when a text arrived, and the unit makes the state directory 0700 (StateDirectoryMode) for the same reason. For a message the store cannot write the delivery report stays an RP-ACK: the signal is its only delivery, and the journal says so. The protocol's refusal — RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a mechanism: the other half, the UE's memory-available notification (RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment would also lose its set. The refusal was built and benched on KPN — the store made unwritable, the text refused; it came again five minutes later, the store writable by then, and a later text came at once — and taken out again; no other core is measured. It returns with the notification and a probe of the store. The record's directory is fsynced after the link, its result unchecked like the directory open's; a concatenated text's earlier segments are held in memory, not in the store, until the set is whole (§7.9). Tested on the dev phone (KPN): a text from the phone to its own number on 2026-10-18 23:30, under this publish (a build of this range ahead of this history, 735dfda, whose StoreReceivedSms has this commit's code), stored as ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof). The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory made immutable at 01:37, a text to the phone's own number not stored (EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again at 01:42:56 under its first SC time stamp, stored and acknowledged, a later text not held. Not on the phone: List's skip of a file that is no record and four of Delete's answers ran on the workstation, in dev mode on a private session bus, on this commit's host build (2026-11-19; its sha256 begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs for a string that is no id; IOError, the record still listed, for a record in a store directory made unwritable; the removal once it was writable; FileNotFound for an id with no record. The engine's start sweeps the .tmp names a crash left — one it cannot unlink stays, unreported — so a deleted text's second name goes at the next engine start that can remove it (Delete leaves .tmp names alone). A Delete whose removal fails answers IOError with the system's reason, and a record that is there is kept; FileNotFound is left for a removal that found no file. List's order breaks a tie between two texts of one run in one second by the sequence number (pinned), not by the id as text.
2026-10-17 00:24:50 +02:00
Check(!ParseStoredSms("received=5\nfrom=00\n"), "store: no id, no record");
Check(!ParseStoredSms("id=x\ntext=zz\n"), "store: a malformed hex value, no record");
Check(!ParseStoredSms("id=x\nreceived=soon\n"), "store: a malformed number, no record");
auto noClass = ParseStoredSms("id=x\nclass=-1\nmessage-waiting=0\n");
Check(noClass && !noClass->sms.msgClass && !noClass->sms.messageWaiting, "store: class -1 is none");
}
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
// a retransmitted MESSAGE: the same final again, nothing else, for 32 s (TimerJ)
{
RecentTransactions recent;
const std::string first = inbound("011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07");
const std::string key = RecentTransactions::Key(first);
Check(key == "in-011107@net|1 MESSAGE|z9hG4bKn1", "recent: the key is Call-ID, CSeq and the Via line's branch");
Check(!recent.Repeat(key, 10.0), "recent: a new request is no retransmission");
recent.Remember(key, "SIP/2.0 200 OK\r\n\r\n", 10.0);
Check(recent.Repeat(key, 10.4) == std::optional<std::string>("SIP/2.0 200 OK\r\n\r\n") && recent.Size() == 1, "recent: the copy gets the same final");
Check(!recent.Repeat("other|1 MESSAGE|z9hG4bKn1", 10.5), "recent: another Call-ID is another request");
Check(RecentTransactions::TimerJ == 32.0 && recent.Repeat(key, 10.0 + 31.5) == std::optional<std::string>("SIP/2.0 200 OK\r\n\r\n"), "recent: TimerJ is 32 s, and a copy half a second before its end still gets the final");
Check(!recent.Repeat(key, 10.0 + RecentTransactions::TimerJ + 0.5) && recent.Size() == 0, "recent: forgotten after TimerJ's 32 s");
const std::string noBranch = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/UDP [2001:db8::105]:6000\r\nCall-ID: nb@net\r\nCSeq: 1 MESSAGE\r\nContent-Length: 0\r\n\r\n";
Check(RecentTransactions::Key(noBranch).empty(), "recent: no branch, no key");
recent.Remember(RecentTransactions::Key(noBranch), "x", 50.0);
Check(!recent.Repeat("", 50.1) && recent.Size() == 0, "recent: an empty key is never remembered");
const std::string branchWithParams = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/UDP [2001:db8::105]:6000;branch=z9hG4bKabc;_aluscr_\r\nCall-ID: c@net\r\nCSeq: 7 MESSAGE\r\nContent-Length: 0\r\n\r\n";
Check(RecentTransactions::Key(branchWithParams) == "c@net|7 MESSAGE|z9hG4bKabc", "recent: the branch ends at the next parameter");
}
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
// SMS over IP off: a short message the network sends anyway is refused, a page-mode text still 200'd
{
imsd::util::Rng rng(85);
Reassembler re;
Context off = MakeCtx();
off.aor = c.aor;
const std::string_view offeredHex = "011107911356131313F3001E040B911346610089F60000208062917314080CC8F71D14969741F977FD07";
const std::string offered = inbound(offeredHex);
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r = OnSmsMessage(off, rng, offered, re, nullptr, sub, 8.0);
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
Check(r.response.starts_with("SIP/2.0 480 Temporarily Unavailable\r\n") && r.response.contains("Call-ID: in-011107@net\r\n"), "off: a short message is refused with 480");
Check(!hasSms(r.actions, SmsAction::Type::Received) && !hasSms(r.actions, SmsAction::Type::SendClient) && r.reportCallId.empty() && !r.rp && re.Pending() == 0, "off: nothing to the bus, no delivery report, nothing parsed");
const auto* log = findSms(r.actions, SmsAction::Type::Log);
Check(log && log->text.ends_with("while SMS_OVER_IMS is off: 480") && !log->text.contains("How are you") && !log->text.contains(std::string_view(offered).substr(offered.find("\r\n\r\n") + 4)) && !log->text.contains(imsd::util::ToHex(*imsd::util::FromHex(offeredHex))), "off: logged with a line that ends at the 480, without the text, the body or its hex");
const std::string plain = "MESSAGE sip:me@ims SIP/2.0\r\nVia: SIP/2.0/TCP [2001:db8::105]:6000;branch=z9hG4bKn3\r\nFrom: <sip:x@ims>;tag=1\r\nTo: <sip:me@ims>\r\nCall-ID: t2@net\r\nCSeq: 1 MESSAGE\r\nContent-Type: text/plain\r\nContent-Length: 2\r\n\r\nhi";
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r2 = OnSmsMessage(off, rng, plain, re, nullptr, sub, 9.0);
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
Check(r2.response.starts_with("SIP/2.0 200 OK") && hasSms(r2.actions, SmsAction::Type::Log), "off: a page-mode text is still 200'd and logged");
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200 TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To "indicates that the request corresponds to a short message submitted by the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the sender store the Call-ID for that. imsd knew only the Call-ID of the segment in flight (OwnsReport): a report that came once its message had ended — the 40 s wait run out — or once its segment was followed by the next was answered 488 like a stranger's, and its line said only "no MESSAGE of ours in flight" (issue #3, the first of its three cases). RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes out in for an hour, with the message's id and the segment. A report In-Reply-To one of them that the message in flight does not take is answered 200, and the journal has `submit report (RP-ACK) In-Reply-To …: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's with its cause. The 488 is left for an In-Reply-To that names no MESSAGE of ours on record, and its line says so ("on record" for "in flight"). A report without In-Reply-To that no message in flight takes by its RP-MR is answered 200 as before; its line ends `that no message in flight owns; 200` where it ended `for no message in flight; 200`. The bus is told nothing of a late report: the Messaging interface is frozen with `failed` as a message's last word (AGENTS.md §8.4), so a text the service centre took after its wait had run out stays `failed` there; the journal's line is the record of it. Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the first of a list that is ours, each segment's MESSAGE put on record as it goes out) and OnSmsMessage (200 and the line for a report on a segment that was followed by the next, on a message that was sent and, with an RP-ERROR's cause, on one its wait had ended; 488 and its line for a stranger's). On the dev phone, with the binary of this range's last commit, no report came for a MESSAGE no longer in flight (the fp6 journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
auto r3 = OnSmsMessage(off, rng, Compact(offered), re, nullptr, sub, 9.5);
sip: a header is found under its compact form, and with white space before the colon RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
Check(r3.response.starts_with("SIP/2.0 480 Temporarily Unavailable\r\n") && r3.response.contains("\r\nCall-ID: in-011107@net\r\n") && !r3.rp, "off: a short message whose content type comes as `c:` is refused with 480 too");
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 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-<run>-<start>-<N>` for a sent text, with the start second and a counter, and `ims-sms-in-<run>-<epoch>-<N>` 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 <state dir>/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 +<the rest>, 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).
2026-10-16 23:30:25 +02:00
}
sip, engine: the SMS over IP transactions as reducers TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered with a final and then with the submit report in a MESSAGE of the IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two pure reducers carry that, in the shape CallMachine has: SmsOutbound takes one message of ours segment by segment — the MESSAGE, its final (a 32 s wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may have), then the next segment with the next RP-MR and TP-MR — and ends it as sent or failed, its State action carrying the reason; OnSmsMessage turns an inbound MESSAGE into its final, the message or status report it carried and the delivery report to send, 488 for a submit report In-Reply-To no MESSAGE of ours in flight — one that is not ours (5.3.1.2), or ours once the message has ended (its report's wait run out, judged by the reducer's caller; a failure; sent) or its segment was superseded by the next, which gets the same answer — an RP-ERROR for a TPDU that is unusable (a delivery or a status report that does not parse, or one of the submit-report type), and a 200 with a log line for what it makes nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a body that is no RP message, a submit report without In-Reply-To for no message in flight. Imsd:Sip gains HeaderUri, the URI of a header's first element, a quoted display name before it passed over (none when that URI holds an ASCII control character, a space, `<`, `>` or `"`: it goes into a request line), and Body, moved out of CallMachine (its four call sites and the shell's NOTIFY/MESSAGE branch follow). No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done): an unanswered MESSAGE or a report that never comes fails the message. RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via branch — the value of the first `branch=` of its first Via line; a request with none or an empty one is not remembered — and gives back the final remembered for it within 32 s (TimerJ, on every transport) — what a caller needs to answer a retransmitted request again and not handle it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be handled again: a second delivery report where the first got one and, of a text in one segment, a second Received. Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 — goes through BuildResponse: each Via: line echoed, the To echoed with a tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2). tests/Engine drives both reducers through the dialogs above and the retransmission table; tests/Sip pins the two helpers. OnSmsMessage's header reads — the delivery report's target (P-Asserted-Identity, else From) among them — go through the text layer, which ends at the header section: a body line may spell a header name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line. A UCS-2 surrogate pair a sender split across two segments comes out whole in the Received action OnSmsMessage returns (the codec decodes a set from its joined units); pinned. Pinned as well: a submit report that arrives before the MESSAGE's own final is taken (the message sent, or the next segment out under its own Call-ID, and the late final nobody's), a text past 255 segments fails at once naming the fit, and a delivery with no P-Asserted-Identity and no From URI is handed over with no delivery report to send. A submit report whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is among them, and a delivered MESSAGE's Call-ID with an ASCII control character or a space in it is not written into the delivery report's In-Reply-To.
2026-10-16 23:20:56 +02:00
}
if (Failures == 0) std::println("Engine: all tests passed");
engine: register fresh when the refresh is refused or nothing answers After bring-up the daemon recovered a dead protected flow by reconnecting through the existing SA and refreshing, on a 5 s → 5 min backoff, forever. That was the whole recovery: a refresh the network refused, or a P-CSCF that stopped answering, kept it in that loop on the same Call-ID and SA until someone restarted the service. O2 UK, 2026-09-24: the 30-minute refresh answered 503, 21 refusals over 70 min; after a manual restart the new registration's flow died 8 s in and no connect over its SA succeeded for 2 h 39 min; a second restart registered within two seconds (13:27:55 → 13:27:57 in the journal; ims ledger F16). Do in place the rest of what a restart does: when the refresh keeps being refused, or reconnect cycles keep ending without an answer unless the modem reports no packet service, register fresh. The fresh registration is the expensive step, so a failed one waits before the next: on a schedule (21 min, growing to 60) after a refusal or a throttle, on a backoff after silence, and a Retry-After from the network is honoured up to an hour. What the network set — a Retry-After, the schedule after a refused or throttled attempt — is kept across a restart in /run/imsd.holds, for the address it was set on. A refused initial registration at bring-up — a final from 300 up to the unprotected REGISTER (its 401 is the challenge), any final but 200 to the protected one, a second 401 (rejected credentials) included — now waits on the same schedule instead of exiting for a systemd restart every two minutes. The policy is a pure reducer in Imsd:Engine (RegRecovery), shaped like the call machine: the daemon supplies the clock and the network, the reducer holds the deadlines and names the next step, and tests/Engine pin it. tests/Engine now exits 0 or 1 instead of its failure count: with more than 255 checks a count of 256 would exit 0, and crafter-build reads 77 as a skipped suite. The bring-up's deferral is logged in the policy's form: `bring-up deferred: <why> — attempt N, next fresh registration in M min` becomes `bring-up deferred: <why>; next: fresh registration in M min`. A bring-up writes the verdict that the old registration is gone as well: a start that goes on to register fresh — its resume failed, or there was nothing to resume over — records it before the attempt, and when the attempt then fails without an answer the daemon exits with the file in place. The next start on the same address and boot does not resume, where 0.3.9 retried the resume: it registers fresh at once. On KPN, with the old registration in fact still live — a start during an outage, staged on the dev phone — that attempt was throttled, and the 21-min schedule began. A bring-up does not retry its resume through an outage the way recovery reconnects. Tested on the dev phone (KPN) in builds of this series; not every path has run there.
2026-09-24 18:56:34 +02:00
return Failures != 0; // not the count: an exit status keeps 8 bits, and this suite has more checks than that
}