PSTN with Cisco SPA devices, FreePBX & Asterisk
Table Of Contents
Abstract
This page deals with getting PSTN lines working with Asterisk/FreePBX when using a Cisco SPA (such as a 3012 or 232D)
The author has found a few pages that get most of the way there, but each has it's own issues - and this will get you running with the SPA as a trunk for incoming & outgoing calls, inbound CLID presentation, Privacy Manager and Google Contacts not breaking Privacy Manager.
Please read ALL of the page, as it's all relevant, and please send some feedback via the Contact form if you found it useful!
Detail
FreePBX is a rather marvelous, free way to control Asterisk - which is in itself a rather marvelous, free, Voice over IP (VoIP) server.
This author has a traditional PSTN line to the house, as well as various SIP lines with their own (Direct Inbound Dialling, or DID) number. In the past, with a Cisco SPA3102, Asterisk (8 thru 11) have been mostly made to work with the SPA, so that the PSTN line would be a failover line if any of the VoIP lines failed.
Asterisk will use the SPA device as a trunk, meaning it will allow devices on the network to make calls, which can route over the PSTN line. Additionally it will allow incoming calls to the PSTN line, to ring devices on the network.
Disclaimer : These instructions were set using FreePBX 13.0.192.19 and Asterisk GIT-15-caad08d on Debian Jessie, mostly built using the official FreePBX instructions, but as long as you have FreePBX 13+ and Asterisk 14 or higher, you should probably be fine!
Notes:
The instructions below require access to the SPA advanced administrator pages (it is presumed you have access to this!)
The instructions below require access to the FreePBX administrator pages (it is presumed you have access to this!)
{Your Asterisk Server IP} should be replaced with your Asterisk server IP, i.e. 192.168.1.10 (or whatever yours is)
{Your SPA IP} should be replaced with your SPA device IP, i.e. 192.168.1.20 (or whatever yours is)
{Your PSTN DID} should be replaced with your PSTN line number, i.e. 01234567890
{Incoming SPA} should be replaced with something such as incomingspa (or whatever you want to refer to your SPA device as) - however do NOT use the same value as {Your PSTN DID}
{Incoming SPA Password} should be replaced with a password you will set/use for <Incoming SPA>
Field names to change are highlighted in italic
Settings to use in the fields are highlighted in bold. Anything not in bold should not be entered anywhere
Curly {} brackets have been used as setting identifiers - they can be removed. Any other character you see in a bold section should be copied as is
The instructions below are based on a Cisco SPA232D, but the fields are mostly common with SPA3102s and other devices...
Cisco SPA Configuration
Open the PSTN settings tab or page, and find the SIP Settings section
Check the SIP port is set to 5061 (this is normally default)
Within the Proxy and Registration section
Change Proxy to {Your Asterisk Server IP}:5160 (5160 is the default port for a pjsip trunk, which you'll configure later)
Change Register to no (your SPA will not be registering with Asterisk)
Change Use OB Proxy in Dialog to yes
Change Make call without reg to yes
Change Answer call without reg to yes
Within the Subscriber Information Section
Leave Display Name blank. If anything is in there, clear it out
Change User ID to {Incoming SPA}
Change Password to {Incoming SPA Password}
Change Use Auth ID to yes
Change Auth ID to {Incoming SPA}
Within the Dial Plans section
Ensure Dial Plan 1 is (xx.)
Change Dial Plan 8 to (S0<:{Your PSTN DID}@{Your Asterisk Server IP}>)
NB : Include all the () and <> brackets you see above, just NOT the {} ones!
Within the VoIP-To-PSTN Gateway Setup section
Change VoIP to PSTN GW Enable to yes
Change VoIP Caller Auth Method to HTTP Digest
Change One Stage Dialling to Yes
Set each of:
Line 1 VoIP Caller DP
DECT Line Caller DP
VoIP Caller Default DP
Line 1 Fallback DP
to none
Within the VoIP Users and Passwords (HTTP Authentication) section
Change VoIP User 1 Auth ID to {Incoming SPA}
Ensure VoIP User 1 DP is left at 1
Change VoIP User 1 Password to {Incoming SPA Password}
Within the PSTN-To-VoIP Gateway Setup section
Change PSTN-To-VoIP Gateway Enable to yes
Change PSTN Caller Auth Method to none
Change PSTN Ring Thru to no
Change PSTN CID For VoIP CID to yes
Change PSTN Caller Default DP to 8
Within the PSTN Timer Values (sec) section
Change VoIP Answer Delay to 1
NB : Setting to 0 has sometimes meant the SPA is quicker than Asterisk and calls don't complete. Setting to 1 may mean you get 1 (or 2) ringtones calling out, but this is better than the occasional abandoned outgoing callChange PSTN Answer Delay to 2
Click Submit
Your SPA should reboot, taking about 40 seconds....
NB: This article is not concerned with regional settings for your PSTN line. If you're a UK user, the ones found here are usable.
FreePBX Configuration
Within the Connectivity > Trunks section
Click + Add Trunk and select Add SIP (chan_pjsip) Trunk (do NOT add a chan_sip trunk)
On the General tab
Change Trunk Name to {Your PSTN DID}
Change Outbound CallerID to {Your PSTN DID}
Change Maximum Channels to 1
Click Submit
On the pjsip Settings tab
On the General sub tab
Change Username to {Incoming SPA}
Change Secret to {Incoming SPA Password}
Change SIP Server to {Your SPA IP}
Change SIP Server Port to 5061
Change Context to from-pstn
Click Submit
On the Advanced sub tab
Change DTMF Mode to inband
Ensure Permanent Auth Rejection is NOT highlighted
Change Forbidden Retry Interval to 10
Change General Retry Interval to 15
Change Expiration to 60
Change Max Retries to 10
Change Qualify Frequency to 15
Click Submit
Within the Connectivity > Outbound Routes section
Click Add Outbound Route
On the Route Settings tab
Change Route Name to Force PSTN
Under Trunk Sequence for Matched Routes select the trunk named {Your PSTN DID}
Click Submit
On the Dial Patterns tab
Leave Prepend blank
Change Prefix to 9
Change Match Pattern to X.
Note: Not counting for spaces & blank fields, the line you entered should look something like ()9|X./Click Submit
Within the Connectivity > Inbound Routes section
Click Add Inbound Route
Change Description to My PSTN Line
Change DID Number to {Your PSTN DID}
Under Set Destination choose Extension and then choose the extension you want to ring when someone calls your PSTN DID.
Note: This author uses a ring group, so select whatever works best for you.Click the red Apply Config button at the top of the screen
If you now pick up an extension and dial a number, prefixed with a 9, you should get a call made over your PSTN line.
Similarly, if you call your PSTN DID from another number (i.e. your mobile), you should hear ringing (on your mobile) for 1-2 seconds as the SPA answers the call and process CLI, before passing the call to Asterisk, where your chosen extension or ring group should ring, presenting your mobile CLI.
You can also now use the new PSTN trunk as a failover, in the event a SIP line you may use as a primary is either busy, or out of credit etc.
Similarly, you might want to set a new Outbound Route for your emergency number (999, 112, 911 etc) and use the PSTN as the default trunk for that, set as an Emergency Route, with the dial pattern set to whatever your regional emergency number is (999, 112, 911 etc).
If you're interested, what you've basically done is:
Outgoing Calls
You've configured the SPA as a VoIP (Asterisk) to PSTN (your line) gateway
You've created a user ( {Incoming SPA} ) on the SPA
You've told FreePBX that any calls prefixed with a 9 will send calls over the trunk named {Your PSTN DID}
You've configured the trunk to authenticate with the SPA using the account {Incoming SPA}
The SPA accepts the call and initiates a PSTN call, and bridges it back to your dialling extension through Asterisk
Incoming Calls
You've configured the SPA to know about Asterisk (via {Your Asterisk Server IP} )
You've configured the SPA to not register with Asterisk, so it just "waits" for PSTN calls
You've also configured the PSTN (your line) to VoIP (Asterisk) gateway
You've told the SPA to wait 2 seconds when it gets a call (which is enough time to receive CLI information)
You've told the SPA that any incoming PSTN calls will use Dial Plan 8
Dial Plan 8 immediately sends all calls to a user called {Your PSTN DID} on {Your Asterisk Server IP} - using Dial Plan 8
Asterisk doesn't have a user called {Your PSTN DID}, but it matches the call against the trunk setup for {Your PSTN DID}
The Inbound Route for {Your PSTN DID} then sends the call to your extension
This method also resolves a problem the author found, where the author used Google Contacts within the FreePBX CallerID Superfecta. All calls from the SPA to Asterisk will be initiated as {Incoming SPA} before the number is replaced with the inbound CLI. Similar instructions to the above exist, but suggest you use {Your PSTN DID} where this article uses {Incoming SPA}. That will still work, but if you use Google Contacts in the Superfecta and have an entry called "Home" or "Home Phone" with your PSTN DID in, FreePBX will use that when incoming calls don't have a CLID (i.e. number withheld) - which means Privacy Manager (if you use it) never works....
This author also found that occasionally, calls over the PSTN trunk would fail on first attempt - which seemed to be down to registration issues (timeouts) on the SPA - so the lowered timing settings correct this.
Hopefully this has been of use. If it has, please let us know!