GATT DescriptorGATT Characteristic 后面的元数据或配置 attribute,用于描述 characteristic value 的展示、格式、扩展属性,或控制 notification/indication 等行为。

核心问题

Characteristic value 只保存核心数据本身,但客户端还可能需要知道:

  • 这个值如何显示?
  • 是否有扩展属性?
  • 当前 client 是否启用了 notification 或 indication?
  • 这个值的人类可读说明是什么?

Descriptor 解决的是“围绕某个 characteristic value 的附加说明和客户端配置”问题。

核心机制

Descriptor 是 characteristic definition 的一部分,位于 characteristic value attribute 之后、下一个 characteristic declaration 之前。例如:

0x0002  Characteristic Declaration
0x0003  Characteristic Value
0x0004  Client Characteristic Configuration Descriptor

最常见的 descriptor 是 CCCD(Client Characteristic Configuration Descriptor,UUID 0x2902)。client 通过写 CCCD 来启用或关闭 notification/indication:

0x0000  disabled
0x0001  notifications enabled
0x0002  indications enabled

CCCD 的值通常是 per-client 状态:同一个 GATT server 上,不同 client 是否订阅同一 characteristic 可以不同。

工程用途

  • 启用或关闭 characteristic notification/indication。
  • 表达 characteristic 的格式、单位、展示说明或扩展属性。
  • 支撑客户端对特定 characteristic 的配置状态。
  • 调试“为什么服务端不推送通知”:检查 characteristic properties 和 CCCD 写入。

边界与常见坑

  • Descriptor 不是 characteristic value 本身:它附着在 characteristic 后面,描述或配置该 value。
  • CCCD 不写通常不会收到通知:即使 characteristic properties 支持 notify,client 也要订阅。
  • CCCD 是客户端配置:多客户端场景不能把一个客户端的订阅状态误用于所有客户端。
  • descriptor permissions 也要检查:有些 descriptor 可读不可写,有些写入需要加密或认证。
  • 不要把所有元数据塞进 descriptor:复杂业务协议通常应放在 characteristic value 或上层协议中。

相关术语

外部参考