Friday, August 24, 2018

One way voice on Huawei E150

By default with E150 local party can listen what talking GSM party, but GSM party listen silence.
E150 require write zero length frame after each 320 bytes 20ms of voice data written. But linux driver named option, nothing know about this E150 'feature'.
Solution is build special versions of option driver and driver for only diagnostic port of E150. The sources of these can be found on https://github.com/Novax/kmod-huawei-voice
Brief instruction for debian and ubuntu: Install git
sudo apt-get install git
Install linux kernel headers for version of your kernel
sudo apt-get install linux-headers-2.6.35-22 
Install sources of kmod-huawei-voice
cd /usr/src
git clone git://github.com/Novax/kmod-huawei-voice.git
Build kernel module
cd kmod-huawei-voice
make
Install module (not fully yet)
/etc/init.d/asterisk stop
rmmod option
insmod ./option.ko
insmod ./huawei_voice.ko
/etc/init.d/asterisk start
Other solution implemented in private chan_dongle and custom patch to option driver.
This working by calling new ioctl for write zero URB to device for 'push' data.
This way allow have E150 and other dongles in one system without colissions.
Note: E150 is USB1.1 and can be working unstable.

Running asterisk as non-root

A lot of people is running Asterisk as “asterisk” user. This may cause chan_dongle not detecting USB modems properly. In that case, you need to give permissions for ttyUSB ports. You can do that automatically by creating file /etc/udev/rules.d/92-dongle.rules and adding:
KERNEL=="ttyUSB*", MODE="0666", OWNER="asterisk", GROUP="uucp"
Other posible solution is to set runuser/rungroup settings in asterisk.conf file.
rungroup = dialout
In other words owner, group, permissions on /dev/ttyUSBx files must allow read and write operations for asterisk's EUID, EGID

Console AT commands

You can send AT commands to any modem using
CLI>dongle cmd <device> <AT_command>
Some useful AT commands:
AT commandDescription
AT+CCWA=0,0,1disable call-waiting
AT+CFUN=1,1reboot modem
AT^CARDLOCK=“<code>”send unlock code
AT^SYSCFG=13,0,3FFFFFFF,0,3modem 2G only, automatic search any band, no roaming
AT^SYSCFG=2,0,3FFFFFFF,2,4Any
AT^SYSCFG=13,1,3FFFFFFF,2,42G only
AT^SYSCFG=14,2,3FFFFFFF,2,43G only
AT^SYSCFG=2,1,3FFFFFFF,2,42G preferred
AT^SYSCFG=2,2,3FFFFFFF,2,43G preferred
AT^U2DIAG=0enable modem function only
ATIget relevant information from modem
ATZreset modem configuration
AT+CIMIread IMSI
AT+CLCK=“SC”,0,“<pin>”disable PIN verification

Receive SMS and USSD

You can handle received SMS and USSD using sms and ussd exten, respectively.
Example for received sms
[dongle-incoming-sms]
exten => sms,1,Noop(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,Hangup()
Example for received USSD
[dongle-incoming-ussd]
exten => ussd,1,Noop(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,Hangup()
Also note, execution of this exten takes place in a “Local” channel.
Always define sms and ussd extens for context where you handle incoming calls for dongle device! Otherwise, incoming SMS or USSD can execute extensions for voice call with unpredictable results.
[dongle-incoming]
include => dongle-incoming-sms
include => dongle-incoming-ussd
Also note that h exten is executed for SMS/USSD just before Local channel is destroyed.

Receive SMS and USSD

You can handle received SMS and USSD using sms and ussd exten, respectively.
Example for received sms
[dongle-incoming-sms]
exten => sms,1,Noop(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,Hangup()
Example for received USSD
[dongle-incoming-ussd]
exten => ussd,1,Noop(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,Hangup()
Also note, execution of this exten takes place in a “Local” channel.
Always define sms and ussd extens for context where you handle incoming calls for dongle device! Otherwise, incoming SMS or USSD can execute extensions for voice call with unpredictable results.
[dongle-incoming]
include => dongle-incoming-sms
include => dongle-incoming-ussd
Also note that h exten is executed for SMS/USSD just before Local channel is destroyed.

Subscriber Number

On incoming call, chan_dongle tries to find matching exten in defined context (see dongle.conf). There is 3 different exten to search, in the following order:
  • Subscriber Number stored in SIM.
  • Number defined in variable exten in dongle.conf
  • s exten
To save Subscriber Number, you can write an entry for OWN NUMBERS storage on SIM. For example, in asterisk CLI
dongle cmd dongle0 AT+CPBS=\"ON\"
dongle cmd dongle0 AT+CPBW=1,\"+79139131234\",145
After restarting dongle0, incoming calls will start dialplan from exten
exten => +79139131234,1,Noop()
also variable CALLERID(dnid) will be set to +79139131234
If subscriber number is unknown, then you can set this in in dongle.conf
exten = +79139131234
If subscriber number is unknown and there is no exten entry in dongle.conf, then s exten will be used as starting point in dialpan.

chan_dongle CLI commands

chan_dongle provides the following CLI commands:
  • dongle cmd <device> <at_command>
    Send <at_command> to the rfcomm port on the device with the specified <device>
  • dongle reset <device>
    Send reboot command to modem AT+CFUN=1,1
  • dongle stop gracefully <device>
    Stop <device> gracefully. Prevents new incoming and outgoing calls and SMS and outgoing USSD from starting up, but allows calls/SMS/USSD in progress to continue. When all the calls/SMS/USSD have finished, <device> stops
  • dongle stop now <device>
    Stop <device> now. Stops <device> immediately, ending any calls/SMS/USSD in progress
  • dongle stop when convenient <device>
    Stop <device> when convenient. Waits until <device> has no calls/SMS/USSD in progress, and then it stops <device>. It does not prevent new calls/SMS/USSD from entering the <device>.
  • dongle show device settings <device>
    Shows settings for <device>
  • dongle show device state <device>
    Shows detailed state for <device>
  • dongle show device statistics <device>
    Shows statistics for <device>
  • dongle show devices
    Shows summarized state for all devices
  • dongle show version
    Show module version
  • dongle sms <device> <number> <message>
    Send SMS to <number> with the <message> using <device>
  • dongle pdu <device> <pdu>
    Send PDU using <device>
  • dongle ussd <device> <ussd>
    Send USSD command <ussd> using <device>
  • dongle start <device>
    Start <device> if not removed from before.
  • dongle restart gracefully <device>
    Prevents new incoming and outgoing calls and SMS and outgoing USSD from starting up in <device>, but allows calls/SMS/USSD in progress to continue. When call/SMS/USSD has finished, <device> restarts. Restart mean first stop device and second reopen and initialize.
  • dongle restart now <device>
    Restarts <device> immediately, ending any calls/SMS/USSD in progress.
  • dongle restart when convenient <device>
    Waits until <device> has no calls/SMS/USSD in progress, and then it restarts <device>. It does not prevent new calls/SMS/USSD from entering the <device>.
  • dongle remove gracefully <device>
    Prevents new incoming and outgoing calls and SMS and outgoing USSD from starting up in <device>, but allows calls/SMS/USSD in progress to continue. When call/SMS/USSD has finished, <device> stopping and removed from module.
  • dongle remove now <device>
    Remove <device> from Asterisk immediately.
  • dongle remove when convenient <device>
    Waits until <device> has no calls/SMS/USSD in progress and then remove <device>. It does not prevent new calls/SMS/USSD from entering the <device>.
  • dongle reload gracefully
    Reloads the chan_dongle configuration gracefully
  • dongle reload now
    Reloads the chan_dongle configuration now
  • dongle reload when convenient
    Reloads the chan_dongle configuration when convenient. BUG: complete removed devices from dongle.conf not removed from module after reload. Use disable=yes as workaround.