Sunday, March 21, 2010

VoIP - Asterisk on BSD as ATA

My DSL service comes with a free SIP account as the DSL link is dedicated to data transfer. In another words, the line carries no POTS signal and I cannot plug a PSTN phone into it.

While there are lots of VoIP phones in the market costing around several hundred dollars, I decided to make use of my PSTN cordless phone sitting idle for afew years by converting my BSD system into an ATA box using Asterisk.Initially, I thought getting a modem card with a phone port would be sufficient. It just won't work, because the PSTN phone requires connection to an FXS port that feeds dial-tone and power.

PCI Card with FXS Port
I searched through some user forums and came across this china-based company called OpenVox www.openvox.cn. Openvox clones Digium (Asterisk's official telephony hardware) but is cheaper. According to their webpage, their hardware is A-tick certified hence it shouldn't be a problem using them in Australia's. Besides, I am not plugging it into PSTN, just using it to interface my own PSTN phone.

I placed my order online and received the product within a week through DHL.



















I purchased a A400P card (4 FXO/FXS PCI card) with one-port FXS (also known as TDM10B) requiring a power feed. So, I had to disconnect that from the DVD drive. Starting up BSD shows the hardware is correctly recognized:

Zapata Telephony Interface Registered on major 196
Zaptel Echo Canceller: MG2
Zaptel Version: zaptel-bsd-ng v0.0.1
wctdm0 port 0x1000-0x10ff mem 0xfc501000-0xfc501fff irq 10 at device 9.0 on pci5
wctdm0: [FILTER]
Freshmaker version: 71
Freshmaker passed register test
Module 0: Installed -- AUTO FXS/DPO
Found a Wildcard TDM: Wildcard TDM400P REV E/F (1 modules)
Registered tone zone 1 (Australia)

Afterwards I setup the hardware referencing Openvox's user manual (for Linux...). The zaptel driver was installed through ports under the directory "/usr/ports/misc/zaptel/" and I updated zaptel.conf as follows:
fxoks=1
loadzone = au
defaultzone=au # The zone list for different countries is located in zaptel/zonedata.c

Using the command "ztcfg -vvv" displayed no errors.
Zaptel Version: zaptel-bsd-ng v0.0.1
Echo Canceller: MG2
Configuration
======================
Channel map:
Channel 01: FXO Kewlstart (Default) (Slaves: 01)
1 channels to configure.

As you may notice, the zaptel output indicates a FXO port while dmesg indicated otherwise. I emailed the OpenVox support team, whom, to their credit, promptly replied and informed me this is the correct output.

Getting Zaptel/ Dahdi to work on Asterisk
I then proceeded to install Asterisk under /usr/ports/net/asterisk, version 1.4.x. Upon installation, I noted the "zap show channels" command not found.

I searched through several forums. One suggested ensuring zaptel driver is installed prior to installing Asterisk, and ensuring "zaptel driver" option is included during Asterisk installation. The other suggested the error was caused by chan_zap.so was built without support for libpri. I then installed "asterisk-bristuff" port. These resolutions seem to take care of the problem.

Another point of interest is, as of Asterisk 1.4, the zaptel driver is renamed to dahdi due to copyright reasons. http://blogs.digium.com/2008/05/19/zaptel-project-being-renamed-to-dahdi/. While Asterisk 1.4 still supports zaptel transparently, its support will be completely removed in Asterisk 1.6. Currently, dahdi port is unavailable on FreeBSD and so I recommend avoiding 1.6 until dahdi port becomes available, unless you are building a pure IP PBX. http://www.freebsd.org/news/status/report-2009-10-2009-12.html#DAHDI-(Zaptel)-support-for-FreeBSD


Having reinstalled Asterisk, I entered into its CLI console. This time, dahdi displayed no channels:
CLI>; dahdi show channels
Chan Extension Context Language MOH Interpret

So I reload the "chan_dahdi.so" module, and noted the following:
CLI > ; reload chan_dahdi.so
-- Reloading module 'chan_dahdi.so' (DAHDI Telephony w/PRI)
[Mar 22 20:49:45] ERROR[1275]: chan_dahdi.c:12040 setup_dahdi: Unable to load zapata.conf

So I copied my chan_dahdi.conf file to zapata.conf. By the way, I added the following to my zapata.conf/ zapata.conf:
[channels]
signalling=fxo_ks
adsi=yes
pulse=yes
context=outbound-local # as defined in "extensions.conf"
channel = > ; 1 # as defined in "zaptel.conf" channel 1. check with "dahdi show channels"

I used the rc.d asterisk script to restart Asterisk. Finally, "dahdi show channels" confirms the channel is up.
Chan Extension Context Language MOH Interpret
pseudo default default
1 outbound-local default


Configuring Asterisk files
There is a community forum for Australian Broadband users where a greate user guide is posted, on setting up Asterisk for iiNet VoIP service. http://whirlpool.net.au/wiki/?tag=iiNetPhone_asterisk. I referenced this guide for most of my configurations (sip.conf and extension.conf) with the following (minor) exceptions:

- sip.conf

; iiNet configuration
register => 0380601093@iinetphone.iinet.net.au:t7hzfxi6l:0380601093@iiNet-out/0380601093

[iiNet-out]
;allow=g729 # I had to disable g729 codec otherwise it led to error when I used my phone. I only have alaw and ulaw enabled.
;;; there are also other configurations, such as type=friend, which are not shown here

- modules.conf
noload = > ; res_musiconhold.so # High CPU issue, disable module

- extensions.conf.
[inbound]
exten = > ; 03,1,Dial(DAHDI/1-1,10) # "DAHDI/1-1" refers to PSTN cordless phone. "10" - rings for 10 seconds


[outbound-local]
exten => _00XXXXXXXXX,1,Dial(iiNet-out/${EXTEN:1})



Having completed the Asterisk's configurations, Asterisk can be invoked through:
# /usr/local/etc/rc.d/asterisk {start | stop}

And to access the Asterisk's console:
# asterisk -rvvvgc - Asterisk terminal with debug
>; sip show register - "iiNet-out" successfully registered to iiNet SIP Server
>; show modules - check for "chan_dahdi.so" (zaptel driver). If not, "load module chan_dahdi.so".
>; dahdi show channels - show zaptel driver channels. See WorkNotes above for troubleshoot...
>; reload - reload Asterisk after all configuration changes.

If you would like to start Asterisk when system starts up, add asterisk_enable="YES" to /etc/rc.conf.


Note: During one of the many reinstallations I had, asterisk simply refused to start up. Console connection caused a "/var/run/asterisk.ctl connection refuse" error. My resolution was to completely remove the entire port (make clean deinstall), and then manually removed the following directories:
/usr/local/lib/asterisk
/usr/local/etc/asterisk
/var/spool/asterisk
/var/log/asterisk
Afterwards, I performed a "make clean depend install" (include zaptel option) and Asterisk works fine again.


I restarted the system, and Asterisk is working fine. The sip account is registered successfully and I was getting a dial-tone on my PSTN phone. I could dial voice calls successfully but couldn't hear any sound for incoming calls. It turned out the D-Link DSL modem (NAT) was blocking incoming voice traffic.

First, I reconfigured "rtp.conf" file's "rtpstart" and "rtpend" parameters to define the RTP port range. Then I proceeded to reconfigure the D-Link DSL modem, but it "bricked" and I had to replace this modem. (And that's definitely a different post).










As of today, I am using a TP-Link 8810 DSL modem, bridge mode with PPPoE and NAT terminating on BSD system. Other than the CPU usage reaching 50%, the VoIP phone works perfectly fine.

1 comment:

  1. Very informative article. Thanks.

    BTW, Is the TDM400P card still working or has it been obsoleted?

    Thanks

    ReplyDelete