Connecting an ISDN PABX to Asterisk
Jan Stocker <Jan.Stocker@t-online.de>
Abstract
This article contains all my notices on how to install Asterisk and attach a PABX to it. You need a FreeBSD 5.x server, an active AVM card and maybe a PABX to connect to.
Introduction
While porting some facsimile software to FreeBSD, I received a request about a CAPI channel implementation for Asterisk. Everything I knew was Asterisk is a telephony service for VoIP, but last time I had a look at VoIP it was a mess. Meanwhile it grow to a good replacement or additional media at least.
Mr. Junghanns created chan_capi for Asterisk on Linux. I ported this application to FreeBSD and made some experience with two providers (IAXTEL and FWD). I try to explain my configuration files in this paper.
While porting and searching for bugs in the new port, I found weird behaviors in Linux which makes me glad having beastie inside (ever successfully tried to read from the writing side on a pipe or listen on a non existing CAPI controller?).
Installation
First you need to install and setup a FreeBSD system with C4B and an active AVM ISDN card, a guide can be found at http://www.shellbang.org/freebsd/introducingc4b.html.
Next step is to install Asterisk itself. Please make sure your ports tree is up-to-date and the Asterisk port is version 1.0.5 at least.
cd /usr/ports/net/asterisk && make install clean
installs Asterisk on your system. All configuration files for Asterisk will be installed in
/usr/local/etc/asterisk
and some of them need to be edited, I will explain this later in this article.
The next step you need to do is downloading the chan_capi port. Furthermore chan_capi depends on a Linux compatibility layer for CAPI, you can also find on my site.
Please download
http://www.shellbang.org/files/chan_capi.tar.gz
http://www.shellbang.org/files/liblinuxcapi.tar.gz
extract them to your ports tree
cd /usr/ports && gunzip -c /mydownload/chan_capi.tar.gz | tar xvf - cd /usr/ports && gunzip -c /mydownload/liblinuxcapi.tar.gz | tar xvf -
and install the chan_capi port as usual (liblinuxcapi is marked as dependency and will be installed automatically)
cd /usr/ports/net/chan_capi && make install clean
You need to add WITH_ULAW=yes to the make call if you are not in Europe, so if you are located in Japan or the USA, you have to write
cd /usr/ports/net/chan_capi && make WITH_ULAW=yes install clean
otherwise chan_capi defaults to aLaw.
General configuration
Everything you need is installed and you can configure Asterisk for a first test. Please edit the modules configuration file for Asterisk with your favorite editor
/usr/local/etc/asterisk/modules.conf
and add a line to the section [modules]:
load => chan_capi.so
and to the [global] section:
chan_capi.so=yes
Next you need to create a capi.conf file. Just copy the example file and edit it.
cp /usr/local/etc/asterisk/capi.conf-dist /usr/local/etc/asterisk/capi.conf
You can read a line called msn=50. Just edit it and enter all MSN numbers used on this line for listening / calling and please turn softdtmf off, because all active AVM cards do this by hardware.
msn=68,69,70 softdtmf=0
If you start asterisk by typing
asterisk -f -vvvvvv -dddddd
you will see many debug messages on the screen helping you to find wrong configurations or other errors.
If Asterisk is started successfully, you can now take your phone and dial the configured MSN (of course you need to change your PABX routing plan to link that MSN to your ISDN card). If you dial 68 in my example you will be connected to Asterisk using its 'demo' context and welcomes you to Asterisk.
If everything is working fine, we can define a custom context for our incoming CAPI calls, I name it [capi-in]. You need to edit capi.conf again and change the value for the key 'context'
context=capi-in
Afterward the context [capi-in] must be created in the dialplan. Just open /usr/local/etc/asterisk/extensions.conf and add a section at the end.
[capi-in] exten => 68,1,Answer exten => 68,2,DigitTimeout,10 exten => 68,3,ResponseTimeout,20
This is just answering your call on MSN 68 (remember: use the number you already defined in capi.conf) an sets some timeouts. If your local PABX uses two-digits numbers for internal telephones you can add these two lines to the [capi-in] section
exten => _[1-9]X,1,Dial(CAPI/68:${EXTEN}) exten => _[1-9]X,2,Congestion
This tells Asterisk to use CAPI for dialing all two-digit numbers, 68 in this case is the outgoing line and ${EXTEN} will be extended to the dialed number. You can test this by using one phone calling 68, Asterisk is answering than you can dial any two digit number of your PABX and Asterisk is establishing the call.
Adding VoIP provider: IAXTEL
IAXTEL is powered by Digium, sponsor of Asterisk. Here you can find many people with knowledge about all Asterisk concerning subjects. I already subscribed to this provider but the connection from Germany is not as good as it is useful for me. But anyway this is a must for a Asterisk user.
Go to http://gnophone.com/directory/createAccount.php and create an account. Do not worry if you get a response mail to enable your new account with an URL like this http://x.linux-support.net/directory/. Use the link to enable your account right now.
To make an outcall to IAXTEL you need to tell Asterisk your chosen username and the password. Create two lines under the section [globals].
IAXTELUSERNAME=YourUsername IAXTELPASSWORD=YourPassword
I find it useful to let all VoIP calls start with an *. So dialing *1700xxxxxxx should call any member of the IAXTEL network, add the following line to the [capi-in] section
exten => _*1700XXXXXXX,1,Dial(IAX2/${IAXTELUSERNAME}:${IAXTELPASSWORD}@iaxtel.com/${EXTEN:1}@iaxtel,180,r)
Do not use "exten => _*1700NXXXXXX,.." mentioned on the IAXTEL site, because of existing numbers starting with a 1.
Now you can call a friend on IAXTEL by using your phone, call 68 (or whatever) to reach Asterisk and then dial *1700number. To handle incoming calls on your own IAXTEL number, you need to register to the service by adding a register statement to the [general] section in /usr/local/etc/asterisk/iax.conf (please change the username and the password).
register =>YourUsername:YourPassword@iaxtel.com
Additionally we need to define a section iaxtel in iax.conf.
[iaxtel] type=user auth=rsa inkeys=iaxtel context=iaxtel-in
All incoming IAXTEL calls are now handled by the context [iaxtel-in]. This context must edited in extensions.conf, like all other ones. Let us assume your office phone on the PABX, which should be called for an incoming call, has the internal number 11. Every call from IAXTEL must be first answered and forwarded to CAPI.
[iaxtel-in] exten => s,1,Answer exten => s,2,Dial(CAPI/68:11) exten => s,3,Hangup
You can use here a define for your office phone, too. Add TELOFFICE=CAPI/68:11 to your [globals] section and use exten => s,2,Dial(${TELOFFICE}) instead.
Adding VoIP provider: FWD
FWD is another fine and free provider for VoIP, it is normally based on SIP, but that's something difficult to setup with Asterisk behind NAT. They also provide a IAX2 protocol interface, I will use in this example. Create an account similar to IAXTEL on http://account.freeworlddialup.com/index_new.php?section_id=94 and enter your personal data. After doing this, you need to enable the IAX interface by visiting http://account.freeworlddialup.com/index_new.php?section_id=112: enter your account data, check the active box and press Submit.
Configuration now is quite similar to IAXTEL.
Define number and password in [globals] section of extensions.conf
FWDNUMBER=YourFWDNumber FWDPASSWORD=YourFWDPassword
Add dialplan information to section [capi-in] in extensions.conf
exten => _*393.,1,SetCIDNum(${FWDNUMBER}) exten => _*393.,2,Dial(IAX2/${FWDNUMBER}:${FWDPASSWORD}@iax2.fwdnet.net/${EXTEN:4},180,r) exten => _*393.,3,Hangup
Register at provider by adding a register entry to section [general] of iax.conf.
register => YourFWDNumber:YourFWDPassword@iax2.fwdnet.net
add a [iaxfwd] section to iax.conf
[iaxfwd] type=user auth=rsa inkeys=freeworlddialup disallow=all allow=ulaw context=fwd-in
and finally add the incoming extensions to extensions.conf
[fwd-in] exten => ${FWDNUMBER},1,Answer exten => ${FWDNUMBER},2,Dial(${TELOFFICE}) exten => ${FWDNUMBER},3,Hangup
Conclusion
Asterisk is a complex telephony service with all capabilities of a PABX. With chan_capi you can extend your existing PABX with VoIP services easily and switch over to SIP phones in a soft way.
Links
- Latest version of this article - http://www.shellbang.org
- http://www.nord-com.net/thomas.wintergerst/
- Asterisk - http://www.asterisk.org
- chan_capi - http://www.junghanns.net
- FWD - http://www.fwdnet.net
- IAXTEL - http://www.iaxtel.com
- The VoIP Wiki - http://www.voip-info.org
Copyright
(C) 2005
Jan Stocker
Redistribution of this text is permitted as long as the copyright is
retained and all text altering is marked by author and date.
Version 1.0 - 2005-03-30