Install and launch Asterisk on an Android smartphone

Hello, habr!

I needed to quickly assemble a stand to demonstrate the work of an aster in a small organization. It was necessary to make several calls, demonstrate transfer, intercept a call, etc. The VoIP server itself is hosted on its smartphone. Why on a smartphone, how and for what purpose - under the cut.



1. Why

I work in a company that is involved in setting up telephony for small and not so companies in the city and region. Asterisk in most cases is the best option for PBX, as it is easily configured, scaled to the needs of the organization, you can supplement the functionality with your own scripts. There is a gentleman's kit to demonstrate the work of the PBX - an old MacBook with Linux on board and configured aster, a Gigaset SIP-pipe, SPA8000 gateway, a SIP-trunk to our PBX for external calls.
It so happened that the cat knocked over a glass of juice on a laptop. I ordered a keyboard on aliexpress, but accidentally broke the cable when replacing it. While I save money on a new top-case and a train - you need to make a stand - in the morning, negotiations. There is no place on the new laptop for the virtual machine, Linux is installed - it's a pity the working system. Decided - it’s worth a try on a smartphone, at the same time to evaluate its capabilities for iron.

2. Installation

We have - Sony Xperia M Dual, the latest build of Cyanogenmod with 4.4.4, MicroSD on 32GB class 10. The method should work for most smartphones with root rights and (preferably) custom firmware.
Google Play has a great Linux Deploy utility . It allows you to install one or several different Linux distributions on a smartphone and run them in a chroot environment. I will not describe the installation process of linux, there is a very visual video with pleasant music on the program page on Google Play, but just in case I’ll duplicate it here.

Installing GNU / Linux on Android via Linux Deploy.



We install the system according to the instructions on the video, I did as well, just chose Debian Wheezy. Click the Start button in the Linux Deploy window, the system is installed and running.
Next, we can connect with our favorite SSH client using the IP address of our smartphone, and we get into the Linux environment. The default password for the user is changeme , in root via sudo -s . For the installed Debian (Ubuntu), update the system and install the necessary packages:

aptitude update
aptitude upgrade
aptitude install mc tmux htop asterisk


3. Configuration

After installation, configuration files will be created in the / etc / asterisk / directory. To minimize the configuration of the VoIP server, you must change them. Under the spoilers, examples of settings:

sip.conf
; Main
[general]
context=incoming_calls                 
allowguest=no                
;match_auth_username=yes        ; if available, match user entry using the
allowoverlap=no               ; Enable RFC3578 overlap dialing support.
udpbindaddr=0.0.0.0           
transport=udp                   
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
;pedantic=yes                   ; Enable checking of tags in headers,
disallow=all                   ; First disallow all codecs
allow=ulaw                     ; Allow codecs in order of preference
language=ru                    ; Default language setting for all users/peers
relaxdtmf=yes                  ; Relax dtmf handling
useragent=Asterisk PBX         ; Allows you to change the user agent string
dtmfmode = rfc2833             ; Set default dtmfmode for sending DTMF. Default: rfc2833
videosupport=yes               ; Turn on support for SIP video. You need to turn this
alwaysauthreject = yes         ; When an incoming INVITE or REGISTER is to be rejected,
autocreatepeer=no             ; Allow any UAC not explicitly defined to register
rtptimeout=60                  ; Terminate call if 60 seconds of no RTP or RTCP activity
recordhistory=yes              ; Record SIP history by default
dumphistory=yes                ; Dump SIP history at end of SIP dialogue
t38pt_udptl = yes,redundancy,maxdatagram=300 
faxdetect = no          ; Default 'no', 'yes' enables both CNG and T.38 detection
nat=no
jbenable = yes              ; Enables the use of a jitterbuffer on the receiving side of a
canreinvite=no
rfc2833compensate=yes
limitonpeers = yes
externrefresh=60
disallow=all
allow=ulaw,alaw
qualify=yes
echocancel=yes
echocancelwhenbridged=yes
register => 4732453344-101:veryStrongSecret@server.prov.ru
; Provider
[ext_template](!)
disallow=all
allow=ulaw,alaw
description=fakeExampleProvider ;)
type=peer
context=incoming_calls
nat=force_rport,comedia
host=server.prov.ru
fromdomain=server.prov.ru
insecure=port,invite
[trunk](ext_template)
fromuser=4732453344-101
defaultuser=4732453344-101
authname=4732453344-101
secret=veryStrongSecret
; GSM
;Templates
[global_template](!)
type=friend
qualify=yes
host=dynamic
nat=no
notifyringing=yes
call-limit=1
limitonpeers=yes
insecure=port,invite
secret=pass
callgroup=1
pickupgroup=1
context=outgoing_calls
;SIP users
[101](global_template)
[102](global_template)
[103](global_template)
[104](global_template)
[105](global_template)


extensions.conf
[default]
exten => _X.,1,Hangup()
[globals]
[features]
exten => ##,1,Pickup()
[incoming_calls]
;from-trunk
exten => s,1,NoOp(${CALLERID(num)})
same => n,Answer()
same => n,Queue(main,tr)
same => n,Hangup()
[outgoing_calls]
exten => _[23]XXXXXX,1,NoOp(${CALLERID(num)})
same => n,Dial(SIP/trunk/${EXTEN},,tTr)
same => n,Hangup()
exten => _8XXXXXXXXXX,1,NoOp(${CALLERID(num)})
same => n,Dial(SIP/trunk/${EXTEN},,tTr)
same => n,Hangup()
exten => _810XXXXXXXXXXXX,1,NoOp(${CALLERID(num)})
same => n,Dial(SIP/trunk/${EXTEN},,tTr)
same => n,Hangup()
include => internal_calls
[internal_calls]
exten => _10[12345],1,Dial(SIP/${EXTEN},,tTr)
same => n,Hangup()


queues.conf
[general]
persistentmembers = yes
autofill = yes
monitor-type = MixMonitor
updatecdr = yes
;musicclass = default
strategy = rrmemory
context = incoming_calls
timeout = 20
retry = 1
weight=0
wrapuptime=1
autofill=yes
maxlen = 0
announce-frequency = 0
relative-periodic-announce=no
announce-holdtime = no
announce-position = no
monitor-format = wav
ringinuse = no
[main]
strategy = rrmemory
ringinuse=no
member => SIP/101
member => SIP/102
member => SIP/103
member => SIP/104
member => SIP/105



When the configuration is written, start the service and go to the CLI:
asterisk && asterisk -vvvvr

When starting a service from init.d, the module chan_sip is not loaded, it writes an error chan_sip.c:28816 reload_config: Unable to create SIP socket: Permission denied. From the root it starts normally, it will come down for a demonstration.

All is ready. I connected an FXS gateway and two softphones to our new PBX. On my device (Xperia M Dual), the processor load of 4 active channels is somewhere around 10%, it doesn’t stutter, there are no lags. You can call internal 101-105 to each other, and communicate with the outside world through a trunk from the provider.

4. Possibilities of application:
a) demonstration of the work of Asterisk PBX
b) portable geek PBX =)
c) for home use (they put it on routers with openwrt, you can do it on a smartphone)
d) just for fun
Screenshot


Ask questions in the comments and in the PM, not only within the framework of the article. If possible, I can prompt and help with the setup.
Thanks for attention.

By first comment
Исправил " Я занимаюсь" на «Я работаю в компании, которая занимается», спасибо shadowalone, сначала просто не придал значения, приношу извинения. Но все же, мои финансовые проблемы -мое личное дело, не так ли? ;)

Also popular now: