Asterisk

Installing and Configuring Asterisk 18 (with Softmodem) on Ubuntu 20

Update and install the dependencies needed to build Asterisk.

# apt update
# add-apt-repository universe
# apt -y install git curl wget libnewt-dev libssl-dev libncurses5-dev subversion libsqlite3-dev build-essential libjansson-dev libxml2-dev  uuid-dev 

Download Asterisk 18 and unpack.

# cd ~
# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-18-current.tar.gz
# tar xvf asterisk-18-current.tar.gz

Download the MP3 decoder library.

# cd asterisk-18.*/
# contrib/scripts/get_mp3_source.sh

Resolve any dependencies.

# sudo contrib/scripts/install_prereq install

Download the Softmodem code and copy it to the Asterisk.

# cd ~
# wget https://raw.githubusercontent.com/johnnewcombe/asterisk-Softmodem/app_softmodem/app_softmodem.c

Copy app_softmodem.c to the ”apps” folder of the Asterisk 18 source e.g.

# cp app_softmodem.c ./asterisk-18.13.0/apps

Build Asterisk. Note that on a Raspberry PiOS you may have to specifically install g++.

# cd asterisk-18.*/
# ./configure

When compiling on a Raspbery Pi 4, ./configure has been known to fail with errors relating to /lib/cpp. If this occurs, it may be that the g++ package needs to be installed.

# make menuselect

If this works you will be presented with a menu. If you do not know what to do with this, simply Save and Exit.

# make
# make install

Optionally.

sudo make progdocs

Create the configs etc.

# make samples
# make config
# ldconfig

Create an Asterisk user and Configure.

# groupadd asterisk
# useradd -r -d /var/lib/asterisk -g asterisk asterisk
# usermod -aG audio,dialout asterisk
# chown -R asterisk.asterisk /etc/asterisk
# chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
# chown -R asterisk.asterisk /usr/lib/asterisk
    
# vim /etc/default/asterisk
    
  AST_USER="asterisk"
  AST_GROUP="asterisk"
    
# vim /etc/asterisk/asterisk.conf

  runuser = asterisk ; The user to run as.
  rungroup = asterisk ; The group to run as.x

Start Asterisk.

# systemctl start asterisk
# systemctl status asterisk

Once you are happy things are OK then enable.

# systemctl enable asterisk

Connect to the Asterisk CLI, the more ‘v’s the more verbose (I think the max is 10!).

# asterisk -rvvv

e.g.

CLI> pjsip show endpoints
No objects found.

Journal entries can be viewed with the following command (x = extra detail, e = jump to the end, u = the unit to view).

# journalctl -xeu asterisk

For the firewall you may need to open some ports for SIP and RTP depending on what provider is used for a SIP Trunk. e.g.

ufw allow proto tcp from <ipaddress_of_SIP_provider> to any port <SIP Port Range Start>:<SIP Port Range End>
ufw allow proto udp from <ipaddress_of_SIP_provider> to any port <RTP Port Range Start>:<RTP Port Range End>

e.g.

ufw allow proto udp from 212.9.44.0/24 to any port 5000:31000
ufw allow proto udp from 212.10.77.0/24 to any port 5000:31000

In addition any cloud provider such as DigitalOcean may also have firewall rules that need altering.

pjsip.conf

This config filer replaces ”sip.conf” which has been deprecated. This will depend upon the SIP Trunk provider that is used.


This particular setup was used successfully with the free Sipgate Basic product. This is not supported by Sipgate and is not recommended either. However, it does work with the restriction that there can be only one incomming connection at a time.

[transport-udp]
type = transport protocol = udp bind = 0.0.0.0
[telstar]
type = registration 
retry_interval = 20 
max_retries = 10 
contact_user = <sip_user_id> 
expiration = 120 
transport = transport-udp 
outbound_auth = telstar 
outbound_proxy = sip:sipgate.co.uk 
client_uri = sip:<sip_user_id>@sipgate.co.uk 
server_uri = sip:sipgate.co.uk
[telstar]
type = auth 
auth_type = userpass 
username = <sip_user_id> 
password = <sip_password> 
realm = sipgate.co.uk
[telstar]
type = aor 
contact = sip:<sip_user_id>@sipgate.co.uk
[telstar]
type = endpoint 
context = from-external 
disallow = all 
allow = alaw 
from_user = <sip_user_id> 
from_domain = sipgate.co.uk 
outbound_auth = telstar 
aors = telstar
[telstar]
type = identify 
endpoint = telstar 
match = sipgate.co.uk

extensions.conf

Note that the Dialplan below increases the TX and RX volume, this was needed for use with Telstar. See note below.

[from-external]
exten => telstar,1,Set(VOLUME(TX)=2)
exten => telstar,n,Set(VOLUME(RX)=2)
exten => telstar,n,Answer()
exten => telstar,n,Softmodem(glasstty.com, 6503, ,v(V23)ld(7)s(1)e)
exten => telstar,n,Hangup()

However, it does add extra cpu processing and should only be added if needed.

In the above example dialplan the volume has been increased. The default setting is zero 0 which disables the calling volume adjustment routine. To increase the volume set the adjustment to integer greater than or equal to 2, similarly, to decrease the volume set the adjustment to integer less than or equal to -2. Thankyou to AndyDev (https://superuser.com/users/251541/anydev) for the explanation and for the following examples.

Using adjustment value of -1 or 1 has no effect on the resulting volume but wastes CPU cycles, use zero 0 instead.

Examples:

; Reduce each sample to 50% the original value
same => n,SET(VOLUME(TX)=-2)

; Reduce each sample to 20% the original value
same => n,SET(VOLUME(TX)=-5)

; Reduce each sample to 10% the original value
same => n,SET(VOLUME(TX)=-10)

; Disable volume adjustments
same => n,SET(VOLUME(TX)=0)

; Increase each sample to 200% of the original value
same => n,SET(VOLUME(TX)=2)