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'.
Now change into the directory you just made, and make another one called '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 '.'
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.
We'll now shift focus onto the Asterisk configuration files.
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.
Once you've opened up the file for editing, copy the following into the text editor and save:
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.
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.
Once inside the text editor, copy this configuration into the file and save:
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:
- 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.
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.
For now, we will insert a very generic dialplan into extensions.conf and then save:
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.
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.
Now that Asterisk is configured, we move onto installing the Obi110 ATA.