> ## 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.

# 执行蓝牙 GAP 功能

> 您可以使用 bluetoothctl 主菜单中提供的命令执行各种蓝牙 GAP 功能。蓝牙 GAP 功能包括启用和禁用蓝牙、运行和停止查询扫描以发现附近的设备，以及启用设备可发现模式。GAP 还支持与远程蓝牙设备配对、查看已绑定或已配对设备的列表以及取消设备配对。

## 前提条件

开始之前，请按照 <a href="verify-gap-functions#set-up-the-device-for-bluetooth-gap-functions" target="_self">为蓝牙 GAP 功能设置设备</a> 中的说明设置设备。

## 启用蓝牙

要在设备上启用蓝牙，请运行以下命令：

```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
```

## 运行蓝牙查询扫描

要开始查询附近的设备，请运行以下命令：

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

**示例输出**

```text theme={null}
[bluetooth]# scan on
Discovery started
[CHG] Controller 22:22:9B:2C:79:1E Discovering: yes
[NEW] Device A4:30:7A:EE:AF:EF [TV] MyDeviceA 8 Series (43)
[NEW] Device 7E:08:AE:BC:66:58 7E-08-AE-BC-66-58
[CHG] Device A4:30:7A:EE:AF:EF RSSI: -91
[CHG] Device A4:30:7A:EE:AF:EF Modalias: bluetooth: v04E8p8080d0000
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 00001112-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device A4:30:7A:EE:AF:EF ManufacturerData Key: 0xff19
[CHG] Device A4:30:7A:EE:AF:EF ManufacturerData Value:
00 75 00 09 01 00 00 00 06 01 00 00 00 00 00 00 .u...............
00 00 00 00 00 00 00 00                            .........
[NEW] Device F8:7D:76:9D:9B:6B MyDeviceB
[CHG] Device 7E:08:AE:BC:66:58 RSSI: -73
```

## 停止蓝牙查询扫描

要停止正在进行的查询，请运行以下命令：

```text theme={null}
scan off
```

**示例输出**

```text theme={null}
[bluetooth]# scan off
Discovery stopped
[CHG] Device 00:95:01:ED:A3:1C RSSI is nil
[DEL] Device 00:95:01:ED:A3:1C 00-95-01-ED-A3-1C
[CHG] Device 8C:FD:F0:0F:41:DB RSSI is nil
[DEL] Device 8C:FD:F0:0F:41:DB 8C-FD-F0-0F-41-DB
[CHG] Device 3F:5C:33:B2:F4:13 RSSI is nil
[DEL] Device 3F:5C:33:B2:F4:13 3F-5C-33-B2-F4-13
[CHG] Device C8:12:0B:50:F2:51 RSSI is nil
[DEL] Device C8:12:0B:50:F2:51 C8-12-0B-50-F2-51
[CHG] Device 8C:FD:F0:0F:1B:B8 RSSI is nil
[DEL] Device 8C:FD:F0:0F:1B:B8 8C-FD-F0-0F-1B-B8
[CHG] Device 0E:19:D7:85:53:8A RSSI is nil
[DEL] Device 0E:19:D7:85:53:8A 0E-19-D7-85-53-8A
[CHG] Device 75:AD:91:DD:40:2A TxPower is nil
[CHG] Device 75:AD:91:DD:40:2A RSSI is nil
[CHG] Device E4:24:2C:94:28:BC RSSI is nil
[CHG] Device 94:7C:00:B0:38:28 RSSI is nil
[CHG] Controller 8C:FD:F0:21:84:23 Discovering: no
```

## 与远程蓝牙设备配对

在配对远程设备之前，请先<a href="#run-bluetooth-inquiry-scan" target="_self">运行蓝牙查询扫描</a>，确保远程设备可用。

要与远程蓝牙设备配对，请运行以下命令：

```text theme={null}
pair <bt_address>
```

要接受发出/传入的配对请求，请输入 `yes`。要拒绝发出/传入的配对请求，请输入 `no`。

**参数**

`<bt_address>` 是远程设备的蓝牙地址。

**示例**

要与 `<bt_address>` 为 `F8:7D:76:9D:9B:6B` 的远程设备配对，请运行以下命令：

```text theme={null}
pair F8:7D:76:9D:9B:6B
```

**示例输出**

```text theme={null}
[bluetooth]# pair F8:7D:76:9D:9B:6B
Attempting to pair with F8:7D:76:9D:9B:6B
[CHG] Device F8:7D:76:9D:9B:6B Connected: yes
[CHG] Device F8:7D:76:9D:9B:6B Name: MyDeviceB
[CHG] Device F8:7D:76:9D:9B:6B Alias: MyDeviceB
Request /*-9
[agent] Confirm passkey 068560 (yes/no): yes
[CHG] Device F8:7D:76:9D:9B:6B Bonded: yes
[DEL] Device 28:DE:65:7B:59:54 28-DE-65-7B-59-54
[CHG] Device F8:7D:76:9D:9B:6B Modalias: bluetooth:v004Cp760Ad1160
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 00000000-deca-fade-deca-deafdecacafe
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 0000110a-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 00001116-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 0000111f-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 0000112f-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 00001132-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 02030302-1d19-415f-86f2-22a2106a0a77
[CHG] Device F8:7D:76:9D:9B:6B UUIDs: 1ff31936-572e-4b36-a2bf-b2409b1aa6f4
[CHG] Device F8:7D:76:9D:9B:6B ServicesResolved: yes
[CHG] Device F8:7D:76:9D:9B:6B Paired: yes
Pairing successful
[DEL] Device 28:DE:65:7B:5B:71 28-DE-65-7B-5B-71
[CHG] Device F8:7D:76:9D:9B:6B ServicesResolved: no
[CHG] Device F8:7D:76:9D:9B:6B Connected: no
```

## 获取已绑定/已配对设备列表

要获取经验证的已配对设备列表，请运行以下命令：

```text theme={null}
devices
```

**示例输出**

```text theme={null}
[bluetooth]# devices
Device F8:7D:76:9D:9B:6B MyDeviceB
```

## 取消设备配对

要取消设备配对，请运行以下命令：

**示例**

要取消与地址为 `F8:7D:76:9D:9B:6B` 的设备的配对，请运行以下命令：

```text theme={null}
remove F8:7D:76:9D:9B:6B
```

**示例输出**

```text theme={null}
[bluetooth]# remove F8:7D:76:9D:9B:6B
[DEL] Device F8:7D:76:9D:9B:6B MyDeviceB
Device has been removed
```

## 启用设备可发现模式

要在 DUT 中启用可发现模式，请运行以下命令：

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

**示例输出**

```text theme={null}
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller 8C:FD:F0:21:84:23 Discoverable: yes
```

## 禁用蓝牙

要在设备上禁用蓝牙，请运行以下命令：

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

**示例输出**

```text theme={null}
[bluetooth]# power off
[CHG] Controller 8C:FD:F0:21:84:23 Discoverable: no
Changing power off succeeded
[CHG] Controller 8C:FD:F0:21:84:23 Powered: no
[CHG] Controller 8C:FD:F0:21:84:23 Discovering: no
[CHG] Controller 8C:FD:F0:21:84:23 Class: 0x00000000
```
