We make a VoIP GSM gateway from Tp-link mr-3020 and Huawei E-171 - part two - add Siemens Gigaset c470IP and SMS
- Tutorial

There is such a standard ETSI 201 912 SMS for “landlines” (landline sms app. Sources) as it turned out it is supported by Gigaset c470IP and sms can be sent using VoIP, having learned this I wanted to do “sms relaying” ie everything that comes to the dongle is sent to the Gigaset C470 IP, and vice versa - to be able to send sms from C470IP to the outside world through the dongle, all this will happen as in the first part on tp-link mr-3020 under openwrt, the final one will also be shown configuration and some pictures.
For those who missed the first part , in it I talked about the basic installation of openwrt and asterisk on tp-link 3020 using pivotroot on the external flash memory of the card reader of the dongle huawei E-171.
The essence of the solution is quite simple, there is a special application for asterisk app_sms and with it the smsq binary for sending “landline” sms, for the dongle to work with sms we need the BASE64_DECODE function in addition to the chan-dongle .
But unfortunately, neither the binary nor the function, that in fact the asterisk module is not installed in openwrt, in order to assemble and install them, will have to be compiled from the source codes, in this case it is easier to immediately assemble the entire system (c) of the droidman. For convenience, I collected everything that I needed right away and made my repository, then corrected opkg.conf, IMHO it is better to collect too much than not to collect. A list of packages and important options in my opinion will be given at the end of the article. Now let's focus on the most important. All that is written below is at least relevant for openwrt BARRIER BREAKER (Bleeding Edge, r35905).
We note all the packages related to asterisk18 with the module, as mentioned above it’s easier to collect the excess and not install it, than to collect and track the dependencies.
In order to build smsq, add a patch before
building cat ./trunk/feeds/packages/net/asterisk-1.8.x/patches/011-smsq_fix.patch
--- a/utils/utils.xml
+++ b/utils/utils.xml
@@ -41,7 +41,7 @@
extended
- no
+ yes popt extended
After the build, we will need to transfer ./trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/asterisk-1.8.10.1/utils/smsq to the router in / usr / sbin /. Surely smsq at startup will produce "smsq: can't load library 'libstdc ++. So.6'" - is treated with:
cd /lib/
ln -s libuClibc-0.9.33.2.so libstdc++.so.6
You will also need to transfer ./trunk/build_dir/target-mips_r2_uClibc-0.9.33.2/asterisk-1.8.10.1/funcs/func_base64.so to the router in / usr / lib / asterisk / modules / from the assembly directory
. in the first part I did not give configs, here I will show everything, the voice part is made based on the links at the end of the first part, I will dwell on sms in more detail.
dongle.conf
[dongle0]
audio=/dev/ttyUSB1 ; tty port for audio connection; no default value
data=/dev/ttyUSB2 ; tty port for AT commands; no default value
context=dongle-incoming
group=0
rxgain=4;
txgain=5;
resetdongle=yes
u2diag=-1
usecallingpres=yes
callingpres=allowed_passed_screen
imei=Тутимейдонгла ; не забудьте сменить
root @ OpenWrt: / lib # cat /etc/asterisk/sip.conf
[general]
externip=10.10.10.10; Эти поля у меня на самом деле не используются
externaddr=10.10.10.10;
localnet=192.168.5.0/255.255.255.0; Это локалка, gigaset тоже в этой сети
context=private;
allowguest=no;
context=default ; Default context for incoming calls
udpbindaddr=0.0.0.0
tcpenable=yes ; Enable server for incoming TCP connections (default is no)
tcpbindaddr=0.0.0.0 ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces)
srvlookup=yes ; Enable DNS SRV lookups on outbound calls
[sg470ip]
type=friend
host=dynamic
secret=pass
context=from-sg470ip ; Контекст для siemens 470 IP, он единственный клиент
canreinvite=yes
dtmfmode=rfc2833
permit=192.168.5.200/255.255.255.255
qualify=yes
root @ OpenWrt: / lib # cat /etc/asterisk/extensions.conf
[general]
static=yes
writeprotect=no
clearglobalvars=no
[dongle-incoming]
include => dongle-incoming-sms-ussd
exten => s,1,Dial(SIP/sg470ip)
exten => h,n,Hangup()
[from-sg470ip]
exten => _7X.,1,Dial(Dongle/dongle0/holdother:+${FILTER(0-9,${EXTEN})})
exten => _+7X.,1,Dial(Dongle/dongle0/holdother:+${FILTER(0-9,${EXTEN})})
exten => _8X.,1,Dial(Dongle/dongle0/holdother:+7${FILTER(0-9,${EXTEN:1})})
exten => _007X.,1,Dial(Dongle/dongle0/holdother:+7${FILTER(0-9,${EXTEN:3})})
exten => 2000,1,NoOp(Receiving SMS from ${CALLERID(num)})
exten => 2000,n,Answer
exten => 2000,n,SMS(2000,as)
exten => 2000,n,System(/etc/asterisk/sms-out.sh)
exten => h,n,Hangup()
[dongle-incoming-sms-ussd]
exten => sms,1,Verbose(Incoming SMS from ${CALLERID(num)} ${BASE64_DECODE(${SMS_BASE64})})
exten => sms,n,System(echo '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME} - ${CALLERID(num)}: ${BASE64_DECODE(${SMS_BASE64})}' >> /var/log/asterisk/sms.txt)
exten => sms,n,System(/usr/sbin/smsq --mt --oa="${CALLERID(num)}" --mttx-callerid="2001" --mttx-channel="SIP/sg470ip" --ud="${BASE64_DECODE(${SMS_BASE64})}")
exten => sms,n,Hangup()
exten => ussd,1,Verbose(Incoming USSD: ${BASE64_DECODE(${USSD_BASE64})})
exten => ussd,n,System(echo '${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - ${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}' >> /var/log/asterisk/ussd.txt)
exten => ussd,n,System(/usr/sbin/smsq --mt --oa="0" --mttx-callerid="2001" --mttx-channel="SIP/sg470ip" --ud="${DONGLENAME}: ${BASE64_DECODE(${USSD_BASE64})}")
exten => ussd,n,Hangup()
We will analyze the last config regarding sms in more detail. The fact is that when the sms center is indicated in 470IP, then when sending messages, they come to * to the number and another 0 at the end, in C470IP I have the SMS center number 200 registered, so all outgoing sms arrive at 2000 cm. [from-sg470ip] further the asterisk answers and SMS (2000, as) means 2000 the name of the queue, a - reply, s - act as an SMS center, i.e. the message is saved in /var/spool/asterisk/sms/morx/2000.* where the asterisk is the date and time, for more information by SMS () you can refer to the links at the end of the post, then a script is executed that parses the saved file and sends it through dongle
/etc/asterisk/sms-out.sh
#!/bin/sh
SPOOL='/var/spool/asterisk/sms/morx'
for SMS in `ls -1 "$SPOOL"`; do
DST=`grep -e '^da=' "$SPOOL/$SMS" | sed 's/da=//'`
MSG=`grep -e '^ud=' "$SPOOL/$SMS" | sed 's/ud=//'`
valid="true"
if [ ${#DST} -gt 1 ] ; then
DSTPRFX=${DST:0:2}
if [ $DSTPRFX = "89" ] ; then
DST=`echo $DST | sed 's/8/\+7/'`
asterisk -rx "dongle sms dongle0 $DST $MSG"
else valid="false"
fi
else
if [ $DST = "0" ] ; then
asterisk -rx "dongle ussd dongle0 $MSG"
else valid="false"
fi
fi
if [ $valid = "false" ] ; then
echo "unknown dest number $DST" >> /var/log/asterisk/sms-out.log
smsq --mt --mttx-callerid="2001" --mttx-channel="SIP/sg470ip" --oa="200" --ud="ERR unknown dest $DST"
fi
rm -f "$SPOOL/$SMS"
done
Here, the fields are selected to whom and the body of SMS, then check is made, if the destination number starts at 89, then 8 is replaced by +7 (you can’t dial + in the number on Siemens) and a message is sent via the dongle, if the destination number is 0, then the body is sent as ussd the request, it’s done so that you can send USSD requests, for example, sending * 100 # to 0 with sgc470ip you can check the balance on the SIM card in the dongle :) If the conditions are not met, then write to the log and send an error message to the phone using smsq , note that when you reply from the SMS center, 1 is already added instead of 0 in n at least the SMS center (although it seems to work on siemens and with 0) the phone knowing this number does not ring as usual, but quietly tries to get the SMS, in short, the principle of the smsq command from the listing is to generate the file in / var / spool / sms / mttx / 0 . * generate.
[dongle-incoming-sms-ussd] in extensions.conf I think it’s already clear, this is for logging in via gsm channel “to the dongle” - logging and forwarding using smsq to 470ip, the same for incoming replies to USSD with the only difference that USSD will have “ussd” in caller-id, gigaset doesn’t like this, so there, when sending from (- oa), the parameter is set to “0”.
It looks like this:
SMS sent from a mobile phone to the number that started in the dongle with “+ ", it came 810

The SMS itself The

call, if there is a gigaset-a in the notebook The

call, if there is no gigaset-a in the book

The gigaset setting itself is trivial, as can be seen from the pictures, my provider is called GSM, the gigaset-a dial plan sends everything that starts at 89 to this provider (mr-3020), the SMS center settings are made from the tube, sms center number 200 , this center was selected for sending and the provider was selected, which is interesting, it may not coincide with the dialplan in the database, it will fly away anyway, as indicated in the SMS settings, several more SMS centers can also be set up, only for reception.
The list of packages that I use is not all necessary, but it’s better to give a complete
opkg list-installed
asterisk18 - 1.8.10.1-4
asterisk18-app-exec - 1.8.10.1-4
asterisk18-app-readexten - 1.8.10.1-4
asterisk18-app-senddtmf - 1.8.10.1-4
asterisk18-app-setcallerid - 1.8.10.1-4
asterisk18-app-sms - 1.8.10.1-4
asterisk18-app-system - 1.8.10.1-4
asterisk18-app-verbose - 1.8.10.1-4
asterisk18-chan-dongle - 1.1.r10-18
asterisk18-chan-local - 1.8.10.1-4
asterisk18-codec-alaw - 1.8.10.1-4
asterisk18-func-shell - 1.8.10.1-4
asterisk18-pbx-spool - 1.8.10.1-4
asterisk18-sounds - 1.8.10.1-4
base-files - 134-r35905
blkid - 2.21.2-1
block-mount - 0.2.0-10
busybox - 1.19.4-6
dnsmasq - 2.62-3
dropbear - 2012.55-2
e2fsprogs - 1.42.4-1
fdisk - 2.21.2-1
firewall3 - 2013-03-02
glib2 - 2.34.3-1
hotplug2 - 1.0-beta-4
httping - 1.5.2-1
iptables - 1.4.18-2
iw - 3.6-1
jshn - 2013-01-29-0bc317aa4d9af44806c28ca286d79a8b5a92b2b8
kernel - 3.8.2-1-f0811f6432963110cc6f2a1623174e3a
kmod-ath - 3.8.2+2013-02-22-1
kmod-ath9k - 3.8.2+2013-02-22-1
kmod-ath9k-common - 3.8.2+2013-02-22-1
kmod-cfg80211 - 3.8.2+2013-02-22-1
kmod-crypto-aes - 3.8.2-1
kmod-crypto-arc4 - 3.8.2-1
kmod-crypto-core - 3.8.2-1
kmod-crypto-hash - 3.8.2-1
kmod-crypto-manager - 3.8.2-1
kmod-fs-ext4 - 3.8.2-1
kmod-gpio-button-hotplug - 3.8.2-1
kmod-ipt-conntrack - 3.8.2-1
kmod-ipt-core - 3.8.2-1
kmod-ipt-nat - 3.8.2-1
kmod-ipt-nathelper - 3.8.2-1
kmod-leds-gpio - 3.8.2-1
kmod-ledtrig-default-on - 3.8.2-1
kmod-ledtrig-netdev - 3.8.2-1
kmod-ledtrig-timer - 3.8.2-1
kmod-ledtrig-usbdev - 3.8.2-1
kmod-lib-crc-ccitt - 3.8.2-1
kmod-lib-crc16 - 3.8.2-1
kmod-mac80211 - 3.8.2+2013-02-22-1
kmod-nls-base - 3.8.2-1
kmod-nls-utf8 - 3.8.2-1
kmod-ppp - 3.8.2-1
kmod-pppoe - 3.8.2-1
kmod-pppox - 3.8.2-1
kmod-scsi-core - 3.8.2-1
kmod-usb-core - 3.8.2-1
kmod-usb-ohci - 3.8.2-1
kmod-usb-serial - 3.8.2-1
kmod-usb-serial-option - 3.8.2-1
kmod-usb-serial-wwan - 3.8.2-1
kmod-usb-storage - 3.8.2-1
kmod-usb-uhci - 3.8.2-1
kmod-usb2 - 3.8.2-1
kmod-wdt-ath79 - 3.8.2-1
libblkid - 2.21.2-1
libblobmsg-json - 2013-01-29-0bc317aa4d9af44806c28ca286d79a8b5a92b2b8
libc - 0.9.33.2-1
libcom_err - 1.42.4-1
libcyassl - 1.6.5-2
libext2fs - 1.42.4-1
libffi - 3.0.11-1
libgcc - 4.6-linaro-1
libiconv-full - 1.11.1-1
libip4tc - 1.4.18-2
libip6tc - 1.4.18-2
libiwinfo - 39
libiwinfo-lua - 39
libjson - 0.9-2
liblua - 5.1.5-1
libncurses - 5.7-5
libnet1 - 1.1.2.1-2
libnl-tiny - 0.1-3
libopenssl - 1.0.1e-1
libpcap - 1.1.1-2
libpopt - 1.7-5
libpthread - 0.9.33.2-1
librpc - 0.9.32-rc2-0a2179bbc0844928f2a0ec01dba93d9b5d6d41a7
librt - 0.9.33.2-1
libubox - 2013-01-29-0bc317aa4d9af44806c28ca286d79a8b5a92b2b8
libubus - 2013-01-13-bf566871bd6a633e4504c60c6fc55b2a97305a50
libubus-lua - 2013-01-13-bf566871bd6a633e4504c60c6fc55b2a97305a50
libuci - 2013-01-04.1-1
libuci-lua - 2013-01-04.1-1
libusb-1.0 - 1.0.9-1
libusb-compat - 0.1.4-1
libustream-cyassl - 2013-01-22-da607e6272d789ed5dae3b0efff90912fda6f81f
libuuid - 2.21.2-1
libxtables - 1.4.18-2
lua - 5.1.5-1
luci - trunk+svn9678-1
luci-app-diag-core - trunk+svn9678-1
luci-app-diag-devinfo - trunk+svn9678-1
luci-app-firewall - trunk+svn9678-1
luci-i18n-english - trunk+svn9678-1
luci-i18n-russian - trunk+svn9678-1
luci-lib-core - trunk+svn9678-1
luci-lib-ipkg - trunk+svn9678-1
luci-lib-nixio - trunk+svn9678-1
luci-lib-sys - trunk+svn9678-1
luci-lib-web - trunk+svn9678-1
luci-mod-admin-core - trunk+svn9678-1
luci-mod-admin-full - trunk+svn9678-1
luci-proto-core - trunk+svn9678-1
luci-proto-ppp - trunk+svn9678-1
luci-sgi-cgi - trunk+svn9678-1
luci-ssl - trunk+svn9678-1
luci-theme-base - trunk+svn9678-1
luci-theme-openwrt - trunk+svn9678-1
mac-to-devinfo - 1.0.0-2
mc - 4.7.5.3-2
mtd - 20
nano - 2.2.6-1
netdiscover - 0.3-beta6-3
netdiscover-to-devinfo - 1.0.0-2
netifd - 2013-02-19-486aa750a164d41905beb61afec89268e3eb7f48
opkg - 618-3
ppp - 2.4.5-9
ppp-mod-pppoe - 2.4.5-9
procd - 2012-12-20-d343dd9e9a64d4ae7d225ea29169e97fa8d116a1
px5g - 1
smap - 0.6.0-2
smap-to-devinfo - 1.0.0-2
swap-utils - 2.21.2-1
swconfig - 10
terminfo - 5.7-5
uboot-envtools - 2012.04.01-1
ubus - 2013-01-13-bf566871bd6a633e4504c60c6fc55b2a97305a50
ubusd - 2013-01-13-bf566871bd6a633e4504c60c6fc55b2a97305a50
uci - 2013-01-04.1-1
uhttpd - 2013-01-22-14e3971c37e6feb0ec5eda0988e07d8a786ba9f9
uhttpd-mod-ubus - 2013-01-22-14e3971c37e6feb0ec5eda0988e07d8a786ba9f9
usb-modeswitch - 1.2.5-1
usb-modeswitch-data - 20121109
wpad-mini - 20130302-1
zlib - 1.2.7-1
Nuances:
In no case do you need to create folders of the form / overlay / var or / overlay / tmp otherwise they will start to be saved to flash, this causes 2 problems at once: speed and restoration of irrelevant files from the previous download, i.e. if you see, for example, in the asterisk console: WARNING [1751]: db.c: 115 dbinit: Unable to open Asterisk database '/ var / lib / asterisk / astdb': No such file or directory The
correct solution would be to add mkdir -p / var / lib / asterisk in the appropriate place in /etc/init.d/boot
Busybox in openwrt is built by default without unicode support, use the CONFIG_BUSYBOX_CONFIG_UNICODE_SUPPORT = y option.
Crooked hands did not allow soldering to mini-USB, but the similarity of POE was possible at a distance of about 15 meters, a simple injector, a power supply from d-link usb-hub 5V 3A and a redesigned “barrel” from the side of the router were used.


And finally, the picture that should have been be the first :)

UPD: don't forget to do make dirclean after updating svn otherwise there may be problems with the build.
UPD: what I got: www.dropbox.com/sh/xjldxibmzo6bdye/88eCAN2j9S
Useful links on the topic:
www.voip-info.org/wiki/index.php?page=Asterisk+cmd+SMS
wiki.e1550.mobi /doku.php?id=usage
www.automated.it/asterisk/sms.html
forum.ixbt.com/topic.cgi?id=88 : 1699-26
forum.asterisk.ru/viewtopic.php?f=3&t= 1160 & start = 10
Part 1