Asterisk PBX with Reliance PRI Line using Digium TE131F
So I got an opportunity to set up Asterisk PBX with a Reliance Communications E1 line. I have worked with Asterisk PBX, but without PSTN interfacing. This post is about what all stuff I have done to get a Reliance E1 line with Digium TE131F card.
Having explored a lot of other distributions like Fedora, Arch, Gentoo, Sabayon, etc. since I ventured into Linux world and learning the internals of Linux and how different components are stitched together I settled on Ubuntu. It’s my favorite these days because everything seems to work out of the box… except when it doesn’t, then you have PPAs. 😛 For this project I have installed Ubuntu 16.04 server edition.
The default Asterisk 13.13 build which is available in the Ubuntu Xenial repository is broken. If you enable the PJSIP channel (res_pjsip.so), Asterisk will crash immediately after starting up. There is even a launchpad bug for the same => Asterisk crashes with default install because of pjsip. Thankfully arpagon (Sebastian) has fixed it in his PPA which is given in the last comment of the bug. The PPA is this one => Asterisk PPA : “Sapian” team.
So add the PPA (but do not install asterisk yet):
sudo add-apt-repository ppa:sapian/asterisk
sudo apt update
DAHDI Driver Installation
First of all, we need to install the DAHDI drivers. The Digium TE131F driver is absent with the default install (launchpad bug) and needs to extra steps so that the module gets installed, as given below.
Install dahdi-dkms package and then remove all the drivers that got installed into current kernel when the package was installed:
apt install dahdi-dkms
dkms uninstall dahdi/2.10.2~dfsg-1ubuntu1
dkms remove dahdi/2.10.2~dfsg-1ubuntu1 --all
Then go to /usr/src/dahdi-2.10.2~dfsg-1ubuntu1 and edit the dkms.conf file to add these lines at the end of the file, just before AUTOINSTALL=yes line. This should be the last few lines of the file:
BUILT_MODULE_NAME[33]="oct612x"
BUILT_MODULE_LOCATION[33]="drivers/dahdi/oct612x/"
DEST_MODULE_LOCATION[33]="/kernel/drivers/telephony/dahdi"
BUILT_MODULE_NAME[32]="wcte13xp"
BUILT_MODULE_LOCATION[32]="drivers/dahdi/"
DEST_MODULE_LOCATION[32]="/kernel/drivers/telephony/dahdi"
AUTOINSTALL=yes
Now we can proceed to installing the dkms drivers to our current kernel and asterisk as well:
dkms add dahdi/2.10.2~dfsg-1ubuntu1
dkms install dahdi/2.10.2~dfsg-1ubuntu1
apt install asterisk asterisk-dahdi
DAHDI Configuration
Edit /etc/dahdi/modules and delete the line that says dahdi_dummy . In the same file add a line wcte13xp. So this should be the content of /etc/dahdi/modules :
dahdi
dahdi_transcode
wcte13xp
Create a modprobe configuration file named /etc/modprobe.d/pri.conf with the content as below:
options dahdi auto_assign_spans=1
options wcte13xp default_linemode=e1
Actually the modprobe configuration file can be avoided if you want to manually configure the DAHDI cards, and it is useful to do so only if you have more than one card in the system. For my case, it is just one so I went this way.
Then load the modules for the card:
modprobe wcte13xp
modprobe dahdi_transcode
Run dmesg to see if there were any errors, when I had done this I got some firmware error that card firmware is running some older version than the one required by the driver. To fix that I downloaded the required TE133 firmware file (the same version as demanded by the driver, given in the dmesg ) from Digium and placed it into /lib/firmware , then unloaded wcte13xp module and reloaded it. After doing that you will see the driver will start flashing the new firmware, once the process is complete the card will be ready for use.
Now we are ready to configure DAHDI for use by Asterisk, first we generate configuration which is used by the DAHDI Linux Tools:
dahdi_genconf --line-mode=E1 -v
Edit /etc/dahdi/system.conf and change the variables loadzone , defaultzone to your country. In my case it is India, so:
# Autogenerated by /usr/sbin/dahdi_genconf on Mon Jul 10 08:43:20 2017
# If you edit this file and execute /usr/sbin/dahdi_genconf again,
# your manual changes will be LOST.
# Dahdi Configuration File
#
# This file is parsed by the Dahdi Configurator, dahdi_cfg
#
# Span 1: WCT13x/0 "Wildcard TE131/TE133 Card 0" (MASTER) CCS/HDB3/CRC4 RED ClockSource
span=1,1,0,ccs,hdb3,crc4
# termtype: te
bchan=1-15,17-31
dchan=16
echocanceller=oslec,1-15,17-31
# Global data
loadzone = in
defaultzone = in
Before jumping on to Asterisk configuration let’s first check if DAHDI configuration works correctly. Read the output of the command below carefully and ensure there is no error present. When I was doing I got some Echo Cancellation related error and that was apparently due to a kernel upgrade that was done by aptitude. I had to redo the driver installation step after rebooting to fix that.
dahdi_cfg -vvv
Asterisk Configuration
There are a lot of parameters in the DAHDI channel configuration, and we do not really care about what they are at this moment, we just want to get the thing working so just edit , go to the end of file, add following line:
#include /etc/asterisk/dahdi-channels.conf
Let’s build a sample extensions.conf that plays Hello World when called. I prefer to configure Asterisk using LUA because I’m a programmer and it’s easier for me to do that then learn a new way to configure something. So this configuration is limited to just playing Hello World for testing purpose:
[from-pstn]
exten = _X.,1,Answer()
same = n,Wait(3)
same = n,Playback(hello-world)
same = n,Hangup()
Finally to ensure that DAHDI is configured properly before Asterisk starts we need to add a override to the Asterisk SystemD Unit file, so run systemctl edit asterisk and add the lines below:
[Service]
ExecStartPre=/usr/sbin/dahdi_cfg
Additionally, we also need to load the DAHDI and our card modules at boot, so:
ln -s /etc/dahdi/modules /etc/modules-load.d/dahdi
The above two steps are required because the dahdi-linux package does not provide the DAHDI init script which does these things. I have filed a bug for the same, at launchpad.
Restart Asterisk and call your allocated DID and you should hear Hello World from Asterisk!