Asterisk PBX and the SPA 3102

I’ve had a Linksys SPA3102 for a while now connected up to a single VOIP provider. For the most part it works great. You turn it on and it pretty much always works. I like things that ‘just work’.

But part of the reason I bought the SPA is because you can split it into the FXO (pstn) and FXS(handset) side to work with an Asterisk server. Asterisk is a very popular computer PBX system. The type of setup I wanted was one where I could get asterisk to route calls out the pstn of the SPA box and also use the handset as a regular extension … and also have a couple of softphones as extensions, plus also route calls out to my VOIP provider. I primarily wanted to play around and undestand the IVR, voicemail and other features. This ‘free’ PBX stuff is very much crossing over into the domain of Unix Admins, so I have a vested interest in it. I also wanted to be able to have multiple DID (dial in numbers) via multiple VOIP providers and as far as I know you cannot do that with an SPA.

I won’t go into too much detail about the configuration of Asterisk other than to say it sucks. There seem to be a zillion websites and forum posts out there each describing some little nuance of Asterisk configuration and they don’t all agree so it tends to be very confusing. I guess I don’t just want to know the magic parameter settings in the config files. I want to know what they do and how they relate to other parts of the config.

Initially I started using the v1.2.x Asterisk included in Debian Etch stable and tweaking the sip.conf and extensions.conf files by hand but then I thought maybe the Asterisk GUI that you can get for Asterisk v1.4.x will make things easier so I compiled v1.4.x of Asterisk as well as the svn of the Asterisk-GUI. Even with the GUI I got stuck several times and had to tweak the config files anyway. Admitedly the Oreilly book you can freely download from the asterisk website is actually a reasonably good book (like most Oreilly stuff) … and is probably worth reading before you try this stuff out. It does actually explain a lot of key things in Asterisk.

I won’t bore you with any more gripes, but here’s some helpful things:

– I had trouble setting up the PSTN interface of the SPA using the Asterisk GUI. I just added it in as a custom service provider and the GUI added some lines like the following to users.conf:

[trunk_2]
username = pstn
allow = all
context = DID_trunk_2
dialformat = ${EXTEN:1}
hasexten = no
hasiax = no
hassip = yes
port = 5061
registeriax = no
registersip = no
secret = 12345678
trunkname = Custom - telecom
trunkstyle = customvoip

I set up the spa under the ‘PSTN Line’ tab so that it has user id ‘pstn’ and the proxy setting was the IP of my asterisk box and the password was set ok. But everytime I rebooted the SPA, the pstn would not register (ie. I would see a message on the asterisk console saying ‘failed to register’). It took a long time to work out that the username the SPA logs in as must be the same as the context name. So now I have something like:

[pstn]
username = pstn
fromuser=pstn
type = friend
disallow = all
allow = ulaw
allow = alaw
allow = g723.1
allow = gsm
context = DID_trunk_2
dialformat = ${EXTEN:1}
hasexten = no
hasiax = no
hassip = yes
host = dynamic
port = 5061
registeriax = no
registersip = no
secret = 12345678
trunkname = Custom - telecom
trunkstyle = customvoip

NB: If you manually change the context name from trunk_2 to pstn like I did you’ll pretty much have to change all the other references to trunk_2 to pstn (or the easy way would have been to change the SPA PSTN config so the login username was ‘trunk_2’)

– When I eventually got the SPA pstn bit setup, I set up a simple echo test dial plan. I would call the PSTN external number, asterisk would pick up and tell me it was an echo test etc. The problem though was that when I hung up, asterisk would not work out that the call had ended. This has to to do with the ‘disconnect detection’ in the SPA. In the ‘PSTN Line’ tab of the SPA config you’ll see a ‘Disconnect Tone’ setting. Mine was set to the following by default:

480@-30,620@-30;4(.25/.25/1+2)

I’m in New Zealand, so I needed to set it up for a NZ disconnect tone. I didn’t find any examples when I did a search, so I had a look at the NZ telepermit specs and tried this:

400@-30,400@-30;1(.250/.250/1+2)

That worked, but to be honest I don’t understand half of it (NB:I’ve since found a great reference for world wide telephone tones at 3amsystems. It has the disconnect tone as 400@-30,400@-30; 2(0.25/0.25/1+2) so I was pretty close)

Also, I found a post in a geekzone.co.nz forum suggesting you use ‘370+620||310nF’ as the FXO Port Impedance. I’ve left the gain figures on the SPA to zero … but I’m often told by some callers that they can hardly hear me, so maybe I should try some different gains.

– Here are some of the key settings I have in the ‘PSTN Line’ tab of the SPA 3102 config to have it work as a SIP trunk with Asterisk:

Line Enable: yes
SIP Port: 5061
Proxy:  [address of my asterisk box]
Register: yes
Display Name: pstn
User ID: pstn
Password: [your password you setup on Asterisk]
Dial Plan 2: (S0<:s>)
VOIP-To-PSTN Gateway Enable: yes
PSTN-To-VOIP Gateway Enable: yes
PSTN CID For VOIP CID: yes
PSTN Caller Default DP: 2   (ie. use the dial plan 2 setup earlier)

– In many of the example for extensions.conf you find on the net it has some examples showing how the dial plans work when dialling between extensions. However, with my asterisk-gui setup there didn’t seem to be anything in extensions.conf to configure this, yet I could call between extensions just fine. It turns out there is a macro called stdexten that gets used somehow. There is a bit in users.conf that says:

;
; Create voicemail mailbox and use use macro-stdexten
;
hasvoicemail = yes

I’m not sure why ‘hasvoicemail’ would enable this macro. I haven’t found anything in that Oreilly Asterisk book about it. Anyway, if you search for macro-stdexten in extensions.conf you should find some dial plan stuff that handles the calls between extensions and also sends the caller to voicemail if they don’t answer or are busy.