Confused about context/rules

Hey guys,

after working with FreePBX for a few weeks now and finding out everything I need on my own I need a bit of help regarding number translation.

I’m using FreePBX only for forwarding everything from my Telekom SIP-Trunk to my Skype for Business Server and vice-versa.

I have two trunks, one for the telekom connection, one for SfB.
I have two Outbound Routes, One Incoming Route.
Incoming Route routes everything to SfB trunk.
Outbound Route for SfB (first rule) routes dial pattern +493012345XX to SfB
Outbound Route for Telekom (second rule) routes everything to Telekom Trunk

So far incoming and outgoing calls are working fine, except the following:

I have to use from-pstn-toheader as the context in my Telekom trunk, or else the incoming CID (Mobile Phone -> Telekom -> FreePBX -> SfB) would be wrong. That way SfB works and my SfB phone rings.
But: if I make a outgoing call with SfB (SfB -> FreePBX -> Telekom -> Mobile Phone) to my mobile for example the CID of the call is wrong. It is the main trunk number instead of my direct number.

I already tried several different rules in extensions_custom.conf, but they always seem to be applied to the SfB trunk, not the telekom trunk.

What am I doing wrong?
0301234510 is the main trunk number
0301234599 is my number, which should be displayed

[[email protected] ~]# cat /etc/asterisk/extensions_override_freepbx.conf 
[macro-dialout-trunk-predial-hook]
exten => s,1,Verbose(2, Adding P-Asserted-Identity for Telekom)
exten => s,n,Verbose(2, ${REALCALLERIDNUM})
exten => s,n,SipAddHeader(P-Asserted-Identity: "CID:${REALCALLERIDNUM}")
exten => s,n,SipAddHeader(Remote-Party-ID: <sip:${REALCALLERIDNUM}@sip-trunk.telekom.de>)
exten => s,n(done),MacroExit()

I do not know if “CID:Number” is correct. If I add a extension and connect with X-Lite to it it does sent it like this and it works - so I assume it does. But my first step is “getting the context to work somehow and then take care of the details”

-- Executing [[email protected]:1] Verbose("PJSIP/SfB-00000002", "2, Adding P-Asserted-Identity for Telekom") in new stack

== Adding P-Asserted-Identity for Telekom
– Executing [[email protected]:9] SIPAddHeader(“PJSIP/SfB-00000002”, "P-Asserted-Identity: “CID:+49301234599"”) in new stack
– Executing [[email protected]:11] SIPAddHeader(“PJSIP/SfB-00000002”, “Remote-Party-ID: < sip:[email protected] >”) in new stack
– Executing [[email protected]:12] MacroExit(“PJSIP/SfB-00000002”, “”) in new stack
– Executing [[email protected]:18] GotoIf(“PJSIP/SfB-00000002”, “0?skipcrm”) in new stack
– Executing [[email protected]:19] Set(“PJSIP/SfB-00000002”, “__CRM_DIRECTION=OUTBOUND”) in new stack
– Executing [[email protected]:20] Set(“PJSIP/SfB-00000002”, “__CRM_DESTINATION=+49MYMOBILENUMBER”) in new stack
– Executing [[email protected]:21] Set(“PJSIP/SfB-00000002”, “__CRM_SOURCE=”) in new stack
– Executing [[email protected]:23] Set(“PJSIP/SfB-00000002”, “CHANNEL(hangup_handler_push)=crm-hangup,s,1”) in new stack
– Executing [[email protected]:24] NoOp(“PJSIP/SfB-00000002”, “CRM Finished”) in new stack
– Executing [[email protected]:25] GotoIf(“PJSIP/SfB-00000002”, “0?bypass,1”) in new stack
– Executing [[email protected]:26] ExecIf(“PJSIP/SfB-00000002”, “0?Set(CONNECTEDLINE(num,i)=+49MYMOBILENUMBER)”) in new stack
– Executing [[email protected]:27] ExecIf(“PJSIP/SfB-00000002”, “0?Set(CONNECTEDLINE(name,i)=CID:0301234510)”) in new stack
– Executing [[email protected]:28] ExecIf(“PJSIP/SfB-00000002”, “0?Set(CONNECTEDLINE(name,i)=CID:(Hidden)0301234510)”) in new stack
– Executing [[email protected]:29] GotoIf(“PJSIP/SfB-00000002”, “0?customtrunk”) in new stack
– Executing [[email protected]:30] Dial(“PJSIP/SfB-00000002”, “PJSIP/[email protected],300,T”) in new stack
– Called PJSIP/[email protected]

I cannot add the SIP Invite debug because the forum software is telling me that “new users cannot add links”, but there isn’t any link…
It’s just a INVITE with no P-Asserted-Identity Header.

It sounds like you’re on the right track.
It’s not impossible that your provider is setting the outbound CID for you. This isn’t uncommon, and many providers will limit you to “non-foreign” numbers associated with your account.

Found it this weekend. It was so obvious, that I overlooked it for hours.
The “Outbound CID” on the Trunk was set. It seems that this overrides any manual setting.

Now there is only one problem remaining. If I get an incoming call everything is working fine, if I make an outgoing call both parties can not hear each other.

But: If I create a extension and call any external number (outgoing to ISP) its working, if I call the SfB trunk its working.
When I call from SfB to Mobile RTP debug does not show incoming RTP packets, only outgoing.