VoIP Telephony with Asterisk

Overview

Links:

Installation

Preparation

# Install pre-requisites
sudo apt-get install uuid-dev libjansson-dev libxml2-dev libncurses5-dev libsqlite3-dev libssl-dev libjansson-dev uuid-dev

# Dowload and untar source package
wget https://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15.1.4.tar.gz
tar xvzf asterisk-*.tar.gz

Builduing Asterisk from sources

Asterisk will be built in a local filesystem (~/local)

cd asterik-*
./configure --prefix=/home/asterisk/local
make menuselect
make
make install
# to generate default configuration:
make samples
# to start Asterisk automatically by the init process:
# sudo make config

Configuration

First, let's create the dial plan:

cd ~/local/etc/asterisk
mv extensions.conf extensions.conf.bak
vim.tiny extensions.conf
 ~/local/etc/asterisk/extensions.conf
[from-internal]
exten = 999,1,Answer()
same = n,Wait(1)
same = n,Playback(hello-world)
same = n,Hangup()

exten => _600[0-8],1,Dial(PJSIP/${EXTEN},40)
exten => _600[0-8],2,Voicemail(${EXTEN}@vm)

exten => 888,1,Answer()
exten => 888,2,VoiceMailMain(${CALLERID(num)}@vm)

Next, create the users:

Latest Asterisk release default to PJ-SIP stack instead of built in

mv pjsip.conf pjsip.conf.bak
vim.tiny pjsip.conf
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

; templates -------------------------------------------------------------
[endpoint-basic](!)
type=endpoint
context=from-internal
disallow=all
allow=ulaw
 
[auth-userpass](!)
type=auth
auth_type=userpass
 
[aor-single-reg](!)
type=aor
max_contacts=1

; ext 6001 --------------------------------------------------------------

[6001](endpoint-basic)
auth=6001
aors=6001

[6001](auth-userpass)
password=unsecurepassword
username=6001

[6001](aor-single-reg)

; ext 6002 --------------------------------------------------------------

[6002](endpoint-basic)
auth=6002
aors=6002

[6002](auth-userpass)
password=unsecurepassword
username=6002

[6002](aor-single-reg)

For older builtin SIP:

mv sip.conf sip.conf.bak
vim.tiny sip.conf
 ~/local/etc/asterisk/sip.conf
[general]
context=default

[6001]
type=friend
context=from-internal
host=dynamic
secret=unsecurepassword
disallow=all
allow=ulaw

Cisco IP phones

Cisco SCCP IP-Phones can be used with Asterisk using Skinny module [Still TBD]

Configuration info | html

Voice mail

mv voicemail.conf voicemail.conf.bak
vi voicemail.conf
[general]
format=wav49|gsm|wav
;serveremail=nobody@nowhere.com
;attach=yes
maxsilence=10
silencethreshold=128
maxlogins=3
;sendvoicemail=yes
[vm]
6001 => 1234,Phone 6001
6002 => 1234,Phone 6002

Run Asterisk server

Invoke server manually

Since server is not is default system location, path and library will not be found automatically.

# To add Asterisk lib path to system libraries:
sudo ldconfig /home/asterisk/local/lib

# add asterisk to path (in ~/.bashrc or directly at shell)
export PATH=$PATH:/home/asterisk/local/sbin

# or asterisk must be run as 'LD_LIBRARY_PATH=/home/asterisk/local/lib ~/local/sbin/asterisk'

To start the server:

# start asterisk server:
asterisk & 

# Connect to Asterisk server's console:
asterisk -cvvvvvvvvvvr
Asterisk 14.5.0, Copyright (C) 1999 - 2016, Digium, Inc. and others.
=========================================================================
Connected to Asterisk 14.5.0 currently running on server (pid = 5082)
server*CLI> sip show users
Username                   Secret           Accountcode      Def.Context      ACL  Forcerport
1001                       secret                            local            No   No        
1002                       secret                            local            No   No        
1003                       secret                            local            No   No        
server*CLI> quit
Asterisk cleanly ending (0).
Executing last minute cleanups

# stop asterisk server:
killall asterisk

SIP clients

FXS for Linksys SPA3102

 pjsip.conf
; --- FXS Port (The Analog Phone) ---
[spa_fxs]
type=endpoint
context=from-internal
disallow=all
allow=ulaw
auth=auth_spa_fxs
aors=spa_fxs

[auth_spa_fxs]
type=auth
auth_type=userpass
username=spa_fxs
password=your_strong_password

[spa_fxs]
type=aor
max_contacts=1

; --- FXO Port (The PSTN Line) ---
[spa_fxo]
type=endpoint
context=from-pstn
disallow=all
allow=ulaw
auth=auth_spa_fxo
aors=spa_fxo

[auth_spa_fxo]
type=auth
auth_type=userpass
username=spa_fxo
password=your_other_password

[spa_fxo]
type=aor
max_contacts=1
 extensions.conf
[from-internal]
; Dialing the analog phone attached to the SPA3102
exten => 101,1,Dial(PJSIP/spa_fxs)

; Dialing out through the PSTN wall jack
exten => _9X.,1,Dial(PJSIP/${EXTEN:1}@spa_fxo)

[from-pstn]
; When the wall jack rings, the SPA dials 's'
exten => s,1,NoOp(Incoming call from PSTN)
exten => s,n,Dial(PJSIP/spa_fxs,20) ; Ring the local phone
exten => s,n,Hangup()

SPA3102 Web Interface Setup

Log into the SPA3102 web GUI (usually via the IVR by dialing **** then 110# on the attached phone to get the IP). Switch to Advanced and Admin Login modes.

Line 1 Tab (FXS - The Phone)
Line Enable: yes

Proxy: [IP of your Asterisk Server]

Register: yes

User ID: spa_fxs

Password: your_strong_password

PSTN Line Tab (FXO - The Wall Jack)
Line Enable: yes

Proxy: [IP of your Asterisk Server]

Register: yes

User ID: spa_fxo

Password: your_other_password

PSTN Answer Delay: 3 (Gives the SPA time to capture Caller ID before passing to Asterisk)

Crucial Settings for Dialing Out:

PSTN Caller Default DP: 1

Dial Plan 1: (S0<:s>)

This tells the SPA that as soon as the PSTN line rings, it should "auto-dial" the extension s in Asterisk.

NAT: If your Asterisk server is in the cloud and the SPA3102 is behind a home router, ensure nat=yes (SIP) or force_rport=yes (PJSIP) is set.

Echo Cancellation: The SPA3102 is notorious for echo on the PSTN line. In the PSTN Line tab, look for SPA To PSTN Gain and PSTN To SPA Gain. Start by lowering these (e.g., -3 or -6) if you hear your own voice.

Disconnect Tone: If the PSTN line stays "off-hook" after a call ends, you need to adjust the Disconnect Tone in the Regional tab to match your country’s specific frequency/cadence.

Regional Tab Settings

In the Regional tab of the SPA3102 web interface, update these specific fields to match the French standard:
Setting Value
Dial Tone 440@-13;10(*/0/1)
Ringback Tone 440@-13;1.5(.5/1/1)
Busy Tone 440@-13;10(.5/.5/1)
Reorder Tone 440@-13;10(.25/.25/1)
MWI Dial Tone 440@-13;10(.1/.1/1)
Disconnect Tone 440@-13;10(.5/.5/1)
Ring Waveform Sinusoid
Ring Frequency 50
Ring Voltage 70
Caller ID Method ETSI FSK (with PR)
FXS Port Impedance `270+7502

PSTN Line Tab (FXO) Settings
These settings ensure the SPA3102 talks correctly to your French wall jack (the "prise en T" or the phone port on your Box).
PSTN Port Impedance: 270+750||150nF
SPA To PSTN Gain: -2 (France lines can be "hot"; this prevents clipping)
PSTN To SPA Gain: 1
PSTN Disconnect Detection:
  Detect CPC: Yes
  Detect Polarity Reversal: Yes (Standard for French lines to signal hang-up)
  Detect Disconnect Tone: Yes

Dialing Logic for France

In France, numbers are 10 digits starting with 0. You should update your extensions.conf to handle the standard French numbering plan.
Updated extensions.conf:

Extrait de code
[from-internal]
; Internal calls to the phone attached to SPA
exten => 100,1,Dial(PJSIP/spa_fxs)

; Outbound calls via PSTN (Dialing 0 to get an outside line)
; Matches 01-05 (landlines) and 06-07 (mobiles)
exten => _0[1-79]XXXXXXXX,1,NoOp(Outbound Call to ${EXTEN})
exten => _0[1-79]XXXXXXXX,n,Dial(PJSIP/${EXTEN}@spa_fxo)

[from-pstn]
; French Caller ID is sent between the first and second ring
; Ensure 'PSTN Answer Delay' is set to 3 in the PSTN Tab
exten => s,1,NoOp(Incoming call from French PSTN: ${CALLERID(num)})
exten => s,n,Dial(PJSIP/spa_fxs,30)
exten => s,n,Hangup()

Since you are plugging the SPA3102 into the Phone port of an internet box (Livebox, Freebox, Bbox, etc.), the environment is slightly different than a traditional copper wall jack. The "Box" is essentially simulating a phone line, which is usually a cleaner signal but has some quirks.

Here are the specific adjustments for a "Box" setup:

1. Impedance & Levels
Most French Boxes are tuned to the European standard impedance. In the PSTN Line tab, ensure:

PSTN Port Impedance: Set to 270+750||150nF (This is the "Complex" impedance for France).

SPA To PSTN Gain: Set this to 0. (Unlike wall jacks, Boxes usually output a very precise signal level, so you don't need to attenuate it as much).

PSTN To SPA Gain: Set this to 2 or 3. (Sometimes the audio coming from the Box into Asterisk can be a bit quiet).

2. Caller ID (The "Waiting" Game)
This is the most common point of failure. French Boxes send Caller ID (FSK) between the first and second ring.

PSTN Answer Delay: Set this to 4.

Why? If Asterisk answers the call immediately (Delay 0), the Box hasn't sent the Caller ID data yet, and your phone logs will show "Unknown."

PSTN Ring Timeout: Set to 5.

Caller ID Method: ETSI FSK is standard, but if it doesn't work, try Bellcore (some newer Boxes use the international standard).

3. Disconnect Detection (The "Hanging Line" Fix)
If you hang up a call but the Box doesn't "tell" the SPA3102 that the call is over, your PSTN line will stay busy.

Detect Polarity Reversal: Set to No. (Most Boxes do not support physical polarity reversal like the old analog network did).

Detect CPC: Set to No.

Detect Disconnect Tone: Set to Yes.

Disconnect Tone: Ensure it matches the value we set earlier: 440@-13;10(.5/.5/1). This is the standard "Busy" tone the Box will emit when the outside party hangs up.

4. Dialing from the SPA (Dial Plans)
The Box expects numbers to be sent just like a regular phone. In the PSTN Line tab, check your PSTN Dial Plan:

Dial Plan: (0[1-9]xxxxxxxx)

This ensures the SPA waits for exactly 10 digits starting with 0 before it "dials" the Box. It makes dialing much faster than waiting for a timeout.

5. Final Checklist
Cabling: Ensure the cable goes from the Box's Phone Port to the SPA3102's LINE Port.

Echo: If you hear an echo, go to the PSTN Line tab and set Echo Canc Enable to Yes and Echo Canc Adapt Enable to Yes.

Voltage: If the SPA doesn't "see" the Box, check the Line-In-Use Voltage setting in the PSTN tab. Set it to 25 (the default is often 30, and some Boxes output a lower idle voltage).

Pro-Tip: If you are using a Freebox, you can actually bypass the SPA3102's FXO port for incoming calls by enabling "SIP Discovery" in your Free subscriber area, but for most other French ISPs, this SPA3102 bridge is the only way to "digitize" your Box's phone line.

Is the SPA3102 registering successfully (Green "Registered" status) in your Asterisk info?

06-May-2026