LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problems with cancelling a SIP "call" (https://www.linuxquestions.org/questions/programming-9/problems-with-cancelling-a-sip-call-4175612650/)

maduino 08-26-2017 06:23 AM

Problems with cancelling a SIP "call"
 
Hi,

I want to ring my IP phone. Therefore I wrote a simple PHP script which talks to my VoIP router. The phone rings as it should but when I send the "CANCEL" request the router always answers with "481 Call Leg/Transaction Does Not Exist" and the phone continues ringing. I check the Call-ID, CSeq and other ids a dozen times but everything seems to match. I also tried a "normal" VoIP client software, captured the data with Wireshark and compared them and found nothing wrong.

Does anyone have an idea where my mistake is? You'll find the complete data below. The router has IP 192.168.0.1 and the calling device has IP 192.168.0.2. The number "**100" is called (internal number).

Regards!

Code:

---- SENDING ----
INVITE sip:**100@192.168.0.1 SIP/2.0
Call-ID: 1319899383
CSeq: 1 INVITE
Max-Forwards: 70
From: "frank" <sip:frank@192.168.0.1>;tag=831859804
Via: SIP/2.0/UDP 192.168.0.2:5060; branch=30b863aa5f9597a118184e78f0646663;rport
To: <sip:**100@192.168.0.1>
Contact: "frank" <sip:frank@192.168.0.2:5060;transport=udp>
Content-Type: application/sdp
Content-Length: 0
----------------

    ---- RESPONSE (192.168.0.1 : 5060) ----
    SIP/2.0 401 Unauthorized
    Via: SIP/2.0/UDP 192.168.0.2:5060;branch=30b863aa5f9597a118184e78f0646663;rport=5060
    From: "frank" <sip:frank@192.168.0.1>;tag=831859804
    To: <sip:**100@192.168.0.1>;tag=7746866CE2755421
    Call-ID: 1319899383
    CSeq: 1 INVITE
    WWW-Authenticate: Digest realm="fritz.box", nonce="487B9755959CA211"
    User-Agent: FRITZ!OS
    Content-Length: 0
    ----------

---- SENDING ----
ACK sip:**100@192.168.0.1 SIP/2.0
Call-ID: 1319899383
CSeq: 1 ACK
Max-Forwards: 70
From: "frank" <sip:frank@192.168.0.1>;tag=831859804
Via: SIP/2.0/UDP 192.168.0.2:5060; branch=30b863aa5f9597a118184e78f0646663;rport
To: <sip:**100@192.168.0.1>
Content-Length: 0
---------------

---- SENDING ----
INVITE sip:**100@192.168.0.1 SIP/2.0
Call-ID: 1319899383
CSeq: 2 INVITE
Max-Forwards: 70
From: "frank" <sip:frank@192.168.0.1>;tag=831859804
Via: SIP/2.0/UDP 192.168.0.2:5060; branch=30b863aa5f9597a118184e78f0646663;rport
To: <sip:**100@192.168.0.1>
Contact: "frank" <sip:frank@192.168.0.2:5060;transport=udp>
Content-Type: application/sdp
Authorization: Digest username="frank", realm="fritz.box", nonce="487B9755959CA211", uri="sip:**100@192.168.0.1", response="edf..."
Content-Length: 0
---------------

    ---- RESPONSE (192.168.0.1 : 5060) ----
    SIP/2.0 100 Trying
    Via: SIP/2.0/UDP 192.168.0.2:5060;branch=30b863aa5f9597a118184e78f0646663;rport=5060
    From: "frank" <sip:frank@192.168.0.1>;tag=831859804
    To: <sip:**100@192.168.0.1>
    Call-ID: 1319899383
    CSeq: 2 INVITE
    User-Agent: AVM FRITZ!Box
    Content-Length: 0
    ----------

    ---- RESPONSE (192.168.0.1 : 5060) ----
    SIP/2.0 183 Session Progress
    Via: SIP/2.0/UDP 192.168.0.2:5060;branch=30b863aa5f9597a118184e78f0646663;rport=5060
    From: "frank" <sip:frank@192.168.0.1>;tag=831859804
    To: <sip:**100@192.168.0.1>;tag=3812AB5062EEB99C
    Call-ID: 1319899383
    CSeq: 2 INVITE
    Contact: <sip:8C3E39F1BF28E5EA45607813E6C96@192.168.0.1>
    User-Agent: AVM FRITZ!Box
    Content-Type: application/sdp
    Content-Length: 355

    ...
    ----------

---- SENDING ----
CANCEL sip:**100@192.168.0.1 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.2:5060;branch=30b863aa5f9597a118184e78f0646663;rport
From: "frank" <sip:frank@192.168.0.1>;tag=831859804
To: <sip:**100@192.168.0.1>
Call-ID: 1319899383
CSeq: 2 CANCEL
Content-Length: 0
---------------

    ---- RESPONSE (192.168.0.1 : 5060) ----
    SIP/2.0 481 Call Leg/Transaction Does Not Exist
    Via: SIP/2.0/UDP 192.168.0.2:5060;branch=30b863aa5f9597a118184e78f0646663;rport=5060
    From: "frank" <sip:frank@192.168.0.1>;tag=831859804
    To: <sip:**100@192.168.0.1>
    Call-ID: 1319899383
    CSeq: 2 CANCEL
    User-Agent: FRITZ!OS
    Content-Length: 0
    ----------


astrogeek 08-30-2017 03:52 PM

I have zero knowledge of SIP protocol, but as no one else has stepped up I will offer the results of my own quick search.

Using the search term "481 Call Leg/Transaction Does Not Exist" as a starting point and DuckDuckGo search engine, I find many potentially helpful pages. This one from asterisk.org stands out as applicable on a quick scan, from which:

Quote:

I looked over the RFC 3261 and saw that
"The following procedures are used to construct a CANCEL request. The
Request-URI, Call-ID, To, the numeric part of CSeq, and From header
fields in the CANCEL request MUST be identical to those in the
request being cancelled, including tags. ..."
Those headers differ between the initial INVITE and the CANCEL requests in your example.

As there appears to be a shortage of SIP programmers participating here, you may get better response from any active VoIP forum - there appear to be many!

Good luck!

aurelian_15 12-31-2017 11:00 AM

Just ran into exactly the same problem while trying to ring all phones connected to a Fritz!Box in response to an home-automation event. The solution is to prefix the "branch" id with the magic cookie "z9hG4bK" to signal compliance with the specification.

See https://github.com/astoeckel/femtosi...er/femtosip.py for a working example.


All times are GMT -5. The time now is 08:04 PM.