Set P-Asserted-Identity (pjsip)

I would guess that this:

[macro-dialout-trunk-predial-hook]
exten => s,1,GoSub(func-set-sipheader,s,1(P-Asserted-Identity,<sip:[email protected]>))
exten => s,n,Return

should do that.

Yet…
ngrep -d ens19 -p -q -W byline port 5060
…keeps showing the default CID.

Am I getting the syntax wrong?

and like every so often I fix my problem minutes after posting them: Contrary to the telco’s howto, send PAI must be OFF in the trunk! Sorry for using you all for rubberducking..:wink:

The correct way is to enable PAI, and set the caller ID. Is there some reason why that option isn’t open to you?

fair point! But the telco want’s the cid in PAI for clip no screening

(which we heavily rely on for on call)

OK heres what we have done

extensions_override_freepbx.conf
Fix to set the P-Preferred-Identityheader of the outbound call

[func-apply-sipheaders]
include => func-apply-sipheaders-custom
exten => s,1,Noop(Applying SIP Headers to channel ${CHANNEL} ${CALLERIDNUMINTERNAL} ${CALLERID(number)} ${CDR(outbound_cnum)} ${CALLERID(num)} ${CALLERID(all)})
exten => s,n,Set(localchan=${CUT(CHANNEL,/,2)})
exten => s,n,Set(DialMCEXT=${CUT(localchan,-,1)})
exten => s,n,Set(CHANNEL(hangup_handler_push)=app-missedcall-hangup,${DialMCEXT},1)
exten => s,n,Set(TECH=${CUT(CHANNEL,/,1)})
;we set the callerid length variable so we can check its external caller id
;as could be internatonal had to have flexability
exten => s,n,Set(PPI=${LEN(${CALLERIDNUMINTERNAL})})
exten => s,n,Noop(${PPI})
exten => s,n,Set(SIPHEADERKEYS=${HASHKEYS(SIPHEADERS)})
;We check that its PJSIP and the correct trunk and the callerid to set to a length longer than extensions before setting the PPI
exten => s,n,ExecIf($[“${TECH}” = “PJSIP” & “${DialMCEXT}” = “TRUNK-USERNAME” & ${PPI} > 9]?Set(PJSIP_HEADER(add,P-Preferred-Identity)=sip:${[CALLERIDNUMINTERNAL}@sv2.sip.vu](mailto:CALLERIDNUMINTERNAL}@sv2.sip.vu)))
exten => s,n,While($[“${SET(sipkey=${SHIFT(SIPHEADERKEYS)})}” != “”])
exten => s,n,Set(sipheader=${HASH(SIPHEADERS,${sipkey})})
exten => s,n,ExecIf($[“${sipheader}” = “unset” & “${TECH}” = “SIP”]?SIPRemoveHeader(${sipkey}:))
exten => s,n,ExecIf($[“${sipheader}” = “unset” & “${TECH}” = “PJSIP”]?Set(PJSIP_HEADER(remove,${sipkey})=))
exten => s,n,ExecIf($[“${sipheader}” != “unset” & “${sipkey}” = “Alert-Info” & ${REGEX(“^<[^>]>" ${sipheader})} != 1 & ${REGEX(“;info=” ${sipheader})} != 1]?Set(sipheader=<http://127.0.0.1>;info=${sipheader}))
exten => s,n,ExecIf($[“${sipheader}” != “unset” & “${sipkey}” = “Alert-Info” & ${REGEX("^<[^>]
>” ${sipheader})} != 1]?Set(sipheader=<http://127.0.0.1>${sipheader}))
exten => s,n,ExecIf($[“${TECH}” = “SIP” & “${sipheader}” != “unset”]?SIPAddHeader(${sipkey}:${sipheader}))
exten => s,n,ExecIf($[“${TECH}” = “PJSIP” & “${sipheader}” != “unset”]?Set(PJSIP_HEADER(add,${sipkey})=${sipheader}))
exten => s,n,EndWhile
exten => s,n,Return()

;–== end of [func-apply-sipheaders] ==–;

extensions_custom.conf
;fix to get DDI from To header of PJSIP

[custom-get-did-from-sip]
;exten => _.,1,Goto(from-trunk,${CUT(CUT(SIP_HEADER(To),:,2),>,1)},1)
exten => _0X.,1,Goto(from-pstn,${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)},1)

Other notes.

In Freepbx make sure that the trunks “Outbound CallerID” is to a valid DDI and that “CID Options” is set to “Block Foreign CIDs” which
sounds counter intuitive but important to preserve the PIA sip header as a valid “voipunlimited” number, You can also set the route caller ID to “overide extension” caller id
if you wish , this does not effect calls forwarding through the system

This code is primarily for passing callers callerID through the system to a remote party call center for example

Blimey david55, as you suggested, a mere…

[macro-dialout-trunk-predial-hook]
exten => s,1,Set(CALLERID(number)=${REALCALLERIDNUM})
exten => s,n,Return

…is working! Been chewing on this one for days now and can’t quite fathom it yet;)

Must I add some regex for country code prefixes in international calls though?

no, you must not!

for my own sake, here’s the slightly refined version honoring internal calls

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(all > 5 digits must be external, set that as CID)
exten => s,n,ExecIf($[${LEN(${REALCALLERIDNUM})} > 5]?Set(CALLERID(number)=${REALCALLERIDNUM}))
exten => s,n,Return