• BLE 广播格式定义


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

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

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

    广播包类型

    • 广播包 (Advertising Data)
    • 响应包 (Scan Response)
      主机主动扫描的情况下, 发送扫描请求给从机, 从机返回扫描响应数据。

    广播数据包格式

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

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

    • 有效数据部分
      包含若干个广播数据单元,称为 AD Structure 。如图所示,AD Structure 的组成是:

      • 长度 Len ,表示这个 AD Structure 的长度(除去 len本身 1)
      • 类型 AD Type
        标记这段广播数据代表什么, 比如设备名, uuid 等。
      • 数据 AD data
    • 无效数据部分
      广播包的长度必须是 31 个 byte,如果有效数据部分不到 31 自己,剩下的就用 0 补全。这部分的数据是无效的。

    Flags

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

    • Limited Discoverable Mode
    • General Discoverable Mode
    • BR/EDR Not Supported
    • Simultaneous LE and BR/EDR to Same Device Capable (Controller)
    • Simultaneous LE and BR/EDR to Same Device Capable (Host)

    广播设备的服务uuid

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

    • 16-bit Bluetooth Service UUIDs
    • 32-bit Bluetooth Service UUIDs
    • Global 128-bit Service UUIDs

    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 - 广播类型定义

  • 相关阅读:
    【中山纪念中学六年级模拟赛】方格翻转 题解
    高斯消元
    net 控件开发资料
    使用自定义验证组件库扩展 Windows 窗体
    POJ 3032
    UVa 10878 Decode the tape
    C语言I博客作业03
    第十周助教总结
    第十二周助教总结
    C语言I博客作业06
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/11375840.html
Copyright © 2020-2023  润新知