> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 验证 GATT 功能

> GATT 是一个使用 ATT 来发现服务并在对等设备上读取和写入特征值的服务框架。

<a id="bluez-gatt" />

要执行蓝牙低功耗 GATT 服务器或客户端功能，您必须先完成以下过程中的步骤。

## 前提条件

* 启用 SSH 以访问您的主机设备。有关说明，请参阅 <a href="https://dragonwingdocs.qualcomm.com/Key-Documents/Flash-Guide/how-to-sign-in-with-ssh" target="_self">使用 SSH 登录</a>。

* 将 DUT 和远程设备置于蓝牙有效范围内。

## 为蓝牙低功耗 GATT 功能设置设备

1. 在命令提示符中使用以下命令运行 SSH：

   ```text theme={null}
   ssh root@<device_IP_address>
   ```

   **示例**

   如果设备的 IP 地址为 `10.92.160.222`，请运行以下命令：

   ```text theme={null}
   ssh root@10.92.160.222
   ```

2. 输入以下密码以连接到 SSH：

   ```text theme={null}
   oelinux123
   ```

3. 运行以下命令打开蓝牙测试应用程序：

   ```text theme={null}
   bluetoothctl
   ```

   您可以通过 bluetoothctl 的主菜单选项执行一些 GATT 功能，例如连接和扫描。

   **示例输出**

   ```text theme={null}
   sh-5.1# bluetoothctl
   Agent registered        uetoothd...
   [CHG] Controller 22:22:F1:C1:99:C0 Pairable: yes
   ```

4. 运行以下命令启用蓝牙：

   ```text theme={null}
   power on
   ```

   **示例输出**

   ```text theme={null}
   [bluetooth]# power on
   [CHG] Controller 22:22:F1:C1:99:C0 Class: 0x007c0000
   Changing power on succeeded
   [CHG] Controller 22:22:F1:C1:99:C0 Powered: yes
   ```

5. 运行以下命令进入 **GATT 子菜单**：

   ```text theme={null}
   menu gatt
   ```

   **示例输出**

   ```text theme={null}
   [bluetooth]# menu gatt
   Menu gatt:
   Available commands:
   -------------------
   list-attributes [dev/local]                       List attributes
   select-attribute <attribute/UUID/local> [attribute/UUID] Select attribute
   attribute-info [attribute/UUID]                   Select attribute
   read [offset]                                     Read attribute value
   write <data=xx xx ...> [offset] [type]            Write attribute value
   acquire-write                                     Acquire Write file descriptor
   release-write                                     Release Write file descriptor
   acquire-notify                                    Acquire Notify file descriptor
   release-notify                                    Release Notify file descriptor
   notify <on/off>                                   Notify attribute value
   clone [dev/attribute/UUID]                        Clone a device or attribute
   register-application [UUID ...]                   Register profile to connect
   unregister-application                            Unregister profile
   register-service <UUID> [handle]                  Register application service.
   unregister-service <UUID/object>                  Unregister application service
   register-includes <UUID> [handle]                 Register as Included service in.
   unregister-includes <Service-UUID> <Inc-UUID>     Unregister Included service.
   register-characteristic <UUID> <Flags=read,write,notify...> [handle] Register application characteristic
   unregister-characteristic <UUID/object>           Unregister application characteristic
   register-descriptor <UUID> <Flags=read,write...> [handle] Register application descriptor
   unregister-descriptor <UUID/object>               Unregister application descriptor
   back                                              Return to main menu
   version                                           Display version
   quit                                              Quit program
   exit                                              Quit program
   help                                              Display help about this program
   export                                            Print environment variables
   ```

   * 有关 GATT 服务器功能，请参阅 <a href="perform-bluetooth-low-energy-gatt-server-functions" target="_self">执行蓝牙低功耗 GATT 服务器功能</a>。

   * 有关 GATT 客户端功能，请参阅 <a href="perform-bluetooth-low-energy-gatt-client-functions" target="_self">执行蓝牙低功耗 GATT 客户端功能</a>。

## 后续步骤

### <a href="perform-bluetooth-low-energy-gatt-server-functions" target="_self">执行蓝牙低功耗 GATT 服务器功能</a>

您可以使用 GATT 子菜单选项和 **bluetoothctl** 命令执行蓝牙低功耗 GATT 服务器功能。蓝牙低功耗 GATT 服务器功能包括连接和断开远程设备、添加主服务以及定义特征和描述符。GATT 功能还支持添加包含服务、注册应用程序以及启动广播以使设备可被发现。

### <a href="perform-bluetooth-low-energy-gatt-client-functions" target="_self">执行蓝牙低功耗 GATT 客户端功能</a>

您可以使用 GATT 子菜单选项和 **bluetoothctl** 命令执行蓝牙低功耗 GATT 客户端功能。蓝牙低功耗 GATT 客户端功能包括连接远程设备以及启动或停止蓝牙低功耗 GATT 扫描。您可以检索属性列表、获取属性信息并选择特定属性。GATT 功能还支持读取和写入特征值（包括加密特征），以及读取和写入描述符值。此外，它们还允许为所选属性打开或关闭通知。
