OpenWrt Forum Archive

Topic: 3G Modem USSD requests

The content of this topic has been archived on 17 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I have TL-WR1043ND and Huawei E173. I'm running Gargoyle and managed to get a working 3G wan. Now I want to send USSD requests to check traffic ballance without switching dongle between router and PC. This thread https://forum.openwrt.org/viewtopic.php?id=22153 pointed me to make a copy of working script /etc/gcom/getstrength.gcom and change the request string. But it results in error.
Standard USSD requests are described here http://3g-modem.wetpaint.com/page/common+AT-commands

Sending USSD Commands
+CUSD=1,"USSD-Command"
e.g. AT+CUSD=1,"*100#"
for some devices you will need to attach ",15" to your AT-command, as there won't come any return otherwise:
e.g. AT+CUSD=1,"*100#",15

So here is my script:

opengt
 set com 115200n81
 set comecho off
 set senddelay 0.02
 waitquiet 0.2 0.2
 flash 0.1

:start
 send "AT+CUSD=1,\"*103#\"^m"
 get 1 "" $s
 print $s

:continue
 exit 0

And result is
root@Gargoyle:/tmp/test# gcom -s ./script.gcom -d /dev/ttyUSB2
AT+CUSD=1,"*103#"
ERROR

I've tried to attach that ",15", but it doesen't help. What am I doing wrong?

I have figured it out. Commands format are device dependent, on Huawei modems it must be GSM 7bit packed, so it should look like: AT+CUSD=1,AA186C06,15
The input message is also encoded, so there must be some routine to decode it from 7bit format. Finally, dcom script must be something like that:

opengt
 set com 115200n81
 set comecho off
 set senddelay 0.02
 waitquiet 0.2 0.2
 flash 0.1

:start
 send "AT+CUSD=1,AA186C06,15^m"
 waitfor 10 "+CUSD: 0,\""
 if % != 0 goto continue
 get 1 "\"" $s
 print $s,"\n"

:continue
 exit 0

(Last edited by Jerry_Offsping on 18 Feb 2012, 19:45)

Is there some progress on sort of 3g modem dashboard for OpenWRT? I mean it should be very useful and convenient. I've made a bash script for balance check, but I have a strong feeling that I'm re-inventing the wheel. Can anyone throw some light on this topic. I just didn't find anything, maybe I just missed something.

Here is my script, maybe somebody will find it useful, ballance.gcom script is from my previous post. It sends a request and decodes the answer from GSM 7bit to normal ASCII. Some providers may send Unicode string and this script will be useless:

#!/bin/ash

ret=''
shift=0
carry=0

data1=$(gcom -s /etc/gcom/ballance.gcom -d /dev/ttyUSB2 | sed -e 's/.\{2\}/&\ /g')

for byte in $data1
do
 if [ $shift -eq 7 ]; then
  ret=$ret$(echo $carry | awk '{printf("%c",$0)}')

  carry=0
  shift=0
 fi

 byte=$((0x$byte))

: $(( a = (0xFF >> ($shift + 1)) & 0xFF ))
: $(( b = $a ^ 0xFF ))

: $(( digit = $carry | (($byte & $a) << $shift) & 0xFF ))
: $(( carry = ($byte & $b) >> (7 - $shift) ))

 ret=$ret$(echo $digit | awk '{printf("%c",$0)}')

: $(( shift++ ))
done

echo $ret

The only option right now for some sort of dashboard functionality would be something like modem-manager or ofono, both of which support a massive amount of features. Though, they also depend on heavy libraries like GLib-and-friends and the venerable dbus.

Actually there is such a dashboard since 2010 - http://eko.one.pl/?p=openwrt-3ginfo
And in 2011 i made a similar dashboard for my needs, again in non-English and for local operators. - https://nethelpforums.net/viewtopic.php?t=153

As already said, there are some problems with these projects:
- heavy dependencies - if you have not compiled your OpenWRT from scratch and have to install all dependencies on a vanilla OpenWRT you'll probably need more than 1 MB flash space, and for routers with 4 MB chips it is a real problem.
- local, non-English languages - i think in latest 3ginfo there is some English
- made for local operators - changing this requires modification of source, it is not like a setting.

However, i recently had the time to address some of these issues. I needed to have this functionality on DDWRT, and i discovered i cannot install dependencies there and had no free space on flash! And i started to rewrite everything to work without dependencies. And this time - in English.
I have succeeded with my DD-WRT console version and some days later i adapted it to work with OpenWRT - it is uploaded here - https://nethelpforums.net/viewtopic.php?f=15&t=618 - just look at the last post for downloading openwrt_balans_cmd_02.zip and install instructions (there is a Google translate in the footer of the forum). Actually you will not need the Bulgarian text - every possible help and instuction is in English in the source code - look at the beginning and the end of the files.

Highlight of the features:
- checking balance/credit with USSD and SMS commands. Returning answer can be in any format (ansi, pdu, ucs2) and will be converted on the fly
- recharging with SMS/USSD commands
- listing of SMS messages
- deletion of SMS
- checking signal strength
- various parameters - port, input and output formats, sms storage space - as configurable settings

Note that for me this console based version is a temporary solution. I am still working on the new version of my beautiful, web-based solution. Expect in the new version:
- switchable to English interface
- one click install via web interface
- no dependencies required and hence very little space.

The only thing i will not have time to put right now is "profiles" for operators around the world. Somebody will still have to spend 20 minutes to replace USSD commands like *101# with corresponding for local operators, for each new country this program is used in. You can post your modified files or links to your derivative projects here for example.
For PDU converted strings you can use http://smstools3.kekekasvi.com/topic.php?id=288 for example.

The discussion might have continued from here.