其他分享
首页 > 其他分享> > BLE 广播格式定义

BLE 广播格式定义

作者:互联网

低功耗蓝牙两类报文 : 广播报文 和 数据报文。
本文讨论广播报文数据段,不包括完整报文其他部分,比如前导,接入地址等

蓝牙设备通过广播表明自己的存在,等待被连接, 就好象一个人站在接口大喊“我要脱单,我要脱单,快来牵手...”。
BLE 考虑功耗, 使用了3个广播信道,顺序广播。

两个蓝牙设备想要建立连接, 第一步是 从机(server) 向外广播, 主机(client) 搜索到后发起请求。 从机广播中包含设备的相关信息,比如设备名称,设备具有的服务uuid 等。

广播包类型

广播数据包格式

7f223bf9-4d85-4e25-917d-222fb063b540.png

每个包都是 31 字节,数据包中分为有效数据(significant)和无效数据(non-significant)两部分。

Flags

对于低功耗蓝牙设备, 广播中需要包括的一个 Structure, 包含一个byte 的标记, 标记设备
Flags used over the LE physical channel are:

广播设备的服务uuid

假如蓝牙设备有心率等profile, 可以在广播中添加那对应的服务uuid ,这样其他设备可以通过广播直接了解设备具备的功能。
GAP 和 GATT 服务的 UUID 不应该出现在广播中, 这对于每个设备都是具有的。
广播中包含服务uuid 包括六种类型, 对应不同程度 uuid 和列表完整性(complete 和 incomplete)

complete 和 incomplete 的区别

比如, 我设备有两个服务对应的 16 bit uuid 分别是 0x1122 和 0x 2233。

valuenote
0x03 len
0x02 Incomplete List of 16-bit Service Class UUIDs
0x22 uuid_L
0x11 uuid_H
valuenote
0x05 len
0x03 Complete List of 16-bit Service Class UUIDs
0x22 uuid1_L
0x11 uuid1_H
0x22 uuid2_L
0x33 uuid2_H

广播中的厂商信息

这个一段的广播标记时 0XFF, 对应用于标记设备的生产商和其他信息。
数据前两个字节时厂商ID, 其他自定义。

具体其他广播数据段类型详见 参考。

官方提供例子

ValueNotes
0x02 Length of this Data
0x01 Flags
0x06 广播标记头
0x06 Length of this Data
0x09 Complete Local Name
0x50 'P'
0x68 'h'
0x6F 'o'
0x6E 'n'
0x65 'e'
0x05 Length of this Data
0x03 Complete list of 16-bit Service UUIDs, 列出所有服务uuid ,否则使用imcomplete
0x15 PANU service class UUID
0x11  
0x1F Hands-free Audio Gateway service class UUID
0x11  
0x01 Length of this data
0x05 Complete list of 32-bit Service UUIDs
0x01 Length of this data
0x07 Complete list of 128-bit Service UUIDs
0x00 End of Data (Not transmitted over the air)

参考

Bluetooth SIG - 增补文档
Bluetooth SIG - 广播类型定义

标签:uuid,Service,广播,UUIDs,BLE,格式,bit,设备
来源: https://www.cnblogs.com/Free-Thinker/p/11375840.html