Converting SIP to PJSIP , i need DIALSTATUS ? is it changed?

Hey, see below, i have this in my dialplan

I first send a push message to activate the registraion on my android, i wait 3 sec , then i dial
When i answer, all is fine

When i decline the call , it should go to line 11 => hangup, this was working on chan_sip
Now i use PJSIP, i decline the call, it starts ringing again… seems the BUSY status is different?

exten => s,1,Set(CURL_RESULT=${SHELL(curl -X POST -H "Content-Type: application/json" -d '{ "user" : "notify.registration" }' http://webhook)})
exten => s,2,Wait(3)
exten => s,3,Dial(PJSIP/6000,45)
exten => s,4,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?9)
exten => s,5,GotoIf($[${DIALSTATUS} = NOANSWER]?11)
exten => s,6,GotoIf($[${DIALSTATUS} = CONGESTION]?11)
exten => s,7,GotoIf($[${DIALSTATUS} = BUSY]?11)
exten => s,8,GotoIf($[${DIALSTATUS} = CANCEL]?11)
exten => s,9,Wait(2)
exten => s,10,Dial(PJSIP/6000,45)
exten => s,11,Hangup()
exten => s,12,NoOp(reporting noanswer returning to caller)
exten => s,13,Verbose(2, Dial status ${DIALSTATUS})

thnx for the info

It works the same. You’d need to provide what is actually happening for anyone to be able to provide any further information.

Here you go,

Here is where i declined the call

[Mar 18 12:26:40] == Everyone is busy/congested at this time (1:0/0/1)

Then it starts ringing again :slight_smile:



[Mar 18 12:26:31]     -- Added contact 'sip:6001@192.168.0.232;transport=udp' to AOR '6001' with expiration of 3600 seconds
[Mar 18 12:26:31]   == Endpoint 6001 is now Reachable
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100    48    0     0  100    48      0  24000 --:--:-- --:--:-- --:--:-- 24000
[Mar 18 12:26:34]     -- Executing [s@default:1] Set("PJSIP/6001-00000000", "CURL_RESULT=") in new stack
[Mar 18 12:26:34]     -- Executing [s@default:2] Wait("PJSIP/6001-00000000", "3") in new stack
[Mar 18 12:26:35]     -- Added contact 'sip:6000@192.168.0.168:48484;transport=udp' to AOR '6000' with expiration of 3600 seconds
[Mar 18 12:26:35]   == Endpoint 6000 is now Reachable
[Mar 18 12:26:37]     -- Executing [s@default:3] Dial("PJSIP/6001-00000000", "PJSIP/6000,45") in new stack
[Mar 18 12:26:37]     -- Called PJSIP/6000
[Mar 18 12:26:38]     -- PJSIP/6000-00000001 is ringing
[Mar 18 12:26:40]   == Everyone is busy/congested at this time (1:0/0/1)
[Mar 18 12:26:40]     -- Executing [s@default:4] GotoIf("PJSIP/6001-00000000", "1?9") in new stack
[Mar 18 12:26:40]     -- Goto (default,s,9)
[Mar 18 12:26:40]     -- Executing [s@default:9] Wait("PJSIP/6001-00000000", "2") in new stack
[Mar 18 12:26:42]     -- Executing [s@default:10] Dial("PJSIP/6001-00000000", "PJSIP/6000,45") in new stack
[Mar 18 12:26:42]     -- Called PJSIP/6000
[Mar 18 12:26:42]     -- PJSIP/6000-00000002 is ringing
[Mar 18 12:26:48]   == Everyone is busy/congested at this time (1:0/0/1)
[Mar 18 12:26:48]     -- Executing [s@default:11] Hangup("PJSIP/6001-00000000", "") in new stack
[Mar 18 12:26:48]   == Spawn extension (default, s, 11) exited non-zero on 'PJSIP/6001-00000000'

What is the actual SIP signaling? (pjsip set logger on). What is the actual value of DIALSTATUS?

hmm, not sure, dont see a dialstatus there?

<--- Transmitting SIP request (437 bytes) to UDP:192.168.0.168:48484 --->
OPTIONS sip:6000@192.168.0.168:48484;transport=udp SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;rport;branch=z9hG4bKPje341024d-f2ba-4e7b-a203-799149ce478e
From: <sip:6000@192.168.0.17>;tag=2290d7de-173b-44ab-95ac-e42ec00deafa
To: <sip:6000@192.168.0.168>
Contact: <sip:6000@192.168.0.17:5060>
Call-ID: 3bbe9572-8af9-4189-9016-88146908e2e1
CSeq: 4630 OPTIONS
Max-Forwards: 70
User-Agent: Asterisk PBX 18.10.1
Content-Length:  0


<--- Received SIP response (391 bytes) from UDP:192.168.0.168:49765 --->
SIP/2.0 603 Decline
Via: SIP/2.0/UDP 192.168.0.17:5060;rport;branch=z9hG4bKPj2003b04c-aae1-4fea-8e96-c14b43efa7c5
From: "6001" <sip:6001@192.168.0.17>;tag=87b4e705-69d2-4191-91ae-8a404621569f
To: <sip:6000@192.168.0.168>;tag=Qw4q2tw
Call-ID: 1c8f6c4d-b3ea-4108-a2b1-4021d6353abd
CSeq: 6704 INVITE
User-Agent: LinphoneAndroid/2.1.730 (belle-sip/1.6.3)
Supported: replaces, outbound


<--- Transmitting SIP request (409 bytes) to UDP:192.168.0.168:49765 --->
ACK sip:6000@192.168.0.168:49765;transport=udp SIP/2.0
Via: SIP/2.0/UDP 192.168.0.17:5060;rport;branch=z9hG4bKPj2003b04c-aae1-4fea-8e96-c14b43efa7c5
From: "6001" <sip:6001@192.168.0.17>;tag=87b4e705-69d2-4191-91ae-8a404621569f
To: <sip:6000@192.168.0.168>;tag=Qw4q2tw
Call-ID: 1c8f6c4d-b3ea-4108-a2b1-4021d6353abd
CSeq: 6704 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 18.10.1
Content-Length:  0


  == Everyone is busy/congested at this time (1:0/0/1)
    -- Executing [s@default:4] GotoIf("PJSIP/6001-00000000", "1?9") in new stack
    -- Goto (default,s,9)
    -- Executing [s@default:9] Wait("PJSIP/6001-00000000", "2") in new stack
<--- Received SIP request (820 bytes) from UDP:192.168.0.168:49765 --->
REGISTER sip:192.168.0.17 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.168:49765;branch=z9hG4bK.qC-Ste1on;rport
From: <sip:6000@192.168.0.17>;tag=0tL1I8E91
To: sip:6000@192.168.0.17
CSeq: 23 REGISTER
Call-ID: cvJnDUJ3Eh
Max-Forwards: 70
Supported: replaces, outbound
Accept: application/sdp
Accept: text/plain
Accept: application/vnd.gsma.rcs-ft-http+xml
Contact: <sip:6000@192.168.0.168:49765;transport=udp>;+sip.instance="<urn:uuid:dc2169e5-5870-4374-8d64-1cdb1c9efc6b>"
Expires: 3600
User-Agent: LinphoneAndroid/2.1.730 (belle-sip/1.6.3)

You would need to adjust the dialplan in order to print out the value, for example using NoOp.

ah, i need to add this ath the top?

exten => s,1,NoOp(#### [default] ####)

sorry new to me :slight_smile:

I’ve dug in a bit. From looking at the code stuff should be working, but it’s seemingly not. You can file an issue[1]. You’ll need to provide specific dialplan as well as the SIP trace. There is no time frame on when it would get looked into. You could see in the mean time if the hangup cause functionality[2] could be used instead. If you don’t know/understand dialplan though, you’re probably going to run into issues with it however.

[1] System Dashboard - Digium/Asterisk JIRA
[2] Hangup Cause - Asterisk Project - Asterisk Project Wiki

ok, maybe i can do it the other way around, seems if i decline

this line is activated :

exten => s,5,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?12)

I used that line on chan_sip before, it the endpoint was not registered, in that case it did a retry

Is there maybe aonther wat like the line above, that i can use to find out if 6000 is registered or not?

There is the DEVICE_STATE dialplan function[1].

[1] Asterisk 19 Function_DEVICE_STATE - Asterisk Project - Asterisk Project Wiki

ok thnx ill have a look

hmm not 100% clear to be

is it enough if i convert this:

exten => s,8,GotoIf($[${DIALSTATUS} = BUSY]?10)

to
exten => s,8,GotoIf($[${DEVICE_STATE} = BUSY]?10)

You need this after the Dial() so you can read what Asterisk set the dial status to.

Noop(Dial status: ${DIALSTATUS})

Device state tells you the state of the endpoint, not the channel.

Device state can help you retry if the device is not online, but won’t help you if you declined the call.

Ah ok, any idea then how I can intercept the decline some other way?

Yes, you can use HANGUPCAUSE_KEYS to retrieve the actual SIP response sent by the endpoint after the dial fails:

same => n,Set(HANGUPCAUSEKEYS=${HANGUPCAUSE_KEYS()})
same => n,GotoIf($[${LEN(${HANGUPCAUSEKEYS})}=0]?logError)
same => n,Set(ARRAY(item)=${HANGUPCAUSEKEYS})
same => n,Set(SIPCAUSE=${HANGUPCAUSE(${item},tech)})
same => n,Set(SIPCAUSECODE=${CUT(SIPCAUSE, ,2)})
same => n,GotoIf($["${SIPCAUSECODE}" != “603”]?callDeclined)

same => n(callDeclined),

HANGUPCAUSE will return something like “SIP 603 Decline”, so we have to use CUT to extract the 2nd item in the space-delimited string in order to get the integer response code.

BTW, you don’t have to number all the lines in your subroutine. Just use ‘exten’ on the first line, then use the “same => n,” syntax on all the others. If you need to jump to a specific line, you can give it a label after the “n” like I did with callDeclined there.

aha, thats interesting info, something for next week

thnx in advance

hey, was working back on this one

is it maybe possible to provide your full example?

Was just testing below, so when 6000 declines, it should redial?

is that ok?

exten => 2,1,Dial(PJSIP/6000,45)
 same => n,Set(HANGUPCAUSEKEYS=${HANGUPCAUSE_KEYS()})
 same => n,GotoIf($[${LEN(${HANGUPCAUSEKEYS})}=0]?logError)
 same => n,Set(ARRAY(item)=${HANGUPCAUSEKEYS})
 same => n,Set(SIPCAUSE=${HANGUPCAUSE(${item},tech)})
 same => n,Set(SIPCAUSECODE=${CUT(SIPCAUSE, ,2)})
 same => n,GotoIf($["${SIPCAUSECODE}" != "603"]?callDeclined)
 same => n(callDeclined)
 same => n,Wait(3)
 same => n,Dial(PJSIP/6000,45)

I’m not sure you can have a priority without an action.

GotoIf only to the next priority is pretty pointless.

A true target name that implies the reverse of the actual condition is very confusing.

There may be problems with the extraction of the cause code, but I’m not familiar enough with that to check it.