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

@ -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
// with an SMS-DELIVER is answered 200, handed to the reassembler and,
// 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
// over for the shell to match; one whose TPDU is unusable is
// 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 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();
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())});
if (auto whole = reassembler.Add(*d, now)) {
SmsAction a{SmsAction::Type::Received};

View file

@ -408,6 +408,10 @@ export namespace imsd::sms {
constexpr std::uint8_t DcsGsm7 = 0x00;
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 -------------------------