Upgrade 3CX to v18 and get it hosted free!

T38modem configuration with Asterisk

Author image

This article describes setting up T38modem for calls between two T38modems. For information on connecting to a SIP provider, see 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.  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 passthrough mode for SIP channels.

This article will describe how to configure T38modem for sending faxes through 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.

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:
http://wiki.opalvoip.org/index.php?n=Main.BuildingPTLibUnix
http://wiki.opalvoip.org/index.php?n=Main.BuildingOpalUnix

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 has 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:[email protected]:/cvsroot/openh323 co ptlib_unix
cvs -z9 -d :pserver:[email protected]:/cvsroot/openh323 co -D "5/21/2007 23:59:59" opal
cvs -z9 -d :pserver:[email protected]:/cvsroot/openh323 co t38modem

# build pwlib
cd ~/pwlib
./configure
make
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
./configure
make
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 the 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\$127.0.0.1:6060 --sip-redundancy 3 --ptty +/dev/ttyT38-1,+/dev/ttyT38-2,+/dev/ttyT38-3 --route "modem:.*=sip:<dn>@127.0.0.1" --route "sip:.*=modem:<dn>"

This will start T38modem in non-daemon mode. You will see some basic log on the current terminal, and full log (Trace level 2) will be written to /var/log/t38modem.log
You may increase the 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\$127.0.0.1:6060 will start a SIP daemon on the 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>@127.0.0.1” 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 the opposite direction, so fax received to the SIP port of T38modem will go to the 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:

[Unit]
Description = T38Modem for /dev/ttyT38-1,/dev/ttyT38-2,/dev/ttyT38-3
#ConditionPathExists =
#Requires = asterisk.service
#After = asterisk.service

[Service]
Type = simple
Restart=always
#RestartSec=30

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

Then start it using:
<pre>
# systemctl enable t38modem.service
# systemctl start t38modem.service

Install
WantedBy=multi-user.target
</pre>

Configuring HylaFax to use T38modem

I’ll assume that Hylafax is already configured, so those are steps to add a 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 :

[Unit]
Description=HylaFAX faxgetty for ttyT38-1

[Service]
User=root
Group=root
Restart=always
RestartSec=30
ExecStart=/usr/local/sbin/faxgetty ttyT38-1

[Install]
WantedBy=multi-user.target

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
t38pt_udptl=yes

Then add account for T38modem:

[T38modem]
type=friend
host=127.0.0.1
permit=127.0.0.1
context=fax_out
port=6060
allow=all
canreinvite=no
t38pt_udptl=yes

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;
    }

    Dial(SIP/${EXTEN}@${TRUNK},180);

    Busy();
    Hangup();
  }
}

/* Whenever you have detected incoming fax, send call here */
context fax_in {
  _X. => {
    Set(max_retries=5);
    /* Try ringing modem for 5 times, in case all modems are currently busy */
    while ("${DIALSTATUS}"!="ANSWER" & ${max_retries}>0) {
      Dial(SIP/${EXTEN}@T38modem,15,g);
      Wait(2);
      Set(max_retries=$[${max_retries}-1]);
    }
    Busy();
    Hangup();
  }
}

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

Testing loopback fax

sendfax -h 127.0.0.1 -f [email protected] -n -D -d 112233 /etc/passwd

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

Note: If your config does not work, try to pass –sip-old-asn as an 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 FreePBX 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)

pjsip.aor_custom.conf:

[1100]
type=aor
mailboxes=1100@device
max_contacts=1
remove_existing=yes
qualify_frequency=60

pjsip.auth_custom.conf:

[1100-auth]
type=auth
auth_type=userpass
password=notarealpassword      ;--- make sure to change the password!
username=1100

pjsip.endpoint_custom.conf:

[1100]
type=endpoint
aors=1100
auth=1100-auth
allow=!all,alaw				; be sure to specify only the codecs that your service provider supports, or you may have troubles!
context=from-internal
callerid=
dtmf_mode=rfc4733
aggregate_mwi=yes
use_avpf=no
rtcp_mux=no
ice_support=no
media_use_received_transport=no
trust_id_inbound=yes
timers=yes
media_encryption_optimistic=no
send_pai=yes
rtp_symmetric=yes
rewrite_contact=yes
force_rport=yes
language=en
t38_udptl=yes				; ***important***
t38_udptl_ec=redundancy     ; consider what value you want for this

See also

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.