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.