In Dial-plan how to detect SIP response 4xx/5xx/6xx

I want to detect 4xx/5xx/6xx SIP response error and want to trigger context in dial-plan. How it is possible ?

I think you can’t get the SIP code responses in the dialplan, you have to use the DIALSTATUS variable.

See if this answers your question: How to check the result of the Dial application

Hangup cause[1] allows inspection of protocol specific information.

[1] Hangup Cause - Asterisk Project - Asterisk Project Wiki

Yes, I looked at Hangup cause and It seems it will do what I want.

But in my case, I am using call files to add end-point into a conference.

How I can create a hangup cause handler for the end-point before end-point ANSWER?

Channel: SIP/1332
MaxRetries: 0
RetryTime: 30
WaitTime: 20

Context: DialOut
Extension: s
Priority: 1

Callerid: 8333

Here , I want to create hangup cause handler for SIP/1332 , But I could not create it untill it ANSWER

Make the A side a local channel.

Hi David , I am new to asterisks. Can you post any example or link? It will help me.


1 Like

If you are referring to adding a hangup handler[1] then you can use the variables functionality in call files to set one.

[1] Hangup Handlers - Asterisk Project - Asterisk Project Wiki

1 Like

Do you mean that by setting an appropriate variable in call files, It is possible to create a handler ?
Can you tell me which channel variable require to set?

You can use dialplan functions alongside variables in call files. The wiki page I’ve linked includes example usage in the dialplan, but it can also be used in call files.

1 Like

I added the below lines to call files and now it is working.
Set: CHANNEL(hangup_handler_push)=hangcausehandler,s,1

Getting code 21 for call rejection

– Executing [s@hangcausehandler:2] Verbose(“SIP/9003-00000003”, “2, #####hangup cause: 21”) in new stack
== #####hangup cause: 21
– Executing [s@hangcausehandler:3] Verbose(“SIP/9003-00000003”, “2, #####hangup cause: SIP/9003-00000003”) in new stack
== #####hangup cause: SIP/9003-00000003

No, I’m telling you that, by using a local channel, you can run dialplan which can do what you want.

You can use the failed function in dialplan, if any call failed due to any cause code it will go in failed context.


Is there any function available in dial-plan for converting ISDN hangup cause code to SIP equivalent ?
Hard-coded mapping is required to implement in dial-plan ?

Any link to an example is welcome!

This isn’t core functionality, it’s up to the SIP channel drivers to do it, and they do not provide a dialplan function for such a conversion.

To further clarify, Asterisk uses ISDN cause codes internally and these are translated to SIP codes, automatically, when sending a a SIP response. The reverse happens when Asterisk receives a SIP response code.

In Dialplan, How can I receive equivalent SIP codes? I am able to received ISDN cause code properly.

I gave you a link to the wiki for such functionality in your other thread. It allows protocol specific, such as SIP response code, access.

What problem are you trying to solve?

Asterisk can provide the actual SIP codes, but there is no capability to return to the dialplan user what would be used if the current technology, at the time the channel was actually hung up, was SIP or PJSIP. (although possibly not common, the A side of a call can be redirected from SIP to, say, DAHDI, and vice versa, so the technology at the time of hang up may not be that when the dialplan looks at the ISDN cause code).

All translations are lossy and I don’t think sip2cause(cause2sip(x)) is always a 1:1 mapping.

I have to terminate conference when there is 4xx/5xx/6xx SIP error from callee while SIP INVITE sent to callee to join conference.