Send a custom SIP response code (PJSIP)


#1

Hi Team,

I have to send a custom SIP response code (compliant to RFC3261) to the calling party on a specific condition (defined by a value of a dialplan variable). Do you know if there is any way to achieve it with dialplan functions?
For instance, something like this:

exten => s,n,Set(ResponseCode=<VALUE>)

If this is supported, could you provide the correct syntax?
Thank you.

P.S. Asterisk 13.21, PJSIP channel drvier.


#2

You can only send the response codes that correspond to defined values of ${HANGUPCAUSE}. That value will be translated to the actual SIP response used.


#3

Thank you @david551
What is the correct syntax for that operation?
exten => s,n,HangUp(${HANGUPCAUSE}) ?


#4

Put the literal value of the desired hangup cause in the Hangup call. Note that the value is the ISDN cause code that corresponds to the SIP response, not the actual SIP response.

(Hangup() is equivalent to Hangup(${HANGUPCAUSE}), but I’m not sure that you can set that “variable”.


#5

The HANGUPCAUSE dialplan variable is special, it gets the data from the channel when asked. While you may be able to set the variable it won’t do anything and can’t be retrieved afterwards.


#6

@jcolp
So, what’s the conclusion? Is it possible to send a custom response code, not referring to HANGUPCAUSE variable?
For instance:
exten => s,n,HangUp(<Q931 code>)


#7

Yes, as @david551 mentioned you can specify an ISDN cause code there as a custom one and it will get translated into a SIP response code. You can’t specify a SIP one there. There is also a mapping[1] on the wiki for the translation. Oh, and the dialplan application is documented to work like this on there too[2].

[1] https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause+Mappings
[2] https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Application_Hangup