Messaging
Messaging
Johan Montelius
Introduction
In this session you will experiment with different messaging alternatives.
You will first send plan SMS messages using a laptop and a mobile phone
an then learn how to code a WAP Push message to send a MMS notification
and a Service Indication.
Through out this tutorial it’s good to have the SMS specification 23.040
at hand. You can find it at the 3GPP web site.
1 Getting started
You need a computer and a mobile phone and some means to connect the
phone to the computer. A cable is of course to prefer but IrDa or Bluetooth
also works. We will communicate with the modem of the phone using AT
commands so you also need a terminal program. On a Windows platform
you could use HyperTerm and and on a Linux platform you can use minicom.
The firs thing you need to do is to connect the mobile and the computer
and find out which com port the modem is assigned. Next open up the
terminal program and attach the terminal to the com port. If you succeed
you should be able to issue the following AT command (¡cr¿ is you typing
return):
AT+ CIMI<cr>
The result should be a fifteen digit number starting with 240.... (240 is
the number for Sweden). This is the IMSI number of the SIM card.
AT+ CSCA?<cr>
AT+ CMGF?<cr>
1
submit header (1 byte)
AT+ CMGS="+46703123456"<cr>
>This is the message<ctrl-Z>
01
00
0B916437021446F0
2
Protocol identifier is set to 00 indicating a regular mobile to mobile
message. One can also play with protocol identifiers from 60 to 9F that are
used to replace previously delivered messages.
00
The coding scheme will in our first SMS be regular GSM 7-bit charac-
ters. So coding scheme is 00. We will use 8-bit data when we send more
complicated messages and then the coding scheme is 04.
00
Since we specified that there was no validity period we can omit this
byte. The length of the my secret message is thirty characters.
1E
61361B947FD7E52071785E0685E56590B8CC7EBBCF20FA1B549F03
A smaller messag that you can work with is “hello”. If we want to code
this we first write it down in 7-bit code with the least significat bit first.
The 7-bit code is ASCII for regular characters.
0001011 1
010011 00
11011 001
1011 1111
011 .....
Patch the last octet with zeros and write down the corresponding hex
code. Remember that the least significat bit is the first bit.
3
0001011 1 0xE8
010011 00 0x32
11011 001 0x9B
1011 1111 0xFD
011 00000 0x06
Since “hello” has five characters the we would code the length field as
05 and the message as E8329BFD06. Simple, right?
Now send you first PDU SMS using the CMGS command. The command
takes one argument that is the number of bytes in the PDU. When we issue
the command we will have an input prompt in the terminal. We can now
write down the PDU as listed above but we have to start with 00 to indicate
that the terminal should use its default SMSC (this byte is not part of the
PDU and is thus not counted in the length of the PDU). End the sequence
with ctr-z.
AT+ CMGS=40<cr>
>0001000B9164..... <ctr-z>
4
1.3 gone in 30 sec
Another parameter one can play with is the validity period. Turn a phone
off and then send it a message with very limited validity period (how do you
code 30 sec?). Then turn the phone back on and see if the SMSC is still
trying to deliver your message. You will probably have to use two phones
for this so collaborate in a small group.
2 Receiving a SMS
Receiving SMS can actually be quite tricky. One has to set it up properly
before we can even read stored messages on the terminal. There are different
memory areas and one can choose to work with, the SIM card denoted
"SM" and the mobile denoted "ME". There are also three different storage:
for reading and deleting, for writing and sending and for storing incoming
messages. Each storage can be allocated on either the SIM card or the
mobile. You can list the current setting with the CPMS command. You will
then also see how many messages you have in each storage.
AT+ CPMS?
The writing storage can be used to store SMS messages and and then
send them at a later point. This could be more convenient then issuing a
full CMSG command. We will now read messages so we must make sure that
the memory area for reading is the same as for storing incoming messages.
If incoming messages are stored in "ME" then we should also us this area for
reading.
AT+ CPMS="ME"
We can now list the content of this memory area with the CMGL command.
However, this command also takes a parameter: the status of the message.
Check in the AT command reference how to use the CMGL command.
AT+ CMGL=1
AT+ CMGR=NN
The result is of course a SMS in its binary PDU format but this is of
course easy for you to decode. Look at a small message and try to identify the
elements. Remember that you’re now looking at a delivered SMS message,
not a submit message. All though similar in structure the decoding is not
the same. Can you see who it is from?
5
The next thing you could explore is how to automatically be notified of
incoming messages. If you build an application you do not want to poll the
terminal every 10’th second you would rather have a message being delivered
to you. First issue the CNMI command to find out how messages are handled
by default. Then change the setting so that arriving messages will give you
a message in the terminal window.
AT+ CNMI=2,1,0,0,0
6
0x02 WBXML version 1.1
0x05 public identifier for SI 1.0
0x04 charset iso-8859-1
0x00 length of string
0x45 si with content
0xC6 indication with content and attributes
0x0D token for ”href=http://www.”
0x03 inline string follows
.... the string ”it.kth.se/courses/2g1722/push.wml
0x00 end of string
0x01 end of indication attributes
0x03 inline string follows
.... the string ”2G1722”
0x01 end of indication
0x01 end of si
7
0x0B User Data Header length (not including this byte)
0x05 identifer elements, port addressing
0x04 length of element
0x0B84 push dest port (2948)
0x23F0 push originator port (9200)
0x00 concatenated short message
0x03 length of element
0x01 ref number
0x01 max number of segments
0x01 current segmenet number