Ady Wicaksono Daily Activities

Sending USSD Proactive Command on Javacard

with 4 comments

First at all, take a look at below Send USSD APDU Proactive Command:

|---[:] COMMAND DETAILS
|---[:] Command Number: 01
|---[:] Command Type: Send USSD
|---[:] Command Qualifier: RFU ==> value: 00
|---[:] DEVICE IDENTITIES
|---[:] Source Device: SIM Card
|---[:] Destination Device: Network
|---[:] ALPHA IDENTIFIER
|---[:] Sending your request
|---[:] USSD STRING: 0F AA 58 6C 36 02
|---[:] Card Status: 90 00
\---[:] Raw data: D027810301120082028183851453656E64696E6720796F757220726571756573748A060FAA586C36029000

This is example of APDU for Send USSD Proactive Command on javacard with USSD string *113#.
The code for sending is very simple:

ProHdlr.init((byte)PRO_CMD_SEND_USSD,(byte)0x00,(byte)DEV_ID_NETWORK);
ProHdlr.appendTLV(TAG_ALPHA_IDENTIFIER, USSD_TITLE_EN,(short)0x00,(short)USSD_TITLE_EN.length);
ProHdlr.appendTLV((byte)(TAG_USSD_STRING), USSDBuffer, (short)0x01, (short)f);
ProHdlr.send();

Where ProHdlr is ProactiveHandler, USSD_TITLE_EN is static byte for alpha identifier to be used
during sending the USSD request, USSDBuffer is buffer for USSD string, f is length of data of USSD string.

The most important thing here is that USSD string consist of:
1. Data Encoding Scheme (which most probably use 0x0F)
2. USSD string itself, which must be 7-bit encoded just like normal 7bit SMS.

E.g we have assigned below *113#

byte lenUSSDBuffer = (byte)0x01;
USSDBuffer[(byte)lenUSSDBuffer++] = (byte)0x0F; // Data encoding scheme
USSDBuffer[(byte)lenUSSDBuffer++] = (byte)'*';
USSDBuffer[(byte)lenUSSDBuffer++] = (byte)'1';
USSDBuffer[(byte)lenUSSDBuffer++] = (byte)'1';
USSDBuffer[(byte)lenUSSDBuffer++] = (byte)'3';
USSDBuffer[(byte)lenUSSDBuffer] = (byte)'#';

*113# will become 0xAA 0x58 0x6C 0x36 0x02 once we code it in 7-bit encoding rule (see TS 23.038).
0x0F is encoding scheme which follow standard encoding scheme for Cell Broadcast (see TS 23.038).
0x0F means GSM 7 bit default alphabet – language unspecified.

Good luck with your USSD !

Written by adywicaksono

December 6, 2009 at 11:52 am

Posted in SmartCard, Telco - GSM

4 Responses

Subscribe to comments with RSS.

  1. Thanks for your effort.
    You can calculate packed USSD string manually for pre-defined string and add it to command.
    that is OK if I know previously USSD string.
    But what happens if USSD string is dynamic
    e.g. Application get input from user and append it to USSD string
    e.g. USSD string may be *100*#
    where is received from user using GET INPUT command
    then I need a function that converts normal string to packed one on run time
    note: I worked with WIB and many native languages, all these languages have capability to pack string

    Thanks again

    abdelrahman

    December 20, 2009 at 3:28 pm

  2. I have the function for that but I can not share it here, sorry. Anyway you can googling for convert 8bit to 7bit

    Thanks

    adywicaksono

    December 21, 2009 at 3:55 am

  3. Hi,
    Im a javacard developer, i try to use the SEND USSD command with code *#06# . This code is to get the imei of the phone. But it returns me entry string. Is it possible to send USSD with this code?

    Miyaka

    February 23, 2011 at 5:48 am

    • *#06# is not USSD code. to get IMEI, send PROVIDE_LOCAL_INFO with IMEI as a tag, you will get IMEI from handset

      adywicaksono

      May 28, 2011 at 6:13 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: