PJSIP not passing correct SIP code to endpoint

I have an asterisk 15.5 with PJSIP configured with two endpoints: 1 sip trunk and 1 sip extension. When placing a call from extension through that trunk, and destination number is not in service, from the trunk I receive a 404 but PJSIP reply to my extension with a 503, that is not precise as much as I need.

00017 1544111045 * <== #.#.5.12:5060          SIP/2.0 404 Not Found
00018 1544111045 * ==> #.#.5.12:5060          ACK sip:092532145@#.#.5.12:5060 SIP/2.0
00019 1544111045 * ==>      SIP/2.0 503 Service Unavailable

Is there any documented/undocumented settings I can configure to refer to the extension the exact failure code?

There is no configuration, but the Hangup application accepts a cause code[1] and there are methods to query the cause codes of the outgoing side. As for why it didn’t forward the 404, it’s because to the calling party the extension was found in Asterisk.

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

Behind that extension there is a webrtc client that needs to know the 404 failure code. How can I get that? You talked about methods to query cause codes? How?

There are dialplan functions[1] to inspect and the wiki contains a mapping[2].

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

You are incredible! Thank you very much! You saved my day. Wish I had a better way to thank you

Is their a way to set the header Reason in the bye message .

For example i want to reply with release cause 88 or 34 .

I need to add “Reason: Q.850;cause=34” to the bye message .

currently we are limited to https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause+Mappings which does not have 34 or 88


The translation tables are only relevant when you are providing or generating a SIP cause. To generate 88, simply do Hangup(88).

However note that codes in BYE are of limited use, as must codes are only really meaningful when the call has not been answered.

hello @david551

I am doing Hangup(88) but it is returning 503 without having the header

Reason: Q.850;cause=88

So my switch can’t differentiate between different 503 sip return.

I assumed it was sending Reason. If it is not sending Reason, setting an explicit reason won’t make a difference.

hello , i just found that i needed to set use_q850_reason=yes in sip.conf .

After doing that Hangup(88) is sending Reason in bye message correctly

SIP/2.0 603 Declined
Via: SIP/2.0/UDP X.X.X.X:5060;branch=z9hG4bK0cBa3bfd57ff84ed396;received=X.X.X.X
From: <sip:12341234@X.X.X.X>;tag=gK0c0847bc
To: <sip:188@>;tag=as1e709a18
Call-ID: 453786638_133767760@X.X.X.X
CSeq: 907897 INVITE
Server: Asterisk PBX 16.3.0
Supported: replaces, timer
Session-Expires: 1800;refresher=uas
Reason: Q.850;cause=88
Content-Length: 0