FreePBX currently maps the Q.850 causes received from the carrier to generic SIP responses (e.g. 503), which causes us to lose the original operator cause code.
We have done several researches and attempted to customize Asterisk (custom dialplan, FreePBX hooks, handling of HANGUPCAUSE / PJSIP_CAUSE), but without conclusive results, as FreePBX still returns a generic SIP error to the SIP client.
We also implemented an application-side requalification logic, but this introduces significant server load since each call requires querying the VoIP server.
Our goal is to directly propagate the original SIP/Q.850 cause received by FreePBX to the SIP client, without remapping it to SIP 503.
What would be the recommended approach in FreePBX / Asterisk (PJSIP) to preserve and forward the original hangup cause?
Change the source code of Asterisk. Note that the SIP codes are not generic; they mainly follow the RFC that specifies how to map between SIP and ISDN.
The process is pretty much: If there is a Q.850 reason code, set hangup cause to that, otherwise use rules close to those in the RFC to map the SIP cause code to the equivalent Q.850 one. Then on the other side, use the RFC to map the hangup cause to the nearest SIP cause, and add a Reason header giving both the hangupcause, and the translation of it to SIP.
To clarify: does this behavior (systematic remapping to SIP 503 and loss of the original Q.850 cause) come from Asterisk core / chan_pjsip, or from a FreePBX-specific layer?
In other words, is there any way to preserve and forward the original cause without modifying Asterisk source code?