How to reply to a USSD menu using Linux command line tools?

Techcare2u picture Techcare2u · Jul 15, 2015 · Viewed 11.4k times · Source

I want to obtain information about the account balance of a SIM card I have installed in a mobile broadband modem in my computer. For my mobile network operator, this works using the USSD code 100#.

I found that gammu can send that USSD code using gammu getussd '100#'. In response, gammu shows me this USSD menu:

Press Ctrl+C to break...  
USSD received  
Status               : Action needed  
Service reply        : "Reply with your option:  
1.Account Balance  
2.Buy a Data Plan  
3.Top Up Now  
No response in specified timeout. Probably phone not connected.

How can select an option from that menu (like, 1)?

Answer

tanius picture tanius · Aug 6, 2015

It seems to me that ModemManager (and its command line client interface mmcli) is currently the most sophisticated, highest-quality solution for interacting with USSD and USSD menus under Linux.

Installation (under Debian / Ubuntu Linux):

sudo apt-get install modemmanager modem-manager-gui

Usage (following the manpage):

  1. Listing your modems: mmcli -L. This will show a modem device path like /org/freedesktop/ModemManager1/Modem/12 and you can use the number at its end to specify the modem to use after the -m option in the following commands.

  2. Showing attributes of your modem: mmcli -m 12.

  3. Enabling the modem (needed before using it for USSD): mmcli -m 12 -e

  4. Starting a USSD session. For example, for Ncell this command shows the main USSD menu: mmcli -m 12 --3gpp-ussd-initiate="*100#"

  5. Responding to a USSD menu. After the session is started, you may use a command like this to respond, here using option 1: mmcli -m 12 --3gpp-ussd-respond="1"

  6. Canceling the USSD session on the given modem: mmcli -m 12 --3gpp-ussd-cancel.

  7. Obtaining the status of all USSD sessions (of all available modems): mmcli --3gpp-ussd-status.

With most hardware, this should work properly and immediately as described.

(With my hardware however, I could not use mmcli so far due to a bug. All USSD related commands in mmcli would reply error: modem not unlocked yet, and mmcli -m 12 | grep " lock" would show that the sim-pin2 lock is enabled. But it is not (means I could not get past this by disabling the lock). And even if it would be enabled, that lock would not limit USSD usage (it's rather just meant for limiting outgoing calls to certain numbers). So, I'll have to remove this overzealous test condition from here, compile it myself and test again … .)