如何找到BLE设备不同UUID对应的句柄

use*_*841 0 bluetooth-lowenergy gatt bluetooth-gatt gatttool

使用 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
Run Code Online (Sandbox Code Playgroud)

然而,我很困惑如何确定哪个句柄适用于哪个 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
Run Code Online (Sandbox Code Playgroud)

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

[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 
Run Code Online (Sandbox Code Playgroud)

相同的通知句柄在第 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 
Run Code Online (Sandbox Code Playgroud)

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

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

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

Nip*_*ipo 6

电池电量特征不是“at 0x2A19”,而是 UUID 00002A19-0000-1000-8000-00805f9b34fb。您的设备上似乎没有这样的特征。注意电池服务允许将

\n\n

编辑后更新

\n\n

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

\n\n

长话短说

\n\n

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

\n\n
    \n
  • 一切都由 UUID 键入,请参阅 3.G.2.5.1:

    \n\n
    \n

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

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

    \n\n
    \n

    服务声明是属性类型设置为 \xc2\xabPrimary Service\xc2\xbb 或 \xc2\xabSecondary Service\xc2\xbb 的 UUID 的属性。[...] 客户端可能会忽略任何具有未知服务 UUID 的服务定义。未知服务 UUID 是不受支持的服务的 UUID。

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

    \n\n
    \n

    特性声明是一个属性,其属性类型设置为 \xc2\xabCharacteristic\xc2\xbb 的 UUID,属性值设置为\n 特性属性、特性值属性句柄\n 和特性 UUID。

    \n
  • \n
\n\n

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

\n\n
    \n
  • 具有标准定义的用途,坚持标准 UUID,

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

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

  • \n
\n\n

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

\n\n

蓝牙规范会自行处理并通过两种方式优化 UUID 流程以适应其自身规范的使用:

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

    \n\n
    \n

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

    \n
    \n\n

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

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

  • \n
\n