Asterisk 1.4 on OpenWrt Guide by PierreDavidOriol aussi disponible en français.

1. Introduction

Landline phone service being overly expensive, I've decided to try and set up a VOIP phone line at home, in order to substantially gain a better control

and reduce the monthly fees related to that service. In order to do so, there are a lot of solutions and available configurations, but each website about

that topic only contains a small bit of information, which makes the installation process a little complex to understand. To setup my solution, I have

decided to run my own Asterisk server only to pay a monthly fee in order to connect it to the VOIP providers' Asterisk server (The VOIP provider is then

connected to the standard telephone network, which allows me to place calls to normal landline phones, and to be provided with a standard phone number).

I've thus decided to write that small guide intended for the people who already have some computer science knowledge (I'll take into account that you

already have read a bit on Asterisk PBX, that you're able to enable/disable your network interface on your OS, that you aren't scared by having to type

commands into a GNU/Linux console and more than everything else, that you can use google). Here is the general diagram of the final VOIP setup we're going

to be talking about.

2. Hardware

In order to use a VOIP connection, you're free to install Asterisk on any networked platform which has an acces to the internet, let this be a GNU/Linux

installation on a conventionnal computer or a router onto which you've installed GNU/Linux, or even under Windows (I haven't read much about Asterisk

installations under Mac OS X, but I can imagine that it's quite possible to do it). I will personally be installing Asterisk PBX on a router onto which I'll previously have installed OpenWrt which is a GNU/Linux distribution specially made

for routers. I have chosen that type of setup more as a strategic move than anything else, first because I have no computer running 24/7, and secondly because if I had

electricity shortage, I could easily use an UPS so as to power my phone setup for a way longer period of time than a standard computer. OpenWrt doesn't run on every router with the same stability, and manufacturers aren't quite happy with the fact that you aren't going to use their standard

software, so they tend to reduce the available "disk" space in order to block you from hacking it too much. I'll thus be using a router which has a lot of RAM, a large enough "disk" space and some USB ports into which I could plug a flash drive if I ever lack

disk space. You can check out which hardware OpenWrt supports, and what are the specs of each router at that specific address:

As noted in the diagram I'll be using the ASUS WL-500G Premium which is used a lot out there for that specific type of configuration, due to its' large

memory size and its two USB 2.0 ports, which will allow me to way much more space than the initial 8MB (to store phone messages etc...). In order to connect my standard analog phones to the VOIP network, I'll be using an Analog Telephone Adapter (ATA) which I'll plug into the main router and

wich will allow me to send commands (phone numbers, etc.) to it. I've chosen the SPA-2102 model from Linksys (Sipura Rebranded), which has two standard

landline phone RJ11 connections (2 FXs). In the future, I'll be able to use IP phones directly connected to my wired/wireless network or even Softphones

installed on any machine connected to that network. Obviously, I will also be getting a physically small flash drive which I'll plug into the router to expand it's storage capacities. OpenWrt doesn't support

SD cards through USB card readers so the device needs to be a conventional USB key card in order to be able to "mount" it.

3. SPA2102 Upgrade

Once I've bought the hardware, I decided to update the ATA first. In order to do so, I've used a Windows XP computer as the only official way to update it

was to use a Win32 executable available on Cisco's website. To update the ATA, it was easier

for me to connect it in the "standard way" described in the user manual, which is: connecting my computer directly to the "Ethernet" port of the ATA, and

the DSL/Cable modem plugged into the "Internet" port of the ATA. That machine also being a router, it automatically gave me an IP using DHCP, and I was then able to use the executable upg-spa2102-5-1-12.exe to send the

new firmware version spa2102-5-1-12.bin.

That upgrade is also possible if you're using GNU/Linux, but it's a little more complicated, the SPA2102 needs to have web access, and you have to send the

.bin file onto a web server (you can do it locally too). Then, using the .bin web address: http://<HTTP_SERVER>/spa2102-5-1-12.bin, open the web

interface of the SPA2102, and go to the Voice->Provisioning section in order to set those two fields: Upgrade Enable: yes and Upgrade Rule:http://<HTTP_SERVER>/spa2102-5-1-12.bin

Then, save the configuration, and the SPA2102 will automatically update the firmware during the next hour (I don't think you can fully control "when" the

update will take place).

4. SPA2102 Basic Configuration

Once the firmware upgrade successfully made, do not unplug the ATA quite yet, take a bit of time to configure it. In order to connect yourself you need it's IP (it's your current DHCP server) and the full path of the welcome page, in oder to get an URL looking like

this http://192.168.XXX.XXX/admin/advanced

<!> The web interface of the SPA-2102 is quite crappy, and if you don't use the full URL (including /admin/advanced after the IP address), even if you've

got the right password, it will systematically deny you the access to the web interface.

While you're at it, there's a couple options you should change.

- Verify that you're in "admin" mode by checking at the top right-hand corner of the interface, and that you've chosen the "advanced" mode too.

- In the Routeur->Wan Setup page, check that you've got those settings correctly set:

This will allow you to access the web interface of the ATA from any computer on the same network in the future.

- In the Voice->System page (how convenient!) chose a new password in order to restrict the web interface access.

The rest of the plethore of options is a bit scary, you could always save screenshots of them so as not to get completely lost if you were to modify one by


5. Which OpenWrt version ?

I've decided to use the more stable Whiterussian 0.9 version of OpenWrt, but I think I could have used the Kamikaze version too, without any

major changes. In order to flash your router, you need to get the OpenWrt installation file (.trx) for the right router chipset. For the ASUS WL-500G

Premium, I needed the openwrt-brcm-2.4-squashfs.trx file, available on OpenWrts' website:

<!> WARNING, since I wrote this article, things have changed. Kamikaze is now the official OpenWrt stable version, Hans Zandbelt's repo for

Whiterussian's Asterisk installation has been taken down (since for him it was obsolete) and X-WRT has been updated in order to better work with Kamikaze

(config files now replace the NVRAM variables). I thus advise you to follow that guide, but replacing Whiterussian with Kamikaze

If you want to install the Kamikaze release instead, you should take the latest "stable" version for which you'll need the install file which is located at

that URL:

I know you can also use the installation firmware located at there :

in order to have an up-to-date kernel (2.6 instead of 2.4) but the available modules for that kernel aren't that good.

You could also use third-party provided modules and .trx installation firmwares, but we'll get to that later on.

All the following instructions are based on a Whiterussian 0.9 installation, but adapting them to the Kamikaze release is quite easy.

6. OpenWrt Installation

Installation of OpenWrt

Once the ATA is fully updated and configured, unplug it and plug the ASUS router instead, connecting your modem to the WAN port and your computer to the

LAN1 port of it.

Double-check that you're able to ping it and that you can access the web interface (re-activate your network interface/DHCP), the default address is and the default login/password is admin/admin. All the available methods to install OpenWrt on the router are listed on OpenWrts' website, on

the routers' page:

Unfortunately, it's not possible to update the router through the web interface for now. You'll have to use another method described on that page.

<!> I strongly advise you to follow the "Backup" step explained on that same page before doing anything, you'll need a USB flash drive for that (and you

might need it to be ext2 formatted).

In the "Installation" section, you'll note that if you're running Windows, you'd better install OpenWrt using the ASUS Firmware Restoration Utility which

is located on the CD-ROM of the router (installed automatically with all the other utilities on the CD-ROM). That's what I did, I checked first that the router was in "DIAG" mode:

Now the router should accept an image via TFTP or via the ASUS firmware restoration tool.

While in DIAG mode, the router automatically takes the address and answers to ping, you should confirm that before going on.

For those of you using GNU/Linux, follow the installation steps using TFTP, as stated on OpenWrt website, I've been told to be cautious regarding

TFTP versions, as they do not all behave in the same way (Mac OS X users especially). For those of you under Windows, the rest of the steps is as follows:

<!> The installation process can take quite some time, it is HIGHLY important that you DO NOT UNPLUG the router during that process, you should take 15

minutes to read a bit about Asterisk.

If the restoration utility can't find your router, even if you're sure that he is in DIAG mode, bring down and unplug all your network interfaces except

the one plugged into the router.

Once the flashing is finished (either by TFTP or by the F.R.U), you should be able to connect yourself to your router using telnet on the

address, just to validate that everything is fine.

7. OpenWrt Configuration

Configuration of OpenWrt

While you're connected through telnet, you should definitely change the root password RIGHT NOW, using the following command:


It's always a better idea to connect to the router using SSH and NOT USING TELNET, you should even disable telnet which is enabled by default. If you're running Windows, you can use putty as an SSH client (google it). To disable telnet, connect to the router using SSH and the password you set above, then move to the startup scripts directory to deactivate the telnet

startup script:

$cd /etc/init.d/
$chmod a-x S50telnet

You should now take 3 minutes of your time in order to read the small OpenWrt user guide, located there:

That guide will give you basic information on the commands we'll be using next.

8. USB support installation

Working with 7MB of disk space isn't really easy. I've thus decided to install a USB jump drive on the router, so as to be able to install the packages I

want, without being worried about the disk space left, and because USB jump drives are quite cheap by now (15-20$ for 2GB). In order to do so, I've followed two well-documented procedures on OpenWrt's Wiki.

The first procedure explains how to install the necessary modules to support USB 1.1 and 2.0:

I've followed the 3.1, 3.2, 3.3, 3.4 steps, I first tried to install the USB 2.0 modules directly but it didn't work without first installing the USB

1.1 modules. Then I went through the 4.1 step, installing fat, ext2 and ext3 support (using the small table there).

<!> You absolutely need to install ext2/ext3 support if you want to install modules on the jump drive using ipkg.

In order to format the jump drive correctly I've had to unmount it:

$umount /dev/scsci/host0/bus0/target0/lun0/part1

And then I followed the second guide which explains you how to format the jump drive using ext2 in order to be able to correctly install modules on it:

Obviously, you have to replace the path used in the guide /dev/mmc/disc0/part1 by the real one pointing to your USB key, which you should have already used

in the previous step: /dev/scsi/host0/bus0/target0/lun0/part1

You should follow the steps 2, 3.1, 3.2, 4 and 5, read the step number 6 in order to know how to install modules on your USB stick using ipkg.

If something goes wrong during the whole USB installation process, you can always try it again, and look what the


command says about the USB detection during the router startup.

9. Installation of a better web interface

Installation of LuCI web interface

OpenWrt really is a nice distribution for the router and it gives you a very precise control of your hardware, but the default web interface isn't that

verbose and user-friendly. I've thus decided to use the webif2 web interface instead, which was first designed for the X-WRT distribution (which itself is a port of Whiterussian). You do not need to install X-WRT as a whole, you can use ipkg to solely install webif2 by directly pointing at the package URL.

$ipkg install

More details are available on their website:

OpenWrt basic configuration is now over, you can now correctly plug the router in your network if needed.

If you bring the router's web interface up (webif2 there's a way to change the firewall settings using the Network->Firewall

section. This can also be done editing the /etc/config/firewall file (which is read upon startup by the script named /etc/init.d/S35firewall). Using the firewall file settings, you can enable external access to the router by adding this :

accept:proto=tcp dport=22 # SSH Access from outside
accept:proto=tcp dport=80 # Web Access from outside (not recommended at all)

10. Asterisk Installation

Asterisk on OpenWrt

In order to install Asterisk on the router, it's quite simple. All you need is the right packages in your ipkg repository. Unfortunately OpenWrt

Whiterussian's default packages aren't up to date at all (Asterisk 1.0.10 instead of 1.4), you'll then need another repository to get a more updated

version of it:

<!> WARNING, since I wrote this article, things have changed. Kamikaze is now the official OpenWrt stable version, Hans Zandbelt's repo for

Whiterussian's Asterisk installation has been taken down (since for him it was obsolete) and X-WRT has been updated in order to better work with Kamikaze

(config files now replace the NVRAM variables). I thus advise you to follow that guide, but replacing Whiterussian with Kamikaze

Up to this date, there's a repository that you can easily add to your /etc/ipkg.conf file which has an updated version of Asterisk, just add the following

line :

src asterisk14

then use the following command to update ipkg's list of packages:

$ipkg update

Then, simply use the following command (using the -d sd option in order to install the package on the jump drive, read the USB jump drive guide in

order to know how to configure ipkg for that purpose)

$ipkg install -d sd asterisk14

and Asterisk will automatically get installed with all the dependencies.

It is possible that you'll need to install the voicemail package and the extra sounds package separately, they're located in the same repository.

You should then be able to start Asterisk, but in order to do so, there's a couple options available:

You can use the standard startup script available for that purpose, which should be located in the installation directory, which either is

/etc/init.d/asterisk if you've installed Asterisk directly on the router's disk space, or /mnt/sd/etc/init.d/asterisk if you've installed Asterisk on the

jump drive mounted as /mnt/sd/.

Use the script as follows:

$/mnt/sd/etc/init.d/asterisk start


$/mnt/sd/etc/init.d/asterisk stop

You can also start Asterisk simply by using the "asterisk" command. All those scripts will launch Asterisk in background and give you the command prompt

back, if you want to hook yourself back to the asterisk server, use the following command:

$asterisk -r

In order to obtain more verbosity, you can set the verbosity level higher by combining many -v flags up to something like this:

$asterisk -rvvvvvvvvvvvvvvv

If you want to start Asterisk withouh regaining access to the command prompt (for testing purposes), you should use the -c option.

You might want to have Asterisk start up automatically when the router boots, you can easily do this by logging into the web interface of the router

(webif2) and by browsing to the System->Startup section, you should see a text area in which you can add the following line:

# place your own startup commands here
# REMEMBER: You *MUST* place an '&' after launching programs you
#   that are to continue running in the background.
#   i.e.
#   BAD:  upnpd
#   GOOD: upnpd &
# Failure to do this will result in the startup process halting
# on this file and the diagnostic light remaining on (at least
# for WRT54G(s) models).
/mnt/sd/etc/init.d/asterisk start&

Obviously, use the right path depending on where the startup script is located...

11. Asterisk Configuration

Configuring Asterisk is the trickiest part of that setup, it requires a bit of knowledge regarding it's functionning and how the configuration files are

intertwined, and you should definitely take some time to read about it before going further (the following setup will work even if you're completely

clueless about what you're doing, but if you want to customize it, you'll be in a bit of trouble). Here, I'll explain to you how to obtain a basic home phone setup (voicemail etc...) but I'll be taking into account the fact that you've already read

about Asterisk, and that you understand its' file syntax, namely extensions.conf and its' multiple protocols (SIP, IAX etc...).

As a useful reading, you could start with Oreilly's Asterisk, the future of telephony 2nd Edition book, which is licensed under

Creative Commons and thus freely available online quite easily. (use google with the following search terms:

" asterisk"). Reading chapters 1, 4 and 5 should be enough for you to acquire basic knowledge about the PBX's inner working and dialplan's



As you should have read it, initially configuring an Asterisk server for a basic home setup only requires modification to three main files, namely

iax.conf, extensions.conf and sip.conf located in /etc/asterisk or /mnt/sd/etc/asterisk.

<!> Begin by making a backup of those three files, and also modules.conf.

11.1. Modules

Regarding our Asterisk setup on OpenWrt, there's a bit more configuration to do, as most modules have been disabled in order to save some space. All the

modules are listed in the modules.conf file and we'll start by activating the most useful ones. In the modules.conf file, uncomment the following lines (remove the semicolon at the beginning of the line) and change "noload" for "load" where

applicable in order to obtain all those lines:

load => ; Comma Separated Values CDR Backend
load => ; Asterisk Call Manager CDR Backend
load => ; Inter Asterisk eXchange (Ver 2)
load => ; Session Initiation Protocol (SIP)
load => ; GSM/PCM16 (signed linear) Codec Translation
load => ; Mu-law Coder/Decoder
load => ; Microsoft WAV format (8000hz Signed Line
load => ; Dialing Application
load => ; Simple Echo Application
load => ; Look up Caller*ID name/number from black
load => ; Extension Macros
load => ; Read Variable Application
load => ; Set CallerID Application
load => ; Set CallerID Name
load => ; Set CallerID Number
load => ; Send verbose output
load => ; Text Extension Configuration
load => ; Caller ID related dialplan functions

Then verify that Asterisk still starts correctly.

You can also load the module that enables incomming call information logging:

load => ; Comma Separated Values CDR Backend

You'll have to configure the cdr.conf file in order to set the limit and the format of the information loggued in the following file:


11.2. IAX Configuration

Next, we'll configure the IAX configuration to the VOIP provider (as seen in the diagram at the beginning of that guide) so as to register the router

towards the provider.

Open iax.conf file, and replace all the content by the following lines:


Replace <PHONENUMBER> by your DID (your actual phone number), replace <IAX_SECRET> by the password supplied by your VOIP provider and replace <IAX_SERVER>

by the IAX server address of your provider. <INBOUND_CONTEXT> in that file, is a "link" to the extensions.conf file, which will indicate into which

context will be executed when an inbound call is received, you can replace it by whatever you want, provided that it's the same everywhere (you can use

your DID for instance).

11.3. Dialplan configuration

Let's then edit the extensions.conf; in that file, replace the whole content by a general section and the previously named inbound context located in

the iax.conf file.

exten => <PHONENUMBER>,1,Ringing()
exten => <PHONENUMBER>,2,Dial(SIP/SPA2102)
exten => <PHONENUMBER>,3,Hangup;

This gives the exact order of the steps executed when the <INBOUND_CONTEXT> is activated (upon receiving a call).

11.4. SIP clients configuration

In the file we've just edited (extensions.conf), if you look at the <INBOUND_CONTEXT> at the step with a priority of "2", we're using a function to

call an SIP client named SPA2102. We need to configure that client accordingly, by modifying the sip.conf file.

Open the sip.conf file and replace the content by:

type=friend ; friend means you can use the client to make inbound and outbound calls
username=SPA2102 ; The setup is easier if this matches what's between the [ ]
host=dynamic ; You can also use a fixed IP for your ATA there, but dynamic works fine

Please remember <OUTBOUND_CONTEXT>, we'll be using it in extensions.conf in a moment. For now, we need to configure the "physical" SIP client, that is

to say the ATA, so that it can successfully authenticate to the Asterisk server using the [SPA2102] context and the <SIP_SECRET> SIP password.

Open up the SPA2102 web interface, and browse to the Line 1 or Line 2 section (depending into which one you've plugged your analog phone) Voice->Line 1 or Voice->Line 2 and configure the following options:

In the "Proxy" and "Outbound Proxy" text fields (even if that last field isn't used) enter the IP of the Asterisk server (the router). In the "Display" section, enter the name of the SIP client that will connect to the Asterisk server (you will see that name when listing SIP clients on the

Asterisk server) and also enter the "User ID", which is the username= located in sip.conf. The password obviously is your <SIP_SECRET>.

You can also chose a different audio codec in the lower settings of the page, I've chosen:

Then save the changes using the "Submit All Changes" button.

In order to see which client are connected and registered in the Asterisk server, while it's running and while you've hooked to it using the "asterisk -r"

command (if you get the CLI> command prompt, it means you are hooked to your Asterisk server), you can use the following Asterisk command:

CLI> sip show peers

This will greatly help you into debugging which clients in sip.conf are correctly configured and "online" (registered).

But for now, let's set up the outbound context, in order to wrap everything up. In sip.conf we already had a name for the outbound context

<OUTBOUND_CONTEXT>, we only need to add it to extensions.conf with the according extensions:

Add the following section to extensions.conf (below the <INBOUND_CONTEXT> for instance):

exten => _NXXNXXXXXX,3,Congestion
exten => _1800NXXXXXX,1,Set(CALLERID(num)=<<PHONENUMBER>>)
exten => _1800NXXXXXX,3,Congestion
exten => _1888NXXXXXX,1,Set(CALLERID(num)=<<NUM_TELEPHONE>>)
exten => _1888NXXXXXX,3,Congestion
exten => _1877NXXXXXX,1,Set(CALLERID(num)=<<PHONENUMBER>>)
exten => _1877NXXXXXX,3,Congestion
exten => _1866NXXXXXX,1,Set(CALLERID(num)=<<PHONENUMBER>>)
exten => _1866NXXXXXX,3,Congestion
exten => _1NXXNXXXXXX,3,Congestion
exten => _911,1,Set(CALLERID(num)=<<PHONENUMBER>>)
exten => _911,2,Dial(IAX2/<PHONENUMBER>:<IAX_SECRET>@<IAX_SERVER>/${EXTEN},30,r)
exten => _911,3,Congestion

Don't forget to replace <OUTBOUND_CONTEXT>, <PHONENUMBER>, <IAX_SECRET> and <IAX_SERVER> with the correct values. Please note that for the "set(CALLERID" lines, <PHONENUMBER> is written between double < > because you really need to write something like this:


including the < >.

That's pretty much everything you need to configure in order to be able to make and receive calls, you should test your setup using "asterisk -rvvvvvvvvvv"

to watch calls getting through your setup.

11.5. Voicemail

In order to set yourself a voicemail, you've got to modify three files: voicemail.conf to define it, sip.conf to associate the voicemail to your

SIP client and extensions.conf in order to access your voicemail through a standard extension.

In voicemail.conf, towards the end of the file, there's already a [default] section with voicemail examples. You should create your own into that section by adding the line:


Here, <VOICEMAIL_ID> is the numeric ID of your voicemail (we'll use <VOICEMAIL_ID>@default to point to it next), <VOICEMAIL_PASS> is the numeric password

used to access your voicemail, <VOICEMAIL_NAME> is your voicemail name, and <MAIL> is the e-mail address to which it would be possible to send your message

to upon reception (you should use google to find out how to configure this). There are other options available in voicemail.conf like the maximum message duration, the maximum number of stored messages etc... I'll let you configure these on your own.

Now, you'll need to associate an SIP client to your newly created voicemail, by editing the sip.conf file:


in the [SPA2102] context.

In order to allow the voicemail to answer when nobody is available, you need to modify the extensions.conf file. Add a line in the <INBOUND_CONTEXT>:

exten => <PHONENUMBER>,1,Ringing();
exten => <PHONENUMBER>,2,Dial(SIP/SPA2102,20);
; added lines
exten => <PHONENUMBER>,3,Answer(300);
exten => <PHONENUMBER>,4,Playback(vm-nobodyavail);
exten => <PHONENUMBER>,5,VoiceMail(<VOICEMAIL_ID>@default);
exten => <PHONENUMBER>,6,Hangup;

This will tell Asterisk to ring your SIP client for 20 seconds, then to answer and wait 300ms, then play a standard message telling that nobody is

available before bringing up the voicemail introduction message. The Answer(300) line fixes a small timing problem that would truncate the beginning of the first message to be played when answering an incomming call.

In order to be able to consult and configure your voicemail using your internal network analog phone, you need to edit the extensions.conf file and add

an outbound extension that will be triggerred upon dialing *98:

So in the <OUTBOUND_CONTEXT>, add the following line:

exten => *98,1,VoiceMailMain(<VOICEMAIL_ID>@default)

This is all you need to configure to receive messages and consult them from the inside, using a default answering voice.

In order to be able to consult your messages from the outside world, simply add a line at the end of your <INBOUND_CONTEXT>:

; added lines
exten => a,1,Set(LANGUAGE()=fr)
exten => a,2,VoicemailMain(<VOICEMAIL_ID>@default)  ; Call voicemail when * is pressed during the voicemail introduction message

This will allow you to enter the voicemail main menu when you'll press the * button of the phone, but only when the voicemail introduction message

ins playing, it will not work during the "vm-nobodyavail" message.

All your voicemail messages will be available in a .wav format in your voicemail's directory located there: /mnt/sd/var/spool/asterisk/voicemail/default/<VOICEMAIL_ID>

You might need to create folders there, namely "tmp" if Asterisk logs (-vvvvvvvvvvv) tells you so.

Please note that this configuration will only answer with a generic welcome message, that you might want to change. To do this, you'll just have to dial in your voicemail configuration using *98, and then by browsing in the voicemail options menu you can record

your own message when "unavailable" (or "busy").

Then, you'll need to modify the extensions.conf file so as to specify which message you want your voicemail to use when answering after 20 seconds,

only by prefixing the <VOICEMAIL_ID> by the appropriate letter: ("u") for unavailable message, ("b") for busy line and ("s") for no message at all.

exten => <PHONENUMBER>,5,VoiceMail(u<VOICEMAIL_ID>@default);

<!> Warning: some versions of the voicemail module require that you refer to the unavailable message using the following syntax:

exten => <PHONENUMBER>,5,VoiceMail(<VOICEMAIL_ID>@default|u);

If you want to remove the automatic message that tell people how to leave a message, add the "s" parameter to the voicemail function call.

exten => <PHONENUMBER>,5,VoiceMail(<VOICEMAIL_ID>@default|us);

<!> Some newer versions of Asterisk deprecate the use of the pipe "|" as a parameter separator, you might be forced to use a comma instead :

exten => <PHONENUMBER>,5,VoiceMail(<VOICEMAIL_ID>@default,us);

Also, don't forget about the minimum/maximum message length options located into voicemail.conf (you don't want to save 3 seconds empty .wav

files do you?).

11.6. Call waiting function

The SPA2102 already has a call waiting function which you can trigger using the "flash" button on your analog phone, you'll hear a short beep when a second

call is comming and you don't have any more lines free (Otherwise your free phones will ring), pressing the "flash" button will switch to that phone call.

12. Quality of Service (QoS)

Once everything is set up, you'd probably want to be able to download while making a call, without having it lag too much. You'll need to configure some

QoS rules for that so that your router knows which priority to give to the VOIP packets. There's an exceptionnally good QoS script located in OpenWrt

forums which you can install using ipkg:

$ipkg install

Once installed, you can easily have it automatically start up in the same way Asterisk is automatically starting up, by opening the web interface and

browsing to the System->Startup section, and adding the following lines to the text area:

# place your own startup commands here
# REMEMBER: You *MUST* place an '&' after launching programs you
#   that are to continue running in the background.
#   i.e.
#   BAD:  upnpd
#   GOOD: upnpd &
# Failure to do this will result in the startup process halting
# on this file and the diagnostic light remaining on (at least
# for WRT54G(s) models).
/mnt/sd/etc/init.d/asterisk start&
# added line

You also need to configure the QoS script, otherwise it's not that useful, you can do this by editing the /etc/qos.conf file, which is overly easy to

understand. In order to shape our traffic correctly, we need to configure three things:

To set your maximum upload/download bandwidth, modify the following lines to write down 80-85% of the maximum MEASURED bandwidth capacity of your

connection. (Use or to get your measured bandwidth capacity)

Modify the qos.conf file as follows:

# Download speed in kilobits per second
# Set 5% - 10% lower than *measured* line speed (set to zero to disable)
DOWNLOAD=4000 # Example with 5MBIT DOWN, 4200 measured
# Upload speed in kilobits per second
# Set 5% - 10% lower than *measured* line speed (set to zero to disable)
UPLOAD=580 # Example with 800KBIT UP, 600 measured

Next, you need to downgrade the P2P traffic using the associated ports:

# Destination ports for classifying 'bulk' traffic
TCP_BULK="1024: 21 12345 6881:6999"

(Here actually 1024: represents every ports > 1024 so 12345 and 6881 are not really needed)

Then, prioritize the VOIP traffic using the ports and the IP of the clients connected to the Asterisk server:

# Destination ports for classifying 'express' traffic
TCP_EXPR="53 5060:5065 4569:4574"
UDP_EXPR="53 5060:5065 4569:4574"



Here, is a fictitious address for the SPA2102 which we only use for SIP so we do not need to specify the port, and could be a

computer running an SIP client but also running P2P programs, hence the "5060" port targetting.

Don't forget that all those rules have priorities between themselves, in that following increasing order:

## The order of the variables is (lowest precedence first): L7_BULK, L7_PRIO,

To start and stop the QoS script, use qos-start and qos-stop commands.

You can also check if the QoS is running on your computer using the following command:


13. Blacklist

Using the previous Asterisk configuration, we probably have the equivalent of a 40$/month landline in terms of features, but there's way more you can do

using Asterisk. The best feature you can have is a blacklist in order to keep those telemarketers away.

To setup a blacklist, you only need to modify the extensions.conf file, and add a bit of logic to it. Be careful, that code only is compatible with Asterisk 1.4, other versions have different syntaxes to do the same.

First, we'll modify the <INBOUND_CONTEXT> to add a call to the blacklist validation function, which will check if the number is present in the blacklist



exten => <NUM_TELEPHONE>,1,Macro(stdexten) ; call the following macro

exten => s,1,LookupBlacklist(j) ; If CID blacklisted, goto 102
exten => s,2,Ringing()
exten => s,4,Set(DB(lastcaller/<NUM_TELEPHONE>)=${CALLERID(all)}); Note the last caller ID
exten => s,5,Dial(SIP/SPA2102,20)

exten => s-NOANSWER,1,Answer();
exten => s-NOANSWER,2,Wait(1);
exten => s-NOANSWER,3,VoiceMail(u<VOICEMAIL_ID>@default);
exten => s-NOANSWER,4,Hangup;

; Blacklisted CallerID
exten => s,102,Goto(blacklisted,s,1)

exten => a,1,Set(LANGUAGE()=fr) 
exten => a,2,VoicemailMain(<VOICEMAIL_ID>@default)

exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Playback(nbdy-avail-to-take-call)
exten => s,4,Playback(carried-away-by-monkeys)
exten => s,5,Playback(lots-o-monkeys)
exten => s,6,Hangup

You've probably noticed that the <INBOUND_CONTEXT> now points to a macro (a sub-section beginning by macro-) this will allow us to simplify the code and

avoid duplicating the <PHONENUMBER> on each line. We'll use "s" as an extension, for "start" (which is a standard Asterisk extension).

You'll probably also see that the Answer(300) line has been modified by two lines Answer() followed by Wait(1), which have the same purpose.

The main logic behind this code is the call to the LookupBlackList(j) function, which seeks through the database in order to see whether the callerID is

located in the blacklist. If the function is able to find the callerID she jumps to the priority identified by 101 + the current priority, in the same

context (here we were at the priority 1 (s,1,LookupBlackList(j)) and if the number is found in the blacklist, the jump is made to the priority 102


Then the 102 priority makes a call to the "blacklisted" context, which in turn answers (in a funny way) that nobody is available to answer the call and

hangs up.

In order to use the "funny sounds" you might have to install extra sounds packages for Asterisk, I've chosen GSM format.

To install the packages in OpenWrt, create a temporary directory on the USB key, and type:

tar -zxvf asterisk-extra-sounds-en-gsm-current.tar.gz -C /var/lib/asterisk/sounds

and restart Asterisk.

You'll probably want to add phone numbers to the blacklist, there are two ways of doing so. First, it's possible to add, consult and delete numbers

directly by using the Asterisk command line and the "database" functions:

CLI>database put blacklist 5555551234 1
Updated database successfully

CLI>database show blacklist
/blacklist/5555551234                             : 1

CLI>database del blacklist 5555551234
Database entry removed.

This is not very user-friendly though, it's thus better to set yourself an extension you can call from the inside in order to blacklist phone numbers using

your analog phone.

Let's create extensions under the <OUTBOUND_CONTEXT> to trigger the blacklist management from the analog phones.

<!> Please note that when chosing an *XX extension, the SPA2102 alread has some pre-configured and he doesn't warn you if you're triggering one by mistake.

If you aren't sure if the extension you'd like to use is "free" from the SPA2102 settings, use its web interface to navigate to Voice->Regional and

delete the ones you want.

So back to our extension setup, let's add those two lines to the <OUTBOUND_CONTEXT>

exten => *95,1,Goto(blacklist-add,s,1)
exten => *96,1,Goto(blacklist-remove,s,1)

You've noticed that those extensions link to two new contexts that we need to create in extensions.conf:

exten => s,1,Playback(enter-num-blacklist)
exten => s,2,Set(TIMEOUT(digit)=5)
exten => s,3,Set(TIMEOUT(response)=30)
exten => _X.,1,Set(DB(blacklist/${EXTEN})=1) ; Add a phone number to blacklist
exten => _X.,2,SayDigits(${EXTEN})
exten => _X.,3,Playback(num-was-successfully)
exten => _X.,4,Playback(added)
exten => _X.,5,Playback(goodbye)
exten => _X.,6,Hangup

exten => s,1,Playback(entr-num-rmv-blklist)
exten => s,2,Set(TIMEOUT(digit)=5)
exten => s,3,Set(TIMEOUT(response)=30)
exten => _X.,1,Set(oldval=${DB_DELETE(blacklist/${EXTEN})}) ; Delete a phone number from blacklist
exten => _X.,2,SayDigits(${EXTEN})
exten => _X.,3,Playback(num-was-successfully)
exten => _X.,4,Playback(removed)
exten => _X.,5,Playback(goodbye)
exten => _X.,6,Hangup

Typing *95 from your local phone, will bring you to the blacklist-add context, and *96 will enter into the blacklist-remove context.

Remember that in the <INBOUND_CONTEXT> we had previously noted the last caller, you can consult it by querying the database as follows:

CLI> database show lastcaller

You can also create yourself another context in order to add it automatically to the blacklist.

14. Call Forward

The next great feature is the Call Forward. Here we'll be configuring extensions.conf in order to have a call forward on no answer, but the configuration will be ready to support call forward on

multiple different call status (busy, no more free lines, etc...). First, let's add some logic to the macro-stdexten previously created:


exten => <NUM_TELEPHONE>,1,Macro(stdexten) ; Call the following macro

exten => s,1,LookupBlacklist(j) ; If CID blacklisted, goto 102
exten => s,2,Ringing()
exten => s,4,Set(DB(lastcaller/<NUM_TELEPHONE>)=${CALLERID(all)}); Note last caller
exten => s,5,Dial(SIP/SPA2102,20)
; ***** modified lines
exten => s,6,Goto(s-${DIALSTATUS},1)            ; Jump to extension based on call status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => s-NOANSWER,1,GotoIf(${DB_EXISTS(CFNA/<IDENTIFIANT>)}?2:3)    ; If CFNA key doesn't exist jump to answer
exten => s-NOANSWER,2,Dial(Local/${DB_RESULT}@<OUTBOUND_CONTEXT>/n)        ; Otherwise DIAL the CFNA key using the OUTBOUND_CONTEXT
exten => s-NOANSWER,3,Answer();
exten => s-NOANSWER,4,Wait(1);
exten => s-NOANSWER,5,VoiceMail(u<VOICEMAIL_ID>@default);
exten => s-NOANSWER,6,Hangup;
exten => s-NOANSWER,7,Goto(s,4)                 ; If # pressed go back to 4

exten => _s-.,1,Goto(s-NOANSWER,1)              ; Everything not being s-NOANSWER will be treated as s-NOANSWER
; ***** end modified lines

; Blacklisted CallerID
exten => s,102,Goto(blacklisted,s,1)

exten => a,1,Set(LANGUAGE()=fr) 
exten => a,2,VoicemailMain(<VOICEMAIL_ID>@default)     ; Voicemail upon * pressed

This code will try and fetch the CFNA/<ID> (<ID> can be the same as your <VOICEMAIL_ID> for instance) key from the database, which should contain a phone

number, if found it'll then use the local <OUTBOUND_CONTEXT> to call the phone number exactly as if you did call it using your analog phone number. If the

key doesn't exist the voicemail will simply take over.

To make this work, you thus need to add a key into the database so as to store the phone number to which to transfer the call. You can do this using the Asterisk command line with the command "db put CFNA/<ID> <CF_NUMBER>" but as with the blacklist, we'd better be configuring local

extensions to do the same:

So first of all, chose three *XX extensions to be added to the <OUTBOUND_CONTEXT>, but as I'll be chosing some conflicting with the SPA2102 settings, I'll

be sure to remove them as noted in Chapter 12 (namely *72 and *73).

; Add a phone number to call forward
exten => *72,1,Goto(callfwd-add,s,1)

; delete call forward
exten => *73,1,Set(temp=${DB_DELETE(CFNA/<IDENTIFIANT>)}) ; delete the CFNA/<IDENTIFIANT> key into database
exten => *73,2,Playback(call-fwd-no-ans)
exten => *73,3,Playback(has-been-cleared)
exten => *73,4,Hangup

; read call forward
exten => *75,1,Playback(call-fwd-no-ans)
exten => *75,2,GotoIf(${DB_EXISTS(CFNA/<IDENTIFIANT>)}?3:6)  ; get the CFNA/<IDENTIFIANT> from database
exten => *75,3,Playback(is-set-to)
exten => *75,4,SayDigits(${DB_RESULT})
exten => *75,5,Hangup
exten => *75,6,Playback(is-not-set)
exten => *75,7,Hangup

You'll note that the *72 extension calls a context not yet configured, so I'll need to add it to the extensions.conf file right away.

exten => s,1,Playback(please-enter-the)
exten => s,2,Playback(call-forwarding)
exten => s,3,Playback(telephone-number)
exten => s,4,Set(TIMEOUT(digit)=5)
exten => s,5,Set(TIMEOUT(response)=30)
exten => _X.,1,Set(DB(CFNA/<IDENTIFIANT>)=${EXTEN})
exten => _X.,2,Playback(call-forwarding)
exten => _X.,3,Playback(has-been-set-to)
exten => _X.,4,SayDigits(${EXTEN})
exten => _X.,5,Playback(goodbye)
exten => _X.,6,Hangup

There's no particular reason to create a context for that one compared to the others, it's just a way of showing different techniques.

15. Date and time

Once everything is set, you'll probably notice that the date and time of the router aren't right. This can be adjusted manually but it'll quickly end up being annoying if you suffer from an electricity shortage.

There's an easy solution to that which consists in installing an ntp client on the machine.

You can do so in different ways: you can simply install the ntpclient package using the following command:

ipkg install ntpclient

Or you can also install the client from the web interface of the router, under the System->Settings by cliking on the available button just under the

NTP Server line. This has the same effect as the above command.

If the ntp client installation creates a startup script named /etc/init.d/S55ntpclient you can modify it so that it looks like this:

# Close existing ntp client
/usr/bin/killall ntpclient

# Start ntp client and sync with server
/usr/sbin/ntpclient -l -h <IP_NTP_SERVER> -c 1 -s &

If no startup script is created, simply go back to the web interface and use the System->Startup section to add this to the text area:

/usr/bin/killall ntpclient
/usr/sbin/ntpclient -l -h <IP_NTP_SERVER> -c 1 -s &

<!> Replace <IP_NTP_SERVER> with a real IP of an NTP server which you can fetch by going on chose your zone, and one of the

server listed then, just be sure that you can ping it.

Restart your router to check that the time is correct.

More details there

16. And then ?

Asterisk really is powerful and allows you to do a lot of things, plus there's a plethora of websites dedicated to helping you setup new features. Juste use google to find the answers you're looking for, the following links might also help you.

Practical Asterisk 1.4:

Tutorials and howto's for the asterisk PBX and voip in general:

The VOIP Wiki - a reference guide to all things VOIP:

Asterisk Montreal Users Group:

OpenWrt Community wiki:

Asterisk14OnOpenWRT (last edited 2018-05-19 02:38:13 by GabrielFilion)