#3 CMPP: UDH 头
CMPP SMS 2022-05-13中国移动 CMPP 协议中的 UDH 头设计源自 SMPP 协议,SMPP 协议又是参考的 GSM 短信服务的相关标准。
- TP_UDHI 字段,1 bit,对应 GSM 协议中的 UDHI,表示短信中是否包含 UDH。
UDH
UDH,User Data Header,定义在 GSM 03.40 / 3GPP 23.040 中。
UDH 是短信中可能包含的一个二进制头部,对短信服务进行拓展。
可以实现以下功能:
- 长短信(级联短信):切割成多条,需要通过 UDH 中的总条数和序号来组装。
- EMS,增强型消息服务,支持颜色,文件格式,图片,动画,音乐
- MMS,彩信
- 本地语言转换表(Nation Language Shift Table):在 GSM-7 的框架上支持其他国家的语言。
概念:
- TP(Transfer Layer Protocol,传输层协议)
- TP-UD(User Data,用户数据),就是短信的正文部分
- 如果存在 UDH,那就在 TP-UD 的开头
- TP-UDHI(User Data Header Indicator,用户数据头指示器)
- 消息的第六 bit,表示短信中是否存在 UDH
UDHL:UDH Length,UDH 的第一字节,表示 UDH 的长度。
UDH 剩余部分是若干标签 + 长度 + 值的组合。其中标签又叫做 IEI(Information-Element-Identifier,信息元素标识符),占一字节。
例如:05 00 03 5F 03 01
- 第一字节 05,表示后面还有 5 Byte 是 UDH
- 第二字节 00,按照下面的 IEI 表,表示级联短信
- 第三字节 03,表示 IEI Length,也就是说这个 IEI 还有 3 Byte
- 第四字节 5F,按照级联短信的设计,这个 Byte 是一个随机 int8,避免不同批次短信搞混
- 第五字节 03,按照级联短信的设计,这个 Byte 表示总短信长度
- 第六字节 01,按照级联短信的设计,这个 Byte 表示当前短信在这一批次短信中的序号
重点:如果短信采用 GSM-7 编码,则需要对齐到 7 bit,也就是说真正需要的 bit 数是 math.ceil(6 * 8 / 7) * 7
上面这个例子,8 bit _ 6 = 48 bit,需要增加 1 bit,对齐成 7 bit _ 7 = 49 bit。
UDH Information Elements
IEI (hex) | Meaning | Classification | Length | May repeat |
---|---|---|---|---|
00 | Concatenated short messages, 8-bit reference number | SMS Control | 3 | no |
01 | Special SMS Message Indication | SMS Control | 2 | yes |
02 | Reserved | N/A | N/A | yes |
03 | Not used to avoid misinterpretation as <LF> character |
N/A | N/A | yes |
04 | Application port addressing scheme, 8 bit address | SMS Control | 2 | no |
05 | Application port addressing scheme, 16 bit address | SMS Control | 4 | no |
06 | SMSC Control Parameters | SMS Control | 1 | no |
07 | UDH Source Indicator | SMS Control | 1 | yes |
08 | Concatenated short message, 16-bit reference number | SMS Control | 4 | no |
09 | Wireless Control Message Protocol | SMS Control | 1-255 | yes |
0A | Text Formatting | EMS Control | 3-4 | yes |
0B | Predefined Sound | EMS Content | 2 | yes |
0C | User Defined Sound (iMelody max 128 bytes) | EMS Content | 2-129 | yes |
0D | Predefined Animation | EMS Content | 2 | yes |
0E | Large Animation (1616 times 4 = 324 =128 bytes) | EMS Content | 129 | yes |
0F | Small Animation (88 times 4 = 84 =32 bytes) | EMS Content | 33 | yes |
10 | Large Picture (32*32 = 128 bytes) | EMS Content | 129 | yes |
11 | Small Picture (16*16 = 32 bytes) | EMS Content | 33 | yes |
12 | Variable Picture | EMS Content | 4-255 | yes |
13 | User prompt indicator | EMS Control | 1 | yes |
14 | Extended Object | EMS Content | 7-255 | yes |
15 | Reused Extended Object | EMS Control | 3 | yes |
16 | Compression Control | EMS Control | 3-255 | no |
17 | Object Distribution Indicator | EMS Control | 2 | yes |
18 | Standard WVG object | EMS Content | 1-255 | yes |
19 | Character Size WVG object | EMS Content | 1-255 | yes |
1A | Extended Object Data Request Command | EMS Control | 0-255 | no |
1B | Reserved for future EMS features | N/A | 0-255 | yes |
1C | Reserved for future EMS features | N/A | 0-255 | yes |
1D | Reserved for future EMS features | N/A | 0-255 | yes |
1E | Reserved for future EMS features | N/A | 0-255 | yes |
1F | Reserved for future EMS features | N/A | 0-255 | yes |
20 | RFC 822 E-Mail Header | SMS Control | 1 | no |
21 | Hyperlink format element | SMS Control | 0-255 | yes |
22 | Reply Address Element | SMS Control | 1-255 | no |
23 | Enhanced Voice Mail Information | SMS Control | 0-255 | no |
24 | National Language Single Shift | SMS Control | 1 | no |
25 | National Language Locking Shift | SMS Control | 1 | no |
26 – 6F | Reserved for future use | N/A | 0-255 | N/A |
70 – 7F | (U)SIM Toolkit Security Headers | SMS Control | 0-255 | ? |
80 – 9F | SME to SME specific use | SMS Control | 0-255 | ? |
A0 – BF | Reserved for future use | N/A | 0-255 | ? |
C0 – DF | SC specific use | SMS Control | 0-255 | ? |
E0 – FF | Reserved for future use | N/A | 0-255 | ? |