Connecting your phone line to Asterisk (Setting up a PBX in your house part 3)

From the previous post, we know that in order to connect your phone line to Asterisk we need FXO ports installed. So, in this post we need to configure our FXO ports (let’s assume that we have only one FXO port here). And then, I will show you a basic dialplan for your home phone. But before that, we need to have something to receive or place a call, right? The best and easiest option is an IP phone or a softphone. I am going for the softphone option here and my choice of a free softphone would be xlite.

Configuring Xlite and Asterisk

First you need to register the Xlite account in Asterisk. The file that you need to configure is /etc/asterisk/sip.conf. Put the following lines to your sip.conf:

[SoftPhone1]
type=friend
host=192.168.0.109
username=SoftPhone1
secret = mypassword
context= OutgoingCall
callerid=SoftPhone1 <1234>

Then you can run xlite and go to menu–>system setting–>SIP proxy–>Default

Things you need to change are enabled (set to yes), display name and username (set to SoftPhone1), domain/realm and SIP proxy (set to Asterisk IP address).

Note that you can set display name and username to whatever name you want AS LONG AS they match the name in your sip.conf.

Note that this softphone, after this tutorial, will be able to receive/place a call.

Configuring FXO ports

The module that supports hardware interface for Asterisk is Zaptel, so we need to configure our zaptel.conf. zaptel.conf is located usually in /etc/zaptel.conf.

One thing merits an explanation: FXO port is using FXS signalling and vice versa.

Put the following in your /etc/zaptel.conf:

fxsks=4
defaultzone=us
loadzone=us

The above configuration tells us that the FXO port is installed in channel 4 in our card, and we’re using the “us” (United States) for loadzone. loadzone will load a ringing tone, busy tone, etc of a specific country. If no loadzone is specified, then the defaultzone is used.

Wait a minute! How can I know in what channel my FXO port is installed.

The picture above has 4 modules installed (2 FXO and 2 FXS). FXO is in red and FXS is in green. We can also see that FXO (red) modules are in channel 1 and 2 while FXS (green) modules are in channel 3 and 4. So you should look at your TDM card, see in which channel it is installed and configure your zaptel.conf accordingly.

Now, save your zaptel.conf.

Go to /usr/src/zaptel-version-number and issue make config.

Then, loadup zaptel by issuing: modprobe zaptel.

Then loadup the FXO module by issuing: modprobe wctdm.

Verify that both modules are loaded: lsmod | grep zaptel and lsmod | grep wctdm. You will see something similar to the following:

lsmod | grep zaptel
zaptel 185988 1 wctdm
crc_ccitt 5953 1 zaptel
[root@defender zaptel-1.4.10.1]# lsmod | grep wctdm
wctdm 37580 0
zaptel 185988 1 wctdm
[root@defender zaptel-1.4.10.1]#

You will see a green light on the FXO port. If not, restart your computer and everything should be OK and you can put your phone line in the FXO port.

Now, we need to setup basic functions for our FXO port, things such as caller id, echo cancellations, etc. Note though, zaptel is a module for hardware interface but it does not mean Asterisk knows everything about zaptel. They both are independent of each other. We need to link zaptel and Asterisk by configuring /etc/asterisk/zapata.conf.

Put the following to your zapata.conf:

;for channel4

language=en
context=IncomingCall
signalling=fxs_ls
usecallerid=yes
hidecallerid=no
callwaiting=yes
usecallingpres=yes
callwaitingcallerid=yes
threewaycalling=yes
transfer=yes
callreturn=yes
echocancel=yes
immediate=no
group=4
channel=>4

What are these keywords? Here is the answer.

The only keyword that I would like to highlight and we’re going to use it in the next section is context. context is your dial-plan. And we set it to IncomingCall. It is the plan when you receive or place a phone. You want to put a voice mail? It is inside the dialplan. You want to forward your call? it is inside the dialplan. You want to restrict the use of your phone to local phone only and block for any inter-local or international call? It is inside the dialplan.

That’s basically it about configuring your FXO port. And now we’re going to configure our dialplan.

Configuring the dialplan

The dialplan is located in /usr/asterisk/extensions.conf. We will create two dialplans. First is OutgoingCall (look at the configuring SIP and Asterisk, you will see context = OutgoingCall) and IncomingCall.

Copy this to your extensions.conf:

[OutgoingCall]

exten => _NXXNXXXXXX,1,Dial(Zap/g4/${EXTEN})
exten => _NXXNXXXXXX,2,Congestion
exten => 911,1,Dial(Zap/g4/911)
exten => 911,2,Congestion

[IncomingCall]

exten => s,1,Dial(SIP/SoftPhone1)

Save it. And issue reload from the Asterisk CLI. For more detail about what each word in extensions.conf means, then please download:http://www.digium.com/asterisk_handbook/extensions.conf.pdf

Now, look at your sip.conf. It says there context = OutgoingCall. And look at IncomingCall. For example,

exten => _NXXNXXXXXX,1,Dial(Zap/g4/${EXTEN})

exten => _NXXNXXXXXX,2,Congestion

This says when you place a call with 10 digit number, Asterisk will route your call to the Zapata group 4 (look at zapata.conf, and find group 4) which is the phone line connected to the FXO port. But if the phone line is busy, then you will here a congestion tone on your phone.

The IncomingChannel basically says that Asterisk will route the call to SoftPhone1.

One Basic Hacking Example

Alright, so far, we haven’t seen Asterisk power so I am going to show you one! You’re getting tired to pick up the phone, but the person who is calling wants to speak with your wife. So you say to your wife to install a softphone in her laptop. She registers the softphone in Asterisk with SoftPhone2 account.

Then you change the IncomingLine in extensions.conf with the following:

[IncomingCall]

exten => s,1,Playback(if-u-know-ext-dial)
exten => 11,1,Dial(SIP/SoftPhone1)
exten => 22,1,Dial(SIP/SoftPhone2)

Then you issue reload from Asterisk CLI. Could you guess what happens when someone calls your phone line? Yes, he/she will receive an answer machine asking, “If you know the extension of the party you want to call, press it now”. If the person presses 11, then SoftPhone1 will ring. If the person presses 22, your wife’s softphone will ring.

Very neat!

Alright, until the next Asterisk hacks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s