Wap push parsing (1) -- sms pdu Encoding

Source: Internet
Author: User

Tian haili @ csdn

2012-06-29

 

Wap push is encapsulated in sms pdu. To resolve wap push, you must first read the sms pdu code, which is the basis of services such as SMS, MMS, and wap push. Wap push is sent to the terminal. Therefore, this article mainly describes the delivery PDU encoding. In addition, if the content to be encapsulated by the PDU is too long, multiple split SMS messages will be received. This article also describes how to splice the received concatenated SMS messages.

 

1. encapsulation of a single SMS PDU

The following is a complete PDU:

0891683108200105f04408a0015608860104216092902512236e0605040b8423f0120601ae02056a0045c60c033231312e3133362e3130372e37382f646f776e2e7068703f703d413063303026733d383500080103e68e8ce68fa1e882a1e5b882e58588e69cbaefbc8ce6aca2e8bf8ee4bdbfe794a8e6898be69cbae8af81e588b8e38082000101

(Note: Due to display reasons, the Branch is manually implemented. In fact, there is no line break in the middle of the package)

The encapsulation of sms pdu does not have a fixed meaning in all locations. It is scanned one by one. After the last field is parsed, the subsequent meaning or the length of the subsequent field is known.

1. SMS Center
 
The SC length is 08, so the next 8 bytes is the SMS center content SC 916830000200105f0 91 is the international number, plus the '+' number; the subsequent number encoding rules are GSM BCD: 683104200105f0-> 8613800210500. Therefore, the SMS center number is + 8613800210500.

 

Now the PDU is scanned in red (the green part has been scanned ):

Bytes

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

 

2. firstbyte:
 
0x44 = 0100 0100 bit1.bit0: MTI 00 delevery 01 submit 10 Status Report bit7: TP-reply-Path 1 0 No bit6: Indicates whether there is userdata header (UDH) 1 0 No bit4.bit3: TP-validity-period (submit type PDU only make sense) 00: Len = 0 10: Len = 1 01/11: Len = 7

 

Now the PDU is scanned in red (the green part has been scanned ):

Bytes

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

 

3. sender address)
 
Address length: length = 08 get the number of bytes occupied by the address (including the length itself): 2 + (Length + 1)/2 = 6 address in 08a001560886 08 a001560886 Toa: 0xa0 = 1010 0000 bit7: Must be 1 bit6... bit4: ton = 010 000 ton_unknown (0) 001 ton_international (1) 010 ton_national (2) 011 ton_network (3) 100 ton_subscriber (4) 101 ton_alphanumeric (5) 110 ton_abbreviated (6) therefore, the sender address is: 01560886-> 10658068

 

Now the PDU is scanned in red (the green part has been scanned ):

08916830000200105f000008a0015608860104216092902512236e0605040b8423f0120601ae02056a

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

 

4. TP-Protocol-identifier (TP-PID)
   TS 23.040 9.2.3.9
   01

 

Now the PDU is scanned in red (the green part has been scanned ):

Bytes

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

 

5. TP-data-coding-Scheme
 (TS 23.038)
 
0x04 = 0000 0100 bit7: If this bit is 0 bit6: automaticdeletion bit5: userdatacompressed bit4: hasmessageclass if (! Userdatacompressed) // bit5 bit3... bit2: 00 encoding_7bit 10 encoding_16bit 01/11: encoding_8bit bit7... bit4: if the four digits are 1111 bit2: 0 encoding_7bit 1 encoding_8bit bit7... bit4: if the four digits are 1100,110 1 or 1110 1110 1100/1101 encoding_16bit (UCS-2) encoding_7bit bit1... bit0: if there is class 00 class_0 01 class_1 10 class_2 11 class_3, the data in this PDU package is 8 bit encoded and there is no class type.

 

Now the PDU is scanned in red (the green part has been scanned ):

Bytes

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

 

6. TP-service-centre-time-stamp
The timestamp issued by the SMS center. The encoding and length are fixed.
 
21609290251223 21 year: 12 60 month: 06 92 day: 29 90 hour: 09 25 minute: 52 12 second: 21 23 timezone byte time zone as high as 4 bit at low, when the low 4-bit bit3 is in the high position, the time zone +/-flag is calculated as 1/4 Time Zone 0x23 = 0010 0011 bit3: sign symbol 0 + 1-0010x011-> x011 0010 = 0011 0010 32/4 = 32 [quarter-Hour] timezone: + = + 8

 
Therefore, the obtained timestamp is 12-06-29 09:52:21 GMT + 8.

Now the PDU is scanned in red (the green part has been scanned ):

Bytes

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

 

7. userdataheader-UDH
 
Userdatalength: The length contains UDH and UD, but does not contain the byte 0x6e = 110 userdataheaderlength: The length does not include the byte itself 0x06 = 6 userdataheader: 05040b8423f0 UDH can have multiple segments, therefore, we need to constantly parse the data until the end of the UDH. Each segment has an ID at the beginning of the meaning, followed by the number of bytes of the data in the specific meaning, then the specific data ID is-0x05 0x00 then 0x08 then 0x05 then 0x04 then 0x24 elt_id_national_1_age_single_shift 0x25 elt_id_national_1_age_locking_shift length: 4 DEST Port: 0b84-> 0x0b84 = 2948 2948 for wap_push SRC port: 23f0-> 0x23f0

 
PDU uses ports to identify specific services. For example, the destination port of the PDU is 2948, which is the PDU encapsulation of wap push.
In addition, if it is still long SMS, the UDH also contains the information required for long SMS splicing, which has multiple meanings.

 

Now the PDU is scanned in red (the green part has been scanned ):

Bytes

Bytes

Bytes

8be69cbae8af81e588b8e31682000101

Now, the basic information of the PDU package has been parsed, and the rest is userdata, which has also differentiated specific services and can be parsed by specific business modules.

 

Ii. encapsulation of multiple SMS PDU

Due to the limitation of the length of a single SMS, the sending of a long SMS is divided into multiple SMS messages, and multiple messages are received at the time of receipt, and then spliced.

The following example shows two sms pdus of a long SMS received twice:

PDU [0]

0891683108200105f04405a02125f00004216092717455238c0b05040b8423f000030b0201790601
ae02056a0045c6080c03662e31303038362e636e2f662f736a6678000103e689bee69c8be58f8be3
8081e69fa5e5a4a9e6b094e38081e79c8be5b08fe8afb4e38081e79c8be696b0e997bbe280a6e689
8be69cbae9a39ee4bfa1efbc8ce7ae80e58d95e4bda0e79a84e7949fe6b4bbefbc81e8b5b6e5bfab
e4b88be8bd

 

PDU [1]

0891683108200105f04405a02125f0000421609271745523220b05040b8423f000030b0202bde4bd
93e9aa8ce6898be69cbae9a39ee4bfa1000101

 

The userdataheader contains multiple SMS messages. We will analyze them from here.

1. parts before UDH
PDU [0] And PDU [1] have the same content before UDH, and are the same as the encapsulation of a single sms pdu. Therefore, we will not describe the parsing of this part here.
 
2. userdataheader-UDH
 
Userdatalength: contains the UDH and UD, but does not contain this byte. Its length refers to the PDU in this PDU. [0]: 0x8c = 140 PDU [1]: 0x22 = 34 userdataheaderlength: This length does not contain the byte itself 0x0b = 11 userdataheader: UDH can have multiple segments, so it must be resolved continuously, until the end of the UDH, each segment of the Meaning starts with an ID, followed by the number of bytes of the specific meaning of the data, followed by the specific data PDU [0]: 05040b8423f0 00030b0201 PDU [1]: 05040b8423f0 00030b0202 ID-0x05 0x00 limit 0x08 elt_id_concatenated_16_bit_reference 0x05 elt_id_applicatio N_port_addressing_16_bit 0x04 bytes 0x24 bytes 0x25 elt_id_national_1_age_locking_shift length: 4 DEST port: 0b84-> 0x0b84 = 2948 2948 port_wap_push SRC Port: 23f0-> 0x23f0 indicates that this is the PDU encapsulation ID of wap push-0x00 length: 03 concatref. refnumber: 0b concatref. msgcount: 02 concatref. seqnumber: PDU [0]: 01 PDU [1]: 02 This indicates that this is a PDU package split from long SMS: Refnumber indicates the long SMS, each split package has the same refnumber msgcount long SMS split Package number seqnumber indicates the order in which the package arrived in each split package: value 1 .. msgcount does not necessarily follow the order in which the split packets arrive at the receiving end.

 

3. userdata

This is a long SMS split, so userdata needs to be spliced in the seqnumber order.

PDU [0]

0891683108200105f04405a02125f00004216092717455238c0b05040b8423f000030b0201790601
ae02056a0045c6080c03662e31303038362e636e2f662f736a6678000103e689bee69c8be58f8be3
8081e69fa5e5a4a9e6b094e38081e79c8be5b08fe8afb4e38081e79c8be696b0e997bbe280a6e689
8be69cbae9a39ee4bfa1efbc8ce7ae80e58d95e4bda0e79a84e7949fe6b4bbefbc81e8b5b6e5bfab
e4b88be8bd

PDU [1]

0891683108200105f04405a02125f0000421609271745523220b05040b8423f000030b0202bde4bd
93e9aa8ce6898be69cbae9a39ee4bfa1000101
 
Concatenate the red userdata in PDU [0] And PDU [1] to obtain the complete userdata.
 
790601ae02056a0045c6080c03662e31303038362e636e2f662f736a6678000103e689bee69c8be5
8f8be38081e69fa5e5a4a9e6b094e38081e79c8be5b08fe8afb4e38081e79c8be696b0e997bbe280
a6e6898be69cbae9a39ee4bfa1efbc8ce7ae80e58d95e4bda0e79a84e7949fe6b4bbefbc81e8b5b6
e5bfabe4b88be8bdbde4bd93e9aa8ce6898be69cbae9a39ee4bfa1000101
 

So far, complete userdata has been obtained, and specific services have been differentiated in UDH, which can be resolved by specific business modules.

 

Iii. Summary

Delivery sms pdu can be parsed as follows: Service centre (optional), UDH, PDU identification, Sender number, TP-pid, encoding format, class type (optional), timestamp, UDH (optional. Include: length of userdata, length of userdataheader, possible port number or Concat information, etc.) and userdata containing specific business data.

The Encapsulation Format of the specific wap push Service in userdata is described in the following articles: wap push parsing (2) -- WSP and wbxml encoding and wap push parsing (3) -- Implementation in Android.

 

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.