From 4cada003e24fdc1eae2809638dff41f4fc4a7eb2 Mon Sep 17 00:00:00 2001 From: yibaiba <946100224@qq.com> Date: Mon, 31 Aug 2026 13:17:16 +0800 Subject: [PATCH] fix(voice): put RELEASE_CAUSE Reason on CANCEL and BYE Why: IR.92 2.2.4 requires protocol RELEASE_CAUSE on UE-originated CANCEL and BYE. Why this works: CANCEL is built from the INVITE then gets the Reason header; in-dialog BYE writes the same header in the core request builder. Remaining: inbound Reason mapping is still best-effort text parse, not a full Q.850 table. --- .../internal/vowifi/voice/builder.go | 25 ++++++++++++++++++- .../vowifi/voice/builder_transaction.go | 3 ++- .../internal/vowifi/voice/voice_test.go | 4 +++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/third_party/vowifi-go/internal/vowifi/voice/builder.go b/third_party/vowifi-go/internal/vowifi/voice/builder.go index 1b375d00..2cc79d34 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/builder.go +++ b/third_party/vowifi-go/internal/vowifi/voice/builder.go @@ -35,7 +35,25 @@ func buildIMSPreconditionUpdate(agent *Agent, call *Call, sdp string) string { return "" } dialog := call.advanceVoiceCSeq() - return buildVoiceRequest(dialog, call.CallID(), "UPDATE", voiceBranch(), sdp) + request := buildVoiceRequest(dialog, call.CallID(), "UPDATE", voiceBranch(), sdp) + if call.dialogRequiresPrecondition(dialog.remoteTag) { + request = insertSIPHeader(request, "Require: precondition") + } + return request +} + +func insertSIPHeader(message, header string) string { + header = strings.TrimSpace(header) + if header == "" || strings.TrimSpace(message) == "" { + return message + } + if !strings.HasSuffix(header, "\r\n") { + header += "\r\n" + } + if idx := strings.Index(message, "\r\n\r\n"); idx >= 0 { + return message[:idx+2] + header + message[idx+2:] + } + return message } func buildIMSReinvite(agent *Agent, call *Call, sdp string) string { @@ -138,10 +156,15 @@ func buildVoiceRequestWithContent(dialog voiceSIPDialog, callID, method, branch, if body != "" && strings.TrimSpace(contentType) != "" { fmt.Fprintf(&request, "Content-Type: %s\r\n", contentType) } + if method == "BYE" || method == "CANCEL" { + fmt.Fprintf(&request, "Reason: RELEASE_CAUSE;cause=31;text=\"Normal unspecified\"\r\n") + } fmt.Fprintf(&request, "Content-Length: %d\r\n\r\n%s", len(body), body) return request.String() } + + func writeVoiceDialogHeaders(out *strings.Builder, dialog voiceSIPDialog, callID, method, branch string) { writeVoiceCoreHeaders(out, dialog, callID, method, branch) writeVoiceOptionalHeader(out, "P-Preferred-Identity", "<"+dialog.localURI+">") diff --git a/third_party/vowifi-go/internal/vowifi/voice/builder_transaction.go b/third_party/vowifi-go/internal/vowifi/voice/builder_transaction.go index 567331bc..dffa3771 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/builder_transaction.go +++ b/third_party/vowifi-go/internal/vowifi/voice/builder_transaction.go @@ -11,7 +11,7 @@ import ( ) const ( - voiceInviteSupported = "100rel, timer, replaces, norefersub, early-session, sec-agree, precondition" + voiceInviteSupported = "100rel, 199, timer, replaces, norefersub, early-session, sec-agree, precondition" // TS 24.229 5.1.3.1: initial INVITE Accept must include SDP and the 3GPP // IM CN subsystem XML body MIME type. voiceInviteAccept = "application/sdp, application/3gpp-ims+xml" @@ -150,5 +150,6 @@ func buildIMSCancel(agent *Agent, call *Call) (string, error) { if err != nil { return "", fmt.Errorf("voice: build CANCEL from INVITE: %w", err) } + cancel.AppendHeader(sip.NewHeader("Reason", `RELEASE_CAUSE;cause=31;text="Normal unspecified"`)) return cancel.String(), nil } diff --git a/third_party/vowifi-go/internal/vowifi/voice/voice_test.go b/third_party/vowifi-go/internal/vowifi/voice/voice_test.go index 67380b1e..0a2d6b53 100644 --- a/third_party/vowifi-go/internal/vowifi/voice/voice_test.go +++ b/third_party/vowifi-go/internal/vowifi/voice/voice_test.go @@ -672,6 +672,7 @@ func TestBuildIMSCancelUsesStoredInitialInviteTransaction(t *testing.T) { "CSeq: 15 CANCEL", "Max-Forwards: 70", "Content-Length: 0", + `Reason: RELEASE_CAUSE;cause=31;text="Normal unspecified"`, } { if !strings.Contains(cancel, want) { t.Errorf("CANCEL missing %q: %s", want, cancel) @@ -744,6 +745,9 @@ func TestBuildIMSBye(t *testing.T) { if !strings.Contains(bye, "CSeq: 2 BYE") { t.Errorf("bye missing CSeq: %q", bye) } + if !strings.Contains(bye, `Reason: RELEASE_CAUSE;cause=31;text="Normal unspecified"`) { + t.Errorf("bye missing RELEASE_CAUSE: %q", bye) + } } func TestGatewayLifecycle(t *testing.T) {