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:
parent
1fa4d77fcd
commit
d6d7ba100a
5 changed files with 126 additions and 19 deletions
71
AGENTS.md
71
AGENTS.md
|
|
@ -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
|
authentication over kernel IPsec (ESP), call signalling for outgoing and
|
||||||
incoming calls, and the RTP media plane (AMR-WB, AMR, G.711) wired into
|
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
|
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
|
§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
|
and GNOME Mobile — places and receives real VoLTE calls on a commercial
|
||||||
network through it.
|
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
|
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,
|
message in flight; a delivered MESSAGE whose Content-Type came folded,
|
||||||
taken for a short message once the datagram framer has unfolded it;
|
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
|
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
|
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,
|
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
|
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`
|
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
|
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
|
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
|
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
|
||||||
|
|
@ -764,7 +769,12 @@ Rules:
|
||||||
a 408, a 504 or an RP-ERROR; a repeat rejected as a duplicate, and one
|
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
|
ended in its turn; the first attempt's report after its repeat went
|
||||||
out.
|
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
|
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,
|
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
|
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|
|
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
|
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
|
<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) ->
|
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,
|
<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
|
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
|
`/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
|
`.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
|
`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
|
the way the modem's memory is for ModemManager, so a whole text it
|
||||||
arrives while no app runs, or none exists, is not lost (a concatenated
|
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
|
one's earlier segments wait in memory until the set is whole — the
|
||||||
**Receiving** bullet below); `List` is an app's way
|
**Receiving** bullet below); `List` is an app's way
|
||||||
in. The record is key=value lines, the sender, the text, the data and
|
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.
|
starts when the one before it ends, without that check again.
|
||||||
- **Receiving** (`OnSmsMessage`): the MESSAGE is answered 200 on the
|
- **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
|
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
|
8-bit data; the class, the ports, a message-waiting indication) and, unless it is refused as a class 2
|
||||||
concatenated one reassembled (`Reassembler`, in memory: a set to
|
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
|
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 —
|
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,
|
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
|
with the refusal of the store bullet) and handed to the bus whole as
|
||||||
`Received`; each segment
|
`Received`, each segment acknowledged with an RP-ACK carrying the SMS-DELIVER-REPORT in a
|
||||||
is 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,
|
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
|
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
|
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
|
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
|
is in the store (the store bullet above) until
|
||||||
an app deletes it — unless it was not stored (`NOT stored`, the
|
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
|
store bullet). A class 2 message is for the (U)SIM — a (U)SIM data
|
||||||
available) is never sent; nothing is done by TP-PID — a short
|
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
|
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)
|
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
|
the consumer's to act on, a Replace Short Message type replaces
|
||||||
and a (U)SIM data download is not passed to the card; a class 0 message
|
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
|
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
|
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
|
and 0x25) is read with the default tables, and a compressed text (TS
|
||||||
|
|
|
||||||
|
|
@ -69,11 +69,11 @@ session and root may place, answer and end calls; an ssh login may not.
|
||||||
|
|
||||||
Off unless `SMS_OVER_IMS=1` is set in `/etc/imsd.env`. On, imsd sends texts
|
Off unless `SMS_OVER_IMS=1` is set in `/etc/imsd.env`. On, imsd sends texts
|
||||||
over the IMS registration it already holds, through the SIM's service
|
over the IMS registration it already holds, through the SIM's service
|
||||||
centre or the one `SMSC` names, and receives texts the network delivers over IMS;
|
centre or the one `SMSC` names, and receives texts over IMS;
|
||||||
its store for received texts is `/var/lib/imsd/sms`, and a text in it stays
|
its store for received texts is `/var/lib/imsd/sms`, and a text in it stays
|
||||||
until a messaging app deletes it. Apps that read ModemManager, such as Spacebar and
|
until a messaging app deletes it. Apps that read ModemManager, such as Spacebar and
|
||||||
Chatty, do not see texts that arrive this way; `imsd-messages`, the app built
|
Chatty, do not see texts that arrive this way; `imsd-messages` is the app built
|
||||||
for imsd's `net.catcrafts.IMS1.Messaging` interface, shows them. The details are
|
for imsd's `net.catcrafts.IMS1.Messaging` interface. The details are
|
||||||
in AGENTS.md: the behaviour and the store in §7.9, the interface in §8.4,
|
in AGENTS.md: the behaviour and the store in §7.9, the interface in §8.4,
|
||||||
what was verified on which network in §5.
|
what was verified on which network in §5.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1642,7 +1642,10 @@ export namespace imsd::engine {
|
||||||
// An inbound MESSAGE (TS 24.341 5.3.2.3, 5.3.1.2, 5.3.1.3). An RP-DATA
|
// An inbound MESSAGE (TS 24.341 5.3.2.3, 5.3.1.2, 5.3.1.3). An RP-DATA
|
||||||
// with an SMS-DELIVER is answered 200, handed to the reassembler and,
|
// with an SMS-DELIVER is answered 200, handed to the reassembler and,
|
||||||
// whole, to the bus, and acknowledged with an RP-ACK carrying the
|
// whole, to the bus, and acknowledged with an RP-ACK carrying the
|
||||||
// SMS-DELIVER-REPORT in a MESSAGE to the IP-SM-GW; one with an
|
// SMS-DELIVER-REPORT in a MESSAGE to the IP-SM-GW — but one of class 2,
|
||||||
|
// which is for the (U)SIM, is refused with an RP-ERROR instead (cause
|
||||||
|
// 111, TP-FCS 0xFF) and goes no further, unless it is a short message
|
||||||
|
// type 0; one with an
|
||||||
// SMS-STATUS-REPORT is acknowledged the same way and the report handed
|
// SMS-STATUS-REPORT is acknowledged the same way and the report handed
|
||||||
// over for the shell to match; one whose TPDU is unusable is
|
// over for the shell to match; one whose TPDU is unusable is
|
||||||
// acknowledged with an RP-ERROR (cause 96, TP-FCS "TPDU not supported")
|
// acknowledged with an RP-ERROR (cause 96, TP-FCS "TPDU not supported")
|
||||||
|
|
@ -1743,6 +1746,24 @@ export namespace imsd::engine {
|
||||||
const int total = concat ? d->ud.header.concat->total : 1;
|
const int total = concat ? d->ud.header.concat->total : 1;
|
||||||
const int seq = concat ? d->ud.header.concat->seq : 1;
|
const int seq = concat ? d->ud.header.concat->seq : 1;
|
||||||
std::string segment = concat ? std::format(", segment {}/{} of set {}", seq, total, d->ud.header.concat->ref) : std::string();
|
std::string segment = concat ? std::format(", segment {}/{} of set {}", seq, total, d->ud.header.concat->ref) : std::string();
|
||||||
|
if (d->coding.msgClass == 2 && d->pid != imsd::sms::PidShortMessageType0) {
|
||||||
|
// Class 2 is (U)SIM-specific — a (U)SIM data download (TP-PID 0x7F, 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: 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" 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 supporting the (U)SIM Application Toolkit; imsd has none).
|
||||||
|
// imsd has no way to the card for either, so an RP-ERROR with that cause is its
|
||||||
|
// answer to both, each segment's on its own: not stored, not handed over — an
|
||||||
|
// RP-ACK would say the card has it. A short message type 0 is no part of this,
|
||||||
|
// 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 (stored and handed over: AGENTS.md §7.9 has that departure).
|
||||||
|
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("short message from {} via {} at {}{}: class 2{} ({} bytes), which imsd cannot pass to the (U)SIM: refused", d->from.Number(), sc, d->scts, segment, d->pid == imsd::sms::PidSimDataDownload ? ", a (U)SIM data download" : "", rp.tpdu.size())});
|
||||||
|
report(imsd::sms::BuildRpError(rp.mr, imsd::sms::RpCauseProtocolError, imsd::sms::DeliverReportError(imsd::sms::FcsUnspecified)), "delivery report RP-ERROR");
|
||||||
|
return r;
|
||||||
|
}
|
||||||
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("short message from {} via {} at {}{}: {} ({} bytes)", d->from.Number(), sc, d->scts, segment, d->ud.alphabet == imsd::sms::Alphabet::Octet ? "8-bit data" : "text", rp.tpdu.size())});
|
r.actions.push_back(SmsAction{SmsAction::Type::Log, std::format("short message from {} via {} at {}{}: {} ({} bytes)", d->from.Number(), sc, d->scts, segment, d->ud.alphabet == imsd::sms::Alphabet::Octet ? "8-bit data" : "text", rp.tpdu.size())});
|
||||||
if (auto whole = reassembler.Add(*d, now)) {
|
if (auto whole = reassembler.Add(*d, now)) {
|
||||||
SmsAction a{SmsAction::Type::Received};
|
SmsAction a{SmsAction::Type::Received};
|
||||||
|
|
|
||||||
|
|
@ -408,6 +408,10 @@ export namespace imsd::sms {
|
||||||
|
|
||||||
constexpr std::uint8_t DcsGsm7 = 0x00;
|
constexpr std::uint8_t DcsGsm7 = 0x00;
|
||||||
constexpr std::uint8_t DcsUcs2 = 0x08;
|
constexpr std::uint8_t DcsUcs2 = 0x08;
|
||||||
|
// TP-PID "(U)SIM Data download" (TS 23.040 9.2.3.9): with a class 2 coding, a message for the card whole
|
||||||
|
constexpr std::uint8_t PidSimDataDownload = 0x7F;
|
||||||
|
// TP-PID "Short Message Type 0" (9.2.3.9): received whatever memory there is; no message for the card
|
||||||
|
constexpr std::uint8_t PidShortMessageType0 = 0x40;
|
||||||
|
|
||||||
// ---- TS 23.040 9.2.3.24: the user-data header -------------------------
|
// ---- TS 23.040 9.2.3.24: the user-data header -------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,8 @@
|
||||||
// message, a page-mode text 200'd and logged, a short message while SMS
|
// message, a page-mode text 200'd and logged, a short message while SMS
|
||||||
// over IP is off refused with 480, a delivered MESSAGE and a final whose
|
// over IP is off refused with 480, a delivered MESSAGE and a final whose
|
||||||
// header names come in compact form, a delivered MESSAGE whose
|
// header names come in compact form, a delivered MESSAGE whose
|
||||||
// Content-Type came folded), and the store's record codec
|
// Content-Type came folded, a class 2 message refused with an
|
||||||
|
// RP-ERROR and kept from the bus), and the store's record codec
|
||||||
// (FormatStoredSms/ParseStoredSms: a full record round trip, defaults
|
// (FormatStoredSms/ParseStoredSms: a full record round trip, defaults
|
||||||
// for absent keys, a value that does not parse or a missing id refused) and order
|
// for absent keys, a value that does not parse or a missing id refused) and order
|
||||||
// (StoredSmsBefore: the arrival second, then within a run the sequence
|
// (StoredSmsBefore: the arrival second, then within a run the sequence
|
||||||
|
|
@ -1852,6 +1853,44 @@ int main() {
|
||||||
const std::string final202 = Compact(final(callid, 202, "Accepted"));
|
const std::string final202 = Compact(final(callid, 202, "Accepted"));
|
||||||
Check(final202.contains(std::format("\r\ni: {}\r\n", callid)) && !final202.contains("Call-ID:") && m.OwnsResponse(final202), "outbound: a final whose Call-ID comes as `i:` is the message in flight's");
|
Check(final202.contains(std::format("\r\ni: {}\r\n", callid)) && !final202.contains("Call-ID:") && m.OwnsResponse(final202), "outbound: a final whose Call-ID comes as `i:` is the message in flight's");
|
||||||
}
|
}
|
||||||
|
// a class 2 message is (U)SIM-specific and imsd has no way to the card: refused with an RP-ERROR of the cause TS 23.038 4 names, not stored, not handed over
|
||||||
|
{
|
||||||
|
imsd::util::Rng rng(95);
|
||||||
|
Reassembler re;
|
||||||
|
// a (U)SIM data download: TP-PID 0x7F, class 2 8-bit data (DCS 0xF6)
|
||||||
|
auto dl = OnSmsMessage(c, rng, inbound("012107911356131313F30017040B911346610089F67FF6208062917314080401020304"), re, nullptr, sub, 10.0);
|
||||||
|
const auto* rep = findSms(dl.actions, SmsAction::Type::SendClient);
|
||||||
|
Check(dl.response.starts_with("SIP/2.0 200 OK\r\n") && !hasSms(dl.actions, SmsAction::Type::Received) && rep && imsd::sip::Body(rep->text) == std::string("\x04\x21\x01\x6F\x41\x03\x00\xFF\x00", 9) && rep->text.starts_with("MESSAGE sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org SIP/2.0\r\n") && rep->text.contains("\r\nIn-Reply-To: in-012107@net\r\n"), "inbound: a (U)SIM data download is refused with an RP-ERROR — cause 111, TP-FCS 0xFF — to the IP-SM-GW, nothing to the bus");
|
||||||
|
Check(RpCauseProtocolError == 111 && FcsUnspecified == 0xFF && PidSimDataDownload == 0x7F && PidShortMessageType0 == 0x40, "the refusal's cause is 111, its TP-FCS 0xFF; the download's TP-PID 0x7F, a type 0's 0x40");
|
||||||
|
Check(logged(dl.actions, "short message from +31641600986 via +31653131313 at 2002-08-26T19:37:41-00:00: class 2, a (U)SIM data download (23 bytes), which imsd cannot pass to the (U)SIM: refused") && logged(dl.actions, "delivery report RP-ERROR (RP-MR 33) -> sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org"), "inbound: the refusal's two lines");
|
||||||
|
// a class 2 text that is no download (TP-PID 0, DCS 0x12): the same answer
|
||||||
|
auto text = OnSmsMessage(c, rng, inbound("012207911356131313F3001E040B911346610089F60012208062917314080CC8F71D14969741F977FD07"), re, nullptr, sub, 11.0);
|
||||||
|
rep = findSms(text.actions, SmsAction::Type::SendClient);
|
||||||
|
Check(!hasSms(text.actions, SmsAction::Type::Received) && rep && imsd::sip::Body(rep->text) == std::string("\x04\x22\x01\x6F\x41\x03\x00\xFF\x00", 9) && logged(text.actions, "short message from +31641600986 via +31653131313 at 2002-08-26T19:37:41-00:00: class 2 (30 bytes), which imsd cannot pass to the (U)SIM: refused"), "inbound: a class 2 text that is no download is refused the same way");
|
||||||
|
// a segment of a class 2 set: refused on its own, nothing kept for a reassembly
|
||||||
|
auto seg = OnSmsMessage(c, rng, inbound("012307911356131313F3001E440B911316325476F80012620161220500800C0500037B02028442A15008"), re, nullptr, sub, 12.0);
|
||||||
|
rep = findSms(seg.actions, SmsAction::Type::SendClient);
|
||||||
|
Check(!hasSms(seg.actions, SmsAction::Type::Received) && rep && imsd::sip::Body(rep->text) == std::string("\x04\x23\x01\x6F\x41\x03\x00\xFF\x00", 9) && re.Pending() == 0 && logged(seg.actions, "short message from +31612345678 via +31653131313 at 2026-10-16T22:50:00+02:00, segment 2/2 of set 123: class 2 (30 bytes), which imsd cannot pass to the (U)SIM: refused"), "inbound: a segment of a class 2 set is refused on its own, none of it held");
|
||||||
|
// the other classes, and TP-PID 0x7F without class 2 ("handled in the normal way", TS 23.040 9.2.3.9): received and acknowledged
|
||||||
|
for (std::string_view tpdu : {"040B911346610089F60010208062917314080CC8F71D14969741F977FD07", "040B911346610089F60011208062917314080CC8F71D14969741F977FD07", "040B911346610089F60013208062917314080CC8F71D14969741F977FD07", "040B911346610089F67FF5208062917314080401020304", "040B911346610089F67F04208062917314080401020304"}) {
|
||||||
|
auto ok = OnSmsMessage(c, rng, inbound(std::format("012407911356131313F300{:02X}{}", tpdu.size() / 2, tpdu)), re, nullptr, sub, 13.0);
|
||||||
|
rep = findSms(ok.actions, SmsAction::Type::SendClient);
|
||||||
|
const auto* rec = findSms(ok.actions, SmsAction::Type::Received);
|
||||||
|
Check(rec && rec->received.msgClass != 2 && rep && imsd::sip::Body(rep->text) == std::string("\x02\x24\x41\x02\x00\x00", 6), std::format("inbound: {} is received and acknowledged", tpdu.substr(18, 4) == "0010" ? "class 0" : tpdu.substr(18, 4) == "0011" ? "class 1" : tpdu.substr(18, 4) == "0013" ? "class 3" : tpdu.substr(18, 4) == "7FF5" ? "TP-PID 0x7F with class 1" : "TP-PID 0x7F with no class"));
|
||||||
|
}
|
||||||
|
// a short message type 0 (TP-PID 0x40) with a class 2 coding (DCS 0x12) is no message for the card (TS 23.040 9.2.3.9): acknowledged, and handed over as any type 0
|
||||||
|
auto type0 = OnSmsMessage(c, rng, inbound("012607911356131313F3001E040B911346610089F64012208062917314080CC8F71D14969741F977FD07"), re, nullptr, sub, 13.5);
|
||||||
|
rep = findSms(type0.actions, SmsAction::Type::SendClient);
|
||||||
|
const auto* rec0 = findSms(type0.actions, SmsAction::Type::Received);
|
||||||
|
Check(rec0 && rec0->received.pid == 0x40 && rec0->received.msgClass == 2 && rec0->received.text == "How are you?" && rep && imsd::sip::Body(rep->text) == std::string("\x02\x26\x41\x02\x00\x00", 6), "inbound: a type 0 message with a class 2 coding is acknowledged and handed over, not refused");
|
||||||
|
// with no gateway named, the refusal cannot go anywhere either: logged, nothing handed over
|
||||||
|
std::string anon = inbound("012507911356131313F30017040B911346610089F67FF6208062917314080401020304");
|
||||||
|
const std::string pai = "P-Asserted-Identity: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>\r\n", from = "From: <sip:ipsmgw@ims.mnc001.mcc001.3gppnetwork.org>;tag=N1";
|
||||||
|
anon.erase(anon.find(pai), pai.size());
|
||||||
|
anon.replace(anon.find(from), from.size(), "From: anonymous;tag=N1");
|
||||||
|
auto none = OnSmsMessage(c, rng, anon, re, nullptr, sub, 14.0);
|
||||||
|
Check(none.response.starts_with("SIP/2.0 200 OK\r\n") && !hasSms(none.actions, SmsAction::Type::Received) && !hasSms(none.actions, SmsAction::Type::SendClient) && logged(none.actions, "no P-Asserted-Identity or From URI on the delivered MESSAGE: no delivery report RP-ERROR sent"), "inbound: a class 2 message that names no gateway: neither handed over nor refused on the wire");
|
||||||
|
}
|
||||||
// a Call-ID the delivery report cannot carry — a byte up to 0x20 in it (but an LF, which ends the line) or a DEL: no In-Reply-To, the message and its report as ever
|
// a Call-ID the delivery report cannot carry — a byte up to 0x20 in it (but an LF, which ends the line) or a DEL: no In-Reply-To, the message and its report as ever
|
||||||
for (int b = 0; b <= 0x7F; b++) {
|
for (int b = 0; b <= 0x7F; b++) {
|
||||||
if ((b > 0x20 && b != 0x7F) || b == 0x0A) continue;
|
if ((b > 0x20 && b != 0x7F) || b == 0x0A) continue;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue