callerID with SipAddHeader is showing device and extension

not sure why, but for whatever reason the Asterisk system when looking at it via CLI is sending the callerid as “device” with XXXX being the extension and not the Outbound CID.

The problem is that i need to include using the SIPAddHeader command the outbound CID and then the IP address. however instead its putting in the extension when i use the CALLERID(number) command. from what i see the callerid is in fact being specified as device and extension as seen in the sip additional conf file.

So is this a bug? is there any easy way for me to fix this so that my header has the outboundCID in it and not the extension? perhaps a different command?

Any help would be most appreciated.

Thank you

from you description it is not clear if there is database corruption or if its the nature of where you are adding the sipheader information. If you call extension to extension are you seeing the proper display name (vs. the device ) ?

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

yes extension to extension is fine, but check it out yourself, go to sip_additional.conf and look and your callerID, then knowing that the command CallerID(number) in SIPaddheader pulls the callerID you will see what i mean.

what is in sip_additional.conf is not relevant. That is simply used to lookup the callerid information in the astdb when that extension is making the call. See FreePBX Devices and Users Under the Hood for more details. When the call is sent out a trunk, there is a fairly ‘complex’ series of lookups and decisions that are made to finalize on what is used for the outbound callerid. When a system is properly configured, it will not use that.

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

ok this is out of the box, i promise you try it yourself, go ahead and add the following to your extensions_custom.conf file

include extensions_trixbox.conf
include extensions_hud.conf

exten => _1NXXNXXXXXX,1,SipAddHeader(P-Asserted-Identity: sip:${CALLERIDNUM})
exten => _NXXNXXXXXX,1,SipAddHeader(P-Asserted-Identity: sip:${CALLERIDNUM})

include => from-internal-trixbox

see the link for further instructions here…

Then go to the CLI and set verbose to 3 (use command set verbose 3) then make a call and you will notice that the P-Asserted tag which is called up with SipAddHeader is refrencing sip_additional.conf info.

Go ahead and try it and you will see what i mean. I think you think i am refrencing extension to extension calls and looking at the screen on the phone, i am not and thats all working fine, i am talking about the SIP information being sent out in the background, this is important since my carrier requires a certain format and its replacing the outbound CID with extension when the above command is called.

the following is actually an example of what i am getting…
– Executing SIPAddHeader(“SIP/2001-0857e7b8”, “P-Asserted-Identity: sip:2001”) in new stack

Plain and simply i need to be able to call the SIPaddheader to include the outbound CID, so if i am using the wrong command to do this then let me know, but as it satands CALLERID(num) or CALLERIDNUM are both calling upon the extension and not the outbound CID. So the main thing is how does someone correct this?

at that point in the dialplan that is what you are going to get. Take a look at the CLI to see what is being called to make a call.
The callerid used for outbound calls is generated in macro-outbound-callerid which is called from macro-dialout-trunk. So you will have to wait until the real callerid is known before you can set your header info. Either that, or you need to do the lookup yourself. You are getting the device id which points to the DEVICE object in Astdb. From there you can determine which user it is and from there you can determine their outbound callerid, if they set one. But if they did not set one then it is going to depend on the trunk settings they are calling out plus the added complication of using the emergency callerid if the given route is an emergency route (which comes from the DEVICE object again). So … you are best to just redefine either macro-outbound-callerid or macro-dialout-trunk and set it there. (You redefine a macro by copying it into the extensions_custom.conf file and the modifying it with what you need. The only caveat is that any time there are updates to core you will want to make sure that there have been no changes to the given macro that you may want since your version will override it.

In the mean time, you may want to add a feature request to the ticket system. It would probably make sense for us to add a hook in macro-dialout-trunk. Probably something like a call to Macro(dialout-trunk-pre-hook) which we would define as a macro that does nothing, just returns and we would never put anything in it. Then you would be able to override that macro in extensions_custom.conf with your own version to do such things as this and you would never have to worry between upgrades.

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

in the CLI which I copied the output in the last post, that line appears before the macro stuff runs. so does that support what you said in the last email? its the very first thing that gets outputted before anything else.

so knowing that do u think u can provide me a sample of what I should be placing in extensions_cusom.conf, I undrstand copying and pasting but should I be naming it with the same header in brackets? ie macro-dialout-trunk or should I be naming it something different? should I be including any conf files? and where should my sipaddheader command go? somewhere inside the macro or completely after?

given that please let me know what u think

So just an update, did as you suggested and copied the following into the extensions_custom.conf, you will notice i inserted the tag somewhere after the callerID has been defined as the outbound CID
exten => _1NXXNXXXXXX,1,SipAddHeader(P-Asserted-Identity: sip:+1${CALLERIDNUM})

I also inserted the macro below both with and without the [macro-outbound-callerid] tag, so one was under the [from-internal-custom] and the other was seperate, both didnt work, i also tried the above sipaddheader tag both after the macro and within the macro, still no change

; Keep the original CallerID number, for failover to the next trunk.
exten => s,1,GotoIf($["${REALCALLERIDNUM:1:2}" != “”]?start)
exten => s,n,Set(REALCALLERIDNUM=${CALLERID(number)})

; If this came through a ringgroup or CF, then we want to retain original CID unless
; OUTKEEPCID_${trunknum} is set.
exten => s,n,GotoIf($["${KEEPCID}" != “TRUE”]?normcid) ;Set to TRUE if coming from ringgroups, CF, etc.
exten => s,n,GotoIf($[“x${OUTKEEPCID_${ARG1}}” = “xon”]?normcid)
exten => s,n,GotoIf($[“foo${REALCALLERIDNUM}” = “foo”]?normcid) ;if not set to anything, go through normal processing

; We now have to make sure the CID is valid. If we find an AMPUSER with the same CID, we assume it is an internal
; call (would be quite a conincidence if not) and go through the normal processing to get that CID. If a device
; is set for this CID, then it must be internal
exten => s,n,GotoIf($[“foo${DB(AMPUSER/${REALCALLERIDNUM}/device)}” = “foo”]?bypass:normcid)

exten => s,n(normcid),Set(USEROUTCID=${DB(AMPUSER/${REALCALLERIDNUM}/outboundcid)})
exten => s,n(bypass),Set(EMERGENCYCID=${DB(DEVICE/${REALCALLERIDNUM}/emergency_cid)})
exten => s,n,Set(TRUNKOUTCID=${OUTCID_${ARG1}})
exten => s,n,GotoIf($["${EMERGENCYROUTE:1:2}" = “”]?trunkcid) ; check EMERGENCY ROUTE
exten => s,n,GotoIf($["${EMERGENCYCID:1:2}" = “”]?trunkcid) ; empty EMERGENCY CID, so default back to trunk
exten => s,n,Set(CALLERID(all)=${EMERGENCYCID}) ; emergency cid for device
exten => s,n,Goto(report)
exten => s,n(trunkcid),GotoIf($["${TRUNKOUTCID:1:2}" = “”]?usercid) ;check for CID override for trunk (global var)
exten => s,n,Set(CALLERID(all)=${TRUNKOUTCID})
exten => s,n(usercid),GotoIf($["${USEROUTCID:1:2}" = “”]?report) ; check CID override for extension
exten => s,n,Set(CALLERID(all)=${USEROUTCID})
exten => _1NXXNXXXXXX,1,SipAddHeader(P-Asserted-Identity: sip:+1${CALLERIDNUM})
exten => s,n,GotoIf($[“x${CALLERID(name)}”!=“xhidden”]?report:hidecid) ; check CID blocking for extension
exten => s,n(hidecid),SetCallerPres(prohib_passed_screen) ; Only works with ISDN (T1/E1/BRI)
exten => s,n(report),NoOp(CallerID set to ${CALLERID(all)})

; Privacy Manager Macro makes sure that any calls that don’t pass the privacy manager are presented
; with congestion since there have been observed cases of the call continuing if not stopped with a
; congestion, and this provides a slightly more friendly ‘sorry’ message in case the user is
; legitamately trying to be cooperative.
; Note: the following options are configurable in privacy.conf:
; maxretries = 3 ; default value, number of retries before failing
; minlength = 10 ; default value, number of digits to be accepted as valid CID

anyone? any help would be great on anything from last two posts

hopefully someone can help?

You need to call the macro before setting the sipheader:

exten => _1NXXNXXXXXX,1,Macro(macro-user-callerid)
exten => _1NXXNXXXXXX,n,Macro(outbound-callerid)
exten => _1NXXNXXXXXX,n,SipAddHeader(P-Asserted-Identity: sip:+1${CALLERID(number)})

not tested but should work…

almost there, i have two trunks with different sip providers so this should work, however when i put it in, it throws back all circuits are busy… Good news is that i see the P-Asserted header with the full outbound CID, so thats great, but for whatever reason the call wont go through. is there anything else that should be added?

Some things i have tested…

exten => _1NXXNXXXXXX after this there is “n”, when i change all 3 above to 1, it works but then no P-Asserted tag (so sip add header doesnt seem to get called). all “n” doesnt work, any combo actually doestn work, your way works but then it doesnt pick up any Trunk.

oh i also tried the following
exten => _1NXXNXXXXXX,1,Macro(macro-user-callerid)
exten => _1NXXNXXXXXX,2,Macro(outbound-callerid)
exten => _1NXXNXXXXXX,3,SipAddHeader(P-Asserted-Identity: sip:+1${CALLERID(number)})

This too outputs the correct info in the CLI, however the trunk is never picked up and the call doesnt go through, it says instead “the person your calling is unavailable” it outputs the following after the P-Asserted tag header

-- Executing Congestion("SIP/200-b790c5c8", "20") in new stack

== Spawn extension (from-internal, 17126661234, 4) exited non-zero on ‘SIP/2 00-b790c5c8’

Any help would be great, thanks so much to all so far for all the help

any ideas on this? am i doing something wrong?

I also have the same problem!
Every incoming calls shows a random Caller ID (frequently a name of extension number).
Any suggestion?
Thank’s in advance.

i think the following is valid but its missing another piece perhaps
exten => _1NXXNXXXXXX,1,Macro(macro-user-callerid)
exten => _1NXXNXXXXXX,2,Macro(outbound-callerid)
exten => _1NXXNXXXXXX,3,SipAddHeader(P-Asserted-Identity: sip:+1${CALLERID(number)})

just so strange since the above wont pickup the trunk to make the outgoing call (and of course one is defined in outbound routes, and so is a secondary trunk)

The following by itself works
exten => _1NXXNXXXXXX,1,SipAddHeader(P-Asserted-Identity: sip:${CALLERIDNUM})

but then you have the original problem of the “Device” issue where extension is being place in the header and not the outbound callerID.

Perhaps to resolve this someone knows how to modify the script which equtes callerid to outboundCID field. right now if you look at sip_additional.conf it looks pretty clear that callerid is being set as “device” and then the extension number.

Well you need to make a 4’th line that tells asterisk what to do with the call. Like

exten => _1NXXNXXXXXX,n,Goto(from-internal,${EXTEN},1)


exten => _1NXXNXXXXXX,n,Goto(outbound-allroutes,${EXTEN},1)

But you are now jumping over a bunch of freepbx stuff, and doing the macros twice (which could realy hurt), the best would be to add the SipAddHeader to extension.conf in the [macro-dialout-trunk] context, around line 667 after the line:

exten => s,n,Macro(outbound-callerid,${DIAL_TRUNK})


exten => s,n,SipAddHeader(P-Asserted-Identity: sip:+1${CALLERID(number)})

this will add that header to all outgoing calls. Remember that with 2.3 that file can / will be overwritten when upgrading core/framework.

Right, i would place it there but wouldnt it be overwritten everytime i do “Apply Changes” as well? or just on upgrades?

oh also whats the difference between
exten => _1NXXNXXXXXX,n,Goto(from-internal,${EXTEN},1)
exten => _1NXXNXXXXXX,n,Goto(outbound-allroutes,${EXTEN},1


Also what do u mean it will be jumping over stuff and that it could really hurt? by hurt specifically do u mean astrisk crashing, resources gobbled? by jumping over do you mean CDR records not being recorded or other things not being done?

take a look at r5091 which has not been published yet as I have been waiting to get some other eyes on it for a sanity check. The change of interest is the addition of macro-dialout-trunk-predial-hook which I eluded to earlier in this thread. That is where you can write code to insert additional SIP headers in or what ever else you want to do. That macro will always be left blank, so you just re-declare it in extensions_custom.conf and your version will override and do what ever you need to do. It is called just prior to the attempted call and the environment will reflect what is normally about to go out. So you can insert SIP headers, mangle the CID or anything else that you may require and when it returns the attempted call will be made. If the call fails and the code takes you to another trunk, your macro will get executed again with that trunk’s parameters so you can make what ever new set of decisions you choose to make…

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx