📜 ⬆️ ⬇️

Making a VoIP GSM Gateway from Tp-link mr-3020 and Huawei E-171 - part one

A tale about how to take a couple of small devices and get something more or TP-LINK MR3020 + Huawei E171 = VoIP <-> GSM



Only a woman can chat for two hours on the phone, and then ask: “Who am I talking to?” - and find out that the person just got the wrong number.


This tale led me to 2 women and a phone bill. It so happened that cellular communication practically does not work at home - either to go to the balcony or use a home dect, or rather, it is not quite dect - it is dect PSTN + IP, the latter was the decisive factor.
')
Immediately make a reservation, who is well acquainted with openwrt will not find anything new for themselves.

So TP-Link mr-3020 router and Huawei e-171 dongle, in principle, fit another one, but for convenience, not to take a soldering iron in hand is better than ever with a flash drive on board.


First of all, you need to unlock the modem, it’s already a habit, to think about something that you may never need :)
Focus on this will not, a lot of places, I liked it here

Then we transfer the modem to the Modem + CardReader mode.
To do this, use the AT command.
AT^U2DIAG=256 

and turn on the voice function
 AT^CVOICE=0 


Let us put aside the modem and return to the router, you need to install openwrt on it, who can just flash the native firmware from the web interface, I had openwrt, so I go to mr-3020 and reinstall it in the console
 cd /tmp/ wget http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin mtd -r write /tmp/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin firmware 

I specifically used the trunk version, since RC1 has an extra web interface at this stage, but RC1 can also be used.

After the reboot, set the basic settings.

 passwd vi /etc/config/network 


 config interface 'lan' option ifname 'eth0' option type 'bridge' option proto 'static' option ipaddr '192.168.5.5' option netmask '255.255.255.0' option gateway '192.168.5.254' list dns '8.8.8.8' list dns '192.168.5.254' 


 echo /etc/config/ >> /etc/sysupgrade.conf reboot 


Install the necessary packages, will have to be transferred to the microSD rootfs, more precisely according to the openwrt terminology, it will be pivotroot.
 opkg install kmod-usb-storage block-mount kmod-fs-ext4 kmod-usb-uhci kmod-usb2 

If you put the trunk, not RC1, then e2fsprogs and fdisk should fit, then you can prepare the flash drive directly in the router, otherwise you will have to do it on a third-party machine.
 opkg install e2fsprogs fdisk 

If you intend to use swap on a flash, be sure to check for swap-utils
We mark up flash, I do not use swap here.
 fdisk /dev/sda 

create a partition, format and clone overlay
 mkfs.ext4 /dev/sda1 mount /dev/sda1 /mnt/ tar -C /overlay -cvf - . | tar -C /mnt/ -xvf - 


Next we bring / etc / config / fstab to the form:

 config mount option target /overlay option device /dev/sda1 option fstype ext4 option options rw,sync option enabled 1 option enabled_fsck 0 


And here the most interesting thing began, if you do a coldreset i. turn off the power, then the pivotroot is not mounted in any way, after loading the device appears / dev / sda, and / dev / sda1 is not present, or until it is “touched” in some way / dev / sda ie do not blkid / dev / sda or head / dev / sda or mount / dev / sda / mnt, after any of these methods, or after poking the dongle, everything appears, but as the saying goes, the train is gone and / overlay is already mounted like without a flash , the place is sorely lacking, it was very tempting to just add a reboot somewhere in the start scripts, since If you do a hotreset using reboot in the console, everything worked as if by magic.

Here is an example of a cold start, part of the output, in which you can see how it goes to jffs2, where it is expected to see a pivotroot with ext4

 - merge overlay components - [ 7.720000] SCSI subsystem initialized [ 7.900000] usbcore: registered new interface driver usbfs [ 7.900000] usbcore: registered new interface driver hub [ 7.910000] usbcore: registered new device driver usb [ 8.410000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 8.420000] ehci-platform ehci-platform: Generic Platform EHCI Controller [ 8.430000] ehci-platform ehci-platform: new USB bus registered, assigned bus number 1 [ 8.460000] ehci-platform ehci-platform: irq 3, io mem 0x1b000000 [ 8.480000] ehci-platform ehci-platform: USB 2.0 started, EHCI 1.00 [ 8.480000] hub 1-0:1.0: USB hub found [ 8.480000] hub 1-0:1.0: 1 port detected [ 8.500000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 8.540000] uhci_hcd: USB Universal Host Controller Interface driver [ 8.600000] Initializing USB Mass Storage driver... [ 8.610000] usbcore: registered new interface driver usb-storage [ 8.610000] USB Mass Storage support registered. [ 8.810000] usb 1-1: new high-speed USB device number 2 using ehci-platform [ 8.970000] scsi0 : usb-storage 1-1:1.3 [ 9.970000] scsi 0:0:0:0: Direct-Access HUAWEI SD Storage 2.31 PQ: 0 ANSI: 2 [ 9.980000] sd 0:0:0:0: [sda] Attached SCSI removable disk switching to jffs2 - init - 

and consequences
 root@OpenWrt:~# ls /dev/|grep sda sda root@OpenWrt:~# df -h Filesystem Size Used Available Use% Mounted on rootfs 1.3M 1.2M 152.0K 89% / /dev/root 1.5M 1.5M 0 100% /rom tmpfs 14.2M 60.0K 14.1M 0% /tmp tmpfs 512.0K 0 512.0K 0% /dev /dev/mtdblock3 1.3M 1.2M 152.0K 89% /overlay overlayfs:/overlay 1.3M 1.2M 152.0K 89% / 


Having tried various options, oddly enough, except for the mount, nothing helped, what helped to “push” / dev / sda after the boot did not help anything during the boot, saved the mount.
I had to fix / lib / preinit / 50_determine_usb_root
 vi /lib/preinit/50_determine_usb_root [ -n "$extroot_settle_time" ] && [ "$extroot_settle_time" -gt 0 ] && { sleep $extroot_settle_time echo -----dirty workaround Huawei gsm dongle cardreader ----- sleep 2 mount /dev/sda /mnt sleep 10 } 


After that, everything turned out
 - merge overlay components - [ 7.720000] SCSI subsystem initialized [ 7.900000] usbcore: registered new interface driver usbfs [ 7.910000] usbcore: registered new interface driver hub [ 7.920000] usbcore: registered new device driver usb [ 8.420000] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver [ 8.420000] ehci-platform ehci-platform: Generic Platform EHCI Controller [ 8.430000] ehci-platform ehci-platform: new USB bus registered, assigned bus number 1 [ 8.470000] ehci-platform ehci-platform: irq 3, io mem 0x1b000000 [ 8.490000] ehci-platform ehci-platform: USB 2.0 started, EHCI 1.00 [ 8.490000] hub 1-0:1.0: USB hub found [ 8.490000] hub 1-0:1.0: 1 port detected [ 8.510000] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver [ 8.550000] uhci_hcd: USB Universal Host Controller Interface driver [ 8.620000] Initializing USB Mass Storage driver... [ 8.620000] usbcore: registered new interface driver usb-storage [ 8.630000] USB Mass Storage support registered. [ 8.820000] usb 1-1: new high-speed USB device number 2 using ehci-platform [ 8.980000] scsi0 : usb-storage 1-1:1.3 [ 9.980000] scsi 0:0:0:0: Direct-Access HUAWEI SD Storage 2.31 PQ: 0 ANSI: 2 [ 9.990000] sd 0:0:0:0: [sda] Attached SCSI removable disk -----dirty workaround Huawei gsm dongle cardreader ----- [ 30.670000] sd 0:0:0:0: [sda] 3854336 512-byte logical blocks: (1.97 GB/1.83 GiB) [ 30.680000] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA [ 30.690000] sda: sda1 [ 41.850000] EXT4-fs (sda1): recovery complete [ 42.130000] EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: (null) switching to external rootfs - init - 


and the result

 root@OpenWrt:~# df -h Filesystem Size Used Available Use% Mounted on rootfs 1.8G 37.1M 1.7G 2% / /dev/root 1.5M 1.5M 0 100% /rom tmpfs 14.2M 408.0K 13.8M 3% /tmp tmpfs 512.0K 0 512.0K 0% /dev /dev/sda1 1.8G 37.1M 1.7G 2% /overlay overlayfs:/overlay 1.8G 37.1M 1.7G 2% / 


We deliver, what could not be delivered without pivotroot. there was not enough space and something that I just wanted, here you can add mc, luci, etc. to your taste.

opkg install kmod-usb-serial kmod-usb-serial-option usb-modeswitch usb-modeswitch-data

After installing kmod-usb-serial, we check for ttyUSB

 ls /dev | grep USB ttyUSB0 ttyUSB1 ttyUSB2 


we study wiki.openwrt.org/ru/doc/howto/build and take the source codes for the version that we have on tp-link trunk or release / release candidate

we swing asterisk-chan-dongle, it is necessary, for work of asteriska with "whistle"
code.google.com/p/asterisk-chan-dongle/downloads/list

unpack and copy to package tree
cp -vrf chan_dongle-1.1.r14 / contrib / openwrt / asterisk18-chan-dongle attitude_adjustment / feeds / packages / net /

rule feeds / packages / net / asterisk18-chan-dongle / Makefile under our version of asterisk
 WITH_ASTERISK=asterisk-1.8.3.2 

to (root @ OpenWrt: ~ # asterisk -V if grep PKG_VERSION: = ./feeds/packages/net/asterisk-1.8.x/Makefile is not compiled)
 WITH_ASTERISK=asterisk-1.8.10.1 

otherwise it will not meet.

And collect package chan-dongle
 Target System (Atheros AR7xxx/AR9xxx) ---> Target Profile (TP-LINK TL-MR3020) ---> Network ---> asterisk18 (Complete Open Source PBX), v1.8.x ---> <M> asterisk18-chan-dongle..................... Huawei UMTS 3G dongle support 


We copy collected on tp-link.
 scp attitude_adjustment/bin/ar71xx/packages/asterisk18-chan-dongle_1.1.r10-18_ar71xx.ipk root@192.168.5.5:/overlay/ 

It is also better to transfer libiconv-full and asterisk18 with which chan-dongle was going in my case this
attitude_adjustment / bin / ar71xx / packages / libiconv-full_1.11.1-1_ar71xx.ipk
attitude_adjustment / bin / ar71xx / packages / asterisk18_1.8.10.1-2_ar71xx.ipk
otherwise there is a great chance to see many new things like this:
 OpenWrt*CLI> module load chan_dongle.so Unable to load module chan_dongle.so Command 'module load chan_dongle.so' failed. WARNING[1854]: loader.c:777 inspect_module: Module 'chan_dongle.so' was not compiled with the same compile-time options as this version of Asterisk. WARNING[1854]: loader.c:778 inspect_module: Module 'chan_dongle.so' will not be initialized as it may cause instability. WARNING[1854]: loader.c:861 load_resource: Module 'chan_dongle.so' could not be loaded. 

Although I must say that I installed libiconv-full opkg from the Internet, but asterisk and chan-dongle took those that I collected myself, because I did them in rc1 and there was already another version of asterisk in the trunk.

Install and verify.
 opkg install /overlay/asterisk18_1.8.10.1-2_ar71xx.ipk libiconv-full /overlay/asterisk18-chan-dongle_1.1.r10-18_ar71xx.ipk /etc/init.d/asterisk start asterisk -rv OpenWrt*CLI> dongle show devices ID Group State RSSI Mode Submode Provider Name Model Firmware IMEI IMSI Number dongle0 0 Free 22 0 0 Beeline E171 11.126.85.01.143 **********1 2**************** Unknown 


The asterisk setting can be viewed here .
UPD: and here .

Today I did not reach it, as well as a soldering iron to make an improvised PoE.

UPD: Part 2

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


All Articles