Original article: http://blog.csdn.net/bhw98/archive/2003/03/27/19666.aspx
We need to understand the SMS specification developed by ESTI. The rules related to short message sending and receiving discussed mainly include GSM 03.38, GSM 03.40, and GSM 07.05. The first two focuses on the technical implementation of SMS (including the encoding method), the latter sets out the DTE-DCE interface standard of SMS (AT command set ).
There are three methods to send and receive SMS messages: block mode, text mode, and PDU mode. Block Mode is a waste of time and is rarely used at present. Text mode is a text-only method. It can use different character sets and can be used technically to send short messages in Chinese. However, Chinese mobile phones are basically not supported in China and are mainly used in Europe and America. PDU mode is supported by all mobile phones and can use any character set. This is also the default encoding method for mobile phones. Text mode is simple and not suitable for custom data transmission. The following describes how to send and receive short messages in PDU mode. Original article: http://blog.csdn.net/bhw98/archive/2003/03/27/19666.aspx
We need to understand the SMS specification developed by ESTI. The rules related to short message sending and receiving discussed mainly include GSM 03.38, GSM 03.40, and GSM 07.05. The first two focuses on the technical implementation of SMS (including the encoding method), the latter sets out the DTE-DCE interface standard of SMS (AT command set ).
There are three methods to send and receive SMS messages: block mode, text mode, and PDU mode. Block Mode is a waste of time and is rarely used at present. Text mode is a text-only method. It can use different character sets and can be used technically to send short messages in Chinese. However, Chinese mobile phones are basically not supported in China and are mainly used in Europe and America. PDU mode is supported by all mobile phones and can use any character set. This is also the default encoding method for mobile phones. Text mode is simple and not suitable for custom data transmission. The following describes how to send and receive short messages in PDU mode.
A pdu string is an ascii code consisting of numbers and letters '0'-'9' and 'A'-'F. They are 8-bit hexadecimal numbers or BCD decimal numbers. The PDU string contains not only the displayed message, but also many other information, such as the SMS service center number, target number, reply number, encoding method, and service time. The structure of the PDU string sent and received is different. We first use two actual examples to describe the structure and arrangement of the PDU string.
Example 1 sending: the SMSC number is + 8613800250500, the peer number is 13851872468, and the message content is "Hello !". The PDU string sent from the mobile phone can be
08 91 68 31 08 20 05 05 F0 11 00 0d 91 68 31 58 81 27 64 F8 00 00 00 06 C8 32 9B FD 0e 01
For detailed analysis, refer to the following specifications:
Segmentation |
Description |
Description |
08 |
Length of SMSC address information |
A total of 8 8 bits (including 91) |
91 |
SMSC address format (ton/NPI) |
Number in international format (Add '+' in front ') |
68 31 08 20 05 05 F0 |
SMSC address |
8613800250500, fill in 'F' into an even number |
11 |
Basic parameters (TP-MTI/VFP) |
Sent, TP-VP in relative format |
00 |
Message Reference value (TP-MR) |
0 |
0d |
Number of target addresses |
A total of 13 decimal numbers (excluding 91 and 'F ') |
91 |
Target address format (ton/NPI) |
Number in international format (Add '+' in front ') |
68 31 58 81 27 64 F8 |
Destination Address (TP-DA) |
8613851872468, fill in 'F' into an even number |
00 |
Protocol identifier (TP-PID) |
Common GSM type, point-to-point mode |
00 |
User Information encoding method (TP-DCS) |
7-bit encoding |
00 |
Validity Period (TP-VP) |
5 minutes |
06 |
User Information length (TP-UDL) |
The actual length is 6 bytes. |
C8 32 9B FD 0e 01 |
User Information (TP-UD) |
"Hello !" |
Example 2 receive: the SMSC number is + 8613800250500, the peer number is 13851872468, and the message content is "Hello !". The PDU string received by the mobile phone can be
08 91 68 31 08 20 05 05 F0 84 0d 91 68 31 58 81 27 64 F8 00 08 30 21 80 63 54 80 06 4f 60 59 7d 00 21
For detailed analysis, refer to the following specifications:
Segmentation |
Description |
Description |
08 |
Length of address information |
8-bit bytes (including 91) |
91 |
SMSC address format (ton/NPI) |
Number in international format (Add '+' in front ') |
68 31 08 20 05 05 F0 |
SMSC address |
8613800250500, fill in 'F' into an even number |
84 |
Basic parameters (TP-MTI/MMS/RP) |
Receive, no more messages, reply address |
0d |
Number of reply addresses |
A total of 13 decimal numbers (excluding 91 and 'F ') |
91 |
Reply address format (ton/NPI) |
Number in international format (Add '+' in front ') |
68 31 58 81 27 64 F8 |
Reply address (TP-RA) |
8613851872468, fill in 'F' into an even number |
00 |
Protocol identifier (TP-PID) |
Common GSM type, point-to-point mode |
08 |
User Information encoding method (TP-DCS) |
Ucs2 Encoding |
30 30 21 80 63 54 80 |
Timestamp (TP-SCTS) |
2003-3-12 08:36:45 + 8 Time Zone |
06 |
User Information length (TP-UDL) |
The actual length is 6 bytes. |
4f 60 59 7d 00 21 |
User Information (TP-UD) |
"Hello !" |
If the maximum bit (TP-RP) of the basic parameter is 0, there are no three segments that reply to the address. This is often the case for short messages sent from the Internet.
Note that the expression of the number and time does not follow the normal order, and the odd number must be supplemented into an even number with 'F.
QIn the above two examples, the 7-bit and ucs2 encoding methods have appeared. Please introduce these encoding methods in detail?
AIn PDU mode, three encoding methods can be used to encode the sent content: 7-bit, 8-bit, and ucs2. 7-bit encoding is used to send Common ASCII characters. It encodes a string of 7-bit characters (the highest bit is 0) into 8-bit data, each 8 characters can be "COMPRESSED" into 7; 8-bit encoding is usually used to send data messages, such as slices and ringtones; while ucs2 encoding is used to send Unicode characters. The maximum size of the user information (TP-UD) segment of the PDU string is 140 bytes, so the maximum number of characters of short messages that can be sent in these three encoding modes is 160, 140, and 70, respectively. Here, an English letter, a Chinese character, and a Data byte are regarded as a character.
It should be noted that the user information length (TP-UDL) of the PDU string has different meanings in various encoding methods. 7-bit encoding refers to the number of characters of the original Short Message, rather than the number of bytes After encoding. 8-bit encoding is the number of bytes. Ucs2 encoding is also the number of bytes, which is twice the number of characters of the original short message. If a header exists in user information (TP-UD for basic parameters is 1), the length of user information (TP-UDHI) in all encoding modes) both are equal to the sum of the header length and the number of encoded bytes. If the compression algorithm recommended by GSM 03.42 is adopted (the High 3-bit TP-DCS is 001), the length is also the sum of the number of bytes after compression or the length of the header and the number of bytes after compression.
The following example describes the 7-bit encoding process. We sent an English text message "Hello !" Encoding:
The source string is encoded into a group of 8 characters (less than 8 characters in this example), and the characters in the group are compressed, but there is no connection between each group.