Commit graph

126 commits

Author SHA1 Message Date
6d05aaed0d
imsd: a server port's answer finds its connection or socket when it is sent
A request that came in on a server port (the protected ports' TCP
listeners and UDP sockets) was answered through a closure that kept a
descriptor's number: its connection's over TCP, a socket's over UDP.
The daemon closes a connection's descriptor when the peer has ended
the connection, and the kernel gives a closed descriptor's number out
again. A call's later answers go through the closure of the call's
latest request when the user answers or refuses or the ringing ends
(the 200 of an Accept, a 486, a 480): they were written to that
number, whatever had it by then, the connection of whoever had
connected since among them.

A closure now keeps the port its request came in on and the peer it
came from, or which of the two UDP ports its answer leaves by. Over
TCP an answer is written to the newest connection the daemon holds
from that peer to that port, and is not sent where it holds none: the
journal says so once in a run. Over UDP it leaves from the socket its
port has at that moment, if it has one.

Tested: the daemon of this commit on the workstation against a
stand-in network that closes the connection its INVITE came on while
the call rings and then connects from another host, from another
port, from the same port to the daemon's other port or from the same
port to the same one, and one that resets the connection right behind
its INVITE and makes it again (the fp6 journal's
2026-12-04-pani-in-dialog capture, bench/); and on the dev phone on
KPN, where it answered a call that came in and the two requests that a
text to the phone's own number brings (the journal's
2026-12-04-imsd-1.2.7-range-on-dev-phone capture).
2026-12-04 23:20:38 +01:00
1eee41f0ed
imsd 1.2.6
All checks were successful
package / package (push) Successful in 2m14s
v1.2.6
2026-12-01 15:51:21 +01:00
0026213073
sip, engine: the retry of an INVITE refused 422
imsd asks for a session interval of 1800 s in a call's first INVITE. A
422 (Session Interval Too Small) is a server's answer to an interval
below its minimum and carries that minimum in a Min-SE (RFC 4028 6);
TS 24.229 5.1.2A.1.1 has a UE that supports RFC 4028 retry an INVITE so
refused in accordance with RFC 4028 7.4. imsd announces "timer" and
took a 422 for any other refusal: on a reporter's phone on AT&T's
network each of the five calls of one boot ended "INVITE final 422"
(AGENTS.md §13).

The call machine now sends the INVITE again in the same call: a new
transaction under the Call-ID, with the next sequence number, the 422's
Min-SE and a session interval no smaller. AGENTS.md §7.6 has when it
does not, and what becomes of an answer to an INVITE it has replaced.

Tested: the suites, and the daemon of this commit on the workstation
against a stand-in network that answers 422 (the fp6 journal's
2026-12-01-min-se-retry capture, bench/).
2026-12-01 15:51:21 +01:00
3d702ec1f1
messages, engine: the INVITE's sequence number, session interval and Min-SE are the dialog's
BuildInvite wrote "CSeq: 1 INVITE", "Session-Expires:
1800;refresher=uac" and "Min-SE: 90" as fixed text, and the INVITE's
CANCEL, its two ACKs and a PRACK's RAck wrote the 1 again. The three
values are fields of the Dialog now, with those defaults, and nothing
in the daemon sets them otherwise yet: every message it sends is byte
for byte what it was.

Tested: the suites (tests/Messages has an INVITE, its CANCEL and its
ACKs for a dialog with other values).
2026-12-01 15:51:21 +01:00
e3b94a8415
AGENTS.md, imsd: an ISIM's identity has registered on a network
AGENTS.md §5 said that this daemon had sent no network a REGISTER with
names it read from an ISIM and no real ISIM an AUTHENTICATE, §13 that it
had not sent the US card's network the card's own names, and a comment
of the shell that no AKA in a real ISIM had run on this code. A
reporter's journal of 2026-11-25 has imsd read that card's ISIM and
register under its names on AT&T's network, without the line an
application that gives no result for the challenge leaves (imsd 1.2.4 by
the reporter's word; the fp6 journal's 2026-12-01-min-se-retry capture,
evidence/). §13 has what the journal shows.
2026-12-01 14:22:05 +01:00
640d261248
imsd 1.2.5
All checks were successful
package / package (push) Successful in 1m57s
v1.2.5
2026-11-29 14:30:43 +01:00
3b9c0fed98
imsd, engine: the registration through a sleep
The refresh of the registration was due after so many awake seconds: its
gate ran on the steady clock, which stands still in a suspend, while the
network counts the registration's lifetime on. A phone that slept most
of two hours sent no refresh and lost its registration (the dev phone,
KPN, 1.1.0, 2026-11-19: registered 09:15:48 for 7200 s, the network's
NOTIFY of the expiry at 11:16:37, registered again 11:37:38 behind the
fresh-SA throttle). Until now the image imsd was written on did not let
its phone suspend.

The refresh's gate and the renewal of the reg-event subscription ahead
of its granted lifetime's end now run on the boot clock, as the recovery
policy's waits already did. And a timer on CLOCK_BOOTTIME_ALARM, which
the kernel turns into the RTC's alarm for a suspend, is armed at the end
of every turn of the loop that takes no command off the queue (one that
takes a command handles it and goes straight to the next turn) for the
time the new WakeAt names (Imsd:Engine): now while a call or a text is
in flight (the hold below); else, with a registration on a live flow,
the refresh's due time, or the subscription's renewal where that comes
first; with a dead flow under a registration the recovery policy's word;
none where nothing waits to be done. The timer is never read: the waking
is the whole of it, and the loop's own clock checks act once the phone
is awake. A resume by itself sends nothing. Where the kernel gives no
such timer (it takes CAP_WAKE_ALARM) or has no RTC behind it, the
journal says so once.

What imsd waits for with the phone awake must not be cut off by a
suspend either. Beside the call's lock the main thread asks for a second
block inhibitor, in the way it asks for the call's, while a step of the
registration exchanges with the network (the refresh, a reconnect, a
fresh registration, the bring-up) and while a text is being sent, whose
waits (128 s for a MESSAGE's final, 130 s for the report) count awake
seconds; not while a bring-up waits out a hold the network set, which
can be an hour. A step can begin before the bus connection is there: its
lock, like a call's, is asked for when the connection comes. For a
suspend that begins all the same (logind refused such a lock where a
suspend's operation was already running; a request can tell it to ignore
inhibitors) there is the alarm: under a call and under a text in flight,
and where a step is due that the next turn runs (but for the look after
a local wait, which has its own slower time), it is set 1.9 s ahead at
every such turn, and the kernel refuses a suspend under an alarm less
than two seconds ahead (alarmtimer_suspend, read at v7.3) where the
suspend comes to that check before the alarm has fired: it syncs and
freezes the processes first. A registration step keeps it at most 30 s
ahead while it waits for the network, whatever else is in flight, so
that a sleep that begins under the step ends there. The alarm fires
once, and a wait can outlast the sleep it ended: it is set anew before
every second of such a wait (a connect's answer, the pause before the
next try, a REGISTER's answer). One of those waits is a receive with a
timeout (the fresh registration's first answer, on a socket of its own),
which the kernel ends with EINTR when a suspend freezes the thread: it
is taken up again for the rest of its time. The connect for a call's
resend is no step and sets the 1.9 s anew the same way, before every
second. A wait for a helper program keeps the alarm that stood when it
began.

A coverage gap must not cost the phone its sleep. The recovery tried a
reconnect 5 s after each one that failed, over TCP 34 s of waiting for
an answer that cannot come: with a lock around the step and an alarm for
the next, a phone in a cellar would have been held awake 34 s of every
39. While the modem reports no packet service the recovery tries nothing
now and takes no lock, and a dead flow's socket that is still open then
is closed without the FIN's exchange (Abort): over TCP, left open it is
readable at every turn of the loop, which would spin instead of waiting,
and a FIN sent into the gap would hold the address pair against the
reconnect after it, as the FIN of a step that closed its flow after an
unanswered wait does. A Dial that finds the flow dead in a gap ends at
once: the recovery's one immediate try for it tries nothing either, and
the INVITE fails on a flow that is gone. Awake and with no call up, the
modem is asked again every 5 s, the pause that was between two
reconnects. A sleeping phone is woken for the next look after as long
again as the modem has been without service, 10 s at the least and 15
min at the most (RegRecovery::WakeTime), counted from the modem's first
word of no service since the network last answered: the modem's word for
its service starts no count over, and where it alternates at the edge of
coverage an attempt made on it costs its wait under the lock while the
looks keep their pace. Every step that follows no local wait is woken
for at the policy's own time: a reconnect cycle the network was silent
to is no local wait where the modem has service, a fresh attempt it was
silent to never is. The kernel refuses a connect locally for as long as
the old flow's socket holds the address pair, which clears in awake
seconds. That is the other local wait: awake and with no call up, the
next look comes 5 s after each; a sleeping phone is woken for it after
as long again as the kernel's refusals have lasted, 10 s at the least
and 15 min at the most, counted from its first refusal since the modem's
last word of no service or the network's last answer, whichever came
later.

Left as they were, among others: the CRLF keepalive, the reg-event
subscription's Timer F, its retries and its renewal after the network
has ended it, the times SMS over IP measures (its two waits, the
30-minute age-out, its tables) and a step's own waits for the network
count awake seconds. Nothing holds a sleep off under the bring-up
script, which runs before the daemon, nor in the wait before a restart
after a failure: a phone suspended there does not register until it is
awake again. And between the alarm's waking the phone and the step it
woke it for, the loop's next turn, there is neither alarm nor lock; nor
is the alarm set again yet, for up to a second, after it has ended a
sleep under a step's wait (where the freeze has ended the receive of the
fresh registration's first wait with time left, it is set at once), and
a helper program the step goes on to in that second has none until the
step's next wait for the network.

Tested: the suites (WakeAt and the policy's wake after a local wait are
pinned in tests/Engine; the rest is the shell's). On the workstation
(the fp6 journal's 2026-11-25-through-sleep capture,
bench/bench-sleep.sh) the sleep is a preloaded clock_gettime under which
the boot clock runs ahead of the steady clock: with it 50 s ahead a
refresh set for 60 s went out 20 s into the registration, and 1.2.4's
did not; with it 599500 s ahead the subscription was renewed, and
1.2.4's was not; with no jump the refresh came at its awake time and not
before. The second lock was taken and released around a refresh, asked
for again at the stand-in logind's PrepareForSleep(false) where that had
refused it at a refresh's start, and held for the 256 s from a text's
sending to its "failed" where the stand-in network answered no MESSAGE.
In a gap of 40 s (the stand-in modem without packet service, no SYN let
through, the flow closed by the network) no connect was tried and no
lock taken, the daemon's own processor time stayed under a second (an
earlier build of this change, which kept the dead flow's socket through
the gap, used 33.9 s of it), and the reconnect came 3 to 5 s after the
gap's end; a Dial inside such a gap ended at once with nothing reopened
under it, the reconnect then 0.5 to 1.5 s after the gap's end; and in a
gap that let no segment through the daemon had no socket of the old flow
at the gap's end; a daemon started inside a hold of 60 s held no lock
for it. With WAKE_TRACE=1, a test seam, the daemon writes a line
whenever the time the alarm is armed for changes (by the second; one
line for a run of times less than two seconds ahead), with a timer or
without: in a gap that a refresh ran into, with the boot clock put 1000
s ahead inside it, the alarm named 900 s ahead; after the gap's end,
where the old flow's socket had two connects refused, it named no more
than 30 s ahead, and the reconnect came 15 to 16 s after the gap's end;
where the stand-in modem reported service twice inside such a gap, the
alarm named 900 s ahead again after each; where the modem still reported
service when the refresh failed, where the network stayed silent for 80
s after the modem's return, and over UDP, it named no more than 30 s
ahead from the modem's return to the recovery; while a step waited for
the network (a refresh's 12 s, a connect's 12 s and the 10 s before the
next try, a fresh registration's two waits with the stand-in holding its
answers back) it named a new time every second, and through the connect
for a call's resend, which the stand-in answered at once, no time 2 s or
more ahead. Stopped 1.5 s into a fresh registration's wait for its first
401 and continued 2 s later (a stop and a continue end a datagram
receive under a timeout as a freeze does), the daemon registered when
the stand-in's held-back 401 came, five runs of five; an earlier build
of this change and 1.2.4 gave the wait up at the continue, five of five
each. The bench's namespace gives no CAP_WAKE_ALARM: every life of this
daemon there says "no wake alarm (Operation not permitted)" and runs on.
The alarm is the dev phone's (KPN, a 7.3 kernel, this commit's daemon
built with the next commit's version string, the capture's phone/,
2026-11-28), with REFRESH_INTERVAL=120 and deep suspends asked of
logind: every refresh that fell due under a sleep went out within 3 s of
its due time, after a resume whose first interrupt was the RTC's alarm
(1.2.4, in three sleeps of that script as it was on 2026-11-25, on the
same kernel build, sent no refresh in seven minutes); under a call a
suspend told to ignore inhibitors was refused by the kernel (alarmtimer,
-16), twice, systemd-sleep having tried its second state; under a text
in flight logind refused a suspend and the kernel a forced one; and
under a refresh whose REGISTER the phone itself dropped, a forced
suspend a second into the wait was ended by imsd's alarm (the RTC's the
first interrupt, 30.6 s in), after which imsd's timer, zero at the
test's first look, read 29 to 30 s ahead at each of its 32 looks from
0.2 s later to the wait's end, which the test saw about 10 s after that
first look (an earlier build of this change, which set the alarm once
for the wait, read zero at every reading until the wait had ended; in
another run, with two more forced suspends in that wait, it slept to the
test's own alarm of 75 s both times). The re-registration after that
refresh came 71 s after its "no reply", the kernel refusing nine
connects over a minute first (the old flow's socket). Seven recovery
steps that fell due under a sleep ran 1.5 to 3 s after their time (an
earlier build, 2026-11-25). A test program's datagram receive under a
timeout returned EINTR at the phone's resume from a suspend
(evidence/recv-eintr/ there). Not run: a suspend under a fresh
registration's first wait with the daemon on a phone; an alarm clock
with no RTC behind it ("no RTC that can wake the phone"), and a
timerfd_settime that fails ("wake alarm not set"); the alarm's disarming
and "wake trace: none", which nothing reaches once the loop runs; a
second forced suspend under one wait with this commit's daemon on a
phone (the dev phone is not to be suspended within ten seconds of a
resume: the earlier build's run with three did so, and its wifi firmware
crashed; and the wait the test stages, an unanswered refresh's 12 s, is
over at about that time); the 1.9 s through a connect for a call's
resend that waits; a fresh registration's look at the modem finding no
packet service (the reconnect's has run); a bring-up the network defers
or refuses, and a stop during a bring-up's hold; the work's lock asked
for at the bus connection's coming (no record tells that request from
the step's own); a coverage gap on a phone, and the wake for its slower
look; on a phone, a sleep longer than a refresh interval of 1800 s; the
alarm at most 30 s ahead through a step's wait while a text is in
flight, which is read from the code; the subscription's renewal on a
network.
2026-11-29 14:30:43 +01:00
52d4b4f217
imsd: logind's block inhibitor for sleep while a call is in the calls table
Nothing of imsd runs while the phone is suspended: a suspend under a
call stops the daemon and the call's media leg for as long as the phone
sleeps. On the dev phone (Plasma Mobile, the sleep targets unmasked for
the test, a call placed on the bus) logind listed one block inhibitor
for sleep under a call, imsd's, and PowerDevil's policy agent none of
its own.

While the calls table holds a call the main thread holds logind's block
inhibitor for sleep (Inhibit with "sleep", "imsd", "a call", "block"):
from the call's addition to the table, which is an incoming call's
announcement and for a Dial follows the recovery's try on a dead flow
and the refresh of the P-Access-Network-Info, to its removal. Under it
logind refused a plain "systemctl suspend" on the dev phone (below); a
request can tell logind to ignore inhibitors (systemctl suspend -i). The
engine starts before the bus connection is there: a lock wanted by then
is asked for when the connection comes.

On the dev phone (systemd 262.2) logind answered Inhibit for this lock
OperationInProgress in a sleep hook before a suspend, in one after it,
and to imsd 0.1 to 0.3 s after the resume, and gave it once it had
logged the operation's "finished". So a lock that was not given and is
still wanted is asked for again when logind sends PrepareForSleep with
false. Where logind gives none at all (the session bus of --session has
no logind) calls go on without one, and the journal says so once until a
call's lock is next given.

Tested: the suites (none reaches the change, which is the main
thread's). On the workstation the daemon of this commit and 1.2.4's ran
with a stand-in logind that prints every Inhibit and every lock's
release and refuses every Inhibit, with logind's OperationInProgress
error, while a file says a sleep's operation runs (the fp6 journal's
2026-11-25-through-sleep capture, bench/bench-sleep.sh): one lock per
call, taken within 1.5 s of the Dial and released within 1.5 s after the
call's end, for a call answered and hung up, a call the network refused
and two calls in a row; a call placed while the stand-in refused had its
lock within 0.5 s of the stand-in's PrepareForSleep(false); with no
logind on the bus the call ran as with one; 1.2.4 asked for no lock. On
the dev phone (KPN, the daemon of this commit, the sleep targets
unmasked for the test; the capture's phone/), under a call to the
carrier's voicemail: the lock in systemd-inhibit's list, "systemctl
suspend" answered "Operation denied due to active block inhibitor" and
no suspend counted, the lock gone after the hang-up; and for a call
placed from a sleep hook at a resume, with logind's operation still
running: the refusal's line, and the lock when logind had said the sleep
was over. Not run: a suspend under a call without the lock; an incoming
call that wakes a sleeping phone; a call announced before the bus
connection is there; a request at a second row's addition or removal (a
Dial refused under a call that has no lock); a second refusal before a
lock is given, which prints no line; an answer of logind's without a
descriptor; a PrepareForSleep whose argument is not one boolean; the
lock wanted where it is held, which asks nothing (a suspend told to
ignore inhibitors under it; a Dial refused under a call that has it); a
desktop's own request for a suspend under the lock.
2026-11-29 14:30:43 +01:00
83a9eb539d
imsd: a re-REGISTER that was sent has used its CSeq, answered or not
A re-REGISTER on the registration's Call-ID (the refresh, a reconnect's,
a resume's) was given the number after the last one that was answered
200: the number was recorded when the 200 came, and only then. So the
REGISTER after one that got no answer, or a refusal, carried that one's
number again. RFC 3261 10.2 has a UA increment the CSeq by one for each
REGISTER with the same Call-ID, and a registrar that took the unanswered
one, its answer lost on the way, has no use for the number a second time
(10.3 step 7: it aborts the update unless the CSeq is higher than the
one it stored).

On the dev phone (KPN, 2026-11-25, a test build with 1.2.4's code at
this place; the fp6 journal's 2026-11-25-refresh-answer-lost capture) a
refresh got no reply: the phone's firewall dropped the network's packets
for 20 s in a test. The reconnect's re-REGISTER, 10 s after the refresh
had failed, was refused "482 Loop Detected", and so was the next one
that reached the network, 66 s later. The recovery then began a fresh
registration and deferred it at a Security-Server with spi-s=0
("fresh-SA throttle active"); the next two re-REGISTERs that reached the
network were answered "480 Temporarily Unavailable" with a Retry-After
of 180, and the phone registered again 25 min 55 s after the refresh had
failed. The journal does not print the number of a REGISTER that fails:
that the two refused with 482 carried the unanswered one's is read from
the code.

The number is now used once the REGISTER is sent (Engine::Reregister,
which all three callers go through), and the state file has it then,
before the answer is waited for: a daemon that dies between a REGISTER
and its answer resumes with the next number, where the file's old one
sent the resume into the same refusal. That write is the one the callers
make after the 200, less the 200's own news. In a resume the file then
also has what the resume made up, which is what the next resume would
make up again. A REGISTER the kernel did not take (the send failed) uses
no number; a refused one's is used like an unanswered one's.

Tested on the workstation: the suites (none of them reaches the change,
which is the shell's), and the daemon of this commit and 1.2.4's against
a stand-in network that keeps the highest CSeq of the protected
REGISTERs it has taken per Call-ID, answers a protected REGISTER that is
not higher 482, and can take one refresh without answering it or refuse
one (the capture's bench/bench-cseq.sh). After a refresh whose answer is
lost this daemon's reconnect sends the next number on the same Call-ID,
is answered 200 and refreshes on; 1.2.4's sends the lost one's number
twice, is refused 482 twice and registers fresh. Killed under the wait
and started again, this daemon resumes with the next number; 1.2.4's
resume is refused 482 and it registers fresh. With either of the
change's two lines taken out the bench says so: without the count both
scenarios fail as 1.2.4 does, without the write the restart's does.
After a refresh the stand-in refuses (503) this daemon's reconnect sends
the next number, and 1.2.4's the refused one's again; the stand-in keeps
no number for a REGISTER it refuses and answers both 200. The stand-in
accepts the fresh registration at once, which KPN did not. And on the
dev phone (KPN, the daemon of this commit; the fp6 journal's
2026-11-25-through-sleep capture, phone/cseqtest-2-a and setup.log),
with the firewall's rule for ESP taken out and the connection tracker's
generic timeout at 0 around a refresh, so that its answer was dropped:
the refresh failed with no reply, the reconnect was answered 200 10 s
later, and the next start resumed from the reconnect's number, one above
the lost one's (that start was of a build with the next commit's change
on this one, in the form it then had, which touches none of this; an
earlier build of this change, with the next two commits' work in
progress on it, in the first capture's phone/, had the next refresh
answered with the number after that). Not run: the number after a
re-REGISTER whose send failed; a re-REGISTER's answer lost over UDP; a
restart after a daemon was told to stop (SIGTERM) under the wait, where
the bench kills it; a resume whose REGISTER gets no answer; a state file
torn by a kill during its write; and what a network makes of a number
that skips one, as a REGISTER that was sent and never arrived leaves it
(the stand-in took one; no phone run tells whether its network saw one).
2026-11-29 14:30:43 +01:00
d48c1017da
imsd 1.2.4
All checks were successful
package / package (push) Successful in 1m56s
v1.2.4
2026-11-25 11:50:16 +01:00
c93df591f1
imsd: no CRLF keepalive on the idle flow unless CRLF_KEEPALIVE names an interval
imsd sent a double CRLF, the ping of RFC 5626 4.4.1, on its idle TCP
flow to the P-CSCF every 30 seconds. On a phone that costs far more
than four bytes. The modem brings the ims bearer up for it; 11 to 13 s
later the bearer goes dormant, which the modem reports to
ModemManager, and 90 s after that the modem makes a file-system
request to rmtfs. Each of the two can wake a phone that has gone back to
sleep: in a loop of suspends on the dev phone (KPN, 2026-11-20, the
fp6 journal's 2026-11-20-modem-echo-wakes capture) the modem ended 29
sleeps of 29, 15 with the report and 14 with that request, and none
reached its 150-second alarm; with imsd held still all six did. Awake
and idle on a USB port the phone's battery lost 140 mA with the ping
and 59 mA without it (2026-11-24, one window of 40 min and one of 33).

No registration of imsd's negotiates keep-alives: its REGISTER has no
"outbound" in Supported and no reg-id (RFC 5626 4.2.1), and no "keep"
in the Via (RFC 6223).

The ping is now sent only where CRLF_KEEPALIVE=<whole seconds> names
an interval. An empty value is as none; any other that is no whole
number of seconds is reported in the journal and sends none
(imsd::util::WholeSeconds).

What a ping does for a flow, outside a call: sent more often than a
P-CSCF's timer for a flow it hears nothing on, it keeps that P-CSCF from
dropping the flow, and it draws the reset of a P-CSCF that has lost the
flow. The setting is for such a network. On the phone the ping also kept
the connection tracker's entry for the P-CSCF's ESP, without which the
firewall dropped what the network started; the commit before this one
gives the firewall a rule for ESP instead. Without the ping, a close by
the network is answered, outside a call, with a reconnect and a
re-REGISTER. A flow the network has dropped without closing, where it
answers the next bytes on it with a reset, is found at those bytes:
where they are the refresh's, it fails once and the same reconnect
follows; where they are a call's INVITE, the flow is reopened for the
call; where they are a call's BYE, the BYE is lost: imsd sends no BYE
again, as before. Where they are a text's MESSAGE, it is lost with the
flow and the text's wait decides. An incoming call sends no request on
the flow before its BYE, and without the ping the flow can have been
silent, or dropped without a close, since long before such a call came
(AGENTS.md §7.6). A flow that died with no close and no reset reaching
the phone is noticed when the refresh's re-REGISTER gets no answer, or
sooner where TCP gives up on bytes imsd sent on it before that (924.6 s
or more after them by the kernel's default tcp_retries2), and until
1.2.3 a ping's were among those every 30 s outside a call; a bearer that
left under a registered daemon was noticed at the refresh under the ping
as well (2026-10-02, AGENTS.md §7.2).

Tested: the suites, WholeSeconds in tests/Util; the daemon of this
commit and 1.2.3's on the workstation against a stand-in network that
prints every ping and can close a silent flow or forget it (the fp6
journal's 2026-11-24-crlf-keepalive capture, bench-keepalive.sh: no ping
by default, with CRLF_KEEPALIVE=0 or with an empty value, 1.2.3's three
in 100 s, the setting's, none over UDP, a value that is no number, the
reconnect at each close, the failed refresh and the reconnect on a
forgotten flow, neither a close nor a forgotten flow under the setting
or under 1.2.3's pings, a ping of 1.2.3's reset on a forgotten flow; and
bench-hangup.sh of the 2026-11-24-bye-resend capture: a placed call's
BYE not delivered where the network had forgotten or closed the flow
under the call, by this daemon as by 1.2.3's on the forgetting one). On
the dev phone on KPN, the binary of the range's tip: no packet on the
ims netdev in two idle minutes where 1.2.3 put one each way every 30 s,
the setting's start line and its pings, the line for a value that is no
number. And there, with builds of this change from before the commit of
the call's resend was put under it: the refresh after 1800 awake seconds
answered on the flow, silent until then, twice; and two loops of
suspends with no packet on the netdev, of six sleeps, none ended by the
modem, and of seven, one ended by it, for a file-system request no
packet had preceded (with the pings and the same ModemManager the modem
ended 5 of 8 on 2026-11-20). No network that closes or forgets an idle
flow has been met.
2026-11-25 11:50:16 +01:00
bc0e70a17f
ims-pdn-up: the firewall accepts the ims PDN's ESP itself, not only as an answer to a packet of the phone's
A request the network starts (a call to the phone, a text, a NOTIFY)
reaches the phone as an ESP packet on the ims netdev. That packet passes
the firewall's input chain before the kernel decapsulates it, and what
it carried passes the chain again afterwards. The script opened the
chain for the second, imsd's two protected ports. For the first there
was no rule, and pmOS's chain then lets an ESP packet in only as an
answer to one the phone sent ("ct state established"): the connection
tracker has no tracker for ESP, and its generic one keeps the entry for
nf_conntrack_generic_timeout seconds after the last packet either way,
600 on the dev phone. A request the network starts later than that after
the phone's last ESP packet is dropped, and its retransmissions until
the phone next sends to that P-CSCF; imsd sees nothing of it.

What keeps the entry is the CRLF keepalive every 30 s, which goes out
over TCP and outside a call only.

The script now inserts a rule that accepts ESP on qmapmux*, under the
comment imsd-esp and with a check of its own, so that a ruleset which
carries the port rules already (fp6-img's 01_imsd.nft) gets it too. The
kernel drops an ESP packet no SA matches, and what an SA decapsulates
passes the chain again, under the rules a packet on qmapmux* meets
without ESP. Like the port rules the script inserts, the rule is in the
running ruleset only: a reload of the ruleset from its files removes it
until imsd next starts, so a ruleset whose files carry the port rules
has to carry this rule in them as well.

Tested: the script's firewall block by itself on the workstation against
nftables, in two network namespaces with an ESP SA pair between them and
the dev phone's ruleset as read from it (the fp6 journal's
2026-11-24-incoming-dropped-without-ping capture, bench-esp-rule.sh),
the tracker's timeout at 8 s: with 1.2.3's block a connection opened to
port 45062 from the network's side 11 s after the phone's last packet
got no answer, its ESP packets new to the tracker and none through the
chain; with this block the rule was inserted once and the same
connection accepted; an ESP packet with an SPI no SA has dropped by the
kernel behind the chain; a connection through the SA to another port
dropped by the chain; ESP on another interface and an AH packet not
accepted, ESP over IPv4 and ESP on a second qmapmux interface accepted;
the rule gone and the connection unanswered again after the ruleset was
loaded again from its file, and kept where the file carries the rule;
all three rules inserted on a ruleset without imsd's, and connections to
both ports accepted through them; nothing done where there is no inet
filter table. Eleven faults put into the block one at a time, ten in its
rule for ESP, that rule's check and its journal lines and one in a port
rule, were each caught by a step. On the dev phone on KPN the script
inserted the rule at imsd's start, above the port rules it found, and
the daemon resumed its registration; and with the tracker's timeout at 0
for the test, so that every ESP packet from the network came without an
entry, a text sent to the phone's own number was answered, reported and
delivered within a second with the rule (six such packets), and none of
the three reached the daemon in 20 s with the rule taken out (23 such
packets). Not met: a request the network starts after the entry has
lapsed of itself, 600 s after the phone's last ESP packet (a call to the
phone from another line).
2026-11-25 11:30:30 +01:00
0aea0dac7f
imsd: when the client flow is found dead before any response to a call's INVITE, one reconnect and the INVITE again, else the call ends
A flow that is dead in a way imsd has not seen yet, the peer having
dropped the connection's state, shows itself at the next bytes sent on
it, where the peer answers them with a reset. Where those bytes were an
outgoing call's INVITE, imsd read the reset, marked the flow dead and
did nothing more for the call: no reconnect runs while a call is up, so
the attempt stayed in `dialing` until its setup deadline, 90 s, sent a
CANCEL that could not go out and was given up 10 s later, where a call
that is no emergency call ends (`setup deadline expired`); the flow was
reconnected only once the call was gone. Against a stand-in network
that forgets a flow after 20 s of silence, 1.2.3's call ended 100 s
after the Dial.

The engine's loop now takes such a call up (MaybeResendInvite). When
the client flow is found dead under an outgoing attempt whose INVITE
has had no response, a 100 included, and no CANCEL, the dead socket is
closed without a FIN's exchange, the flow is reopened with one connect
and the same INVITE is sent again, the setup deadline running from
then. Once per attempt: an emergency call's fallback attempt has a
resend of its own. The INVITE is the first one byte for byte, its
branch included, so a server that did receive the first matches the
second to its transaction (RFC 3261 17.2.3). No REGISTER goes first:
the registration and its SAs stand, and TS 33.203 7.1 has a UE with no
TCP connection towards the P-CSCF set one up before it sends a request.
Where a reg-event NOTIFY has ended the binding nothing is reopened.
Where nothing is reopened, the connect fails (one that gets no answer,
after 12 s) or the flow dies again before a response, the call ends
with `error`, an emergency call's first attempt too: there is no flow
for its fallback. The recovery policy takes the flow up once the call
is gone, as before.

The close without a FIN's exchange is for a flow the peer closed:
closed the usual way, such a socket stays in the kernel's table until
the peer has acknowledged imsd's own FIN, and a connect from its port
before that is refused. A reset goes out in the FIN's place there;
after a reset or the kernel's own giving up the socket is closed
already and nothing is sent; and the reopen runs on a flow already
found dead only. The recovery's reconnect closes the usual way, as
before, and connects once more 10 s after such a refusal (one is in a
user's log on O2, 2026-09-24, in the second the flow was found dead).

Not changed: under a call, a flow that died with no reset and no close
reaching the phone is found dead only when the kernel gives up on
unacknowledged bytes, 924.6 s or more after them by its default
tcp_retries2, so an attempt whose own INVITE is the first such bytes
gets no response and is cancelled at its setup deadline, as before; a
flow found dead after a response to the INVITE is not reopened, as
before; a Dial whose INVITE cannot be sent ends its call at once, as
before.

Tested: tests/Engine (which attempt is sent again, the same bytes, once
per attempt, the deadline anew, the call's end where the flow is lost);
the daemon of this commit and 1.2.3's on the workstation against a
stand-in network (the fp6 journal's 2026-11-24-crlf-keepalive capture,
bench-dial.sh): a flow the network forgot, reopened and the INVITE
answered 486 as on a live flow, where 1.2.3's call ended after 100 s; a
flow the network closed at the INVITE, with the acknowledgement of the
daemon's close kept back; one that died on the daemon's side at the
kernel's retransmission limit; a network that takes no new connection,
one that resets the second INVITE's flow too and one that has ended the
binding, where the call ended within a second; UDP. And on the dev phone
on KPN, the binary of the range's tip: a call to voicemail answered and
hung up, and one whose flow was made to die under the INVITE before the
INVITE left the phone: reopened from the same port, the INVITE again 2.1
s after the death was found, answered 0.2 s later. By a call, no P-CSCF
that had dropped a flow's state has been met, and none that had received
the first INVITE before the flow died.
2026-11-25 10:24:07 +01:00
d3e495c333
imsd 1.2.3
All checks were successful
package / package (push) Successful in 2m23s
v1.2.3
2026-11-23 19:32:58 +01:00
610d8e1300
imsd: with an identity read from the card's ISIM, a fresh registration is made under it and the ISIM is asked for the answer to the challenge
imsd registered the identity TS 23.003 derives from the IMSI on every
card and authenticated in the USIM. TS 23.003 has a UE derive its home
domain and a temporary public identity "if there is no ISIM
application" (13.2, 13.4B); TS 24.229 5.1.1.1A names the ISIM as
holding the parameters a registration starts from and says "The ISIM
shall always be used for authentication to the IM CN subsystem, if it
is present"; GSMA IR.92 2.2.1 has the UE register the public identity
of EF_IMPU's first record.

A US card on AT&T's network (operator name "Dark Star") holds names of
the operator's own: <IMSI>@private.att.net, one.att.net and
sip:<IMSI>@one.att.net (a read-only probe of the card, 2026-11-23).
imsd 1.1.0's first REGISTER there, with the derived names, was
answered 480 Temporarily Unavailable (2026-11-09); TS 24.229 5.3.1.3
has an I-CSCF answer 480 when the HSS lookup "cannot be completed".
This daemon has not sent that network the card's own names.

Unless ISIM=0 is set, a bring-up reads the ISIM application of the
USIM's slot, in whatever state the modem lists it, over a logical
channel: EF_IMPI, EF_DOMAIN and record 1 of EF_IMPU. When the three
make an identity it is the card's, and the ISIM is asked for the answer
to the challenge; an ISIM that gives no result is followed by the same
challenge to the card's USIM, where 1.2.2 sent every challenge.
Without an ISIM, with ISIM=0, or when the read or the check of the
three fails, the derived names and the USIM stand as before. An
`identity:` line in the journal says which and why. So with ISIM=0,
with an ISIM that gives no identity and behind one that gives no result
imsd asks the USIM where 5.1.1.1A has the ISIM used.

A fresh registration is made under the card's identity. A resumed one
keeps the identity it was made under until its next fresh registration,
as it keeps its P-CSCF and its address: the state file records the
three names, and a file without them is taken for one made under the
derived ones. Otherwise a card whose ISIM holds other names, on a
network that took the derived ones as well, would have its standing
registration refreshed under new names at the first start after the
upgrade. An ISIM that gave no identity at the bring-up
is read again at each recovery by a fresh registration later in the
same run, until it gives one: such a registration would else go out
under the derived names. A state file whose three names are no identity
imsd can register is no registration to resume, whatever transport the
file names.

Calls and texts follow the registration's identity. Its home domain is
what RuriFor takes for the address of a dialled number, an outgoing
call's Request-URI and To (the host, and the phone-context where it
writes one), and what ScPsi takes for the service centre's address of
an SMS submission; while no P-Associated-URI has named another, its
public identity is the one the reg-event SUBSCRIBE names and CallerId
gives. Under an identity read from an ISIM these are the ISIM's.

The read and the AKA run share one channel helper (UimChannel), which
closes its channel on every way out: 1.2.2 left the AKA's channel open
when the card's answer was the single byte 61.

Tested: the suites; the daemon of this commit on the workstation, its
registration against a stand-in for qmicli and a stand-in network that
answers a first REGISTER of any names but its subscriber's 480 and
tells the two applications' answers to the challenge apart (the fp6
journal's 2026-11-23-isim-identity capture): 46 scenarios, among them
an ISIM with names of the operator's own, one with the derived names,
ISIM=0 on the first (480, as on 2026-11-09), an ISIM that cannot be
read or does not answer the challenge, the resume by this daemon of a
registration imsd 1.2.2 made under the derived names on a card whose
ISIM holds others, and a fresh registration in a run that resumed. Not
run on a phone yet, and on no network.
2026-11-23 19:32:58 +01:00
3754687b0d
aka: the ISIM application of a card, its identity files and the identity they hold
An ISIM holds the parameters a registration starts from (TS 24.229
5.1.1.1A): the private identity in EF_IMPI, the home domain in
EF_DOMAIN and public identities in EF_IMPU (TS 31.103 4.2.2 to 4.2.4),
of which the first record's is the one to register (GSMA IR.92 2.2.1).
TS 23.003 has a UE derive its home domain and a temporary public
identity from the IMSI "if there is no ISIM application" (13.2, 13.4B);
those derived names are the only ones imsd has. This is the part of
reading an ISIM that has no I/O; the daemon does not use it yet.

ParseIsimApp finds the ISIM application of one slot in qmicli's card
status, in whatever state the modem lists it. On the two cards with an
ISIM that a read-only probe read (a US card, 2026-11-23, and a
Norwegian one, 2026-11-21) the Fairphone 6's modem lists the ISIM
`detected` beside the `ready` USIM, and on both a logical channel
opened on it and its identity files were read.

The commands are the ones that probe sent: SELECT by file identifier,
READ BINARY, READ RECORD (TS 102 221 11.1.1, 11.1.3, 11.1.5).
ApduAnswer is a card's answer, '90 00', '91 XX' and '92 XX' its normal
endings (10.2.1.1), and ApduFollowUp the command it asks for next when
the answer brought no data: GET RESPONSE for '61 XX', a command without
data again with the length named for '6C XX' (7.3.1.1.5); an answer
with data is taken for the command's last. HoldsRead takes a read's
data under the warning '62 82' as well (10.2.1.3). ParseIsimValue takes
the value of the data object with tag '80' that a file begins with,
cuts 'FF' bytes from the end of its length as the probe does, and gives
none for a value with a blank or a byte that is not printable ASCII.
IsimIdentity checks the three values before they replace the derived
names: they are written into a quoted string and between the angle
brackets of SIP header fields. It refuses a value with a quote, a
backslash, an angle bracket, a blank, a line break or another byte
outside printable ASCII, a private or a public identity of more than
255 characters, a private identity without an @ between two parts, a
domain that is not labels of letters, digits and inner hyphens, 63
characters a label and 253 in all at most, and a public identity that
does not begin sip: or is that alone.

The two readers of the card status share how they read a line;
ParseCardStatus gives what it gave.

Tested: tests/Aka (the application out of a card status with the US
card's two applications, in either order, and out of a second slot with
the Norwegian card's AID; the commands, the answers and their
follow-ups, the values, the identity and what is refused) and
tests/Messages (the two REGISTERs of an ISIM's identity against the
pinned ones).
2026-11-23 19:32:58 +01:00
460343e578
aka: a command on a logical channel from 4 to 19 carries the extended class byte
The AUTHENTICATE and the GET RESPONSE went out with the channel number
as their class byte. That is the coding of the standard logical
channels, 0 to 3 (ETSI TS 102 221 10.1.1, table 10.3: the channel in
bits b2 and b1). For the extended ones, 4 to 19, table 10.4a has
'01x0 xxxx' with the channel less four in the low four bits: a command
for channel 4 starts with 40. As 04 it is a command for channel 0 with
a secure-messaging bit set.

The channel is the one the modem returns when imsd opens a logical
channel for the AKA run; imsd does not log it, so whether a
registration ever got one above 3 is not on record.

tests/Aka pins the class byte of channels 0, 1, 3, 4, 5 and 19, the
AUTHENTICATE on channels 3 and 4 and the GET RESPONSE on channel 7.
2026-11-23 14:47:32 +01:00
ddb8798d85
imsd 1.2.2
All checks were successful
package / package (push) Successful in 2m3s
v1.2.2
2026-11-23 11:19:04 +01:00
d3c1ba4a29
ipsec: the default offer names the null cipher beside aes-cbc
The UE is to announce the IPsec algorithms it supports (TS 24.229
5.1.1.2.2 d), and TS 33.203 7.2 has its first REGISTER carry "a list of
identifiers for the integrity and encryption algorithms, which the UE
supports". The null cipher is one a UE must support (7.1 by TS 33.210
5.3.3 and RFC 8221; GSMA IR.92 5.3), and imsd can install it, but its
default offer named aes-cbc alone.

Ice Norway has answered imsd's first REGISTER 403 (2026-11-01, -02),
where the phone's own modem had carried a call with the CS domain
detached (2026-09-02). On Odido it drew an answer that the imsd of that
day did not log, and the Python stack's REGISTER minutes later a 403
(2026-09-16), with a SIM that another Fairphone 6's own IMS client had
registered with (2026-07-15). That client's four mechanisms were
answered with one naming ealg=null, as the Python stack's offer of the
null cipher was (2026-07-13). Whether the offer is the reason for either
answer is not measured.

The default offer is aes-cbc, then null. A P-CSCF that selects the null
cipher from it gets SAs that protect the signalling's integrity and do
not encrypt it; EALG=aes-cbc gives 1.2.1's offer.

Tested: the suites; the daemon of this commit against a stand-in P-CSCF
on the workstation that refuses an offer without the null cipher (imsd
1.2.1 is answered 403 there, this commit's is challenged and selects the
null mechanism); on the FP6 on KPN, in an earlier build of this change,
on 1.2.0, a reregistration and a fresh registration with the default
offer: KPN named aes-cbc, and answered the reregistration, the fresh
registration's protected REGISTER and the reg-event SUBSCRIBEs 200.
2026-11-23 11:19:04 +01:00
ed2a009425
ipsec, messages, imsd: the offered ESP ciphers are a list
imsd's Security-Client held one mechanism, its cipher the value of EALG,
aes-cbc when unset. TS 33.203 7.2 has the UE's first REGISTER carry "a
list of identifiers for the integrity and encryption algorithms, which
the UE supports", and imsd can install three ciphers: an offer of one
could not say so.

EALG is now a comma-separated list, offered in the order written: one
mechanism per cipher in a single Security-Client, each with the
REGISTER's SPIs and ports (7.2 NOTE 1, NOTE 2). The default stays
aes-cbc alone. A name imsd cannot install is ignored with a journal
line where it used to go out as written, `3des` is offered as
des-ede3-cbc, RFC 3329's name for it, a setting that names no cipher
gives the default, and the bring-up logs what is offered (`ESP ciphers
offered: …`).

An offer of more than one cipher needs a further rule for the 401's
list. O2 UK's P-CSCF lists six mechanisms and puts the SPIs on one: the
sha1 entry without a cipher for a null offer, the sha1 entry with
aes-cbc for an aes-cbc offer (2026-09-17, 2026-09-20). The second has
the higher q, so with both ciphers offered the highest-q offered entry
and the entry carrying the SPIs can be two entries. The entry carrying
the SPIs is therefore taken when it is the only such entry and one of
the offer; otherwise the highest-q offered entry, as before. With one
cipher offered the two name the same algorithms; they can differ in mod
or prot, and there the marked entry's are now taken, where 1.2.1 took
the highest-q entry's.

Tested: tests/Ipsec (the setting; the selection against two offered
ciphers) and tests/Messages (a Security-Client of two mechanisms); the
daemon of this commit against a stand-in P-CSCF on the workstation, with
one cipher offered and with two.
2026-11-23 10:08:04 +01:00
6b0d6341d3
ipsec: the Security-Verify rebuilt from the kernel's SA names the SA's algorithms
A resume sends the 401's Security-Server list from the state file as its
Security-Verify, and where the file holds none for the pair in the
kernel, one mechanism rebuilt from that pair: its SPIs and ports, with
alg=hmac-sha-1-96 and ealg=aes-cbc written in whatever the pair was
installed with. Over a pair with the null cipher, 3DES or hmac-md5-96
that entry named an algorithm the pair does not use, and RFC 3329 2.3.1
has a server answer a Security-Verify that differs from its own list
with a 494.

ParseExistingSa now reads the two names from the state it takes spi-s
from: `ip xfrm state` prints them on its auth-trunc and enc lines, in
the kernel's names for what imsd installs. A state that prints neither
line, or another name, reads as hmac-sha-1-96 and aes-cbc, as before.

Tested: tests/Ipsec, on the lines `ip xfrm state` prints for the SAs
imsd installs (Linux 7.2, iproute2 7.2).
2026-11-23 10:07:59 +01:00
2ec2426597
ipsec, imsd: two comments cite the part of RFC 3329 that holds their rule
That a Security-Verify mirrors the server's whole list is in 2.3.1, and
that an absent ealg means no encryption is in Appendix A, the syntax of
ipsec-3gpp; both comments named 2.2, the syntax of the header fields.
Comments only.
2026-11-23 08:40:03 +01:00
d381805d66
messages: the header names the 400 among what the module covers
The header's list of what the module builds has lacked BuildBadRequest's
400 since that builder came. A comment only.
2026-11-23 08:39:47 +01:00
21ebfa2823
imsd 1.2.1
All checks were successful
package / package (push) Successful in 2m12s
v1.2.1
2026-11-22 17:35:14 +01:00
d6d7ba100a
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).
2026-11-22 17:35:13 +01:00
1fa4d77fcd
imsd: what the client flow already holds is read before an SMS wait is judged
The run loop judged the wait of the message in flight — its MESSAGE's
final, its submit report — after draining the server ports and before
its read of the client flow. A final that had arrived in time and was
still unread at that pass counted as none: the segment was sent again —
before the repeat existed, the message failed — and the final then
found nothing to own (issue #3, the third of its three cases).

The pass now reads what the flow holds, without waiting, before it
judges: SipFlow::RecvReady returns a message that is whole in the frame
buffer or readable on the socket now. RecvMsg's read of the socket
moved into a helper both use (ReadOnce), and the handling of a message
read from the flow into OnFlowMessage, for the loop's two reads.

Tested on the workstation's loopback with the daemon's own SipFlow built
around a bench main (the fp6 journal's 2026-11-20-issues-2-5 capture,
flow-read): over TCP and over UDP RecvReady returns a message the socket
holds without waiting and none when it holds none, and RecvMsg waits its
time and returns a message when one comes; over TCP RecvReady leaves a
message that is not whole yet. On the dev phone the binary of this
range's last commit judged a report's wait at that pass, 130.06 s after
the final, and sent the repeat (the capture's phone-form6,
visit-journal.txt); the pass has not run with a final waiting unread:
that takes a final timed to it.
2026-11-22 17:35:13 +01:00
23892e8e81
sms, engine, imsd: a segment that gets no answer, or an RP-ERROR with cause 41, is sent once more with TP-RD set
A submission whose submit report did not come in time ended as
`failed`, and nothing was sent again. The service centre may have the
text all the same, and a user who then sends it again delivers it
twice: the second submission has a new TP-MR, and the service centre
cannot tell that it is a repeat (issue #3, the second of its three
cases).

TS 23.040 9.2.3.6 has the MS "automatically repeat the SMS-SUBMIT", one
to three times, with the same TP-MR and TP-RD set, when no response or
an RP-ERROR with an appropriate cause comes, so that the service centre
can discard a duplicate. SmsOutbound now sends a segment once more: when
either wait runs out, on a final of 408 or 504 (RFC 3261 21.4.9: the
server "could not produce a response within a suitable amount of time";
21.5.5: it "did not receive a timely response from an external server")
and on an RP-ERROR with cause 41, temporary failure, or with a value TS
24.011 table 8.4's part 1 does not list, which it has "treated as cause
number 41". Of the causes part 1 lists, Annex E-2 says of 41 alone that
the MS "may wish to try another short message transfer attempt almost
immediately". The repeat is a MESSAGE of its own, under its own Call-ID
and the next RP-MR — the shell's counter now goes on after the last
RP-MR a message used, one per MESSAGE built — with the same SMS-SUBMIT,
TP-RD set by the codec's flag, which nothing set until now.

The two waits are longer, so that a repeat does not overtake an answer
that is only late: 128 s for the final and 130 s from the final for the
report. TS 24.229 table 7.7.1 recommends a UE whose requests name one
of the accesses clause 7.7 lists in P-Access-Network-Info a T1 of 2 s
and a timer F of 64*T1, and TS 24.341 5.3.1.1 NOTE 1 has an SM-over-IP
sender's TR1M set to a value greater than timer F (Jorijn, 2026-11-21).

The segment is accepted by an RP-ACK to either attempt — the first
attempt's is taken when it comes after the repeat went out — and by the
RP-ERROR whose TP-FCS is the duplicate rejection (0xC5) when it answers
the repeat and no RP-ERROR has answered the first attempt by then: the
service centre is taken to have the first. An RP-ERROR to the first
attempt that comes after the repeat went out leaves the segment to the
repeat's answer. Any other end of the repeat fails the message, with
both attempts' ends in the reason. A final refused with another status
and an RP-ERROR with another cause fail the message at once, as before.

What the duplicate rejection does not say is which SMS-SUBMIT the
service centre holds: one of this subscription's that reached it
another way under the same TP-MR can draw the rejection too, and with
imsd's first attempt lost the message is then `sent` for a text that
never arrived (Jorijn, 2026-11-21: taken as the clause has it).

Not done of the clause's repeat: it cannot be switched off, and a failed
message is not kept for a user's retransmission under its TP-MR.

No member of the Messaging interface changes: `sent` and `failed` come
as before, a `failed` later by the waits — with nothing answering, 256 s
after the MESSAGE where 1.2.0 said it after 32 s — and texts queued
behind the message wait as long.

Tested by tests/Engine and tests/Sms (RpCauseIsTemporary over all 128
values; a cross-generated SMS-SUBMIT with TP-RD), and on the dev phone
against KPN with the binary of this range's last commit (the fp6
journal's 2026-11-20-issues-2-5 capture, phone-form6, repeat-bench.log):
with the phone deaf on its protected server port a text to the own
number got its 202 and no submit report, went out again 130 s after the
final under the next RP-MR, with the same TP-MR and TP-RD set, and ended
`sent`; the message after it took the RP-MR after the repeat's.

KPN's service centre did not discard the repeat in that bench, nor in
the six before it (one of them with a build that waited 40 s): the
repeat got an RP-ACK under a time stamp of its own, and once the port
was open again the text came twice, under the two attempts' time
stamps: the recipient got the text twice without the user sending it
again, and the message was `sent`. 1.2.0 ends a submission whose report
does not come as `failed` and sends nothing again.

The repeat is sent all the same, on Jorijn's decision of 2026-11-20 with
the first of those benches before him: the clause has the MS repeat
("shall") and the service centre discard ("should"), and Android's
framework sends its own retries so (AOSP's ImsSmsDispatcher and
GsmSMSDispatcher set TP-RD and the earlier TP-MR; the capture's
repeat-research).
2026-11-22 17:35:12 +01:00
ef04b473a7
engine, imsd: a submit report for a MESSAGE no longer in flight that this run sent in the last hour is answered 200
TS 24.341 5.3.1.2 has a submit report answered 200 when its In-Reply-To
"indicates that the request corresponds to a short message submitted by
the SM-over-IP sender" and 488 when it does not, and its NOTE 3 has the
sender store the Call-ID for that. imsd knew only the Call-ID of the
segment in flight (OwnsReport): a report that came once its message had
ended — the 40 s wait run out — or once its segment was followed by the
next was answered 488 like a stranger's, and its line said only "no
MESSAGE of ours in flight" (issue #3, the first of its three cases).

RecentSubmissions keeps the Call-ID of every MESSAGE a submission goes
out in for an hour, with the message's id and the segment. A report
In-Reply-To one of them that the message in flight does not take is
answered 200, and the journal has `submit report (RP-ACK) In-Reply-To
…: sms <id>'s segment i/n, no longer in flight; 200`, an RP-ERROR's
with its cause. The 488 is left for an In-Reply-To that names no MESSAGE
of ours on record, and its line says so ("on record" for "in flight").
A report without In-Reply-To that no message in flight takes by its
RP-MR is answered 200 as before; its line ends `that no message in
flight owns; 200` where it ended `for no message in flight; 200`.

The bus is told nothing of a late report: the Messaging interface is
frozen with `failed` as a message's last word (AGENTS.md §8.4), so a
text the service centre took after its wait had run out stays `failed`
there; the journal's line is the record of it.

Tested by tests/Engine: the table (a Call-ID on record for 3600 s, the
first of a list that is ours, each segment's MESSAGE put on record as it
goes out) and OnSmsMessage (200 and the line for a report on a segment
that was followed by the next, on a message that was sent and, with an
RP-ERROR's cause, on one its wait had ended; 488 and its line for a
stranger's). On the dev phone, with the binary of this range's last
commit, no report came for a MESSAGE no longer in flight (the fp6
journal's 2026-11-20-issues-2-5 capture, phone-form6), so the 200 for
one and its line have run in the suite alone.
2026-11-22 17:35:12 +01:00
710f884575
imsd: List answers IOError for a store it could not read, and a scan's read error no longer ends the daemon
LoadStoredSms had no way to report a failure. A store directory that
could not be opened read as an empty store, and a record that could not
be opened read as a corrupt file and was skipped: Messaging.List
answered success with texts missing. A consumer that forgets a deleted
text's id once List no longer carries it forgets it too early then, and
imports the text again when a later List has it; and a text that
arrived while no app ran stays unseen until another List (issue #5).
The scans also walked the directory with the iterator's throwing
increment and tested each entry with is_regular_file() in its throwing
form, and nothing catches that at the start's sweep, in List's handler
or in the run loop: a read error there ended the process — in the run
loop from the count for the `stored` journal line, with a text stored
and its delivery report unsent.

The three scans now go through opendir, readdir, stat and read. What a
scan cannot read is a StoreFault, logged by the scan that met it;
List's read and the count hand theirs back as well. List answers
org.freedesktop.DBus.Error.IOError with the system's reason, the error
Delete gives for a removal that failed: no list, so a consumer takes
nothing for deleted and asks again. A store directory that does not
exist is still an empty list, and a file that reads and is no record is
still skipped with its line. The sweep logs the fault and lets the
daemon start; the `stored` line goes without its count. The journal
names what could not be read: `sms store: cannot read <path>:
<reason>`.

The Messaging interface is frozen as of 1.2.0 (AGENTS.md §8.4): no
member, signature, key, state word or error name changes; List gains a
failure answer under an error name the interface has.

Tested in dev mode on a private session bus, on the workstation's
build of this commit (the fp6 journal's 2026-11-20-issues-2-5 capture,
list-io): IOError with "Permission denied" for the store directory at
mode 000 and at mode 400 and for a record at mode 000, and with "Not a
directory" for a file in the directory's place; an empty list with no
directory; both records listed beside a file that is no record, a
directory and a dangling link named like records; a start with the
directory at mode 000 logs the sweep's fault and the daemon answers.
On the dev phone, with the binary of this range's last commit (the
capture's phone-form6): an empty list with the store directory moved
away, IOError with "Not a directory" with a file in its place, the
fault in the journal for each call it refused. Not benched: a read
that fails part-way, a file removed between the directory's read and
its own, a process out of descriptors, the `stored` line without its
count.
2026-11-22 17:35:12 +01:00
9333621c66
sip: a received message's header section is unfolded where it is framed
RFC 3261 7.3.1 lets a header value go on over further lines, each begun
with a space or a tab: "The line break and the whitespace at the
beginning of the next line are treated as a single SP character." The
text layer read a header from one line, so of a folded value it had the
first line only. Networks fold: KPN's 401 to the unprotected REGISTER
of 2026-07-18 and Odido's of 2026-07-13 had the WWW-Authenticate over
four lines (AGENTS.md §13; imsd finds a 401's nonce by a search of the
whole message, on a continuation line as on any other). A
Security-Server folded the same way would be read by its first line
alone, without the SPIs and ports on the further lines, and the
bring-up deferred; a short message whose Content-Type stands on a
continuation line would be taken for a page-mode text, answered 200
and never shown; a folded Content-Length on a connection would frame
no body, and the body's bytes begin the next message.

Unfolded takes the folds out of a header section, and the two framers
— FrameBuffer::TryExtract for a stream, DatagramMessage for a datagram
— hand a message on with its header section unfolded and its body as
it came; the Content-Length that frames the body is read from the
unfolded section. CutShortRequest reads its Content-Length so too, and
the header section it gives for the 400 is unfolded. Every socket imsd
reads SIP from goes through one of the two framers, so each reader of
a header still reads one line. A DUMP_SIP dump of a received message
holds it as framed.

Jorijn's decision of 2026-11-21 ("Unfold now").

Tested by tests/Sip — Unfolded on 7.3.1's own example, a tab, a bare LF,
a value begun on the next line and a line break that nothing follows;
both framers on a 401 whose WWW-Authenticate goes over four lines and
whose Content-Length is folded; CutShortRequest on a request cut short
of a folded Content-Length; ViaResponsePort on a Via list folded after
its comma, through the datagram framer — and by tests/Engine, a
delivered MESSAGE whose Content-Type came folded. On the workstation's
loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, init-port,
server-ports and cut-short, at this commit and at the one before): a
stand-in's 401 with its Security-Server over three lines gives the whole
value, where the commit before deferred the bring-up for want of SPIs; a
request with its Content-Type and Content-Length on continuation lines
comes out of the server ports unfolded and framed by that length, as a
datagram and over a connection; a request cut short of a folded
Content-Length, its Via on a continuation line, is answered 400 with its
Via whole, on a server port and on the client flow, where the commit
before did not read the folded length and handed the request on as it
came; a request on a server port whose Via row is a list folded after
its comma, `rport` on its lower value, is answered from the client-port
socket, the way to the port its top value names, as at the commit
before. On the dev phone the binary of this range's last commit
registered fresh on KPN after a reboot; the 401 was not dumped, so
whether it came folded that time is not on record. A MESSAGE the phone
sent to its own protected server port, its Via row a list folded after
its comma with `rport` on the lower value, was answered from the
client-port socket (the capture's phone-form6, fresh-check.log and
inject-bench.log).
2026-11-22 17:35:12 +01:00
5f01b46909
imsd: a datagram on a server port or the init port is framed as one on the client flow is
SipFlow passes a datagram of the client flow through DatagramMessage:
one datagram is one message, the bytes past the Content-Length read
from it are no part of it and one whose body is shorter than that
length is no message (RFC 3261 18.3), nor is one that has no end of
headers. The two other places that read a datagram handed it on as it
came: the protected server ports, where the network's requests arrive,
and the init port, where the 401 to the unprotected REGISTER does.
Bytes after a body so reached its readers: behind an RP-ACK or an
RP-ERROR without user data, bytes shaped like that element (0x41, a
length and at least as many bytes) would be read as its submit report.

Both go through DatagramMessage now. On a server port a request cut
short of the Content-Length read from it is answered 400 as on the
client flow (Jorijn's decision of 2026-11-22, asked of him for this
port), by the way any answer from that port goes, and its line reads
`UDP: … on server socket <port> — answered 400`; whatever else
DatagramMessage refuses there is ignored with that line's `— ignored`.
The init port answers no request, whole or cut short: what
DatagramMessage refuses there is ignored with `UDP: … on the init
port, from port <n> — ignored`. A datagram of line breaks alone is
passed over on all three, and so is one of no bytes: on the init port
it ended the wait for the 401, and on a server port that pass's read
of the socket, with whatever stood behind it left for the next pass.
The server ports pass over one of other white space alone, as before.

Tested on the workstation's loopback with stand-ins for the network
(the fp6 journal's 2026-11-20-issues-2-5 capture, init-port and
server-ports; each at this commit and at the one before). The init
port, with the daemon in dev mode: an empty datagram and one of line
breaks are passed over, a 401 cut short of its Content-Length is
ignored with its line, and the 401 after each is taken, where the
commit before ended its wait at the empty one and took the cut-short
one for the reply; a request, cut short or whole, draws no answer at
either. The server ports, their class built around a bench main: a
request with bytes after its body comes out without them; one with a
short body is answered 400 on either port; a response, an ACK and a
CANCEL cut short so and a request without an end of headers are
ignored with their lines; a request behind a datagram of no bytes
comes out in the same pass. The commit before handed each of those
requests on as it came and stopped its pass at the datagram of no
bytes. A request whose Content-Length is folded is handed on at either
commit, with a body shorter than that length or with the bytes past
it, a folded value being read by its first line. On the dev phone the
binary of this range's last commit registered fresh through the init
port after a reboot; the submit report and the delivery of each of two
texts came to the server port as datagrams, by a packet counter; and a
MESSAGE with a Content-Length larger than its body, sent from the
phone to its own server port, was answered 400 (the capture's
phone-form6: fresh-check.log, checks.log, inject-bench.log).
2026-11-22 17:35:11 +01:00
7cae603c0c
sip, messages, imsd: the client flow answers a request datagram cut short of the Content-Length it reads with a 400, unless an ACK or a CANCEL
RFC 3261 18.3 on a datagram that ends before its message's body does:
"If the message is a response, it MUST be discarded. If the message is
a request, the element SHOULD generate a 400 (Bad Request) response."
The client flow's datagram read ignored either, where the
Content-Length it read said more bytes than came, with one line, `UDP:
datagram truncated (…) — ignored`.

CutShortRequest gives the header section of a request whose datagram
has fewer body bytes than the Content-Length read from it says, and
BuildBadRequest the 400 for it, in the shape of BuildResponse's finals:
every Via row echoed, the To tagged unless it holds a tag. The client
flow sends that 400 and its line ends `— answered 400`. Such a request
is known by its first line, which ends with the SIP version where a
status line begins with it (7.1, 7.2), in upper or in lower case: a
response cut short so, bytes that are no SIP cut short so and a
datagram without an end of headers are ignored as before. imsd keeps
nothing of a request it answers so, and follows 8.2.7 for an element
that answers without state: a To tag it adds is made from the
request's header section and a secret drawn once for the run, "in a
manner that will generate the same tag for the same request
consistently", and an ACK or a CANCEL cut short so gets no answer. The
server ports and the init port hand a datagram on as it came, as
before this commit.

Tested by tests/Sip (CutShortRequest: the header section of a request
cut short, with line breaks before it, under a compact Content-Length
and with its version in lower case; nothing for a body that is all
there, no Content-Length, no end of headers, a response in either
letter case, bytes that are no SIP, an ACK, a CANCEL) and by
tests/Messages (the 400 by its lines, its tag against Python's
hashlib; the same request, the same 400; another request or another
secret, another tag). On the workstation's loopback, SipFlow built
around a bench main (the fp6 journal's 2026-11-20-issues-2-5 capture,
cut-short, at this commit and at the one before): a MESSAGE with five
body bytes of nine draws the 400, and the same one when it is sent
again, where the commit before ignored it; a response cut short the
same way, in upper and in lower case, an ACK, a CANCEL, bytes that are
no SIP and a request without an end of headers draw nothing at either
commit; the MESSAGE with its Content-Length folded is handed on at
either commit, a folded value being read by its first line; a whole
request sent after them is returned by the flow.
2026-11-22 17:35:11 +01:00
c81dd3d267
sip: both framers read a Content-Length as a number
DatagramMessage read the first nine characters of a Content-Length, the
zeros before its number among them: a length written 0000000005 came out
as 0, and the body after it was cut off as bytes past the message.
FrameBuffer read the value into a long, and one too long for that
counted as no Content-Length: the body was framed as the start of the
next message. RFC 3261 25.1 writes the value as 1*DIGIT.

LengthOf reads it for both: the number its leading digits spell, zeros
before it aside; of a number of more than nine digits the first nine,
more than a datagram holds and enough that a stream waits. A value that
begins with no digit is no length, as before.

Tested by tests/Sip through both framers: a length of one digit written
with ten zeros before it frames that many bytes; a twenty-digit length
that wraps to zero in 64 bits is a datagram cut short and a stream's
body waited for; a value without a leading digit leaves a datagram's
body the rest of it and a stream's empty.
2026-11-22 17:35:11 +01:00
78c702546a
sip: ResponseOf compares a response's CSeq as its number and its method
ResponseOf matched a response to a request by its Call-ID and by its
CSeq compared as text. RFC 3261 25.1 writes the CSeq as 1*DIGIT LWS
Method, so a response may part the two by a tab or by more than one
space, and one written so was no transaction's: a REGISTER's wait ran
out without a reply.

CSeqParts takes a CSeq value as its number and its method: the digits it
begins with, the spaces or tabs after them, the method to the value's
end. ResponseOf compares the two as 20.16 has two CSeqs equal, "if the
sequence number and the request method are identical": the number as a
number — zeros before it do not make it another — and the method to the
letter. A value of another shape matches nothing.

Tested by tests/Sip: a final whose CSeq has two spaces, a tab or both
between its parts, or zeros before its number, is the transaction's, and
so is its 100 Trying; another number, another method, a method in other
letter case, and a CSeq without its number, its method or the white
space between them are not.
2026-11-22 17:35:11 +01:00
1267fe1ada
sip: a header is found under its compact form, and with white space before the colon
RFC 3261 7.3.3 lets a sender write a header name in its one-letter form
at any time and has every implementation accept both forms. The text
layer matched the long name only, so to every reader a header sent in
compact form was absent: the TCP framer took no body length from `l:`
and read the body as the start of the next message, a response with
`i:` matched no transaction and a request no call, the finals imsd
builds left out a Via, From, To or Call-ID that came in compact form,
and a short message whose content type came as `c:` was answered 200
and logged instead of taken (issue #2).

MatchHeaderLine now takes a line under the name it is asked for or
under that name's compact form: the ten RFC 3261 defines, and `o` for
Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two
extension headers imsd reads that have one. Every reader goes through
it — Header, Headers, the framer, DatagramMessage — so no reader
changes for it. It also takes white space between the name and the
colon, which the same grammar allows (25.1's HCOLON; 7.3.1's
"Subject      :      lunch") and the matcher refused. A value folded
onto further lines is still read by its first line.

One reader is changed for the rows it is now handed. ViaResponsePort
gives the port the top Via names, to which the answer to a request that
came in a datagram on a server port goes (RFC 3261 18.2.2), and none
where that Via carries `rport` (RFC 3581): the answer then goes back to
the port the request came from. It took `rport` for present where
those five letters, in lower case, stood anywhere behind the row's
first semicolon. Parameter names are case-insensitive (7.3.1), and a
request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over,
would have been answered to the port that Via names, its `rport` not
seen. ViaResponsePort now reads the Via's parameters one by one, each
to the next semicolon outside a quoted string, and `rport` is one by
its name, in any case: not those letters in a value or in a longer
name. Read so, the last parameter of the top value would run on into
the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no
`rport`, and 1.2.0's search of the letters found it —, so the top value
is cut from the row first, at the first comma outside a quoted string.
With that cut a lower value's `rport` no longer counts for the top
one's, as it did in 1.2.0 for a list on one line.

Tested by the suites: tests/Sip pins each of the twelve forms through
Header, in lower and in upper case, and through Headers, `l:` through
the framer and DatagramMessage, 7.3.1's four spellings of the colon, and
ViaResponsePort's reading of a Via row, `rport` by its name and of a
list on one line the top value alone; tests/Engine drives an incoming
call from an INVITE in compact form, an outgoing call from responses in
compact form and a delivered MESSAGE in compact form through the
reducers; tests/Messages builds BuildResponse, BuildResponse200 and
BuildInviteResponse for a request in compact form. On the workstation's
loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports,
at this commit and at the one before) a request on a server port whose
Via row is a list on one line with `rport` on its lower value is
answered from the client-port socket, the way to the port its top value
names, where the commit before answered it from the socket it had come
on. On the dev phone the binary of this range's last commit answered a
MESSAGE the phone sent to its own protected server port from the
client-port socket where its Via row was such a list, and from the
socket it had come on where its one Via came as `v: …;RPORT` (the
capture's phone-form6, inject-bench.log).
2026-11-22 17:35:11 +01:00
5c1fca12b9
docs: a phone record shows to and operator in a List
AGENTS.md §5 said no phone record shows the two keys in a `Received` or
a `List`. The tip of 1.2.0 ran on the dev phone on 2026-11-20, after
that sentence was written: a text sent to the own number over the bus
was delivered back, and `List` gave its record with `to` and
`operator` (the fp6 journal's 2026-11-20-imsd-1.2.0-frozen-on-dev-phone
capture, checks.log). No capture holds a `Received` with them.
2026-11-22 17:35:11 +01:00
ca825937bf
tests: the Sip suite's header names its sections, and its reginfo fixture takes a documentation address and the suites' instance id
The suite's header comment named five of its sections — header access,
the status line, the granted lifetime, the caller's identity and the
frame buffer — and left out six: ViaResponsePort, DatagramMessage,
RetryAfter and RefusalSummary, ResponseOf, RegInfoContactState,
HeaderUri and Body. Its reg-event fixture had a contact at
[2a03:db8::1], outside the documentation prefix 2001:db8::/32, and an
instance id built on a real phone model's type allocation code. The
header now names every section; the fixture has [2001:db8::1] and the
instance id that tests/Aka and tests/Messages use, 35999999-000000-1.
No check changes.
2026-11-22 17:35:11 +01:00
a63132deb8
tests: every suite returns 1 for a failure, not the count
Six suites ended in `return Failures;`. `crafter-build test` takes an
exit status of 77 for a skipped suite and then succeeds, and an exit
status keeps 8 bits: 77 failing checks read as a skip, 256 as a pass.
All nine now return 1 after any failure, as Engine, Sip and Sms did.

Tested with 77 failing checks added to Ipsec, to Messages and to Sdp
in turn (the fp6 journal's 2026-11-20-issues-2-5 capture, exit-status):
before, `crafter-build test` ended `8 passed, 1 skipped` with exit
status 0; now it ends `8 passed, 1 failed` with exit status 1.
2026-11-22 17:35:11 +01:00
f8cc160e1f
imsd 1.2.0
All checks were successful
package / package (push) Successful in 2m13s
v1.2.0
2026-11-19 18:26:21 +01:00
e39f7e39d6
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.
2026-11-19 18:26:21 +01:00
c434c8e84d
imsd: the Messaging GetStatus carries the subscriber's own number
The subscriber's own number was in the frozen interface's GetStatus and
not in the Messaging one, so a consumer that wanted it beside the
Messaging status needed a second call, and two calls can disagree: the
second can fail alone, and the status can change between them. Both
GetStatus methods take the number from the daemon's one status snapshot
as it then is, and within a run the number is never cleared. So one
answer can carry it: the Messaging GetStatus gives `ppi` beside `smsc`
and `registered`, as the frozen interface gives it but made valid UTF-8
as `to` is, so a consumer reads the status in one call and never lacks a
number the frozen status gives.

Tested: the suites as before (the key is a line in the method's reply;
the frozen interface's `ppi` is unchanged).
2026-11-19 18:26:20 +01:00
04c615fc15
imsd, engine: a received text records the subscriber it arrived for
The Messaging interface gave a received text with its sender and the
service centre but not the subscriber it was for. A consumer completing a
national-form sender with a country code had to take the code from the
daemon's status at import time, which is the wrong moment: the daemon
keeps a text on disk until an app deletes it, so the app that imports it
after a SIM change knows only the new SIM's code, and a national number
under the old SIM's plan is keyed, and replied to, under the new one —
another subscriber. Only the daemon knows at receipt which subscriber a
text arrived for. The stored record and the Received and List
dictionaries carry it
as `to`: the own number the daemon holds at the moment of 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 key is absent
while the daemon holds none.
It is additive: an app that does not know it ignores it, and a record
without it reads as before. The value comes from a header, so the
emission makes it valid UTF-8, as it does a failed submission's reason.

Tested: tests/Engine, the record round trip with `to` and a record
without it.
2026-11-19 18:26:20 +01:00
910e2594a0
project, docs: the linter goes
The Catcrafts house-style rules (Crafter.LintRules) rode in project.cpp
as a dependency crafter-build cloned once and built on every load; the tree
never passed them (111 findings on the 1.1.0 tree, 156 on an early freeze
of this range (2e87e26), 100 of the 156 the shared naming rule's, each
for a variable whose name begins with a capital — the
fp6 journal's lint captures, lint-tip-2e87e26), CI never ran them,
and AGENTS.md kept a census nobody acted on. Out: the dependency, the
import and the five AddRules calls, the lint-disable comments in 25
files and on 4 lines, §4.2 and the census of §6 — now "Code style", the
three rules that were never the linter's; the cross-compiling section
becomes §4.2 and its six citations — §4.1's sysroot sentence, §9.1, the CI
workflow, the APKBUILD, build-package.sh, make-sysroot.sh — follow. Jorijn, 2026-10-17: "just
remove the linter, we are ignoring it anyway".
2026-11-19 16:43:16 +01:00
d0cfaf712d
imsd, engine, packaging: received short messages are kept until an app deletes them — List and Delete on the Messaging interface
A received message went to a bus signal and nowhere else but DUMP_SIP's
opt-in raw dump of the last MESSAGE outside a call's dialog, so with no
app listening it was gone. It is now written
to <state dir>/sms/<id>.msg — mode 0600 in a 0700 directory, whole to a
.tmp, linked to its name and the directory fsynced; the engine's FormatStoredSms/ParseStoredSms
record codec, pinned by tests/Engine — before the signal, and stays until
Delete. List hands over the records it can read, by arrival second, then
within a run by sequence number. The record is named by
the message's id and published with link(2), which refuses a name the
store already holds, so the next number is tried and nothing is
replaced. link(2) refuses only a name the store
still holds: a client that deleted the daemon's copy after importing it
freed the name, and the run's token in the id is what keeps a later run
from giving it to another text, unless that run draws the same token and
meets the same second and number. The two methods sit behind the
Messaging polkit action with Send, and the policy text says so; GetStatus,
the open read, does not count the store, since the count would tell any
local account when a text arrived, and the unit makes the state
directory 0700 (StateDirectoryMode) for the same reason.

For a message the store cannot write the delivery report stays an
RP-ACK: the signal is its only delivery, and the journal says so. The
protocol's refusal —
RP-ERROR "memory capacity exceeded", TS 24.011 cause 22 — is half of a
mechanism: the other half, the UE's memory-available notification
(RP-SMMA, TS 24.341 5.3.2.5), imsd does not send; a refused last segment
would also lose its set. The
refusal was built and benched on KPN — the store made unwritable, the
text refused; it came again five minutes later, the store writable by
then, and a later text came at once — and taken out again; no other core
is measured. It returns
with the notification and a probe of the store. The record's directory is
fsynced after the link, its result unchecked like the directory open's; a
concatenated text's earlier segments are held in memory, not in the
store, until the set is whole (§7.9).

Tested on the dev phone (KPN): a text from the phone to its own number on
2026-10-18 23:30, under this publish (a build of this range ahead of this
history, 735dfda, whose StoreReceivedSms has this commit's code), stored
as
ims-sms-in-1792359045-1, an id of that build's shape; the store directory listed on 2026-10-19 holds
that record and no temporary (the fp6 journal's 2026-10-17-sms-over-ip-bench
capture: r20-tip-smoke-2026-10-18-2329, r22-store-backup-and-delete-proof).
The Exists path has no bench: a run's own ids never repeat. The refusal's bench (store-refused-2026-10-18-0136): the store directory
made immutable at 01:37, a text to the phone's own number not stored
(EPERM on its .tmp), the RP-ERROR answered 202, the text delivered again
at 01:42:56 under its first SC time stamp, stored and acknowledged, a later
text not held. Not on the phone: List's skip of a file that is no record
and four of Delete's answers ran on the workstation, in dev mode on a
private session bus, on this commit's host build (2026-11-19; its sha256
begins 8fdd9192866645d5): the skip, with its journal line; InvalidArgs
for a string that is no id; IOError, the
record still listed, for a record in a store directory made unwritable;
the removal once it was writable; FileNotFound for an id with no record.

The engine's start sweeps the .tmp names a crash left — one it cannot
unlink stays, unreported — so a deleted text's second name goes at the
next engine start that can remove it (Delete leaves .tmp
names alone). A Delete whose removal fails answers IOError with the system's
reason, and a record that is there is kept; FileNotFound is left for a
removal that found no file.
List's order breaks a tie between two texts of one run in one second by
the sequence number (pinned), not by the id as text.
2026-11-19 16:43:16 +01:00
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
4de5f0be45
sip, engine: the SMS over IP transactions as reducers
TS 24.341 has a submission travel as a MESSAGE with the RP-DATA, answered
with a final and then with the submit report in a MESSAGE of the
IP-SM-GW's own, and a delivery arrive as a MESSAGE with the RP-DATA to be
answered and acknowledged with an RP-ACK in a MESSAGE of ours. Two
pure reducers carry that, in the shape CallMachine has: SmsOutbound takes
one message of ours segment by segment — the MESSAGE, its final (a 32 s
wait, which a provisional starts over), the RP-ACK or RP-ERROR matched by
In-Reply-To, else by RP-MR (within 40 s of the final, a length TR1M may
have),
then the next segment with the next RP-MR and TP-MR — and ends it
as sent or failed, its State action carrying the reason; OnSmsMessage turns an
inbound MESSAGE into its final, the message or status report it carried
and the delivery report to send, 488 for a
submit report In-Reply-To no MESSAGE of ours in flight — one that is not
ours (5.3.1.2), or ours once the message has ended (its report's wait
run out, judged by the reducer's caller; a failure; sent) or its segment
was superseded by the next, which gets the same answer — an RP-ERROR for
a TPDU that is
unusable (a delivery or a status report that does not parse, or one of
the submit-report type), and a 200 with a log line for what it makes
nothing of: a MESSAGE whose Content-Type does not contain the SMS one, a
body that is no RP message, a submit report without In-Reply-To for no
message in flight. Imsd:Sip gains
HeaderUri, the URI of a header's first element, a quoted display name
before it passed over (none when that URI holds an ASCII control
character, a space, `<`, `>` or `"`: it goes into a request line), and
Body, moved out of CallMachine (its four call sites and the shell's
NOTIFY/MESSAGE branch follow).

No retransmission (TS 23.040 9.2.3.6's repeat with TP-RD is not done):
an unanswered MESSAGE or a report that never comes fails the message.
RecentTransactions, the reducer, keys a request by Call-ID, CSeq and Via
branch — the value of the first `branch=` of its first Via line; a
request with none or an empty one is not remembered — and gives back the
final remembered for it within 32 s (TimerJ, on every transport) — what
a caller needs to answer a retransmitted request again and not handle
it again (RFC 3261 17.2.2); without it a repeated RP-DATA would be
handled again: a second delivery report where the first got one and, of
a text in one segment, a second Received.

Every final OnSmsMessage gives an inbound MESSAGE — the 200, the 488 —
goes through BuildResponse: each Via: line echoed, the To echoed with a
tag minted for the request unless it holds `tag=` (RFC 3261 8.2.6.2).

tests/Engine drives both reducers through the dialogs above and the
retransmission table; tests/Sip pins the two helpers.

OnSmsMessage's header reads — the delivery report's target
(P-Asserted-Identity, else From) among them — go through the text
layer, which ends at the header section: a body line may spell a header
name (a text, or UCS-2 bytes that do) and must pick nothing. Pinned with
an 8-bit SMS-DELIVER whose data spells a P-Asserted-Identity line.

A UCS-2 surrogate pair a sender split across two segments comes out
whole in the Received action OnSmsMessage returns (the codec decodes a
set from its joined units); pinned.

Pinned as well: a submit report that arrives before the MESSAGE's own
final is taken (the message sent, or the next segment out under its own
Call-ID, and the late final nobody's), a text past 255 segments fails at
once naming the fit, and a delivery with no P-Asserted-Identity and no
From URI is handed over with no delivery report to send. A submit report
whose In-Reply-To lists Call-IDs (RFC 3261 20.21) is ours when ours is
among them, and a delivered MESSAGE's Call-ID with an ASCII control
character or a space in it is not written into the delivery report's
In-Reply-To.
2026-11-19 16:43:15 +01:00
0717c3008a
messages: the SIP MESSAGE of SMS over IP, +g.3gpp.smsip behind a context flag
TS 24.341 5.3.1.2 has a submission travel as a SIP MESSAGE to the
service centre's PSI with the RP-DATA as an application/vnd.3gpp.sms
body, and 5.3.2.4 the delivery report as one to the IP-SM-GW with
In-Reply-To naming the delivered MESSAGE: BuildMessageSms builds both,
out of dialog over the registration's Route with the same
P-Preferred-Identity, P-Access-Network-Info and sec-agree headers as the
INVITE and the reg-event SUBSCRIBE, and no Contact (RFC 3428 4). The REGISTER Contact carries +g.3gpp.smsip only
when Context::smsOverIp says so — the tag routes terminating short
messages to imsd (the 2026-10-17 bench's mt-last-message-in.raw), which
at this commit still answers them 200 and logs them — after the ICSI.
BuildResponse builds a final for an inbound request outside a call (the
488 of 5.3.1.2 for a report that is not ours, or a 200); the shell does
not call it in this commit — it still answers a MESSAGE with
BuildResponse200.

tests/Messages pins the Contact with the tag, the MESSAGE's headers and
body bytes both ways, the absence of Contact, and the 488.

BuildResponse echoes each Via: line and the To, with a tag added unless
the To already holds `tag=` (RFC 3261 8.2.6.2 has a UAS add a tag to a
To that carries none); tests/Messages pins the 488 and a 200.

ScPsi gives the service centre's PSI from its international number
(5.3.1.2 NOTE 1: the SC's E.164 number as a SIP URI with user=phone, or
a tel URI; the home domain is imsd's choice); RuriFor's dialled-number guess, whose trunk 0 is Dutch, has no
place there. Pinned in tests/Messages.
2026-11-19 16:43:15 +01:00
89048c3602
sip: a header is read from the header section only
Header and Headers iterated every line of a message, body included, so a
body line that spells a header name — a text someone typed, or the UCS-2
bytes of one — would be read as that header: a second Via for a final to
echo, a P-Asserted-Identity that CallerId takes for the sender. ForEachLine now ends
at the first empty line after a line of text (RFC 3261 7: the headers
end at the empty line) and skips empty lines before it (a keepalive's
CRLFs ahead of a message), so every reader of a header reads the header
section. Pinned in tests/Sip:
a body Via is no Via, a name that occurs only in the body is absent,
leading CRLFs are skipped. With these the suite has more than 77 checks,
so it returns 1 for any failure and no longer their count: `crafter-build
test` takes an exit status of 77 for a skipped suite.
2026-11-19 16:43:15 +01:00
c88de31a0a
sms: the short message codecs of TS 23.038, 23.040 and 24.011, and EF_SMSP
SMS over IP (TS 24.341) carries the bytes a 2G/3G phone puts in an
RP-DATA inside a SIP MESSAGE body of type application/vnd.3gpp.sms, so
imsd needs the whole stack below SIP once it owns SMS on a carrier whose
modem IMS is off: the GSM 7-bit default alphabet with its extension table
and the septet packing, UCS-2 for everything else (TS 23.038); SMS-SUBMIT
built per segment with the concatenation header, SMS-DELIVER,
SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed, the SMS-DELIVER-REPORT
that acknowledges a delivery, the user-data header and the reassembly of
a concatenated message (TS 23.040); RP-DATA, RP-ACK and RP-ERROR in both
directions with their causes (TS 24.011); and EF_SMSP, where the (U)SIM
names the service centre the RP-DATA is addressed to (TS 31.102 4.2.27,
the KPN SIM's record read on the dev phone on 2026-10-16: +31653131313).

A new partition, Imsd:Sms, pure std with no SIP, clock or I/O; tests/Sms
checks it against the classic
public PDU vectors ("hellohello", the "How are you?" SMS-DELIVER) and
vectors cross-generated by an independent Python reference.

A concatenated set with one alphabet throughout is decoded from its
segments' joined units — the septets, or the UTF-16BE octets — not from
the segments' texts, so a surrogate pair or an escape pair a sender cut
at a segment boundary comes out whole; a U+0000 in UCS-2 decodes as
U+FFFD, since no text means it and a D-Bus string cannot carry it.

A status report's TP-ST is read as TS 23.040 9.2.3.15 has the MS read it:
a reserved value, any with bit 7 set among them, as "Service Rejected" —
a temporary error after which the SC is not making any more transfer
attempts (StatusAsRead, pinned over all 256 values; StatusText has the
clause's four classes in words). Three more readings follow their
clauses the same way, each pinned: a time stamp semi-octet that is no
digit reads as 0 (9.2.3.11); `1111` before an address's last semi-octet
is skipped, not taken for its end (9.1.2.3); an SMS-SUBMIT-REPORT for
RP-ERROR with an unused bit of its first octet set gives TP-FCS 0xFF,
unspecified, with nothing else examined (9.2.2.2a).
2026-11-19 16:43:15 +01:00
87e3e6f007
README, FUNDING.yml: Forgejo's funding file and the shared License / Funding / Copyright footer
FUNDING.yml is the file Forgejo reads for a repository's Donate button
(Forgejo 17.0 and later: .forgejo/, .github/, then the root of the default
branch); it points at https://catcrafts.net/shop/donation. The README
closes with the footer shared by imsd, fingerprintd and fp6-img: License,
Funding, Copyright.
2026-11-19 10:42:10 +01:00