T38modem configuration with Asterisk

This article describes setting up T38modem for calls between two T38modems. For information on connecting to a SIP provider, see the blue notes below.
I have just completed an article on connecting t38modem directly to Callcentric (a US-based SIP provider) without using Asterisk at all. It is available on the wiki: T38modem SIP configuration with Callcentric. Hopefully it will help others. (drinian)

Yes, there is a solution to send fax to External SIP provider: T38modem->Asterisk->SIP-provider. My article 'VentaFax->T38modem(SIP)->Asterisk->SIP-provider' is here. http://www.voipinfo.ru/forum/viewtopic.php?t=11767 It is in Russian, if there will be some more time I will try to write about it in English. (dmitry77)

Asterisk 1.4 does support T.38 in passtrough mode for SIP channels.
This article will describe how to configure T38modem for sending faxes trough Asterisk. Example configuration will use Hylafax+ for sending and receiving fax, however other software may be used.
Note: There is a bug with T.38 in Asterisk version 1.4.19 and this example won't work on it, so it's recommended that you use Asterisk >=1.4.20

I've managed and got together a HOWTO from all components here and there. You could check it here: http://www.foriamroot.org/hylafax-6-0-debian-or-ubuntu-t38modem-1-0-asterisk-1-6/

Compiling T38modem

As Asterisk doesn't yet support T.38 for H323, T38modem have to be configured with SIP support. For that you need OPAL.
There is a known issue with T38modem : it won't compile with OPAL versions released after May 21, 2007.

Download required libraries and T38modem

It's highly recommended to download and compile everything in your home directory, otherwise you may step on several linking problems.

cd ~
cvs -z9 -d :pserver:anonymous@openh323.cvs.sourceforge.net:/cvsroot/openh323 co ptlib_unix
cvs -z9 -d :pserver:anonymous@openh323.cvs.sourceforge.net:/cvsroot/openh323 co -D "5/21/2007 23:59:59" opal
cvs -z9 -d :pserver:anonymous@openh323.cvs.sourceforge.net:/cvsroot/openh323 co t38modem

# build pwlib
cd ~/pwlib
sudo make install
Edit by darkbasic: you should remove unixodbc headers, otherwise compilation will fail. In debian: apt-get remove --purge unixodbc-dev

# build OPAL
cd ~/opal
sudo make install
sudo ldconfig

# build T38modem
cd ~/t38modem
make USE_OPAL=1 USE_UNIX98_PTY=1 opt
sudo make USE_OPAL=1 USE_UNIX98_PTY=1 install

Note: It's advised to have USE_UNIX98_PTY, as your kernel might not have 'Legacy PTY Support' required for default installation of T38modem. Also launching parameters will be different when using this option.

Starting T38modem

sudo /usr/local/bin/t38modem -tt -o /var/log/t38modem.log --no-h323 -u T38modem --sip-listen udp\$ --sip-redundancy 3 --ptty +/dev/ttyT38-1,+/dev/ttyT38-2,+/dev/ttyT38-3 --route "modem:.*=sip:<dn>@" --route "sip:.*=modem:<dn>"

This will start T38modem in non-daemon mode. You will see some basic log on current terminal, and full log (Trace level 2) will be written to /var/log/t38modem.log
You may increase amount of -tttt to get more details in log.

--no-h323 will disable H323 support, which won't work with Asterisk anyway for now.

-u T38modem does set SIP user to "T38modem", so that you can use it to identify it in Asterisk.

--sip-listen udp\$ will start a SIP daemon on local interface, port 6060. Don't use port 5060, as it should be used by Asterisk on the same machine.

--sip-redundancy 3 sets 3 retry packets

--ptty +/dev/ttyT38-1,+/dev/ttyT38-2,+/dev/ttyT38-3 will create 3 virtual modem devices.

--route "modem:.*=sip:<dn>@" creates a route, so that fax sent from modem will be sent trough SIP to local Asterisk.

--route "sip:.*=modem:<dn>" creates a route in opposite direction, so fax received to SIP port of T38modem will go to modem device.

Configuring HylaFax to use T38modem

I'll assume that Hylafax is already configured, so those are steps to add modem.

Use default configuration for all 3 modems:
cp ~/t38modem/HylaFAX/config.ttyx /var/spool/hylafax/etc/config.ttyT38-1
ln -s /var/spool/hylafax/etc/config.ttyT38-1 /var/spool/hylafax/etc/config.ttyT38-2
ln -s /var/spool/hylafax/etc/config.ttyT38-1 /var/spool/hylafax/etc/config.ttyT38-3

Listen to modems for incoming faxes (make sure you enter correct path for faxgetty):
echo "t1:2345:respawn:/usr/sbin/faxgetty ttyT38-1" >> /etc/inittab
echo "t2:2345:respawn:/usr/sbin/faxgetty ttyT38-2" >> /etc/inittab
echo "t3:2345:respawn:/usr/sbin/faxgetty ttyT38-3" >> /etc/inittab
kill -HUP 1

Restart hylafax:
/etc/init.d/hylafax restart

So, now Hylafax should see those 3 modems for sending and receiving.
You may want to look into /var/spool/hylafax/status/ttyT38-1 and other files there for current modem status.
$ cat /var/spool/hylafax/status/ttyT38-1
Running and idle

Configuring Asterisk for T38modem

Open /etc/asterisk/sip.conf for editing.

In [general]section add:

; enable general T.38 support

Then add account for T38modem:

In extensions.ael (assuming you are using AEL2 to code dialplan for fax reception/sending) create:

/* Outgoing fax goes trough context "fax_out" */
context fax_out {
  _X. => {
    /* Test destination that goes back to T38modem */
    if ("${EXTEN}"="112233") {
      goto fax_in,${EXTEN},1;



/* Whenever you have detected incoming fax, send call here */
context fax_in {
  _X. => {
    /* Try ringing modem for 5 times, in case all modems are currently busy */
    while ("${DIALSTATUS}"!="ANSWER" & ${max_retries}>0) {

So, now you just have to reload sip and ael code, and it should be working.

Testing loopback fax

sendfax -h -f email@company.com -n -D -d 112233 /etc/passwd

Now check /var/spool/hylafax/log/ and see last two files, one of them should be log of sending, and another of receiving.

Note: If your config does not work, try to pass --sip-old-asn as additional parameter. Our asterisk box is connected to an HiPath 3350 system and without that parameter, t38modem refused to work. Now works as expected!

See also

Created by: atis, Last modification: Tue 11 of Sep, 2012 (00:29 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+