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/

Modern versions of T38Modem

The section below "Compiling T38modem" instructions are very old, and you may experience great difficulty getting them working. At this time (26 February 2018), Pete Davidson appears to have the most up to date maintained version on his Github site, which includes relatively modern patched versions of PTLIB, OPAL and T38Modem. https://github.com/PeteDavidson?tab=repositories . Use his libraries forks.

For example a successful build made on 26/2/2018 which seems to work is:
ptlib tag v2.10.15
opal tag v3.10.15
t38modem v3.15.3

T38Modem Version 3.15.3
(OPAL-3.10.15/3.10.15 (svn:30298), PTLIB-2.10.15/2.10.15 (svn:30295)) by Frolov,Holtschneider,Davidson on Unix Linux (3.10.0-693.11.1.el7.x86_64-x86_64)

For exact commands to run to do this see the guides at:

In T38Modem sources:
- Look at the Readme.txt.
- Changes.txt will mostly tell you which versions of PtLib and Opal are compatible with the t38modem version.

Compiling T38modem

Edit: 26 February 2018 These are older instructions and you may experience difficulties due to multiple factors. SourceForgeCVS. To use a modern compiler you will need to "export STDCXXFLAGS=-std=gnu++98" before running the commands.

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.

systemd configuration

Some linux distributions such as CentOS 7 have moved to systemd rather than SystemV for initialization.

Create a file /etc/systemd/system/t38modem.service:
Description = T38Modem for /dev/ttyT38-1,/dev/ttyT38-2,/dev/ttyT38-3
#ConditionPathExists =
#Requires = asterisk.service
#After = asterisk.service

Type = simple

ExecStart = /usr/sbin/t38modem -ttt -o /var/log/t38modem.log --no-h323 -u T38modem --sip-listen udp$ --sip-t38-udptl-redundancy 3 --ptty +/dev/ttyT38-1,+/dev/ttyT38-2,+/dev/ttyT38-3 --route "modem:.*=sip:<dn>@" --route "sip:.*=modem:<dn>" --force-fax-mode --force-fax-mode-delay 0  --sip-register 1100@,pwd

Then start it using:
# systemctl enable t38modem.service
# systemctl start t38modem.service


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

For System V init:

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

Alternatively, for systemd:

Create a file /etc/systemd/system/faxgetty-ttyT38-1.service :
Description=HylaFAX faxgetty for ttyT38-1

ExecStart=/usr/local/sbin/faxgetty ttyT38-1


Enable them to run at boot time, and start now:
# systemctl enable t38modem.service
# systemctl start t38modem.service

Repeat making a file for each ttyT38-x instance you have set when launching t38modem.

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 with Chan_SIP

Consider using PJSIP - instructions are below
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!

Configuring Asterisk for T38modem with PJSIP

PJSIP is a newer SIP implementation in more recent asterisk versions.

For FreePBX users: If you are using FreePBX to manage it then you should create a custom extension, this will allow you to add the custom endpoint, and update your dialplan.
In the FreeePBX custom extension config user interface, go to Advanced, Edit Extension, Dial. And make sure PJSIP/ prefixes the extension number e.g. PJSIP/1100, this will map it to the endpoint correctly in the dialplan. The custom endpoint files should be created.

Note, if you are using Asterisk directly (rather than FreePBX), then you can edit the pjsip.conf rather than the custom files below.

Here is an example config that works with Asterisk 15. (Some are defaults provided by my install of FreePBX v14 and may not be required)


password=notarealpassword      ;--- make sure to change the password!

allow=!all,alaw				; be sure to specify only the codecs that your service provider supports, or you may have troubles!
t38_udptl=yes				; ***important***
t38_udptl_ec=redundancy     ; consider what value you want for this

See also

Created by: atis, Last modification: Thu 01 of Mar, 2018 (01:59 UTC) by jdavison
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+