SIP 客户端在取消时响应 481

SIP Client Responding 481 on CANCEL

我正在尝试为移动设备编写 SIP 客户端。我为 android 使用 PJSIP,为 iOS 使用 Linphone。有时客户会响应 481 请求合法的取消。

我阅读了 RFC 3261 第 9.1 节并试图了解为什么客户端与对话框不匹配。但据我所知,请求 URI 匹配,Call-ID header、包含标记的 To header 和 Cseq[=11 的数字部分也是如此=]

INVITE sip:#######@127.0.0.0 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-197747523180-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>
Max-Forwards: 68
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204936 INVITE
Contact: <sip:##########@127.0.0.1>
User-Agent: Server UAS
Allow: ACK,BYE,CANCEL,INVITE,REGISTER,UPDATE,MESSAGE,INFO,OPTIONS,SUBSCRIBE,NOTIFY,REFER,COMET,PUBLISH,PING,DO
Allow-Events: presence,refer,telephone-event,keep-alive,dialog,message-summary
Supported: privacy,replaces
Accept: application/sdp,application/dtmf-relay,audio/telephone-event,message/sipfrag,text/plain,text/html
Content-Disposition: session;handling=required
Content-Type: application/sdp
Content-Length: 521

v=0
o=root 1954582096 1954582096 IN IP4 127.0.0.2
s=Sonus_UAC
c=IN IP4 127.0.0.1
t=0 0
m=audio 10852 RTP/AVP 0 9 8 18 10 3 111 5 7 110 97 101
a=rtpmap:0 PCMU/8000
a=rtpmap:9 G722/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:10 L16/8000
a=rtpmap:3 GSM/8000
a=rtpmap:111 G726-32/8000
a=rtpmap:5 DVI4/8000
a=rtpmap:7 LPC/8000
a=rtpmap:110 speex/8000
a=rtpmap:97 iLBC/8000
a=fmtp:97 mode=30
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=sendrecv

SIP/2.0 100 Trying
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-197747523180-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: sip:#######@127.0.0.0
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204936 INVITE

SIP/2.0 180 Ringing
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-197747523180-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>;tag=43ye8Yn
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204936 INVITE
User-Agent: belle-sip/1.6.3
Supported: replaces, outbound

CANCEL sip:#######@127.0.0.0 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-171352412518-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>
Max-Forwards: 68
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204936 CANCEL
User-Agent: Server UAS
Warning: 399 127.0.0.0 "Cancel received (0x15) (4007)"
M-Stat: s:0 r:0 l:0 es:0 er:0 el:0
Content-Length: 0

BYE sip:#######@127.0.0.0 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-151544386511-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>;tag=43ye8Yn
Max-Forwards: 68
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204937 BYE
User-Agent: Server UAS
Warning: 399 127.0.0.0 "Cancel received (0x15) (4007)"
M-Stat: s:0 r:0 l:0 es:0 er:0 el:0
Content-Length: 0

SIP/2.0 481 Call/transaction does not exist
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-171352412518-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>;tag=K4PcWbb
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204936 CANCEL

SIP/2.0 501 Not implemented
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-151544386511-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>;tag=43ye8Yn
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204937 BYE

CANCEL sip:#######@127.0.0.0 SIP/2.0
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-171352412518-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>
Max-Forwards: 68
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204937 CANCEL
User-Agent: Server UAS
Warning: 399 127.0.0.0 "Cancel received (0x15) (4007)"
M-Stat: s:0 r:0 l:0 es:0 er:0 el:0
Content-Length: 0

SIP/2.0 481 Call/transaction does not exist
Via: SIP/2.0/UDP 127.0.0.1:5060;rport;branch=z9hG4bK-171352412518-702327557205
From: "WIRELESS CALLER" <sip:##########@my.sipserver.com>;tag=a410144978468667
To: <sip:#######@127.0.0.0>;tag=azviy
Call-ID: 0ce8e8201a70540029d0ec3402005633@127.0.0.2:5060-b4-3551-277
CSeq: 204937 CANCEL

出于隐私原因,我删除了识别详细信息。

取消请求有一项额外要求(RFC3261 第 9.1 章):

A CANCEL constructed by a client MUST have only a single Via header field value matching the top Via value in the request being cancelled. Using the same values for these header fields allows the CANCEL to be matched with the request it cancels

当 UAS 收到 CANCEL 请求时,它必须找到相应的 INVITE 服务器事务。 RFC3261 第 9.2 章:

The TU determines the transaction to be cancelled by taking the CANCEL request, and then assuming that the request method is anything but CANCEL or ACK and applying the transaction matching procedures of Section 17.2.3. The matching transaction is the one to be cancelled.

匹配条件之一是 CANCEL 请求顶部 Via header 中的分支参数:它必须与创建服务器事务的 INVITE 请求中的参数相同。由于你的INVITE和CANCEL请求中的branch参数不同,导致UAS找不到服务端事务,取消INVITE。