Friday, November 12, 2004

Linux 2.6 with mISDN stack

ISDN is a telephone network widespread in european countries. Having faster call setup times than tipical PSTN lines makes it ideal for PABX systems. Historically, isdn4linux has been the first ISDN stack for the linux kernel, it has support for several devices but its support is discontinued for Linux 2.6 branch.

mISDN stands for modular ISDN, and of course is the next generation ISDN stack for passive adapters. One of the most disadvantages on using isdn4linux is the lack of a common CAPI 2.0 interface implementation (as of today, capidrv supports a small subset of CAPI 2.0 features). On the other hand, mISDN provides modules that expose a CAPI 2.0 compliant API for any supported adapter card.

The main objective of this tutorial is to setup the CAPI 2.0 support for passive ISDN adapters using the modular ISDN stack. It is assumed that the reader has the knowledge and skills to configure, compile, and install a linux 2.6.x kernel.

0. Prerequisites

# apt-get install build-essential cvs

1. Checkout mISDN sources from cvs

# export CVSROOT=:pserver:guest@cvs.isdn4linux.de/i4ldev
# cvs login
# cvs co mISDN

When prompted for a password enter readonly.

2. Integrate mISDN in your kernel source tree

# cd mISDN
# ln -s <your-kernel-tree-path> /usr/src/linux
# sh < std2kern

3. Configure, build and install the new modules

# cd /usr/src/linux
# make menuconfig

Under Device Drivers -> ISDN subsystem perform the following selections



Then under Modular ISDN driver perform these other selections



Enabling support for all cards is safe since every driver is built as a kernel module. When finished configure, build and istall the kernel as usual.

4. Loading the module

This step is quite important make sure to understand it deeply enough. If you try to load your module directly you'll end up with a failure message, instead you must use a modprobe script.

While on many systems it is sufficient to add the following lines to the file /etc/modprobe.conf, on Debian the preferred way is to create a file in /etc/modprobe.d (name it /etc/modprobe.d/capi) containg these directives (w6692pci is my choice, but you can replace it with any other low-level driver, ie avmfritz, hfcpci, ...):

alias /dev/capi20 w6692pci
alias char-major-68-0 w6692pci

install w6692pci /sbin/modprobe capi; \
/sbin/modprobe mISDN_core; \
/sbin/modprobe mISDN_l1; \
/sbin/modprobe mISDN_l2; \
/sbin/modprobe l3udss1; \
/sbin/modprobe mISDN_capi; \
/sbin/modprobe mISDN_x25dte; \
/sbin/modprobe --ignore-install w6692pci protocol=2

remove w6692pci /sbin/modprobe -r --ignore-remove w6692pci; \
/sbin/modprobe -r mISDN_x25dte; \
/sbin/modprobe -r mISDN_capi; \
/sbin/modprobe -r l3udss1; \
/sbin/modprobe -r mISDN_l2; \
/sbin/modprobe -r mISDN_l1; \
/sbin/modprobe -r mISDN_core; \
/sbin/modprobe -r capi

Now it is possible to load the module issuing a modprobe or by enabling discover at startup.

# modprobe w6692pci

Make sure the driver is correctly loaded, a sample syslog output follows:

Modular ISDN Stack core $Revision: 1.23 $
mISDNd: kernel daemon started
mISDNd: test event done
CAPI Subsystem Rev 1.1.2.8
capifs: Rev 1.1.2.3
capi20: Rev 1.1.2.7: started up with major 68 (middleware+capifs)
ISDN L1 driver version 1.11
ISDN L2 driver version 1.19
mISDN: DSS1 Rev. 1.26
mISDN Capi 2.0 driver file version 1.14
X25 DTE modul version 1.6
Winbond W6692 PCI driver Rev. 1.12
mISDN_w6692: found adapter Dynalink/AsusCom IS64PH at 0000:01:05.0
W6692: Winbond W6692 version (0): W6692 V00
kcapi: Controller 1: mISDN1 attached
w6692: IRQ 17 count 4
kcapi: card 1 "mISDN1" ready.
w6692 1 cards installed

5.1. Install the isdn utilitiles the Debian Sarge way

# apt-get install isdnutils-base libcapi20-3 isdnactivecards

Open the file /etc/isdn/capi.conf and comment out everything (usually passive ISDN cards don't need a firmware).

5.2. Install the isdn utilitiles from source

# cvs co isdn4k-utils
# cd isdn4k-utils/capiinfo
# ./configure
# make
# make install

6. Issue a capiinfo to see the hardware/driver capabilities

# capiinfo

Will output something similar to:

Number of Controllers : 1
Controller 1:
Manufacturer: mISDN CAPI controller W6692_1
CAPI Version: 2.0
Manufacturer Version: 1.0
Serial Number: 0002
[...]

7. Conclusions and future improvements

mISDN support is needed for using chan_capi or chan_misdn (I've only tested the former). Enabling asterisk CAPI support support is quite easy once mISDN modules are properly configured.

See also

Asterisk How to connect with CAPI
chan_capi Home
Asterisk CAPI readme

Thursday, November 11, 2004

Asterisk with MoH Patch on Debian Sarge

Music on hold is a nice feature of asterisk, implemented through res_musiconhold.so. To setup music on hold the standard way you need to download recompile and install mpg123 as voip-info suggests.

Note that on Debian there's a symlink between mpg123 and mpg321 (which is not supported currently). So, download mpg123-0.59r.tar.gz, compile it, and install it (by default the package is installed in /usr/local/bin, which is the first path searched by asterisk).

Another way to setup music on hold is to integrate MoH patch (the patch is bundled with chanspy) into the asterisk package, thus enabling native file format decoding and removing mpg123 dependancy. What follows are some simple steps to setup a MoH extension using ulaw encoded files.

0. Prerequisites

# apt-get install build-essential dh-make patch
# wget <url-to-chanspy-tar-gzip-archive>
# tar xzf chanspy.tar.gz

This command creates a directory named chanspy

1. Patch and rebuild asterisk

# apt-get source asterisk

This command creates a directory named asterisk-<current-version> (in my case asterisk-1.0.1)

# cd asterisk-1.0.1
# patch -p0 < ../chanspy/mohpatch.diff
# dpkg-buildpackage -D -b


If this last command fails, make sure to fulfill all the dependencies (don't be warned if more than 50 packages need to be installed).

# dpkg -i ../asterisk_*.deb

2. Add a sample extension to asterisk

First add the following lines to /etc/asterisk/extensions.conf

exten => 1234,1,Answer
exten => 1234,2,SetMusicOnHold(ulawfiles)
exten => 1234,3,MusicOnHold()

Then configure the ulawfiles class in /etc/asterisk/musiconhold.conf adding these lines

[moh_files]
ulawfiles => /usr/share/asterisk/sounds/ulawfiles

Make sure to have some files to be played in the right place

# mkdir -p /usr/share/asterisk/sounds/ulawfiles
# sox -V example.mp3 -t au -r 8000 -U -b -c 1 \
/usr/share/asterisk/sounds/ulawfiles/example.ulaw resample -ql

3. Restart asterisk and make a call to 1234 and enjoy the music on hold...

# /etc/init.d/asterisk restart

4. Fine tuning and audio improvements

With format_mp3.so module MoH can also play mp3 files. Some files may play scratchy due to the high volume level, you can adjust the amplitude with the "-v volume" flag of sox.

Saturday, September 11, 2004

Maybe I'm wrong

Eventually I decided to open my brand new Blog! I'm a software developer and linux enthusiast, so the majority of postings will be related to tech issues and similar odd stuff.
By the way, stay tuned for more free thoughts...