CallerID when calling from trunk-int to trunk-ext

I posted the same question on the elastix forum, but as far as i understand now its more freepbx related.

I have the following setup in a Siemes Hicom to asterisk migration project

PSTN(3BRI) <-> Patton 4638 <-> trunk <->
–>
asterisk <-> extensions -> SIP Phones
-------- <-> trunk -> Patton 4118 FXS Lines
-------- <-> trunk -> Patton 4638(3
bri) <-> Hicom

Everything is working fine by now except:
When a call starting- or endpoint is not a sip extension on asterisk or PSTN, means the call gets forwarded from an internal trunk ( for example Hicom calling PSTN, or FXS endpoint calling PSTN) the outbound CallerID is not set to the caller id of the caller. Instead asterisk uses the Outbound CID configured in the last trunk before the endpoint.

For Example:

Analog Telephone on Patton FXS(trunk, context from-internal) calls PSTN -> Outbound CID is taken from the PSTN trunk which routes to Patton 4638 attached to PSTN.

But when the same handset calls SIP extension on Asterisk the Callerid is shown correctly.
Same for calls originating from a SIP extension. These calls show correct CallerIDs on PSTN.

Anybody has an idea where i can start to look at or anybody knows why, when calling gateway -> asterisk -> gateway, callerid doesnt’t make its way into USEROUTCID?

Or am I doing something completly wrong by connecting internal fxs extensions on a patton gateway to elastix/freepbx through a trunk definition with context= from-internal?

Thx
Mathias

My configuration for the trunks:

trunk pattonbri01 (to PSTN)

host=10.101.1.92
port=5060
type=friend
context=from-trunk-custom (which only adds a 0 to the callerid from external an reroutes to context from-trunk)

trunk Pattonfx0 (Internal FXS endpoints like FAX or mobile handsets)

host=10.101.1.95
type=friend
context=from-internal

And the call trace of the not working call from above:

[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] Macro(“SIP/pattonfxs-000002db”, “user-callerid,SKIPTTL,”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] Set(“SIP/pattonfxs-000002db”, “AMPUSER=515”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:2] GotoIf(“SIP/pattonfxs-000002db”, “0?report”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:3] ExecIf(“SIP/pattonfxs-000002db”, “1?Set(REALCALLERIDNUM=515)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:4] Set(“SIP/pattonfxs-000002db”, “AMPUSER=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:5] Set(“SIP/pattonfxs-000002db”, “AMPUSERCIDNAME=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:6] GotoIf(“SIP/pattonfxs-000002db”, “1?report”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Goto (macro-user-callerid,s,10)
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:10] GotoIf(“SIP/pattonfxs-000002db”, “1?continue”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Goto (macro-user-callerid,s,19)
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:19] Set(“SIP/pattonfxs-000002db”, “CALLERID(number)=515”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:20] Set(“SIP/pattonfxs-000002db”, “CALLERID(name)=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:21] NoOp(“SIP/pattonfxs-000002db”, “Using CallerID “” <515>”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:2] NoOp(“SIP/pattonfxs-000002db”, “Calling Out Route: 0_outside”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:3] Set(“SIP/pattonfxs-000002db”, “MOHCLASS=default”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:4] Set(“SIP/pattonfxs-000002db”, “_NODEST=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [0177XXX[email protected]:5] Macro(“SIP/pattonfxs-000002db”, “record-enable,OUT,”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] GotoIf(“SIP/pattonfxs-000002db”, “1?check”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Goto (macro-record-enable,s,4)
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:4] ExecIf(“SIP/pattonfxs-000002db”, “1?MacroExit()”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:6] Macro(“SIP/pattonfxs-000002db”, “dialout-trunk,2,0177XXXXXX2,”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] Set(“SIP/pattonfxs-000002db”, “DIAL_TRUNK=2”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:2] GosubIf(“SIP/pattonfxs-000002db”, “0?sub-pincheck,s,1”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:3] GotoIf(“SIP/pattonfxs-000002db”, “0?disabletrunk,1”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:4] Set(“SIP/pattonfxs-000002db”, “DIAL_NUMBER=0177XXXXXX2”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:5] Set(“SIP/pattonfxs-000002db”, “DIAL_TRUNK_OPTIONS=tr”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:6] Set(“SIP/pattonfxs-000002db”, “OUTBOUND_GROUP=OUT_2”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:7] GotoIf(“SIP/pattonfxs-000002db”, “0?nomax”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:8] GotoIf(“SIP/pattonfxs-000002db”, “0?chanfull”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:9] GotoIf(“SIP/pattonfxs-000002db”, “0?skipoutcid”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:10] Set(“SIP/pattonfxs-000002db”, “DIAL_TRUNK_OPTIONS=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:11] Macro(“SIP/pattonfxs-000002db”, “outbound-callerid,2”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] ExecIf(“SIP/pattonfxs-000002db”, “0?Set(CALLERPRES()=)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:2] ExecIf(“SIP/pattonfxs-000002db”, “0?Set(REALCALLERIDNUM=515)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:3] GotoIf(“SIP/pattonfxs-000002db”, “1?normcid”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Goto (macro-outbound-callerid,s,6)
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:6] Set(“SIP/pattonfxs-000002db”, “USEROUTCID=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:7] Set(“SIP/pattonfxs-000002db”, “EMERGENCYCID=”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:8] Set(“SIP/pattonfxs-000002db”, “TRUNKOUTCID=<0>”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:9] GotoIf(“SIP/pattonfxs-000002db”, “1?trunkcid”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Goto (macro-outbound-callerid,s,12)
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:12] ExecIf(“SIP/pattonfxs-000002db”, “1?Set(CALLERID(all)=<0>)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:13] ExecIf(“SIP/pattonfxs-000002db”, “0?Set(CALLERID(all)=)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:14] ExecIf(“SIP/pattonfxs-000002db”, “0?Set(CALLERID(all)=)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:15] ExecIf(“SIP/pattonfxs-000002db”, “0?Set(CALLERPRES()=prohib_passed_screen)”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:12] GosubIf(“SIP/pattonfxs-000002db”, “0?sub-flp-2,s,1”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:13] Set(“SIP/pattonfxs-000002db”, “OUTNUM=0177XXXXXX2”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:14] Set(“SIP/pattonfxs-000002db”, “custom=SIP/pattonbri01”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:15] ExecIf(“SIP/pattonfxs-000002db”, “0?Set(DIAL_TRUNK_OPTIONS=M(setmusic^default))”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:16] Macro(“SIP/pattonfxs-000002db”, “dialout-trunk-predial-hook,”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] MacroExit(“SIP/pattonfxs-000002db”, “”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:17] GotoIf(“SIP/pattonfxs-000002db”, “0?bypass,1”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:18] GotoIf(“SIP/pattonfxs-000002db”, “0?customtrunk”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] pbx.c: – Executing [[email protected]:19] Dial(“SIP/pattonfxs-000002db”, “SIP/pattonbri01/0177XXXXXX2,300,”) in new stack
[Dec 24 17:40:22] VERBOSE[9484] netsock2.c: == Using SIP RTP TOS bits 184
[Dec 24 17:40:22] VERBOSE[9484] netsock2.c: == Using SIP RTP CoS mark 5
[Dec 24 17:40:22] VERBOSE[9484] app_dial.c: – Called SIP/pattonbri01/0177XXXXXX2
[Dec 24 17:40:29] VERBOSE[9484] app_dial.c: – SIP/pattonbri01-000002dc is ringing
[Dec 24 17:40:29] VERBOSE[9484] app_dial.c: – SIP/pattonbri01-000002dc is ringing
[Dec 24 17:40:33] VERBOSE[9484] app_macro.c: == Spawn extension (macro-dialout-trunk, s, 19) exited non-zero on ‘SIP/pattonfxs-000002db’ in macro ‘dialout-trunk’
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: == Spawn extension (from-internal, 0177XXXXXX2, 6) exited non-zero on ‘SIP/pattonfxs-000002db’
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] Macro(“SIP/pattonfxs-000002db”, “hangupcall”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:1] GotoIf(“SIP/pattonfxs-000002db”, “1?endmixmoncheck”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,9)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:9] NoOp(“SIP/pattonfxs-000002db”, “End of MIXMON check”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:10] GotoIf(“SIP/pattonfxs-000002db”, “1?nomeetmemon”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,15)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:15] NoOp(“SIP/pattonfxs-000002db”, “MEETME_RECORDINGFILE=”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:16] GotoIf(“SIP/pattonfxs-000002db”, “1?noautomon”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,18)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:18] NoOp(“SIP/pattonfxs-000002db”, “TOUCH_MONITOR_OUTPUT=”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:19] GotoIf(“SIP/pattonfxs-000002db”, “1?noautomon2”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,25)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:25] NoOp(“SIP/pattonfxs-000002db”, “MONITOR_FILENAME=”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:26] GotoIf(“SIP/pattonfxs-000002db”, “1?skiprg”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,29)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:29] GotoIf(“SIP/pattonfxs-000002db”, “1?skipblkvm”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,32)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:32] GotoIf(“SIP/pattonfxs-000002db”, “1?theend”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Goto (macro-hangupcall,s,34)
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: – Executing [[email protected]:34] Hangup(“SIP/pattonfxs-000002db”, “”) in new stack
[Dec 24 17:40:33] VERBOSE[9484] app_macro.c: == Spawn extension (macro-hangupcall, s, 34) exited non-zero on ‘SIP/pattonfxs-000002db’ in macro ‘hangupcall’
[Dec 24 17:40:33] VERBOSE[9484] pbx.c: == Spawn extension (from-internal, h, 1) exited non-zero on ‘SIP/pattonfxs-000002db’