Skip to content

Asterisk chan_dongle

# Download
cd /usr/src
wget https://github.com/oleg-krv/asterisk-chan-dongle/archive/asterisk13.zip
# The package includes installation instructions!
$ cd asterisk-chan-dongle-asterisk13
#
$ aclocal 
$ autoconf
$ automake -a
#
$ ./configure
#
$ make
$ make install
....
cpvt.o dc_config.o pdu.o mixbuffer.o pdiscovery.o
strip chan_dongle.so
/usr/bin/install -c -m 755 chan_dongle.so /usr/lib/asterisk/modules

CLI commands

dongle show devices

dongle restart now 

dongle sms MTS1 38050XXXXX test sms

# Clear SMS storage
#  1 SIM storage
#  2 modem storage
dongle cmd  AT+CPMS=\"SM\",\"SM\",\"SM\" 
dongle cmd  AT+CMGD=1,4

/etc/asterisk/dongle.conf

[general]
interval=15        ; Frequency for checking connected devices

[defaults]
context=dongle-income     ; Context for incoming calls
usecallingpres=yes    ; Detect caller number
callwaiting=no        ; Accept a second call during an active conversation
autodeletesms=yes     ; Delete SMS from the SIM card on restart
rxgain=0           ; Change speaker volume
txgain=0           ; Change microphone volume

[LIFE1]
context=dongle1-income
;audio=/dev/ttyUSB1
;data=/dev/ttyUSB1
imei=35939XXXXXXXXXX ; Bind modem name to IMEI number
imsi=25506XXXXXXXXXX ; Bind by SIM; can be omitted

[MTS1]
context=mts1-income
imei=35480XXXXXXXXX  
imsi=25500XXXXXXXXX 

/etc/asterisk/extensions.conf

#
[dongle1-income]

exten => sms,1,Noop(Incoming SMS from ${CALLERID(num)} )
 same => n,System(/etc/asterisk/scripts/sendsmsemail.sh "${CALLERID(num)}" "${DONGLENUMBER}" "${BASE64_DECODE(${SMS_BASE64})}")
 same => n,Hangup()

exten => _+38X.,1,Noop(INCOMMING CALL BY DONGLE-1 FROM ${CALLERID(num)})
 ; Strip leading +38 from the caller number
 same => n,Set(CNUM=${CALLERID(num)})
 same => n,ExecIf($["${CNUM:0:3}"="+38"]?Set(CALLERID(num)=${CNUM:3}))
 ;
 ; Strip leading +38 from the called number
 same => n,Set(ENUM=${EXTEN})
 same => n,ExecIf($["${ENUM:0:3}"="+38"]?Set(ENUM=${ENUM:3}))
 ;
 same => n,Set(CALLTYPE=in)
 same => n,GotoIfTime(08:50-18:10|mon-fri|*|*?worktime:noworktime)
 same => n(worktime),Noop()
 same => n,Answer()
 same => n,Playback(support_worktime)
 same => n,Gosub(sub-mixmonitor,${ENUM},1)
 same => n,Dial(SIP/operator1&SIP/operato2&SIP/operator3,300,t)
 same => n,Goto(exit)

 same => n(noworktime),Noop()
 same => n,Goto(support-noworktime,${ENUM},1)

 same => n(exit),HangUp()

/etc/udev/rules.d/92-dongle.rules

$ cat /etc/udev/rules.d/92-dongle.rules
KERNEL=="ttyUSB*", MODE="0666", OWNER="asterisk", GROUP="dialout"

Before:

ls -la /dev/ttyUSB*
crw-rw---- 1 root dialout 188,  0 Nov 29 06:17 /dev/ttyUSB0
crw-rw---- 1 root dialout 188,  1 Nov 29 06:17 /dev/ttyUSB1
crw-rw---- 1 root dialout 188,  2 Nov 29 06:17 /dev/ttyUSB2

After:

ls -la /dev/ttyUSB*
crw-rw-rw- 1 asterisk dialout 188, 0 Nov 29 15:30 /dev/ttyUSB0
crw-rw-rw- 1 asterisk dialout 188, 1 Nov 29 15:30 /dev/ttyUSB1
crw-rw-rw- 1 asterisk dialout 188, 2 Nov 29 15:30 /dev/ttyUSB2

Check which devices are visible

# 
$ lsusb
Bus 001 Device 005: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

$ lsusb -s 1:5 -v
# A working modem looks like this:
Bus 001 Device 005: ID 12d1:1001 Huawei Technologies Co., Ltd. E169/E620/E800 HSDPA Modem
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x12d1 Huawei Technologies Co., Ltd.
  idProduct          0x1001 E169/E620/E800 HSDPA Modem
  bcdDevice            0.00
  iManufacturer           3 HUAWEI Technology
  iProduct                2 HUAWEI Mobile
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           85
    bNumInterfaces          3
    bConfigurationValue     1
    iConfiguration          1 Qualcomm Configuration
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               5
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval              32
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval              32
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval              32
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval              32
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval              32
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval              32
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0001
  Self Powered


# A modem that does not connect is shown as Mass Storage SCSI

Bus 001 Device 004: ID 12d1:1446 Huawei Technologies Co., Ltd. E1552/E1800/E173 (HSPA modem)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x12d1 Huawei Technologies Co., Ltd.
  idProduct          0x1446 E1552/E1800/E173 (HSPA modem)
  bcdDevice            0.00
  iManufacturer           2 HUAWEI Technology
  iProduct                1 HUAWEI Mobile
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           55
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          3 Qualcomm Configuration
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only

etc/asterisk/scripts/sendsmsemail.sh

#!/bin/sh
# Send SMS to email
# $1 source number
# $2 destination number
# $3 SMS text

if [ $# != 3 ]
then
    echo "Use: sendsmsemail.sh 0441234567 0501234567 "
    exit 1
fi

CALLER=$1
CALLTONUM=$2
TEXT=$3

TOEMAIL="[email protected]"
LOGFILE="/var/log/asterisk/sendsmsemail.log"
EMAILCMD="/usr/sbin/sendmail -t"
FROMEMAIL="[email protected]"
SUBJECT="[PBX] SMS from ${CALLER} to ${CALLTONUM}"

#logging
echo [`date +"%Y-%m-%d %H:%M:%S"`] SMS TO: ${TOEMAIL} Subject: ${SUBJECT} >> ${LOGFILE}

#send email
${EMAILCMD} <
${TEXT}

--
(c) Astersik PBX
INLINE
exit 0

UPDATED 2017-04-03

Four of five modems completely froze. lsusb showed only one. Because physical access to the device was unavailable, I restarted the entire server. The modems came back up and worked.