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).
This commit is contained in:
Jorijn van der Graaf 2026-11-22 17:35:12 +01:00
commit 23892e8e81
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
7 changed files with 670 additions and 123 deletions

165
AGENTS.md
View file

@ -43,11 +43,11 @@ PipeWire. The verified device/carrier combinations are in the README.
| `interfaces/Imsd-Util.cppm` | `imsd::util` — SIP tokens, IPv6 host/port formatting, the RFC 5952 §4 IPv6 text (`CanonicalIp6`/`CanonicalAddr`; an IPv4-mapped address spelled in hex stays hex, where §5 and `inet_ntop` write it dotted) and the comma-separated address-list parser (`ParseAddressList`), hex/base64, MD5 (RFC 1321), the fixed protected ports `PortUc`/`PortUs` (45061/45062). | | `interfaces/Imsd-Util.cppm` | `imsd::util` — SIP tokens, IPv6 host/port formatting, the RFC 5952 §4 IPv6 text (`CanonicalIp6`/`CanonicalAddr`; an IPv4-mapped address spelled in hex stays hex, where §5 and `inet_ntop` write it dotted) and the comma-separated address-list parser (`ParseAddressList`), hex/base64, MD5 (RFC 1321), the fixed protected ports `PortUc`/`PortUs` (45061/45062). |
| `interfaces/Imsd-Sip.cppm` | `imsd::sip` — SIP as a text layer plus TCP framing: header extraction (from the header section only: a read ends at the first empty line after the start line, empty lines before it skipped; a header is asked for by its long name and found under that or its compact form — RFC 3261 7.3.3: the RFC's ten, and `o` for Event and `x` for Session-Expires — with or without white space before the colon; `Unfolded`, by which the framers hand a message on with its folded header lines — 7.3.1 — joined; `HeaderUri`: the party a header names; `Body`, moved here out of `CallMachine`), status codes, the granted lifetime, `ResponseOf` transaction matching (the Call-ID, and the CSeq as its number and its method, whatever spaces or tabs part them and whatever zeros stand before the number), `CutShortRequest`: the header section of a request — any but an ACK or a CANCEL — whose datagram has fewer body bytes than the Content-Length read from it says, which its 400 is built from. Not a full RFC 3261 parser, deliberately. | | `interfaces/Imsd-Sip.cppm` | `imsd::sip` — SIP as a text layer plus TCP framing: header extraction (from the header section only: a read ends at the first empty line after the start line, empty lines before it skipped; a header is asked for by its long name and found under that or its compact form — RFC 3261 7.3.3: the RFC's ten, and `o` for Event and `x` for Session-Expires — with or without white space before the colon; `Unfolded`, by which the framers hand a message on with its folded header lines — 7.3.1 — joined; `HeaderUri`: the party a header names; `Body`, moved here out of `CallMachine`), status codes, the granted lifetime, `ResponseOf` transaction matching (the Call-ID, and the CSeq as its number and its method, whatever spaces or tabs part them and whatever zeros stand before the number), `CutShortRequest`: the header section of a request — any but an ACK or a CANCEL — whose datagram has fewer body bytes than the Content-Length read from it says, which its 400 is built from. Not a full RFC 3261 parser, deliberately. |
| `interfaces/Imsd-Sdp.cppm` | `imsd::sdp` — SDP offer/answer: the AMR-WB + AMR + telephone-event offer (optional IR.92 preconditions; `OfferedTelephoneEventPt` names its telephone-event numbers), the parser the media plane needs (the codec, its payload type and mode, and the telephone-event payload type the m-line lists at that codec's clock), `BuildAnswer` for the terminating side, the `CODECS` override. | | `interfaces/Imsd-Sdp.cppm` | `imsd::sdp` — SDP offer/answer: the AMR-WB + AMR + telephone-event offer (optional IR.92 preconditions; `OfferedTelephoneEventPt` names its telephone-event numbers), the parser the media plane needs (the codec, its payload type and mode, and the telephone-event payload type the m-line lists at that codec's clock), `BuildAnswer` for the terminating side, the `CODECS` override. |
| `interfaces/Imsd-Sms.cppm` | `imsd::sms` — the short message codecs SMS over IP rides on (TS 24.341 carries the bytes a 2G/3G phone puts in an RP-DATA, in a SIP MESSAGE body): the GSM 7-bit default alphabet with its extension table and the septet packing, UCS-2 (TS 23.038); the SM-TL PDUs (TS 23.040: SMS-SUBMIT built, one per segment with the concatenation header when the text needs more than one; SMS-DELIVER, SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed; the SMS-DELIVER-REPORT that acknowledges a delivery; the user-data header — concatenation, application ports — and the `Reassembler` of a concatenated message); the SM-RL messages (TS 24.011: RP-DATA, RP-ACK, RP-ERROR in both directions, the cause values); EF_SMSP (TS 31.102 §4.2.27), where the (U)SIM names the service centre, and qmicli's hex dump of it. Byte-level only: no SIP, no clock, no I/O. | | `interfaces/Imsd-Sms.cppm` | `imsd::sms` — the short message codecs SMS over IP rides on (TS 24.341 carries the bytes a 2G/3G phone puts in an RP-DATA, in a SIP MESSAGE body): the GSM 7-bit default alphabet with its extension table and the septet packing, UCS-2 (TS 23.038); the SM-TL PDUs (TS 23.040: SMS-SUBMIT built, one per segment with the concatenation header when the text needs more than one; SMS-DELIVER, SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed; the SMS-DELIVER-REPORT that acknowledges a delivery; the user-data header — concatenation, application ports — and the `Reassembler` of a concatenated message); the SM-RL messages (TS 24.011: RP-DATA, RP-ACK, RP-ERROR in both directions, the cause values) and `RpCauseIsTemporary`, the causes of a submission after which imsd sends the segment again; EF_SMSP (TS 31.102 §4.2.27), where the (U)SIM names the service centre, and qmicli's hex dump of it. Byte-level only: no SIP, no clock, no I/O. |
| `interfaces/Imsd-Aka.cppm` | `imsd::aka` — USIM AKA glue: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response. | | `interfaces/Imsd-Aka.cppm` | `imsd::aka` — USIM AKA glue: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response. |
| `interfaces/Imsd-Ipsec.cppm` | `imsd::ipsec` — the two ESP SA pairs (TS 33.203) as `ip xfrm` argv lists, the Security-Server mechanism selection, and the reader that reconstructs SPIs/ports from `ip xfrm state`/`policy` text for a warm resume, and (1.0.0) `SaPeer`, the P-CSCF the kernel's pair is to, read from the `dir out` policies that carry imsd's fingerprint, `OwnXfrmDeleteCommands`, the deletes by exact key of what two rules select — the policies carrying imsd's fingerprint and the reqid-1/2 transport-mode ESP states in their direction or on the UE's ims-PDN address, whoever installed them (§12), and `FileNamesAnotherPair`, whether a state file's `spi_uc`/`spi_us` name the kernel's pair (unknown on either side decides nothing). | | `interfaces/Imsd-Ipsec.cppm` | `imsd::ipsec` — the two ESP SA pairs (TS 33.203) as `ip xfrm` argv lists, the Security-Server mechanism selection, and the reader that reconstructs SPIs/ports from `ip xfrm state`/`policy` text for a warm resume, and (1.0.0) `SaPeer`, the P-CSCF the kernel's pair is to, read from the `dir out` policies that carry imsd's fingerprint, `OwnXfrmDeleteCommands`, the deletes by exact key of what two rules select — the policies carrying imsd's fingerprint and the reqid-1/2 transport-mode ESP states in their direction or on the UE's ims-PDN address, whoever installed them (§12), and `FileNamesAnotherPair`, whether a state file's `spi_uc`/`spi_us` name the kernel's pair (unknown on either side decides nothing). |
| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite. Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each Via row echoed in order and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); since 1.2.1 `BuildBadRequest`, the 400 to a request cut short of the Content-Length read from it — any but an ACK or a CANCEL, in a call's dialog or not —, in that shape, a To tag it adds made from the request's header section and a secret of the run (RFC 3261 8.2.7); of requests that came whole, in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. | | `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite. Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each Via row echoed in order and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); since 1.2.1 `BuildBadRequest`, the 400 to a request cut short of the Content-Length read from it — any but an ACK or a CANCEL, in a call's dialog or not —, in that shape, a To tag it adds made from the request's header section and a secret of the run (RFC 3261 8.2.7); of requests that came whole, in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. |
| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first Via row and a request with none or an empty one never matched — answered with the same final and not handled again) and, since 1.2.1, `RecentSubmissions` (the Call-IDs of the MESSAGEs our submissions went out in, an hour each, by which a submit report for one that is no longer in flight is known for ours — TS 24.341 5.3.1.2); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. | | `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, since 1.2.1 a segment that gets no answer, or an RP-ERROR with cause 41, sent once more with TP-RD set — TS 23.040 9.2.3.6 —, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first Via row and a request with none or an empty one never matched — answered with the same final and not handled again) and, since 1.2.1, `RecentSubmissions` (the Call-IDs of the MESSAGEs our submissions went out in, an hour each, by which a submit report for one that is no longer in flight is known for ours — TS 24.341 5.3.1.2); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. |
| `interfaces/Imsd-Qmi.cppm` | `imsd::qmi` — the QMI WDS request bytes `imsd-pcscf` sends (Bind Mux Data Port, Set IP Family, Get Packet Service Status, Get Current Settings, Get Profile Settings), the message/TLV parser, the P-CSCF list readers (0x22 flag, 0x23 IPv4, 0x24 FQDN, 0x2E IPv6 — the last one libqmi does not model). | | `interfaces/Imsd-Qmi.cppm` | `imsd::qmi` — the QMI WDS request bytes `imsd-pcscf` sends (Bind Mux Data Port, Set IP Family, Get Packet Service Status, Get Current Settings, Get Profile Settings), the message/TLV parser, the P-CSCF list readers (0x22 flag, 0x23 IPv4, 0x24 FQDN, 0x2E IPv6 — the last one libqmi does not model). |
| `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control and messaging (`Gated`'s `Action` parameter names the action), shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. | | `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control and messaging (`Gated`'s `Action` parameter names the action), shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. |
| `implementations/main.cpp` | The `imsd` daemon shell: GLib main loop, GDBus service, sockets, subprocesses, the registration sequence and the run loop that pumps the core. | | `implementations/main.cpp` | The `imsd` daemon shell: GLib main loop, GDBus service, sockets, subprocesses, the registration sequence and the run loop that pumps the core. |
@ -339,7 +339,8 @@ What the suites pin:
its extension table and the septet packing (the classic "hellohello" its extension table and the septet packing (the classic "hellohello"
vector), UCS-2 with surrogate pairs (and U+0000 as U+FFFD), the address fields (international, vector), UCS-2 with surrogate pairs (and U+0000 as U+FFFD), the address fields (international,
a short code, `*`/`#`, an alphanumeric sender), SMS-SUBMIT (the classic a short code, `*`/`#`, an alphanumeric sender), SMS-SUBMIT (the classic
tutorial PDU, UCS-2, the concatenated pair for a 161-character text, an tutorial PDU, UCS-2, one with TP-RD, the concatenated pair for a
161-character text and the one for a 71-character text in UCS-2, an
escape pair and a surrogate pair kept whole at a segment boundary, the escape pair and a surrogate pair kept whole at a segment boundary, the
160/70-character fits), SMS-DELIVER (the classic "How are you?" PDU; a 160/70-character fits), SMS-DELIVER (the classic "How are you?" PDU; a
header with fill bits, a 16-bit concatenation reference, class 0, header with fill bits, a 16-bit concatenation reference, class 0,
@ -350,7 +351,8 @@ What the suites pin:
TS 23.040 9.2.3.15 has the MS read it: every reserved value, bit 7 set TS 23.040 9.2.3.15 has the MS read it: every reserved value, bit 7 set
among them, as "Service Rejected") and among them, as "Service Rejected") and
SMS-SUBMIT-REPORT, RP-DATA / RP-ACK / RP-ERROR both ways (a type read SMS-SUBMIT-REPORT, RP-DATA / RP-ACK / RP-ERROR both ways (a type read
against its direction refused), EF_SMSP on the KPN SIM's record (dev against its direction refused), which RP causes of a submission have the
segment sent again (all 128 values), EF_SMSP on the KPN SIM's record (dev
phone, 2026-10-16) straight from qmicli's dump, and the `Reassembler` phone, 2026-10-16) straight from qmicli's dump, and the `Reassembler`
(segments out of order, a lone message, a set dropped by `Purge`, a (segments out of order, a lone message, a set dropped by `Purge`, a
surrogate pair and an escape pair split across two segments whole surrogate pair and an escape pair split across two segments whole
@ -372,9 +374,27 @@ What the suites pin:
network terminated); and SMS over IP (TS 24.341): `SmsOutbound` through a network terminated); and SMS over IP (TS 24.341): `SmsOutbound` through a
submission — the MESSAGE with the RP-DATA to the SC's PSI, its 202, the submission — the MESSAGE with the RP-DATA to the SC's PSI, its 202, the
RP-ACK ending it as sent with the SC's time stamp; a refused final; an RP-ACK ending it as sent with the SC's time stamp; a refused final; an
RP-ERROR with its cause and TP-FCS; the final's wait and the report's running out; a RP-ERROR with its cause and TP-FCS; the final's wait and the report's
running out (128 s and 130 s), each followed by the segment's repeat — the same
SMS-SUBMIT with TP-RD set and no other bit changed, under a Call-ID and
an RP-MR of its own — and the repeat accepted, rejected as a duplicate
(sent, with RP cause 41 as with another) or ended in its turn (failed,
both ends in the reason); a
duplicate rejection of a first attempt, a refusal like any other (RP
cause 21: failed), and one of a repeat whose first attempt an RP-ERROR
had refused, before the repeat went out or after (failed, both refusals
in the reason); the first attempt's
RP-ACK after the repeat went out taken by In-Reply-To and by RP-MR, its
RP-ERROR then — cause 41 or 28 — leaving the segment to the repeat's
answer (sent on its RP-ACK; failed on its wait, that RP-ERROR named as
the first attempt's end); an RP-ERROR with cause 41 repeated, and one
with a cause part 1 does not list (0, 2); one with 38, 42 or 47 failing
at once; a first segment's RP-ERROR not weighing
on the second segment's repeat; a 408 and a 504 final repeated,
a 403, a 480, a 500 and a 503 failing at once; a repeat the flow could
not send; a
failed send; two segments with consecutive RP-MR/TP-MR, the second sent failed send; two segments with consecutive RP-MR/TP-MR, the second sent
on the first's RP-ACK; a destination that is no number; no service on the first's RP-ACK, a repeat under the next RP-MR; a destination that is no number; no service
centre — and `OnSmsMessage`: a delivered message to the bus and its centre — and `OnSmsMessage`: a delivered message to the bus and its
RP-ACK to the IP-SM-GW with In-Reply-To, a concatenated pair handed over RP-ACK to the IP-SM-GW with In-Reply-To, a concatenated pair handed over
once whole and each segment acknowledged, a status report, a submit once whole and each segment acknowledged, a status report, a submit
@ -653,7 +673,7 @@ Rules:
capture, `phone/arms.out` and `phone-form6/arms.out`): a refused final to a submission's MESSAGE, an RP-ERROR this capture, `phone/arms.out` and `phone-form6/arms.out`): a refused final to a submission's MESSAGE, an RP-ERROR this
code sends (the cause-96 unusable-TPDU path; an RP-ERROR that came in was code sends (the cause-96 unusable-TPDU path; an RP-ERROR that came in was
reached: `smsc-override-2026-10-18-0217`, 02:19:41, RP cause 28 + TP-FCS reached: `smsc-override-2026-10-18-0217`, 02:19:41, RP cause 28 + TP-FCS
0xc1, through `OnReport`), the final's wait running out, the report's wait ending a message as `failed`, a dead flow under a `Send`, a status report (one requested 0xc1, through `OnReport`), the final's wait running out (the report's ran out on the dev phone: the repeat's benches, below), a dead flow under a `Send`, a status report (one requested
at 01:33 with TP-SRR; none came in the following 11 minutes — the at 01:33 with TP-SRR; none came in the following 11 minutes — the
unfiltered journal of 01:33:30–01:45:00, unfiltered journal of 01:33:30–01:45:00,
`r23-phone-journal-2026-10-17-precise-and-modem-sms`; whether KPN's SC `r23-phone-journal-2026-10-17-precise-and-modem-sms`; whether KPN's SC
@ -728,6 +748,22 @@ Rules:
`checks.log`: a text sent to the own number over the bus, delivered `checks.log`: a text sent to the own number over the bus, delivered
back and listed); no capture holds a `Received` with them; the store's back and listed); no capture holds a `Received` with them; the store's
round trip with each is in `tests/Engine`. round trip with each is in `tests/Engine`.
A segment's repeat ran on the dev phone against KPN (2026-11-22, the fp6
journal's `2026-11-20-issues-2-5` capture, `phone-form6`,
`repeat-bench.log`, the binary of 1.2.1): with the
phone deaf on its protected server port a text to the own number got
its 202 and no submit report and went out again 130 s after the final,
under RP-MR 178 after 177, with TP-MR 16 and TP-RD; the repeat got an
RP-ACK under a time stamp of its own (`sent`), and once the port was
open again the text came twice, under the two attempts' time stamps;
the message after it took RP-MR 179. The six benches before it went the
same way (`phone-form6/visit1` to `visit5`, 2026-11-21 and 2026-11-22,
on earlier builds; `phone`, 2026-11-20, on one that waited
40 s). Run on no hardware: a repeat after the final's wait,
a 408, a 504 or an RP-ERROR; a repeat rejected as a duplicate, and one
ended in its turn; the first attempt's report after its repeat went
out.
`tests/Engine` pins the reducer for each.
- A request cut short of its Content-Length on the client flow ran on the - A request cut short of its Content-Length on the client flow ran on the
workstation's loopback (2026-11-22, the fp6 journal's workstation's loopback (2026-11-22, the fp6 journal's
`2026-11-20-issues-2-5` capture, `cut-short`: `SipFlow` built around a `2026-11-20-issues-2-5` capture, `cut-short`: `SipFlow` built around a
@ -1586,14 +1622,28 @@ Lines the operator (and the scripts) look for, all prefixed `imsd: `:
international number (+ and digits); …` and `SMS over IP: on (+g.3gpp.smsip international number (+ and digits); …` and `SMS over IP: on (+g.3gpp.smsip
advertised: …)`; per message of ours `sms <id>: segment i/n to <number> advertised: …)`; per message of ours `sms <id>: segment i/n to <number>
via <uri>: MESSAGE sent (RP-MR a, TP-MR b, N bytes)`, `sms <id>: segment via <uri>: MESSAGE sent (RP-MR a, TP-MR b, N bytes)`, `sms <id>: segment
i/n -> <code>; awaiting the submit report`, then `sms <id>: sent: …` or i/n -> <code>; awaiting the submit report`, for a segment's repeat `sms
<id>: <how the first attempt ended>; sending the segment again, TP-RD
set` and `sms <id>: segment i/n to <number> via <uri>: MESSAGE sent again
(RP-MR a, TP-MR b with TP-RD, N bytes)`, and after it `sms <id>: segment
i/n: the repeat was rejected as a duplicate (RP cause N (…), TP-FCS
0xc5 (…)): the first attempt is taken for accepted`, `sms <id>: segment i/n: the first attempt's
submit report came after the repeat went out: accepted` or `sms <id>:
segment i/n refused by the SC: RP cause N (…)[, TP-FCS 0xNN (…)], in the
first attempt's report, which came after the repeat went out: the
repeat's decides`,
then `sms <id>: sent: …` or
`sms <id>: failed: …` (the reason: `'…' is not a number`, `no service `sms <id>: failed: …` (the reason: `'…' is not a number`, `no service
centre …`, `the text does not fit 255 segments`, `imsd is not registered`, `the flow to the P-CSCF is down`, centre …`, `the text does not fit 255 segments`, `imsd is not registered`, `the flow to the P-CSCF is down`,
`segment i/n refused: <status and its Retry-After / Warning / Reason / Server headers>`, `segment i/n refused `segment i/n refused: <status and its Retry-After / Warning / Reason / Server headers>`, `segment i/n refused
by the SC: RP cause N (…)[, TP-FCS 0xNN (…)]`, `no answer to the MESSAGE by the SC: RP cause N (…)[, TP-FCS 0xNN (…)]`, `no answer to the MESSAGE
of segment i/n within 32 s`, `no submit report for segment i/n within of segment i/n within 128 s`, `no submit report for segment i/n within
40 s of the final`, `segment i/n not sent: the flow to the P-CSCF is 130 s of the final`, `segment i/n not sent: the flow to the P-CSCF is
down`) and, after a status report, `sms <id>: delivered|delivery-pending| down`; of a segment that was sent again the reason is the repeat's
followed by `; the first attempt: <that attempt's>` — for a first
attempt that an RP-ERROR answered after the repeat went out, `segment
i/n refused by the SC: RP cause N (…)[, TP-FCS 0xNN (…)], in a report
that came after the repeat went out`) and, after a status report, `sms <id>: delivered|delivery-pending|
delivery-failed: <TP-ST in words>` or `sms <id>: a segment delivered delivery-failed: <TP-ST in words>` or `sms <id>: a segment delivered
(TP-MR n); k still to be reported`, and for a report's word on the (TP-MR n); k still to be reported`, and for a report's word on the
message still in flight `sms <id>: delivered|delivery-pending| message still in flight `sms <id>: delivered|delivery-pending|
@ -1817,21 +1867,88 @@ do that answers without state.
escape or surrogate pair never split), TP-MR counting up per segment from escape or surrogate pair never split), TP-MR counting up per segment from
the one in `/var/lib/imsd/sms-tpmr`, random only when the file gives none (TS 23.040 9.2.3.6's the one in `/var/lib/imsd/sms-tpmr`, random only when the file gives none (TS 23.040 9.2.3.6's
Last-Used-TP-MR on the (U)SIM is not read or written), RP-MR from a Last-Used-TP-MR on the (U)SIM is not read or written), RP-MR from a
counter seeded at random at start. One message on the counter seeded at random at start, the next for every MESSAGE built
for a submission, one the flow could not send too. One message on the
flow at a time, segment by segment: the MESSAGE with the flow at a time, segment by segment: the MESSAGE with the
RP-DATA, its final within 32 s of the MESSAGE or of its latest provisional (a RP-DATA, its final within 128 s of the MESSAGE or of its latest provisional (a
provisional starts the wait over); the submit report — an provisional starts the wait over); the submit report — an
RP-ACK or RP-ERROR in a MESSAGE of its own, matched by In-Reply-To, else RP-ACK or RP-ERROR in a MESSAGE of its own, matched by In-Reply-To, else
by RP-MR, answered 200 — within 40 s of a 2xx final (a length TS 24.011 by RP-MR, answered 200 — within 130 s of a 2xx final; then the
10.1 allows TR1M, which 6.3.1 sets when the RP-DATA is transferred); then the next segment. The two waits are a UE's (Jorijn, 2026-11-21; 1.2.0 waited
next segment. Every 32 s and 40 s): TS 24.229 table 7.7.1 recommends a UE whose requests name
segment's RP-ACK: `sent`, with the SC's time stamp when its submit one of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s and a
report carries one; a refused final, an RP-ERROR (its cause and the timer F of 64*T1,
submit report's TP-FCS), a wait that runs out or a flow that is down: and TS 24.341 5.3.1.1 NOTE 1 has an
`failed` with the reason; a wait is judged at the run loop's passes, SM-over-IP sender's TR1M set to a value greater than timer F — past the
35 to 45 s of TS 24.011 10.1, and here counted from the final, where
6.3.1 sets TR1M when the RP-DATA is transferred. A segment that gets no answer, or an RP-ERROR with cause 41, is
sent once more, as TS 23.040 9.2.3.6 has the MS "automatically repeat
the SMS-SUBMIT" (one to three times; here once): when the final's wait
or the report's runs out, when the final is a 408 or a 504 — no
response in time (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"), which leaves the MESSAGE's
fate as open as no final — 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" (`RpCauseIsTemporary`; 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", and of 38 that "immediately
reattempting the short message transfer is not likely to be
successful"). The repeat is a MESSAGE of its
own — its Call-ID, the next RP-MR — carrying the same SMS-SUBMIT, the same
TP-MR, with TP-RD set, by which a service centre that has the first
"should discard" it and answer with an RP-ERROR whose TP-FCS is the
duplicate rejection (0xC5), or with an RP-ACK (9.2.3.6): either ends the
segment as accepted, and so does the first attempt's own RP-ACK when
it comes after the repeat went out. The duplicate rejection is taken so
only where no RP-ERROR has answered the first attempt by then — after
one it is a refusal like any other —, and an RP-ERROR to the first
attempt that comes after the repeat went out leaves the segment to the
repeat's answer; one that comes once the rejection has ended the
segment is answered and logged (Receiving, below) and changes
nothing. An RP-ACK to the repeat is an acceptance whatever became
of the first attempt: the clause lets a service centre answer a repeat
it discards with an RP-ACK as well ("for backward compatibility … may
be configured to respond with an RP-ACK"), which nothing tells from an
acceptance. What the rejection does not say is which SMS-SUBMIT the service
centre holds: imsd's TP-MR is its own count (above), so an SMS-SUBMIT
of this subscription that reached the service centre another way — the
modem's own short message stack — under the same TP-MR can draw the same
rejection, and where imsd's first attempt never arrived the message is
then `sent` for a text the service centre does not have (Jorijn,
2026-11-21: taken as the clause has it). KPN's service centre did not discard it in
seven benches of seven (2026-11-20 to 2026-11-22, §5): each time it
took the repeat for a new text — an RP-ACK under a time stamp of its
own — and delivered both. The repeat is
sent all the same (Jorijn, 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 fp6 journal's
`2026-11-20-issues-2-5` capture, `repeat-research`). A status report is
matched by TP-MR, which both copies carry: of two reports under one
TP-MR the first of the completed class, or of one in which the service
centre has stopped trying, is taken, and a report after it is logged as
naming no message of ours — so for a message that ended `sent`, a first
copy reported failed gives `delivery-failed` though the other may
still be delivered. Every segment accepted: `sent`, with the SC's
time stamp from the latest RP-ACK whose submit report carried one; a
final refused with another status, an RP-ERROR with another cause (its
cause and the submit report's TP-FCS), a MESSAGE the flow
cannot send, or a repeat that ends short of an acceptance: `failed` with the
reason — after a repeat the repeat's end and the first attempt's —, at
once: a report that still comes for the first attempt is then answered
and logged (Receiving, below) and changes nothing; a wait is judged at the run loop's passes,
after the server ports are read, so an answer read before that counts after the server ports are read, so an answer read before that counts
however late. No retransmission (9.2.3.6's repeat with however late. Not done of the clause's repeat: it cannot be switched off
TP-RD is not done): the sender retries. A `Send` is judged when the engine ("should be capable of being disabled through MMI"), and a failed
message is not kept for the user to send again under its TP-MR — a
`Send` of the same text is a new message with the next TP-MR, which the
service centre cannot tell from a new text; and a final refused with
another status than 408 or 504 is taken for the network's refusal of the
MESSAGE, not for the clause's "no response", though it brings no RP-ACK
or RP-ERROR either. A `Send` is judged when the engine
takes its command up: unregistered or with the flow down at that moment, takes its command up: unregistered or with the flow down at that moment,
it fails with that reason and is not held for a recovery step; otherwise it fails with that reason and is not held for a recovery step; otherwise
it starts, or queues behind the message in flight, and a queued message it starts, or queues behind the message in flight, and a queued message
@ -1885,14 +2002,14 @@ do that answers without state.
status report that does not parse, or one of the submit-report type — is status report that does not parse, or one of the submit-report type — is
acknowledged the same way with an RP-ERROR (cause 96, TP-FCS "TPDU not supported"). A submit acknowledged the same way with an RP-ERROR (cause 96, TP-FCS "TPDU not supported"). A submit
report In-Reply-To a MESSAGE of ours that is no longer in flight — its report In-Reply-To a MESSAGE of ours that is no longer in flight — its
message has ended (its report's wait run out, judged by the shell; a message has ended (its waits run out, judged by the shell; a
failure; sent) or its segment was followed by the next — is answered 200 failure; sent) or its segment was followed by the next — is answered 200
and logged with the message's id and, for an RP-ERROR, its cause, for an and logged with the message's id and, for an RP-ERROR, its cause, for an
hour after that MESSAGE went out (`RecentSubmissions`: 5.3.1.2's 200 for hour after that MESSAGE went out (`RecentSubmissions`: 5.3.1.2's 200 for
a report on "a short message submitted by the SM-over-IP sender", whose a report on "a short message submitted by the SM-over-IP sender", whose
Call-ID its NOTE 3 has the sender store). The bus hears nothing of it: Call-ID its NOTE 3 has the sender store). The bus hears nothing of it:
`failed` is a message's last word (§8.4), so a text the service centre `failed` is a message's last word (§8.4), so a text the service centre
took after its wait had run out stays `failed` there, and the journal's took after its waits had run out stays `failed` there, and the journal's
line is the record of it. One In-Reply-To no MESSAGE of ours on record — line is the record of it. One In-Reply-To no MESSAGE of ours on record —
a stranger's, ours of more than an hour ago, ours of before a restart — a stranger's, ours of more than an hour ago, ours of before a restart —
is answered 488, which for the last two departs from the clause: it has is answered 488, which for the last two departs from the clause: it has

View file

@ -158,7 +158,7 @@ imsd gives may gain a key.
| `List()` | `→ a(sa{sv})`: the stored messages, by the arrival second on the phone's wall clock, then within a run the sequence number (a 1970 clock before the first time sync sorts first; the SC's `timestamp` is the real chronology), each the id and the dictionary `Received` carries; `IOError` when a store that is there cannot be read | | `List()` | `→ a(sa{sv})`: the stored messages, by the arrival second on the phone's wall clock, then within a run the sequence number (a 1970 clock before the first time sync sorts first; the SC's `timestamp` is the real chronology), each the id and the dictionary `Received` carries; `IOError` when a store that is there cannot be read |
| `Delete(id)` | `s`: removes a stored message | | `Delete(id)` | `s`: removes a stored message |
| `Received` | `s a{sv}` (id, message: `from`, `text`, `timestamp` (the SC's, as `2026-10-16T22:50:00+02:00`), `received` (x), `sc`, `to` (when the daemon held an own number at receipt: that number, e.g. `tel:+31612345678`), `operator` (the SIM's operator id at receipt), `class` (i, -1 none), `pid` (y), `dcs` (y), `segments` (i), `message-waiting` (b), `port-dst`/`port-src` (u, when addressed to a port), `data` (ay, 8-bit data), `pdu` (ay, the SMS-DELIVER as received; of a concatenated message, the segment that completed it)) | | `Received` | `s a{sv}` (id, message: `from`, `text`, `timestamp` (the SC's, as `2026-10-16T22:50:00+02:00`), `received` (x), `sc`, `to` (when the daemon held an own number at receipt: that number, e.g. `tel:+31612345678`), `operator` (the SIM's operator id at receipt), `class` (i, -1 none), `pid` (y), `dcs` (y), `segments` (i), `message-waiting` (b), `port-dst`/`port-src` (u, when addressed to a port), `data` (ay, 8-bit data), `pdu` (ay, the SMS-DELIVER as received; of a concatenated message, the segment that completed it)) |
| `StateChanged` | `s s s` (id, state, reason): `sent` (every segment accepted by the SC), `failed` (why), and with a status report `delivered` (every segment), `delivery-pending`, `delivery-failed` — each speaks for the whole message, never for one segment, and `delivery-pending` can come more than once | | `StateChanged` | `s s s` (id, state, reason): `sent` (every segment accepted by the SC; AGENTS.md §7.9 has what counts as accepted when a segment was sent twice), `failed` (why), and with a status report `delivered` (every segment), `delivery-pending`, `delivery-failed` — each speaks for the whole message, never for one segment, and `delivery-pending` can come more than once |
`Send`, `Subscribe`, `List` and `Delete` are gated by polkit's `net.catcrafts.IMS1.Messaging`. `Send`, `Subscribe`, `List` and `Delete` are gated by polkit's `net.catcrafts.IMS1.Messaging`.

View file

@ -1506,7 +1506,7 @@ public:
// after the server ports were drained: a submit report that landed // after the server ports were drained: a submit report that landed
// during a blocking re-REGISTER below must not count as a timeout // during a blocking re-REGISTER below must not count as a timeout
if (smsOut_ && smsOut_->Deadline() > 0 && Mono() > smsOut_->Deadline()) { if (smsOut_ && smsOut_->Deadline() > 0 && Mono() > smsOut_->Deadline()) {
ExecuteSms(smsOut_->OnDeadline()); ExecuteSms(smsOut_->OnDeadline(Mono()));
AfterSms(); AfterSms();
} }
// a concatenated set that got no segment for §7.9's 30 min ages out // a concatenated set that got no segment for §7.9's 30 min ages out
@ -2944,20 +2944,26 @@ private:
const std::size_t segments = smsOut_->Segments(); const std::size_t segments = smsOut_->Segments();
tpMr_ = static_cast<std::uint8_t>(tpMr_ + segments); tpMr_ = static_cast<std::uint8_t>(tpMr_ + segments);
if (segments > 0) SaveTpMr(tpMr_); if (segments > 0) SaveTpMr(tpMr_);
rpMr_ = static_cast<std::uint8_t>(rpMr_ + segments);
if (segments > 1) concatRef_++; if (segments > 1) concatRef_++;
for (const auto& a : actions) for (const auto& a : actions)
if (a.type == imsd::engine::SmsAction::Type::SendClient) DumpRaw("imsd-message-out.raw", a.text); if (a.type == imsd::engine::SmsAction::Type::SendClient) DumpRaw("imsd-message-out.raw", a.text);
ExecuteSms(actions); ExecuteSms(actions);
if (smsOut_ && smsOut_->Done()) smsOut_.reset(); if (smsOut_ && smsOut_->Done()) EndSms();
} }
} }
// The message in flight has ended: the RP-MR counter goes on after the
// last it used (every MESSAGE built for it took one, a repeat too).
void EndSms() {
rpMr_ = smsOut_->NextRpMr();
smsOut_.reset();
}
// The message in flight ended: the next queued message starts (its // The message in flight ended: the next queued message starts (its
// TP-MRs went on record when it started). // TP-MRs went on record when it started).
void AfterSms() { void AfterSms() {
if (!smsOut_ || !smsOut_->Done()) return; if (!smsOut_ || !smsOut_->Done()) return;
smsOut_.reset(); EndSms();
StartNextSms(); StartNextSms();
} }

View file

@ -30,7 +30,8 @@ local-hangup/remote-hangup/refused-or-busy/error).
SMS over IP (TS 24.341) has its own reducers at the end: SmsOutbound, one SMS over IP (TS 24.341) has its own reducers at the end: SmsOutbound, one
short message of ours on its way to the service centre segment by segment short message of ours on its way to the service centre segment by segment
(the MESSAGE with the RP-DATA, its final, the submit report that comes (the MESSAGE with the RP-DATA, its final, the submit report that comes
back in a MESSAGE of its own), and OnSmsMessage, what an inbound back in a MESSAGE of its own; a segment that gets no answer, or an
RP-ERROR with cause 41, sent once more, TP-RD set), and OnSmsMessage, what an inbound
MESSAGE outside a call's dialog leads to (the final for it, the message or MESSAGE outside a call's dialog leads to (the final for it, the message or
status report it delivered, the delivery report to send), with status report it delivered, the delivery report to send), with
RecentTransactions (a retransmitted request within 32 s gets its final RecentTransactions (a retransmitted request within 32 s gets its final
@ -1066,10 +1067,10 @@ export namespace imsd::engine {
// "indicates that the request corresponds to a short message submitted // "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 // 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. The message in flight // has the sender store the Call-ID for that. The message in flight
// knows its own MESSAGE (SmsOutbound); this table keeps every one for // knows the MESSAGEs of its segment in flight (SmsOutbound); this table
// an hour after it went out, so a report that comes once its message // keeps every one for an hour after it went out, so a report that comes
// has ended — its wait run out, say — or once its segment was followed // once its message has ended — its waits run out, say — or once its
// by the next is still known for ours: answered 200 and logged with // segment was followed by the next is still known for ours: answered 200 and logged with
// the message's id. Nothing else follows from it: a message that has // the message's id. Nothing else follows from it: a message that has
// ended has had its word on the bus, and `failed` is its last (§8.4); // ended has had its word on the bus, and `failed` is its last (§8.4);
// one whose next segment is in flight goes on as it was. The table is // one whose next segment is in flight goes on as it was. The table is
@ -1100,15 +1101,19 @@ export namespace imsd::engine {
std::map<std::string, Entry, std::less<>> byCallId_; std::map<std::string, Entry, std::less<>> byCallId_;
}; };
// The waits (TS 24.011 10: TR1M; TS 24.341 5.3.1.1 NOTE 1 has it // The waits. TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP sender's TR1M
// exceed SIP timer F): a MESSAGE's final within 32 s // set to a value greater than SIP timer F, and TS 24.229 table 7.7.1
// of the MESSAGE or of its latest provisional, which starts the wait // recommends a UE on a 3GPP access a T1 of 2 s and a timer F of 64*T1.
// over; the submit report within 40 s of the final — a length TR1M may // So: a MESSAGE's final within 128 s of the MESSAGE — or of its latest
// have, though 6.3.1 sets TR1M when the RP-DATA is transferred. // provisional, which starts the wait over here, as it did in 1.2.0;
inline constexpr double SmsSendTimeout = 32.0; // RFC 3261's timer F does not start over —; the submit report within
inline constexpr double SmsReportTimeout = 40.0; // 130 s of the final — past the 35 to 45 s TS 24.011 10.1 has for
// What the bus hears: `sent` once every segment's submit report is // TR1M, as the NOTE asks, and from the final, where 6.3.1 sets TR1M
// in, `failed` with the reason; a status report's word // when the RP-DATA is transferred.
inline constexpr double SmsSendTimeout = 128.0;
inline constexpr double SmsReportTimeout = 130.0;
// What the bus hears: `sent` once the service centre has accepted
// every segment, `failed` with the reason; a status report's word
// after `sent` (StatusReportBook, SmsWordOrder, which also has the one // after `sent` (StatusReportBook, SmsWordOrder, which also has the one
// failure posted as `sent`). // failure posted as `sent`).
inline constexpr std::string_view SmsStateSent = "sent"; inline constexpr std::string_view SmsStateSent = "sent";
@ -1167,14 +1172,43 @@ export namespace imsd::engine {
std::optional<Word> held_; std::optional<Word> held_;
}; };
// A segment's MESSAGEs at most: the first and one repeat. TS 23.040
// 9.2.3.6 has the MS repeat an SMS-SUBMIT that got no answer "in the
// range 1 to 3" times and leaves the number to the implementation.
inline constexpr std::size_t SmsAttempts = 2;
// One short message of ours on its way to the service centre, segment // One short message of ours on its way to the service centre, segment
// by segment: the MESSAGE with the segment's RP-DATA, its final, the // by segment: the MESSAGE with the segment's RP-DATA, its final, the
// submit report, then the next segment. RP-MR and TP-MR count up from // submit report, then the next segment. RP-MR and TP-MR count up from
// the values the shell hands over (TS 23.040 9.2.3.6, 9.2.3.24.1; the // the values the shell hands over (TS 23.040 9.2.3.6, 9.2.3.24.1; the
// shell keeps the counters across messages). No retransmission: an // shell keeps the counters across messages).
// unanswered MESSAGE or a report that never comes fails the message //
// (TS 23.040 9.2.3.6's automatic repeat with TP-RD is not done) and // A segment that gets no answer, or an RP-ERROR with cause 41, is sent
// the bus hears why. // once more, as 9.2.3.6 has it: "In the case where no response or an
// RP-ERROR with an appropriate cause value (see 3GPP TS 24.011 [13]) is
// received in response to an SMS-SUBMIT, then the MS shall automatically
// repeat the SMS-SUBMIT but must use the same TP-MR value and set the
// TP-RD bit to 1". Here that is: the final's wait or the report's run
// out; a final of 408 or 504 — no response in time, the server's own
// (RFC 3261 21.4.9) or one it waited for (21.5.5), so what became of
// the MESSAGE past it is as unknown as with no final; an RP-ERROR whose
// cause invites another attempt at once (RpCauseIsTemporary). The
// repeat is a MESSAGE of its own — its Call-ID, the next RP-MR — with
// the same SMS-SUBMIT, TP-RD set. A service centre that has the first
// "should discard" the repeat and answer it with an RP-ERROR whose
// TP-FCS is the duplicate rejection (0xC5), or with an RP-ACK (9.2.3.6
// again): either ends the segment as accepted — the rejection only
// where no RP-ERROR has refused the first attempt by then — and so
// does the first attempt's own RP-ACK when it comes after the repeat
// went out; its RP-ERROR then leaves the segment to the repeat's
// answer, and one that comes once that answer has ended the segment
// changes nothing (OnSmsMessage logs it). Any
// other refusal — a final that is neither of the two, an RP-ERROR with
// another cause, a flow that is down — fails the message at once, and
// so does whatever ends the repeat short of an acceptance; the reason
// then names the first attempt's end as well. Not done of the clause's
// repeat: it cannot be switched off, and a failed message is not kept
// for the user to send again under its TP-MR.
class SmsOutbound { class SmsOutbound {
public: public:
struct Params { struct Params {
@ -1192,10 +1226,10 @@ export namespace imsd::engine {
// `submitted`: where each MESSAGE this message goes out in is put on record // `submitted`: where each MESSAGE this message goes out in is put on record
SmsOutbound(const imsd::msg::Context& ctx, imsd::util::Rng& rng, RecentSubmissions& submitted, std::string id, Params p) SmsOutbound(const imsd::msg::Context& ctx, imsd::util::Rng& rng, RecentSubmissions& submitted, std::string id, Params p)
: ctx_(ctx), rng_(rng), submitted_(submitted), id_(std::move(id)), p_(std::move(p)) {} : ctx_(ctx), rng_(rng), submitted_(submitted), id_(std::move(id)), p_(std::move(p)), nextRpMr_(p_.rpMr) {}
const std::string& Id() const { return id_; } const std::string& Id() const { return id_; }
// the segment in flight's MESSAGE (empty before the first went out) // the MESSAGE in flight — the segment in flight's latest (empty before the first went out)
const std::string& CallId() const { return callid_; } const std::string& CallId() const { return callid_; }
Phase State() const { return phase_; } Phase State() const { return phase_; }
bool Done() const { return phase_ == Phase::Done; } bool Done() const { return phase_ == Phase::Done; }
@ -1205,6 +1239,11 @@ export namespace imsd::engine {
// later status report to this message // later status report to this message
const std::vector<std::uint8_t>& TpMrs() const { return tpMrs_; } const std::vector<std::uint8_t>& TpMrs() const { return tpMrs_; }
std::size_t Segments() const { return tpdus_.size(); } std::size_t Segments() const { return tpdus_.size(); }
// The RP-MR after the last this message used — every MESSAGE built
// for it took the next one from `rpMr` on, one the flow could not
// send as well: where the shell's counter goes on once the message
// has ended.
std::uint8_t NextRpMr() const { return nextRpMr_; }
// Builds the segments and sends the first. A destination that is // Builds the segments and sends the first. A destination that is
// no number, or a text past 255 segments, fails the message at once. // no number, or a text past 255 segments, fails the message at once.
@ -1223,13 +1262,16 @@ export namespace imsd::engine {
out.push_back(Fail("no service centre (none from SMSC= or EF_SMSP)")); out.push_back(Fail("no service centre (none from SMSC= or EF_SMSP)"));
return out; return out;
} }
s.rejectDuplicates = true; // each segment's repeat: the same SMS-SUBMIT with TP-RD set
repeats_ = imsd::sms::BuildSubmits(s, p_.text, p_.concatRef);
for (std::size_t i = 0; i < tpdus_.size(); i++) tpMrs_.push_back(static_cast<std::uint8_t>((p_.tpMr + i) & 0xFF)); for (std::size_t i = 0; i < tpdus_.size(); i++) tpMrs_.push_back(static_cast<std::uint8_t>((p_.tpMr + i) & 0xFF));
SendSegment(out, now); SendSegment(out, now);
return out; return out;
} }
// The segment in flight's MESSAGE: its final is matched by Call-ID // The MESSAGE in flight: its final is matched by Call-ID and CSeq.
// and CSeq. // The first attempt's final, come after the repeat went out, is
// nobody's.
bool OwnsResponse(std::string_view msg) const { bool OwnsResponse(std::string_view msg) const {
return phase_ == Phase::Sending && imsd::sip::ResponseOf(msg, callid_, "1 MESSAGE"); return phase_ == Phase::Sending && imsd::sip::ResponseOf(msg, callid_, "1 MESSAGE");
} }
@ -1242,8 +1284,13 @@ export namespace imsd::engine {
return out; return out;
} }
if (status >= 300) { if (status >= 300) {
std::string why = std::format("segment {}/{} refused: {}", seg_ + 1, tpdus_.size(), imsd::sip::RefusalSummary(msg));
if (status == 408 || status == 504) { // Request Timeout, Server Time-out: no word on the MESSAGE's fate
EndAttempt(out, now, std::move(why));
return out;
}
phase_ = Phase::Done; phase_ = Phase::Done;
out.push_back(Fail(std::format("segment {}/{} refused: {}", seg_ + 1, tpdus_.size(), imsd::sip::RefusalSummary(msg)))); out.push_back(Fail(std::move(why)));
return out; return out;
} }
phase_ = Phase::AwaitingReport; phase_ = Phase::AwaitingReport;
@ -1252,51 +1299,79 @@ export namespace imsd::engine {
return out; return out;
} }
// Whether an RP-ACK/RP-ERROR the IP-SM-GW sent is this segment's: // Which of the segment in flight's MESSAGEs an RP-ACK/RP-ERROR the
// In-Reply-To names our MESSAGE (TS 24.341 5.3.1.2), or — from an // IP-SM-GW sent answers — 0 the first, 1 its repeat — or none of
// IP-SM-GW that sends none — the RP-MR is the one in flight. A // them: by In-Reply-To when the report has one (TS 24.341 5.3.1.2;
// report arriving before the MESSAGE's own final (the IP-SM-GW's // the later MESSAGE when it lists both), else — from an IP-SM-GW
// order is its own) is taken as well. // that sends none — by RP-MR. A report arriving before the
bool OwnsReport(std::string_view inReplyTo, std::optional<std::uint8_t> rpMr) const { // MESSAGE's own final (the IP-SM-GW's order is its own) is taken as
if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return false; // well.
if (!inReplyTo.empty()) // a list of Call-IDs (RFC 3261 20.21): ours among them std::optional<std::size_t> ReportAttempt(std::string_view inReplyTo, std::optional<std::uint8_t> rpMr) const {
return std::ranges::contains(InReplyToCallIds(inReplyTo), std::string_view(callid_)); if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return std::nullopt;
return rpMr && *rpMr == CurrentRpMr(); const std::vector<std::string_view> named = InReplyToCallIds(inReplyTo); // a list of Call-IDs (RFC 3261 20.21): ours among them
for (std::size_t k = attempts_.size(); k-- > 0;) {
if (!inReplyTo.empty() ? std::ranges::contains(named, std::string_view(attempts_[k].callid)) : rpMr && *rpMr == attempts_[k].rpMr) return k;
}
return std::nullopt;
} }
// The submit report for the segment in flight: an RP-ACK moves to // The submit report for the segment in flight, answering its
// the next segment, or ends the message as sent; an RP-ERROR fails // MESSAGE number `attempt` (ReportAttempt; none given: the one in
// it with its cause. The shell answers the report's MESSAGE // flight). An RP-ACK to either attempt moves to the next segment,
// itself. // or ends the message as sent. An RP-ERROR to the first attempt,
std::vector<SmsAction> OnReport(const imsd::sms::Rp& rp, double now) { // come after its repeat went out, changes what is known of that
// attempt and nothing else: the repeat's answer ends the segment.
// An RP-ERROR to the attempt in flight: the duplicate rejection
// (TP-FCS 0xC5) of a repeat whose first attempt no RP-ERROR has
// refused so far is taken for that attempt accepted, whatever RP
// cause comes with it — 9.2.3.6 has the service centre discard a
// repeat of what it has —; a cause that
// invites another attempt at once (RpCauseIsTemporary) ends the
// attempt — the repeat follows, or the message has failed —; any
// other fails the message with its cause. The shell answers the
// report's MESSAGE itself.
std::vector<SmsAction> OnReport(const imsd::sms::Rp& rp, double now, std::optional<std::size_t> attempt = std::nullopt) {
std::vector<SmsAction> out; std::vector<SmsAction> out;
if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return out; if (phase_ != Phase::AwaitingReport && phase_ != Phase::Sending) return out;
const std::size_t inFlight = attempts_.size() - 1;
const std::size_t answered = std::min(attempt.value_or(inFlight), inFlight);
const bool late = answered < inFlight; // the first attempt's report, after the repeat went out
if (rp.type == imsd::sms::RpType::ErrorMt) { if (rp.type == imsd::sms::RpType::ErrorMt) {
std::string why = std::format("segment {}/{} refused by the SC: {}", seg_ + 1, tpdus_.size(), RpErrorWords(rp));
if (late) {
out.push_back(LogAct(std::format("sms {}: {}, in the first attempt's report, which came after the repeat went out: the repeat's decides", id_, why)));
firstRefused_ = true;
firstWhy_ = why + ", in a report that came after the repeat went out";
return out;
}
const auto report = imsd::sms::ParseSubmitReport(rp.tpdu, true);
if (answered > 0 && !firstRefused_ && report && report->failureCause == imsd::sms::FcsDuplicateRejected) {
out.push_back(LogAct(std::format("sms {}: segment {}/{}: the repeat was rejected as a duplicate ({}): the first attempt is taken for accepted", id_, seg_ + 1, tpdus_.size(), RpErrorWords(rp))));
Accepted(out, now);
return out;
}
if (imsd::sms::RpCauseIsTemporary(rp.cause.value_or(0))) {
firstRefused_ = true;
EndAttempt(out, now, std::move(why));
return out;
}
phase_ = Phase::Done; phase_ = Phase::Done;
out.push_back(Fail(std::format("segment {}/{} refused by the SC: {}", seg_ + 1, tpdus_.size(), RpErrorWords(rp)))); out.push_back(Fail(std::move(why)));
return out; return out;
} }
if (rp.type != imsd::sms::RpType::AckMt) return out; if (rp.type != imsd::sms::RpType::AckMt) return out;
if (late) out.push_back(LogAct(std::format("sms {}: segment {}/{}: the first attempt's submit report came after the repeat went out: accepted", id_, seg_ + 1, tpdus_.size())));
if (auto r = imsd::sms::ParseSubmitReport(rp.tpdu, false); r && !r->scts.empty()) scts_ = r->scts; if (auto r = imsd::sms::ParseSubmitReport(rp.tpdu, false); r && !r->scts.empty()) scts_ = r->scts;
seg_++; Accepted(out, now);
if (seg_ < tpdus_.size()) { SendSegment(out, now); return out; }
phase_ = Phase::Done;
deadline_ = 0;
out.push_back(StateAct(SmsStateSent, scts_.empty() ? std::format("{} segment(s) accepted by the SC", tpdus_.size()) : std::format("{} segment(s) accepted by the SC at {}", tpdus_.size(), scts_)));
return out; return out;
} }
// The wait ran out: no final to the MESSAGE, or no submit report. // The wait ran out: no final to the MESSAGE, or no submit report.
std::vector<SmsAction> OnDeadline() { std::vector<SmsAction> OnDeadline(double now) {
std::vector<SmsAction> out; std::vector<SmsAction> out;
if (phase_ == Phase::Sending) { if (phase_ == Phase::Sending) EndAttempt(out, now, std::format("no answer to the MESSAGE of segment {}/{} within {:.0f} s", seg_ + 1, tpdus_.size(), SmsSendTimeout));
phase_ = Phase::Done; else if (phase_ == Phase::AwaitingReport) EndAttempt(out, now, std::format("no submit report for segment {}/{} within {:.0f} s of the final", seg_ + 1, tpdus_.size(), SmsReportTimeout));
out.push_back(Fail(std::format("no answer to the MESSAGE of segment {}/{} within {:.0f} s", seg_ + 1, tpdus_.size(), SmsSendTimeout))); else deadline_ = 0;
} else if (phase_ == Phase::AwaitingReport) {
phase_ = Phase::Done;
out.push_back(Fail(std::format("no submit report for segment {}/{} within {:.0f} s of the final", seg_ + 1, tpdus_.size(), SmsReportTimeout)));
}
deadline_ = 0;
return out; return out;
} }
@ -1304,26 +1379,62 @@ export namespace imsd::engine {
std::vector<SmsAction> OnSendFailed() { std::vector<SmsAction> OnSendFailed() {
std::vector<SmsAction> out; std::vector<SmsAction> out;
phase_ = Phase::Done; phase_ = Phase::Done;
deadline_ = 0;
out.push_back(Fail(std::format("segment {}/{} not sent: the flow to the P-CSCF is down", seg_ + 1, tpdus_.size()))); out.push_back(Fail(std::format("segment {}/{} not sent: the flow to the P-CSCF is down", seg_ + 1, tpdus_.size())));
return out; return out;
} }
private: private:
std::uint8_t CurrentRpMr() const { return static_cast<std::uint8_t>((p_.rpMr + seg_) & 0xFF); } // One MESSAGE the segment in flight went out in.
struct Attempt { std::string callid; std::uint8_t rpMr = 0; };
// The segment in flight as a MESSAGE: the first attempt with the
// SMS-SUBMIT as built, the repeat with TP-RD set in it, each under a
// Call-ID of its own and the next RP-MR, so a report without
// In-Reply-To still tells the two.
void SendSegment(std::vector<SmsAction>& out, double now) { void SendSegment(std::vector<SmsAction>& out, double now) {
const bool repeat = !attempts_.empty();
const std::vector<std::uint8_t>& tpdu = repeat ? repeats_[seg_] : tpdus_[seg_];
callid_ = std::format("{}@{}", rng_.Token(16), ctx_.local); callid_ = std::format("{}@{}", rng_.Token(16), ctx_.local);
attempts_.push_back({callid_, nextRpMr_++});
submitted_.Sent(callid_, id_, seg_ + 1, tpdus_.size(), now); submitted_.Sent(callid_, id_, seg_ + 1, tpdus_.size(), now);
std::vector<std::uint8_t> rp = imsd::sms::BuildRpData(CurrentRpMr(), p_.scAddress, tpdus_[seg_]); std::vector<std::uint8_t> rp = imsd::sms::BuildRpData(attempts_.back().rpMr, p_.scAddress, tpdu);
out.push_back(SmsAction{SmsAction::Type::SendClient, imsd::msg::BuildMessageSms(ctx_, p_.scTarget, callid_, rng_.Token(8), rng_.Token(16), rp)}); out.push_back(SmsAction{SmsAction::Type::SendClient, imsd::msg::BuildMessageSms(ctx_, p_.scTarget, callid_, rng_.Token(8), rng_.Token(16), rp)});
out.push_back(LogAct(std::format("sms {}: segment {}/{} to {} via {}: MESSAGE sent (RP-MR {}, TP-MR {}, {} bytes)", id_, seg_ + 1, tpdus_.size(), p_.number, p_.scTarget, CurrentRpMr(), tpMrs_[seg_], tpdus_[seg_].size()))); out.push_back(LogAct(std::format("sms {}: segment {}/{} to {} via {}: MESSAGE sent{} (RP-MR {}, TP-MR {}{}, {} bytes)", id_, seg_ + 1, tpdus_.size(), p_.number, p_.scTarget, repeat ? " again" : "", attempts_.back().rpMr, tpMrs_[seg_], repeat ? " with TP-RD" : "", tpdu.size())));
phase_ = Phase::Sending; phase_ = Phase::Sending;
deadline_ = now + SmsSendTimeout; deadline_ = now + SmsSendTimeout;
} }
// The attempt in flight ended without the service centre's word, or
// with RP cause 41 or one read as it (RpCauseIsTemporary): the
// repeat when the segment has had none, else the message has failed.
void EndAttempt(std::vector<SmsAction>& out, double now, std::string why) {
if (attempts_.size() >= SmsAttempts) {
phase_ = Phase::Done;
out.push_back(Fail(std::move(why)));
return;
}
out.push_back(LogAct(std::format("sms {}: {}; sending the segment again, TP-RD set", id_, why)));
firstWhy_ = std::move(why);
SendSegment(out, now);
}
// The service centre has the segment in flight: the next one, or
// the message is sent.
void Accepted(std::vector<SmsAction>& out, double now) {
seg_++;
attempts_.clear();
firstRefused_ = false;
if (seg_ < tpdus_.size()) { SendSegment(out, now); return; }
phase_ = Phase::Done;
deadline_ = 0;
out.push_back(StateAct(SmsStateSent, scts_.empty() ? std::format("{} segment(s) accepted by the SC", tpdus_.size()) : std::format("{} segment(s) accepted by the SC at {}", tpdus_.size(), scts_)));
}
// `failed` with the reason; of a segment that was sent again, how
// the first attempt ended as well.
SmsAction Fail(std::string why) { SmsAction Fail(std::string why) {
deadline_ = 0; deadline_ = 0;
if (attempts_.size() > 1) why += std::format("; the first attempt: {}", firstWhy_);
return StateAct(SmsStateFailed, std::move(why)); return StateAct(SmsStateFailed, std::move(why));
} }
SmsAction StateAct(std::string_view state, std::string reason) { SmsAction StateAct(std::string_view state, std::string reason) {
@ -1340,10 +1451,15 @@ export namespace imsd::engine {
RecentSubmissions& submitted_; RecentSubmissions& submitted_;
std::string id_; std::string id_;
Params p_; Params p_;
std::vector<std::vector<std::uint8_t>> tpdus_; std::uint8_t nextRpMr_; // the RP-MR the next MESSAGE takes
std::vector<std::vector<std::uint8_t>> tpdus_; // each segment's SMS-SUBMIT
std::vector<std::vector<std::uint8_t>> repeats_; // the same with TP-RD set, for a segment's repeat
std::vector<std::uint8_t> tpMrs_; std::vector<std::uint8_t> tpMrs_;
std::size_t seg_ = 0; std::size_t seg_ = 0;
std::string callid_; // the segment in flight's MESSAGE std::vector<Attempt> attempts_; // the MESSAGEs the segment in flight went out in: the first, then its repeat
std::string firstWhy_; // how the first attempt ended, once the segment was sent again
bool firstRefused_ = false; // an RP-ERROR has answered an attempt of the segment in flight: where a repeat's duplicate rejection reads it, the first
std::string callid_; // the MESSAGE in flight
std::string scts_; // the SC's time stamp from the last RP-ACK's submit report std::string scts_; // the SC's time stamp from the last RP-ACK's submit report
Phase phase_ = Phase::Idle; Phase phase_ = Phase::Idle;
double deadline_ = 0; double deadline_ = 0;
@ -1576,8 +1692,8 @@ export namespace imsd::engine {
if (rp.type == RpType::AckMt || rp.type == RpType::ErrorMt) { if (rp.type == RpType::AckMt || rp.type == RpType::ErrorMt) {
std::string inReplyTo; // every In-Reply-To row: the rows are one list (RFC 3261 7.3.1) std::string inReplyTo; // every In-Reply-To row: the rows are one list (RFC 3261 7.3.1)
for (std::string_view row : imsd::sip::Headers(message, "In-Reply-To")) inReplyTo.append(inReplyTo.empty() ? "" : ",").append(row); for (std::string_view row : imsd::sip::Headers(message, "In-Reply-To")) inReplyTo.append(inReplyTo.empty() ? "" : ",").append(row);
if (outbound && outbound->OwnsReport(inReplyTo, rp.mr)) { if (const auto attempt = outbound ? outbound->ReportAttempt(inReplyTo, rp.mr) : std::nullopt) {
r.actions = outbound->OnReport(rp, now); r.actions = outbound->OnReport(rp, now, *attempt);
return r; return r;
} }
if (!inReplyTo.empty()) { if (!inReplyTo.empty()) {

View file

@ -688,6 +688,10 @@ export namespace imsd::sms {
Bytes DeliverReportError(std::uint8_t fcs) { return {0x00, fcs, 0x00}; } Bytes DeliverReportError(std::uint8_t fcs) { return {0x00, fcs, 0x00}; }
constexpr std::uint8_t FcsUnspecified = 0xFF; constexpr std::uint8_t FcsUnspecified = 0xFF;
constexpr std::uint8_t FcsTpduNotSupported = 0xB0; constexpr std::uint8_t FcsTpduNotSupported = 0xB0;
// "SM Rejected-Duplicate SM" (9.2.3.22): the cause 9.2.3.6 has the SC
// give an SMS-SUBMIT with TP-RD set whose TP-MR is that of the one
// before it
constexpr std::uint8_t FcsDuplicateRejected = 0xC5;
// Segment capacities (9.2.3.24.1): a lone message, and one with the // Segment capacities (9.2.3.24.1): a lone message, and one with the
// 8-bit-reference concatenation header (six octets: UDHL + 00 03 r t s). // 8-bit-reference concatenation header (six octets: UDHL + 00 03 r t s).
@ -880,6 +884,25 @@ export namespace imsd::sms {
default: return std::format("cause {}", cause & 0x7F); default: return std::format("cause {}", cause & 0x7F);
} }
} }
// Whether an RP-ERROR to a submission invites another attempt at once.
// Of the causes table 8.4's part 1 lists for a mobile originating
// transfer, Annex E-2 says so of one, 41 temporary failure: "the Mobile
// Station may wish to try another short message transfer attempt
// almost immediately" (of 38, network out of order, it says that
// "immediately reattempting the short message transfer is not likely
// to be successful"); and part 1 has every value it does not list
// "treated as cause number 41". So: 41, and any value part 1 does not
// list.
constexpr bool RpCauseIsTemporary(std::uint8_t cause) {
switch (cause & 0x7F) {
// part 1's values but 41
case 1: case 8: case 10: case 11: case 21: case 27: case 28: case 29: case 30: case 38: case 42: case 47:
case 50: case 69: case 81: case 95: case 96: case 97: case 98: case 99: case 111: case 127:
return false;
default:
return true;
}
}
constexpr std::uint8_t RpCauseMemoryCapacityExceeded = 22; constexpr std::uint8_t RpCauseMemoryCapacityExceeded = 22;
constexpr std::uint8_t RpCauseInvalidMandatoryInformation = 96; constexpr std::uint8_t RpCauseInvalidMandatoryInformation = 96;
constexpr std::uint8_t RpCauseProtocolError = 111; constexpr std::uint8_t RpCauseProtocolError = 111;

View file

@ -29,9 +29,13 @@
// ids (RunToken, SentSmsId, ReceivedSmsId); // ids (RunToken, SentSmsId, ReceivedSmsId);
// SmsOutbound through a // SmsOutbound through a
// submission (the MESSAGE with the RP-DATA, its 202, the RP-ACK -> sent; a // submission (the MESSAGE with the RP-DATA, its 202, the RP-ACK -> sent; a
// refused final, an RP-ERROR with its cause, the final's wait and the // refused final, an RP-ERROR with its cause, the segment's one repeat with
// report's running out, a failed send, two segments with consecutive // TP-RD set — after the final's wait or the report's ran out, a 408 or a
// RP-MR/TP-MR, 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
// destination that is no number, no service centre, a submit report before // 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 // the MESSAGE's own final, a text past 255 segments) and OnSmsMessage (a
// delivery with no gateway for its report, a // delivery with no gateway for its report, a
@ -1341,7 +1345,7 @@ int main() {
auto a = m.Start(100.0); auto a = m.Start(100.0);
const auto* sent = findSms(a, SmsAction::Type::SendClient); 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"); 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");
Check(m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 100.0 + SmsSendTimeout, "outbound: sending, the 32 s wait for the final armed"); Check(m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 100.0 + SmsSendTimeout, "outbound: sending, the 128 s wait for the final armed");
if (!sent) return 1; if (!sent) return 1;
const std::string callid(imsd::sip::Header(sent->text, "Call-ID").value_or("")); const std::string callid(imsd::sip::Header(sent->text, "Call-ID").value_or(""));
auto rp = bodyRp(sent->text); auto rp = bodyRp(sent->text);
@ -1350,10 +1354,10 @@ int main() {
Check(m.TpMrs() == std::vector<std::uint8_t>{10} && m.Segments() == 1, "outbound: one segment"); 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"); 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); auto b = m.OnResponse(final(callid, 202, "Accepted"), 202, 101.0);
Check(m.State() == SmsOutbound::Phase::AwaitingReport && m.Deadline() == 101.0 + SmsReportTimeout && !hasSms(b, SmsAction::Type::State), "outbound: 202 -> awaiting the submit report, its 40 s wait armed"); 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 == 32.0 && SmsReportTimeout == 40.0, "outbound: the wait for the final is 32 s, the one for the submit report 40 s"); 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.OwnsReport(callid, std::nullopt) && !m.OwnsReport("x@y", 20) && m.OwnsReport("", 20) && !m.OwnsReport("", 21), "outbound: a report is matched by In-Reply-To, else by RP-MR"); 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.OwnsReport(std::format("x@y, {}", callid), std::nullopt) && m.OwnsReport(std::format("{},x@y", callid), 21) && m.OwnsReport(std::format("z@w , {} ,x@y", callid), 21) && m.OwnsReport(std::format("z@w\t,\t{}", callid), 21) && !m.OwnsReport("x@y, z@w", 20) && !m.OwnsReport(callid + "x", 20) && !m.OwnsReport("x" + callid, 20), "outbound: of an In-Reply-To that lists Call-IDs, ours among them is ours"); 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");
Rp ack{RpType::AckMt, 20, std::nullopt, *imsd::util::FromHex("010062016122050080"), std::nullopt, std::nullopt}; Rp ack{RpType::AckMt, 20, std::nullopt, *imsd::util::FromHex("010062016122050080"), std::nullopt, std::nullopt};
auto d = m.OnReport(ack, 102.0); auto d = m.OnReport(ack, 102.0);
const auto* st = findSms(d, SmsAction::Type::State); const auto* st = findSms(d, SmsAction::Type::State);
@ -1376,35 +1380,264 @@ int main() {
auto a = m.Start(0.0); auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or("")); 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); m.OnResponse(final(callid, 100, "Trying"), 100, 5.0);
Check(m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 5.0 + SmsSendTimeout, "outbound: a provisional starts the 32 s wait over"); Check(m.State() == SmsOutbound::Phase::Sending && m.Deadline() == 5.0 + SmsSendTimeout, "outbound: a provisional starts the 128 s wait over");
m.OnResponse(final(callid, 200, "OK"), 200, 6.0); m.OnResponse(final(callid, 200, "OK"), 200, 6.0);
Rp err{RpType::ErrorMt, 20, std::nullopt, *imsd::util::FromHex("01c30062016122050080"), 28, std::nullopt}; Rp err{RpType::ErrorMt, 20, std::nullopt, *imsd::util::FromHex("01c30062016122050080"), 28, std::nullopt};
auto b = m.OnReport(err, 7.0); auto b = m.OnReport(err, 7.0);
const auto* st = findSms(b, SmsAction::Type::State); 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"); 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");
} }
// timeouts and a failed send // 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");
{ {
imsd::util::Rng rng(74); imsd::util::Rng rng(74);
SmsOutbound m(c, rng, sub, "ims-sms-4", p); SmsOutbound m(c, rng, sub, "ims-sms-4", p);
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);
m.Start(0.0); m.Start(0.0);
auto a = m.OnDeadline(); const std::string callid2 = callIdOf(findSms(m.OnDeadline(128.5), SmsAction::Type::SendClient));
const auto* st = findSms(a, SmsAction::Type::State); m.OnResponse(final(callid2, 202, "Accepted"), 202, 129.0);
Check(st && st->state == "failed" && st->reason.contains("no answer to the MESSAGE"), "outbound: no final within the wait fails it"); auto d = m.OnDeadline(259.5);
imsd::util::Rng rng2(75); const auto* st = findSms(d, SmsAction::Type::State);
SmsOutbound m2(c, rng2, sub, "ims-sms-5", p); 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");
auto b = m2.Start(0.0); Check(m.OnDeadline(260.0).empty() && m.OnReport(temporary, 261.0).empty(), "outbound: an ended message takes no deadline and no report");
const std::string callid(imsd::sip::Header(findSms(b, SmsAction::Type::SendClient)->text, "Call-ID").value_or("")); }
m2.OnResponse(final(callid, 202, "Accepted"), 202, 1.0); // 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
auto d = m2.OnDeadline(); for (bool byCallId : {true, false}) {
st = findSms(d, SmsAction::Type::State); imsd::util::Rng rng(78);
Check(st && st->state == "failed" && st->reason.contains("no submit report"), "outbound: no submit report within its wait fails it"); SmsOutbound m(c, rng, sub, "ims-sms-23", p);
imsd::util::Rng rng3(76); 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);
SmsOutbound m3(c, rng3, sub, "ims-sms-6", p); SmsOutbound m3(c, rng3, sub, "ims-sms-6", p);
m3.Start(0.0); m3.Start(0.0);
auto e = m3.OnSendFailed(); 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);
st = findSms(e, SmsAction::Type::State); st = findSms(e, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason.contains("flow to the P-CSCF is down"), "outbound: a failed send fails it"); Check(st && st->state == "failed" && m2.Done(), "outbound: a report numbered past the only attempt is that attempt's");
} }
// two segments: the second goes after the first's RP-ACK, with the next RP-MR and TP-MR // two segments: the second goes after the first's RP-ACK, with the next RP-MR and TP-MR
{ {
@ -1424,7 +1657,7 @@ int main() {
Check(callid2 != callid, "outbound: a Call-ID of its own per segment"); Check(callid2 != callid, "outbound: a Call-ID of its own per segment");
auto rp = bodyRp(second->text); 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"); 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");
Check(m.OwnsReport("", 21) && !m.OwnsReport("", 20), "outbound: the report in flight is the second segment's"); Check(m.ReportAttempt("", 21) && !m.ReportAttempt("", 20), "outbound: the report in flight is the second segment's");
m.OnResponse(final(callid2, 202, "Accepted"), 202, 3.0); 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); auto d = m.OnReport(Rp{RpType::AckMt, 21, std::nullopt, {}, std::nullopt, std::nullopt}, 4.0);
const auto* st = findSms(d, SmsAction::Type::State); const auto* st = findSms(d, SmsAction::Type::State);
@ -1438,7 +1671,7 @@ int main() {
SmsOutbound m(c, rng, sub, "ims-sms-8", bad); SmsOutbound m(c, rng, sub, "ims-sms-8", bad);
auto a = m.Start(0.0); auto a = m.Start(0.0);
const auto* st = findSms(a, SmsAction::Type::State); const auto* st = findSms(a, SmsAction::Type::State);
Check(st && st->state == "failed" && st->reason == "'nobody' is not a number" && m.Done() && !hasSms(a, SmsAction::Type::SendClient), "outbound: a destination that is no number fails at once"); 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");
SmsOutbound::Params longNumber = p; SmsOutbound::Params longNumber = p;
longNumber.number = "+" + std::string(21, '3'); longNumber.number = "+" + std::string(21, '3');
imsd::util::Rng rngL(80); imsd::util::Rng rngL(80);
@ -1509,7 +1742,7 @@ int main() {
Check(e.post.size() == 1 && e.post[0].state == "sent" && !e.forget, "order: sent with nothing held"); 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", SmsStateDeliveryPending, "congestion", true);
order.Report("ims-sms-4", SmsStateDelivered, "received by the SME", true); order.Report("ims-sms-4", SmsStateDelivered, "received by the SME", true);
e = order.Submission("ims-sms-4", SmsStateFailed, "no submit report for segment 2/2 within 40 s of the final"); e = order.Submission("ims-sms-4", SmsStateFailed, "no submit report for segment 2/2 within 130 s of the final");
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)"); 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); 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"); e = order.Submission("ims-sms-5", SmsStateFailed, "segment 2/2 refused by the SC: RP cause 38");
@ -1693,7 +1926,7 @@ int main() {
SmsOutbound m(c, rng, sub, "ims-sms-11", p); SmsOutbound m(c, rng, sub, "ims-sms-11", p);
auto a = m.Start(0.0); auto a = m.Start(0.0);
const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or("")); const std::string callid(imsd::sip::Header(findSms(a, SmsAction::Type::SendClient)->text, "Call-ID").value_or(""));
Check(m.State() == SmsOutbound::Phase::Sending && m.OwnsReport(callid, std::nullopt), "outbound: a report is owned while the MESSAGE's final is still due"); Check(m.State() == SmsOutbound::Phase::Sending && m.ReportAttempt(callid, std::nullopt), "outbound: a report is owned while the MESSAGE's final is still due");
auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 1.0); auto r = OnSmsMessage(c, rng, inbound("0314", std::format("In-Reply-To: {}\r\n", callid)), re, &m, sub, 1.0);
const auto* st = findSms(r.actions, SmsAction::Type::State); 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"); 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");
@ -1752,6 +1985,22 @@ int main() {
const auto* st = findSms(r.actions, SmsAction::Type::State); 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"); 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");
} }
// 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");
}
// a submit report for the message in flight; one for nobody // a submit report for the message in flight; one for nobody
{ {
imsd::util::Rng rng(83); imsd::util::Rng rng(83);
@ -1774,10 +2023,21 @@ int main() {
auto a3 = m3.Start(10.0); auto a3 = m3.Start(10.0);
const std::string callid3(imsd::sip::Header(findSms(a3, SmsAction::Type::SendClient)->text, "Call-ID").value_or("")); 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); m3.OnResponse(final(callid3, 202, "Accepted"), 202, 11.0);
m3.OnDeadline(); m3.OnDeadline(141.5); // the segment goes out again
auto r5 = OnSmsMessage(c, rng, inbound("05140126410A01C30062016122050080", std::format("In-Reply-To: {}\r\n", callid3)), re, &m3, sub, 60.0); 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);
const auto* l5 = findSms(r5.actions, SmsAction::Type::Log); const auto* l5 = findSms(r5.actions, SmsAction::Type::Log);
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 its wait ended the message: 200, its cause and TP-FCS in the line"); 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");
auto r3 = OnSmsMessage(c, rng, inbound("0314"), re, nullptr, sub, 4.0); auto r3 = OnSmsMessage(c, rng, inbound("0314"), re, nullptr, sub, 4.0);
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"); 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");
} }

View file

@ -9,8 +9,10 @@
// you?" PDU and vectors cross-generated by the fp6 journal's Python // you?" PDU and vectors cross-generated by the fp6 journal's Python
// reference: a header with fill bits, a 16-bit concatenation reference, a // reference: a header with fill bits, a 16-bit concatenation reference, a
// class-0 message, port-addressed 8-bit data, an alphanumeric sender, a // class-0 message, port-addressed 8-bit data, an alphanumeric sender, a
// negative time zone), SMS-STATUS-REPORT and SMS-SUBMIT-REPORT, the // negative time zone), SMS-STATUS-REPORT and SMS-SUBMIT-REPORT (the
// RP-DATA / RP-ACK / RP-ERROR messages both ways, EF_SMSP with the KPN // duplicate rejection's TP-FCS among its causes), the
// RP-DATA / RP-ACK / RP-ERROR messages both ways, which RP causes of a
// submission invite a repeat, EF_SMSP with the KPN
// SIM's record, qmicli's hex dump, and the reassembly of a concatenated // SIM's record, qmicli's hex dump, and the reassembly of a concatenated
// message. // message.
import std; import std;
@ -136,6 +138,12 @@ namespace {
Check(to.size() == 1, "SUBMIT with a status report requested: one segment"); Check(to.size() == 1, "SUBMIT with a status report requested: one segment");
if (!to.empty()) Eq(to[0], "31010A9113163254760000A902C834", "SMS-SUBMIT: status report requested, TP-VP A9, an even number of digits"); if (!to.empty()) Eq(to[0], "31010A9113163254760000A902C834", "SMS-SUBMIT: status report requested, TP-VP A9, an even number of digits");
Submit r = o;
r.rejectDuplicates = true;
auto tr = BuildSubmits(r, "Hi", 0);
Check(tr.size() == 1, "SUBMIT with TP-RD: one segment");
if (!tr.empty()) Eq(tr[0], "35010A9113163254760000A902C834", "SMS-SUBMIT with TP-RD: bit 2 of the first octet set, the rest as without it");
Submit c{"+31612345678", 10}; Submit c{"+31612345678", 10};
std::string longText(153, 'A'); std::string longText(153, 'A');
longText += std::string(8, 'B'); longText += std::string(8, 'B');
@ -145,6 +153,12 @@ namespace {
Eq(tc[0], "410A0B911316325476F80000A00500032A020182C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683", "segment 1/2: UDHI, the concatenation header, 153 septets after one fill bit, TP-MR 10"); Eq(tc[0], "410A0B911316325476F80000A00500032A020182C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683C16030180C0683", "segment 1/2: UDHI, the concatenation header, 153 septets after one fill bit, TP-MR 10");
Eq(tc[1], "410B0B911316325476F800000F0500032A02028442A15028140A01", "segment 2/2: TP-MR 11, 8 septets"); Eq(tc[1], "410B0B911316325476F800000F0500032A02028442A15028140A01", "segment 2/2: TP-MR 11, 8 septets");
} }
auto tw = BuildSubmits(c, Rep("ü", 70) + "❤", 0x2A);
Check(tw.size() == 2, "71 UCS-2 characters: two segments");
if (tw.size() == 2) {
Eq(tw[0], "410A0B911316325476F800088C0500032A0201" + Rep("00FC", 67), "UCS-2 segment 1/2: TP-MR 10, the header and 67 characters in 140 octets");
Eq(tw[1], "410B0B911316325476F800080E0500032A020200FC00FC00FC2764", "UCS-2 segment 2/2: TP-MR 11, the header and four characters");
}
Check(BuildSubmits(c, std::string(160, 'A'), 1).size() == 1, "160 characters fit one message"); Check(BuildSubmits(c, std::string(160, 'A'), 1).size() == 1, "160 characters fit one message");
Check(BuildSubmits(c, std::string(161, 'A'), 1).size() == 2, "161 characters need two"); Check(BuildSubmits(c, std::string(161, 'A'), 1).size() == 2, "161 characters need two");
Check(BuildSubmits(c, Rep("ü", 70) + "❤", 1).size() == 2, "71 UCS-2 characters need two"); Check(BuildSubmits(c, Rep("ü", 70) + "❤", 1).size() == 2, "71 UCS-2 characters need two");
@ -293,6 +307,8 @@ namespace {
Check(udhi && udhi->failureCause == 0xC3, "TP-UDHI (bit 6) is no unused bit: the cause as sent"); Check(udhi && udhi->failureCause == 0xC3, "TP-UDHI (bit 6) is no unused bit: the cause as sent");
EqS(ScTimeStamp(Hex("621AF12205A0A0")), "2026-01-10T22:50:00+00:00", "SCTS: a semi-octet that is no digit reads as 0, in the zone too (9.2.3.11)"); EqS(ScTimeStamp(Hex("621AF12205A0A0")), "2026-01-10T22:50:00+00:00", "SCTS: a semi-octet that is no digit reads as 0, in the zone too (9.2.3.11)");
EqS(FailureCauseText(0xC3), "invalid SME address", "TP-FCS C3"); EqS(FailureCauseText(0xC3), "invalid SME address", "TP-FCS C3");
Check(FcsDuplicateRejected == 0xC5, "TP-FCS C5 is the duplicate rejection (9.2.3.22)");
EqS(FailureCauseText(FcsDuplicateRejected), "duplicate short message rejected", "TP-FCS C5 in words");
Eq(DeliverReportAck(), "0000", "SMS-DELIVER-REPORT for RP-ACK"); Eq(DeliverReportAck(), "0000", "SMS-DELIVER-REPORT for RP-ACK");
Eq(DeliverReportError(0xFF), "00FF00", "SMS-DELIVER-REPORT for RP-ERROR"); Eq(DeliverReportError(0xFF), "00FF00", "SMS-DELIVER-REPORT for RP-ERROR");
} }
@ -317,6 +333,15 @@ namespace {
auto errMt = ParseRp(Hex("052A011C410A01C30062016122050080")); auto errMt = ParseRp(Hex("052A011C410A01C30062016122050080"));
Check(errMt && errMt->type == RpType::ErrorMt && errMt->cause == 28 && !errMt->diagnostic && errMt->tpdu.size() == 10, "RP-ERROR network to MS with a submit report"); Check(errMt && errMt->type == RpType::ErrorMt && errMt->cause == 28 && !errMt->diagnostic && errMt->tpdu.size() == 10, "RP-ERROR network to MS with a submit report");
EqS(RpCauseText(28), "unidentified subscriber", "RP cause 28"); EqS(RpCauseText(28), "unidentified subscriber", "RP cause 28");
// a submission's RP-ERROR invites another attempt at once for cause 41 (TS 24.011 Annex E-2) and for a value table 8.4's part 1 does not list (treated as 41)
{
const std::set<int> listed{1, 8, 10, 11, 21, 27, 28, 29, 30, 38, 41, 42, 47, 50, 69, 81, 95, 96, 97, 98, 99, 111, 127};
bool asTabled = true;
for (int cause = 0; cause < 128; cause++)
if (RpCauseIsTemporary(static_cast<std::uint8_t>(cause)) != (cause == 41 || !listed.contains(cause))) asTabled = false;
Check(asTabled && listed.size() == 23, "RpCauseIsTemporary over the 128 cause values: 41, and whatever part 1's 23 do not list");
Check(RpCauseIsTemporary(41) && RpCauseIsTemporary(0x80 | 41) && !RpCauseIsTemporary(28) && !RpCauseIsTemporary(0x80 | 28) && RpCauseIsTemporary(2) && !RpCauseIsTemporary(11), "RpCauseIsTemporary: the extension bit is no part of the value; an unlisted 2 invites a repeat, the reserved 11 is listed");
}
auto diag = ParseRp(Hex("0507022611")); auto diag = ParseRp(Hex("0507022611"));
Check(diag && diag->cause == 38 && diag->diagnostic == 0x11 && diag->tpdu.empty(), "RP-ERROR with a diagnostic octet"); Check(diag && diag->cause == 38 && diag->diagnostic == 0x11 && diag->tpdu.empty(), "RP-ERROR with a diagnostic octet");
Check(!ParseRp(Hex("05")), "one byte: nothing"); Check(!ParseRp(Hex("05")), "one byte: nothing");