# 通用属性配置文件

通用属性配置文件（Generic Attribute Profile，GATT）是一项蓝牙规范，它定义了一个构建于属性协议（Attribute Protocol，ATT）之上的服务框架，描述设备如何公开服务与特征，以及对端设备如何发现服务并读取、写入、通知和指示特征值。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup> 它位于[蓝牙](https://www.edgepedia.org/zh/bluetooth)协议栈的主机部分，在属性协议之上，与通用访问配置文件（Generic Access Profile，GAP）并列，为蓝牙技术联盟（Bluetooth SIG）或实现者定义的所有[低功耗蓝牙](https://www.edgepedia.org/zh/bluetooth-low-energy)（Bluetooth Low Energy，LE）配置文件提供了构建框架。<sup>[2](https://docs.silabs.com/bluetooth/6.1.0/bluetooth-gatt/gatt-flowcharts)</sup><sup> • </sup><sup>[3](https://www.bluetooth.com/wp-content/uploads/2020/01/Bluetooth_5.2_Feature_Overview.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 一种使用属性协议来发现服务以及读写对端设备特征值的服务框架<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup> |
| 数据模型 | 服务器属性表中的属性被分组为服务、特征和描述符<sup>[4](https://www.bluetooth.com/bluetooth-le-primer/)</sup> |
| 角色 | GATT 客户端与 GATT 服务器；一个设备可以同时实现两种角色<sup>[5](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/attribute-protocol--att-.html)</sup> |
| 服务类型 | 主要服务公开设备功能；次要服务仅作为其他服务的一部分存在，且没有用于发现次要服务的过程<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup> |
| 传输 | 在 LE 上，ATT 使用固定的 L2CAP 通道 CID 0x0004，在基本 L2CAP 模式下默认 ATT_MTU 为 23 个八位组<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup> |
| 增强 ATT 承载 | 最小 ATT_MTU 为 64 个八位组，在加密链路上通过 L2CAP 增强型基于信用的流量控制通道承载<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup> |
| 标识符 | GATT 服务已分配 UUID 0x1801，且每个 GATT 服务器上都必须存在<sup>[8](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Assigned_Numbers/out/en/Assigned_Numbers.pdf?v=1716434606120)</sup><sup> • </sup><sup>[9](https://software-dl.ti.com/lprf/sdg-latest/html/ble-stack-3.x/gatt.html)</sup> |

## 数据模型：服务、特征与描述符

GATT 以服务器属性表中持有的属性来定义更高层级的数据类型。属性通过句柄寻址，连续句柄范围内的一组属性通常代表一个复杂类型，例如一个服务或一个特征。<sup>[4](https://www.bluetooth.com/bluetooth-le-primer/)</sup> 该规范按三种属性类型对属性进行分组：「主要服务」、「次要服务」和「特征」。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup>

**服务。** 服务是数据和相关行为的集合，用于完成特定功能或特性，由服务定义来定义，其中可包含被包含服务、必需特征和可选特征。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup> 主要服务公开设备的功能，并可被另一个服务包含；被包含的服务仍作为独立服务存在，包含关系不会改变它。对包含定义的数量或嵌套包含的深度没有限制。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup> 为保持向后兼容性，后续版本的服务定义只能新增被包含服务或可选特征，禁止改变先前版本的行为。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup>

**特征。** 特征是服务中使用的一个值，连同关于该值如何被访问和显示的属性及配置信息。其定义由特征声明、特征的属性和一个值组成；还可包含描述符，用于提供关于该值的信息或允许针对该特征配置服务器。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup> 特征是具有类型、值和一组指示数据可如何使用的属性的独立状态数据项；例如，一个特征可以允许对端读取但不允许写入。<sup>[4](https://www.bluetooth.com/bluetooth-le-primer/)</sup> 同一特征类型可以出现在多个服务中，其使用规则因上下文而异，具体由相关服务规范规定。<sup>[10](https://www.bluetooth.com/wp-content/uploads/2022/05/the-bluetooth-le-primer-v1.2.0.pdf)</sup>

**UUID。** 服务、特征和描述符通过 UUID 标识。蓝牙技术联盟定义的类型使用「已分配编号」规范中列出的 16 位 UUID；实现者可以用 128 位 UUID 定义自定义类型，或从蓝牙技术联盟购买 16 位值。16 位 UUID 有等效的 128 位形式：0000XXXX-0000-1000-8000-00805F9B34FB，其中 XXXX 为 16 位值。GATT 服务器可以只包含蓝牙技术联盟定义的属性，也可以混合包含蓝牙技术联盟定义的属性和自定义属性。<sup>[4](https://www.bluetooth.com/bluetooth-le-primer/)</sup> 客户端必须同时支持 16 位和 128 位 UUID，并可忽略任何服务 UUID 未知的服务定义。<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup>

## 过程

GATT 定义了用于发现、读取、写入、通知和指示特征以及配置特征广播的过程。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup> 规范中列举的过程族涵盖服务器配置（交换 MTU）、主要服务发现、关系发现（查找被包含服务）、特征发现、特征描述符发现、特征值读取、特征值写入（包括无响应写入）、特征值通知、特征值指示以及特征描述符操作。<sup>[11](https://bluetooth.spec.whatwg.org/)</sup>

发现过程使用 ATT PDU 执行。例如，ATT_READ_BY_GROUP_TYPE_REQ PDU 可用于查找属于主要服务定义的所有属性的句柄和 UUID，ATT_FIND_BY_TYPE_VALUE_REQ 可通过 UUID 定位特定的主要服务，搜索句柄范围 0x0001 至 0xFFFF。<sup>[4](https://www.bluetooth.com/bluetooth-le-primer/)</sup><sup> • </sup><sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup> ATT_READ_BY_GROUP_TYPE_REQ PDU 中不得使用「特征」分组类型。<sup>[6](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)</sup>

**通知与指示。** 服务器可以将特征值推送给客户端，而无需客户端读取。通知使用 ATT_HANDLE_VALUE_NTF 发送，在属性协议层不期望确认；指示使用 ATT_HANDLE_VALUE_IND 发送，要求客户端以 ATT_HANDLE_VALUE_CFM 响应。两者均通过客户端特征配置描述符进行配置，配置文件定义何时使用指示。<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup> 多可变长度通知子过程使用 ATT_MULTIPLE_HANDLE_VALUE_NTF，可在一条消息中携带多个特征值。<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup>

## 安全

GATT 中的认证独立应用于每个特征。过程可能要求客户端已通过认证且连接已加密，才能读取或写入某个特征；如果请求通过未认证或未加密的链路到达，服务器以 ATT_ERROR_RSP PDU 响应，客户端随后可运行 GAP 认证过程并重试。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup> 一个特征可以允许任何设备读取但仅允许已认证设备写入，或反之；每个特征可以具有不同的安全属性。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup> 一旦客户端针对某个特征通过认证，服务器可根据更高层或实现特定的要求，将访问权限扩展到同一服务定义或其他服务定义中的其他特征。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup>

设备所支持的服务和特征列表不被视为私有或机密，因此服务和特征发现过程应始终被允许；不得对查找信息请求返回认证不足错误（0x05）。授权同样按特征进行，未授权的请求会收到带有错误码「授权不足」（0x08）的 ATT_ERROR_RSP。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup>

## 缓存与服务变更

为在服务器的基于 GATT 的服务发生变更时支持缓存，服务器在服务被添加、移除或修改时向客户端发送指示。客户端也可通过读取数据库哈希特征（若存在）来检测服务变更。如果服务定义内分组的属性与属性句柄的绑定关系发生变化，则基于 GATT 的服务被视为已修改。<sup>[1](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)</sup>

## 与 ATT 和 EATT 的关系

GATT 过程运行于属性协议之上，该协议基于六种方法（命令、请求、响应、通知、指示和确认）定义了 31 种不同的 PDU。服务器必须响应所有请求，未在 30 秒内响应即构成超时。<sup>[4](https://www.bluetooth.com/bluetooth-le-primer/)</sup> 存在两种 ATT 变体：基本 ATT 和增强属性协议（Enhanced Attribute Protocol，EATT）。在 LE 上，基本 ATT 使用固定通道 CID 0x0004，默认 ATT_MTU 为 23 个八位组，并采用基本 L2CAP 模式和尽力而为的流规范。<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup> 增强 ATT 承载使用以 EATT 固定 PSM 建立的增强型基于信用的流量控制模式下的 L2CAP 面向连接通道；客户端与服务器之间可以存在多条此类通道，底层 ACL 连接必须在通道创建前加密，最小 ATT_MTU 为 64 个八位组。<sup>[7](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)</sup>

## 示例：心率配置文件

蓝牙技术联盟定义的配置文件以 GATT 角色和服务来表达。在心率配置文件中，心率传感器应为 GATT 服务器，采集器应为 GATT 客户端；传感器恰好实例化一个心率服务和一个设备信息服务。<sup>[12](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/HRP_v1.0/out/en/index-en.html)</sup> 心率服务已分配 UUID 0x180D。<sup>[8](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Assigned_Numbers/out/en/Assigned_Numbers.pdf?v=1716434606120)</sup> 采集器通过其客户端特征配置描述符控制心率测量特征的通知，并且必须能够接收该特征的多次通知。<sup>[12](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/HRP_v1.0/out/en/index-en.html)</sup>

## 平台实现

GATT 通过映射到其过程的平台 API 对外提供。Android 应用使用 `BluetoothDevice.connectGatt()` 连接到外设的 GATT 服务器，并通过 `BluetoothGattCallback` 接收连接状态、服务发现、特征读取和通知事件。<sup>[13](https://developer.android.com/develop/connectivity/bluetooth/ble/connect-gatt-server?authuser=7&hl=en)</sup> Apple 的 Core Bluetooth 框架提供用于外设服务、远程外设服务的特征以及 GATT 服务器在 ATT 事务期间可能返回的错误的对象。<sup>[14](https://developer.apple.com/documentation/corebluetooth?language=objc)</sup> Windows 在标准蓝牙配置文件驱动函数之外，还提供用于开发 GATT 客户端应用的蓝牙 LE 函数。<sup>[15](https://learn.microsoft.com/en-us/windows-hardware/drivers/bluetooth/bluetooth-low-energy-overview)</sup>

## 规范状态

GATT 是蓝牙核心规范主机卷的第 G 部分。核心规范已改为每半年发布一次的节奏，核心 6.1 于 2025 年 5 月 6 日发布。<sup>[16](https://www.bluetooth.com/blog/delivering-on-the-bi-annual-release-schedule-bluetooth-core-6-1-is-here/)</sup>

## References

1. [Part G, Generic Attribute Profile (GATT), Bluetooth Core Specification v6.3](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core_v6.3/out/en/host/generic-attribute-profile--gatt-.html)
2. [GATT Flowcharts, Silicon Labs Bluetooth LE documentation v6.1.0](https://docs.silabs.com/bluetooth/6.1.0/bluetooth-gatt/gatt-flowcharts)
3. [Bluetooth 5.2 Feature Overview, Bluetooth SIG](https://www.bluetooth.com/wp-content/uploads/2020/01/Bluetooth_5.2_Feature_Overview.pdf)
4. [The Bluetooth Low Energy Primer, Bluetooth SIG](https://www.bluetooth.com/bluetooth-le-primer/)
5. [Part F, Attribute Protocol (ATT), Bluetooth Core Specification v5.4](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/attribute-protocol--att-.html)
6. [Part G, Generic Attribute Profile (GATT), Bluetooth Core Specification v5.4](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html)
7. [Part G, Generic Attribute Profile (GATT), Bluetooth Core Specification v6.2](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-62/out/en/host/generic-attribute-profile--gatt-.html)
8. [Assigned Numbers, Bluetooth SIG](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Assigned_Numbers/out/en/Assigned_Numbers.pdf?v=1716434606120)
9. [GATT Services and Profile, BLE-Stack User's Guide, Texas Instruments](https://software-dl.ti.com/lprf/sdg-latest/html/ble-stack-3.x/gatt.html)
10. [The Bluetooth Low Energy Primer v1.2.0 (PDF), Bluetooth SIG](https://www.bluetooth.com/wp-content/uploads/2022/05/the-bluetooth-le-primer-v1.2.0.pdf)
11. [Web Bluetooth, WHATWG draft community group report](https://bluetooth.spec.whatwg.org/)
12. [Heart Rate Profile v1.0, Bluetooth SIG](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/HRP_v1.0/out/en/index-en.html)
13. [Connect to a GATT server, Android Developers](https://developer.android.com/develop/connectivity/bluetooth/ble/connect-gatt-server?authuser=7&hl=en)
14. [Core Bluetooth, Apple Developer Documentation](https://developer.apple.com/documentation/corebluetooth?language=objc)
15. [Bluetooth Low Energy (LE) Overview, Windows drivers, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/bluetooth/bluetooth-low-energy-overview)
16. [Delivering on the bi-annual release schedule: Bluetooth Core 6.1 is here, Bluetooth SIG](https://www.bluetooth.com/blog/delivering-on-the-bi-annual-release-schedule-bluetooth-core-6-1-is-here/)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 网络与安全 › Wireless networking

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/generic-attribute-profile

English original: https://www.edgepedia.org/generic-attribute-profile
