Send inbound calls to FreePBX from Cisco gateway

Hello everyone

I’m getting along quite good with FreePBX GUI and I read tutorials on my spare time so I can understand how the Asterisk configuration files work, but I am still quite a neophyte with VoIP in general.

We are migrating our workplace from Cisco to FreePBX. That’s about 400 telephones that have to be migrated or remplaced. We have set up a SIP trunk between our Cisco Call Manager and FreePBX so everyone can still talk to each other until we’re finished migrating everyone. We also have a trunk set up between FreePBX and our VoIP gateway, which is a Cisco router. This specific trunk handles outbound calls from Asterisk phones.

For now, inbound calls (=> people from outside our organization dialing our public phone number 418-555-9999) are still handled by the Cisco Call Manager, but we’re planning on re-recording the IVRs pretty soon, so we can turn the Call Manager offline for good. We do not plan on replacing the Cisco gateway with one of another brand (although I would love to, Cisco VoIP is a mess) because we’re planning to replace our external lines (currently a PRI with Telus) with a SIP service provider in the following year, if our Internet provider can fix their stability issues.

The plan now is to configure the Cisco gateway so that it sends all inbound calls to FreePBX.

FreePBX Distro is installed on a virtual machine on Hyper-V
FreePBX 10.13.66-19
Asterisk 13.19.1
VoIP gateway: Cisco C2801-IPVOICEK9-M running IOS 12.4

We’re planning on updating to the newest big version of FreePBX Distro in the following weeks. I am willing to do the upgrade sooner if someone thinks it might be of any help.

We have two trunks:
a SIP trunk “Cisco-GW” : FreePBX <-> Cisco Gateway
a PJSIP trunk “cucm01” : FreePBX <-> Cisco Call Manager

Outbound calls work fine:
Asterisk phone -> FreePBX -> SIP trunk “Cisco-GW” -> Cisco router -> Provider network (telus)

On the other hand, inbound calls currently take this path:
Provider (Telus) -> Cisco router -> Cisco Call Manager -> PJSIP Trunk “cucm01” -> FreePBX -> Asterisk Phone

We want inbound calls to do this:
Provider -> Cisco Router -> SIP trunk “Cisco-GW” -> FreePBX -> Asterisk Phone

We’re having many problems with the “cucm01” trunk between FreePBX and Call Manager (such as calls hanging up randomly), so we’re looking forward to finish this migration as quickly as possible

Looking on how to configure the Cisco router, I found this thread:

It looked rather simple, but it did not go as expected. When I try to call using an external phone (say my cellphone) nothing happens, no ringing.

I’ll include as much debug info as I can get. I’ll be replacing my personal phone number with 4185551111 and my work phone number with 4185559999. You might see in the logs that the trunk is actually named “CIsco-GW” (with a capital i) it was a typo, but still we made sure we’re using the same syntax everywhere.

I caught this in the asterisk console (Verbose 3) when the call goes in (sorry I don’t have the permission to post links on the forum yet): pastebin com/efrF3mQz

I captured 4 Packets using wireshark and a monitor session on the switch. Basically the gateway seems to send an INVITE request to FreePBX with all the right information (as far as I know, as I mentioned earlier I’m still learning all of this), the PBX server then sends “trying”, and then “Declined”. This happens 12 times in a second before the gateway gives up. The first packet contained an SDP packed encapsulated within it, I included it here: pastebin com/RsU70xnd

PBX <----- INVITE ----- Gateway
PBX ----- TRYING —> Gateway
PBX — DECLINED --> Gateway
PBX <----- ACK ------- Gateway

Below is the trunk configuration:

Cisco-GW Trunk

Trunk name: CIsco-GW (with capital i)


User context: from-internal


Note that outgoing calls can pass through this trunk without problem. Only incoming calls are troublesome

I also set up an inbound route in FreePBX that calls my extension when a call comes in, as we have no IVR set up yet. This is what I believe is the dial plan for this route (taken from extensions_additional.conf):

Inbound route
exten => 4185559999,1,Set(__DIRECTION=INBOUND)
exten => 4185559999,n,Gosub(sub-record-check,s,1(in,${EXTEN},dontcare))
exten => 4185559999,n,Set(__FROM_DID=${EXTEN})
exten => 4185559999,n,Set(returnhere=1)
exten => 4185559999,n,Gosub(app-blacklist-check,s,1())
exten => 4185559999,n(did),Set(CDR(did)=${FROM_DID})
exten => 4185559999,n,GotoIf(${LEN(${BLDEST})}?${BLDEST})
exten => 4185559999,n(callerid),ExecIf($[ "${CALLERID(name)}" = "" ] ?Set(CALLERID(name)=${CALLERID(num)}))
exten => 4185559999,n,Set(__MOHCLASS=)
exten => 4185559999,n,Ringing()
exten => 4185559999,n,Set(__RINGINGSENT=TRUE)
exten => 4185559999,n,Set(__REVERSAL_REJECT=FALSE)
exten => 4185559999,n,GotoIf($["${REVERSAL_REJECT}"!="TRUE"]?post-reverse-charge)
exten => 4185559999,n,GotoIf($["${CHANNEL(reversecharge)}"="1"]?macro-hangupcall)
exten => 4185559999,n(post-reverse-charge),Noop()
exten => 4185559999,n,Set(__CALLINGNAMEPRES_SV=${CALLERID(name-pres)})
exten => 4185559999,n,Set(__CALLINGNUMPRES_SV=${CALLERID(num-pres)})
exten => 4185559999,n,Set(CALLERID(name-pres)=allowed_not_screened)
exten => 4185559999,n,Set(CALLERID(num-pres)=allowed_not_screened)
exten => 4185559999,n(did-cid-hook),Noop(CallerID Entry Point)
exten => 4185559999,n(dest-ext),Goto(from-did-direct,2132,1)

Here is the Cisco router configuration file, note that I removed many unrelevant lines: pastebin com/XAL5rdmU

What catches my attention is the final line of the Asterisk console dump:

[2018-06-16 14:16:55] WARNING[27341][C-000006cc] pbx.c: Channel ‘SIP/CIsco-GW-00000976’ sent to invalid extension but no invalid handler: context,exten,priority=outbound-allroutes,4185559999,2

I can’t find a solution on google. The people I’ve seen with this message found they had made errors in their dial plan or so. It may be the case for me, but I just can’t see it.

I used this thread as a reference:

There’s a command that was in that thread that I did not set in my dial-peer:
numbering-type unknown
When I set that command, the gateway just doesn’t talk to the PBX. It’s like it can’t find any correspondence in the dial-peers list. So I removed it, and that’s where we are right now. I’m also not familiar with Cisco VoIP (I know call manager in some way that’s pretty much it), so the problem may as well be cause by a configuration problem in the Cisco gateway. If someone around here knows Cisco better than I do, I will gladly accept comments.

We’re planning on updating to the newer big version of FreePBX Distro in the following weeks. I am willing to do the upgrade sooner if someone thinks it might be of any help.

If there are debugging info or logs that I missed, I will gladly provide them. I will update this thread if I make any progression.

Thank you everyone for your help.

OK, I seem to have found the solution, after many days of trial and error.

One of my colleagues found me this forum post:

The problem was my SIP trunk between FreePBX and the cisco gateway. The context set in the “Outgoing” tab should be set to “from-trunk”, whereas in my previous post I had it set to “from-internal”. Proof that you can’t always blindly copy-paste stuff from the internet and hope it works without understanding what it does.


Now everything works perfectly!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.