一.广播报文格式
-
广播链路层报文格式如下:
-
Preamble: 前言, 广播通道固定为10101010b,数据通道是10101010b or 01010101b
-
Access Address :接入地址,广播通道固定为0x8E89BED6, 数据通道是随机值,不同的连接有不同的值。在连接建立之后的两个设备间使用。
-
PDU:
-
CRC: CRC校验,计算公式 x24 + x10 + x9 + x6 + x4 + x3 + x + 1
-
PDU格式
2.1 PDU Header
-
PDU Type :
-
RFU:RESERVED FOR FUTURE USE,保留给未来使用
-
TxAdd 1: 公共地址(BD_ADDR); 0:随机地址(RANDOM DEVICE ADDRESS)
-
RxAdd 1: 公共地址(BD_ADDR); 0:随机地址(RANDOM DEVICE ADDRESS)
-
Length : Payload的字节长度
-
RFU :RESERVED FOR FUTURE USE,保留给未来使用
PDU Type如下所示
状态 | PDU类型 | PDU格式 | 说明 |
Advertising | ADV_IND | AdvA(6 octets) AdvData(0~31 octets) | connectable undirected advertising event,用于常规的广播,可携带不超过31bytes的广播数据,可被连接,可被扫描: AdvA,6bytes的广播者地址,并由PDU Header的TxAdd bit决定地址的类型(0 public,1 random); AdvData,广播数据。 |
| ADV_DIRECT_IND | AdvA(6 octets) InitA(6 octets) | connectable directed advertising event,专门用于点对点连接,且已经知道双方的蓝牙地址,不可携带广播数据,可被指定的设备连接,不可被扫描: AdvA,6bytes的广播者地址,并由PDU Header的TxAdd bit决定地址的类型(0 public,1 random); InitA,6bytes的接收者(也是连接发起者)地址,并由PDU Header的RxAdd bit决定地址的类型(0 public,1 random)。 |
| ADV_NONCONN_IND | AdvA(6 octets) AdvData(0~31 octets) | 和ADV_IND类似,但不可以被连接,不可以被扫描。 |
| ADV_SCAN_IND | AdvA(6 octets) AdvData(0~31 octets) | 和ADV_IND类似,但不可以被连接,可以被扫描。 |
Scanning | SCAN_REQ | ScanA(6 octets) AdvA(6 octets) | 当接收到ADV_IND或者ADV_SCAN_IND类型的广播数据的时候,可以通过该PDU,请求广播者广播更多的信息: ScanA,6bytes的本机地址,并由PDU Header的TxAdd bit决定地址的类型(0 public,1 random); AdvA,6bytes的广播者地址,并由PDU Header的RxAdd bit决定地址的类型(0 public,1 random)。 |
| SCAN_RSP | AdvA(6 octets) ScanRspData(0~31 octets) | 广播者收到SCAN_REQ请求后,通过该PDU响应,把更多的数据传送给接受者。 AdvA,6bytes的广播者地址,并由PDU Header的TxAdd bit决定地址的类型(0 public,1 random); ScanRspData,scan的应答数据。 |
Initiating | CONNECT_REQ | InitA (6 octets) AdvA (6 octets) LLData (22 octets) | 当接收到ADV_IND或者ADV_DIRECT_IND类型的广播数据的时候,可以通过该PDU,请求和对方建立连接: InitA,6bytes的本机地址,并由PDU Header的TxAdd bit决定地址的类型(0 public,1 random); AdvA,6bytes的广播者地址,并由PDU Header的RxAdd bit决定地址的类型(0 public,1 random); LLData,BLE连接有关的参数信息,具体请参考后续文章的介绍。 |
-
PDU Payload
报文格式
Length :每个AD Structure的长度
AD Type : All AD types are listed in the Bluetooth Assigned Numbers document,
详情可以查看https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile
AD Date: 广播数据
AD Type定义
0x01 | «Flags» |
0x02 | «Incomplete List of 16-bit Service Class UUIDs» |
0x03 | «Complete List of 16-bit Service Class UUIDs» |
0x04 | «Incomplete List of 32-bit Service Class UUIDs» |
0x05 | «Complete List of 32-bit Service Class UUIDs» |
0x06 | «Incomplete List of 128-bit Service Class UUIDs» |
0x07 | «Complete List of 128-bit Service Class UUIDs» |
0x08 | «Shortened Local Name» |
0x09 | «Complete Local Name» |
0x0A | «Tx Power Level» |
0x0D | «Class of Device» |
0x0E | «Simple Pairing Hash C» |
0x0E | «Simple Pairing Hash C-192» |
0x0F | «Simple Pairing Randomizer R» |
0x0F | «Simple Pairing Randomizer R-192» |
0x10 | «Device ID» |
0x10 | «Security Manager TK Value» |
0x11 | «Security Manager Out of Band Flags» |
0x12 | «Slave Connection Interval Range» |
0x14 | «List of 16-bit Service Solicitation UUIDs» |
0x15 | «List of 128-bit Service Solicitation UUIDs» |
0x16 | «Service Data» |
0x16 | «Service Data - 16-bit UUID» |
0x17 | «Public Target Address» |
0x18 | «Random Target Address» |
0x19 | «Appearance» |
0x1A | «Advertising Interval» |
0x1B | «LE Bluetooth Device Address» |
0x1C | «LE Role» |
0x1D | «Simple Pairing Hash C-256» |
0x1E | «Simple Pairing Randomizer R-256» |
0x1F | «List of 32-bit Service Solicitation UUIDs» |
0x20 | «Service Data - 32-bit UUID» |
0x21 | «Service Data - 128-bit UUID» |
0x22 | «LE Secure Connections Confirmation Value» |
0x23 | «LE Secure Connections Random Value» |
0x24 | «URI» |
0x25 | «Indoor Positioning» |
0x26 | «Transport Discovery Data» |
0x27 | «LE Supported Features» |
0x28 | «Channel Map Update Indication» |
0x29 | «PB-ADV» |
0x2A | «Mesh Message» |
0x2B | «Mesh Beacon» |
0x3D | «3D Information Data» |
0xFF | «Manufacturer Specific Data» |
二.举例说明
2.1 ADV_IND 数据包
对应的数据如下:D6 BE 89 8E 60 21 0D A0 95 14 25 FB 03 19 00 03 02 01 06 07 03 09 18 0F 18 0A 18 0B 09 4E 6F 72 64 69 63 5F 48 54 53 0F 58 F2 3B A6
Access Address | D6 BE 89 8E | ||||
PDU Header | 60 21 (00 100001 0 1 10 0000b) | PDU Type (0000)
| ADV_IND | ||
RFU(10) | |||||
TxAdd(1) | |||||
RxAdd(0) | |||||
Length(100001) | 数据长度33个字节 | ||||
RFU(00) | |||||
AdvA | 0D A0 95 14 25 FB | BD_ADDR公共地址 | |||
AdvData | 03 19 00 03 02 01 06 07 03 09 18 0F 18 0A 18 0B 09 4E 6F 72 64 69 63 5F 48 54 53 | length | AD Type | AD Data | |
03 | 19 | 00 03 | Appearance,外观,显示这是一个Generic Thermometer | ||
02 | 01 | 06 | Flags,这是一个低功耗蓝牙,且不支持BR/EDR( LE General Discoverable Mode BR/EDR Not Supported) | ||
07 | 03 | 09 18 0F 18 0A 18 | Complete List of 16-bit Service Class UUIDs 有三个服务分别是 0x1809,0x180f,0x180a
| ||
0B | 09 | 4E 6F 72 64 69 63 5F 48 54 53 | Complete Local Name 本地名称是“Nordic_HTS” | ||
crc | 0F 58 F2 |
2.2 SCAN_REQ
用抓包工具抓到的数据如下:D6BE898E C30C 53ED3BCBE975 0DA0951425FB
Access Address | 0x8E89BED6 | ||
PDU Header | 0x0CC3 ( 0000 1100 1100 0011) | PDU Type (0011)
| SCAN_REQ |
RFU(00) | |||
TxAdd(1) | 随机地址 | ||
RxAdd(1) | 随机地址 | ||
Length(001100) | 数据长度12个字节 | ||
RFU(00) | |||
ScanA | 0x75E9CB3BED53 | 扫描地址 | |
AdvA | 0xFB251495A00D |
| 广播地址 |
crc | 0xF2580F | Crc校验 |
欢迎关注个人公众号“低功耗蓝牙技术研究及推广”