We make a VoIP GSM gateway from Tp-link mr-3020 and Huawei E-171 - part one

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



Only a woman can twitter cute for two hours on the phone, and then ask: "And who am I talking to?" - and find out that the person just made a mistake with the number.


2 women and a telephone bill pushed me to this tale. It so happened that cellular communication practically doesn’t work at home - either go out onto the balcony or use a home dect, or rather it’s not quite dect — it is dect PSTN + IP, the latter became a decisive factor.

I will make a reservation right away who is well acquainted with openwrt will not find anything new for itself.

So the TP-Link mr-3020 router and the Huawei e-171 dongle, in principle, will suit another one, but for convenience, it’s better not to pick up a soldering iron with a flash drive on board.


The first step is to unlock the modem, it’s already a habit, think about something that you might never need :)
I will not focus on this, there are a lot of places, I liked it here

Next, we put the modem in Modem + CardReader mode.
To do this, use the AT command.
AT^U2DIAG=256

and turn on the voice function
AT^CVOICE=0


We will postpone the modem and go back to the router, we need to install openwrt on it, whose native firmware can simply be flashed 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 version from trunk, as RC1 has an extra web interface at this stage, but RC1 can also be used.

After rebooting, 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


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

If you installed trunk, not RC1, then e2fsprogs and fdisk should still 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 are going to use swap on a flash, do not forget to check for swap-utils.
We mark out 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, 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 fun began, if you do a coldreset i.e. turn off the power, then pivotroot is not mounted in any way, after loading, the device / dev / sda appears, and / dev / sda1 does not, or until / touch / dev / sda is touched in some way ie do not make 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 the train, as they say, is gone and already / overlay is mounted as without a flash , space is sorely lacking, it was very tempting to just add reboot somewhere in the startup scripts, because if you do hotreset using reboot in the console, everything worked as if by magic.

here is an example of a cold start, part of the output, which shows how it goes to jffs2, where it is expected to see 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 different options, oddly enough, except for mount nothing helped, what helped to “push” / dev / sda after boot helped nothing during boot, saved 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 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 we could not deliver without pivotroot since there was not enough space and what you just want, here you can already 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 check for ttyUSB

ls /dev | grep USB
ttyUSB0
ttyUSB1
ttyUSB2


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

download asterisk-chan-dongle, it is necessary for asteriska to work with a “whistle”
code.google.com/p/asterisk-chan-dongle/downloads/list

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

correct feeds / packages / net / asterisk18-chan-dongle / Makefile for our version of the asterisk
WITH_ASTERISK=asterisk-1.8.3.2 

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

otherwise it will not be collected.

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


Copy the collected to 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 it is
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 a great chance to see a lot of 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 it must be said that I installed opkg-m from the Internet libiconv-full, but asterisk and chan-dongle took those that I collected myself, because I did them in rc1 and in trunk there was already another version of asterisk-a.

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     


You can see the asterisk setting here .
UPD: and here .

Today, I didn’t get to it, like to a soldering iron, to make an impromptu PoE.

UPD: Part 2

Also popular now: