Text message content format and Compression Method

Source: Internet
Author: User

 

Author: scruffybear

Release time: 29/08/2007

If any reprint is available, please indicate the source and maintain the integrity of the Article. Thank you!

The project for police service communication in March involves modifying the existing text message content, that is, patching COs to modify the text message content, here, we will briefly introduce the formats and compression methods of GSS and CSS.
1. General Format of GSMs
Gss sms format fully complies with the gsm03.40 specification, so it is easy to parse the existing SMS through the existing specification. The card organizes text messages according to the gsm11.14 specification. The command tag for sending text messages is '13', And the SMS tpdu tag is '0b/8B '. For more information, see this specification, the text message format is as follows:
Fetch command to get text message content:
Bytes
Command details 01/81 03 0a (command number) 13 (command tag) 00 (command qualifier) This item is mandatory (mandatory)
Device identities 02/82 02 81 (SIM) 83 (network) This item is mandatory (mandatory)
Alpha identifier 05/85 0d 8077ed4fe153d190014e2d2026 (sending sms ...) This option should be optional (optional)
Address tag is not found in this example. For example: 06/86 08 ffffffffffffffff this item should be optional (optional)
SMS tpdu tag 0b/8B 13 01000881949488110008081234567812345678 (this content is described in gsm03.40)
The content of the SMS tpdu is explained by the gsm03.40 specification. For details, see section 9.2 of the specification, service provided by the SM-TL (the short message transfer layer ), only the tpdu of this text message is explained. The content is as follows: 0b/8B 13 01000881949488110008081234567812345678. This text message is of the submit type:
TP-MTI (TP-message-type-indicator), 01, bit1, bit0, the minimum two is 01, indicating that the text message content is SMS-SUBMIT (in the direction MS to SC), bit4, bit3 is 00, indicating that the SMS has no TP-VP field: 0 0 TP-VP field not present
TP-MR (TP-message-reference) 00
Tpda (TP-destination-address) 088194948811, the length of tpda is (LEN + 1)/2 + 1, in this example, is (8 + 1) /2 + 1 = 5
TP-PID (TP-Protocol-identifier) 00
The TP-DCS (TP-data-coding-Scheme) 08
TP-VP (TP-validity-period) is not included in this message, which indicates the validity period of the message.
TP-UDL + tpud (TP-user-data-Length + TP-user-data) 081234567812345678
Note: The length of tpudl is the length before compression.
For more information, see the relevant specifications.

2. GSS text message compression and compilation implementation
Due to the need to compress the GNET text message in the patch, and it is not convenient to call the existing function, the GNET text message compression is implemented using the assembly.
GNET text message compression format in the TP-DCS instructions, TP-DCS in the "gsm03.38" has instructions, generally use the 7bit encoding compressed into 8bit encoding method, this compression method is also described in gsm03.38.
The compression encoding method compresses 8-byte 7-bit encoding into 7-byte 8-bit encoding. That is to say, 160-byte long text messages can be compressed into 140-byte text messages and 20 bytes are compressed. The specific compression method is as follows:
The original 8-byte uncompressed encoding is as follows:
-Bits Number:
6 5 4 3 2 1 0
1A 1B 1C 1D 1E 1f 1g
2a 2B 2C 2D 2E 2f 2G
3A 3B 3C 3D 3E 3f 3G
4A 4B 4C 4D 4E 4f 4G
5A 5B 5C 5d 5E 5f 5g
6a 6B 6C 6D 6e 6f 6g
7A 7b 7C 7d 7E 7f 7G
8A 8B 8C 8d 8e 8f 8g
After compression, the 8bit encoding is as follows:

-Eight Characters in seven octets:
-Bits Number:
7 6 5 4 3 2 1 0
2G 1A 1B 1C 1D 1E 1f 1g
3f 3G 2a 2B 2C 2D 2E 2f
4e 4f 4G 3A 3B 3C 3D 3E
5D 5E 5f 5g 4A 4B 4C 4D
6c 6D 6e 6f 6g 5A 5B 5C
7b 7C 7d 7E 7f 7g 6a 6b
8A 8B 8C 8d 8e 8f 8g 7A
From the preceding compression method, we can see that after the first compression, the byte is the first 7-bit plus the second 7-bit bytes at the highest bit, the second compressed byte is the second 7-bit high six-bit plus the third 7-bit low two-bit, and so on. The seventh compressed byte (the last compressed byte) is the maximum bit of the seventh 7bit plus the seven digits of the eighth 7bit. In this way, the 8-byte 7-bit encoding is compressed into 7-byte 8-bit encoding.
For example, string 3132333435363738 is 7-bit encoded and is now compressed into 8-bit encoding.
3132333435363738 to 00110001 (31) 00110010 (32) 00110011 (33) 00110100 (34) 00110101 (35) 00110110 (36) 00110111 (37) 00111000 (38 ), the conversion process is as follows:
A: Convert the bytes of to the highest bit of 31. 31 remains unchanged. The first compressed byte is 31.
B. For 32-bit conversion, because of the percentile bit, it is equivalent to moving one digit to the right, which is 00011001. Put the lower two digits of 33 on the 31 high digits of the right shift, that is, 11011001, that is, D9.
C. The conversion is 33,33. Because the lower two digits are obtained, the two digits are shifted to the right, which is 00001100. the lower three digits of 34 are placed on the 33 high positions of the right two digits, that is, 10001100, that is, 8C.
D, conversion 34, 34 because the low three digits are taken, it is equivalent to moving three digits to the right, for 00000110, put the lower four digits of 35 on the 34 high position of the right three, that is, 01010110, that is, 56.
E. The conversion of 35 to 35 is as low as four bits, which is equivalent to moving four bits to the right, which is 00000011. Put the lower five bits of 36 to the 35 bits of the four bits to the right, that is, 10110011, that is, B3.
F. The conversion is 36,36. Because the lower five bits are obtained, the fifth bits are shifted to the right, which is 00000001, and the lower six bits of 37 are placed on the 36 bits of the right-shifted five-bits, that is, 11011101, DD.
G, the conversion is 37,37 because the lower six bits are taken, it is equivalent to moving the six bits to the right, which is 00000000, and placing the whole seven bits of 38 on the 37 high position of the right six bits, that is, 1110000, that is, 70.
3132333435363738 of the 7-bit encoding is compressed to 31d98c56b3dd70 of the 7-byte, that is, one byte is compressed.
During encoding, the text message before compression can be processed in a group of 8 bytes and processed as the compressed seven bytes to form an outer loop. The number of cycles is the length of the text message divided by 8 and then rounded up, for example, 11/8 = 1, 1 + 1 = 2, that is, after two cycles. During inner loop processing, seven cycles are required. When the number of loops reaches N (0 <n <8), the current byte is first shifted to n-1 bits, take the lower N bits of the last byte and place them at the higher N bits after the right-shifted n-1 bits of the Current byte. In this way, 8 bytes can be compressed and the entire text message can be compressed.
As it involves processing a lot of related environment variables, only the framework of Assembly implementation is listed here (Standard 51 assembly, dual dptr) as follows:

Dptr and dptr1 both point to the beginning of the text message. R1 stores the outer loop variable. The inner loop variable is R2 and the initial value is 1. R3 stores the total length of characters to be converted, and configured.
In fact, each inner loop is processed in two bytes. Here, the two bytes are called the first byte and the second byte respectively.
In each layer loop, the lower R2 of the second byte is placed on the upper R2 bit of the first byte, and the second byte is shifted to the lower R2 bit as the first byte of the next inner loop.
Movx A, @ dptr
MoV R6, A; R6 is the first byte before the first processing.
Out_transbegin:; at the beginning of the outer loop, the loop [Len/8] (Note that it is rounded up.
MoV R2, #1; Before the outer loop, you need to change the internal loop R2 to 1
Transbegin:; the starting point of the inner loop. The loop is 7 times.
MoV A, R6; the 2nd number of last loop as the first number.
MoV R5, A; R5 store the 1st number.
INC dptr
Movx A, @ dptr
MoV R6, A; R6 store 2rd number.

MoV r0, A; store the second byte in R0 for later use.

MoV A, R2; 2*2 *... * 2 (R2 2)-1
MoV R7,
Lcall power2; power2 is the Npower of 2. N is passed in from R7. The implementation of the power2 function is very simple and is not listed here.
CLR C
Subb A, #01 H; 2*2 *... * 2-1: 2's R2 power minus one, 2exp (R2)-1
Anl a, R6; 2nd number & 111... 11, takes the lower R2 bits of the last byte. For example, in the first loop, the second bits are used. 2exp (1)-1 = 1, take the nth bit. If 2exp (2)-1 = 3, take the lowest two.
MoV R6, A; R6 store the ANL result

MoV A, #8; Calculate 8-r2, take the lower R2 bit of the second byte, move it to the left (8-r2) bit, and finally perform or operation with the first byte.
CLR C
Subb A, R2; 8-r2
MoV R7, A; R7 is the input parameter, that is, the number of shifts left.
MoV A, R6; ANL operation is followed by a left shift (8-r2), placed at the high position of the first byte.
Lcall lfrotaten; left displacement (8-R2) bit. lfrotaten is simple and not listed. The result is placed in.

Orl A, R5; performs or operations to put the lower R2 bits of the second byte on the higher R2 bits of the first byte.
Movx @ dptr1, A; the result is stored in the place indicated by dptr1.

MoV A, r2
MoV R7, A; number of shifts to the right.
MoV A, R0; the second byte previously saved is in R0. Here, R2 is shifted to the right, which is the first byte of the next loop.
Lcall rtrotaten; right shift R2 operation. rtrotaten is simple, not listed, and the result is placed in.
MoV R6, A; R6 is the first byte of the next loop.


INC dptr1; write pointer dptr1 plus 1
INC R2; Inner Loop Variable plus 1

MoV A, R3; R3 is the Len
CLR C
Subb A, #1
MoV R3, A; R3 is the total length of the conversion minus one, R3 = R3-1
JZ transend; if the length is 0, it indicates that all bytes have been processed, that is, output.
Cjne R2, #8, transbegin; the cycle range is 1 ~ 7

INC dptr; outer loop proceed, preparations before the next outer loop.
Movx A, @ dptr
MoV R6, A; before the next 8-byte processing, the first byte is R6 by default.

MoV A, R3; R3 is the short message length. when entering the next layer loop, R3 also needs to be reduced by 1, processing the first two bytes of the next 8 bytes.
CLR C
Subb A, #1
MoV R3,
JZ transend

Djnz R1, out_transbegin; loop [Len/8] times. If R1 is not reduced to 0, it enters the lower-layer loop.

Transend:

The above is the implementation of 7-bit encoding compressed into 8-bit encoding algorithm.

3. CEN text message Compression Method
CEN text messages are organized in accordance with the UTK technical requirements of China Unicom 800 MHz CDMA digital cellular mobile communication network. The following is a simple explanation of a specific text message:
Bytes
Similar to g's text message, these are active UIM command labels (13), alpha Identifiers (85) (o), device Identifiers (82), and cdma sms tpdu (C8)

C81c000002100204080b81319364174f7080b0003200000010000017ffe09000 is the content of cdma sms tpdu. The analysis is as follows:
C81c (TAG + Len)
00 (segment Message Type: 00 SMS Point to Point)
00 02 1002 (Tag: teleservice identifier)
04 08 0b81319363694f7 (destination address)
08 0b 00 03 200000 01 04 1017ffe0 (bearer data)

Bearer data is 080b0003200000010000017ffe0, split,
08 0b (TAG + Len)
00 03 200000 (Message identifier)
01 04 1017ffe0 (user data)
First, convert the content 1017ffe0 after 0104 to bit: 0001 0000 0001 0111 1111 1111 1110
The first 5bit is the encoding type, which is 00010, expressed as 7-bit encoding. The encoding type is 00010 0000001 0111111 11111111 00000.

The above only analyze the specific text message, for more information, please refer to the TIA-EIA-637-A.

4. References:
1, gsm11.14
2, gsm03.40
3, gsm03.38
4. UTK technical requirements of China Unicom 800 MHz CDMA digital cellular mobile communication network
TIA-EIA-637-A 5

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.