Linux userspace IMS daemon
  • C++ 95.9%
  • Shell 4.1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jorijn van der Graaf aa3c394041
imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging
With the modem's own IMS client off, a carrier that carries SMS over IMS
only leaves the phone no path for texts but imsd; on one with SMS over
NAS the +g.3gpp.smsip tag may take them off a path that works (the
order is operator policy, TS 24.341 5.3.3.4.2 NOTE 2). So the knob is the user's and off by default: SMS_OVER_IMS=1
advertises the tag (Context::smsOverIp), reads the service centre from
EF_SMSP record 1 at bring-up — SMSC= instead — and opens Send on a
second interface, net.catcrafts.IMS1.Messaging, beside the frozen one,
gated by a polkit action of its own (Gated's Action parameter; the Voice
action's callers are unchanged). The shell keeps one message in flight
on the flow and queues the rest, routes the in-flight MESSAGE's final
to it (OnSmsResponse; a submit report reaches it through OnSmsMessage),
seeds and advances the TP-MR, RP-MR and concatenation counters, answers an inbound
MESSAGE outside a call through OnSmsMessage (one inside the call's
dialog stays the CallMachine's, and is not the MESSAGE of any sentence
below) — the message to the bus as
Received, the delivery report on the flow with its final logged, a
status report matched by TP-MR and recipient to the message that asked
for one — and reports a message's fate as StateChanged. A Send is judged
when the engine takes its command up: unregistered or with the flow down
then, it fails with that reason.
The journal names a delivered message's sender, size and time — a text
reaches it only as the body of a MESSAGE whose Content-Type does not
contain application/vnd.3gpp.sms or as the hex of a body that is no RP
message or of an unusable TPDU; DUMP_SIP adds the two MESSAGE dumps.

While the knob is off a network may deliver a short message over IP
regardless; answering it 200 and acknowledging it would count it
delivered to nobody, so it is refused with 480 Temporarily Unavailable,
which lets the IP-SM-GW try the modem's path where the network has one
(TS 24.341 5.3.3.4.2 NOTE 2); a MESSAGE outside a call's dialog whose
Content-Type does not contain application/vnd.3gpp.sms (letter case
ignored) is still answered 200 and logged with its body — the 200 in
BuildResponse's shape now, the line with the content type. A
retransmitted MESSAGE — the same
Call-ID, CSeq and Via branch (the value of the first `branch=` of its
first Via line; a MESSAGE with none or an empty one is never taken for a
copy) within 32 s of our final, in the same run of the daemon — is
answered again and not handled again (the engine's RecentTransactions, a
table in memory), where a repeated RP-DATA would otherwise,
with SMS over IP on, be handled again: a second delivery report where
the first got one and, of a text in one segment, a second text.

The Messaging signals carry a text's content, and a D-Bus broadcast
reaches every account the bus policy lets receive from imsd — which
polkit cannot narrow — so they are never broadcast: Subscribe, behind the
same action as Send, records the caller's unique name, and Received and
StateChanged go unicast to each subscriber (the submission's sent or
failed also to the Send caller), which the bus delivers to those
connections — root's busctl monitor sees them as well. A subscription
ends with its connection; a consumer
subscribes at start and again when imsd's name reappears. GetStatus
answers `enabled` from the daemon's configuration, not from the
registration snapshot, so an asker before the first registration reads
the truth.

A message's id holds the run's token, eight hex digits drawn from
std::random_device at the daemon's start, ahead of a second and a
count: `ims-sms-<run>-<start>-<N>` for
a sent text, with the start second and a counter, and
`ims-sms-in-<run>-<epoch>-<N>` for a received one, with its second. A
counter starts over with the daemon, and the phone's wall clock reads
1970 until the first time sync, so a second repeats across runs: the
token is what tells one run's ids from another's, and a client keys by id
(RunToken, SentSmsId and ReceivedSmsId, pinned by tests/Engine).

Tested on the dev phone on KPN (2026-10-17; the fp6 journal's
2026-10-17-sms-over-ip-bench capture) on sms-branch builds ahead of this
history (195e91b, then c57765a with the retransmission absorption): the
tag on a resumed and on a fresh registration, Sends to 202 and their
submit reports in one and two segments and in UCS-2, texts received in
one and two segments and in UCS-2, every delivery report answered 202
but one of the two for the 01:23 text, refused 488 on the build before
the absorption, and a same-second retransmission absorbed under c57765a
(01:44) — AGENTS.md §5 has the record and §13 the network facts,
among them that the modem was CS-detached that night. On the host's
session bus in dev mode:
two Sends answered with ids and failed "imsd is not registered"
(2026-10-16), and three connections — a subscriber, a match-rule-only
listener, an unsubscribed sender — where only the subscriber and the
sender heard the StateChanged and the subscription ended with its
connection (2026-10-17); with the knob off, GetStatus's `enabled` false,
Send refused NotSupported and Subscribe answered (a private session bus,
this commit's host build, 2026-11-19; its sha256 begins 98e30a9522409d99).
The SMSC= override ran on 2026-10-18 from 02:17
(smsc-override-2026-10-18-0217):
the EF_SMSP number as an override and a Send through it to sent, and
SMSC=abc stopped at bring-up with "is not a number" (ForNumber dials
digits, * and # only; the bench's first run, on a build outside this
history that dialled the BCD table's a, b and c, submitted with them and
got an RP-ERROR back, RP cause 28).

A status report is matched to the message that asked for one by its TP-MR
and the recipient's number — among this run's messages: the book is in
memory — and the message gets a word for the whole (StatusReportBook,
pinned), by TS 23.040 9.2.3.15's classes of TP-ST: delivery-failed at the
first report in which the SC is not making any more transfer attempts (a
permanent error or a temporary one; a reserved value too, read as
"Service Rejected" as the clause has the MS read it), delivered when the
last of its segments is reported in the completed class (the SC's word
in the reason) — never a later segment's word over an earlier failure.
The next TP-MR is kept in
<state dir>/sms-tpmr across restarts, so the TP-MRs continue instead of
starting over at random: a reuse needs a full 256-segment wrap, not a
restart (a report can be days late) — as long as the file's last write
reached the disk: it is neither checked nor synced.

One message's StateChanged words come in the order they mean, which is
not the order imsd learns them: the service centre can deliver and report
on segment 1 while segment 2 is still on its way. SmsWordOrder
(Imsd:Engine, pure) gives the order §8.4 states: the submission's word
first — `sent`, or `failed`, after which nothing follows — and a
report's only after `sent`. A report's word on the message in flight is
held until the submission ends (the latest word; one message is in
flight at a time) and posted after `sent`. A submission that fails after
the centre reported every segment delivered posts `sent`, the failure in
its reason, and then `delivered`. A `failed` otherwise drops the held
word and StatusReportBook::ForgetMessage forgets the message's TP-MRs, so
a later report on a part that went matches nothing and is logged.
tests/Engine pins the book's forgetting and each of these orders.

BuildResponse (the messages commit) is the final of the inbound MESSAGE
path from here on — the 200, the 480 and the 488; BuildResponse200's hop-by-hop
shape stays for the other answers that had it.

The reassembler's 30-minute age-out is judged in the run loop beside the
SMS deadline, whether or not another MESSAGE ever comes.

The MESSAGE's target is the service centre's own international number
(ScPsi), not RuriFor's dialled-number guess, whose trunk-0 rule is
Dutch: a national SMSC= of nine or more characters starting with 0 would
have become a +31 number, a 00-prefixed one +<the rest>, any other
non-international value a phone-context URI at the home domain; a service
centre ScPsi makes nothing of (national, 00-prefixed, or a '*' or '#'
among the digits, which ForNumber dials) is refused at bring-up on that same
predicate with a journal line, never announced, and Send then fails
with no service centre.

A failed submission's StateChanged reason can hold the network's text (a
refused final's, RefusalSummary); a D-Bus string must be valid UTF-8, so
the emission makes it so (g_utf8_make_valid: bytes that are not become
U+FFFD, and a NUL byte ends the string).
2026-11-19 16:43:16 +01:00
.forgejo/workflows packaging, ci: build the apks with the Crafter.Build Flatpak 2026-10-06 14:01:33 +02:00
implementations imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00
interfaces imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00
packaging imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00
tests imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00
.gitignore imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00
AGENTS.md imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00
FUNDING.yml README, FUNDING.yml: Forgejo's funding file and the shared License / Funding / Copyright footer 2026-11-19 10:42:10 +01:00
LICENSE imsd 0.2.7 — initial public snapshot 2026-07-22 23:04:21 +02:00
project.cpp sms: the short message codecs of TS 23.038, 23.040 and 24.011, and EF_SMSP 2026-11-19 16:43:15 +01:00
README.md imsd, engine, ImsdBus, packaging, README: SMS over IP behind SMS_OVER_IMS=1, net.catcrafts.IMS1.Messaging 2026-11-19 16:43:16 +01:00

imsd

Userspace IMS/VoLTE daemon for mainline Linux phones.

Most Linux phones drive the modem's internal IMS engine. imsd implements the whole IMS client in userspace instead wired into PipeWire so a stock mobile dialer like Plasma Dialer or GNOME Calls under Phosh can place and receive real VoLTE calls on a commercial network.

Calls verified by community members to be fully working:

Device OS Carrier
The Fairphone (Gen. 6) Nura, Linux 7.1.2 KPN NL
The Fairphone (Gen. 6) Nura, Linux 7.1.2 Telekom Deutschland GER
The Fairphone (Gen. 6) Nura, Linux 7.1.2 Phonero
The Fairphone (Gen. 6) Nura, Linux 7.1.2 Telia Norge
The Fairphone (Gen. 6) Nura, Linux 7.2.0 o2-uk

What it needs

imsd talks to the modem through ModemManager plus qmicli over QRTR, installs its security associations with ip xfrm and plays audio through PipeWire, so in practice: a Qualcomm modem on a mainline kernel with working WWAN/ModemManager integration, kernel ESP, PipeWire, systemd and polkit.

Install and configure

For automatic updates add the Catcrafts Alpine repository. Note this does also pull in other packages.

Otherwise just download the latest imsd and imsd-systemd APKs and install them.

Both can be found in the packages tab:

https://forgejo.catcrafts.net/Catcrafts/-/packages/alpine/imsd

Dialers

imsd itself is desktop-agnostic: everything a dialer needs is on the system bus as net.catcrafts.IMS1. A small translation daemon per desktop speaks the backend protocol its dialer already consumes, so dialer, shell and the call-history/contacts stack run unmodified.

Desktop Daemon Package Owns Consumed by
Plasma Mobile imsd-dialerd imsd org.kde.telephony.* (session bus) plasma-dialer + kde-telephony-daemon, replacing modem-daemon
Phosh / GNOME Mobile imsd-ofonod imsd-ofono org.ofono (system bus) GNOME Calls' ofono provider plugin

Plasma Mobile needs nothing beyond the imsd package: imsd-dialerd is autostarted in the session in place of plasma-dialer's modem-daemon, whose own autostart must be off — the package hides it for accounts created after the install (/etc/skel); an existing account hides it itself with a Hidden=true copy of org.kde.modem.daemon.desktop in ~/.config/autostart.

For Phosh and GNOME Mobile, apk add imsd-ofono enables imsd-ofonod and points GNOME Calls at its ofono provider (a gschema override; the per-user equivalent is gsettings set org.gnome.Calls autoload-plugins "['ofono']"). Do not run it alongside a real ofonod.

Call control is polkit's net.catcrafts.IMS1.Voice: the active local session and root may place, answer and end calls; an ssh login may not.

SMS over IMS

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 centre or the one SMSC names, and receives texts the network delivers over IMS, and announces a received text on its net.catcrafts.IMS1.Messaging interface. Apps that read ModemManager, such as Spacebar and Chatty, do not see texts that arrive this way; an app gets them by subscribing on the Messaging interface. The details are in AGENTS.md: the behaviour in §7.9, the interface in §8.4, what was verified on which network in §5.

Full config:

Configuration is environment variables in /etc/imsd.env, none are required.

Variable Default Meaning
PCSCF (the first of PCSCF_DISCOVERED) P-CSCF address (IPv6), exactly one — not a comma-separated list — in RFC 5952 §4 form (lowercase, leading zeros dropped, the longest zero run compressed, no brackets — what ip prints for a plain IPv6 address; an IPv4-mapped address only as hex, ::ffff:a00:1 — the dotted spelling RFC 5952 §5 and ip use for it is refused); upper case, leading zeros, an uncompressed run or brackets are refused at start with the spelling to use (in the packaged unit the bring-up script refuses brackets first, with the rule), a dotted-quad tail with the rule; before 1.0.0 an upper-case, zero-padded or uncompressed PCSCF= matched no SA in ip xfrm's text and registered fresh at every restart — an upgraded phone with such a setting stops at start with the spelling to use. Set, it wins over PCSCF_DISCOVERED. It is where a fresh registration goes; a registration resumed from the kernel's SAs stays on the P-CSCF it was made to until its next fresh registration. With neither this nor PCSCF_DISCOVERED there is no fresh registration: a phone with nothing to resume idles (idle: no P-CSCF …), unless a resume failed with its pair still resumable, or the reader did not answer (PCSCF_DISCOVERY=failed): those exit non-zero for systemd's restart
PCSCF_DISCOVERED (from the PDN's PCO) the IPv6 P-CSCF list the network put in the ims PDN's PCO, comma-separated in the order the modem reports it; the first entry CanonicalIp6 accepts is used when PCSCF is unset. The packaged service gets it via /run/imsd.env from ims-pdn-up.sh, which reads it from the modem with imsd-pcscf (at most eight; it routes the first; imsd routes the P-CSCF it uses — the fresh target, the resumed SA peer — itself as well); entries CanonicalIp6 does not read — an IPv4 address, a name, an IPv6 literal with a zone or a dotted-quad tail (an IPv4-mapped entry in hex only) — are ignored (logged by the engine when the daemon goes on to register); `PCSCF_DISCOVERY=found
IMSD_PCSCF /usr/libexec/imsd-pcscf the P-CSCF reader ims-pdn-up.sh runs — a bench seam (the mock bench's fake reader; a stub through a unit drop-in on the dev phone), from the environment
PCSCF_PORT 5060 unprotected SIP port for the initial REGISTER
DEV qmapmux0.0 ims-PDN netdev; the packaged service passes the real one via /run/imsd.env
LOCAL (auto) UE address (compared in RFC 5952 form). The packaged service gets the PDN address ModemManager assigned, via /run/imsd.env from ims-pdn-up.sh; a manual run prefers a global IPv6 on DEV that is neither temporary nor dynamic (RA-derived), then any non-temporary one, then the first (the kernel's temporary SLAAC address is listed first, and a registration bound to it is lost when the kernel retires it)
USER_AGENT imsd/<version> REGISTER User-Agent. Some networks fingerprint UAs; setting your device's stock build string reproduces the stock modem's registration exactly. Empty omits the header
STATE_FILE /var/lib/imsd/imsreg.state (root) / $XDG_STATE_HOME/imsd/imsreg.state persisted registration context for warm resume
HOLDS_FILE /run/imsd.holds (root) / $XDG_RUNTIME_DIR/imsd.holds (/tmp/imsd.holds without a runtime dir) the waits the network imposed (a Retry-After, the refusal schedule), where that schedule stands whether the old registration is gone (old_gone) and the refusal count (refusals: a resume refused without a Retry-After at a start with no fresh target is one, the restart's the second), kept across a restart of imsd for the PDN they were set on — not across a reboot; /dev/null switches the file off (only a regular file is ever removed; anything else is emptied). imsd-handover.sh honours it too
RESUME auto 0 forces a fresh registration (ignores a warm SA) where there is a fresh target; with none the untried pair is removed and the bring-up ends as AGENTS §7.2 (the daemon's own bring-up) step 1 says
REFRESH_INTERVAL (auto) keepalive re-REGISTER period in s; default = half the granted expiry, clamped to [120, 1800]
EALG aes-cbc offered ESP cipher (aes-cbc, des-ede3-cbc, null). From the 401's Security-Server list imsd selects the highest-preference ipsec-3gpp mechanism that matches this offer (RFC 3329 §2.3.1) and takes the SPIs/ports from the entry carrying them (some cores list every mechanism they support and put the SPIs on the one they applied); when no entry matches, the P-CSCF's SPI-carrying entry is installed as listed (hmac-md5-96, an absent ealg = null) and the journal says so. The line, the selection and the SA parameters are logged at every fresh registration
SIP_TRANSPORT auto transport of the protected leg (the second REGISTER and everything after it): tcp, udp, or auto = TCP, falling back to a fresh registration over UDP when the P-CSCF leaves two TCP connects unanswered — but only on a phone that has never registered over TCP: once the state file records a TCP registration, a silent connect is treated as an outage, not a policy (delete the file or set udp to override, e.g. after a SIM change). The challenge (first REGISTER) is always UDP. Over UDP a REGISTER or INVITE larger than ~1.2 KB leaves as IPv6 fragments at the ims PDN's 1280-byte MTU (the journal says so once per flow); there are no SIP retransmission timers over UDP yet, so a lost datagram costs a timeout. The SAs, the listener and the firewall rule cover both transports
SMS_OVER_IMS 0 1 takes short messages over IMS (AGENTS.md §7.9): the REGISTER Contact advertises +g.3gpp.smsip and net.catcrafts.IMS1.Messaging.Send submits one; off, imsd does not advertise it and refuses Send (AGENTS.md §7.9 says how imsd answers a text the network sends anyway)
SMSC (EF_SMSP) the service centre a submission is addressed to, in international form (+31653131313; spaces, dashes and dots dropped; a national or 00-prefixed number, or a * or # in it, is refused at bring-up); unset, imsd reads the (U)SIM's EF_SMSP record 1. Without either, Send fails with the reason
EMERGENCY_NUMBERS (empty) comma-separated additions to the builtin 112/911 emergency numbers (e.g. a private test core's short code). SIM EF_ECC is not read yet. imsd-ofonod reads it too, for the oFono EmergencyNumbers property
RTP_PORT 50004 local RTP port advertised in SDP
PRECOND 0 1 offers SDP QoS preconditions
CODECS (empty — defaults) comma-separated codec preference list over AMR-WB, AMR (or AMR-NB), PCMA, PCMU: restricts and orders both the codecs offered on an outgoing call and those accepted from an inbound offer (default: offer AMR-WB + AMR, accept all four in that order). A bench knob — a network whose gateway transcodes every caller up to AMR-WB otherwise never lets the narrowband path run
DUMP_SIP 0 1 writes raw REGISTER-200/SUBSCRIBE-200 dumps, the last refused REGISTER or SUBSCRIBE final (imsd-register-fail.raw, imsd-subscribe-fail.raw), the last incoming call's INVITE (imsd-invite-in.raw), the last outgoing INVITE (imsd-invite-out.raw), the last inbound MESSAGE outside a call's dialog (imsd-message-in.raw) and the last MESSAGE a submission started with (imsd-message-out.raw), mode 0600, for debugging — they contain your IMSI/MSISDN and addresses, and the two MESSAGE dumps the text of a short message. A refused REGISTER or SUBSCRIBE is logged with its status line and any Retry-After / Warning / Reason / Server headers
DUMP_DIR, OUT_DIR state dir where dumps / per-call media stats land
IMSD_MEDIA (auto) path to imsd-media (default: next to imsd, else /usr/libexec/imsd-media)
IMSD_ENV /etc/imsd.env the configuration file's path — a bench seam for manual runs of ims-pdn-up.sh (the packaged unit reads /etc/imsd.env through EnvironmentFile=). The file's existence changes nothing

The protected client/server ports are fixed at 45061/45062 (imsd::util::PortUc/PortUs) — changing them in source also requires updating the firewall rules ims-pdn-up.sh installs.

imsd-media (per-call, set through imsd's environment)

Variable Default Meaning
MIC, PLAY 1, 1 uplink mic capture / downlink playout via PipeWire, as imsd passes them (imsd-media started by hand defaults both to off)
AUDIO_USER (auto) account whose PipeWire session carries call audio; imsd sets it per call from logind's seat0 session. Set in imsd's own environment it pins an account instead
GAIN, PLAY_GAIN 10, 1.0 uplink / downlink gain, as imsd passes them (imsd-media started by hand defaults GAIN to 1.0)
AMR_MODE 2 AMR encoder mode of whichever AMR codec is active, as imsd passes it (12.65 kbit/s for AMR-WB; imsd-media started by hand defaults to 2 for AMR-WB and 7 for AMR)
DTX 0 encoder discontinuous transmission
MEDIA_TIMEOUT 6.0 seconds of downlink silence before exit 3 (far-end-hangup signal)
RTP_DUMP 0 1 captures raw downlink RTP next to the stats file

D-Bus ABI

net.catcrafts.IMS1 at /net/catcrafts/IMS1. The ABI is frozen.

Member Signature
Dial(number) s → s (callUni)
HangUp(callUni) s
Accept(callUni) s
SendDtmf(callUni, tones) ss
GetCalls() → aa{sv}
GetStatus() → a{sv}
CallAdded s a{sv}
CallStateChanged s s s (callUni, state, reason)
CallDeleted s
RegistrationChanged b

Both imsd-dialerd and imsd-ofonod are users of this ABI. A new desktop needs a new translation daemon, not changes here.

net.catcrafts.IMS1.Messaging (since 1.2.0)

A second interface on the same object, for short messages over IMS (SMS_OVER_IMS=1). Additive: the interface above is unchanged. Frozen as of 1.2.0: what the table lists stays as it is, and a dictionary imsd gives may gain a key.

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
GetStatus() → a{sv}: enabled (b), smsc (s), 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
Received s a{sv} (id, message: from, text, timestamp (the SC's, as 2026-10-16T22:50:00+02:00), received (x), sc, 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

Send and Subscribe are gated by polkit's net.catcrafts.IMS1.Messaging.

License

GPL-3.0-only - see LICENSE.

Funding

https://catcrafts.net/shop/donation - see FUNDING

Copyright (C) 2026 Catcrafts® catcrafts.net