How to extract caller id from P Asserted Identity for incoming call

I am able to capture the Caller ID in SIP Debug but I have no knowledge how to extract it.
Therefore the pbx shows Anonymous from all incoming calls.

The SIP provider require the PBX to use P-Asserted-Identity to display the Caller Line Identity (CLIP).

I have tried the context provided by freepbx such as [from-pstn-toheader] but it did not extract the CLIP from the Sip Header.

Please advise.

Equipment Version
Asterisk 13.12.1

Testing scenario
+60399999999 calling +60388888888

DID (+60388888888) is detected correctly via PAI and sent to Extension
But incoming Calling Line Identity appears as Anonymous.

The following is the output of the SIP debug

<--- SIP read from UDP:XX.XX.XX.XX:5060 --->
INVITE tel:+60388888888 SIP/2.0
Via: SIP/2.0/UDP XX.XX.XX.XX:5060;branch=z9hG4bK0byz189xyt118w8sxzy121x90;Role=3;Dpt=7862_36;TRC=ffffffff-ffffffff
Route: <sip:sATXX.XX.XX.XX:5160;lr;ann=VOBB_1120>
Record-Route: <sip:XX.XX.XX.XX;lr;Dpt=7862_36;Role=3;CxtId=4;spln=P;X-HwB2bUaCookie=15734;TRC=ffffffff-ffffffff>
From: <sip:AnonymousATims.xxxxx>;tag=r1gijhja-CC-151
To: <sip:88888888ATims.xxxxx>
From: <sip:AnonymousATims.xxxxxxxx>;tag=r1gijhja-CC-151
To: <sip:88888888ATims.xxxxxxxx>
Alert-Info: info=pattern1
Contact: <sip:**+60399999999**ATXX.XX.XX.XX:5060>
Max-Forwards: 62
Supported: 100rel,timer
Session-Expires: 1200
Min-SE: 1200
P-Called-Party-ID: <tel:+60388888888>
P-Access-Network-Info: xDSL;dsl-location="XXX_V1032 eth 0/11/0/13:400";"location-info=XXX_V1032 eth 0/11/0/13:400"
P-Early-Media: gated
Content-Length: 219
Content-Type: application/sdp

o=HuaweiATS9900 5313141 5313141 IN IP4 XX.XX.XX.XX
s=Sip Call
t=0 0
m=audio 41170 RTP/AVP 8 0 18
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
--- (20 headers 11 lines) ---
Sending to XX.XX.XX.XX:5060 (NAT)
Sending to XX.XX.XX.XX:5060 (NAT)
Using INVITE request as basis request - xj8plg1gipp0zlr2i8a2vijli88j2a38
Found peer 'multisip' for 'Anonymous' from XX.XX.XX.XX:5060
Found RTP audio format 8
Found RTP audio format 0
Found RTP audio format 18
Found audio description format PCMA for ID 8
Found audio description format PCMU for ID 0
Found audio description format G729 for ID 18
Capabilities: us - (alaw|ulaw), peer - audio=(ulaw|alaw|g729)/video=(nothing)/text=(nothing), combined - (alaw|ulaw)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x0 (nothing), combined - 0x0 (nothing)
Peer audio RTP is at port XX.XX.XX.XX:41170
Looking for +60388888888 in from-pstn (domain )
sip_route_dump: route/path hop: <sip:XX.XX.XX.XX;lr;Dpt=7862_36;Role=3;CxtId=4;spln=P;X-HwB2bUaCookie=15734;TRC=ffffffff-ffffffff>

Lots of information is lost due to formatting, please fix.
For sure, P-Asserted-Identity is not even present in INVITE.

1 Like

The CallerID is in the Contact header from your SIP provider. You could copy the [from-pstn-toheader] context from:
Rename it, then edit to use the contact header. Then edit the trunk to use this new context.

Hi AndrewZ and Igaetz,
Thank you for your speedy response.

I have tried manipulating the following which I copied from extension.conf (via Config Edit in Freepbx GUI)

exten =>  _.,1,NoOp(Attempting to extract DID from SIP To header)
exten =>  _.,n,gotoif($["${CHANNEL(channeltype)}"="SIP"]?SIP)
exten =>  _.,n,gotoif($["${CHANNEL(channeltype)}"="PJSIP"]?PJSIP)
exten =>  _.,n,NoOp(Unable to determine SIP channel type)
exten =>  _.,n,goto(from-pstn,${EXTEN},1))
exten =>  _.,n(SIP),Goto(from-pstn,${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)
exten =>  _.,n(PJSIP),Goto(from-pstn,${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)},1)

This is the line I tried to modify by putting variables I could find via google and voip info website.

exten =>  _.,n(SIP),Goto(from-pstn,${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)

But I was not getting anywhere.
I was not able to find a variable called “Contact” in examples.

1)Am I looking at the right line to modify?
2) Would you know what is the variable for “Contact”?

Thank you

There is no PAI in the INVITE. If your provider is saying that they are using that particular header you should discuss this with them. Maybe this is the header that you should use when making outbound calls?

Getting Calling number from Contract seems a bit unusual for me, but you can try:

exten => s,1,Goto(from-trunk,${CUT(CUT(SIP_HEADER(Contact),@,1),:,2)},1)
1 Like

why would you not put “trustrpid=yes” in your inbound trunk definition and use the context from-pstn-e164-us (if you are not in the US i think there is a similar context for international) ? if the carrier is sending a valid rpid, then you will get rid of the Anonymous and things will be grand

Hi Guys,

I have tried all the suggestions above,ie.

  • using SIP_HEADER(Contact)
    Outcome, unable to get the DID from Sip Header (PAI), therefore calls not forwarded to any extension.

  • [from-pstn-e164-us] context.
    Outcome - call came through as Anonymous similar to from-pstn. default setting is “trustrpid=yes”

I noticed the [from-pstn-toheader] context only extract the DID received via PAI, then trimmed it.

I have no problem getting the DID trimmed or untrimmed and sending it to a dedicated extension I have defined.

However, the context does not have the part where it grabs the “Contact” variable and equates that to the Inbound Caller number.

Any suggestions?

The context I provided earlier does have it.
Make sure the context name match between the trunk config and extensions_custom.conf

Hi all,
I have solved this. works and able to call back the CLIP captured via missed call.

I have referred to [from-pstn-e164-us] context. and
exten => s,1,Goto(from-trunk,${CUT(CUT(SIP_HEADER(Contact),@,1),:,2)},1) <- from Andrew
and added a Caller ID equation.

All the suggestion helped.
Thank you all for advising me.