You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## A small guide on how to send and receive USSD codes on Linux
I am using the built in GSM (UMTS) modem of my Thinkpad X1 extensively because I am often in places with flaky internet connections. I connect through the standard Network Manager on Ubuntu and everything works fine. There was one major annoyance though. Every time I wanted to top up the SIM balance or book a new package, I needed a phone to send and receive USSD codes. So I took some time to figure out how to do it from the shell. I wrote this down as a help for others and a reminder for myself. Without further ado...
First intsall gammu and picocom.
```bash
➜ ~ sudo apt-get install -y gammu picocom
```
Obtaining infos about the device
```bash
➜ ~ dmesg | grep tty
[74804.272165] cdc_acm 3-4:1.1: ttyACM0: USB ACM device
[74804.273338] cdc_acm 3-4:1.3: ttyACM1: USB ACM device
[74804.301617] cdc_acm 3-4:1.9: ttyACM2: USB ACM device
[91522.989255] cdc_acm 3-4:1.1: ttyACM0: USB ACM device
[91522.989957] cdc_acm 3-4:1.3: ttyACM1: USB ACM device
[91523.017825] cdc_acm 3-4:1.9: ttyACM2: USB ACM device
[99661.279473] cdc_acm 3-4:1.1: ttyACM0: USB ACM device
[99661.280822] cdc_acm 3-4:1.3: ttyACM1: USB ACM device
[99661.309089] cdc_acm 3-4:1.9: ttyACM2: USB ACM device
[99958.320040] cdc_acm 3-4:1.1: ttyACM0: USB ACM device
[99958.321636] cdc_acm 3-4:1.3: ttyACM1: USB ACM device
[99958.349615] cdc_acm 3-4:1.9: ttyACM2: USB ACM device
➜ ~ lsusb | grep -i ericsson
Bus 003 Device 021: ID 0bdb:1926 Ericsson Business Mobile Networks BV
➜ ~ lsusb -v -s 003:021
Bus 003 Device 021: ID 0bdb:1926 Ericsson Business Mobile Networks BV
Couldn't open device, some information will be missing
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0bdb Ericsson Business Mobile Networks BV
idProduct 0x1926
bcdDevice 0.00
iManufacturer 1
iProduct 2
...
➜ ~ for n in `ls /sys/class/*/*{ACM,wdm}*/device/interface`;do echo $(echo $n|awk -F '/''{print $5}') : $(cat $n);done
ttyACM0 : H5321 gw Mobile Broadband Modem # this is what we're looking for
ttyACM1 : H5321 gw Mobile Broadband Data Modem
ttyACM2 : H5321 gw Mobile Broadband GPS Port
cdc-wdm0 : H5321 gw Mobile Broadband Device Management
cdc-wdm1 : Ericsson H5321 gw
cdc-wdm2 : H5321 gw Mobile Broadband USIM Port
```
We can now try to interact with the modem
```bash
➜ ~ sudo gammu --identify
Warning: No configuration file found!
Warning: No configuration read, using builtin defaults!
Device : /dev/ttyACM0
Manufacturer : Lenovo
Model : unknown (H5321 gw)
Firmware : R3C11
IMEI : 355001040455270
SIM IMSI : 452010133540292
➜ ~ sudo picocom /dev/ttyACM0
picocom v1.7
port is : /dev/ttyACM0
flowcontrol : none
baudrate is : 9600
parity is : none
databits are : 8
escape is : C-a
localecho is : no
noinit is : no
noreset is : no
nolock is : no
send_cmd is : sz -vv
receive_cmd is : rz -vv
imap is :
omap is :
emap is : crcrlf,delbs,
Terminal ready
*EMRDY: 1
AT+CPIN?
+CPIN: READY
OK
Thanks for using picocom
```
Cool, no pin needed in my case, makes things a lot easier.
Now we can either run `sudo gammu-config` or create a config file manually under `~/.gammurc`
```bash
➜ ~ cat ~/.gammurc
# This is a generated gammurc file.
# It was generated by Gammu configurator 0.4
# In Unix/Linux : copy it into your home directory and name it .gammurc
# or into /etc and name it gammurc
# In Win32 : copy it into directory with Gammu.exe and name gammurc
# Port : in Windows/DOS: "com*:",
# (instead of "*" please put "1", "2", etc.)
# in other (Linux/Unix) "/dev/ttyS%"
# or "/dev/ircomm%" ("irda" connection)
# (instead of "%" please put "0", "1", "2", etc.)
# Model : use only, when Gammu doesn't recognize your phone model.
# Put it here. Example values: "6110", "6150", "6210", "8210"
# Connection : type of connection. Use "fbus" or "mbus" or "dlr3" or
# "irda" (Infrared over sockets) or "infrared" (DirectIR)
# or "at19200" (AT commands on 19200, 8 bits, None parity,
# 1 stop bit, no flow control) or "at115200" (AT commands on
User Data Header : Concatenated (linked) message, ID (8 bit) 183, part 1 of 1
Dear , you have ordered the following Offering(s): Package6 1Month U get free 5000MB effect on 2014-12-21, thank you.
19 SMS parts in 19 SMS sequences
```
Connection should work now. Based on these commands you can now go ahead and create shortcuts for all the commands. If entering your password annoys you, create an entry ìn sudoers.d like so `sudo visudo -f /etc/sudoers.d/gammu` with the this content `username hostname = (root) NOPASSWD: /usr/bin/gammu`.
Note that i didn't manipulate `/etc/sudoers` because it's a better practice and easier to maintain. As of debian version 1.7.2p1-1, the default /etc/sudoers file created on installation of the package now includes the directive `/etc/sudoers.d`. Read more about it in the man pages.
Add entries like these with your carriers USSD codes to your *sh_aliases or *shrc file.
```bash
alias gsm-balance='sudo gammu -c ~/.gammurc getussd *122#'
alias gsm-data='sudo gammu -c ~/.gammurc getussd *123#'
alias gsm-monitor='sudo gammu -c ~/.gammurc monitor 1'
alias gsm-sms='sudo gammu -c ~/.gammurc getallsms'
```
If you want to do this through a GUI, have a look at [wammu](http://wammu.eu). This is the GUI client to gammu. Apparently it has all the superpowers of Gammu but I don't like GUIs so I didn't try it. You can send and receive SMS through both as well.
As an alternative to `picocom` you can use `cu` (cu - call up another system) which I didn't try out myself.