As discussed in an earlier post, you can connect to a GSM modem and use AT commands to send SMS messages. There are 2 possible methods: text mode and PDU mode.

It turns out that most devices support PDU mode, but only a few support text mode.

Here is an example AT command to submit a PDU:

AT+CMGS=24<crlf>
> 0001000B915121551532F400000CC8F79D9C07E54F61363B04<Ctrl-Z>
As explained before the size (24) is the number of octets in the PDU. he PDU itself is passed as a hex representation of those octets (48 characters). Here is what the individual octets represent:
Size Value Description
1 octet 00 Indicates that we don’t supply a SMSC number. The one that is configured in the device will be used.
1 octet 01 PDU type and options. This is a one octet bit-field that controls:

  • Message type (here it set to 1 which means this is an SMS-SUBMIT PDU)
  • Validity period format
  • Reply path
  • User Data header present (UDH indicator)
  • Request status report

The most significant of these is the UDH indicator. More on these fields in a future post.

1 octet 00 Our message reference. In case there is an error delivering the message, this number will be part of the error response so we can see which message failed.
1 octet 0B Size of destination telephone number (in digits)
1 octet 91 International numbering plan. This indicates that what follows is is an international telephone number.
6 octets 5121551532f4 Telephone number. This is the destination phone number is a reverse nibble encoding:

  • octet ’51’ stands for digits 1 and 5
  • octet ’21’ stands for digits 1 and 2
  • octet ‘55’ stands for 5 and 5
  • octet ‘15’ stands for 5 and 1
  • octet ‘32’ stands for 2 and 3
  • octet ‘f1’ stands for digit 1 and the f indicates the end

So ‘915121551532f4’ translates to +1 512 555 1234.

1 octet 00 Protocol identifier. This can be used to indicate a higher level protocol. ‘0’ indicates no higher level protocol.
1 octet 00 This represents the Data Coding Scheme. A ‘0’ indicates that the messages is encoded in the GSM 7 (default) alphabet.

  • The message could also be encoded in UCS-2. In which case this octet would be ‘08’.

‘There are other (fun) uses for this byte that I’ll show in a future post.

1 octet 0c Payload size in septets (characters). This field is also called User Data Length.
11 octets C8f79D9C07E5
4F61363B04
The payload, also known as User Data. In this case it is just GSM encoded text. This is the tricky encoding:

  • The GSM-7 alphabet is a 7 bit alphabet. It’s character set is unlike any of the standard ISO or ASCII character sets (for instance a septet ‘0’ stands for the character ‘@’).
  • Septets are placed in octets in a funny way. I’ll explain below.

This particular string represents “Howdy y’all!”

The GSM-7 payload encoding is hard to explain, I’ll show how it works with the example above. Each character is represented by the bits with the same color:

C8 1 1 0 0 1 0 0 0 1001000 = ‘H’
F7 1 1 1 1 0 1 1 1 1101111 = ‘o’
9D 1 0 0 1 1 1 0 1 1110111 = ‘w’
9C 1 0 0 1 1 1 0 0 1100100 = ‘d’
07 0 0 0 0 0 1 1 1 1111001 = ‘y’
E5 1 1 1 0 0 1 0 1 0100000 = ‘ ‘ (space)
4F 0 1 0 0 1 1 1 1 1111001 = ‘y’,0100111 = ‘‘’ (quote)
61 0 1 1 0 0 0 0 1 1100001 = ‘a’
36 0 0 1 1 0 1 1 0 1101100 = ‘l’
3B 0 0 1 1 1 0 1 1 1101100 =’l’
04 0 0 0 0 0 1 0 0 0100001 = ‘!’

So every septet is added by first inserting the least significant bits in the unused most significant bits of the octet, then the rest of the bits (the most significant bits) are inserted in the next octet’s least significant bits. Confused? It becomes a lot clearer if you realize the octets are transmitted right to left. I have written articles (with code) on how to convert to the GSM-7 character set and another on how to pack GSM-7 septets.

The precise specification of the PDUs is given in 3GPP TS 23.040. The spec for the AT commands is in 3GPP TS 27.005. The GSM-7 character set is described in 3GPP TS 23.038.

There is little literature on these topics, but I found the following book has a pretty good introduction to the general topic and explores some SIM-based scenarios:

Leave a Reply

Your email address will not be published. Required fields are marked *