Linksys SPA-3102 – Asterisk configuration HOWTO
The Linksys SPA3102 in a very inexpensive (under $80 US) and versatile FXO, FXS, VoIP SP Gateway, yet it is quite difficult to find clear instructions on how to configure its Web interface and how connect it to an Asterisk PBX.
The SPA3102 will allow you to connect your Asterisk box to both the Public Switched Telephone Network (PSTN) and an ordinary phone. This HOWTO will discuss the options that need to be set in the Web interface of a SPA3102 and the Asterisk configuration files that need to be created to set up simple Asterisk system consisting of only the SPA3102, an older computer (600 MHz or better CPU, 256 MB RAM and 10 GB hard drive) and a analog telephone.
This demo system is not very useful in itself. We will be spending about $100 to turn a single analog phone, that could connect directly to the PSTN, into an analog phone with a digital switch inserted before the PSTN. Once that is working, an addition of SIP based IP phones at about $100 each, or a couple of Linksys PAP2T-NAs at about $30 per port to allow you to use existing analog phones or the addition of any number of SIP or IAX2 based soft phones, and this demonstration unit will run a home or small business.
The installation of a Linux distribution on your computer and the compilation of the basic Asterisk software will not be covered here. You may want to purchase an Asterisk book for those instructions. Astrex For Dummies is now a bit dated, covering only Asterisk V 1.2 and Asterisk, The Future of Telephony. 2nd Ed. Is a good reference book, but does not cover less expensive Linksys hardware. For reference sake, my system is running CentOS and Asterisk 1.4.13.
There are multitudes of configuration options in the SPA3102 Web interface and I am presenting the results of considerable Google mining and experimentation. I relied heavily on: freepbx.org/support/document … 00-freepbx
and
forum.voxilla.com/linksys-sipura … 18612.html .
Only the options that I have altered from the defaults and some that are ‘interesting’ but left in the default state, are mentioned. In the instructions below, I have added comments following configuration setting by using a left arrow ‘<’.If I have missed useful features, please comment. I am new to Asterisk, but I hope this shortens another new user’s ramp-up.
To configure the SPA3102, initially set up your network like this: Internet source (cable or DSL MODEM) > wired router > Internet connection on the SPA3102 > Ethernet connection on the SPA3102 > Windows or Linux computer. For the moment, don’t connect anything to either the ‘Line’ or the ‘Phone’ ports on the SPA3102.
Ideally, you should configure your router so that it hands out a predictable address to the SPA3102 or you will need to determine the SPA3102’s address some other way.
Power up the SPA3102 and allow it to fully boot: about 15 seconds. It will now act as a DHCP server (192.168.0.x) on the Ethernet side. Boot your computer and it will pick up an address (192.168.0.2) from the SPA3102. Open a browser and check for connectivity. You should be able to reach internet sites unless your router is also using 192.168.0.x as a subnet and there is an address conflict. In that case, disconnect the SPA3102 from the internet. You will not need the internet for the moment. My internal subnet happens to be 192.168.5.x.
Now open a browser log onto the SPA3102 at 192.168.0.1 and choose the Administrator, advanced screen and:
…Go to the first tab, ‘Router’ and second sub-tab, ‘Wan Setup’:
…Internet Connection Settings: Leave as DHCP or set as static and fill in the other fields to describe your network.
…Optional Settings:
…HostName: SPA3102a < I have two SPA3102s
…Primary NTP Server: 0.pool.ntp.org
…Secondary NTP Server: 1.pool.ntp.org
…Remote Management
…Enable Wan Web Server: yes < We want to configure the SPA3102 from the ‘Internet’ port which is our internal LAN.
…Click Submit All Changes
…Go to the first tab ‘Router’ and third sub-tab ‘Lan Setup’:
…Networking Services: Bridge
…Lan Network Settings:
…Lan IP Address: 192.168.5.238 < Put it on the same subnet as your LAN
…Enable DHCP Server: no < We will use your existing DHCP server as the only DHCP server
…Click Submit All Changes
The computer will not be able to reload the SPA3102’s Web configuration pages because the network subnet has changed. To correct this, refresh your network settings. If you do not know how to do this, rebooting the computer will do the trick.
You can now disconnect your computer from your SPA3102 and connect it directly to your router. All of the following configuration steps will be done from the internet side of the SPA3102. To reduce confusion and wiring errors, I tend to fill the unused Ethernet port with a crimped, but empty, RJ45 plug. It can also be used and one additional port on your internal LAN.
Open a browser and navigate to the SPA3102 Web Page at its new address and:
…Go to the second tab, ‘Voice’ and the second sub-tab ‘System’:
…System Configuration:
…Here you can set both User and Admin passwords. You will probably want to revisit this page later, but I found it easier to do the configuration without passwords, and since I trust my physical environment, the IP address and passwords are written on the bottom of all devices themselves.
…Click Submit All Changes
…Go to the first tab ‘Voice’ and fifth sub-tab ‘Regional’:
…I live in North America, which is the default for this device, so I have no advice for the bulk of these settings. If you live elsewhere you will need to do additional research.
…Miscellaneous:
…Set Local Date and Set Local Time: These will be blank but have been set by NTP so there is no need to use them here.
…Check Time Zone: Make it applicable to your location.
…Check Daylight Saving Time Rule: Make it applicable to your location.
…Click Submit All Changes
…Go to the first tab ‘Voice’ and sixth sub-tab ‘Line 1’
…SIP Settings:
…SIP Port: Notice that it is set to 5060 for line 1 and 5061 for PSTN Line (next tab). These port values must be correctly transferred to the correct contexts in sip.conf.
…Proxy and registration:
…Proxy: 192.168.5.70 < The IP address of your Asterisk server
…Subscriber Information:
…Display Name: LivingRoom < This will be the test phone, but any name would do as lone as it is used in the configuration files.
…User ID: LivingRoom
…Password: SomePassword
…Auth ID: LivingRoom < probably not needed
…Dial Plan:
…Dial Plan: (*xx|[3469]11|0|00|[2-9]xxxxxxxxx|1xxx[2-9]xxxxxxxxxS0|xxxxxxxxxxxx.) < We have 10 digit local dialing. The default is set for seven digit local dialing. Adjust as needed.
…Emergency Number: < Hmmm, I don’t know what to do here: it’s probably important, but it is poor form to dial 911 just to test. . . Help?
…Click Submit All Changes
…Go to the first tab ‘Voice’ and seventh sub-tab ‘PSTN User’:
…SIP Settings:
…SIP Port: Notice that it is set to 5061 for PSTN User and 5060 for Line 1. These port values must be correctly transferred to the correct contexts in sip.conf.
…Proxy and Registration:
…Proxy: 192.168.5.70 < The IP address of your Asterisk server
…Subscriber Information:
…Display Name: PSTN1 < I have two lines so there is an PSTN2, but we will not discuss it here.
…User ID: PSTN1
…Password: SomePassword
…Auth ID: PSTN1 < probably not needed.
…Dial Plans:
…Dial Plan 2: (S0<:s>) < That is an S-zero. The incoming call will be passed to your extensions.conf file with extension ‘s’ where we will Playback a greeting to the caller and then playback the main menu of our internal users and their extension numbers. You can also use specific extension numbers, such as: (S0<:2091>), which will send all incoming calls to that extension for processing. This might work best with two or more external lines where a second call comes in while the first is being processed through the main menu and extension capture.
…VoIP-To-PSTN Gateway Setup:
…Line 1 VoIP Caller DP: 1 < Leave this at 1. The SPA3102 will use the Dial Plan 1 (above = (xx.)) so all your Dial Plan decision making will be done in the Asterisk extensions.conf file. The SPA3102 will dial out whatever Asterisk hands out.
…PSTN-To-VoIP Gateway Setup:
…PSTN Ring Thru Line 1: no < When this is ‘yes’, an incoming call goes directly through to Line 1. We only want line 1 to ring when Asterisk routs a call to it.
…PSTN CID for VoIP CID: yes < capture the Caller ID provided by the incoming call and pass it through to Asterisk to display on your internal phones.
…PSTN Caller Default DP: 2 < Change to 2. The incoming call will be passed to your extensions.conf file with extension ‘s’ as defined in Dial Plan 2 (above).
…Off Hook While Calling VoIP: no < I read this in some Google search. I don’t know what it does, but stuff seems to work. Help?
…FXO Timer Values (sec):
…PSTN Answer Delay: 5 < Delay so that you can get the CID data. NghtShd at forum.voxilla.com/linksys-sipura … 18612.html claims that 5 seconds is long enough.
…Click Submit All Changes
Any additional changes to the SPA3102 can be made from anywhere on the network so we can now begin to configure the Asterisk box. Plug the simplest, tested, unpowered, Touch Tone telephone handset that you can get from a used junk shop into the ‘Phone’ line on the SPA3102 and connect the ‘Line’ port to a standard, tested, PSTN jack in your wall. There is no need to disconnect the rest of your regular phones from the circuit, but you might want to advise the other members of your household when you will be doing testing. You will also need use of a cell phone or a second landline so that you can call into your Asterisk box from the PSTN port.
The SPA3102 interfaces with Asterisk through two files: sip.conf and extensions.conf.
This ‘starter’ sip.conf will establish contexts for the attached analog phone (LivingRoom) connected to the ‘Phone’ jack of the SPA3102 and your PSTN wall jack attached to the ‘Line’ jack (PSTN1) on the SPA3102. Calls coming into the SPA3102, either from the PSTN or the attached phone will be passed to the Asterisk box for processing and to be switched to the correct extension. As this demo system has only one phone and one line, the logic is trivial, but acts as proof of concept and will allow you to add more phones or lines to build a useful system.
/etc/asterisk/sip.conf
[general]
context=default
; srvlookup=yes ; useful if you have an external SIP provider
; This is the context for the analog phone
[LivingRoom] ; Ex. 2010, SPA3102a-1, 192.168.5.232 port 5060
type=friend ; device ‘LivingRoom’ can make and take calls
; secret=goodpass ; put this password in the Line 1 tab
qualify=yes ; Check if the device is alive from time to time
nat=no ; No firewall between the SPA3102 and Asterisk
host=dynamic ; The device will register with Asterisk
port=5060 ; every line on a device gets its own port
canreinvite=no ; We do not use an external SIP provider
context=internal ; The device ‘FAX’ (SPA3102a-1) will be assigned the ; extension 2010 and switched to another device under ; the context ‘internal’ in /etc/asterisk/extensions.conf
; PSTN phone: Line 1
[PSTN1] ; Ex. 2091, SPA3102a-2, 192.168.5.232 port 5061
disallow=all ; Turn off all codex
allow=all ; Turn them all back on
username=PSTN1 ; Used in extensions.conf
canreinvite=no ; Useful if you have an external SIP VoIP provider
type=friend ; Device PSTN1 can make and take calls
; secret=goodpass ; put this password in the PSTN Line tabs
qualify=yes ; Check if the device is alive from time to time
nat=no ; No firewall between the SPA3102 and Asterisk
dtmfmode=auto ; How Touch Tones are transmitted
host=dynamic ; The device will register with Asterisk
port=5061 ; every line on a device gets its own port
insecure=very ; Determine how to authenticate a device
context=internal ; The device ‘PSTN1’ (SPA3102a-1) will be assigned the ; extension 2091 and switched to another device under ; the context ‘internal’ in /etc/asterisk/extensions.conf
/etc/asterisk/extensions.conf
[globals] ; context global
[general] ; context general defined in iax.conf & sip.conf
autofallthrough=yes ; from * TFOT
[internal] ; context internal defined in iax.conf & sip.conf
ignorepat => 9 ; see if we get a dialtone after 9, Well, it doesn’t. Help?
; Inbound PSTN calls will start here
exten => s,1,Answer() ; Answer inbound calls or internal miss-dials
exten => s,2,Playback(silence/1)
exten => s,3,Background(enter-ext-of-person) ; input an extension
exten => s,n,WaitExten(20) ; Adjust wait, default 5 sec
exten => s,n,Goto(internal,${EXTEN},1) ; Goto the correct extension
exten => s,n,Hangup() ; End the call
; LivingRoom 2010 SIP SPA3102a-1 (SPA3102a-2 is the PSTN port)
exten => 2010,1,Answer() ; Answer the call
exten => 2010,n,Verbose(1|Call LivingRoom 2010 SIP SPA3102a-1) ; Log it
exten => 2010,n,Dial(SIP/LivingRoom,15) ; Ring the extension
exten => 2010,n,Hangup() ; End the call
; PSTN, 2091 SIP SPA3102a-2 to PSTN line
; This context was added to show how to process an incoming call at a
; specific extension number
exten => 2091,1,Answer() ; Answer the call
exten => 2091,n,Verbose(1|Inbound call on SIP SPA3102a-2) ; Log it
exten => 2091,n,Wait(1) ; 1 sec pause to sync phone
exten => 2091,n,Playback(silence/1) ; 1 sec to sync phones
exten => 2091,n,Background(enter-ext-of-person) ; Line 1
exten => 2091,n,WaitExten(20) ; Adjust wait, default 5 sec
exten => 2091,n,Goto(internal,${EXTEN},1) ; Goto the correct extension
exten => 2091,n,Hangup() ; End the call
exten => i,1,Playback(pbx-invalid) ; We have only one valid extension, 2010
exten => i,2,Goto(internal,s,1) ; send them back to try again
exten => t,1,Playback(vm-goodbye) ; This is not working as expected. Help?
exten => t,2,Hangup ; too slow, or no hangup > dump them
Copy and paste these files into the correct locations and restart Asterisk and you should be able to dial out with ‘9’ area_code seven_digit_number. You may want to call your local recorded time or weather for testing. Then grab a cell phone and try calling yourself. You should get instructions to enter an extension. With ‘2010’ the analog phone will ring. With a ‘wrong’ extension, you will get redirected back to enter an extension.
Buy a book. Start to experiment. Free soft phones are good.
The iax channel of ZoIPer soft phone punches through NAT on a router better than SIP. You will need to fiddle with your firewall to port forward UDP packets on port 4569 to your Asterisk box and determine your external IP address, but with some experimenting you can connect your road warier to your PBX reliably. So for good measure, here is a iax.conf file.
/etc/asterisk/iax.conf
[general]
;bandwidth=low ; Adjustable, not in use
;disallow=lpc10 ; Disallow some compression methods
jitterbuffer=no ; Sounds good, but increases latency
eforcejitterbuffer=no ; Sounds good, but increases latency
tos=lowdelay ; Only affects IAX2 packets as they leave the LAN
autokill=yes ; Do not attempt to re-register a remote device after ; 2000 mSec (adjustable)
[2023] ; Ex. 2023, ZoIPer on John’s D610
type=friend ; Device 2032 can make and take calls
host=dynamic ; The device must register with Asterisk
qualify=no ; This is a soft phone on a notebook, so we will not
; attempt to qualify endlessly, only when there is a call
context=internal ; Device 2023 will be assigned an extension under the
; the context ‘internal’.
Add these lines to /etc/asterisk/extensions.conf between [LivingRoom] and [PSTN1]:
; John’s Notebook 2023 IAX2 ZoIPer on D610
exten => 2023,1,Answer() ; Answer the call
exten => 2023,n,Verbose(1|Call to John 2023 IAX2 ZoIPer on D610) ; Log it
exten => 2023,n,Dial(IAX2/2023,15) ; Ring the extension
exten => 2023,n,Hangup() ; End the call
Remember, I am new to this, so these config files are primitive. You will hear that there are some strange delays, there are rough edges and security holes. I have also asked for help where some bits don’t work. If you find solutions or errors, add them to the thread. If you just read it and benefit, simply tag on an extra post and the thread will move back to the top of the list so that newbies are more likely to find it.
Enjoy: John T