sms, engine: a class 2 message is refused, not acknowledged, unless it is a short message type 0

OnSmsMessage acknowledged every SMS-DELIVER it could parse with an
RP-ACK and handed it to the bus, whatever its class. For a class 2
message the acknowledgement said more than was done: TS 23.038 4 has the
MS "ensure that the message has been transferred to the SMS data field
in the (U)SIM before sending an acknowledgement to the SC", and TS
23.040 9.2.3.9 has a (U)SIM data download — TP-PID 0x7F with a class 2
coding — passed to the (U)SIM. imsd writes nothing to the card, so the
network had an acknowledgement for something that had not happened
(issue #4).

imsd has no way to the card for such a message yet. TS 23.038 4 names
the answer of an MS that cannot store a class 2 message in the (U)SIM
while other storage is free, "protocol error, unspecified", and excepts
only a download on an MS that supports the (U)SIM Application Toolkit,
which imsd does not. The delivery report of a class 2 message, a
segment of a set included, is now an RP-ERROR with that cause, 111, and
the TP-FCS 0xFF, unspecified error cause; the message is neither stored
nor handed to the bus, and the journal has its sender, service centre
and time. A short message type 0 (TP-PID 0x40) with a class 2 coding is
no part of this: 9.2.3.9 has it received "irrespective of whether there
is memory available in the (U)SIM or ME or not". TP-PID 0x7F without a
class 2 coding stays a message like any other, and so do classes 0, 1
and 3.

What this changes for a consumer: no `Received` comes for a refused
class 2 message, a text of that class among them, which 1.2.0 stored
and handed over (Jorijn, 2026-11-21: the refusal is kept). The
interface's members, keys and words are as they were.

Still open of issue #4: the way to the card itself — TS 31.111 7.1.1's
ENVELOPE (SMS-PP DOWNLOAD) for a download, an EF_SMS record for any
other class 2 message — and with it an acknowledgement made from the
card's answer. Read from the dev phone for it (the fp6 journal's
2026-11-20-issues-2-5 capture, phone): the KPN USIM's service table
lists 28 (data download via SMS-PP) and 10 (short message storage),
EF_SMS holds ten records of 176 bytes, the modem's route table has a
class 2 message it receives itself stored on the card, and qmicli has
the APDU route AKA takes and no toolkit command. Whether the modem lets
an ENVELOPE through that route has not been tried.

Tested by tests/Engine. On the dev phone the daemon, the binary of this
range's last commit, refused five class 2 deliveries that the phone sent
to its own protected server port — answered 200, the journal's line,
nothing stored, and no report, since they named no gateway — and took
six deliveries from KPN as before (the capture's phone-form6).
This commit is contained in:
Jorijn van der Graaf 2026-11-22 17:35:13 +01:00
commit d6d7ba100a
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 126 additions and 19 deletions

View file

@ -19,7 +19,7 @@ imsd does the whole IMS client itself: SIP registration with USIM AKA
authentication over kernel IPsec (ESP), call signalling for outgoing and
incoming calls, and the RTP media plane (AMR-WB, AMR, G.711) wired into
PipeWire, and since 1.2.0 short messages over IMS (TS 24.341: the SIP MESSAGE
carrying an RP-DATA, a store for what arrives, the Messaging interface —
carrying an RP-DATA, a store, the Messaging interface —
§7.9). A stock mobile dialer — Plasma Dialer, or GNOME Calls under Phosh
and GNOME Mobile — places and receives real VoLTE calls on a commercial
network through it.
@ -413,6 +413,11 @@ What the suites pin:
while SMS over IP is off — and a final in compact form taken by the
message in flight; a delivered MESSAGE whose Content-Type came folded,
taken for a short message once the datagram framer has unfolded it;
a class 2 message kept from the bus and refused with an RP-ERROR (cause
111, TP-FCS 0xFF) — a (U)SIM data download, a text, a segment of a set —
or, naming no gateway, kept from the bus with no report; the other
classes, TP-PID 0x7F without class 2, and a short message type 0 with a
class 2 coding, received;
a submit report before the MESSAGE's own final taken — the message sent
and the late final nobody's; with two segments the second goes out under
its own Call-ID — a text past 255 segments failed at once naming the fit,
@ -672,7 +677,7 @@ Rules:
fp6 journal's `2026-11-19-imsd-1.2.0-r32-cut` capture, `searches/arms.out`, and for the phone's
visits of 2026-11-20 to 2026-11-22 in its `2026-11-20-issues-2-5`
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 (an RP-ERROR that came in was
reached: `smsc-override-2026-10-18-0217`, 02:19:41, RP cause 28 + TP-FCS
0xc1, through `OnReport`), the final's wait 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
@ -764,7 +769,12 @@ Rules:
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. The read of the client flow before a wait is
`tests/Engine` pins the reducer for each, and the refusal of a class 2
message: it ran on the dev phone's daemon for MESSAGEs the phone sent
to its own protected server port (`phone-form6`, `inject-bench.log`), among them one with a line per header
and one with its Content-Type on a continuation line and bytes after
its body — each answered 200, refused in the journal, stored nowhere
and, naming no gateway, reported to nobody. The read of the client flow before a wait is
judged: `SipFlow`'s two reads ran on the workstation's loopback, the
daemon's class built around a bench `main` (2026-11-20 to 2026-11-22,
the fp6 journal's `2026-11-20-issues-2-5` capture, `flow-read`: over TCP and
@ -1660,7 +1670,10 @@ Lines the operator (and the scripts) look for, all prefixed `imsd: `:
message still in flight `sms <id>: delivered|delivery-pending|
delivery-failed: <TP-ST in words> — held until the submission ends`; per delivery `short message from
<sender> via <sc> at <time>[, segment i/n of set r]: text|8-bit data (N
bytes)`, `sms ims-sms-in-<run>-<epoch>-<N>: from … via …, N bytes of text|8-bit data[ in
bytes)` — or, for a class 2 message that is
refused (§7.9), `… at <time>[, segment i/n of set
r]: class 2[, a (U)SIM data download] (N bytes), which imsd cannot pass
to the (U)SIM: refused` —, `sms ims-sms-in-<run>-<epoch>-<N>: from … via …, N bytes of text|8-bit data[ in
n segments]` once whole, `delivery report RP-ACK|RP-ERROR (RP-MR n) ->
<uri>` (its final and its failures: the bus and MESSAGE lines below) or,
for a MESSAGE that names no gateway, `no P-Asserted-Identity or From URI on
@ -1801,8 +1814,8 @@ do that answers without state.
`/var/lib/imsd/sms/<id>.msg` (mode 0600, the directory 0700; whole to a
`.tmp` beside it, then `link(2)`ed to its name) before the bus hears
`Received`, and stays until `Delete` — the daemon is the message store
the way the modem's memory is for ModemManager, so a whole text that
arrives while no app runs, or none exists, is not lost (a concatenated
the way the modem's memory is for ModemManager, so a whole text it
stores while no app runs, or none exists, is not lost (a concatenated
one's earlier segments wait in memory until the set is whole — the
**Receiving** bullet below); `List` is an app's way
in. The record is key=value lines, the sender, the text, the data and
@ -1967,14 +1980,13 @@ do that answers without state.
starts when the one before it ends, without that check again.
- **Receiving** (`OnSmsMessage`): the MESSAGE is answered 200 on the
channel it came in on first; an SMS-DELIVER is decoded (7-bit, UCS-2 or
8-bit data; the class, the ports, a message-waiting indication), a
concatenated one reassembled (`Reassembler`, in memory: a set to
8-bit data; the class, the ports, a message-waiting indication) and, unless it is refused as a class 2
message (below), a concatenated one reassembled (`Reassembler`, in memory: a set to
which no segment has come for 30 min is dropped at the run loop's next pass with a journal line
naming the sender, the set and the segments held, and an imsd restart between segments —
an upgrade's, a `Restart=` — loses the set; a store of parts is a later release's work,
with the refusal of the store bullet) and handed to the bus whole as
`Received`; each segment
is acknowledged with an RP-ACK carrying the SMS-DELIVER-REPORT in a
`Received`, each segment acknowledged with an RP-ACK carrying the SMS-DELIVER-REPORT in a
MESSAGE to the IP-SM-GW — the delivered MESSAGE's P-Asserted-Identity,
else its From — with In-Reply-To naming it (5.3.2.4; left out when its Call-ID holds an ASCII control
character or a space); no report goes for
@ -2031,12 +2043,43 @@ do that answers without state.
not its text (§12 has the cases in which a text does reach it); the text
is in the store (the store bullet above) until
an app deletes it — unless it was not stored (`NOT stored`, the
store bullet). Class 2 messages are not written to the (U)SIM; RP-SMMA (memory
available) is never sent; nothing is done by TP-PID — a short
store bullet). A class 2 message is for the (U)SIM — a (U)SIM data
download (TP-PID 0x7F with a class 2 coding, which TS 23.040 9.2.3.9 has
the ME pass to the (U)SIM), or a message for the card's EF_SMS — and
imsd has no way to the card for it, so it is refused, each segment as
it comes. TS 23.038 4 has the MS
"ensure that the message has been transferred to the SMS data field in
the (U)SIM before sending an acknowledgement to the SC" and return
"protocol error, unspecified" when it "cannot be stored in the (U)SIM
and there is other short message storage available" (the clause
excepts a download for an MS that supports the (U)SIM Application
Toolkit, which imsd does not; its "memory capacity exceeded", for an
MS whose storage is all in use, imsd never answers: its store has no
bound of its own). The delivery
report is an RP-ERROR with that cause, 111, and the TP-FCS 0xFF,
unspecified error cause; a MESSAGE that names no gateway
gets none, as with any delivery. The message is neither stored nor
handed to the bus, and the journal has its sender, service centre and
time. A short message type 0 (TP-PID 0x40) is no message for the card,
whatever its class: 9.2.3.9 has it received "irrespective of whether
there is memory available in the (U)SIM or ME or not", and it goes the
way of any type 0 (below). Handing a class 2 message to the card from imsd — TS
31.111 7.1.1's ENVELOPE (SMS-PP DOWNLOAD) for a download, an EF_SMS
record for the rest — is not done. The dev phone's KPN USIM has both
services (2026-11-20, the fp6 journal's `2026-11-20-issues-2-5` capture,
`phone`: its service table lists 28, data download via SMS-PP, and 10,
short message storage, and EF_SMS holds ten records of 176 bytes; the
modem's route table has a class 2 message it receives itself stored on
the card,
`--wms-get-routes`), and `qmicli` has the APDU route AKA takes
(`--uim-send-apdu`) and no toolkit command; whether the modem lets an
ENVELOPE through there has not been tried. RP-SMMA
(memory available) is never sent; nothing else is done by TP-PID — a short
message type 0, which TS 23.040 9.2.3.9 has an MS acknowledge, discard
and not show, is stored and handed over like any text, its `pid` (0x40)
the consumer's to act on, a Replace Short Message type replaces nothing
and a (U)SIM data download is not passed to the card; a class 0 message
the consumer's to act on, a Replace Short Message type replaces
nothing, and TP-PID 0x7F without a class 2 coding is a message like any
other (9.2.3.9: "handled in the normal way"); a class 0 message
is stored like any other, its `class` the consumer's to act on; a 7-bit text under a national language shift
table (TS 23.040 9.2.3.24.15 and 9.2.3.24.16, the header's elements 0x24
and 0x25) is read with the default tables, and a compressed text (TS