Extension's outbound CID has no effect

So I’ve scoured the Internet looking for a solution to this, and I know there are many posts on this site relating to outbound CID issues, but I haven’t found one which addresses this one…

I’ve got two buildings, so we need to send outbound CID appropriate to each extension. I have the outbound CID set appropriately on every extension. The trunk also has a CID set, but the outbound route does not. The trunk is not set to override the extension’s CID. Nevertheless, the trunk’s CID is always used; never the extension’s.

I have confirmed with a packet trace that it is not our VoIP provider setting the CID. The INVITE going out from our system has something like

From: <sip:[WRONG CID]@[Our IP]>

I have also confirmed that the correct outbound CID is set in the astdb. So for example,

/AMPUSER/9992/outboundcid  : "Name" <Number>

The call trace shows the following (I added [number hidden] and [IP hidden] in some places). It’s strange that USEROUTCID is blank, even though the outbound CID is populated in the astdb:

  == Using SIP RTP TOS bits 184
  == Using SIP RTP CoS mark 5
    -- Executing [[email protected]:1] Set("SIP/9992-00001f33", "SIP_CODEC_INBOUND=ulaw") in new stack
    -- Executing [[email protected]:2] Set("SIP/9992-00001f33", "SIP_CODEC_OUTBOUND=ulaw") in new stack
    -- Executing [[email protected]:3] ExecIf("SIP/9992-00001f33", "0 ?Set(CDR(accountcode)=)") in new stack
    -- Executing [[email protected]:4] Set("SIP/9992-00001f33", "MOHCLASS=default") in new stack
    -- Executing [[email protected]:5] Set("SIP/9992-00001f33", "_NODEST=") in new stack
    -- Executing [[email protected]:6] Macro("SIP/9992-00001f33", "dialout-trunk,2,[number hidden],,off") in new stack
    -- Executing [[email protected]:1] Set("SIP/9992-00001f33", "DIAL_TRUNK=2") in new stack
    -- Executing [[email protected]:2] GosubIf("SIP/9992-00001f33", "0?sub-pincheck,s,1()") in new stack
    -- Executing [[email protected]:3] GotoIf("SIP/9992-00001f33", "0?disabletrunk,1") in new stack
    -- Executing [[email protected]:4] Set("SIP/9992-00001f33", "DIAL_NUMBER=[number hidden]") in new stack
    -- Executing [[email protected]:5] Set("SIP/9992-00001f33", "DIAL_TRUNK_OPTIONS=Ttr") in new stack
    -- Executing [[email protected]:6] Set("SIP/9992-00001f33", "OUTBOUND_GROUP=OUT_2") in new stack
    -- Executing [[email protected]:7] GotoIf("SIP/9992-00001f33", "1?nomax") in new stack
    -- Goto (macro-dialout-trunk,s,9)
    -- Executing [[email protected]:9] GotoIf("SIP/9992-00001f33", "0?skipoutcid") in new stack
    -- Executing [[email protected]:10] Set("SIP/9992-00001f33", "DIAL_TRUNK_OPTIONS=T") in new stack
    -- Executing [[email protected]:11] Macro("SIP/9992-00001f33", "outbound-callerid,2") in new stack
    -- Executing [[email protected]:1] ExecIf("SIP/9992-00001f33", "0?Set(CALLERPRES(name-pres)=)") in new stack
    -- Executing [[email protected]:2] ExecIf("SIP/9992-00001f33", "0?Set(CALLERPRES(num-pres)=)") in new stack
    -- Executing [[email protected]:3] ExecIf("SIP/9992-00001f33", "1?Set(REALCALLERIDNUM=9992)") in new stack
    -- Executing [[email protected]:4] GotoIf("SIP/9992-00001f33", "1?normcid") in new stack
    -- Goto (macro-outbound-callerid,s,7)
    -- Executing [[email protected]:7] Set("SIP/9992-00001f33", "USEROUTCID=") in new stack
    -- Executing [[email protected]:8] Set("SIP/9992-00001f33", "EMERGENCYCID=") in new stack
    -- Executing [[email protected]:9] Set("SIP/9992-00001f33", "TRUNKOUTCID=3085357100") in new stack
    -- Executing [[email protected]:10] GotoIf("SIP/9992-00001f33", "1?trunkcid") in new stack
    -- Goto (macro-outbound-callerid,s,15)
    -- Executing [[email protected]:15] ExecIf("SIP/9992-00001f33", "1?Set(CALLERID(all)=[number hidden])") in new stack
    -- Executing [[email protected]:16] ExecIf("SIP/9992-00001f33", "0?Set(CALLERID(all)=)") in new stack
    -- Executing [[email protected]-callerid:17] ExecIf("SIP/9992-00001f33", "0?Set(CALLERID(all)=)") in new stack
    -- Executing [[email protected]:18] ExecIf("SIP/9992-00001f33", "0?Set(CALLERPRES(name-pres)=prohib_passed_screen)") in new stack
    -- Executing [[email protected]:19] ExecIf("SIP/9992-00001f33", "0?Set(CALLERPRES(num-pres)=prohib_passed_screen)") in new stack
    -- Executing [[email protected]:20] Set("SIP/9992-00001f33", "CDR(outbound_cnum)=[number hidden]") in new stack
    -- Executing [[email protected]:21] Set("SIP/9992-00001f33", "CDR(outbound_cnam)=") in new stack
[2017-03-20 09:56:56] WARNING[7012]: func_cdr.c:377 cdr_write_callback: CDR requires a value (CDR(variable)=value)
    -- Executing [[email protected]:12] GosubIf("SIP/9992-00001f33", "0?sub-flp-2,s,1()") in new stack
    -- Executing [[email protected]:13] Set("SIP/9992-00001f33", "OUTNUM=[number hidden]") in new stack
    -- Executing [[email protected]:14] Set("SIP/9992-00001f33", "custom=PJSIP") in new stack
    -- Executing [[email protected]:15] ExecIf("SIP/9992-00001f33", "0?Set(DIAL_TRUNK_OPTIONS=M(setmusic^default)T)") in new stack
    -- Executing [[email protected]:16] ExecIf("SIP/9992-00001f33", "0?Set(DIAL_TRUNK_OPTIONS=TM(confirm))") in new stack
    -- Executing [[email protected]:17] Macro("SIP/9992-00001f33", "dialout-trunk-predial-hook,") in new stack
    -- Executing [[email protected]:1] MacroExit("SIP/9992-00001f33", "") in new stack
    -- Executing [[email protected]:18] GotoIf("SIP/9992-00001f33", "0?bypass,1") in new stack
    -- Executing [[email protected]:19] ExecIf("SIP/9992-00001f33", "0?Set(CONNECTEDLINE(num,i)=[number hidden])") in new stack
    -- Executing [[email protected]:20] ExecIf("SIP/9992-00001f33", "0?Set(CONNECTEDLINE(name,i)=CID:[number hidden])") in new stack
    -- Executing [[email protected]:21] ExecIf("SIP/9992-00001f33", "0?Set(CONNECTEDLINE(name,i)=CID:(Hidden)[number hidden])") in new stack
    -- Executing [[email protected]:22] GotoIf("SIP/9992-00001f33", "0?customtrunk") in new stack
    -- Executing [[email protected]:23] Dial("SIP/9992-00001f33", "PJSIP/[number hidden]@ALLO_PJSIP,300,T") in new stack
    -- Called PJSIP/[email protected]_PJSIP
    -- PJSIP/ALLO_PJSIP-00000e85 is making progress passing it to SIP/9992-00001f33
       > Set codec to 'ulaw' for this call because of ${SIP_CODEC*} variable
       > 0x7f7848b6e9a0 -- Probation passed - setting RTP source address to [IP hidden]:7078
       > 0x7f7860452e00 -- Probation passed - setting RTP source address to [IP hidden]:23470
  == Spawn extension (macro-dialout-trunk, s, 23) exited non-zero on 'SIP/9992-00001f33' in macro 'dialout-trunk'
  == Spawn extension (from-internal, [number hidden], 6) exited non-zero on 'SIP/9992-00001f33'
    -- Executing [[email protected]:1] Macro("SIP/9992-00001f33", "hangupcall") in new stack
    -- Executing [[email protected]:1] GotoIf("SIP/9992-00001f33", "1?theend") in new stack
    -- Goto (macro-hangupcall,s,3)
    -- Executing [[email protected]:3] ExecIf("SIP/9992-00001f33", "0?Set(CDR(recordingfile)=)") in new stack
    -- Executing [[email protected]:4] Hangup("SIP/9992-00001f33", "") in new stack
  == Spawn extension (macro-hangupcall, s, 4) exited non-zero on 'SIP/9992-00001f33' in macro 'hangupcall'
  == Spawn extension (from-internal, h, 1) exited non-zero on 'SIP/9992-00001f33'

Can anyone help me with this? Thanks in advance!!

A simple start could be to set the “Intracompany Route” in the outbound trunks?

This way, the extension caller ID will propagate. It might not be the best solution in all cases, but it sounds like it’s tailor made for this one.

I thought that would send the internal extension number instead of the outbound CID? So it would send 9992 instead of the actual external number that we want to show up.

It might, but since you’re setting the extension caller ID, it might send that. It’s a click and reload - try it for a minute and see what happens…

You can always turn it back off if it doesn’t work the way you want it to.

It seems that with the Intra-Company set in the route, the dialplan skips the code which sets the outbound CID from the astDB, so the CID went out as 9992.

I did figure out one odd thing. I found this forum post from a few years ago. Following that lead, I replaced

exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${AMPUSER}/outboundcid)})

with

exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)})

in the context macro-outbound-callerid and the outbound callerID seems to work as expected - with the CID set on the extension instead of the trunk. So it seems that it may not be setting AMPUSER correctly? This isn’t the ideal solution since this file will be regenerated by FreePBX.

AMPUSER is set in macro-user-callerid as follows:

exten => s,n,Set(AMPUSER=${DB(DEVICE/${REALCALLERIDNUM}/user)})

… but I don’t have any users in FreePBX, only extensions.

See these two lines early on in the call trace:

-- Executing [[email protected]:1] Set("SIP/9992-00001f33", "SIP_CODEC_INBOUND=ulaw") in new stack
-- Executing [[email protected]:2] Set("SIP/9992-00001f33", "SIP_CODEC_OUTBOUND=ulaw") in new stack

I don’t recognize these lines. They appear to be custom dialplan that has been added, and which are superseding FreePBX generated dialplan. One of the generated lines that is missing is the macro call to user-callerid, which may well explain what you are seeing.

Yep that did it. I had put some custom rules for from-pstn-custom, outbound-allroutes-custom, and from-internal-noxfer-custom in order to force a particular codec based on the dialed number, to avoid transcoding.

Where is the best place to put these rules which I want to execute in those particular places but without causing this kind of problem? In extensions_custom.conf? I had looked at the three contexts above and they seemed to be empty, so I didn’t think it would hurt to put them in extensions_override_freepbx.conf.