
Raises telephony from scratch: Asterisk, FreePBX, GSM-gateway on Huawei E173 in Debian
- From the sandbox
- Tutorial

First, a little background. Not so long ago, our company almost lost its urban connection, one telephone operator didn’t share something with another and as a result, calls stopped passing between them. It was decided, since it happened so completely abandon regular telephone communications and completely switch to ip-telephony.
Statement of the problem:
1) Organize telephone communications;
2) Recording conversations;
3) Call Queue;
4) Voice menu;
5) GSM-gateway, as well as calls from mobile operators should be processed.
6) The minimum cost of the decision, as the situation is force majeure and the budget has not been allocated.
I’ve never worked with telephony before, the task was urgent, I’ll try to tell in detail how I personally solved it, about the rake that I stepped on, if what was done was not entirely optimal or I will be gratefully crooked for corrections and additions, and so we went.
The choice of platform.
First of all, I decided to look at the ready-made assemblies indicated on the site asterisk.ru , ready-made images of AsteriskNOW, FreePBX, Elastix were downloaded, the documentation was just read about the rest. TrixBox was immediately thrown back due to its fee, as it contradicted point 6. AsteriskNOW seemed damp and unfinished, FreePBX, Elastix liked both logical and convenient assemblies, but didn’t want to be friends with the available Huawei E173 modem, they were also built on CentOS with a fairly old kernel and did not fit into the general server park on Debian. He decided to collect everything from scratch, thereby gaining invaluable experience.
Assembling the working environment, linking elements and customization.
So we have a freshly installed Debian 6 Squeeze, minimal installation.
Add the repositories necessary in the future to
/etc/apt/sources.list
deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free
deb http://www.deb-multimedia.org stable main non-free
deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all
deb http://repos.zend.com/zend-server/deb server non-free
Install the keys
apt-get update && apt-get install deb-multimedia-keyring
wget http://www.dotdeb.org/dotdeb.gpg -O- |apt-key add -
wget http://repos.zend.com/zend.key -O- |apt-key add -
We get hold of ourselves.
apt-get update && apt-get upgrade
From backports we put a fresh core, which is necessary for the correct operation of the GSM modem
apt-get install -t squeeze-backports linux-image-3.2.0-0.bpo.3-amd64
apt-get install -t squeeze-backports linux-headers-3.2.0-0.bpo.3-amd64
Reboot
reboot
We put a web server.
Since the load on the web server is planned to be one-time and small, it was too lazy to install the necessary modules separately apache + php +, I decided to use a good, in my opinion, build Zend Server CE.
We will put everything all at once.
aptitude install zend-server-ce-php-5.3 php-5.3-source-zend-server control-panel-zend-server bison libaudiofile-dev libssl-dev checkinstall mpg123 libmpg123-0 libmpg123-dev xmms2-plugin-mpg123 mysql-server libmysqlclient15-dev php-db php-pear sox curl g++ libncurses-dev libxml2-dev subversion libspandsp-dev lame libmp3lame-dev
Configuring the Zend Web Server
echo "PATH=$PATH:/usr/local/zend/bin" >> /etc/profile
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zend/lib" >> /etc/profile
source /etc/profile
chown zend:adm -R /var/log/apache2/
mkdir /var/www/freepbx/
adduser asterisk --disabled-password --gecos "Asterisk PBX"
We change the user from under whom the apache works, on asterisk.
sed -i "s/\(^User *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf
sed -i "s/\(^Group *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf
We change the php settings (it is possible through a special server admin panel, available at _https: // IP: 10082 / ZendServer or _http: // IP: 10081 / ZendServer.).
post_max_size = 32M
max_execution_time = 60
max_input_time = 60
memory_limit = 256M
upload_max_filesize = 16M
date.timezone = "Europe/Kiev"
Download the necessary sources
cd /tmp
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.8.15.1.tar.gz
tar xvzf asterisk-1.8.15.1.tar.gz
wget http://mirror.freepbx.org/freepbx-2.9.0.tar.gz
tar xvzf freepbx-2.9.0.tar.gz
wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4.12.tar.gz
tar xvzf libpri-1.4.12.tar.gz
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-2.6.1+2.6.1.tar.gz
tar xvzf dahdi-linux-complete-2.6.1+2.6.1.tar.gz
We collect them for the convenience of further updates immediately into packages.
cd libpri-1.4.12/
make
checkinstall -D
cd /tmp/dahdi-linux-complete-2.6.1+2.6.1/
make all
mkdir /etc/hotplug
mkdir /etc/hotplug/usb/
mkdir /etc/dahdi
checkinstall -D
make config
We disconnect unnecessary modules, in general I did not need dahdi, but on the forums and in the documentation it is advised to collect with it anyway.
nano /etc/dahdi/modules
/etc/init.d/dahdi start
cd /tmp/asterisk-1.8.15.1/
if we plan to enable mp3
./contrib/scripts/get_mp3_source.sh
if not, right away
./configure
make menuselect
We include the following options in menuconfig;
app_mysql, app_saycountpl, cdr_mysql, format_mp3, res_config_mysql, EXTRAS-SOUNDS-EN-GSM EXTRAS-SOUNDS-RU-GSM (the necessary codecs and languages) and other necessary options.
make
checkinstall -D
make config
make samples
If you received an error of a non-existing directory
mkdir /var/lib/asterisk/phoneprov
and again
make samples
Create and populate the database necessary for FreePBX
cd /tmp/freepbx-2.9.0
mysqladmin -uroot create asterisk -p'Password'
mysqladmin -uroot create asteriskcdrdb -p'Password'
mysql -uroot -p'Password' asterisk < SQL/newinstall.sql
mysql -uroot -p'Password' asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql -uroot -pPassword # Password - Ваш пароль для рутового пользователя MySQL
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'amp109'; # amp109 - Ваш пароль для пользователя asteriskuser в MySQL
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'amp109'; # amp109 - Ваш пароль для пользователя asteriskuser в MySQL
flush privileges;
quit;
Run Asterisk before installing FreePBX
/etc/init.d/asterisk start
We configure FreePBX to work with Asterisk:
cd /tmp/freepbx-2.9.0
pear install DB
./install_amp
We use all the default parameters, only the path is set to / var / www / freepbx / , which we created earlier.
Now a small digression, the version of freepbx-2.10.0 is available on the FreePBX website , but its installer for Debian behaved very strangely, I had to apply several patches from bug reports, but its further behavior was also not pleasant and it was decided to use freepbx-2.9.0 for installation, and then upgrade. After a successful installation, go to the web interface at _http: // IP server / freepbx and update the system, the update process is well described in the interface and a separate link is made, so I won’t dwell on it in detail, the update goes quickly and smoothly and through 10 minutes we have the latest version of the system.
We fasten the huaway E173 modem
The modem was previously unlocked for all operators and voice functions were unlocked in it. I will not dwell on this point in detail, everything is quite trivial and is not included in the topic being described, but if anyone is interested I will answer.
To determine the sane name of the modem
apt-get install -t squeeze-backports usb-modeswitch usb-modeswitch-data
We insert the modem and execute
dmesg | tail
We get a conclusion similar to
[ 303.594149] usb 1-7: New USB device found, idVendor=12d1, idProduct=1001
[ 303.594155] usb 1-7: New USB device strings: Mfr=3, Product=2, SerialNumber=0
[ 303.594158] usb 1-7: Product: HUAWEI Mobile
[ 303.594161] usb 1-7: Manufacturer: HUAWEI Technology
[ 303.596731] option 1-7:1.0: GSM modem(1-port) converter detected
[ 303.596968] usb 1-7: GSM modem (1-port) converter now attached to ttyUSB0
[ 303.597241] option 1-7:1.1: GSM modem (1-port) converter detected
[ 303.597373] usb 1-7: GSM modem (1-port) converter now attached to ttyUSB1
[ 303.597584] option 1-7:1.2: GSM modem (1-port) converter detected
[ 303.597716] usb 1-7: GSM modem (1-port) converter now attached to ttyUSB2
If it doesn’t work, find out the device identifier:
lsusb
Bus 002 Device 050: ID 12d1:140c Huawei Technologies Co., Ltd.
We check the presence of the file “12d1: *” in /etc/usb_modeswitch.d , in one of the files there
should be a mention of the product “1446”. For instance:
# Huawei E270+ (HSPA+ modem)
DefaultVendor= 0x12d1
DefaultProduct=0x1446
TargetVendor= 0x12d1
TargetProductList="1001,1406,140c,14ac"
CheckSuccess=20
MessageContent="55534243123456780000000000000011060000000000000000000000000000"
If the file does not exist, then it can be created using the above example, simply changing DefaultProduct to:
DefaultProduct= 0x140c
We reboot, after which the modem has a sane name, continue to associate it with Asterisk
svn co https://www.makhutov.org/svn/chan_datacard/trunk/ /tmp/chan_datacard
cd /tmp/chan_datacard
automake
./configure
cp etc/datacard.conf /etc/asterisk/
We configure the module parameters for our modem:
nano /etc/asterisk/datacard.conf
at the very bottom of the configuration file, delete all data (Ctrl + k) after the last line and paste this config
[000101]
context=from-gsm ; context для входящих звонков
audio=/dev/ttyUSB1 ; tty порт для аудио подключения
data=/dev/ttyUSB2 ; tty порт для управляющих AT комманд модема
group=1 ; Группа вызова
rxgain=10 ; Изменение громкости динамика
txgain=-5 ; Изменение громкости микрофона
autodeletesms=yes ; auto delete incoming sms
resetdatacard=yes ; reset datacard during initialization
u2diag=256 ; set U2DIAG parameter (256 = включить модем и кард ридер)
usecallingpres=yes ; use the caller ID presentation or not
callingpres=allowed_passed_screen ; set caller ID presentation
write the changes Ctrl + O and exit the nano editor Ctrl + X
Create the content in the dialplan (Do not forget to turn off the PIN code on the SIM):
nano /etc/asterisk/extensions_custom.conf
[from-gsm]
exten => s,1,Set(CALLERID(all)=${CALLERID(num)})
exten => s,n,Set(CALLERID(num)=8${CALLERID(num):2})
exten => s,n,goto(from-trunk,${IMEI},1)
Restart Asterisk
service asterisk restart
Checking the status of the modem:
asterisk -r
datacard show devices
cam*CLI> datacard show devices
ID Group State RSSI Mode Submode Provider Name Model Firmware IMEI IMSI Number
000101 1 Free 23 0 0 DJUICE E173 11.126.16.04.174 867767ХХХХХХХ 255030580735317 +38097ХХХХХХХ
Now in the FreePBX admin panel we add routes for this modem.
Outgoing route:
In the web interface (FreePBX 2.10) - Connectivity -> Trunks -> Add Custom Trunk
Trunk name - Write a name so as not to forget, for example GSM-modem
Last point - Custom dial string - specify
datacard/i:00000000000000/$OUTNUM$
where 0000000000000 is the IMEI of the modem (visible in the previous paragraph).
In the web interface (FreePBX 2.10) - Connectivity -> Outbound routes -> ADD route
Name for example Outbound
match patern ->. (put a dot in this field),
in Trunk Sequence for Matched Routes, select our trunk.
Incoming route:
In the web interface (FreePBX 2.10) - Connectivity -> Inbound routes -> ADD Incoming route
Name for example Inbound
DID number -> 0000000000000 (IMEI of the modem)
in 'Set destination' select the recipient of calls coming to the modem.
We enable Russian-language dubbing for protocols, for example, for SIP, through the WEB-interface
Settings -> Asterisk SIP Settings -> language -> ru
Create a FreePBX autorun script: /etc/init.d/amportal-startup
#!/bin/sh
# /etc/init.d/amportal-startup
#
### BEGIN INIT INFO
# Provides: Asterisk
# Required-Start: $remote_fs $syslog $all
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Asterisk at boot time
# Description: Enable Asterisk.
### END INIT INFO
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
export PATH
case "$1" in
start)
amportal start
;;
stop)
amportal stop
;;
*)
echo "Usage: /etc/init.d/amportal-startup {start|stop}"
exit 1
;;
esac
exit 0
We give him the right to execute
chmod +x /etc/init.d/amportal-startup
Add to startup.
insserv amportal-startup
FreePBX is partially translated into Russian, but its inclusion did not initially work for me, so we can do the following manipulations to fix it.
We fix the file /usr/share/locale/locale.alias
Delete the line with the encoding for russian and add 3 lines instead:
russian ru
ru ru_RU
ru_RU ru_RU.UTF-8
then regenerate the locale
locale-gen ru_RU.utf8
and everything starts to work.
This ended the working day, the rest of the work was postponed to tomorrow, I apologize for some confusion in my thoughts, I write in hot pursuit and with a pleasant feeling that the system worked, made a test call from the modem and accepted the call to the modem, the connection is clear, I will continue to describe the settings as I continue inclusion and verification.
I used documentation from FreePBX , asterisk-pbx , blog.911.in.ua sites , official project documentation and search engines to configure .
UPD Continued from my colleague.