P-Preferred-Identity for SIP and PJSIP

i got a problem with my SIP Extenions.
Asterisk 13.32.0

all my extensions are PJSIP Port 5060. My SIP-Trunk is Port 5060.

I added a SIP Extension now (Port 5160). Incoming Calls, no problem. Outgoing calls working only 10%.
Why?
I figured out it has to do sth with p-prefered-identity. When I add the Asterisk Trunk Dial Options in my Trunk with the Code:

[custom-sip-header]
exten => s,1,Noop(entering user defined context custom-sip-header in extensions_custom.conf)
exten => s,n,SIPAddHeader(P-Preferred-Identity: sip:${CALLERID(number)}@fpbx.de)
exten => s,n,Return

i get this warning when i dial out via SIP (5160) (Not when i dial out via PJSIP)

[2020-11-18 17:04:20] WARNING[2142][C-00000075]: chan_sip.c:24167 handle_response_invite: Received response: “Forbidden” from ‘“Test” sip:[email protected]:5160;tag=as4f3cfef7’

What gets my attention is, that the Port at the end of the URI is 5160. My trunk is but configured to use port 5060.
Is this the error why the calls are not working?

Hi @HansMax,

This is the right way to add custom sip headers to your trunks with the GUI:

[custom-sip-header]
; Add B(custom-sip-header^s^1) to the dial options of a trunk in addition to the defaults already there
; This only affects calls on specific trunks
exten => s,1,Noop(entering user defined context custom-sip-header in extensions_custom.conf)
exten => s,n,Set(HASH(__SIPHEADERS,P-Preferred-Identity)=sip:${CALLERID(num)}@fpbx.de)
;exten => s,n,Set(HASH(__SIPHEADERS,P-Asserted-Identity)=sip:[email protected])
exten => s,n,Return

Thank you,

Daniel Friedman
Trixton LTD

^^ that technique won’t work with PJSIP trunks, as the B dial parameter is on the calling channel, not the called channel. You would want the b parameter, but you can’t use that either because FreePBX is already using that internally.

Adding custom SIP headers has been a moving target for years. Most of the techniques I’ve posted in the past are all broken now. The current supported way of adding channel agnostic custom SIP headers is using the method in this post: Custom SIP header on outgoing calls

2 Likes

Hello @lgaetz,

I am using this method for a long time and it is working well because I am adding the SIP header to the outgoing call directly to the array of SIPHEADERS. I agree that in some cases it may clash with the regular dialplan, and in that case I will add the SIP header to the macro dialplan hook.

I wish that one day, the outbound routing module will be more customizable for better integration with various SIP providers and gateways/proxies.

Thank you,

Daniel Friedman
Trixton LTD.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.