首页 > 解决方案 > 如何找到BLE设备不同UUID对应的句柄

问题描述

使用 gattool,我可以找到与我的智能手表手柄相对应的 UUID,如下所示:

Device: MAC address
Name: MS1020
Alias: MS1020
Paired: yes
Trusted: yes
Blocked: no
Connected: no
LegacyPairing: no
UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
UUID: Unknown                   (0000cc00-0000-1000-8000-00805f9b34fb)
UUID: Tencent Holdings Limited  (0000fee7-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific           (00010203-0405-0607-0809-0a0b0c0d1912)
ManufacturerData Key: 0x0211
ManufacturerData Value:
[LE]> characteristics
handle: 0x0002, char properties: 0x12, char value handle: 0x0003, uuid: 2b120008-0600-072a-0100-050200042a00
handle: 0x0004, char properties: 0x02, char value handle: 0x0005, uuid: 0708090a-0b0c-0d2b-1200-080600072a01
handle: 0x0007, char properties: 0x06, char value handle: 0x0008, uuid: 00010203-0405-0607-0809-0a0b0c0d2b12
handle: 0x000b, char properties: 0x08, char value handle: 0x000c, uuid: 0000fec7-0000-1000-8000-00805f9b34fb
handle: 0x000d, char properties: 0x20, char value handle: 0x000e, uuid: 0000fec8-0000-1000-8000-00805f9b34fb
handle: 0x0010, char properties: 0x02, char value handle: 0x0011, uuid: 0000fec9-0000-1000-8000-00805f9b34fb
handle: 0x0012, char properties: 0x32, char value handle: 0x0013, uuid: 0000fea1-0000-1000-8000-00805f9b34fb
handle: 0x0015, char properties: 0x2a, char value handle: 0x0016, uuid: 0000fea2-0000-1000-8000-00805f9b34fb
handle: 0x0019, char properties: 0x0a, char value handle: 0x001a, uuid: 0000cc02-0000-1000-8000-00805f9b34fb
handle: 0x001b, char properties: 0x12, char value handle: 0x001c, uuid: 0000cc03-0000-1000-8000-00805f9b34fb
handle: 0x001e, char properties: 0x12, char value handle: 0x001f, uuid: 0000cc04-0000-1000-8000-00805f9b34fb
handle: 0x0021, char properties: 0x1a, char value handle: 0x0022, uuid: 0000cc05-0000-1000-8000-00805f9b34fb
handle: 0x0024, char properties: 0x08, char value handle: 0x0025, uuid: 0000cc06-0000-1000-8000-00805f9b34fb

[LE]> primary
attr handle: 0x0001, end grp handle: 0x0005 uuid: 00001800-0000-1000-8000-00805f9b34fb
attr handle: 0x0006, end grp handle: 0x0009 uuid: 00010203-0405-0607-0809-0a0b0c0d1912
attr handle: 0x000a, end grp handle: 0x0017 uuid: 0000fee7-0000-1000-8000-00805f9b34fb
attr handle: 0x0018, end grp handle: 0x0025 uuid: 0000cc00-0000-1000-8000-00805f9b34fb

[LE]> char-desc
handle: 0x0001, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0002, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0003, uuid: 00002a00-0000-1000-8000-00805f9b34fb
handle: 0x0004, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0005, uuid: 00002a01-0000-1000-8000-00805f9b34fb
handle: 0x0006, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0007, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0008, uuid: 00010203-0405-0607-0809-0a0b0c0d2b12
handle: 0x0009, uuid: 00002901-0000-1000-8000-00805f9b34fb
handle: 0x000a, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x000b, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x000c, uuid: 0000fec7-0000-1000-8000-00805f9b34fb
handle: 0x000d, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x000e, uuid: 0000fec8-0000-1000-8000-00805f9b34fb
handle: 0x000f, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0010, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0011, uuid: 0000fec9-0000-1000-8000-00805f9b34fb
handle: 0x0012, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0013, uuid: 0000fea1-0000-1000-8000-00805f9b34fb
handle: 0x0014, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0015, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0016, uuid: 0000fea2-0000-1000-8000-00805f9b34fb
handle: 0x0017, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0018, uuid: 00002800-0000-1000-8000-00805f9b34fb
handle: 0x0019, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001a, uuid: 0000cc02-0000-1000-8000-00805f9b34fb
handle: 0x001b, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001c, uuid: 0000cc03-0000-1000-8000-00805f9b34fb
handle: 0x001d, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x001e, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x001f, uuid: 0000cc04-0000-1000-8000-00805f9b34fb
handle: 0x0020, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0021, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0022, uuid: 0000cc05-0000-1000-8000-00805f9b34fb
handle: 0x0023, uuid: 00002902-0000-1000-8000-00805f9b34fb
handle: 0x0024, uuid: 00002803-0000-1000-8000-00805f9b34fb
handle: 0x0025, uuid: 0000cc06-0000-1000-8000-00805f9b34fb

但是,我很困惑,如何确定哪个句柄适用于哪个 BLE 功能。例如,https ://www.bluetooth.com/specifications/gatt/characteristics/ 上的页面显示电池电量规格功能位于 0x2A19。但是,我不知道在哪里或如何在上面的 char-desc 输出中获取与 0x2A19 对应的 UUID。我怎么得到这个?

编辑:感谢答案中非常有用的描述(两者都非常好)。我已经添加了上面的特征信息。我还有一些额外的信息可能有用也可能没用。

通过反复试验,我能够确定血压测量值(从我按下表带上的按钮时获得)是从通知句柄的第三个和第四个条目(十六进制格式)获得的(见输出):

Notification handle = 0x001f value: f3 14 73 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

但是,当什么都不做时,即没有按下任何按钮,我得到:

[LE]> char-read-hnd 0x001f
Characteristic value/descriptor: 07 00 04 4e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

相同的通知句柄在第 11 个条目中给出了心率(按下该按钮时):

Notification handle = 0x001f value: 20 00 00 00 00 00 00 00 00 00 63 00 00 00 00 00 00 00 00 00 

然而,在所有情况下,第一个条目也发生了变化(并且它们似乎对操作和不作为是唯一的)。

例如,我想知道我是否可以访问这些信息,以及如何触发 BP 测量。再次感谢!

如果我的问题不清楚或需要更多信息,请在评论中告诉我。我很乐意根据需要提供更多信息。感谢您花时间阅读和提出建议/指示。

标签: bluetooth-lowenergygattbluetooth-gattgatttool

解决方案


电池电量特性不是“在 0x2A19”,而是 UUID 00002A19-0000-1000-8000-00805f9b34fb。您的设备上似乎没有这样的特性。注意Battery Service允许被声明为 Secondary Service,那么它可能不会被“primary”命令发现。

编辑后更新

不幸的是,该设备在非标准服务(句柄 0x18,类型 0000cc00-0000-1000-8000-00805f9b34fb)中使用非标准特征(句柄 0x1e,类型 0000cc04-0000-1000-8000-00805f9b34fb)来传递数据。如果有一种方法可以触发您想要的测量,它属于逆向工程。

TL;博士

蓝牙规范希望允许特定于供应商的 GATT 功能与标准功能共存,而无需全局目录。为此,GATT 中的所有内容都是通过 128 位 UUID 的 ID 指定的,任何人都可以生成而无需真正关心冲突。

  • 一切都由 UUID 输入,参见 3.G.2.5.1:

    属性类型是描述属性值的 UUID。

  • 每个服务也有一个类型,参见 3.G.3.1:

    服务声明是属性类型设置为“主要服务”或“次要服务”的 UUID 的属性。[...] 客户端可能会忽略任何具有未知服务 UUID 的服务定义。未知服务 UUID 是不受支持的服务的 UUID。

  • 并且每个特征也有一个类型,参见 3.G.3.3.1:

    特征声明是一个属性,其属性类型设置为 «Characteristic» 的 UUID,属性值设置为特征属性、特征值属性句柄和特征 UUID。

UUID 分配很简单,我们在上面的设备转储中得到了完美的说明:

  • 标准定义的用途,坚持标准的 UUID,

  • 蓝牙 SIG 为其成员提供基于蓝牙的 UUID以优化使用,因此0000fee7-0000-1000-8000-00805f9b34fb是合规且特定于供应商的(由 SIG 分配至Tencent Holdings Limited2014 年 4 月 24 日)。

  • 从头开始生成随机 UUID 并将其用于自定义目的。00010203-0405-0607-0809-0a0b0c0d1912看起来合规,但看起来一点也不随机。其他人可能会偶然获得相同的值。

OTOH,我找不到任何定义的蓝牙规范0000cc00-0000-1000-8000-00805f9b34fb,它看起来不兼容。

蓝牙规范自行处理,并通过两种方式针对其自身规范使用优化了 UUID 流程:

  • 为了便于查找,所有蓝牙定义的 ID 都有一个共同的基础,即nnnnnnnn-0000-1000-8000-00805f9b34fb,其中nnnnnnnn32 位值是不可接受冲突的,因此在分配时必须严格控制。见 3.B.2.5.1:

    为了减轻存储和传输 128 位 UUID 值的负担,已预先分配了一系列 UUID 值,以分配给常用的注册用途。

    当您查看GATT 服务/ GATT 特性页面时,您实际上是在查看基于蓝牙的 UUID 列表,即-0000-1000-8000-00805f9b34fb当您在 gatttool 的输出中查找它们时应该附加。

  • 作为一种优化,GATT 协议允许将基于蓝牙的 UUID 编码为较短的变体,即“16 位”和“32 位”变体,即不重复-0000-1000-8000-00805f9b34fb。有关此类情况的示例,请参见 3.G.3.3.1 中的表 3.4。


推荐阅读