miércoles, 8 de diciembre de 2010

SPA-3102 con Elastix

How to setup a Linksys SPA-3102 or Sipura SPA-3000 with FreePBX

Here is how you can setup Linksys/Sipura SPA-3000 series devices to work with FreePBX. These instructions were originally written for the Sipura SPA-3000, but are also applicable to the Linksys SPA-3102.
It took a lot of work to get the SPA-3000 working, but what finally got it working was very simple setup.
The FXS port (where you plug in your phone) is set up in the normal manner, just as on the Linksys PAP2 or a Sipura unit. So when you want to set up that port (labeled "Line 1" in the web interface), just look for instructions for setting up a Line port on a PAP2 or SPA-2000 (such as How to set up a Linksys PAP2 or Sipura SPA-2000 for use with FreePBX) - the setup of the FXS port is pretty much identical to those devices. What were are concerned with here is the FXO port, that is, the port that connects to the PSTN telephone line (appropriately labeled "PSTN Line" in the web interface).
Before you begin you may want to make sure you have the latest firmware, which at this writing may be available at theLinksys site. Note that the old Sipura site (which is now redirected to the Linksys site) implied that if you had 2.0 hardware you had to use 2.0 series firmware. However, at least two people have successfully upgraded a 2.0.x series SPA-3000 to firmware revision 3.1.10(GWd). No guarantees, but if you are feeling lucky (and can locate the firmware) you may want to try it. Of course if you have the 3.0.x series hardware you can definitely upgrade your firmware. The upgrade will give you some additional settings but will wipe any current configuration, so you will want to do that first if you intend to do it. You may want to hold off on the upgrade unless you experience problems - that is up to you.

FreePBX Trunk setup:

For the PSTN setup here is what I did to finally get it working.
1) Create a new SIP trunk in FreePBX.
2) For Caller ID I put my inbound DID there since it's from my BellSouth POTS line.
3) Max channels: I put 1 since it's only one line. This is important because if you don't do this, and this trunk is busy, calls may not fall through properly to the next trunk, due to a combination of bugs in certain versions of Linksys/Sipura firmware, and a bug in chan_sip in some versions of Asterisk. Even with this set, this bug can still bite you if you have an Asterisk version earlier than 1.2.16, the device is in use for an incoming call and the system attempts to use it for an outgoing call (the max channels logic only counts outgoing channels, not incoming ones).
4) Dialing rules, Dialing Wizard and prefix I left blank. (Remembering to keep it simple at the beginning will go a long way). If you want to add or strip a prefix you can change the dialing rules later. (Note: If you plan to send out calls with the *67 privacy code prefix, after you get the rest of this working you can go to the page How to set up per-use Caller ID blocking (*67), and particularly take note of the section at the bottom of the page, "Additional Instructions if you are using a SPA-3000/SPA-3102 device...")
5) Trunk name: Call this 1-pstn (again, simple). The reason for starting this trunk name with the digit "1" is an attempt to make it the first sip trunk listed in /etc/sip_additional.conf, which can help you avoid a strange bug in Asterisk (more on this in the "Additional information" section below). IMPORTANT - Note that the Trunk Name must match the User ID in the "Sipura 3000/3102 Device Settings" section below, otherwise you may have registration problems.
6) Outgoing settings - Peer settings (don't enter the comments - the text following the semicolons):
disallow=all ;Starting with FreePBX 2.4 this must be the first statement in the peer settings
allow=ulaw
canreinvite=no
context=from-trunk ; this is needed here - very important.
dtmfmode=rfc2833 ; you can try inband if you have problems accessing your IVR menus
host=dynamic ; or you may use host= followed by a static IP address, SEE NOTE BELOW
incominglimit=1
nat=never ; if Sipura is not on your local network you may need nat=yes
port=5061 ; we use port 5061 rather than 5060
qualify=yes
secret=XXXXXX ; pick a good password
type=friend
username=1-pstn ; must match the trunk name or registration may fail.
NOTE: The original author of this page had written that the host setting should be host=dynamic and added the comment "IMPORTANT - use this even if you set the Sipura to use a static IP." However I (wiseoldowl) found that when the Sipura has a static IP address on the same local network, you can set the host= to that address (example:host=192.168.0.250) and it works fine EXCEPT that you will get complaints in your Asterisk log in the form "Peer '1-pstn' is trying to register, but not configured as host=dynamic". If you use the recommended host=dynamic (to avoid the log entries, or because the adapter really is on a dynamically assigned IP address), then you probably should use a fairly short registration interval in the SPA-3000/3102 configuration - see the section below on Sipura 3000/3102 PSTN settings.
7) Incoming settings - User settings
From wiseoldowl: It turns out that these are not needed at all as long as you set the type=friend in the Peer Settings. The original author of this page had placed some settings in this section but I do not believe they were actually being used and in fact may have been causing problems. Other Sipura 3000/3102 configuration pages on the net don't include a User context or User settings so I strongly advise leaving these blank.
8) No Register String is used. Click Submit Changes and remember to click the orange bar to update your system.

FreePBX Outbound Route setup:

You now are ready to setup your outbound routing.
1) Name the route whatever you like. I called my route spa3000; again this is to keep it simple.
2) No password for the route; keep it simple
3) I only want calls to my area code and 911 via this route so under dial pattern I have:
911
305NXXXXXX
786NXXXXXX
The point here is to use dial patterns that will allow only those calls that you wish to go out via the Sipura - don't just copy the above verbatim!
4) Trunk sequence: I have it going to the trunk associated with the Sipura (SIP/1-pstn) first. Then, to my Voipjet settings.
5) Submit Changes and remember to click the orange bar for the update.

FreePBX Inbound Route setup:

This is easy to set up, but necessary if you want to receive incoming calls!
1) Give the Inbound Route any name you like, such as 1-pstn or spa3000 - it's totally up to you.
2) For DID number, keep it simple and use the phone number associated with the line connected to the Sipura. The most important thing to remember is that this must EXACTLY match the number you put in "Dial Plan 2" while configuring the Sipura, as shown in the instructions below.
3) Skip down to the bottom of the page and set a destination for incoming calls - this can be a particular extension, your IVR, or any destination you like.
4) Submit Changes and remember to click the orange bar for the update.
Skip the other Inbound Route options for now - once you get it working you can come back and make changes if you like.

Sipura 3000/3102 Device Settings:

Next you need to setup your actual Sipura 3000/3102 PSTN settings.
The person who originally started this page said, "Ok here is where I was playing for 3 days to get this part working. It's strange that when I just removed everything and kept it very simple and logical it started to work just fine." So if possible, start with a Sipura 3000 or Linksys 3102 set to the factory default configuration and go from there, because other than the changes specifically mentioned below you'll probably want the default settings.
To begin the setup, login to the device, click on admin (if prompted, enter "admin" as the username and the password, if you have set one up), and then click on advanced. Some of the following settings may not be visible if you are only logged in as a user, or have not clicked on the advanced link.
Check the RTP Packet Size!!!
VERY IMPORTANT: Before you do anything else, go to the SIP tab. Look under RTP Parameters and check the RTP Packet Size. Linksys has set this to 0.030 by default, which is not correct for use on ulaw (G711u codec) connections. Change it to 0.020 instead (or 0.02 on older Sipura devices). If you don't do this, you may experience strange problems with "choppiness" or random clicks on some calls but not others, and you may also experience problems when playing Asterisk sound files. By the way, this applies to all Linksys/Sipura adapters, not just the SPA-3000/3102.
Next go to the PSTN Line tab - I am only putting what needs to change.
1) Sip settings: Just make sure the SIP Port is set to port 5061 (I did not need to change mine).
2) Proxy and Registration:
Proxy: The numeric IP address of your Asterisk box if both the Sipura and the Asterisk box are on the same local network, or the address of your Asterisk server if it is elsewhere on the Internet.
Make Call Without Reg: Yes
Ans Call Without Reg: Yes
Register Expires: 300 (if Asterisk box is on same local network and you used host=dynamic in the FreePBX Trunk settings), or see discussion in note below
Notes on Proxy and Registration section: Some people have reported that they had to set Make Call Without Reg and Ans Call Without Reg to Yes before things would work - it apparently doesn't hurt anything to change those two settings, and it may save you some grief. Also, if you used host=dynamic in the FreePBX Trunk settings (as discussed above), then you will probably want to make the Register Expires: setting something fairly low, especially if the SPA-3000/3102 is on the same local network as the Asterisk box - for example, Register Expires: 300 would make the unit re-register at five minute intervals, while a setting of 900 would probably be a good choice if the device and the Asterisk Server are not on the same local network. The reason for the shortened timeout is that when you use host=dynamic in the FreePBX Trunk settings, if registration is lost for any reason (such as a server reboot) then the SPA-3000/3102 will be inaccessible until the next time it re-registers. This has led some people to conclude that host=dynamic doesn't work, when in fact it does but is just waiting for the adapter to re-register.
3) Subscriber Information:
Display name: Put something here that will identify this line - this is only displayed on your phones if you get a call with no Caller ID information (or you don't subscribe to Caller ID). Keep it at 15 characters or shorter. You could use something like LOCAL PSTN CALL.
User ID: 1-pstn ; very important - this must exactly match the FreePBX Trunk name and username in the trunk configuration!
Password: XXXXXX (same as you used in FreePBX Trunk settings).
4) Audio Configuration (if you don't see all these settings, you forgot to click on "advanced"):
DTMF Process INFO: Yes
DTMF Process AVT: Yes
DTMF Tx Method: Auto
Note: The DTMF Tx Method is the one you especially need to check if your IVR is not receiving DTMF from your callers reliably. Also, in this section you may want to check to make sure that the Preferred Codec is set to the default G711u(assuming you placed "allow=ulaw" in the FreePBX Trunk configuration as shown above).
5) Dial Plans:
Under Dial Plans it's important not to change the default (xx.) on any except Dial Plan 2. I put it very simple to go to my inbound so FreePBX takes care of my calls:
(S0<:1234567890>)
Replace 1234567890 with the telephone number of the PSTN line coming into the device. Note that this must exactly match the DID number in your FreePBX Inbound Route setting for this device. If the number here and in the Inbound Route don't match exactly, you won't receive incoming calls.
6) VoIP-To-PSTN Gateway Setup:
This is another important settings section.
VoIP-To-PSTN Gateway Enable: yes
VoIP Caller Auth Method: None ; use "None" to start, you can change later for added security (see below).
VoIP PIN Max Retry: 3 ; I did not change this.
One Stage Dialing: Yes ; very important
Line 1 VoIP Caller DP: none
VoIP Caller Default DP: none
Line 1 Fallback DP: none
7) VoIP Users and Passwords (HTTP Authentication):
During the initial setup, leave all of these blank (the drop-downs can be left set to 1). After you get everything working you can revisit this section to add security, as will be discussued later.
8) PSTN-To-VoIP Gateway Setup:
Here is another section that made me pull my hair out.
PSTN-To-VoIP Gateway Enable: Yes
PSTN Caller Auth Method: none
PSTN Ring Thru Line 1: no ; I use Asterisk for my routing.
PSTN Pin Max Retry: 3
PSTN CID for VoIP CID: Yes if you subscribe to CallerID service on your PSTN line, otherwise No
PSTN CID Number Prefix: (Leave Blank)
PSTN Caller Default DP: 2 ; important - here is where it sends the calls to.
Off Hook While Calling VoIP: No
Line 1 Signal Hook Flash To PSTN: Disabled
PSTN CID Name Prefix: (Leave Blank)
Leave everything else in this section blank. We are almost finished now.
9) FXO Timer Values (sec):
Just change 2 items here.
Voip Answer Delay: 0 (The original recommendation was 1, but this can cause a spurious half ring on outgoing calls, before actual ringing from the called line commences, so 0 is now the recommended value).
PSTN Answer Delay: If you do not subscribe to CallerID service on your PSTN line, this can be set to 0. Most users will want to set it to at least 3 so that the incoming CallerID data is captured. In rare situations you may need a slightly longer delay (5 should be more than enough).
10) PSTN Disconnect Detection:
Skip the PSTN Disconnect Detection section unless you know what type of PSTN disconnect signal(s) are used on your PSTN line and wish to change the settings so that those signals (and only those signals) are detected. Generally you should only tweak this section if the Sipura isn't properly detecting disconnected calls on the PSTN side. The "Disconnect Tone" is by default set to detect the "fast busy" signal usually sent after a call has ended in North America - you may wish to tweak this setting if the switch serving your PSTN line sends a different tone after disconnect.
11) International Control
Check the settings here - each country uses different values for PSTN lines. If you live in Australia, Canada, the United States or most other countries with modern telephone systems you probably won't have to change anything except perhaps the gain levels, so we'll only deal with them for now. The default values for both the SPA To PSTN Gain and the PSTN To SPA Gain are 0 (zero), and that's where you should leave them when you're first setting up the SPA-3000/3102. But just so you know, here's some information on those settings:
If the SPA to PSTN gain is set too low, the parties on the PSTN side of the connection will probably complain about your volume being too low, or will ask you to speak up or talk closer to the phone. If it is set too high, however, you are more likely to hear echo, and outgoing calls may fail because the level of DTMF tones sent by the SPA-3000/3102 will be too "hot" to register properly at the PSTN switching equipment.
If the PSTN To SPA Gain is set too low, you'll hear low volume levels on PSTN calls. If it's set too high, the people on the PSTN side of the connection will be more likely to hear echo (they may hear their own voices echoed back from your end). Also, any echo that has been reflected back to you will be heard at a higher volume level, and will therefore be more objectionable.
While the default levels are usually adequate, we found that boosting both values up to 3 produced a more "natural" sounding volume level in both directions. However, this is very much dependent on the characteristics of the PSTN line - if you're on a very short loop, values of 0 may be adequate for both settings, if on a very long loop you may need to go even higher than 3. The valid range is -15 dB to 12 dB in 1 dB increments (but just enter a numeric value, do not enter "dB" in the text field). If you have actual test equipment available you can fine-tune the volume settings for best results.
We'll talk a bit more about settings in this section under "Troubleshooting", below. For now, that's it. Submit and it should register and you should be able to use the PSTN port on the Sipura. Note that if you used host=dynamic in the FreePBX Trunk setting, the adapter may take some time to register, and it will not be accessible until it does (as discussed above). If you're in a hurry, you can power-cycle the adapter to force it to re-register (but make sure that you have first submitted your changes, and that the adapter's web page has refreshed!).

Troubleshooting

If you are connecting VoIP adapters back-to-back (SPA-3000 PSTN port to a line port on another device, perhaps because you are wanting to access a line from a commercial VoIP provider that insists you use a VoIP device that they provide) and if their device ever sends caller ID names with a single quotation mark, those calls will either simply ring and never answer, or will be answered but then disconnected after a few seconds, due to a bug in the SPA-3000 firmware. This problem usually presents itself if the other device is a Cisco ATA-186. You can either have your provider send you a newer device (they may charge you for this) OR you can disable CallerID passthru (which will throw away the incoming Caller ID). To do the latter, set PSTN CID for VoIP CID to NO, and you may as well set PSTN Answer Delay to 0 since there will be no need to wait for CallerID. A third option involves patching Asterisk itself but that is beyond the scope of this article (however, see the added comment at the bottom of this article).
If you have problems getting the SPA-3000 to register with your Asterisk box, try setting the Sipura up on a static IP address instead of letting your router assign it one via DHCP. Go to the System tab, and the Internet Connection Type settings:
DHCP: No
Static IP: (pick an address on your local network that will not conflict with your router's DHCP assignments, such as192.168.0.250)
NetMask: (usually 255.255.255.0 unless you have a large network)
Gateway: (usually either 192.168.0.1 or 192.168.1.1, unless your local net is numbered differently - for home users, this is generally the same address you use to get to your router's configuration page)
Skip down to Primary DNS: (you will probably want to put the same address as you used in Gateway here - usually both functions are handled by your router. Or, you can use a third-party DNS service such as OpenDNS).
While you are here you may want to set a Primary NTP Server so that your Sipura will know the time. Usually you can point this to any NTP server on your local network (such as your Asterisk box) and it will be close enough, but you could also use a public "pool" NTP server. But if you do this you will also want to set a time zone, and that setting is found under the "Regional" tab at the bottom of the page (if you have the latest firmware you can also include a Daylight Savings Time rule). It is NOT necessary to set up a time server to get this unit to operate as a PSTN gateway; I only mention this so that people who do want to set the time will know where the settings are.
There are two other settings under the PSTN tab, in the International Control section that you should be aware of if you are having problems. If you can't seem to get calls to go out (and in particular, if Asterisk reports that there are no circuits available), try setting the Line-In-Use Voltage to a lower value, such as 15. Some telephone companies use "pair gain" or "subscriber carrier" equipment to put multiple subscribers on the same loop. If you have the great misfortune to receive telephone service through such equipment, your on-hook line voltage may be less than 30 volts, and if that is true the Sipura will think the line is always in use unless the Line-In-Use Voltage setting is lowered. In the U.S.A. and Canada, nominal on-hook voltage is about 45 to 48 volts, and in that situation the 30 volt setting is correct. But if you are "served" using pair gain or subscriber carrier equipment (or are unsure of the telephone line voltages used in your locality), you may want to use a voltmeter to measure both PSTN on-hook voltage and off-hook voltage (the latter being the voltage on the line when a phone is taken off-hook), and set the Line-In-Use Voltage setting to a value about halfway between those two measured voltages. That's also a report that a particular fixed cellular terminal designed for making calls over GSM only produces 14 volts on-hook voltage - one user had to set the SPA-3102 Line-In-Use Voltage to 10 to get it to work properly with that device.
Also, the FXO Port Impedance default setting is 600 ohms is correct for many places in the world. Some places use 900 ohms. You really should try to find out the standard impedance setting for the PSTN line you are connected to, since an improper setting can cause some frequencies to be higher or lower in volume than others. Mismatched impedance can also be a source of echo and DTMF recognition problems. However, determining the best/most correct setting can be something of a black art, as this Cisco document illustrates. That said, if you don't know the correct impedance, the 600 ohm setting will generally work well, especially on loops of about one mile/1.5 km or less. If you have noticeable echo, try also the 900 ohm setting to see if that reduces or eliminates the echo.

Adding security

Once you have it working satisfactorily using the above instructions (test it with both incoming and outgoing calls), you can try adding additional security - most users seem to have had success doing this, but occasionally someone has problems, however it's easy to reverse the procedure if you do have any issues. Go to the adapter's PSTN Line tab and make the following changes:
In the VoIP-To-PSTN Gateway Setup section, change VoIP Caller Auth Method to HTTP Digest.
In the VoIP Users and Passwords (HTTP Authentication) section, change the following:
VoIP User 1 Auth ID: 1-pstn
VoIP User 1 DP: none
VoIP User 1 Password: XXXXXX (same as you used in trunk settings).
After making the above changes test to make sure that both incoming and outgoing calls still work as expected. That's all the security changes under the PSTN tab.
However, the Sipura's web pages are still wide open (unless you have already set up passwords) and if anyone on your local network goes there (or someone manages to hack their way in) they can go to the Sipura's web pages, and see and change all your settings. So you will probably want to password protect the settings pages. Note that there are separate user and admin passwords - you can set these in the System Configuration section of the page accessed through the System tab. BE CAREFUL - take your time and think about what you are doing here, because if (for example) you make a typo in a password and don't catch it, you could lock yourself out of your Sipura!

Additional information

If your adapter is at a remote location, or for some other reason you would like incoming calls on the PSTN line to ring through directly to "line 1" (the phone port) WITHOUT first passing through Asterisk (but still having the ability to send the call to voicemail if no one answers), set PSTN Ring Thru Line 1 to Yes, set PSTN Answer delay to whatever number of seconds delay you wish before the call goes to voicemail, and then set PSTN Caller Default DP to 1 and set Dial Plan 1 as (<:*extensionnumber@asterisk_ip:port>) - the * in front of the extension number tells FreePBX to send the call directly to that extension's voicemail without building a inbound route. So, incoming calls from the PSTN should ring directly into any telephones connected to the phone port, but if not answered in the specified time they will still get transferred to the extensions voicemail (thanks to "cyberglobe" for suggesting this in the IRC channel).
The reason we used a trunk name starting with the digit "1" is an attempt to make it the first sip trunk listed in /etc/sip_additional.conf (which seems to have trunk names sorted alphanumerically). This can help some users avoid a strange bug in Asterisk. In some versions of Asterisk, if there are one or more SIP trunks configured and Internet connectivity is lost, it becomes impossible to place any SIP call, including calls between SIP extensions that are on the same local network as the Asterisk server (and which therefore should be unaffected by the Internet outage - sadly, that is not the case)! Note that calls using protocols other than SIP are unaffected. There have been some reports that if the first SIP trunk (listed in /etc/sip_additional.conf) is accessible, Asterisk will be happy and continute to complete calls on the local network. Therefore, we suggested using 1-pstn so that the adapter would be the first SIP trunk and (assuming it's on the same local network as the Asterisk server) always accessible, even during an Internet service outage, thereby (hopefully) avoiding the issues when the Internet connection goes down. If you have more than one adapter, or don't need this attempted protection against Internet service outages, then you can change ALL instances of 1-pstn to some other string, but just make sure that ALL instances mentioned above are changed to the EXACT SAME string (otherwise the adapter will not be able to register with Asterisk).

No hay comentarios:

Publicar un comentario