PDU code and decoding of SMS (turn)

Source: Internet
Author: User
Tags reserved

Original link: http://www.cppblog.com/zhangyq/archive/2009/07/04/89245.html

There are three ways to send and receive SMS information: Block Mode, Text Mode, and PDU mode. PDU mode is supported by all mobile phones and can use any character set, which is the default encoding of the phone.

Send short messages commonly used text and PDU (Protocol Data Unit, Protocol) mode. Use text mode to send and receive short message code simple, easy to achieve, but the biggest drawback is not to send and receive Chinese text messages, and PDU mode not only support Chinese text messages, but also send English text messages. PDU mode send and receive SMS can use 3 kinds of encoding: 7-bit, 8-bit and UCS2 encoding. The 7-bit encoding is used to send a generic ASCII character that encodes a string of 7-bit characters (up to 0) into 8-bit data, each 8 character "compressed" into 7; 8-bit encoding is often used to send data messages, such as pictures and ringtones. , and the UCS2 encoding is used to send Unicode characters. In these three coding modes, the maximum capacity of the user information (Tp-ud) segment of the PDU string (the maximum number of characters for the short message that can be sent) is 160, 140, and 70, respectively. Here, an English letter, a Chinese character, and a data byte are treated as one character.
The user information length (tp-udl) of the PDU string has different meanings in various coding modes. 7-bit encoding refers to the number of characters of the original short message, not the number of bytes encoded. 8-bit encoding is the number of bytes. When UCS2 is encoded, it is also a byte number, equal to twice times the number of characters in the original short message. If there is a header in the user information (Tp-ud) (The Tp-udhi of the basic parameter is 1), the user information length (tp-udl) is equal to the sum of the length of the header and the number of bytes encoded in the encoding mode. If the proposed compression algorithm for GSM 03.42 (Tp-dcs 3 bits is 001), the length is also the sum of bytes after compression encoding or the length of the header and the number of bytes after compression.

A PDU is the equivalent of a packet consisting of information that constitutes a message (SMS). As a data unit, it must contain the source/destination address, protection (valid) time, data format, protocol type, and body text, which can be up to 140 bytes in length, and they are all represented in hexadecimal. The PDU structure is based on a short message that is initiated by a mobile terminal or with a mobile terminal for different purposes. Each message can send 140 bytes, because the longest string in the system does not have more than 140 bytes, so data can be sent with a single message.
The general PDU code consists of a B C D E F G H I J m 13.
A: SMS Center address length, 2-bit hexadecimal (1-byte).
B: Short Message Center number type, 2-digit hexadecimal number.
C: The SMS Center number, the length of the b+c will be determined by the data in a.
D: File header Byte, 2-bit hexadecimal number.
E: Information type, 2-bit hexadecimal number.
F: Called number length, 2-digit hexadecimal number.
G: Called number type, 2-digit hexadecimal number, value same as B.
H: Called number, length is determined by the data in F.
I: Protocol ID, 2-bit hexadecimal number.
J: Data encoding scheme, 2-bit hexadecimal number.
K: Valid, 2-digit hexadecimal number.
L: User data length, 2-bit hexadecimal number.
M: User data, whose length is determined by the data in L. J is set to use UCS2 encoding, here is the Unicode character in English and Chinese.
PDU Coding Protocol Simple Description
Example 1 Send: SMSC number is+8613800250500, the other number is13693092030, the message content is "hello!”。 The PDU string sent from the phone can be
F0 0D F0 C8 (9B FD), at the same, and the 0E 01 of a
Control specifications, specific analysis:
Paragraph meaning description
ASMSC Address information has a total of 8 eight-bit bytes (including 91)
theSMSC address Format (TON/NPI) in international format number (plus ' + ' in front)
F0 ASMSC address 8613800250500, complement ' F ' together into several
OneBasic parameters (TP-MTI/VFP) sent, TP-VP in relative format
ofMessage base value (TP-MR) 0
0DThe destination address number is a total of 13 decimal digits (excluding 91 and ' F ')
theDestination address format (TON/NPI) in international format number (plus ' + ' in front)
The F0Target Address (TP-DA) 8613693092030, complement ' F ' together into even several
ofProtocol identification (TP-PID) is a common GSM type, point-to-point way
ofUser information encoding Method (Tp-dcs) 7-bit encoding
ofValidity period (TP-VP) 5 minutes
- ModifiedUser information Length (TP-UDL) actual length 6 bytes
C8 9B FD 0EUser information (Tp-ud) "hello!"
Example 2 Receive: SMSC number is+8613800250500, the other number is13693092030, the message content is "How do you do?”。 The PDU string that the handset receives can be
F0 0D F0 (4F) 7D 00 21, at the same, and at the same, in the same.
Control specifications, specific analysis:
Paragraph meaning description
ALength of address information eight-bit bytes (including 91)
theSMSC address Format (TON/NPI) in international format number (plus ' + ' in front)
F0 ASMSC address 8613800250500, complement ' F ' together into several
theBasic parameters (TP-MTI/MMS/RP) receive, no more messages, have reply address
0DThe number of reply addresses is 13 decimal digits (excluding 91 and ' F ')
theReply to address format (TON/NPI) in international format number (plus ' + ' in front)
The F0Reply Address (Tp-ra) 8613693092030, complement ' F ' together with several
ofProtocol identification (TP-PID) is a common GSM type, point-to-point way
AUser information encoding Method (Tp-dcs) UCS2 encoding
under theTimestamp (tp-scts) 2003-3-12 08:36:45 + 8 time zone
- ModifiedUser information Length (TP-UDL) actual length 6 bytes
4F 7DUser information (tp-ud) "Hello!"

Detailed resolution:
0891683108200505f011190d91683105155694f50008ff10008ff044f60597d
<1> SMS Center Address field: 0891
08:address-lengt (address length), SMS Center address length is 8 bytes, is () + (683108200505f0) length, 8 8-bit bytes
91 Address Type: 10010001 bit7:1. Always 1 Bits 6,5,4:type-of-number (type of numbers): 001, representing internation number. Also is the number before adding "+". Note: For some of the more specific numbers, such as mobile phone and PHS interoperability, this can not be set to 001, but to set to 000, the number of representatives before the "+", otherwise can not receive.
The following is an explanation of the GSM03.40 protocol number type:
0 0 0 Unknown
0 0 1 International number
0 1 0 National number
0 1 1 Network specific number
1 0 0 Subscriber number
1 0 1 alphanumeric (coded according to TS03.38 7-bit default alphabet)
1 1 0 abbreviated number
1 1 1 Reserved for extension
ll not interpret reserved values but would store them as received.
Bits 3,2,1,0:numbering-plan-identification (number identification), 0000-unknown, 0001-isdn/phone number (e.164/e.163), 1111-left for expansion; general defaults to 0001, That represents the type of phone number. The following is an explanation of the GSM03.40 number identification:
BITS3 2 1 0
0 0 0 0 Unknown
0 0 0 1 isdn/telephone Numbering Plan (e.164/e.163)
0 0 1 1 Data numbering Plan (x.121)
0 1 0 0 Telex numbering plan
1 0 0 0 National numbering plan
1 0 0 1 Private numbering plan
1 0 1 0 ermes numbering Plan (ETSI de/ps 3 01-3)
1 1 1 1 Reserved for extension
All other values are reserved.
<2> SMS Center number: 683108200805f0
A byte inversion, 8613800280500, if the length is odd, you need to add "F" to be padded. For example, the number is: +8613505165495, remove "+" at the end of the add F to: 8613505165495F, and then the phone number of odd digits and even number of the exchange of 683105155694F5
<3>firstoctet field: 1119
(1) 11 contains TP-MTI (2bit), Tp-rd (1bit), TP-VPF (2bit), TP-RP (1bit), Tp-udhi (1bit), TP-SRR (1bit)
Binary representation: 0 0 0 10 0 01
TP-MTI:01 tp-message-type-indicator (Message type indicator)

     bit1,0:00-read out (Deliver);  01-commit (Submit)
Bit1,0:01 indicated as sms-submit type  
The following is an explanation of GSM03.40:
 bit1 bit0  Message type
 0     0    Sms-deliver (in the direction SC to MS)
 0     0    sms-deliver Direction MS to SC)
 1     0    Sms-status-report (in the direction SC to MS)
 1     0    Sms-command (in the direction MS to SC)
 0      1    Sms-submit (in the direction MS to SC)
 0     1     Sms-submit-report (in the direction SC to MS)
 1    1       reservedtp-rd:0  tp-reject-duplicates (Reject same duplicate message)

bit2:0-accept replication; 1-Reject Replication

bit2:0 instructs the short message center to receive a message that is not forwarded with the same TP-MR.
Bit 2:
0 instruct the SC to accept a sms-submit for a SM still held in the SC which has the same tp-mr and the same tp-da a s a previously submitted SM from the same OA.
1 instruct the SC to reject a sms-submit for a SM still held in the SC which has the same tp-mr and the same tp-da As the previously submitted SM from the same OA. In this case an appropriate Tp-fcs value would be returned in the Sms-submit-report.
Tp-vpf:10 Tp-validity-period-format (validity format)

Bit4,3::00-does not provide (not present), 01-reserved, 10-integer (standard), refers to the use of relative format, 11-Provides 8-byte half (Semi-octet represented)
Here's an explanation of GSM03.40:
BIT4 bit3
0 0 TP-VP Field not present
1 0 TP-VP Field present and integer represented (relative)
0 1 Reserved
1 1 TP-VP Field present and Semi-octet represented (absolute)
tp-srr:0 Tp-status-report-request
Bit5:1: Need to report, 0: no report required.
Bit 5:
0 A status are not requested
1 A status is requested
tp-udhi:0 tp-user-data-header-indicator (User Data header) Bit6:1: header information 0: does not contain header information, indicates that this is an SMS message, no user data header, EMS (enhanced messaging Service) message needs to be set. Picture ringtones These all contain header information. Text does not contain header information
Bit 6
0 The Tp-ud field contains only
1 The beginning of the Tp-ud field contains a Header in addition to
tp-rp:0 Tp-reply-path (reply path) Bit7:1: Set reply path, 0: No reply path set.
Here is the GSM03.40 explanation:
Bit 7:
0:tp-reply-path parameter is not set in this Sms-submit/deliver
1:tp-reply-path parameter is set in this Sms-submit/deliver
(2) Message reference value TP-MR (tp-message-reference): 19 If you use the "00" value, you let the phone set the message reference value yourself.

<4> offset Number field: 0D913105155694F5
0D: Number of destination addresses, total 13 decimal digits (excluding 91 and ' F ')
91: Address type, with SMS Center number settings.
3105155694F5: Target cell phone number.

<5> upper layer Protocol Identification Tp-pid (Tp-protocol-identifier): 00
General set to 00, means common GSM, point-to-point <6> Data Coding settings Tp-dcs (tp-data-coding-scheme): 08
Indicates how the TP-UD is encoded. 08 represents the Unicode method. Refer to the GSM03.38 protocol:
Bit 3,2
Default alphabet
8 bit
Ten UCS2 (16bit) [10]
One Reserved
<7> validity TP-VP (tp-validity-period): FF
FF represents the largest.
<8> User Data length tp-udl (tp-user-data-length): 4
The actual length of the user data. Note that user lengths are defined differently under different encodings.
<9> User data: 4f60597d "Hello" Unicode encoding
You: 0x4f60; good: 0x597d
2: Mobile phone to receive PDU string
0891683108200505f0040d91683105155694f5000850208151754500044f60597d
<1> SMS Center Address field: 0891683108200505F0, which is +8613800250500
<2>firstoctet:04 Binary code: 00000100
tp-mti:00
Tp-mms (tp-more-message-to-send): 1 SMS Center no more messages to send
tp-sri:0
tp-udhi:0
tp-rp:0
<3> Sender Number: 0d91683105155694f5 +8613505165495
<4> Agreement identification: Tp-dcs Point
<5> encoding: Tp-dcs Unicode encoding
<6> SMS Center Time 50208151754500
Byte reversal 05/02/18 15:57:45 The last 00 represents the time zone, here is 0
<7> User Data length: 4
<8> User data: 4f60597d
Unicode encoding for "Hello" in Chinese

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.