messages, imsd: P-Access-Network-Info in responses and in requests within a dialog
imsd named the serving cell in its REGISTERs, the reg-event SUBSCRIBE, an INVITE and a MESSAGE. TS 24.229 5.1.2A.1.1 and 5.1.2A.2 have a UE insert the header into a request within a dialog as well, and into a response within a dialog, to a request for a dialog and to a standalone method: not into a CANCEL nor into a response to one, and into an ACK at its choice. A PRACK and a BYE carry it now, and every response imsd builds but a 100 Trying, the 200 to a CANCEL and the transport's 400 to a request cut short. The server ports (the protected ports' TCP listeners and UDP sockets) take a request from any source (AGENTS.md §12), and the header is the phone's cell. What they send in answer keeps it only on the two paths of the SA pair the shell has on record, and loses it anywhere else. Tested: the suites, and the daemon of this commit on the workstation against a stand-in network that asks it from both sides of those paths (the fp6 journal's 2026-12-04-pani-in-dialog capture, bench/), and on the dev phone on KPN, where its answers to a text's two requests and a call's 180 and 200 carried the header inside the SA pair (the journal's 2026-12-04-imsd-1.2.7-range-on-dev-phone capture).
This commit is contained in:
parent
6d05aaed0d
commit
a65724a252
11 changed files with 460 additions and 38 deletions
|
|
@ -7,7 +7,9 @@ Imsd:Messages — the SIP request/response text the engine puts on the wire.
|
|||
Every VoLTE message the daemon sends is assembled here from an explicit
|
||||
context and the per-request variables so the builders
|
||||
are pure functions with no hidden state: the engine owns the dialog bookkeeping
|
||||
and the transport owns the socket, this module only formats bytes. That makes
|
||||
and the transport owns the socket (and takes the P-Access-Network-Info line
|
||||
out of an answer the server ports send on neither path of the SA pair on
|
||||
record), this module only formats bytes. That makes
|
||||
each message byte-pinnable — tests/Messages compares a REGISTER pair and an INVITE
|
||||
with strings cross-generated from the Python reference stack, header for header
|
||||
but for the divergences that suite's header names.
|
||||
|
|
@ -77,7 +79,13 @@ export namespace imsd::msg {
|
|||
// P-Access-Network-Info value (imsd::aka::ParsePani from live mmcli
|
||||
// location: real MCC/MNC/TAC/ECI, FDD). Empty omits the header —
|
||||
// never fabricate one: the network reads it to learn which access
|
||||
// the UE is reachable on (stock sends it in every REGISTER/INVITE).
|
||||
// the UE is reachable on.
|
||||
// It rides in every request but the ACKs and the CANCEL and in every
|
||||
// response but a 100 Trying, a CANCEL's and BuildBadRequest's 400:
|
||||
// by TS 24.229 5.1.2A.1.1 and 5.1.2A.2 for a request within a
|
||||
// dialog and for the three kinds of response detail::AccessInfo
|
||||
// names (the 100 and the 400 are left out by imsd's choice), by RFC
|
||||
// 7315 5.7 for the ACKs and the CANCEL.
|
||||
std::string panInfo;
|
||||
// Advertise SMS over IP in the REGISTER Contact (+g.3gpp.smsip, TS
|
||||
// 24.341 5.3.2.2): the network then delivers terminating short
|
||||
|
|
@ -224,6 +232,18 @@ export namespace imsd::msg {
|
|||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// The P-Access-Network-Info line of a response with status `code`
|
||||
// to `request`, where the serving cell is known: TS 24.229
|
||||
// 5.1.2A.1.1 and 5.1.2A.2 have a UE insert the header into every
|
||||
// response it sends within a dialog, to a request for a dialog and
|
||||
// to a standalone method, those to a CANCEL excepted. A 100 Trying
|
||||
// gets none, by imsd's choice: a stateful proxy never forwards it
|
||||
// (RFC 3261 21.1.1; AGENTS.md §7.6).
|
||||
inline void AccessInfo(std::vector<std::string>& l, const Context& c, std::string_view request, int code) {
|
||||
if (c.panInfo.empty() || code == 100 || request.starts_with("CANCEL ")) return;
|
||||
l.push_back(std::format("P-Access-Network-Info: {}", c.panInfo));
|
||||
}
|
||||
}
|
||||
|
||||
// ---- REGISTER -------------------------------------------------------
|
||||
|
|
@ -423,6 +443,9 @@ export namespace imsd::msg {
|
|||
|
||||
// An in-dialog request (PRACK, BYE, UPDATE...) over the dialog route set.
|
||||
// `extra` lines go after CSeq; an optional body sets Content-Type/Length.
|
||||
// P-Access-Network-Info as in the INVITE (TS 24.229 5.1.2A.1.1,
|
||||
// 5.1.2A.2); the ACKs and the CANCEL, built below, carry none (RFC 7315
|
||||
// 5.7: the header appears in no ACK and no CANCEL).
|
||||
std::string BuildInDialog(const Context& c, const Dialog& d, std::string_view method, int cseq, std::string_view viaBranch, std::span<const std::string> extra = {}, std::string_view body = {}, std::string_view ctype = {}) {
|
||||
std::string target = d.remoteTarget.value_or(d.ruri);
|
||||
std::string to = d.dialogTo.value_or(std::format("<{}>", d.ruri));
|
||||
|
|
@ -438,6 +461,7 @@ export namespace imsd::msg {
|
|||
};
|
||||
for (const std::string& e : extra)
|
||||
l.push_back(e);
|
||||
if (!c.panInfo.empty()) l.push_back(std::format("P-Access-Network-Info: {}", c.panInfo));
|
||||
if (!body.empty()) {
|
||||
l.push_back(std::format("Content-Type: {}", ctype));
|
||||
l.push_back(std::format("Content-Length: {}", body.size()));
|
||||
|
|
@ -508,7 +532,8 @@ export namespace imsd::msg {
|
|||
// half by tagging To (all but 100 Trying, which is hop-by-hop and
|
||||
// tagless). 1xx/2xx carry our Contact (the dialog's remote target for the
|
||||
// caller) and Allow; `extra` appends headers (RSeq, Session-Expires...);
|
||||
// `sdp` turns a 200 into the answer.
|
||||
// P-Access-Network-Info follows them where the cell is known, in all
|
||||
// but a 100; `sdp` turns a 200 into the answer.
|
||||
std::string BuildInviteResponse(const Context& c, std::string_view invite, int code, std::string_view text, std::string_view toTag, std::optional<std::string_view> sdp = std::nullopt, std::span<const std::string> extra = {}) {
|
||||
std::vector<std::string> l = {std::format("SIP/2.0 {} {}", code, text)};
|
||||
for (auto v : imsd::sip::Headers(invite, "Via"))
|
||||
|
|
@ -530,6 +555,7 @@ export namespace imsd::msg {
|
|||
}
|
||||
for (const std::string& e : extra)
|
||||
l.push_back(e);
|
||||
detail::AccessInfo(l, c, invite, code);
|
||||
if (sdp) {
|
||||
l.push_back("Content-Type: application/sdp");
|
||||
l.push_back(std::format("Content-Length: {}", sdp->size()));
|
||||
|
|
@ -544,10 +570,12 @@ export namespace imsd::msg {
|
|||
// 488 to one we did not: each Via row echoed in order (RFC 3261
|
||||
// 8.2.6.2), From, To with
|
||||
// `toTag` added unless the request's To holds `tag=` (8.2.6.2 again),
|
||||
// Call-ID and CSeq; no body. The shell's answers to any other request
|
||||
// Call-ID and CSeq, then P-Access-Network-Info where the cell is known;
|
||||
// no body. The shell's answers to any other request
|
||||
// outside a call but an INVITE (an OPTIONS, a NOTIFY, a method it does
|
||||
// not handle) keep BuildResponse200's hop-by-hop shape, as before.
|
||||
std::string BuildResponse(const Context&, std::string_view request, int code, std::string_view text, std::string_view toTag) {
|
||||
// not handle) keep BuildResponse200's hop-by-hop shape, as before,
|
||||
// unless the request is cut short: BuildBadRequest's 400 has this one.
|
||||
std::string BuildResponse(const Context& c, std::string_view request, int code, std::string_view text, std::string_view toTag) {
|
||||
std::vector<std::string> l = {std::format("SIP/2.0 {} {}", code, text)};
|
||||
for (auto v : imsd::sip::Headers(request, "Via")) l.push_back(std::format("Via: {}", v));
|
||||
if (auto f = imsd::sip::Header(request, "From")) l.push_back(std::format("From: {}", *f));
|
||||
|
|
@ -557,6 +585,7 @@ export namespace imsd::msg {
|
|||
}
|
||||
if (auto ci = imsd::sip::Header(request, "Call-ID")) l.push_back(std::format("Call-ID: {}", *ci));
|
||||
if (auto cs = imsd::sip::Header(request, "CSeq")) l.push_back(std::format("CSeq: {}", *cs));
|
||||
detail::AccessInfo(l, c, request, code);
|
||||
l.push_back("Content-Length: 0");
|
||||
return std::format("{}\r\n", detail::Join(l));
|
||||
}
|
||||
|
|
@ -564,25 +593,30 @@ export namespace imsd::msg {
|
|||
// The 400 to a request whose datagram ended before its body did (RFC
|
||||
// 3261 18.3), from the request's header section
|
||||
// (imsd::sip::CutShortRequest), as BuildResponse makes a final. imsd
|
||||
// keeps nothing of such a request, so the To tag is made from the
|
||||
// request itself, "in a manner that will generate the same tag for the
|
||||
// same request consistently" (8.2.7), and from `secret`, which the
|
||||
// keeps nothing of such a request, so the tag it adds to a To that holds
|
||||
// none is made from the request itself, "in a manner that will generate
|
||||
// the same tag for the same request consistently" (8.2.7), and from
|
||||
// `secret`, which the
|
||||
// caller draws once for the run: the randomness 19.3 asks of a tag. It
|
||||
// is the first sixteen hex digits of the MD5 of the secret and that
|
||||
// header section.
|
||||
// header section. The transport answers with it, without the
|
||||
// registration's context: it carries no P-Access-Network-Info.
|
||||
std::string BuildBadRequest(std::string_view head, std::string_view secret) {
|
||||
return BuildResponse({}, head, 400, "Bad Request", imsd::util::Md5::HexDigest(std::format("{}{}", secret, head)).substr(0, 16));
|
||||
}
|
||||
|
||||
// A 200 OK for an inbound request: echo Via/From/To/Call-ID/CSeq in order,
|
||||
// then either an SDP answer (with our Contact) or an empty body.
|
||||
// `extra` appends headers (Session-Expires echo for refreshes...).
|
||||
// `extra` appends headers (Session-Expires echo for refreshes...), and
|
||||
// P-Access-Network-Info follows them where the cell is known, unless
|
||||
// the request is a CANCEL.
|
||||
std::string BuildResponse200(const Context& c, std::string_view request, std::optional<std::string_view> sdp = std::nullopt, std::span<const std::string> extra = {}) {
|
||||
std::vector<std::string> l = {"SIP/2.0 200 OK"};
|
||||
for (std::string_view h : {"Via", "From", "To", "Call-ID", "CSeq"})
|
||||
if (auto v = imsd::sip::Header(request, h)) l.push_back(std::format("{}: {}", h, *v));
|
||||
for (const auto& e : extra)
|
||||
l.push_back(e);
|
||||
detail::AccessInfo(l, c, request, 200);
|
||||
if (sdp) {
|
||||
l.push_back(std::format("Contact: <sip:{}@{}>", ContactUser(c), imsd::util::HostPort(c.local, c.portUs)));
|
||||
l.push_back("Content-Type: application/sdp");
|
||||
|
|
|
|||
Loading…
Reference in a new issue