Freeswitch Howto: Configuration

In this section I’m going to focus exclusively on calling in and out over the POTS lines.  I’m doing this for two reasons.  One, this was the part I had the most trouble with, and two, the other dialplan options are (or seem to me to be) better documented.  I would suggest buying the Freeswitch book.  It’s been very helpful to me, though some if the information is outdated.

When setting up in-bound and out-bound analog calling (using the freetdm mod which was enabled on install) we deal with these files(these are all in the default install locations, if you installed some where else you’ll have to adjust accordingly):

/usr/local/freeswitch/conf/freetdm.conf
/usr/local/freeswitch/conf/autoload_configs/freetdm.conf.xml
/usr/local/freeswitch/conf/dialplan/default.xml
/usr/local/freeswitch/conf/dialplan/public/00_inbound_did.xml

I’ll post these, and go through the ones I know.

/usr/local/freeswitch/conf/freetdm.conf

[span wanpipe FXS]
name => freetdm
trunk_type => fxs
group => grp1
fxs-channel => 1:7

trunk_type => fxs
group => grp1
fxs-channel => 1:8

[span wanpipe FXO]

name => freetdm
trunk_type => fxo
group => grp2
fxo-channel => 1:1

trunk_type => fxo
group => grp2
fxo-channel => 1:2

trunk_type => fxo
group => grp2
fxo-channel => 1:3

trunk_type => fxo
group => grp2
fxo-channel => 1:4

trunk_type => fxo
group => grp2
fxo-channel => 1:5

trunk_type => fxo
group => grp2
fxo-channel => 1:6

Now to be honest I didn’t actually configure this file, or freetdm.conf.xml.  When /usr/sbin/wancfg_fs was run it automatically set both of these files up.  I didn’t have to change either of them.

/usr/local/freeswitch/conf/autoload_configs/freetdm.conf.xml

<analog_spans>
<span name=”FXO”>
<!–<param name=”hold-music” value=”$${moh_uri}”/>–>
<param name=”dialplan” value=”XML”/>
<param name=”context” value=”public”/>
<!– regex to stop dialing when it matches –>
<!–<param name=”dial-regex” value=”5555″/>–>
<!– regex to stop dialing when it does not match –>
<!–<param name=”fail-dial-regex” value=”^5″/>–>
</span>

<span name=”FXS”>
<!–<param name=”hold-music” value=”$${moh_uri}”/>–>
<param name=”dialplan” value=”XML”/>
<param name=”context” value=”default”/>
<!– regex to stop dialing when it matches –>
<!–<param name=”dial-regex” value=”5555″/>–>
<!– regex to stop dialing when it does not match –>
<!–<param name=”fail-dial-regex” value=”^5″/>–>
</span>
</analog_spans>

 

Now we get to the good stuff.  I took this from my default dial plan.  It only shows one of our five lines, but it should be enough to get you headed in the right direction.

/usr/local/freeswitch/conf/dialplan/default.xml

<extension name=”Call out business hours(Staff)” continue=”true”>
<condition field=”ani” expression=”^(1014|1015)” break=”on-true”/>
<condition wday=”2-6″ hour=”9-18″/>
<!– The call out prefix is 7 –>
<condition field=”destination_number” expression=”^7(.+)$”>
<action application=”set” data=”hangup_after_bridge=true”/>
<action application=”set” data=”continue_on_fail=true”/>
<action application=”bridge” data=”freetdm/FXO/2/$1″/>
<action application=”bridge” data=”freetdm/FXO/3/$1″/>
<action application=”bridge” data=”freetdm/FXO/4/$1″/>
<action application=”bridge” data=”freetdm/FXO/5/$1″/>
<action application=”bridge” data=”freetdm/FXO/1/$1″/>
<action application=”playback” data=”phrase:oh_gee”/>
</condition>
</extension>

The break down:

<extension name=”Call out business hours(Staff)” continue=”true”>

This is simply the extension name. I have continue set to true. I didn’t think I needed it but it wouldn’t work without it.

 

<condition field=”ani” expression=”^(1014|1015)” break=”on-true”/>

I have two phones that I don’t want dialing out on this extension. If phones 1014 or 1015 are dialing the number they won’t go out through this extension.

 

<condition wday=”2-6″ hour=”9-18″/>

This extension only works Monday through Friday between nine in the morning and six at night.

 

<condition field=”destination_number” expression=”^7(.+)$”>

Our “call out” number is seven. If seven is dialed before the number it is an external call and will be run through this extension.

 

<action application=”set” data=”hangup_after_bridge=true”/>

I’m not sure why this is important but I needed it.

 

<action application=”set” data=”continue_on_fail=true”/>

If you remember we have five outgoing phone lines (POTS). If one of them is busy (it fails to connect) I want to try the next phone line.

 

<action application=”bridge” data=”freetdm/FXO/2/$1″/>

This is the good part. This actually does the calling. The “freetdm/FXO/2” references freetdm.conf.xml. Span FXO, line 2. The “$1” is the number the person is calling. If line 2 is busy it “continue_on_fail=true” so it tries the next one (and so on and so forth).

 

<action application=”playback” data=”phrase:oh_gee”/>

This last line is simply a message, I recorded. If all the phone lines are in use this message gets played and the call ends.

 

Incoming Calls

This was by far the hardest part for me. Thanks to Steve on the Freeswitch mailing list for explaining it to me.

First let me explain what I was trying to do. Like I said earlier, we have five POTS lines. I needed to direct incoming calls from each line individually to different phones (and or groups) on campus. Where the calls get directed depends on the time of day and the particular phone line in question (I hope that isn’t to confusing).

/usr/local/freeswitch/conf/dialplan/public/00_inbound_did.xml

<!– LINE1 328-6825–>
<!– during work hours will ring the “Administration” phones –>
<extension name=”Line 1(6825) work” continue=”true”>
<condition field=”source” expression=”mod_freetdm”/>
<condition wday=”2-6″ hour=”9-18″/>
<condition field=”${channel_name}” expression=”^(FreeTDM/2:1/)$”>
<action application=”set” data=”domain_name=$${domain}”/>
<action application=”set” data=”transfer_ringback=$${us-ring}”/>
<action application=”transfer” data=”2020 XML default”/>
</condition>
</extension>

<!– During off hours goes to everyone except Kitchen and Guests –>
<extension name=”Line 1(6825) not work” continue=”true”>
<condition field=”source” expression=”mod_freetdm”/>
<condition field=”${channel_name}” expression=”^(FreeTDM/2:1/)$”>
<action application=”set” data=”domain_name=$${domain}”/>
<action application=”set” data=”transfer_ringback=$${us-ring}”/>
<action application=”transfer” data=”2035 XML default”/>
</condition> </extension>
<!– LINE1 DONE–>

Again, line by line:

<extension name=”Line 1(6825) work” continue=”true”>

This is simply the extension name. I have continue set to true. I’m pretty sure I need it, and it works with it enabled.

 

<condition field=”source” expression=”mod_freetdm”/>

This tells Freeswitch the source of the inbound call (pretty self explanatory).

 

<condition wday=”2-6″ hour=”9-18″/>

This extension only works Monday through Friday between nine in the morning and six at night.

 

<condition field=”${channel_name}” expression=”^(FreeTDM/2:1/)$”>

This tests to see what line is calling from the “mod_freetdm” source. My FXO ports are in the second span of my freetdm.conf,  so “FreeTDM/2:1/” is span two line 1. This is the part I got from Steve, and I couldn’t find this information any where.

 

<action application=”set” data=”domain_name=$${domain}”/>

I have no idea what this does but I know I need it.

 

<action application=”set” data=”transfer_ringback=$${us-ring}”/>

I’m assuming this changes depending on the country you live in.

 

<action application=”transfer” data=”2020 XML default”/>

This transfers the incoming call to (in my case) group 2020 in the default dial plan. It can be replaced with any valid extension number.

The second extension (again this is just for one of our phone lines.  Each line will need an extension) is for off hours and weekends.

 

Faxing

We have an analog fax machine, which is why I needed the FXS modules on my Sagnoma card.  Here are the relevant dialplan parts I used to send and receive faxes.

 

Receiving a Fax

This gets set up in the public dialplan.  On our install /usr/local/freeswitch/dialplan/public/00_inbound_did.xml.

<!– LINE3 328-6982–>
<!– Always directed to the fax machine –>
<extension name=”Line 3(6982)” continue=”true”>
<condition field=”source” expression=”mod_freetdm”/>
<condition field=”${channel_name}” expression=”^(FreeTDM/2:3/)$”>
<action application=”set” data=”domain_name=$${domain}”/>
<action application=”set” data=”transfer_ringback=$${us-ring}”/>
<action application=”bridge” data=”freetdm/2/3|freetdm/1/1″/>
</condition>
</extension>
<!– LINE3 DONE–>

<action application=”bridge” data=”freetdm/2/3|freetdm/1/1″/>

This is the important one.  It takes the incoming call from span 2 line 3 and transfers it to span 1 line 1.

 

Sending a Fax

This gets set up in the default dialplan.  On our install /usr/local/freeswitch/conf/dialplan/default.xml.

<extension name=”bridge-FXS-to-FXO” continue=”true”>
<condition field=”destination_number” expression=”^7(.+)$”/>
<condition field=”channel_name” expression=”FreeTDM/1:1/”>
<action application=”bridge” data=”freetdm/1/1/${destination_number}|freetdm/2/3/${destination_number}”/>   </condition>
</extension>

<condition field=”channel_name” expression=”FreeTDM/1:1/”>
<action application=”bridge” data=”freetdm/1/1/${destination_number}|freetdm/2/3/${destination_number}”/>   </condition>

These are the two lines that work the magic.  I got this off the Freeswitch wiki.  Direct span 1 line 1 to span 2 line 3 and dial the number.  Presto the fax goes out.

Freeswitch Howto: Installation

I’m not going to cover the installation of CentOS 5.5, nor will I cover how to setup a software RAID.  There are plenty of other tutorials already done that explain those things.  Here is what I did, though, step by step to get Freeswitch and the wanpipe drivers installed on our system (I’m assuming a basic working knowledge of the Linux command line).

Note: All of the following commands should be run as root.

yum list updates

yum update

yum install unixODBC-devel gnutls-devel libtiff-devel autoconf automake awk* bison core-devel curl-devel expat-devel flex gcc* gettext-devel gnutls gnutls-devel kernel-devel-$(uname -r) libjpeg-devel libtiff libtiff-devel libtool libX11-devel libzrtpmake ncurses-devel openssl patch python-devel unixODBC-devel zlib zlib-devel

The above commands should install all the dependencies needed for git, the Sangoma drivers, and freeswitch.

Install Git

Make sure /usr/local/lib is in your ld.so.conf, this is required for git-http-push to correctly link up to the Curl version you are installing.

vi /etc/ld.so.conf

Insert the following:
/usr/local/lib

Save the file, then run:
ldconfig

Now download and install Git:
cd /usr/local/src
wget http://www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
tar xzvf git-latest.tar.gz
cd git-{date}
autoconf
./configure –with-curl=/usr/local
make
make install

Install Sangoma Drivers

cd /usr/local/src
wget ftp://ftp.sangoma.com/linux/current_wanpipe/wanpipe-latest.tgz
tar xfz wanpipe-latest.tgz
cd wanpipe-.tgz
make freetdm
make install

Install Freeswitch

cd /usr/local/src
git clone git://git.freeswitch.org/freeswitch.git
cd freeswitch
./bootstrap.sh

Edit modules.conf remove the “#” from the freetdm and flite modules:
vi /usr/local/src/freeswitch/modules.conf

When your done editing save and continue with the installation:
./configure
make
make install
make all cd-sounds-install cd-moh-install
The last command will download about 300Mb of sound files.  These are for the voice mail/IVR system and the music on hold.

Run this command to configure the Sangoma hardware. When I set this up I had to turn off hardware DTMF. When it was on using calling cards was almost impossible. Calling cards work just fine with the software DTMF.

/usr/sbin/wancfg_fs

This will start freeswitch. To start it as a daemon freeswitch -nc.
cd /usr/local/freeswitch/bin
./freeswitch

This will start the freeswitch command line when the command “fs_cli” is run.
ln -s /usr/local/freeswitch/bin/fs_cli /usr/local/bin/fs_cli

That’s it.  I would suggest starting Freeswitch with the -nc option, unless your having problems and need to trouble shoot.

Freeswitch Howto

As promised here is my Freeswitch howto.  A few things first.  The reason I’m doing this is to get more documentation out there.  I have to admit I have never been so disappointed with Google.  I had one heck of a time trying to find the information I needed, so I’m writing this in hopes that the next poor sap wont have such a hard time.  I offer no guarantees that any of this will work for you, nor do I guarantee that it wont completely destroy your system if you try it.  A lot of this information can be found on the Internet, some of it I got through the Freeswitch mailing list, the Freeswitch wiki, and the Sangoma wiki.  That being said here goes.

 

Background

I work at Beartooth Mountain Christian Ranch.  We run 10 weeks of camp in the summer, and a one year Bible college during the off season.  We have buildings spread across our campus, and wanted a phone system that worked in all of them.  Up until now we’ve had a system in the main office, but no way of transferring calls to the other buildings.  When our office phone system broke they told me to look into an actual campus wide PBX, and Freeswitch was what I came up with.  We’ve got five POTS lines that come into camp, 17 phones, one fax, and two soft phones to share them with.   We needed to be able to (obviously) send and receive phone calls and faxes, but we also wanted to be able to transfer phone calls and get every one a voice mail box.

 

The Hardware

Mother board: Asus M2N68-AM Plus

CPU: AMD Athlon X2 Black Edition 2.8GHz

RAM: 2Gb PC6400 Crucial

HDD: 2 500Gb WD in a software RAID 1 setup

Telephony Card: Sangoma A200 PCI-e with hardware echo cancelation – 1 Remora addon with 3 FXO modules, 1 FXS module, and a back pane connector.

Wired IP Phones: 15 Grandstream GXP280

Wireless IP Phones: 2 Cisco WIP310

The Software

I’m using CentOS as the operating system.  Freeswitch git version c7abfa7 (I downloaded it March 6, 2011).  Wanpipe driver version 3.5.18.

 

Installation

 

Configuration