imsd, engine: the Messaging status and a received text carry the SIM's operator

A consumer that keeps a number in the form it was written in — a
national number, an operator's short code — has to know where it was
written before it dials it again: a national number's country, a short
code's operator. The own number's country code is not enough for either:
countries share a code, and the operators of one country share theirs.
The daemon reads the SIM's operator id at bring-up (ModemManager's: MCC
then MNC), which names the subscription's country and operator. The
Messaging GetStatus gives it as `operator`, from the snapshot `ppi`
comes from, and a received text's record and its Received and List
dictionaries carry the one the daemon held at receipt, beside `to` —
additive keys, as `to` and `ppi` are, and the operator id only, never
the IMSI.

Tested: tests/Engine, the record round trip with `operator` and a
record without it.
This commit is contained in:
Jorijn van der Graaf 2026-11-12 00:21:41 +01:00
commit e39f7e39d6
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 30 additions and 18 deletions

View file

@ -653,8 +653,8 @@ Rules:
`SMSC='abc' is not a number` (`ForNumber` dials digits, `*` and `#` only; `SMSC='abc' is not a number` (`ForNumber` dials digits, `*` and `#` only;
the bench's first run, on a build outside this history that dialled a, b the bench's first run, on a build outside this history that dialled a, b
and c, submitted with them and got an RP-ERROR back, RP cause 28). and c, submitted with them and got an RP-ERROR back, RP cause 28).
No phone record shows `to` in a `Received` or a `List`; the store's round No phone record shows `to` or `operator` in a `Received` or a `List`; the
trip with it is in `tests/Engine`. store's round trip with each is in `tests/Engine`.
- `imsd-pcscf` ran on the dev phone (KPN) on 2026-10-11 against the live ims - `imsd-pcscf` ran on the dev phone (KPN) on 2026-10-11 against the live ims
bearer: the `--mux 1 --profile 2 -v` sequence, a plain run, and `OutOfCall` bearer: the `--mux 1 --profile 2 -v` sequence, a plain run, and `OutOfCall`
on an unbound mux (the fp6 journal's `2026-10-11-pcscf-pco-probe` capture, on an unbound mux (the fp6 journal's `2026-10-11-pcscf-pco-probe` capture,
@ -722,7 +722,8 @@ login, an inactive session or a system service account). Reads (`GetStatus`,
ModemManager's are to every local account: the call ModemManager's are to every local account: the call
signals reach them all anyway, the status (the address, the P-CSCF, the signals reach them all anyway, the status (the address, the P-CSCF, the
phone number) travels in no broadcast signal — `Received` carries the phone number) travels in no broadcast signal — `Received` carries the
phone number (`to`), unicast to the Messaging interface's subscribers (§8.4). phone number (`to`) and the SIM's operator, unicast to the Messaging
interface's subscribers (§8.4).
Two threads: a dedicated engine thread runs the SIP loop (blocking framed Two threads: a dedicated engine thread runs the SIP loop (blocking framed
receive on the protected client flow, the protected-port listeners for receive on the protected client flow, the protected-port listeners for
@ -1871,12 +1872,12 @@ when it does not know it.
| Member | Signature | | Member | Signature |
|---|---| |---|---|
| `Send(number, text, options)` | `ssa{sv} → s` (the message's id, `ims-sms-<run>-<start>-<N>`: this run's token — eight hex digits drawn at the daemon's start —, its start second and a counter; a later run gives the same id only if it draws the same token and starts in the same second, and a received id (`ims-sms-in-<run>-<epoch>-<N>`) only with the same token, arrival second and counter; a client keys `StateChanged` by id); options: `status-report` (b). `org.freedesktop.DBus.Error.NotSupported` while `SMS_OVER_IMS` is off | | `Send(number, text, options)` | `ssa{sv} → s` (the message's id, `ims-sms-<run>-<start>-<N>`: this run's token — eight hex digits drawn at the daemon's start —, its start second and a counter; a later run gives the same id only if it draws the same token and starts in the same second, and a received id (`ims-sms-in-<run>-<epoch>-<N>`) only with the same token, arrival second and counter; a client keys `StateChanged` by id); options: `status-report` (b). `org.freedesktop.DBus.Error.NotSupported` while `SMS_OVER_IMS` is off |
| `GetStatus()` | `→ a{sv}`: `enabled` (b, the daemon's configuration — answered before the first registration too), `smsc` (s, the service centre as of the daemon's last status snapshot, the one the frozen `GetStatus` answers from — so empty before a run's first, and when none is known), `ppi` (s, the own number in that snapshot — the frozen interface's `ppi`, made valid UTF-8 as `to` is, so a consumer needs no second call — empty while the snapshot holds none), `registered` (b), `subscribers` (u). No count of the store: `GetStatus` is the open read, and a count would tell any local account when a text arrived; `List`'s length is behind the gate | | `GetStatus()` | `→ a{sv}`: `enabled` (b, the daemon's configuration — answered before the first registration too), `smsc` (s, the service centre as of the daemon's last status snapshot, the one the frozen `GetStatus` answers from — so empty before a run's first, and when none is known), `ppi` (s, the own number in that snapshot — the frozen interface's `ppi`, made valid UTF-8 as `to` is, so a consumer needs no second call — empty while the snapshot holds none), `operator` (s, the SIM's operator id — MCC then MNC, as ModemManager gives it, and never the IMSI — empty until the first status after the SIM is read), `registered` (b), `subscribers` (u). No count of the store: `GetStatus` is the open read, and a count would tell any local account when a text arrived; `List`'s length is behind the gate |
| `Subscribe()` | `→` nothing: the caller's connection receives the two signals below from now on, until it closes. It succeeds while SMS over IP is off too (only `Send` is refused then); a consumer reads `enabled` for that state | | `Subscribe()` | `→` nothing: the caller's connection receives the two signals below from now on, until it closes. It succeeds while SMS over IP is off too (only `Send` is refused then); a consumer reads `enabled` for that state |
| `List()` | `→ a(sa{sv})`: the stored messages it can read, by the arrival second on the phone's wall clock, then within a run the sequence number — oldest first on a synced clock (a 1970 second before the first time sync sorts first; the SC's `timestamp` is the chronology, §7.9) — each the id and the same dictionary `Received` carries (its `received` the arrival time) | | `List()` | `→ a(sa{sv})`: the stored messages it can read, by the arrival second on the phone's wall clock, then within a run the sequence number — oldest first on a synced clock (a 1970 second before the first time sync sorts first; the SC's `timestamp` is the chronology, §7.9) — each the id and the same dictionary `Received` carries (its `received` the arrival time) |
| `Delete(id)` | `s`: removes a stored message; `org.freedesktop.DBus.Error.InvalidArgs` for an empty string, one over 64 bytes or one with a character other than an ASCII letter, an ASCII digit or `-`; `org.freedesktop.DBus.Error.FileNotFound` for any other string when the removal found no file; `org.freedesktop.DBus.Error.IOError`, with the system's reason, when the removal failed — a record that is there is kept | | `Delete(id)` | `s`: removes a stored message; `org.freedesktop.DBus.Error.InvalidArgs` for an empty string, one over 64 bytes or one with a character other than an ASCII letter, an ASCII digit or `-`; `org.freedesktop.DBus.Error.FileNotFound` for any other string when the removal found no file; `org.freedesktop.DBus.Error.IOError`, with the system's reason, when the removal failed — a record that is there is kept |
| `Received` | `s a{sv}` — unicast to each subscriber (id `ims-sms-in-<run>-<epoch>-<N>`; `from` s, `text` s, `timestamp` s (the SC's, with its offset: `2026-10-16T22:50:00+02:00`), `received` x (epoch), `sc` s, `to` s when the daemon held an own number at receipt (the first tel: P-Associated-URI of this run's latest answer to a fresh registration, a resume or a reconnect that carried one — a periodic refresh's answer is not read for it — and, until the first such, the state file's once a resume attempt has taken it up): the subscriber the text arrived for, which a later SIM's status cannot tell, `class` i (-1: none), `pid` y, `dcs` y, `segments` i, `message-waiting` b, `port-dst`/`port-src` u when the header addresses a port, `data` ay for 8-bit data, `pdu` ay — the SMS-DELIVER as received; of a concatenated message, the segment that completed the set, the last to arrive) | | `Received` | `s a{sv}` — unicast to each subscriber (id `ims-sms-in-<run>-<epoch>-<N>`; `from` s, `text` s, `timestamp` s (the SC's, with its offset: `2026-10-16T22:50:00+02:00`), `received` x (epoch), `sc` s, `to` s when the daemon held an own number at receipt (the first tel: P-Associated-URI of this run's latest answer to a fresh registration, a resume or a reconnect that carried one — a periodic refresh's answer is not read for it — and, until the first such, the state file's once a resume attempt has taken it up): the subscriber the text arrived for, which a later SIM's status cannot tell, `operator` s when the SIM's operator id was known at receipt: the subscription's country and operator, by which a consumer reads a sender in national form or a short code, `class` i (-1: none), `pid` y, `dcs` y, `segments` i, `message-waiting` b, `port-dst`/`port-src` u when the header addresses a port, `data` ay for 8-bit data, `pdu` ay — the SMS-DELIVER as received; of a concatenated message, the segment that completed the set, the last to arrive) |
| `StateChanged` | `s s s` — unicast to each subscriber, and the submission's `sent` / `failed` also to the connection that called `Send` (id, state, reason): `sent` / `failed` for the submission, `delivered` / `delivery-pending` / `delivery-failed` from a status report — each speaks for the whole message, never for one segment, and `delivery-pending` can come more than once; `delivered` only when every segment's report is in the completed class (§7.9; the reason carries the SC's status word). The words of one message come in this order: the submission's first — `sent`, or `failed`, after which nothing follows — and a status report's only after `sent` (a report the SC sends while a later segment is still on its way is held until the submission ends; a submission whose every segment the SC reported delivered before its last submit report came ends as `sent` then `delivered`), so a consumer applies each word as it comes. Every string of the two signals is valid UTF-8: a `failed` reason can hold the network's text (a refused final's, `RefusalSummary`), so the emission makes it valid — bytes that are not UTF-8 become U+FFFD, and a NUL byte ends the string (the `Received` strings are the codecs' own; `to` is made valid the same way) | | `StateChanged` | `s s s` — unicast to each subscriber, and the submission's `sent` / `failed` also to the connection that called `Send` (id, state, reason): `sent` / `failed` for the submission, `delivered` / `delivery-pending` / `delivery-failed` from a status report — each speaks for the whole message, never for one segment, and `delivery-pending` can come more than once; `delivered` only when every segment's report is in the completed class (§7.9; the reason carries the SC's status word). The words of one message come in this order: the submission's first — `sent`, or `failed`, after which nothing follows — and a status report's only after `sent` (a report the SC sends while a later segment is still on its way is held until the submission ends; a submission whose every segment the SC reported delivered before its last submit report came ends as `sent` then `delivered`), so a consumer applies each word as it comes. Every string of the two signals is valid UTF-8: a `failed` reason can hold the network's text (a refused final's, `RefusalSummary`), so the emission makes it valid — bytes that are not UTF-8 become U+FFFD, and a NUL byte ends the string (the `Received` strings are the codecs' own; `to` is made valid the same way, and `operator` is digits) |
`Send`, `Subscribe`, `List` and `Delete` are gated by polkit's `Send`, `Subscribe`, `List` and `Delete` are gated by polkit's
`net.catcrafts.IMS1.Messaging` through the same `imsd-bus` gate (`Gated`'s `Action` parameter); `net.catcrafts.IMS1.Messaging` through the same `imsd-bus` gate (`Gated`'s `Action` parameter);

View file

@ -153,11 +153,11 @@ gain a key.
| Member | Signature | | Member | Signature |
|---|---| |---|---|
| `Send(number, text, options)` | `ssa{sv} → s` (id); options: `status-report` (b, ask the SC to report delivery). Refused with `NotSupported` while SMS over IMS is off | | `Send(number, text, options)` | `ssa{sv} → s` (id); options: `status-report` (b, ask the SC to report delivery). Refused with `NotSupported` while SMS over IMS is off |
| `GetStatus()` | `→ a{sv}`: `enabled` (b), `smsc` (s), `ppi` (s, the own number in the daemon's last status, e.g. `tel:+31612345678`), `registered` (b), `subscribers` (u) | | `GetStatus()` | `→ a{sv}`: `enabled` (b), `smsc` (s), `ppi` (s, the own number in the daemon's last status, e.g. `tel:+31612345678`), `operator` (s, the SIM's operator id in that status), `registered` (b), `subscribers` (u) |
| `Subscribe()` | `→` nothing: the calling connection receives `Received` and `StateChanged` from now on (unicast, never broadcast: to subscribers, and a submission's `sent` / `failed` also to its `Send` caller); subscribe again when imsd's name reappears on the bus | | `Subscribe()` | `→` nothing: the calling connection receives `Received` and `StateChanged` from now on (unicast, never broadcast: to subscribers, and a submission's `sent` / `failed` also to its `Send` caller); subscribe again when imsd's name reappears on the bus |
| `List()` | `→ a(sa{sv})`: the stored messages it can read, 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 | | `List()` | `→ a(sa{sv})`: the stored messages it can read, 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 |
| `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`), `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), `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

@ -822,6 +822,7 @@ struct StatusSnapshot {
std::int64_t expiry = 0; std::int64_t expiry = 0;
std::int64_t cseq = 0; std::int64_t cseq = 0;
std::string smsc; // the service centre a submission goes to (empty: none known) std::string smsc; // the service centre a submission goes to (empty: none known)
std::string simOperator; // the SIM's operator id: MCC then MNC, as ModemManager gives it (empty: no SIM read when the status was taken)
}; };
// engine -> main-loop event // engine -> main-loop event
@ -834,6 +835,7 @@ struct Event {
imsd::engine::SmsReceived sms; // SmsReceived imsd::engine::SmsReceived sms; // SmsReceived
std::int64_t at = 0; // SmsReceived: when it arrived (epoch seconds) std::int64_t at = 0; // SmsReceived: when it arrived (epoch seconds)
std::string to; // SmsReceived: the subscriber it arrived for (the own number the daemon held then) std::string to; // SmsReceived: the subscriber it arrived for (the own number the daemon held then)
std::string simOperator; // SmsReceived: the operator id of the SIM it arrived under
}; };
GDBusConnection* DbusConn = nullptr; GDBusConnection* DbusConn = nullptr;
@ -1079,7 +1081,7 @@ std::vector<imsd::engine::StoredSms> LoadStoredSms(bool log = true) {
std::size_t StoredSmsCount() { return LoadStoredSms(false).size(); } std::size_t StoredSmsCount() { return LoadStoredSms(false).size(); }
// a received short message as the Messaging interface's a{sv} (§8.4) // a received short message as the Messaging interface's a{sv} (§8.4)
GVariant* SmsVariant(const imsd::engine::SmsReceived& m, std::int64_t receivedAt, const std::string& to) { GVariant* SmsVariant(const imsd::engine::SmsReceived& m, std::int64_t receivedAt, const std::string& to, const std::string& simOperator) {
GVariantBuilder b; GVariantBuilder b;
g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}")); g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(&b, "{sv}", "from", g_variant_new_string(m.from.c_str())); g_variant_builder_add(&b, "{sv}", "from", g_variant_new_string(m.from.c_str()));
@ -1089,6 +1091,7 @@ GVariant* SmsVariant(const imsd::engine::SmsReceived& m, std::int64_t receivedAt
g_variant_builder_add(&b, "{sv}", "sc", g_variant_new_string(m.sc.c_str())); g_variant_builder_add(&b, "{sv}", "sc", g_variant_new_string(m.sc.c_str()));
// from a header: made valid UTF-8 like a failed submission's reason // from a header: made valid UTF-8 like a failed submission's reason
if (!to.empty()) g_variant_builder_add(&b, "{sv}", "to", g_variant_new_take_string(g_utf8_make_valid(to.c_str(), -1))); if (!to.empty()) g_variant_builder_add(&b, "{sv}", "to", g_variant_new_take_string(g_utf8_make_valid(to.c_str(), -1)));
if (!simOperator.empty()) g_variant_builder_add(&b, "{sv}", "operator", g_variant_new_string(simOperator.c_str()));
g_variant_builder_add(&b, "{sv}", "class", g_variant_new_int32(m.msgClass.value_or(-1))); g_variant_builder_add(&b, "{sv}", "class", g_variant_new_int32(m.msgClass.value_or(-1)));
g_variant_builder_add(&b, "{sv}", "pid", g_variant_new_byte(m.pid)); g_variant_builder_add(&b, "{sv}", "pid", g_variant_new_byte(m.pid));
g_variant_builder_add(&b, "{sv}", "dcs", g_variant_new_byte(m.dcs)); g_variant_builder_add(&b, "{sv}", "dcs", g_variant_new_byte(m.dcs));
@ -1143,7 +1146,7 @@ gboolean OnIdleEvent(gpointer data) {
break; break;
case Event::Type::SmsReceived: case Event::Type::SmsReceived:
for (const std::string& to : Subscribers) for (const std::string& to : Subscribers)
EmitSignalTo(to, "Received", g_variant_new("(s@a{sv})", ev->uni.c_str(), SmsVariant(ev->sms, ev->at, ev->to))); EmitSignalTo(to, "Received", g_variant_new("(s@a{sv})", ev->uni.c_str(), SmsVariant(ev->sms, ev->at, ev->to, ev->simOperator)));
break; break;
case Event::Type::SmsState: { case Event::Type::SmsState: {
std::set<std::string> to = Subscribers; std::set<std::string> to = Subscribers;
@ -1475,6 +1478,7 @@ private:
imsd::msg::Context ctx_; imsd::msg::Context ctx_;
RegState reg_; RegState reg_;
std::string route_, ppi_, ss_; std::string route_, ppi_, ss_;
std::string simOperator_; // the SIM's operator id as read at bring-up: MCC then MNC
bool registered_ = false; bool registered_ = false;
SipFlow sip_; SipFlow sip_;
ServerPorts server_; ServerPorts server_;
@ -1586,6 +1590,7 @@ private:
auto info = imsd::aka::ParseSimInfo(siminfo.out); auto info = imsd::aka::ParseSimInfo(siminfo.out);
if (!info) throw std::runtime_error("SIM IMSI/operator not found"); if (!info) throw std::runtime_error("SIM IMSI/operator not found");
ctx_.id = imsd::aka::MakeIdentity(info->imsi, info->mcc, info->mnc); ctx_.id = imsd::aka::MakeIdentity(info->imsi, info->mcc, info->mnc);
simOperator_ = info->mcc + info->mnc;
ctx_.local = local_; ctx_.local = local_;
ctx_.ealgOffer = ealgOffer_; ctx_.ealgOffer = ealgOffer_;
SetTransport(transport_); SetTransport(transport_);
@ -2903,11 +2908,12 @@ private:
ev->at = NowEpoch(); ev->at = NowEpoch();
ev->sms = m; ev->sms = m;
ev->to = ppi_; // the subscriber it arrived for: the own number held now, not a later SIM's ev->to = ppi_; // the subscriber it arrived for: the own number held now, not a later SIM's
ev->simOperator = simOperator_;
std::string why; std::string why;
StoreResult stored = StoreResult::Failed; StoreResult stored = StoreResult::Failed;
for (int tries = 0; tries < 1000; tries++) { for (int tries = 0; tries < 1000; tries++) {
ev->uni = imsd::engine::ReceivedSmsId(smsRun_, ev->at, ++smsInSeq_); ev->uni = imsd::engine::ReceivedSmsId(smsRun_, ev->at, ++smsInSeq_);
stored = StoreReceivedSms({ev->uni, ev->at, m, ppi_}, why); stored = StoreReceivedSms({ev->uni, ev->at, m, ppi_, simOperator_}, why);
if (stored != StoreResult::Exists) break; if (stored != StoreResult::Exists) break;
Log(std::format("sms store: {} exists already; taking the next id", ev->uni)); Log(std::format("sms store: {} exists already; taking the next id", ev->uni));
} }
@ -3156,7 +3162,7 @@ private:
void EmitStatus(bool registrationSignal) { void EmitStatus(bool registrationSignal) {
auto ev = std::make_unique<Event>(); auto ev = std::make_unique<Event>();
ev->type = registrationSignal ? Event::Type::Registration : Event::Type::Status; ev->type = registrationSignal ? Event::Type::Registration : Event::Type::Status;
ev->status = StatusSnapshot{registered_, local_, pcscf_, ppi_, reg_.expiry, reg_.cseq, smsc_}; ev->status = StatusSnapshot{registered_, local_, pcscf_, ppi_, reg_.expiry, reg_.cseq, smsc_, simOperator_};
PostEvent(std::move(ev)); PostEvent(std::move(ev));
} }
void PostAdded(const CallInfo& info) { void PostAdded(const CallInfo& info) {
@ -3305,6 +3311,7 @@ void HandleMessagingMethod(GDBusConnection* conn, const gchar*, const gchar*, co
g_variant_builder_add(&b, "{sv}", "enabled", g_variant_new_boolean(TheEngine->SmsEnabled() ? TRUE : FALSE)); g_variant_builder_add(&b, "{sv}", "enabled", g_variant_new_boolean(TheEngine->SmsEnabled() ? TRUE : FALSE));
g_variant_builder_add(&b, "{sv}", "smsc", g_variant_new_string(StatusSnap.smsc.c_str())); g_variant_builder_add(&b, "{sv}", "smsc", g_variant_new_string(StatusSnap.smsc.c_str()));
g_variant_builder_add(&b, "{sv}", "ppi", g_variant_new_take_string(g_utf8_make_valid(StatusSnap.ppi.c_str(), -1))); // from a header, as `to` g_variant_builder_add(&b, "{sv}", "ppi", g_variant_new_take_string(g_utf8_make_valid(StatusSnap.ppi.c_str(), -1))); // from a header, as `to`
g_variant_builder_add(&b, "{sv}", "operator", g_variant_new_string(StatusSnap.simOperator.c_str()));
g_variant_builder_add(&b, "{sv}", "registered", g_variant_new_boolean(StatusSnap.registered ? TRUE : FALSE)); g_variant_builder_add(&b, "{sv}", "registered", g_variant_new_boolean(StatusSnap.registered ? TRUE : FALSE));
g_variant_builder_add(&b, "{sv}", "subscribers", g_variant_new_uint32(static_cast<guint32>(Subscribers.size()))); g_variant_builder_add(&b, "{sv}", "subscribers", g_variant_new_uint32(static_cast<guint32>(Subscribers.size())));
g_dbus_method_invocation_return_value(inv, g_variant_new("(a{sv})", &b)); g_dbus_method_invocation_return_value(inv, g_variant_new("(a{sv})", &b));
@ -3313,7 +3320,7 @@ void HandleMessagingMethod(GDBusConnection* conn, const gchar*, const gchar*, co
if (m == "List") { if (m == "List") {
GVariantBuilder b; GVariantBuilder b;
g_variant_builder_init(&b, G_VARIANT_TYPE("a(sa{sv})")); g_variant_builder_init(&b, G_VARIANT_TYPE("a(sa{sv})"));
for (const auto& r : LoadStoredSms()) g_variant_builder_add(&b, "(s@a{sv})", r.id.c_str(), SmsVariant(r.sms, r.receivedAt, r.to)); for (const auto& r : LoadStoredSms()) g_variant_builder_add(&b, "(s@a{sv})", r.id.c_str(), SmsVariant(r.sms, r.receivedAt, r.to, r.simOperator));
g_dbus_method_invocation_return_value(inv, g_variant_new("(a(sa{sv}))", &b)); g_dbus_method_invocation_return_value(inv, g_variant_new("(a(sa{sv}))", &b));
return; return;
} }

View file

@ -1309,8 +1309,8 @@ export namespace imsd::engine {
// A received message as the daemon keeps it until an app takes it // A received message as the daemon keeps it until an app takes it
// (`List`/`Delete` on the Messaging interface, §8.4): its id, when it // (`List`/`Delete` on the Messaging interface, §8.4): its id, when it
// arrived (epoch seconds), the message and the subscriber it arrived // arrived (epoch seconds), the message, the subscriber it arrived
// for. One record per file, // for and the SIM's operator then. One record per file,
// key=value lines; the sender, the text, the data and the PDU as hex // key=value lines; the sender, the text, the data and the PDU as hex
// (a sender or a text may hold any character). Absent keys read as // (a sender or a text may hold any character). Absent keys read as
// their defaults; a record without an id, or with a number or hex // their defaults; a record without an id, or with a number or hex
@ -1320,6 +1320,7 @@ export namespace imsd::engine {
std::int64_t receivedAt = 0; std::int64_t receivedAt = 0;
SmsReceived sms; SmsReceived sms;
std::string to; // the own number the daemon held at receipt (from a tel: P-Associated-URI); "" while it held none std::string to; // the own number the daemon held at receipt (from a tel: P-Associated-URI); "" while it held none
std::string simOperator; // the SIM's operator id at receipt (MCC then MNC); "" when none was read
}; };
std::string FormatStoredSms(const StoredSms& r) { std::string FormatStoredSms(const StoredSms& r) {
@ -1328,6 +1329,7 @@ export namespace imsd::engine {
out += std::format("id={}\n", r.id); out += std::format("id={}\n", r.id);
out += std::format("received={}\n", r.receivedAt); out += std::format("received={}\n", r.receivedAt);
if (!r.to.empty()) out += std::format("to={}\n", r.to); if (!r.to.empty()) out += std::format("to={}\n", r.to);
if (!r.simOperator.empty()) out += std::format("operator={}\n", r.simOperator);
out += std::format("from={}\n", hex(r.sms.from)); out += std::format("from={}\n", hex(r.sms.from));
out += std::format("sc={}\n", r.sms.sc); out += std::format("sc={}\n", r.sms.sc);
out += std::format("timestamp={}\n", r.sms.scts); out += std::format("timestamp={}\n", r.sms.scts);
@ -1381,6 +1383,7 @@ export namespace imsd::engine {
if (k == "id") r.id = std::string(v); if (k == "id") r.id = std::string(v);
else if (k == "received") r.receivedAt = intOf(v); else if (k == "received") r.receivedAt = intOf(v);
else if (k == "to") r.to = std::string(v); else if (k == "to") r.to = std::string(v);
else if (k == "operator") r.simOperator = std::string(v);
else if (k == "from") r.sms.from = stringOf(v); else if (k == "from") r.sms.from = stringOf(v);
else if (k == "sc") r.sms.sc = std::string(v); else if (k == "sc") r.sms.sc = std::string(v);
else if (k == "timestamp") r.sms.scts = std::string(v); else if (k == "timestamp") r.sms.scts = std::string(v);

View file

@ -1674,6 +1674,7 @@ int main() {
r.id = "ims-sms-in-1792186043-7"; r.id = "ims-sms-in-1792186043-7";
r.receivedAt = 1792186043; r.receivedAt = 1792186043;
r.to = "tel:+31612345678"; r.to = "tel:+31612345678";
r.simOperator = "20408";
r.sms.from = "KPN Service=\n\"x\""; r.sms.from = "KPN Service=\n\"x\"";
r.sms.text = "Grüße ❤\nline two=three"; r.sms.text = "Grüße ❤\nline two=three";
r.sms.scts = "2026-10-16T22:50:00+02:00"; r.sms.scts = "2026-10-16T22:50:00+02:00";
@ -1688,11 +1689,11 @@ int main() {
r.sms.data = {0xDE, 0xAD}; r.sms.data = {0xDE, 0xAD};
r.sms.tpdu = {0x04, 0x0B, 0x91}; r.sms.tpdu = {0x04, 0x0B, 0x91};
const std::string text = FormatStoredSms(r); const std::string text = FormatStoredSms(r);
Check(text.starts_with("id=ims-sms-in-1792186043-7\nreceived=1792186043\nto=tel:+31612345678\nfrom=") && text.contains("\nport-dst=2948\nport-src=9200\n") && text.ends_with("\npdu=040b91\n") && !text.contains("Grüße"), "store: the record's shape, the text as hex"); Check(text.starts_with("id=ims-sms-in-1792186043-7\nreceived=1792186043\nto=tel:+31612345678\noperator=20408\nfrom=") && text.contains("\nport-dst=2948\nport-src=9200\n") && text.ends_with("\npdu=040b91\n") && !text.contains("Grüße"), "store: the record's shape, the text as hex");
auto back = ParseStoredSms(text); auto back = ParseStoredSms(text);
Check(back && back->id == r.id && back->receivedAt == r.receivedAt && back->to == r.to && back->sms.from == r.sms.from && back->sms.text == r.sms.text && back->sms.scts == r.sms.scts && back->sms.sc == r.sms.sc && back->sms.msgClass == 0 && back->sms.pid == 0x40 && back->sms.dcs == 0x08 && back->sms.segments == 2 && back->sms.messageWaiting && back->sms.portDst == 2948 && back->sms.portSrc == 9200 && back->sms.data == r.sms.data && back->sms.tpdu == r.sms.tpdu, "store: a full record round-trips"); Check(back && back->id == r.id && back->receivedAt == r.receivedAt && back->to == r.to && back->simOperator == r.simOperator && back->sms.from == r.sms.from && back->sms.text == r.sms.text && back->sms.scts == r.sms.scts && back->sms.sc == r.sms.sc && back->sms.msgClass == 0 && back->sms.pid == 0x40 && back->sms.dcs == 0x08 && back->sms.segments == 2 && back->sms.messageWaiting && back->sms.portDst == 2948 && back->sms.portSrc == 9200 && back->sms.data == r.sms.data && back->sms.tpdu == r.sms.tpdu, "store: a full record round-trips");
auto minimal = ParseStoredSms("id=x\n"); auto minimal = ParseStoredSms("id=x\n");
Check(minimal && minimal->id == "x" && minimal->receivedAt == 0 && minimal->to.empty() && !minimal->sms.msgClass && !minimal->sms.portDst && minimal->sms.segments == 1 && minimal->sms.text.empty(), "store: absent keys read as defaults"); Check(minimal && minimal->id == "x" && minimal->receivedAt == 0 && minimal->to.empty() && minimal->simOperator.empty() && !minimal->sms.msgClass && !minimal->sms.portDst && minimal->sms.segments == 1 && minimal->sms.text.empty(), "store: absent keys read as defaults");
Check(!ParseStoredSms("received=5\nfrom=00\n"), "store: no id, no record"); Check(!ParseStoredSms("received=5\nfrom=00\n"), "store: no id, no record");
Check(!ParseStoredSms("id=x\ntext=zz\n"), "store: a malformed hex value, no record"); Check(!ParseStoredSms("id=x\ntext=zz\n"), "store: a malformed hex value, no record");
Check(!ParseStoredSms("id=x\nreceived=soon\n"), "store: a malformed number, no record"); Check(!ParseStoredSms("id=x\nreceived=soon\n"), "store: a malformed number, no record");