目前,發送短消息常用Text和PDU(Protocol Data Unit,協定資料單元)模式。使用Text模式收發短信代碼簡單,實作起來十分容易,但最大的缺點是不能收發中文短信;而PDU模式不僅支援中文短信,也能發送英文短信。PDU模式收發短信可以使用3種編碼:7-bit、8-bit和UCS2編碼。7-bit編碼用于發送普通的ASCII字元,8-bit編碼通常用于發送資料消息,UCS2編碼用于發送Unicode字元。
PDU的構成
PDU是由一串由“0-9”及“A-F”組成。表面上看起來就是一組16進制的數所組成的。
1:一個手機發送的一個PDU串
0891683108200505F011190D91683105155694F50008FF10008FF044F60597D
<1>短信中心位址字段:0891
08:Address-Lengt(位址長度),短資訊中心位址長度為8個位元組,是(91)+(683108200505F0)的長度,8個8位位元組
91位址類型:10010001 Bit7:1。始終為1 Bits 6,5,4:Type-of-Number(号碼類型):001,代表Internation Number。也即是号碼前加“+”。注意:對某些比較特殊的号碼,例如手機與小靈通的互通時,這裡不能設定為001,而要設定成000,代表号碼前沒有“+”,否則無法接收。
下面是GSM03.40協定号碼類型的解釋:
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 will store them as received.
Bits 3,2,1,0:Numbering-plan-identification(号碼鑒别),0000—未知,0001—ISDN/電話号碼(E.164/E.163),1111—留作擴充;一般預設為0001,表示電話号碼類型的。下面是GSM03.40号碼鑒别的解釋:
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>短信中心号碼:683108200805F0
一個位元組内反轉,8613800280500,如果長度為奇數則需要加“F”補齊。比如号碼為:+8613505165495,去掉"+"後在末尾添加F變為:8613505165495F,再将手機号碼的奇數位和偶數位的相交換為683105155694F5
<3>FirstOctet字段:1119
(1)11 包含TP-MTI(2bit),TP-RD(1bit),TP-VPF(2bit),TP-RP(1bit),TP-UDHI(1bit),TP-SRR(1bit)
二進制表示形式:0 0 0 10 0 01
TP-MTI:01 TP-Message-Type-Indicator(消息類型訓示符)
Bit1,0:00—讀出(Deliver); 01—送出(Submit)
Bit1,0:01訓示為SMS-SUBMIT類型
下面是GSM03.40的解釋:
bit1 bit0 Message type
0 0 SMS-DELIVER (in the direction SC to MS)
0 0 SMS-DELIVER REPORT (in the 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(是否拒絕相同重複消息)
Bit2:0—接受複制; 1—拒絕複制
Bit2:0 訓示短消息中心接收未轉發的具有相同TP-MR的消息。
Bit 2:
0 Instruct the SC to accept an SMS-SUBMIT for an SM still held in the SC which has the same TP-MR and the same TP-DA as a previously submitted SM from the same OA.
1 Instruct the SC to reject an SMS-SUBMIT for an 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 will be returned in the SMS-SUBMIT-REPORT.
TP-VPF:10 TP-Validity-Period-Format(有效期格式)
Bit4,3::00—不提供(Not present);01—預留; 10—整型(标準),指使用相對格式;11—提供8位位元組的一半(Semi-Octet Represented)
下面是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:需要報告,0:不需要報告。
Bit 5:
0 A status report is not requested
1 A status report is requested
TP-UDHI:0 TP-User-Data-Header-Indicator(使用者資料頭标示) Bit6: 1:含頭資訊 0:不含頭資訊,訓示這是一個SMS消息,沒有使用者資料頭,EMS(增強消息業務)消息需要設定。圖檔鈴聲這些都是包含頭部資訊的.文本不包含頭部資訊
Bit 6
0 The TP-UD field contains only the short message
1 The beginning of the TP-UD field contains a Header in addition to the short message
TP-RP:0 TP-Reply-Path(回複路徑) Bit7: 1:設定回複路徑,0:沒有設定回複路徑。
下面是GSM03.40解釋:
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)消息參考值TP-MR (TP-Message-Reference):19如果使用"00" 值代表讓電話自己設定消息參考值.
<4> 對方号碼字段:0D913105155694F5
0D:目标位址數字個數,共13個十進制數(不包括91和‘F’)
91:位址類型,同短信中心号碼設定.
3105155694F5:目标手機号碼。
<5>上層協定辨別TP-PID(TP-Protocol-Identifier):00
一般設定為00,表示普通GSM,點對點 <6> 資料編碼設定TP-DCS(TP-Data-Coding-Scheme):08
訓示TP-UD的編碼方式。08代表Unicode方式。參照GSM03.38協定:
Bit 3,2
00 Default alphabet
01 8 bit
10 UCS2 (16bit) [10]
11 Reserved
<7>有效期TP-VP(TP-Validity-Period):FF
FF表示最大。
<8> 使用者資料長度TP-UDL(TP-User-Data-Length):4
使用者資料實際長度。注意不同編碼下使用者長度定義不同。
<9>使用者資料 :4F60597D "你好"的Unicode編碼
你:0x4F60;好:0x597D
2:手機接收的PDU串
0891683108200505F0040D91683105155694F5000850208151754500044F60597D
<1>短信中心位址字段:0891683108200505F0,即是+8613800250500
<2>FirstOctet :04 其二進制代碼:00000100
TP-MTI:00
TP-MMS(TP-More-Message-to-Send):1 短信中心沒有更多的消息發送
TP-SRI: 0
TP-UDHI:0
TP-RP: 0
<3>發送方号碼 :0D91683105155694F5 即+8613505165495
<4>協定辨別: 00 TP-DCS 點對點
<5>編碼方式: 08 TP-DCS Unicode編碼
<6>短信中心時間 50208151754500
位元組反轉05/02/18 15:57:45 最後的00代表時區,這裡為0
<7>使用者資料長度 :4
<8>使用者資料:4F60597D
中文“你好”的Unicode編碼
參考資料:<1>GSM03.40協定
<2>短消息PDU字段分析與實作 趙波 王凱寫