My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Friday, 14 December 2012

SMS and the PDU format


Introduction

The SMS message, as specified by the Etsi  organization (documents GSM 03.40 and GSM 03.38), can be up to 160 characters long, where each character is 7 bits according to the 7-bit default alphabet. Eight-bit messages (max 140 characters) are usually not viewable by the phones as text messages; instead they are used for data in e.g. smart messaging (images and ringing tones) and OTA provisioning of WAP settings.  16-bit messages (max 70 characters) are used for Unicode (UCS2) text messages, viewable by most phones. A 16-bit text message of class 0 will on some phones appear as a Flash SMS (aka blinking SMS or alert SMS) Thanks for [http://www.dreamfabric.com] .


The 7 bit default alphabet

This is the 7 bit default alphabet as specified by GSM 03.38. The corresponding ISO-8859-1 decimal codes are shown in the rightmost column. Note that the euro sign (€) is a member of the ISO-8859-15 character set. 

HexDecCharacter nameCharacterISO-8859-1 DEC
0x000COMMERCIAL AT@64
0x011POUND SIGN£163
0x022DOLLAR SIGN$36
0x033YEN SIGN¥165
0x044LATIN SMALL LETTER E WITH GRAVEè232
0x055LATIN SMALL LETTER E WITH ACUTEé233
0x066LATIN SMALL LETTER U WITH GRAVEù249
0x077LATIN SMALL LETTER I WITH GRAVEì236
0x088LATIN SMALL LETTER O WITH GRAVEò242
0x099LATIN CAPITAL LETTER C WITH CEDILLAÇ199
0x0A10LINE FEED10
0x0B11LATIN CAPITAL LETTER O WITH STROKEØ216
0x0C12LATIN SMALL LETTER O WITH STROKEø248
0x0D13CARRIAGE RETURN13
0x0E14LATIN CAPITAL LETTER A WITH RING ABOVEÅ197
0x0F15LATIN SMALL LETTER A WITH RING ABOVEå229
0x1016GREEK CAPITAL LETTER DELTAΔ
0x1117LOW LINE_95
0x1218GREEK CAPITAL LETTER PHIΦ
0x1319GREEK CAPITAL LETTER GAMMAΓ
0x1420GREEK CAPITAL LETTER LAMBDAΛ
0x1521GREEK CAPITAL LETTER OMEGAΩ
0x1622GREEK CAPITAL LETTER PIΠ
0x1723GREEK CAPITAL LETTER PSIΨ
0x1824GREEK CAPITAL LETTER SIGMAΣ
0x1925GREEK CAPITAL LETTER THETAΘ
0x1A26GREEK CAPITAL LETTER XIΞ
0x1B27ESCAPE TO EXTENSION TABLE
0x1B0A27 10FORM FEED12
0x1B1427 20CIRCUMFLEX ACCENT^94
0x1B2827 40LEFT CURLY BRACKET{123
0x1B2927 41RIGHT CURLY BRACKET}125
0x1B2F27 47REVERSE SOLIDUS (BACKSLASH)\92
0x1B3C27 60LEFT SQUARE BRACKET[91
0x1B3D27 61TILDE~126
0x1B3E27 62RIGHT SQUARE BRACKET]93
0x1B4027 64VERTICAL BAR|124
0x1B6527 101EURO SIGN164 (ISO-8859-15)
0x1C28LATIN CAPITAL LETTER AEÆ198
0x1D29LATIN SMALL LETTER AEæ230
0x1E30LATIN SMALL LETTER SHARP S (German)ß223
0x1F31LATIN CAPITAL LETTER E WITH ACUTEÉ201
0x2032SPACE32
0x2133EXCLAMATION MARK!33
0x2234QUOTATION MARK"34
0x2335NUMBER SIGN#35
0x2436CURRENCY SIGN¤164 (ISO-8859-1)
0x2537PERCENT SIGN%37
0x2638AMPERSAND&38
0x2739APOSTROPHE'39
0x2840LEFT PARENTHESIS(40
0x2941RIGHT PARENTHESIS)41
0x2A42ASTERISK*42
0x2B43PLUS SIGN+43
0x2C44COMMA,44
0x2D45HYPHEN-MINUS-45
0x2E46FULL STOP.46
0x2F47SOLIDUS (SLASH)/47
0x3048DIGIT ZERO048
0x3149DIGIT ONE149
0x3250DIGIT TWO250
0x3351DIGIT THREE351
0x3452DIGIT FOUR452
0x3553DIGIT FIVE553
0x3654DIGIT SIX654
0x3755DIGIT SEVEN755
0x3856DIGIT EIGHT856
0x3957DIGIT NINE957
0x3A58COLON:58
0x3B59SEMICOLON;59
0x3C60LESS-THAN SIGN<60
0x3D61EQUALS SIGN=61
0x3E62GREATER-THAN SIGN>62
0x3F63QUESTION MARK?63
0x4064INVERTED EXCLAMATION MARK¡161
0x4165LATIN CAPITAL LETTER AA65
0x4266LATIN CAPITAL LETTER BB66
0x4367LATIN CAPITAL LETTER CC67
0x4468LATIN CAPITAL LETTER DD68
0x4569LATIN CAPITAL LETTER EE69
0x4670LATIN CAPITAL LETTER FF70
0x4771LATIN CAPITAL LETTER GG71
0x4872LATIN CAPITAL LETTER HH72
0x4973LATIN CAPITAL LETTER II73
0x4A74LATIN CAPITAL LETTER JJ74
0x4B75LATIN CAPITAL LETTER KK75
0x4C76LATIN CAPITAL LETTER LL76
0x4D77LATIN CAPITAL LETTER MM77
0x4E78LATIN CAPITAL LETTER NN78
0x4F79LATIN CAPITAL LETTER OO79
0x5080LATIN CAPITAL LETTER PP80
0x5181LATIN CAPITAL LETTER QQ81
0x5282LATIN CAPITAL LETTER RR82
0x5383LATIN CAPITAL LETTER SS83
0x5484LATIN CAPITAL LETTER TT84
0x5585LATIN CAPITAL LETTER UU85
0x5686LATIN CAPITAL LETTER VV86
0x5787LATIN CAPITAL LETTER WW87
0x5888LATIN CAPITAL LETTER XX88
0x5989LATIN CAPITAL LETTER YY89
0x5A90LATIN CAPITAL LETTER ZZ90
0x5B91LATIN CAPITAL LETTER A WITH DIAERESISÄ196
0x5C92LATIN CAPITAL LETTER O WITH DIAERESISÖ214
0x5D93LATIN CAPITAL LETTER N WITH TILDEÑ209
0x5E94LATIN CAPITAL LETTER U WITH DIAERESISÜ220
0x5F95SECTION SIGN§167
0x6096INVERTED QUESTION MARK¿191
0x6197LATIN SMALL LETTER Aa97
0x6298LATIN SMALL LETTER Bb98
0x6399LATIN SMALL LETTER Cc99
0x64100LATIN SMALL LETTER Dd100
0x65101LATIN SMALL LETTER Ee101
0x66102LATIN SMALL LETTER Ff102
0x67103LATIN SMALL LETTER Gg103
0x68104LATIN SMALL LETTER Hh104
0x69105LATIN SMALL LETTER Ii105
0x6A106LATIN SMALL LETTER Jj106
0x6B107LATIN SMALL LETTER Kk107
0x6C108LATIN SMALL LETTER Ll108
0x6D109LATIN SMALL LETTER Mm109
0x6E110LATIN SMALL LETTER Nn110
0x6F111LATIN SMALL LETTER Oo111
0x70112LATIN SMALL LETTER Pp112
0x71113LATIN SMALL LETTER Qq113
0x72114LATIN SMALL LETTER Rr114
0x73115LATIN SMALL LETTER Ss115
0x74116LATIN SMALL LETTER Tt116
0x75117LATIN SMALL LETTER Uu117
0x76118LATIN SMALL LETTER Vv118
0x77119LATIN SMALL LETTER Ww119
0x78120LATIN SMALL LETTER Xx120
0x79121LATIN SMALL LETTER Yy121
0x7A122LATIN SMALL LETTER Zz122
0x7B123LATIN SMALL LETTER A WITH DIAERESISä228
0x7C124LATIN SMALL LETTER O WITH DIAERESISö246
0x7D125LATIN SMALL LETTER N WITH TILDEñ241
0x7E126LATIN SMALL LETTER U WITH DIAERESISü252
0x7F127LATIN SMALL LETTER A WITH GRAVEà224



Flash SMS

On some phones (all Nokia, some Siemens, Ericsson, Motorola etc..) a class 0 message will appear as a flash SMS message. These messages appear on the screen immediately upon arrival, without the need to press any buttons on the phone. If the data coding scheme is set to 16-bit unicode (ucs2), and the message starts with "0001", it will appear as a blinking flash message.

OctetValueDescription
TP-DCS1816 bits (UCS2), message class 0
TP-VPAAValidity period
TP-UDL0CUser Data Length, 12 octets
TP-UD00 01 00 41 00 6C 00 65 00 72 00 74User Data, message "Alert"
This table shows some relevant octets in a flash SMS message

The first unicode character ("00 01") enables the blinking. The maximum length of such a message will then be 69 unicode characters.


The PDU format

There are two ways of sending and receiving SMS messages: by text mode and by PDU (protocol description unit) mode. The text mode (unavailable on some phones) is just an encoding of the bit stream represented by the PDU mode. Alphabets may differ and there are several encoding alternatives when displaying an SMS message. The most common options are "PCCP437", "PCDN", "8859-1", "IRA" and "GSM". These are all set by the at-command  AT+CSCS, when you read the message in a computer application. If you read the message on your phone, the phone will choose a proper encoding. An application capable of reading incoming SMS messages, can thus use text mode or PDU mode. If text mode is used, the application is bound to (or limited by) the set of preset encoding options. In some cases, that's just not good enough. If PDU mode is used, any encoding can be implemented.
Receiving a message in the PDU mode

The PDU string contains not only the message, but also a lot of meta-information about the sender, his SMS service center, the time stamp etc. It is all in the form of hexa-decimal octets or decimal semi-octets. The following string is what I received on a Nokia 6110  when sending the message containing "hellohello" from www.mtn.co.za .

07 917283010010F5 040BC87238880900F10000993092516195800AE8329BFD4697D9EC37

This octet sequence consists of three parts: An initial octet indicating the length of the SMSC information ("07"), the SMSC information itself ("917283010010F5"), and the SMS_DELIVER part (specified by ETSI in GSM 03.40).

Note: on some phones (e.g. Ericssson 888?) the first three (colored) parts are omitted when showing the message in PDU mode!


Octet(s)Description
07Length of the SMSC information (in this case 7 octets)
91Type-of-address of the SMSC. (91 means international format of the phone number)
72 83 01 00 10 F5Service center number(in decimal semi-octets). The length of the phone number is odd (11), so a trailing F has been added to form proper octets. The phone number of this service center is "+27381000015". See below.
04First octet of this SMS-DELIVER message.
0BAddress-Length. Length of the sender number (0B hex = 11 dec)
C8Type-of-address of the sender number
72 38 88 09 00 F1Sender number (decimal semi-octets), with a trailing F
00TP-PID. Protocol identifier.
00TP-DCS Data coding scheme
99 30 92 51 61 95 80TP-SCTS. Time stamp (semi-octets)
0ATP-UDL. User data length, length of message. The TP-DCS field indicated 7-bit data, so the length here is the number of septets (10). If the TP-DCS field were set to indicate 8-bit data or Unicode, the length would be the number of octets (9).
E8329BFD4697D9EC37TP-UD. Message "hellohello" , 8-bit octets representing 7-bit data.

All the octets above are hexa-decimal 8-bit octets, except the Service center number, the sender number and the timestamp; they are decimal semi-octets. The message part in the end of the PDU string consists of hexa-decimal 8-bit octets, but these octets represent 7-bit data (see below). 

The semi-octets are decimal, and e.g. the sender number is obtained by performing internal swapping within the semi-octets from "72 38 88 09 00 F1" to "27 83 88 90 00 1F". The length of the phone number is odd, so a proper octet sequence cannot be formed by this number. This is the reason why the trailing F has been added. The time stamp, when parsed, equals "99 03 29 15 16 59 08", where the 6 first characters represent date, the following 6 represents time, and the last two represents time-zone related to GMT. 

Interpreting 8-bit octets as 7-bit messages

This transformation is described in detail in GSM 03.38,  The transformation is based on the 7 bit default alphabet , but an application built on the PDU mode can use any character encoding.

Sending a message in the PDU mode

The following example shows how to send the message "hellohello" in the PDU mode from a Nokia 6110.

AT+CMGF=0 //Set PDU mode AT+CSMS=0 //Check if modem supports SMS commands AT+CMGS=23 //Send message, 23 octets (excluding the two initial zeros) &gt;0011000B916407281553F80000AA0AE8329BFD4697D9EC37&lt;ctrl-z&gt; There are 23 octets in this message (46 'characters'). The first octet ("00") doesn't count, it is only an indicator of the length of the SMSC information supplied (0). The PDU string consists of the following:

Octet(s)Description
00Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. Note: This octet is optional. On some phones this octet should be omitted! (Using the SMSC stored in phone is thus implicit)
11First octet of the SMS-SUBMIT message.
00TP-Message-Reference. The "00" value here lets the phone set the message reference number itself.
0BAddress-Length. Length of phone number (11)
91Type-of-Address. (91 indicates international format of the phone number).
6407281553F8The phone number in semi octets (46708251358). The length of the phone number is odd (11), therefore a trailing F has been added, as if the phone number were "46708251358F". Using the unknown format (i.e. the Type-of-Address 81 instead of 91) would yield the phone number octet sequence 7080523185 (0708251358). Note that this has the length 10 (A), which is even.
00TP-PID. Protocol identifier
00TP-DCS. Data coding scheme.This message is coded according to the 7bit default alphabet. Having "04" instead of "00" here, would indicate that the TP-User-Data field of this message should be interpreted as 8bit rather than 7bit (used in e.g. smart messaging, OTA provisioning etc).
AATP-Validity-Period. "AA" means 4 days. Note: This octet is optional, see bits 4 and 3 of the first octet
0ATP-User-Data-Length. Length of message. The TP-DCS field indicated 7-bit data, so the length here is the number of septets (10). If the TP-DCS field were set to 8-bit data or Unicode, the length would be the number of octets.
E8329BFD4697D9EC37TP-User-Data. These octets represent the message "hellohello". How to do the transformation from 7bit septets into octets is shown here




Coding 7-bit data (septets) into octets

The message "hellohello" consists of 10 characters, called septets when represented by 7 bits each. These septets need to be transformed into octets for the SMS transfer.

hellohello
104101108108111104101108108111
1101000110010111011001101100110111111010001100101110110011011001101111
1101000
1100101
1101100
1101100
1101111
1101000
1100101
1101100
1101100
1101111

The first septet (h) is turned into an octet by adding the rightmost bit of the second septet. This bit is inserted to the left which yields 1 + 1101000 = 11101000 ("E8"). The rightmost bit of the second character is then consumed, so the second character (septet) needs two bits (yellow) of the third character to make an 8bit octet. This process goes on and on yielding the following octets:

11101000
00110010
10011011
11111101
01000110
10010111
11011001
11101100
110111
E8329BFD4697D9
EC37

The 9 octets from "hellohello" are E8 32 9B FD 46 97 D9 EC 37


+CMS ERROR

Message service error
Description These are the error codes for +CMS ERROR.
Error code Meaning 
0-127 GSM 04.11 Annex E-2 values 
128-255 GSM 03.40 section 9.2.3.22 values 
300 Phone failure 
301 SMS service of phone reserved 
302 Operation not allowed 
303 Operation not supported 
304 Invalid PDU mode parameter 
305 Invalid text mode parameter 
310 SIM not inserted 
311 SIM PIN necessary 
312 PH-SIM PIN necessary 
313 SIM failure 
314 SIM busy 
315 SIM wrong 
320 Memory failure 
321 Invalid memory index 
322 Memory full 
330 SMSC (message service center) address unknown 
331 No network service 
332 Network timeout 
500 Unknown error 
512 Manufacturer specific 



No comments:

Post a Comment

Note: only a member of this blog may post a comment.