There is an uptake in USSD services  in Nigeria and I thought to share my knowledge in the area. My hope is that, Nigerian developers can take advantage of USSD to build simple services that can be accessible by all phones.

This post is targeted at the absolute beginner with no Telcom experience.

What is USSD?

USSD is Unstructured Supplementary Services Data. It is a Telecoms standard that allow subscribers to communicate with Telecom operator nodes for services beyond basic voice calls.

In other words, its a medium to access additional services on the Operator network asides VOICE and SMS.

You already use USSD everyday

These days you can access mobile money services through your phone by dialling a USSD code e.g *894#, *909# etc….

To check your balance you can also dial *556#  on the MTN Network, *123# on Airtel, *232# on Glo etc. Dialling these codes connect you to USSD services configured on these USSD codes.

The USSD Gateway

The USSD protocol is well understood within GSM. Almost all the nodes within the GSM network have a USSD handler that understands USSD. For example, the MSC, HLR, VLR etc all have an internal USSD handler.

However, most operators have a dedicated equipment/server called the USSD Gateway (USSD GW) or USSD Centre. It is the USSD GW that allows them to handle USSD requests.

As we will see later, while a USSD GW can respond to user requests directly, It has the capability of forwarding on those requests to other applications that can respond to those requests.

Simple USSD Architecture

Simple USSD Architecture.

Figure 1: Simple USSD Architecture

Going by the architecture diagram in Figure 1, you can see a high level diagram of what happens when you dial the USSD code. Your request goes through the operator network and the request is processed by the USSD GW or an Application server on the other end.

The application server processes your request and sends the response back to the USSD Gateway, which in turn sends it to your phone. These steps are as follows:

1. User dials the  Code *e.g *777#
2. Phone Connects to the available Cell/Base Station/MSC
3. MSC forwards the request to the appropriate HLR/STP
4. STP/HLR sends the request to the USSD Gateway
5. USSD processes the request and respond OR sends the request to the Application Server
6. Application Server processes the request and sends back the response to the USSD GW through all the nodes and user gets the response.

Now lets take each of these steps and analyse a little further.

1. The Man-Machine Interface (MMI) Code

In telecoms, the full sequence of code you dial to access a USSD service is called the MMI code/string. The Operator Network/USSD Gateway typically expects MMI code composed according to a particular format.

Once the MMI code is in the right format, the Operator network will be able to determine the type of action the subscriber has requested and also the appropriate USSD nodes to send the request to (Based on Point Codes).

According to the 3GPP TS 22.030, the format for the MMI code is

AI*SC*SI#

where:
AI is Action Indicator:
SC is Service Code
SI is Supplementary Information:  

The asterisk * within the MMI code is used to concatenate additional supplementary information(SI). The hash ‘#’ character is used to indicate the end of the MMI code.

It is also possible to have more than one Supplementary Information (SI) provided within an MMI Code. The Additional SI will be separated by an asterisks. As such, the MMI code  AI*SC*SI*SI*SI# is also valid.

Let’s explain each of the fields.

Action indicator(AI): 

Action indicator could be any of the following:

Activation/Registration – (MMI code starts with *)
Deactivation – (MMI code starts with #)
Interrogation – (MMI code starts with *#)
Registration – (MMI code starts with **)
Erasure – (MMI code starts with ##)

The action you want to perform through the USSD will determine the action indicator you will specify in the MMI Code.

Service Code(SC): The service code is composed of 2 or 3 digits between 00 and 999. The SC uniquely identifies a particular supplementary service. The SC codes are either reserved,  manufacturer defined or  assigned by the network operator. In figure 1 above, the 777 service code has assigned by the operator.

Supplementary Information(SI)

This is used to provide additional information required by a particular service. Within the MMI code, you can include additional information for the service being requested. (For developers, think of this as additional parameters/arguments to go with the service code.)

Example  MMI code:s

Example 1: *#06# – View your mobile phone IMEI number

A breakdown of the MMI code *#06# is as follows:

Action Indicator (Interrogation) = *#
Service Code = 06
Supplementary Information = None

Example 2: *999#

Lets say this code is provisioned for a service on the operator network that allows us to perform balance enquiry and to also recharge our phones.

1. *999#  – check balance

A breakdown of the MMI code is as follows:

Action Indication (Activation) = *
Service Code = 999
Supplementary Information = None

2. *999*1234566789# – Reload account with scratch card number

A breakdown of the MMI code is as follows:

Action Indication (Activation) = *
Service Code = 999
Supplementary Information = 1234566789

From the above, we provided Supplementary information which could be a series of numbers gotten from a scratch recharge card.

Categories of MMI Code

Not all MMI Codes are used for USSD services.  There are 3 categories of MMI Code:

1. MMI code for Supplementary Services(SS)

Supplementary Services are used to query and set certain service parameters  directly on mobile devices.  With supplementary services, you can instruct your phone to take specific actions.  When initiated, actions are performed only on your mobile phone and does not go to the operator network. Example of Supplementary services include Calling Barring and Call Forwarding – *21*[phone number]#

2. Manufacturer defined MMI Codes

These are MMI codes specific to different mobile phones.  A common MMI code is the *#06# that is used to view the IMEI number of a mobile phone.

3. MMI Code for USSD services

All MMI codes that are not recognised by the mobile phone as being in either 1 or 2 above are forwarded to the mobile Operator network. These codes are provisioned by the Operator network and configured for specific services.

How does the mobile phone know what to do?

Mobile phones are capable of interpreting USSD MMI codes.

This is made possible by the fact that, all mobile phone operating systems have a USSD Handler in built that allows the mobile phone to send and receive USSD messages sent by the Mobile Network.

Whenever a user dials an MMI Code,  the dialled code is parsed by the mobile phone Operating System.  Any MMI code that is not device specific or that is not for supplementary services are sent to the operator network.

The USSD handler uses the MMI code/string to invoke a USSD session with the mobile network.

For android developers, this is a link to the PhoneUtils class of the Android OS that has the USSD Handler source code

_END_

In the next post of this series, we will learn what happens after the user dials the MMI code and the requests gets to the Operator network and subsequently the USSD Gateway.