{"id":41,"date":"2007-12-27T13:06:37","date_gmt":"2007-12-27T20:06:37","guid":{"rendered":"http:\/\/www.kernelcrash.com\/blog\/2007\/12\/27\/asterisk-pbx-and-the-spa-3102\/"},"modified":"2008-01-07T20:40:39","modified_gmt":"2008-01-08T03:40:39","slug":"asterisk-pbx-and-the-spa-3102","status":"publish","type":"post","link":"https:\/\/www.kernelcrash.com\/blog\/asterisk-pbx-and-the-spa-3102\/2007\/12\/27\/","title":{"rendered":"Asterisk PBX and the SPA 3102"},"content":{"rendered":"<p>I&#8217;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 &#8216;just work&#8217;.<\/p>\n<p>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 <a href=\"http:\/\/www.asterisk.org\">Asterisk<\/a> 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 &#8230; 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 &#8216;free&#8217; 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.<\/p>\n<p>I won&#8217;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&#8217;t all agree so it tends to be very confusing.  I guess I don&#8217;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.<\/p>\n<p>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) &#8230; and is probably worth reading before you try this stuff out. It does actually explain a lot of key things in Asterisk.<\/p>\n<p>I won&#8217;t bore you with any more gripes, but here&#8217;s some helpful things:<\/p>\n<p>&#8211; 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:<\/p>\n<pre>\r\n[trunk_2]\r\nusername = pstn\r\nallow = all\r\ncontext = DID_trunk_2\r\ndialformat = ${EXTEN:1}\r\nhasexten = no\r\nhasiax = no\r\nhassip = yes\r\nport = 5061\r\nregisteriax = no\r\nregistersip = no\r\nsecret = 12345678\r\ntrunkname = Custom - telecom\r\ntrunkstyle = customvoip<\/pre>\n<p>I set up the spa under the &#8216;PSTN Line&#8217; tab so that it has user id &#8216;pstn&#8217; 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 &#8216;failed to register&#8217;). 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:<\/p>\n<pre>\r\n<strong>[pstn]<\/strong>\r\nusername = pstn\r\nfromuser=pstn\r\ntype = friend\r\ndisallow = all\r\nallow = ulaw\r\nallow = alaw\r\nallow = g723.1\r\nallow = gsm\r\ncontext = DID_trunk_2\r\ndialformat = ${EXTEN:1}\r\nhasexten = no\r\nhasiax = no\r\nhassip = yes\r\nhost = dynamic\r\nport = 5061\r\nregisteriax = no\r\nregistersip = no\r\nsecret = 12345678\r\ntrunkname = Custom - telecom\r\ntrunkstyle = customvoip<\/pre>\n<p>NB: If you manually change the context name from trunk_2 to pstn like I did you&#8217;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 &#8216;trunk_2&#8217;)<\/p>\n<p>&#8211; 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 &#8216;disconnect detection&#8217; in the SPA. In the &#8216;PSTN Line&#8217; tab of the SPA config you&#8217;ll see a &#8216;Disconnect Tone&#8217; setting. Mine was set to the following by default:<\/p>\n<p>480@-30,620@-30;4(.25\/.25\/1+2)<\/p>\n<p>I&#8217;m in New Zealand, so I needed to set it up for a NZ disconnect tone. I didn&#8217;t find any examples when I did a search, so I had a look at the NZ telepermit specs and tried this:<\/p>\n<p>400@-30,400@-30;1(.250\/.250\/1+2)<\/p>\n<p>That worked, but to be honest I don&#8217;t understand half of it (NB:I&#8217;ve since found a great reference for world wide  telephone tones at <a href=\"http:\/\/www.3amsystems.com\/wireline\/tone-search.htm?start=0&amp;kCountry=128&amp;format=Sipura\">3amsystems.<\/a>  It has the disconnect tone as 400@-30,400@-30; 2(0.25\/0.25\/1+2)  so I was pretty close)<\/p>\n<p>Also, I found a post in a geekzone.co.nz forum suggesting you use &#8216;370+620||310nF&#8217; as the FXO Port Impedance. I&#8217;ve left the gain figures on the SPA to zero &#8230; but I&#8217;m often told by some callers that they can hardly hear me, so maybe I should try some different gains.<\/p>\n<p>&#8211; Here are some of the key settings I have in the &#8216;PSTN Line&#8217; tab of the SPA 3102 config to have it work as a SIP trunk with Asterisk:<\/p>\n<pre>\r\nLine Enable: yes\r\nSIP Port: 5061\r\nProxy:  [address of my asterisk box]\r\nRegister: yes\r\nDisplay Name: pstn\r\nUser ID: pstn\r\nPassword: [your password you setup on Asterisk]\r\nDial Plan 2: (S0&lt;:s&gt;)\r\nVOIP-To-PSTN Gateway Enable: yes\r\nPSTN-To-VOIP Gateway Enable: yes\r\nPSTN CID For VOIP CID: yes\r\nPSTN Caller Default DP: 2   (ie. use the dial plan 2 setup earlier)<\/pre>\n<p>&#8211; 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&#8217;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:<\/p>\n<pre>\r\n;\r\n; Create voicemail mailbox and use use macro-stdexten\r\n;\r\nhasvoicemail = yes<\/pre>\n<p>I&#8217;m not sure why &#8216;hasvoicemail&#8217; would enable this macro. I haven&#8217;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&#8217;t answer or are busy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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 &#8216;just work&#8217;. But part of the reason I bought the SPA is because you can split it into [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,3],"tags":[],"class_list":["post-41","post","type-post","status-publish","format-standard","hentry","category-asterisk","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/41","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/comments?post=41"}],"version-history":[{"count":0,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/media?parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/categories?post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/tags?post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}