Initial Asterisk configuration


Asterisk has three main configuration files: asterisk.conf, sip.conf, and extensions.conf. We'll go over their significance one by one. But first, we need to add some more directories to the 'banana' user's home directory. We will tell Asterisk to look for some sound files and the Banana Phone scripts there later.

Assuming you are logged in as the 'banana' user, move into your home directory and create another directory called 'banana_phone'.

cd ~
mkdir banana_phone

Now change into the directory you just made, and make another one called 'asterisk_resources'.

cd banana_phone
mkdir asterisk_resources

Asterisk comes with a set of audio files for things like background music, voicemail beeps and other standard telephone sounds. We will be using our own sound files for Banana Phone, so we will move the contents of the default Asterisk resource directory to the 'banana' user and tell Asterisk to look there for audio files.

Move into the 'asterisk_resources' directory, and copy all the files from Asterisk's default resource directory into yours. With some bash trickery, we can copy all the files from the default Asterisk resource directory into our own using 'cp -R' and the shell wildcard '.'

cd asterisk_resources
sudo cp -R /var/lib/asterisk/* .

Don't forget to leave a space between '/var/lib/asterisk/*' and '.' or you'll get an error when running the command.

Now we need to change permissions on the newly copied files, as they still belong to the root user.

sudo chown -R banana:banana *

We'll now shift focus onto the Asterisk configuration files.


asterisk.conf

This file sets default permissions for sockets, and tells Asterisk where to find resources like sound files and AGI files (AGI is garbage, btw).

Move into the main Asterisk install directory, rename the default asterisk config file and use 'nano' to open a new file called 'asterisk.conf'. This will replace the one we renamed, and will have a minimal configuration telling Asterisk to look for audio files in our 'banana_phone' directory.

cd /etc/asterisk
sudo mv asterisk.conf asterisk.conf.bk
sudo nano asterisk.conf

Once you've opened up the file for editing, copy the following into the text editor and save:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[directories]
astetcdir = /etc/asterisk
astmoddir = /usr/lib/asterisk/modules
astvarlibdir = /var/lib/asterisk
astdbdir = /var/lib/asterisk
astkeydir = /var/lib/asterisk
astdatadir = /home/banana/banana_phone/asterisk_resources
astagidir = /var/lib/asterisk/agi-bin
astspooldir = /var/spool/asterisk
astrundir = /var/run/asterisk
astlogdir = /var/log/asterisk
astsbindir = /usr/sbin

[options]
; If we want to start Asterisk with a default verbosity for the verbose
; or debug logger channel types, then we use these settings.
;verbose = 5
;debug = 5

; User and group to run asterisk as. NOTE: This will require changes to
; directory and device permissions.
runuser = banana	; The user to run as.
rungroup = banana	; The group to run as.

defaultlanguage = en
documentation_language = en_US

On line 7, we tell Asterisk to look for data resources in the directory we made for the 'banana' user. On lines 22 and 23, we set Asterisk to run as the 'banana' user, because the Asterisk server will be running scripts associated with it.


sip.conf

This file is responsible for defining "SIP endpoints" in Asterisk. That's a fancy way of saying "places where SIP calls should go."

Consider an endpoint like a single end of a telephone call; on one end there is a phoneline run by the telecom provider, and on the other is the actual phone handset where the call get pushed to. This concept of breaking up a telephone call into sending and receiving parties (FXO and FXS, roughly speaking) is key to how Asterisk makes phone calls happen. The sip.conf file defines SIP endpoints on the Asterisk server.

We will start by doing the same thing we did for asterisk.conf. Rename the sip.conf file and create our own. Again, make sure you're in the '/etc/asterisk' directory.

sudo mv sip.conf sip.conf.bk
sudo nano sip.conf

Once inside the text editor, copy this configuration into the file and save:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;This section is for general setting of the sip channel
[general]
context=unauthenticated          ; default context for incoming calls
allowguest=no                    ; disable unauthenticated calls
srvlookup=no                     ; disable DNS SRV record lookup on outbound calls

udpbindaddr=192.168.1.207        ; make it the static IP you set up on eth0/wlan0
tcpenable=no                     

[PhoneHandset]
username=PhoneHandset
secret=n677!hsnl08               ; a unique password for this device
type=friend                      ; the channel driver will match on username first
context=PhoneHandset             ; where calls from the device will enter the dialplan
host=dynamic                     ; the device will register with asterisk
dtmfmode=inband               ; accept touch-tones from the devices
disallow=all                     ; reset which voice codecs this device will accept
allow=g722                       ; audio codecs to accept from, and request to
allow=ulaw                       
allow=alaw

[PhoneLine]
username=PhoneLine
secret=hj87tbd!i90
type=friend
context=PhoneLine
host=dynamic
qualify=yes
dtmfmode=inband
canreinvite=no
disallow=all
allow=g722
allow=ulaw

There is a lot going on here, so we'll focus on the important key words and what they mean.

Line 2 is the "general" settings for the SIP part of the Asterisk server. The "context" keyword in line 3 defines the default endpoint to route calls to. We'll go into what exactly Contexts are in Asterisk, so for now, just copy it and move on.

Line 7 defines the IP address that Asterisk will be listening for calls on. Set this to the static IP on your RPi.

Line 10 starts the definition of the first SIP endpoint, called "PhoneHandset." This endpoint will associate the actual phone with our Asterisk system. All the keywords/values following after that pertain to that endpoint. We'll go through these keywords.

  • username - this is exactly what it sounds like. This username is associated with this endpoint and is used with a password to tie calling devices (like our ATA later on) to Asterisk.
  • secret - the password that the username will authenticate with. Think of a good secure one, or use this command to generate one for you:
openssl rand -base64 11
  • type - Asterisk users have three types:
    • user - can make calls from Asterisk
    • peer - can send calls to Asterisk, an exampke would be like a 3rd party VoIP provider you could have a SIP phone number with
    • friend - is both a peer and a user, so they can send and receive calls from Asterisk

In this case, our PhoneHandset is a friend type. Clearly.

  • context - the default "landing spot" for calls originating from this endpoint. This will make sense when we cover dialplan basics.
  • host - specifies the IP or hostname of the SIP peer or user. It can be a server name or an IP or dynamic. Dynamic means that the SIP peer/user needs to register with the server before calls can be made. 
  • qualify - Tell Asterisk to periodically check to see if the peer/user is up and able to handle calls.
  • dtmfmode - DTMF signals are the formal name for the dial pad buttons (0-9, #,*) that are one all phones.  We'll set this to inband.
  • disallow, allow - these pertain to the audio codecs to be used during phone calls. It starts by disalloing all of them, then allowing g722, ulaw and alaw. For more information on the codecs, see http://www.voip-info.org/wiki/view/Asterisk+codecs+allow

On line 23, we create another endpoint and name it "PhoneLine." This endpoint will be associated with the phoneline coming into the Asterisk system. 

These usernames and passwords defined in sip.conf will be used by the Obi110 ATA to tie in our phoneline and handset to the Asterisk server over the local network.


extensions.conf

This file is the core of Asterisk functionality. Using the Asterisk Extension Language(AEL), you can manipulate calls coming into the server to do all sorts of things, like interactive voice menus, database lookups on incoming caller IDs (hint) and other arbitrary logic. A collection of AEL commands for call processing is called a dialplan.

Repeat the steps we did for asterisk.conf and sip.conf, renaming the defaults and making our own.

sudo mv extensions.conf extensions.conf.bk
sudo nano extensions.conf

For now, we will insert a very generic dialplan into extensions.conf and then save:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[general] 
exten => _X.,1,Answer()
    same => n,NoOp("generic catch-all extension")
    same => n,NoOp(${EXTEN})
    same => n,HangUp()

[PhoneLine]
exten => _X.,1,Answer()
    same => n,NoOp("in PhoneLine extension")
    same => n,NoOp(${EXTEN})
    same => n,HangUp()

[PhoneHandset]
exten => _X.,1,Answer()
    same => n,NoOp("in PhoneHandset extension")
    same => n,NoOp(${EXTEN})
    same => n,HangUp()

None of this is supposed to make sense yet. We'll go over this dialplan and get familiar with the Extension language later on. To finish out our Asterisk configs, change the owner of all the files in the directory to the 'asterisk' user.

sudo chown asterisk:asterisk *.conf

We really only needed to chown the 3 files we added, but that was faster and all files in this directory should be owned by 'asterisk' anyways.

Once all our new conf files are in place, restart the Asterisk server.

sudo /etc/init.d/asterisk restart

Now that Asterisk is configured, we move onto installing the Obi110 ATA.

-> Next section: Obi110 ATA settings