Provider sends CID only in "Contact:" header. How to configure FreePBX to take CID from it?

Provider sends CID only in “Contact:” header, not “From:”
“From:” is filled as “anonymous.”
Here is example: > my-sip1.sip: SIP, length: 984
    INVITE sip:[email protected]:5060;line=zyjlrii SIP/2.0
    Via: SIP/2.0/UDP;branch=z9hG4bKer3rgewezrrkl1zllrrkk3lx0T36093
    Record-Route: <sip:;transport=udp;lr>
    Call-ID: [email protected]
    From: "Anonymous"<sip:[email protected]>;tag=sbc04062zrxhhzr-CC-13
    To: <sip:[email protected]:5060;transport=udp;user=phone>
    CSeq: 1 INVITE
    Contact: <sip:[email protected]:5060;user=phone>
    Max-Forwards: 26
    Supported: 100rel,timer
    Session-Expires: 1800
    Min-SE: 600
    P-Called-Party-ID: <tel:+73439144003>
    Content-Length: 222
    Content-Type: application/sdp

FreePBX displays such calls as “Anonymous”

How to configure FreePBX/Asterisk to take CID from “Contact:” header, not “From:”?

Hello @arti_crb,

Do you use a SIP or PJSIP trunk with your provider?

Thank you,

Daniel Friedman
Trixton LTD.

Not tested, but I hope this is close:

For a chan_sip trunk, add to /etc/asterisk/extensions_custom.conf :

exten => _.,1,Set(CALLERID(num)=${CUT(CUT(SIP_HEADER(Contact),@,1),:,2)}) 
exten => _.,n,Goto(from-trunk,${EXTEN},1)

Or for pjsip:

exten => _.,1,Set(CALLERID(num)=${CUT(CUT(PJSIP_HEADER(read,Contact),@,1),:,2)}) 
exten => _.,n,Goto(from-trunk,${EXTEN},1)

Then change context for your trunk to from-trunk-fixcid


@Stewart1 has the fix. For ideas on how to combine the two methods to a single context, check the built in context from-pstn-toheader

What’s going on with this provider? Do all calls arrive like that or just some?

Depending on the relationship it honestly feels as though they may be leaking information that is supposed to be withheld, as the call is seemingly supposed to be anonymous. The information being in the Contact header (which isn’t supposed to be used for callerid) would be a coincidence. Coincidence is probably the wrong word. More like the SIP server is likely putting the callerid into the Contact header and disregarding any presentation information (that it is anonymous/withheld).



I’m using PJSIP trunk.

Thank you.

Thank you, @Stewart1 and @lgaetz

I’ll test your fix ASAP.

I was hoping, such provider’s behavior occurs often, but apparently I was wrong.

@jcolp says about provider

Maybe it’s an artefacts, when provider had a paid service (“Caller ID”), but I havn’t any information about it.

You didn’t answer the question whether this happens on all inbound calls or just some.

I think all calls are the same.
I tried mobile calls, landline and SIP. No difference.

Your VoIP provider is broken. You should report this issue to them. If they try to sell you caller ID service, they suck. Find another provider. No one charges for numeric caller ID.

Here in NANP land, years ago I recall reading something about those with toll free DIDs being entitled to CID (even on anonymous calls) since they are the party footing the bill for the call. But I have never actually seen it in practice.

That is a legacy goes all the way back to WATS numbers

But ANI is not exactly the same as CLID and WATS numbers always ended up on ‘landline’ numbers

My TF numbers with Vitelity and Alcazar deliver blocked CIDs with no issue.

But I did have a problem once with Vitelity. A few years ago, blocked numbers suddenly stopped coming in. I opened a ticket and they explained that they had raised the rate (for small potatoes like me) to $0.024 and to grandfather me at $0.019 they moved me to another carrier that didn’t deliver blocked numbers. I was offered three choices:

  1. Agree to the new rate and they would return to the old carrier (XO).
  2. Get the old rate with XO by limiting coverage to US48.
  3. Do nothing and blocked numbers won’t be delivered.

I chose option 2.

A couple of years later, Vitelity switched to a new scheme where there are different rates for US48, HI, AK, Canada, etc. Users can enable each of these on the portal.

@Stewart1, many thanks :+1:
It’s works!
Now I have:

exten => _.,1,Set(CALLERID(num)=${CUT(CUT(PJSIP_HEADER(read,Contact),@,1),:,2)}).
exten => _.,n,Set(CALLERID(name)=${CUT(CUT(PJSIP_HEADER(read,Contact),@,1),:,2)}).
exten => _.,n,Goto(from-pstn,${EXTEN},1)

Yes, it’s almost good.

CDR report now says only one field “anonymous”: ANI. I

What else I must fill to totally eliminate “anonymous” in CDR?

I don’t believe that the ANI column displays by default. If you have customized the columns, either remove ANI from the list, or populate CALLERID(ani) with something useful.

I suppose you could write it from the Contact header (same as you are doing for num and name), but that would just clutter the report with redundant information.

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