10  Interfacing Asterisk to PSTN

If you are using TRIXBOX v1.0, please refer to section 10.3 before proceeding as there is a little problem of TRIXBIX not recognising ZAP device.  This issue has been addressed in later versions of TRIXBOX.

10.1  Digium Wildcard X100P FXO PCI Card

This card allows you to connect a POTS (plain Old Telephone System) line to your Asterisk box (See Notes for Patch information).

If this card is added after Asterisk has been configured, it may be necessary to configure it by using the zaptel card auto-config utility so the correct zaptel driver will be set up.  To do that, enter the following from the command line.

rebuild_zaptel

Restart Asterisk

Shutdown –r now

After restart run the following;

genzaptelconf

Restart again.

Shutdown –r now

Next go into the freePBX web interface to create a trunk and you will notice that there is already a trunk called ZAP/g0.  You need to edit this.


1.  Enter the phone number for you pots line in the Caller ID field
2.  Enter 1 for Maximum channels
3.  Set a dial rule you want for this trunk
4.  Select an outbound dial prefix to select this trunk when dialing
5.  Set the Zap Identifier to 1 (the default is g0)


Once the card is configured, you must add a route for Incoming Calls or asterisk will not answer this line.

Click on Incoming Calls in freePBX and set up an incoming route. To make outbound calls you will need to set an outbound route as well.

If you have this card installed, you may need to edit the following files (usually you don’t have to); zapata.conf, Zapata-auto.conf, zaptel.conf and modprobe.conf. The last 2 files live in the /etc directory – use a text editor (I use nano) to edit them as you cannot edit them through Config Edit.

 

10.1.1  zapata.conf

Under [channels] add the following lines:

[channels]

busydetect=yes
busycount=6

The above is to ensure that the line is hung up if there is no answer or busy after 6 busy tones.

For my installation to function correctly, I have also changed the following setting to obtain a good compromise on volume/echoing:

rxgain=4   (you may have to experiment a little with this setting)
txgain=2  
(you may have to experiment a little with this setting)

 

10.1.2  zapata-auto.conf

Ensure the following exist in zapata_auto.conf.  It is located at the end of the file.

context=from-pstn
group=0
channel => 1

Leave the rest of the file as it is.

 

10.1.3  zaptel.conf

Change the loadzone and defaultzone to “au”

# Global data
loadzone = au
defaultzone = au

 

10.2  Digium TDM400P FXO/FXS Card

Like the Digium Wildcard X100P, this card allows you to connect a POTS (plain Old Telephone System) line to your TRIXBOX box. Unlike the X100P, this card has 4 module ports that can be loaded with FXS or FXO modules. Channel 1 is the top RJ-45 on the back of the TDM400P card.

If this card is installed after Asterisk has been loaded, you will need to configure it just like the X100P by using the following command on the command line:

rebuild_zaptel

Restart Asterisk

Shutdown –r now

After restart run the following;

genzaptelconf

Restart again.

Shutdown –r now

 

10.2.1  zapata-auto.conf

Next, using config edit, look in the zapata-auto.conf file and you will see a list of all your channels in your TDM400P. Set up the trunks as trunks and the extensions as extensions in freePBX.

When you open the zapata-auto.conf file, it will look something like the illustration below  (see the red highlight)

   
; Autogenerated by /usr/local/sbin/genzaptelconf -- do not hand edit
; Zaptel Channels Configurations (zapata.conf)
; This is not intended to be a complete zapata.conf. Rather, it is intended
; to be #include-d by /etc/zapata.conf that will include the global settings
;  
callerid=asreceived

; Span 1: WCTDM/0 "Wildcard TDM400P REV E/F Board 1"
signalling=fxs_ks
; Note: this is a trunk. Create a ZAP trunk in AMP for Channel 1
context=from-pstn
group=0
channel => 1
; channel 2, WCTDM, inactive
; channel 3, WCTDM, inactive.
; channel 4, WCTDM, inactive.

 

If in the illustration it shows channel 1 is your Zap extension then add a zap extension for channel 1 in freePBX and if it shows your Zap trunk is channel 2 you should create a zap trunk for channel 2 in freePBX.

Once this is done, reboot your PC and when Asterisk starts, use freePBX to add a route for incoming calls or asterisk will not answer your trunk.  Similarly, to make outbound calls you will need an outbound route. Set them up as per setting up routes in the earlier chapters of this document.

If you have this card installed, you may need to edit the following files: zapata.conf and zaptel.conf as per the X100P card in the previous section.

 

10.2.2  modprobe.conf

You may need to edit the modprobe.conf  to add the necessary option for usage in Australia (in later versions of Trixbox you don’t need to do this):

If exist, locate the line “install wctdm /sbin/ztcfg-- --ignore-install wctdm && /sbin/ztcfg” and edit it to reflect the following:

install wctdm opermode=AUSTRALIA fxshonormode=1 boostringer=1 /sbin/ztcfg-- --ignore-install wctdm && /sbin/ztcfg

Note: as of Zaptel Drivers 1.2.4, by selecting opermode=AUSTRALIA the zaptel drivers automatically add the "boostringer=1 , fxshonormode=1".

Also see Appendix E.2 (Users Suggestions)

10.3  Caller ID (CID) using ZAP device

The illusive CID has been a talking point and hair pulling exercise for many users.  It has always been the case of “I have my ZAP trunk working fine but it is not sending the CID to my Softphone or SIP Phone”.

The simple answers to this:

Naturally if you are using an X100P clone for your FXO, the following exercise will probably be futile as the X100P, even at the best of time will probably not handle the CID properly.  However if you are using a more substantial device such as the TDM400, then this may possibly help you towards getting the CID passed correctly.

(caveat: This solution may not necessarily work for your installation but you have nothing to loose if you try)

A participant (Shane B) in the Whirlpool Forum provided the solution below that will correctly pass the CID to Asterisk and your telephones:

You may need to set the following switches in your zapata.conf and zapata-auto.conf.

10.3.1  zapata.conf

usecallingpres=yes
callwaitingcallerid=yes
threewaycalling=yes
usecallerid=yes
hidecallerid=no


10.3.2  zapata-auto.conf

The following switches may need to be added to the existing ones.

useincommingcalleridonzaptransfer=yes
adsi=yes
sendcalleridafter=2  ;you may to add this switch

After the above are done, restart trixbox:

Amportal restart

If you are lucky, it should work.  If not, you haven’t really lost anything.

 

10.4  Rebuild  Zaptel Driver

IMPORTANT: If you are installing Trixbox 1.2.x or upgrading from 1.1.x to 1.2.2, this section does not apply to you.

If you are using TRIXBOX v1.0 you will need to rebuild the Zaptel Driver as ZAP device does not work the way it should with TRIXBOX v1.0.  The /usr/src/zaptel directory is visibly missing (at the time of this update, it is version 1.2.7.  By the time you read this, the version may have changed.  It is a good idea for you to check what the latest version is).

---------------------------------------------------------------------------------------------------

Hint: To find out what zaptel modules you have, issue the following command:

rpm -qa | grep zaptel-modules
----------------------------------------------------------------------------------------------------

To do this, you will need to download the zaptel-1.2.7.tar.gz file from Digium and install it as described below:

You will have to log on to the TRIXBOX system.  You can either do this at the System box itself or through your favourite SSH client.  I use Putty.

At the command prompt, do the following:

amportal stop
service zaptel stop 
(it helps to stop the zaptel service as well)
cd /usr/src/
wget http://ftp.digium.com/pub/zaptel/releases/zaptel-1.2.7.tar.gz

once the file is downloaded, unpack the file;

tar -zxvf zaptel-1.2.7.tar.gz

After the files have been unpacked, move them to the /usr/src/zaptel directory:

mv zaptel-1.2.7 zaptel

Leave it there for now, as we need to fix an inherent bug in the Centos release of Red Hat.

The following is the fix (source Nerd Vittles http://nerdvittles.com/index.php?p=123 )

Log into your new server as root and issue the following commands:

(depending on the version you have.  At the time of writing it is 2.6.9-34.0.1.EL-1686).

cd /usr/src/kernels/2.6.9-34.0.1.EL-i686/­ include/linux
mv spinlock.h spinlock.h.old
wget  http://nerdvittles.com/trixbox/spinlock.h

Alternatively, after you change to the directory, instead of getting the file from NerdVittles, you may edit the spinlock.h file manually.  This is what you have to do:

Edit the spinlock.h file.  I use nano to do it using the following command (depending on the version you have).  At the time of writing it is 2.6.9-34.0.1.EL-1686.

nano /usr/src/kernels/2.6.9-34.0.1.EL-i686/include/linux/spinlock.h

Locate the line entry below, at line 407.

#define DEFINE_RWLOCK(x) rw_lock_t x = RW_LOCK_UNLOCKED

You need to change this entry to reflect the line below:

#define DEFINE_RWLOCK(x) rwlock_t x = RW_LOCK_UNLOCKED

Once done, save the file.

Now do the following:

cd /usr/src/zaptel
make clean
make install

Now it might be a good idea to create the fxotune.conf file that is missing.  Do the following:

touch /etc/fxotune.conf
/usr/sbin/fxotune -s

Once done, reboot using the following command:

reboot

When the reboot completes, you can start rebuilding the support for your ZAP devices or for that matter, ztdummy if you don’t have any ZAP devices.

Log in as root and type the following command:

(Every time there is a kernel update with yum (which is the case with Asterisk and CentOS), ZAP device support needs to be rebuilt using the new kernel and you will need to follow the same process below)

rebuild_zaptel

Then reboot your system:

reboot

Now log in as root again and enter the following command:

amportal stop
genzaptelconf

Reboot once again:

reboot

..and you're done.

(See also user Users’ Suggestions)

Note: While the procedure above seems to have fixed most TRIXBOX users’ woes, it didn’t with mine … for me, it’s back to reinstalling from scratch.

.. and after reinstall, still it would not detect my card.  It seems that there is a detection issue with the procedures, so, this time armed with a bigger hammer I proceeded to use the brute force method.

 

10.4.1 If All Else Failed

If all else fail, do the following at the command prompt,

cd /etc/sysconfig
nano zaptel

Locate the line entry corresponding to your card e.g:

If you are using the X100P, you will be looking for this:

#MODULES="$MODULES wcfxo"       # X100P - Single port FXO interface

Since I use TDM400P, in my case I need to locate the following line.

#MODULES="$MODULES wctdm"       # TDM400P - Modular FXS/FXO interface (1-4 ports)

Remove the # so the line will read like this;

MODULES="$MODULES wctdm"       # TDM400P - Modular FXS/FXO interface (1-4 ports)

Save the file and restart.

When the system restarts, log in and do the following at the command prompt:

amportal stop
genzaptelconf

Once completed, restart again;

Shutdown –r now 

Your ZAP device will now be recognised…. Phewww, that was a task and a half.

 

10.4.2  How to overcome the Zaptel 1.2.5 dependency

Did you get this error message when updating your Zaptel driver?

Error: Missing Dependency: zaptel = 1.2.5 is needed by package zaptel-modules-2.6.9-34.EL

Yes, it is a pain in the proverbial.

If you are one of many who have been bugged by this, the easiest way around is to install 1.2.5 and be done with it.

Log in to TRIXBOX as root.

cd /usr/src
wget http://ftp.digium.com/pub/zaptel/releases/zaptel-1.2.5.tar.gz
tar -zxvf zaptel-1.2.5.tar.gz
mv zaptel-1.2.5 zaptel
cd /usr/src/zaptel
make clean
make install
rebuild_zaptel
modprobe wcfxo

genzaptelconf
reboot

after you have completed the above procedure, you will have the correct zaptel that trixbox update insists on having.

 

10.5  Sipura SPA3000 as a PSTN Interface

To those new to the SPA3000, there is a simplified installation and configuration instruction by JMG Technology.  While it is directed mainly at standalone ATA users, it gives a good insight of the Sipura SPA3000’s capabilities.

I have come across a few people in the various forums wanting to use their Sipura SPA-3000s as FXO front-end to their TRIXBOX boxes. To help them in their endeavours, I've put the following together, as no one single source of information that I've found so far has a config that would actually work for me.

 

10.5.1  Log in to SPA3000

Login to your SPA-3000 as admin/advanced.

Before you change anything, I'd suggest taking a snapshot (i.e. just save the .html page) of your current SPA-3000 configuration, just in case you ever need to refer back to your own customisations.

If you're not already running the latest SPA-3000 firmware, then upgrade it to the latest version (at the time of writing, it's 3.1.5a). Take another snapshot for good measure. Nothing should have changed in your settings, except that you have a few extra options that you didn't have before.

Now reset SPA-3000 back to factory defaults, because I'm only going to list the minimum changes required to keep things simple. Take another snapshot now too, in case you ever want to know what the defaults were.

 

 10.5.2  Change the settings

System tab
DHCP: No
Static IP: something on your local subnet e.g.; 192.168.1.200
NetMask: 255.255.255.0
Gateway: your router's IP address e.g.; 192.168.1.254
Primary DNS: your ISP's primary DNS address e.g.; 203.12.160.35
Secondary DNS: your ISP's secondary DNS address e.g.; 203.12.160.36

Regional tab
Dial Tone: 400@-19,425@-19;10(*/0/1+2)
Busy Tone: 425@-10;10(.4/.4/1)
Reorder Tone: 425@-10;10(.2/.2/1)
Ring Back Tone: 400@-19,425@-19,450@-19;*(.4/.2/1+2+3,.4/.2/1+2+3,0/2/0)
Ring 1 Cadence: 60(1.5/3.4)
Ring 3 Cadence: 60(1.5/3.4,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2,.4/.2,.4/2)
CWT8 Cadence: 30(.2/.2,.2/4.4)
Hook Flash Timer Min: .07
Hook Flash Timer Max: .13
Delete all the Vertical Service Activation Codes.
FXS Port Impedance: 220+820||120nF

Line 1 tab
Proxy: IP address of your Asterisk box e.g.; 192.168.1.234
Register Expires: 60
Display Name: Whatever
User ID: Asterisk extension number e.g.; 200
Password: password for that extension

Silence Threshold: medium
DTMF Tx Method: INFO
Hook Flash Tx Method: INFO
Dial Plan: (*xx|000|0011xxxxxxxxxxx.|0[23478]xxxxxxxx|09xxxxxx|1100 |122[135]|1222xxxxxxx|12510[12]|12554|1[38]00xxxxxx|13[1-9]xxx |1747xxxxxxx|2xx|393xxxxxx|3xxxx. |[4689]xxxxxxx|7777|899060xxxxx.) for example

(*xx.|x.) will work, but I like to do a bit of sanity checking, etc.

PSTN Line tab (method 1)
Proxy: IP address of your Asterisk box e.g.; 192.168.1.234
Register:
no
Make Call Without Reg:
yes
Ans Call Without Reg: yes
Display Name: No name
User ID:
PSTN
Password: password

Silence Supp Enable: no
Echo Canc Enable: no
Echo Canc Adapt Enable: no
Echo Supp Enable: no

FAX CED Detect Enable: yes
FAX CNG Detect Enable: yes
FAX Passthru Codec: G711u

FAX Codec Symmetric: no
FAX Passthru Method: None

DTMF Tx Method:
INFO
FAX Process NSE: no

Dial Plan 1:
(S0<:0298765432>) for example  - it could be your phone number
VoIP Caller Default DP:
none
PSTN Ring Thru Line 1:
no
PSTN CID For VoIP CID:
yes
PSTN Answer Delay:
2
PSTN Ring Thru Delay:
3
PSTN Ring Timeout:
4
PSTN Hook Flash Len: .
1
Disconnect Tone:
425@-30,425@-30;1(.375/.375/1+2)
FXO Port Impedance:
220+820||120nF
On-Hook Speed:
26ms (Australia)

Using method 1 above, it will be necessary for you to create an inbound route using the 0298765432 (or whatever you have defined) as your inbound route DID number.  As this incoming call is identified by the (S0<:0298765432>) in the dial plan 1 setting of your SPA3000, this can be directed to any extension by the inbound route.

 
Note
:
Disconnect Tone setting of
425@-30,425@-30;1(.375/.375/1+2 seems to work well for Telstra, while 425@-30,425@-30;1(.390/.390/1+2) works better with Optus.
 

PSTN Line tab (method 2)
Proxy: IP address of your Asterisk box e.g.; 192.168.1.234
Register: no
Make Call Without Reg: yes
Ans Call Without Reg: yes
Display Name: No name
User ID: PSTN
Password: leave blank

Silence Supp Enable: no
Echo Canc Enable: no
Echo Canc Adapt Enable: no
Echo Supp Enable: no

FAX CED Detect Enable: yes
FAX CNG Detect Enable: yes
FAX Passthru Codec: G711u

FAX Codec Symmetric: no
FAX Passthru Method: None

DTMF Tx Method: INFO
FAX Process NSE: no

Dial Plan 1: (S0<:s@YourAsteriskIP>) e.g. (S0<:s@192.168.0.101:5060>)or try w/o the port designation
VoIP Caller Default DP: none
PSTN Ring Thru Line 1: no
PSTN CID For VoIP CID: yes
PSTN Answer Delay: 2
PSTN Ring Thru Delay: 3
PSTN Ring Timeout: 4
PSTN Hook Flash Len: .1
Disconnect Tone: 425@-30,425@-30;1(.375/.375/1+2)
FXO Port Impedance: 220+820||120nF
On-Hook Speed: 26ms (Australia)

Using method 2 above, you are not required to create an inbound route as the call is directed directly to asterisk and will be handled by the any DID / any CID catch all inbound route.  Through this route, you can direct it to your IVR or any extension you like.  This method is simpler if you only have one SPA3000, however if you are using multiple SPA3000, method 1 is the recommended method.

 
Note
:
Disconnect Tone setting of
425@-30,425@-30;1(.375/.375/1+2 seems to work well for Telstra, while 425@-30,425@-30;1(.390/.390/1+2) works better with Optus.
 

User 1 tab
Default Ring: 3
Default CWT: 8

 

10.5.3  Add SIP Trunk

Then in freePBX, add a SIP trunk.

General Settings:
Outbound Caller ID: <0298765432> (for example)

Maximum Channels: 1

Dial Rules:      0+NXXXXXXXX  (for example)
  
                         0011+ZXXXXXXXXXX.

Trunk Name: telstra  (for example)

Peer Details:
canreinvite=no
context=from-pstn
host=the IP address of your SPA-3000 (for example; 192.168.1.200)
insecure=very
nat=no
port=5061  (for example)
qualify=yes
type=peer
username=PSTN

User Context: telstra-incoming (for example)

User Details:
canreinvite=no
context=from-pstn
host=the IP address of your SPA-3000 (for example; 192.168.1.200)
insecure=very
nat=no
port=5061 for example
type=user
username=PSTN

Leave "Register String" empty

  

10.5.4  SPA3000 as an outbound PSTN Trunk

To make PSTN calls using the SPA3000 you simply select the SPA3000 trunk which you have named Telstra (see trunk name that you have given to this trunk above) as the first choice in your outbound route.

Also see Eliminating echo problems in Appendix E.3 in Sipura SPA-3000