FreePBX as a SIP gateway to a legacy PBX via PRI

I have a new FreePBX 2.9.0.5 build clean with a Digium TE121B. I have configured it as a SIP gateway to a legacy PBX.
I can call from the Legacy PBX through the PRI to an extension on the Asterisk PBX, no problem.
I can call from the Asterisk PBX through the PRI to an extension on the Legacy PBX, no problem.
I can route a SIP DID from the Asterisk PBX through PRI to an extension on the legacy PBX, no problem.
I cannot make an outbound call from the legacy PBX through the PRI to the Asterisk PBX and then out the SIP Trunk. If I assign a Inbound route to the Asterisk server of the number I am calling then the call will go out the SIP trunk. So I tried to use wildcards in my inbound routes. It does not seem to pass the dialed number through.
Here is my log, any help would be greatly appreciated.
– Accepting call from ‘’ to '1XXXXXXXXXX ’ on channel 0/23, span 1
– Executing [1XXXXXXXXXX @from-pstn:1] Set(“DAHDI/i1/-2”, “__FROM_DID=1XXXXXXXXXX”) in new stack
– Executing [1XXXXXXXXXX @from-pstn:2] NoOp(“DAHDI/i1/-2”, "Received an unknown call with DID set to 1XXXXXXXXXX ") in new stack
– Executing [1XXXXXXXXXX @from-pstn:3] Goto(“DAHDI/i1/-2”, “s,a2”) in new stack
– Goto (from-pstn,s,2)
– Executing [s@from-pstn:2] Answer(“DAHDI/i1/-2”, “”) in new stack
– Executing [s@from-pstn:3] Wait(“DAHDI/i1/-2”, “2”) in new stack
– Executing [s@from-pstn:4] Playback(“DAHDI/i1/-2”, “ss-noservice”) in new stack
– <DAHDI/i1/-2> Playing ‘ss-noservice.ulaw’ (language ‘en’)
– Channel 0/23, span 1 got hangup request, cause 16
== Spawn extension (from-pstn, s, 4) exited non-zero on ‘DAHDI/i1/-2’
– Executing [h@from-pstn:1] Macro(“DAHDI/i1/-2”, “hangupcall,”) in new stack
– Executing [s@macro-hangupcall:1] GotoIf(“DAHDI/i1/-2”, “1?theend”) in new stack
– Goto (macro-hangupcall,s,3)
– Executing [s@macro-hangupcall:3] Hangup(“DAHDI/i1/-2”, “”) in new stack
== Spawn extension (macro-hangupcall, s, 3) exited non-zero on ‘DAHDI/i1/-2’ in macro ‘hangupcall’
== Spawn extension (from-pstn, h, 1) exited non-zero on ‘DAHDI/i1/-2’
– Hungup ‘DAHDI/i1/-2’

You need to set the context of your trunk to ‘from-internal’ and it will follow the outbound dial rules. ‘from-internal’ treats the calls as if they came from an extension. You can’t accept a call into the ‘from-did’ or 'from-pstn ’ context and send it to the internal dial plan.

Still learning but I think I set it here in the dahdi-channels.conf file. I commented out the “context=from-pstn” and added “context=from-internal”. I thought I tried to test this once and it did not work. I will test back in the lab tomorrow. Thanks again for the direction.

; Span 1: WCT1/0 “Wildcard TE121 Card 0” (MASTER) B8ZS/ESF ClockSource
group=0,11
;context=from-pstn
context=from-internal
switchtype = national
signalling = pri_net
channel => 1-23
context = default
group = 63

Better but now I am getting this back. Anymore suggestions?

– Accepting call from ‘’ to ‘1XXXXXXXXXX’ on channel 0/23, span 1
– Executing [1XXXXXXXXXX@from-internal:1] ResetCDR(“DAHDI/i1/-f”, “”) in ne w stack
– Executing [1XXXXXXXXXX@from-internal:2] NoCDR(“DAHDI/i1/-f”, “”) in new s tack
– Executing [1XXXXXXXXXX@from-internal:3] Progress(“DAHDI/i1/-f”, “”) in ne w stack
– Executing [1XXXXXXXXXX@from-internal:4] Wait(“DAHDI/i1/-f”, “1”) in new s tack
– Executing [1XXXXXXXXXX@from-internal:5] Progress(“DAHDI/i1/-f”, “”) in ne w stack
– Executing [1XXXXXXXXXX@from-internal:6] Playback(“DAHDI/i1/-f”, “silence/ 1&cannot-complete-as-dialed&check-number-dial-again,noanswer”) in new stack
– <DAHDI/i1/-f> Playing ‘silence/1.ulaw’ (language ‘en’)
– <DAHDI/i1/-f> Playing ‘cannot-complete-as-dialed.ulaw’ (language ‘en’)
– <DAHDI/i1/-f> Playing ‘check-number-dial-again.ulaw’ (language ‘en’)
– Channel 0/23, span 1 got hangup request, cause 16
== Spawn extension (from-internal, 1XXXXXXXXXX, 6) exited non-zero on ‘DAHDI/i1/-f’
– Executing [h@from-internal:1] Hangup(“DAHDI/i1/-f”, “”) in new stack
== Spawn extension (from-internal, h, 1) exited non-zero on ‘DAHDI/i1/-f’
– Hungup ‘DAHDI/i1/-f’

Do you have an outbound route that matches the dial digits?

When I did this I had my legacy PBX keep the leading ‘9’ when passing the number to the PRI. Then I used the standard(?) 9_outside route.

You guys are the best!!! Thank you for your help. I forgot to set the outbound route to the number pattern being dialed. It is working now!!!