📜 ⬆️ ⬇️

Raises telephony from scratch: Asterisk, FreePBX, GSM Gateway on Huawei E173 in Debian



First, a little background. Not so long ago, our company almost lost its city connection, one telephone operator, did not share something with another, and as a result calls between them stopped. It was decided, since it so happened to completely abandon the usual telephone connection and fully switch to ip-telephony.
Formulation of the problem:
1) Organize a telephone connection;
2) Record conversations;
3) The queue of calls;
4) Voice menu;
5) GSM gateway, as well as calls from mobile operators must be processed.
6) The minimum cost of the solution, since the situation is force majeure and the budget has not been allocated.

Never before did I work with telephony, the urgent task arose, I’ll try to tell you in detail how I personally solved it, about which I stepped on a rake, if something was done that wasn’t quite optimal, or I’ll generally be grateful for corrections and additions, and so we went.

')
Choosing a platform.

First of all, I decided to see the finished builds listed on the asterisk.ru website, the finished images of AsteriskNOW, FreePBX, Elastix were downloaded, the rest of the documentation was just read. TrixBox was immediately folded because of its payment, as it contradicted paragraph 6. AsteriskNOW seemed damp and unmodified, FreePBX, Elastix liked both the logical and convenient builds, but did not want to be friends with the available Huawei E173 modem, and were also built on CentOS with a fairly old core and did not fit into the common server fleet on Debian. I decided to collect everything from scratch, thereby gaining invaluable experience.

Assembling the working environment, linking elements and setting.

So we have a freshly installed Debian 6 Squeeze, minimal installation.
We add necessary further repositories in
/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 knock out.
 apt-get update && apt-get upgrade 

From backports we put a fresh kernel, 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 a one-time and small, it was too lazy to put the apache + php + necessary modules separately, I decided to use a good, in my opinion, assembly of Zend Server CE.
We will put everything 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 

Setting up a 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 which the Apache, on asterisk works.
 sed -i "s/\(^User *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf sed -i "s/\(^Group *\)\(.*\)/\1asterisk/" /etc/apache2/apache2.conf 


We change the parameters of php (it is possible through a special server admin panel accessible via the link _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 in the 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 

Turning off unnecessary modules, I don’t need dahdi at all, but on forums and in documentation it is advised to collect it anyway.
 nano /etc/dahdi/modules /etc/init.d/dahdi start cd /tmp/asterisk-1.8.15.1/ 

if we plan to turn on mp3 we perform
 ./contrib/scripts/get_mp3_source.sh 

if not immediately
 ./configure make menuselect 

Enable 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 get a non-existing directory error
 mkdir /var/lib/asterisk/phoneprov 

and again
 make samples 


Create and populate the database required 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 


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 freepbx-2.10.0 version is available on the FreePBX website, but its installer for Debian behaved very strange, I had to apply several patches from bug reports, but I didn’t like its further behavior and decided to use freepbx-2.9.0 for install, and then upgrade. After a successful installation, we go to the web interface at _http: // IP server / freepbx and update the system, the update process is well described in the interface itself and a separate link is made, so I will not dwell on this in detail, the update runs quickly and smoothly and 10 minutes we have the latest version of the system.

We fasten the huaway E173 modem

The modem was previously unlocked by all operators and voice functions were unlocked in it. At this moment I will not dwell in detail, everything is rather trivial and is not included in the topic being described, but if anyone is interested I will answer.

To determine the imputed 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 ID:
  lsusb 

  Bus 002 Device 050: ID 12d1:140c Huawei Technologies Co., Ltd. 


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 example:

 # 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 by changing the DefaultProduct to:
 DefaultProduct= 0x140c 

We are overloaded, after which the modem has a sane name, we continue to connect 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 parameters of the module under 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 editor nano Ctrl + X

Create content in the dialplan (Do not forget to turn off the pincode 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 

Check modem status:
 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 we add routes for this modem in the FreePBX admin area.

Outbound route:
In the web interface (FreePBX 2.10) - Connectivity -> Trunks -> Add Custom Trunk
Trunk name - We write the name so as not to forget, for example, GSM-modem
The last item - Custom dial string - specify
 datacard/i:00000000000000/$OUTNUM$ 

where 0000000000000 - IMEI 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 choose 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 modem)
in 'Set destination' select the recipient of calls received on the modem.

We include the Russian-language voice acting for the protocols, for example for SIP, through the WEB interface
Settings -> Asterisk SIP Settings -> language -> en

Create the 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 perform
 chmod +x /etc/init.d/amportal-startup 

Add to autoload.
 insserv amportal-startup 


FreePBX is partially translated into Russian, but its inclusion did not initially work for me in order to fix it by doing the following manipulations.
Fixing the /usr/share/locale/locale.alias file

Remove the line with the encoding for russian and add 3 lines instead of it:
 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.

At this, the working day is over, the rest of the work is postponed until tomorrow, I apologize for some confusion in my thoughts, I am writing hot traces and a pleasant feeling that the system has earned, made a test call from the modem and accepted the call to the modem, the connection is clean, I’ll continue the configuration inclusion and verification.

For setup I used the documentation from the FreePBX , asterisk-pbx , blog.911.in.ua sites , official project documentation and search engines.

UPD. Continued from my colleague.

Source: https://habr.com/ru/post/151011/


All Articles