Asterisk is one of the most widely deployed SIP switching platforms in the world, and is known to work very well with Power-T.38. In fact, some of our largest service provider customers have built their businesses on Asterisk and related Open Source telephony tools! The features available and configuration you will need varies widely by release, as we will detail in the sections below (this page is a work in progress, and contributions to our support@ email address are always welcome!).


Fax for Asterisk


This is a commercial driver, available from Digium, that can used with both Switchvox and Asterisk. They offer one license for free.

You can learn more at:

http://www.digium.com/en/products/software/fax-for-asterisk



Asterisk 13 (LTS)


This version supports both T.38 passthrough and T.38 termination. We have configuration instructions for both chan_sip and chan_pjsip, be sure that you're using the right configuration!


Chan_SIP:


T.38 Passthrough Support:


To integrate T38Fax.com with Asterisk to connect a fax machine to a T-38 capable ATA.  This will allow a fax machine to send and receive calls via T38Fax.com with Asterisk in the middle.


1. Sign up for a free trial at https://www.t38fax.com/signup

2. Check astmoddir (/usr/lib/asterisk/modules) for two standard modules: chan_sip.so and res_rtp_asterisk.so.


If you do not have both modules, you must reconfigure/recompile asterisk.  Here are the commands:

cd /usr/local/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
tar xvfz asterisk-13-current.tar.gz
cd asterisk-13.*
./configure
make menuselect
# Ensure that the following modules are enabled [*]
# Channel Drivers/chan_sip
# Resource Modules/res_rtp_asterisk
make install

 

3. Modify your sip.conf file (/etc/asterisk/sip.conf):

  • Add the following to the [general] section of your sip.conf file:
directmedia=no
t38pt_udptl=yes,redundancy
register=YOUR_DID:YOUR_PWORD@sip.t38fax.com~600

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.

  • Add a T38fax user definition to the bottom of your sip.conf file as follows:
[t38fax]
type=peer
context=Power-T.38-in
qualify=no
defaultexpiry=600
insecure=port,invite
host=sip.t38fax.com
realm=sip.t38fax.com
defaultuser=YOUR_DID
secret=YOUR_PWORD

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a user definition for your ATA to register as. Add this after the [t38fax] definition in your sip.conf file:
[YOUR_DID]
type=friend
context=Power-T.38-out
qualify=yes
qualifyfreq=600
host=dynamic
defaultexpiry=600
defaultuser=YOUR_DID
callerid="John Doe" <YOUR_DID>
secret=YOUR_ATA_PWORD

 

Make sure to replace YOUR_ATA_PWORD with a password for your ATA to register to your Asterisk server, and replace YOUR_DID with your T38fax.com DID. Depending on your deployment & network topology, you may need to add nat=yes to both of the definitions above. Ask your network administrator if you are using NAT Traversal.


  • Add the following to your udptl.conf file (/etc/asterisk/udptl.conf):
udptlstart=10000
udptlend=10999
T38FaxUdpEC=t38UDPRedundancy

 


4. Modify/Create your extensions.conf file (/etc/asterisk/extensions.conf):

  • Make sure you have a "exten => s" in your [default] context.  This allows for proper replies to T38fax.com SIP monitoring.
[default]
; This ensures we reply 200 OK to OPTIONS messages.
exten => s,1,NoOp( got in default/S )

 

  • Create your [Power-T.38-in] context:
[Power-T.38-in]
; The following detects the dialed number.
exten => s,1,Set(DNID=${SIP_HEADER(To)})
exten => s,n,Set(DNID=${CUT(DNID,@,1)})
exten => s,n,Set(DNID=${CUT(DNID,:,2)})
exten => s,n,Goto(${DNID},1)
; The following sends the incoming call to the SIP user.
exten => YOUR_DID,1,Dial(SIP/YOUR_DID)
; If you have more than one DID, you can add additional definitions to route them as well:
exten => YOUR_SECOND_DID,1,Dial(SIP/YOUR_SECOND_DID)

 

Make sure to replace YOUR_DID with your T38fax.com DID.


  • Create your [Power-T.38-out] context:
[Power-T.38-out]
; Add support for 11 digit dialing (adds the leading 1).
exten => _1NXXNXXXXXX!,1,NoOp(caught 11 digits ${EXTEN})
exten => _1NXXNXXXXXX!,n,Dial(SIP/${EXTEN}@t38fax)

 

5. Configure your ATA to connect to Asterisk.


As an Example, to configure a Cisco SPA-112:


  1. Follow the steps at: <SPAARTICLE>
  2. Navigate to "Voice -> Line 1".
  3. Enter your Asterisk Server's address/hostname in the "Proxy" field.
  4. Enter the context you created in Step 2 in the "Display Name" and "User ID" fields. (Likely your T38Fax.com DID if you followed this guide).
  5. Enter the password for the context you created in Step 3 in the "Password" Field.
  6. Click Submit, and the SPA112 should reload it's configuration.
  7. In the Asterisk CLI (asterisk -r) you should now be able to see the device register. Enter: sip show peer YOUR_DID (You'll want to look for "Status: OK" and "Addr -> IP" to show an IP address. Remember to replace YOUR_DID with your T38Fax.com DID!)


T.38 Termination Support:


Coming Soon!


Chan_PJSIP:


T.38 Passthrough Support:


To integrate T38Fax.com with Asterisk to connect a fax machine to a T-38  capable ATA.  This will allow a fax machine to send and receive calls  via T38Fax.com with Asterisk in the middle.


1. Sign up for a free trial at https://www.t38fax.com/signup

2. Check astmoddir (/usr/lib/asterisk/modules) for two standard modules: chan_pjsip.so and res_pjsip.so.


If you do not have both modules, you must reconfigure/recompile  asterisk.  You will also need to download and compile pjproject. Here  are the instructions:


Download & Compile pjproject:

cd /usr/src
wget http://www.pjsip.org/release/2.4/pjproject-2.4.tar.bz2
tar -xjvf pjproject-2.4.tar.bz2
cd pjproject-2.*

# See https://wiki.asterisk.org/wiki/display/AST/Building+and+Installing+pjproject for additional options you may wish to configure. Note: This command must be modified when using a 32-bit operating system. Simply remove the --libdir=/usr/lib64 option from the command.

./configure CFLAGS="-DNDEBUG -DPJ_HAS_IPV6=1" --prefix=/usr --libdir=/usr/lib64 --enable-shared --disable-video --disable-sound --disable-opencore-amr

make dep
make
make install
ldconfig

# Verify that the PJSIP libraries have been dynamically linked by running:
ldconfig -p | grep pj

 

Then, recompile Asterisk with the PJSIP Modules:

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-13-current.tar.gz
tar xvfz asterisk-13-current.tar.gz
cd asterisk-13.*
# Configure Asterisk, if using a 32-bit operating system, just run ./configure
./configure --libdir=/usr/lib64
make menuselect
# Ensure that the following modules are enabled [*]
# Channel Drivers/chan_pjsip
# Resource Modules/res_pjsip
make install

 

 3. Modify your pjsip.conf file (/etc/asterisk/pjsip.conf):


This configuration guide assumes that you have configured your network  correctly and understand it's setup. We do not include NAT or Transport  specifications as each deployment will be different.


  • Setup your Transport. Use the UDP Protocol, and configure the transport as your network requires.
  • Add a trunk section to define your T38Fax.com SIP Trunk, it's configuration is below. Be sure to add in your account-specific information!
;===============TRUNK

[t38fax_reg]
type=registration
transport=YOUR-TRANSPORT
outbound_auth=t38fax_auth
server_uri=sip:sip.t38fax.com
client_uri=sip:YOUR-DID@sip.t38fax.com:5060
retry_interval=60
contact_user=YOUR-DID

[t38fax_auth]
type=auth
auth_type=userpass
password=YOUR-ACCOUNT-PASSWORD
username=YOUR-DID

[t38fax_aor]
type=aor
contact=sip:sip.t38fax.com:5060

[t38fax_endpoint]
type=endpoint
transport=YOUR-TRANSPORT
context=Power-T.38-in
disallow=all
allow=ulaw
outbound_auth=t38fax_auth
aors=t38fax_aor
force_rport=yes
rtp_symmetric=yes
rewrite_contact=no
t38_udptl=yes
t38_udptl_maxdatagram=400
t38_udptl_ec=redundancy
t38_udptl_nat=yes
direct_media=no

[t38fax_endpoint]
type=identify
endpoint=t38fax_endpoint
match = 8.34.182.111
match = 8.34.182.112

 

Be sure to define a transport, and replace YOUR-TRANSPORT with the definition you defined in pjsip.conf. Make sure to replace YOUR-DID with your T38fax.com DID, and replace YOUR-ACCOUNT-PASSWORD with the provided password for your account.


  • Finally, add a "Devices" definition after your trunk section to define configuration options for your ATA so it can register using a PJSIP channel. A configuration example is below:
;===============Devices

[YOUR-DID]
type=aor
max_contacts=1
qualify_frequency=600
remove_existing=yes

[YOUR-DID]
type=auth
auth_type=userpass
username=YOUR-DID
password=DEFINE-A-PASSWORD
realm=sip.t38fax.com

[YOUR-DID]
type=endpoint
transport=YOUR-TRANSPORT
context=Power-T.38-out
dtmf_mode=rfc4733
disallow=all
allow=alaw
allow=ulaw
force_rport=yes
rtp_symmetric=yes
rewrite_contact=no
direct_media=no
callerid="John Doe" <YOUR-DID>
auth=YOUR-DID
outbound_auth=YOUR-DID
aors=YOUR-DID
trust_id_outbound=yes
t38_udptl=yes
t38_udptl_maxdatagram=400
t38_udptl_ec=redundancy
t38_udptl_nat=yes

 

Be sure to define a transport, and replace YOUR-TRANSPORT with the definition you defined in pjsip.conf. Make sure to replace YOUR-DID with your T38fax.com DID, and replace DEFINE-A-PASSWORD with a secure & unique password for your ATA to use when  registering. This does not (and likely should not) be the same as your  SIP Trunk's password that you added in section B.


4. Modify/Create your extensions.conf file (/etc/asterisk/extensions.conf):

  • Make sure you have a "exten => s" in your [default] context.  This allows for proper replies to T38fax.com SIP monitoring.
[default]
; This ensures we reply 200 OK to OPTIONS messages.
exten => s,1,NoOp( got in default/S )

 

  • Create your [Power-T.38-in] context:
exten => s,1,Noop(Fixing DID using information from SIP TO header)
exten => s,n,Set(pseudodid=${PJSIP_HEADER(read,To)})
exten => s,n,Set(pseudodid=${CUT(pseudodid,@,1)})
exten => s,n,Set(pseudodid=${CUT(pseudodid,:,2)})
exten => s,n,Goto(${pseudodid},1)

exten => YOUR-PRIMARY-DID,1,Dial(PJSIP/YOUR-PRIMARY-DID)
;If you have multiple DID's on the same account, create additional definitions for them in the Devices section of your pjsip.conf, and add additional lines here, for example:
exten => YOUR-SECOND-DID,1,Dial(PJSIP/YOUR-SECOND-DID)

 

Make sure to replace YOUR_DID with your T38fax.com DID.


  • Create your [Power-T.38-out] context:
[Power-T.38-out]
; Add support for 11 digit dialing (adds the leading 1).
exten => _1NXXNXXXXXX!,1,NoOp(caught 11 digits ${EXTEN})
exten => _1NXXNXXXXXX!,n,Dial(PSIP/${EXTEN}@t38fax_endpoint)

 

5. Add the following to your udptl.conf file (/etc/asterisk/udptl.conf):

udptlstart=10000
udptlend=10999
T38FaxUdpEC=t38UDPRedundancy

 

6. Configure your ATA to connect to Asterisk.


You should now be  able to register your ATA to Asterisk, and to make and receive fax  calls using T.38! If you have any trouble, please open a ticket and one  of our Technical Support Engineers will assist you in getting set up.


T.38 Termination Support:


Coming Soon!


Asterisk 12 (Standard)


In Asterisk 12, a new SIP channel driver (chan_pjsip) was introduced.


Asterisk 11 (LTS)


This version supports both T.38 passthrough and T.38 Termination.


T.38 Passthrough Support:

To integrate T38Fax.com with Asterisk to connect a fax machine to a T-38  capable ATA.  This will allow a fax machine to send and receive calls  via T38Fax.com with Asterisk in the middle.

1. Sign up for a free trial at https://www.t38fax.com/signup

2. Check astmoddir (/usr/lib/asterisk/modules) for two standard modules: chan_sip.so and res_rtp_asterisk.so.



If you do not have both modules, you must reconfigure/recompile asterisk.  Here are the commands:
cd /usr/local/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
tar xvfz asterisk-11-current.tar.gz
cd asterisk-11.*
./configure
make menuselect
# Ensure that the following modules are enabled [*]
# Channel Drivers/chan_sip
# Resource Modules/res_rtp_asterisk
make install

 

3. Modify your sip.conf file (/etc/asterisk/sip.conf):

  • Add the following to the [general] section of your sip.conf file:
directmedia=no
t38pt_udptl=yes,redundancy
register=YOUR_DID:YOUR_PWORD@sip.t38fax.com~600

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a T38fax user definition to the bottom of your sip.conf file as follows:
[t38fax]
type=peer
context=Power-T.38-in
qualify=no
defaultexpiry=600
insecure=port,invite
host=sip.t38fax.com
realm=sip.t38fax.com
defaultuser=YOUR_DID
secret=YOUR_PWORD

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a user definition for your ATA to register as. Add this after the [t38fax] definition in your sip.conf file:
[YOUR_DID]
type=friend
context=Power-T.38-out
qualify=yes
qualifyfreq=600
host=dynamic
defaultexpiry=600
defaultuser=YOUR_DID
callerid="John Doe" <YOUR_DID>
secret=YOUR_ATA_PWORD

 

Make sure to replace YOUR_ATA_PWORD with a password for your ATA to register to your Asterisk server, and replace YOUR_DID with your T38fax.com DID. Depending on your deployment & network topology, you may need to add nat=yes to both of the definitions above. Ask your network administrator if you are using NAT Traversal.


  • Add the following to your udptl.conf file (/etc/asterisk/udptl.conf):
udptlstart=10000
udptlend=10999
T38FaxUdpEC=t38UDPRedundancy

 

4. Modify/Create your extensions.conf file (/etc/asterisk/extensions.conf):

  • Make sure you have a "exten => s" in your [default] context.  This allows for proper replies to T38fax.com SIP monitoring.
[default]
; This ensures we reply 200 OK to OPTIONS messages.
exten => s,1,NoOp( got in default/S )

 

  • Create your [Power-T.38-in] context:
[Power-T.38-in]
; The following detects the dialed number.
exten => s,1,Set(DNID=${SIP_HEADER(To)})
exten => s,n,Set(DNID=${CUT(DNID,@,1)})
exten => s,n,Set(DNID=${CUT(DNID,:,2)})
exten => s,n,Goto(${DNID},1)
; The following sends the incoming call to the SIP user.
exten => YOUR_DID,1,Dial(SIP/YOUR_DID)
; If you have more than one DID, you can add additional definitions to route them as well:
exten => YOUR_SECOND_DID,1,Dial(SIP/YOUR_SECOND_DID)

 

Make sure to replace YOUR_DID with your T38fax.com DID.


  • Create your [Power-T.38-out] context:
[Power-T.38-out]
; Add support for 11 digit dialing (adds the leading 1).
exten => _1NXXNXXXXXX!,1,NoOp(caught 11 digits ${EXTEN})
exten => _1NXXNXXXXXX!,n,Dial(SIP/${EXTEN}@t38fax)

 

5. Configure your ATA to connect to Asterisk:


As an Example, to configure a Cisco SPA-112:


  1. Follow the steps at: <SPAARTICLE>
  2. Navigate to "Voice -> Line 1".
  3. Enter your Asterisk Server's address/hostname in the "Proxy" field.
  4. Enter the context you created in Step 2 in the "Display Name" and "User ID" fields. (Likely your T38Fax.com DID if you followed this guide).
  5. Enter the password for the context you created in Step 3 in the "Password" Field.
  6. Click Submit, and the SPA112 should reload it's configuration.
  7. In the Asterisk CLI (asterisk -r) you should now be able to see the device register. Enter: sip show peer YOUR_DID (You'll want to look for "Status: OK" and "Addr -> IP" to show an IP address. Remember to replace YOUR_DID with your T38Fax.com DID!)


T.38 Termination Support:


To integrate T38fax.com with Asterisk so that Asterisk itself is able  to receive and send faxes directly, follow the steps below.


1. Sign up for a free trial at https://www.t38fax.com/signup

2. Prepare your system to handle FAX/TIFF messages.


Install Perl and other basic utilities:

CentOS 7.x/6.x:

yum -y install perl cpan libyaml perl-YAML perl-Time-HiRes libwww-perl

 

Install tools to handle TIFF files:

CentOS 7.x:

yum -y install libtiff-tools

 


CentOS 6.x:

yum -y install libtiff


3. Install support tools for mime-construct:
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Proc::WaitStat"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install MIME::Types"

 

4. Install mime-construct utility for e-mailing processed fax images:

cd /usr/local/src
wget http://search.cpan.org/CPAN/authors/id/R/RO/ROSCH/mime-construct-1.11.tar.gz
tar xvfz mime-construct-1.11.tar.gz
cd mime-construct-1.11
perl Makefile.PL
make install

 

5. Install spandsp:

cd /usr/local/src
wget http://www.soft-switch.org/downloads/spandsp/spandsp-0.0.6.tar.gz
tar xvfz spandsp-0.0.6.tar.gz
cd spandsp-0.0.6
./configure --prefix=/usr
make
make install

 

6. Check astmoddir (/usr/lib/asterisk/modules) for four modules: chan_sip.so, res_rtp_asterisk.so, res_fax.so, res_fax_spandsp.so


If you do not have all four of those modules, you must reconfigure/recompile asterisk. Here are the commands:

cd /usr/local/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz
tar xvfz asterisk-11-current.tar.gz
cd asterisk-11.*
./configure
make menuselect
# ensure the following four modules are enabled [*]
# Channel Drivers/chan_sip
# Resource Modules/res_rtp_asterisk
# Resource Modules/res_fax
# Resource Modules/res_fax_spandsp
make install

 

7. Modify your sip.conf file (/etc/asterisk/sip.conf):

  • Add the following to the [general] section of your sip.conf file:
t38pt_udptl=yes,redundancy
register=YOUR_DID:YOUR_PWORD@sip.t38fax.com~600

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a T38fax user definition to the bottom of your sip.conf file as follows:
[t38fax]
type=peer
context=Power-T.38-in
qualify=no
defaultexpiry=600
insecure=port,invite
host=sip.t38fax.com
realm=sip.t38fax.com
defaultuser=YOUR_DID
secret=YOUR_PWORD

 

 Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


8. Modify/Create your extensions.conf file (/etc/asterisk/extensions.conf):

  • Add the following to the [globals] section:
VSA=/var/spool/asterisk
FAXRCPT=YOUR_ADDR@EXAMPLE.COM

 

  • Make sure you have a “exten => s” in your [default] context.  This allows for proper replies to T38fax.com SIP monitoring.
[default]
; This ensures we reply 200 OK to OPTIONS messages.
exten => s,1,NoOp( got in default/S )

 

  • Create your [Power-T.38-in] context:
[Power-T.38-in]
; The following detects the dialed number.
exten => s,1,Set(DNID=${SIP_HEADER(To)})
exten => s,n,Set(DNID=${CUT(DNID,@,1)})
exten => s,n,Set(DNID=${CUT(DNID,:,2)})
; The following sends the call to the fax context.
exten => s,n,Goto(fax,rx,1)

 

  • Create the [fax] context to send/receive faxes:
[fax]
; This is so Asterisk handles the fax as a t38 client.
exten => rx,1,NoOp( ** RECEIVING FAX ** )
exten => rx,n,Answer
exten => rx,n,StopPlaytones
exten => rx,n,Set(FAXFILEBASE=${VSA}/fax/${CALLERID(num)}-${EPOCH})
exten => rx,n,Set(FAXFILE=${FAXFILEBASE}.tif)
exten => rx,n,Wait(1)
exten => rx,n,ReceiveFAX(${FAXFILE})

exten => tx,1,NoOp( ** SENDING FAX ** )
exten => tx,n,Wait(6)
exten => tx,n,Set(FAXOPT(localstationid)=YOUR_DID)
exten => tx,n,SendFAX(${VSA}/fax/channel-001.tiff,dfz)

exten => h,1,Noop(FAX ${FAXOPT(status)} from ${CALLERID(all)}: ${FAXOPT(error)})
exten => h,n,System(/usr/local/script/fax2mail -p --cid-name ${CALLERID(name)} --cid-number ${CALLERID(num)} --dest-exten ${DNID} --dest-email ${FAXRCPT} -f ${FAXFILEBASE})
exten => h,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => h,n,NoOp(FAXOPT(filename) : ${FAXOPT(filename)})
exten => h,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
exten => h,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
exten => h,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
exten => h,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
exten => h,n,NoOp(FAXOPT(pages) : ${FAXOPT(pages)})
exten => h,n,NoOp(FAXOPT(rate) : ${FAXOPT(rate)})
exten => h,n,NoOp(FAXOPT(remotestationid) : ${FAXOPT(remotestationid)})
exten => h,n,NoOp(FAXOPT(resolution) : ${FAXOPT(resolution)})
exten => h,n,NoOp(FAXOPT(status) : ${FAXOPT(status)})
exten => h,n,NoOp(FAXOPT(statusstr) : ${FAXOPT(statusstr)})
exten => h,n,NoOp(FAXOPT(error) : ${FAXOPT(error)})

exten => _[it],1,Hangup()

 

Make sure to replace YOUR_DID with your T38Fax.com DID.


9. Install fax2mail script to convert the raw fax image into a PDF file and email it:

mkdir -p /usr/local/script
cd /usr/local/script
wget -O fax2mail 'http://www.generationd.com/Include/PHP/FileDownload.php?type=filelist&name=F73C063A7F0C11E0B6B66E984824019B'
chmod ugo+x fax2mail

cd /usr/local/src

cat <<__EOPATCH__ > fax2mail.patch
--- fax2mail 2015-04-21 18:59:47.336779832 +0000
+++ /usr/local/script/fax2mail 2015-04-21 15:55:36.084776251 +0000
@@ -94,2 +94,4 @@
 
+PATH=/usr/local/script:/usr/local/bin:/usr/bin:/bin:$PATH
+
 VERSION="fax2mail v2.3"
@@ -97,4 +99,4 @@
 DATETIME=$(date +"%A, %B %d %Y, at %I:%M %p")
-FROMEMAIL="Asterisk PBX <asterisk@spinen.com>"
-DEFAULTTO="info@spinen.com"
+FROMEMAIL="Asterisk PBX <YOUR_EMAIL@EXAMPLE.COM>"
+DEFAULTTO=""
 
@@ -168,3 +170,3 @@
 echo "Error: A file is required"
- echo " No file was given.">>>>$LOGFILE
+ echo " No file was given." >>$LOGFILE
 exit 1;
@@ -219,3 +221,3 @@
 # Read data from TIFF file
- PAGES=$(tiffinfo $SOURCEFILE | grep "Page" | cut -d " " -f 1)
+ PAGES=$(tiffinfo $SOURCEFILE | grep "Page" | cut -d " " -f 5)
 DT=$(tiffinfo $SOURCEFILE | grep "Date")
__EOPATCH__

patch /usr/local/script/fax2mail < fax2mail.patch

 

10. Make the fax directory:

mkdir /var/spool/asterisk/fax

 

NOTE: tiff (original source) files will accumulate in /var/spool/asterisk/fax Use cron or any other desired method to periodically remove these files.



Asterisk 10 (Standard)


This was the first release that included T.38 Fax Gateway Support.


https://wiki.asterisk.org/wiki/display/AST/T.38+Fax+Gateway



Asterisk 1.8


T.38 Passthrough Support:


To integrate T38Fax.com with Asterisk to connect a fax machine to a  T.38 capable ATA.  This will allow a fax machine to send and receive  calls via T38Fax.com with Asterisk in the middle.


1. Sign up for a free trial at https://www.t38fax.com/signup

2. Check astmoddir (/usr/lib/asterisk/modules) for two standard modules: chan_sip.so and res_rtp_asterisk.so.


If you do not have both modules, you must reconfigure/recompile asterisk.  Here are the commands:

cd /usr/local/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8-current.tar.gz
tar xvfz asterisk-1.8-current.tar.gz
cd asterisk-1.8.*
./configure
make menuselect
# Ensure that the following two modules are enabled [*]
# Channel Drivers/chan_sip
# Resource Modules/res_rtp_asterisk
make install

 

3. Modify your sip.conf file (/etc/asterisk/sip.conf):

  • Add the following to the [general] section of your sip.conf file:
directmedia=no
t38pt_udptl=yes,redundancy
register=YOUR_DID:YOUR_PWORD@sip.t38fax.com~600

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a T38fax user definition to the bottom of your sip.conf file as follows:
[t38fax]
type=peer
context=Power-T.38-in
qualify=no
defaultexpiry=600
insecure=port,invite
host=sip.t38fax.com
realm=sip.t38fax.com
defaultuser=YOUR_DID
secret=YOUR_PWORD

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a user definition for your ATA to register as. Add this after the [t38fax] definition in your sip.conf file:
[YOUR_DID]
type=friend
context=Power-T.38-out
qualify=yes
qualifyfreq=600
host=dynamic
defaultexpiry=600
defaultuser=YOUR_DID
callerid="John Doe" <YOUR_DID>
secret=YOUR_ATA_PWORD

 

Make sure to replace YOUR_ATA_PWORD with a password for your ATA to register to your Asterisk server, and replace YOUR_DID with your T38fax.com DID. Depending on your deployment & network topology, you may need to add nat=yes to both of the definitions above. Ask your network administrator if you are using NAT Traversal.


  • Add the following to your udptl.conf file (/etc/asterisk/udptl.conf):
udptlstart=10000
udptlend=10999
T38FaxUdpEC=t38UDPRedundancy

 

4. Modify/Create your extensions.conf file (/etc/asterisk/extensions.conf):

  • Make sure you have a "exten => s" in your [default] context.  This allows for proper replies to T38fax.com SIP monitoring.
[default]
; This ensures we reply 200 OK to OPTIONS messages.
exten => s,1,NoOp( got in default/S )

 

  • Create your [Power-T.38-in] context:
[Power-T.38-in]
; The following detects the dialed number.
exten => s,1,Set(DNID=${SIP_HEADER(To)})
exten => s,n,Set(DNID=${CUT(DNID,@,1)})
exten => s,n,Set(DNID=${CUT(DNID,:,2)})
exten => s,n,Goto(${DNID},1)
; The following sends the incoming call to the SIP user. Duplicate this line for as many DIDs that you wish to configure.
exten => YOUR_DID,1,Dial(SIP/YOUR_DID)
; If you have more than one DID, you can add additional definitions to route them as well:
exten => YOUR_SECOND_DID,1,Dial(SIP/YOUR_SECOND_DID)

 

Make sure to replace YOUR_DID with your T38fax.com DID.


  • Create your [Power-T.38-out] context:
[Power-T.38-out]
; Add support for 11 digit dialing (adds the leading 1).
exten => _1NXXNXXXXXX!,1,NoOp(caught 11 digits ${EXTEN})
exten => _1NXXNXXXXXX!,n,Dial(SIP/${EXTEN}@t38fax)

 

5. Configure your ATA to connect to Asterisk:


As an Example, to configure a Cisco SPA-112:


  1. Follow the steps at: <SPAARTICLE>
  2. Navigate to "Voice -> Line 1".
  3. Enter your Asterisk Server's address/hostname in the "Proxy" field.
  4. Enter the context you created in Step 2 in the "Display Name" and "User ID" fields. (Likely your T38Fax.com DID if you followed this guide).
  5. Enter the password for the context you created in Step 3 in the "Password" Field.
  6. Click Submit, and the SPA112 should reload it's configuration.
  7. In the Asterisk CLI (asterisk -r) you should now be able to see the device register. Enter: sip show peer YOUR_DID (You'll want to look for "Status: OK" and "Addr -> IP" to show an IP address. Remember to replace YOUR_DID with your T38Fax.com DID!)


T.38 Termination Support:


To integrate T38fax.com with Asterisk so that Asterisk itself is able  to receive and send faxes directly, follow the steps below.


1. Sign up for a free trial at https://www.t38fax.com/signup

2. Prepare your system to handle FAX/TIFF messages.


Install Perl and other basic utilities:

CentOS 7.x/6.x:

yum -y install perl cpan libyaml perl-YAML perl-Time-HiRes libwww-perl

 

Install tools to handle TIFF files:

CentOS 7.x:

yum -y install libtiff-tools


CentOS 6.x:

yum -y install libtiff

 


3. Install support tools for mime-construct:
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Proc::WaitStat"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install MIME::Types"

 

 

4. Install mime-construct utility for e-mailing processed fax images:

cd /usr/local/src
wget http://search.cpan.org/CPAN/authors/id/R/RO/ROSCH/mime-construct-1.11.tar.gz
tar xvfz mime-construct-1.11.tar.gz
cd mime-construct-1.11
perl Makefile.PL
make install

 

 

5. Install spandsp:

cd /usr/local/src
wget http://www.soft-switch.org/downloads/spandsp/spandsp-0.0.6.tar.gz
tar xvfz spandsp-0.0.6.tar.gz
cd spandsp-0.0.6
./configure --prefix=/usr
make
make install

 

 

6. Check astmoddir (/usr/lib/asterisk/modules) for four modules: chan_sip.so, res_rtp_asterisk.so, res_fax.so, res_fax_spandsp.so


If you do not have all four of those modules, you must reconfigure/recompile asterisk. Here are the commands:

cd /usr/local/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8-current.tar.gz
tar xvfz asterisk-1.8-current.tar.gz
cd asterisk-1.8.*
./configure
make menuselect
# Ensure the following four modules are enabled [*]
# Channel Drivers/chan_sip
# Resource Modules/res_rtp_asterisk
# Resource Modules/res_fax
# Resource Modules/res_fax_spandsp
make install

 

7. Modify your sip.conf file (/etc/asterisk/sip.conf):

  • Add the following to the [general] section of your sip.conf file:
t38pt_udptl=yes,redundancy
register=YOUR_DID:YOUR_PWORD@sip.t38fax.com~600


Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


  • Add a T38fax user definition to the bottom of your sip.conf file as follows:
[t38fax]
type=peer
context=Power-T.38-in
qualify=no
insecure=port,invite
defaultexpiry=600
host=sip.t38fax.com
realm=sip.t38fax.com
defaultuser=YOUR_DID
secret=YOUR_PWORD

 

Make sure to replace YOUR_DID with your T38fax.com DID, and replace YOUR_PWORD with the provided password for your account.


8. Modify/Create your extensions.conf file (/etc/asterisk/extensions.conf):

  • Add the following to the [globals] section:
VSA=/var/spool/asterisk
FAXRCPT=YOUR_ADDR@EXAMPLE.COM

 

  • Make sure you have a “exten => s” in your [default] context.  This allows for proper replies to T38fax.com SIP monitoring.
[default]
; This ensures we reply 200 OK to OPTIONS messages.
exten => s,1,NoOp( got in default/S )

 

  • Create your [Power-T.38-in] context:
[Power-T.38-in]
; The following detects the dialed number.
exten => s,1,Set(DNID=${SIP_HEADER(To)})
exten => s,n,Set(DNID=${CUT(DNID,@,1)})
exten => s,n,Set(DNID=${CUT(DNID,:,2)})
; The following sends the call to the fax context.
exten => s,n,Goto(fax,rx,1)

 

  • Create the [fax] context to send/receive faxes:
[fax]
; this is for asterisk handling a fax as a t38 client.
exten => rx,1,NoOp( ** RECEIVING FAX ** )
exten => rx,n,Answer
exten => rx,n,StopPlaytones
exten => rx,n,Set(FAXFILEBASE=${VSA}/fax/${CALLERID(num)}-${EPOCH})
exten => rx,n,Set(FAXFILE=${FAXFILEBASE}.tif)
exten => rx,n,Wait(1)
exten => rx,n,ReceiveFAX(${FAXFILE})

exten => tx,1,NoOp( ** SENDING FAX ** )
exten => tx,n,Wait(6)
exten => tx,n,Set(FAXOPT(localstationid)=YOUR_DID)
exten => tx,n,SendFAX(${VSA}/fax/channel-001.tiff,dfz)

exten => h,1,Noop(FAX ${FAXOPT(status)} from ${CALLERID(all)}: ${FAXOPT(error)})
exten => h,n,System(/usr/local/script/fax2mail -p --cid-name ${CALLERID(name)} --cid-number ${CALLERID(num)} --dest-exten ${DNID} --dest-email ${FAXRCPT} -f ${FAXFILEBASE})
exten => h,n,NoOp(FAXOPT(ecm) : ${FAXOPT(ecm)})
exten => h,n,NoOp(FAXOPT(filename) : ${FAXOPT(filename)})
exten => h,n,NoOp(FAXOPT(headerinfo) : ${FAXOPT(headerinfo)})
exten => h,n,NoOp(FAXOPT(localstationid) : ${FAXOPT(localstationid)})
exten => h,n,NoOp(FAXOPT(maxrate) : ${FAXOPT(maxrate)})
exten => h,n,NoOp(FAXOPT(minrate) : ${FAXOPT(minrate)})
exten => h,n,NoOp(FAXOPT(pages) : ${FAXOPT(pages)})
exten => h,n,NoOp(FAXOPT(rate) : ${FAXOPT(rate)})
exten => h,n,NoOp(FAXOPT(remotestationid) : ${FAXOPT(remotestationid)})
exten => h,n,NoOp(FAXOPT(resolution) : ${FAXOPT(resolution)})
exten => h,n,NoOp(FAXOPT(status) : ${FAXOPT(status)})
exten => h,n,NoOp(FAXOPT(statusstr) : ${FAXOPT(statusstr)})
exten => h,n,NoOp(FAXOPT(error) : ${FAXOPT(error)})

exten => _[it],1,Hangup()

 

Make sure to replace YOUR_DID with your T38fax.com DID.


9. Install fax2mail script to convert the raw fax image into a PDF file and email it:

mkdir -p /usr/local/script
cd /usr/local/script
wget -O fax2mail 'http://www.generationd.com/Include/PHP/FileDownload.php?type=filelist&name=F73C063A7F0C11E0B6B66E984824019B'
chmod ugo+x fax2mail

cd /usr/local/src

cat <<__EOPATCH__ > fax2mail.patch
--- fax2mail 2015-04-21 18:59:47.336779832 +0000
+++ /usr/local/script/fax2mail 2015-04-21 15:55:36.084776251 +0000
@@ -94,2 +94,4 @@
 
+PATH=/usr/local/script:/usr/local/bin:/usr/bin:/bin:$PATH
+
 VERSION="fax2mail v2.3"
@@ -97,4 +99,4 @@
 DATETIME=$(date +"%A, %B %d %Y, at %I:%M %p")
-FROMEMAIL="Asterisk PBX <asterisk@spinen.com>"
-DEFAULTTO="info@spinen.com"
+FROMEMAIL="Asterisk PBX <YOUR_EMAIL@EXAMPLE.COM>"
+DEFAULTTO=""
 
@@ -168,3 +170,3 @@
 echo "Error: A file is required"
- echo " No file was given.">>>>$LOGFILE
+ echo " No file was given." >>$LOGFILE
 exit 1;
@@ -219,3 +221,3 @@
 # Read data from TIFF file
- PAGES=$(tiffinfo $SOURCEFILE | grep "Page" | cut -d " " -f 1)
+ PAGES=$(tiffinfo $SOURCEFILE | grep "Page" | cut -d " " -f 5)
 DT=$(tiffinfo $SOURCEFILE | grep "Date")
__EOPATCH__

patch /usr/local/script/fax2mail < fax2mail.patch

 

10. Make the fax directory:

mkdir /var/spool/asterisk/fax

 

NOTE: tiff (original source) files will accumulate in /var/spool/asterisk/fax Use cron or any other desired method to periodically remove these files.




Asterisk 1.6


T.38 Passthrough & T.38 Termination (receives faxes via ReceiveFax)



Asterisk 1.4


T.38 Passthrough Only. T.38 Passthrough allows Asterisk to carry T.38 UDPTL from one T.38-speaking endpoint to another T.38-speaking endpoint. Asterisk does not modify the media.



Asterisk 1.2


No T.38 capability at all.