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

# 调试蓝牙问题

<a id="bt_debugging" />

要调试蓝牙问题，请使用主机日志或空口（OTA）日志。主机日志包括 Logcat 和 BTSnoop（协议栈）/HCI 日志。您可以使用这些日志进行初步调试。

下表列出了调试不同蓝牙问题所需的日志。

| 问题类型  | Logcat | BTSnoop/HCI | 内核日志 | OTA | PipeWire | 子系统重启（SSR）日志 |
| ----- | ------ | ----------- | ---- | --- | -------- | ------------ |
| 一般问题  | 必需     | 必需          | 不需要  | 建议  | 不需要      | 不需要          |
| 蓝牙控制器 | 不需要    | 建议          | 不需要  | 必需  | 不需要      | 必需           |
| 蓝牙开/关 | 必需     | 不需要         | 不需要  | 不需要 | 不需要      | 必需           |
| 崩溃    | 必需     | 不需要         | 必需   | 不需要 | 不需要      | 必需           |
| 音频    | 不需要    | 必需          | 不需要  | 必需  | 必需       | 不需要          |

## 调试 BlueZ 协议栈

<a id="debug-bluez-stack" />

在启用或收集日志之前，请执行以下操作：

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

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

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

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

   **示例**

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

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

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

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

### 启用 BlueZ 日志

要启用 BlueZ 日志，请在 SSH 中执行以下操作：

1. 运行以下命令启用读写权限：

   ```text theme={null}
   mount -o remount rw /
   ```

2. 在文本编辑器中打开 Bluetooth 服务文件。

   **示例**

   要在 VI 编辑器中打开 `bluetooth.service` 文件，请运行以下命令：

   ```text theme={null}
   vi /lib/systemd/system/bluetooth.service
   ```

3. 在文件中的以下行末尾追加 `-d` 选项：

   ```text theme={null}
   ExecStart=/usr/libexec/bluetooth/bluetoothd -d
   ```

4. 保存文件。

5. 运行以下命令重新加载 Bluetooth 守护进程：

   ```text theme={null}
   systemctl daemon-reload
   ```

6. 运行以下命令重启蓝牙：

   ```text theme={null}
   systemctl restart bluetooth
   ```

### 收集 BlueZ 日志

* 要收集 BlueZ 用户空间日志，请在 SSH 中运行以下命令：

  ```text theme={null}
  journalctl -f -u bluetooth.service > /var/log/bluetooth.log
  ```

* 要收集所有日志，请在 SSH 中运行以下命令：

  ```text theme={null}
  journalctl -f > /var/log/full.log
  ```

### 收集 snoop 日志

要收集 snoop 日志，请在 SSH 中执行以下操作：

1. 运行 `hcidump` 工具。

2. 运行以下命令保存文件：

   ```text theme={null}
   hcidump --save-dump=<filename.log>
   ```

   **示例**

   要将 snoop 日志保存到 `snoop.log` 文件，请运行以下命令：

   ```text theme={null}
   hcidump --save-dump=/var/log/snoop.log
   ```

   如果设备有多个 HCI 接口，请在捕获 snoop 日志时使用 `-i` 选项指定目标接口。请先运行 `hciconfig` 以识别可用接口。

   **示例输出**

   ```text theme={null}
   sh-5.2# hciconfig
   hci1:   Type: Primary  Bus: USB
           BD Address: 8C:FD:F0:96:54:42  ACL MTU: 1024:7  SCO MTU: 240:8
           UP RUNNING
           RX bytes:5782304 acl:27596 sco:0 events:29481 errors:0
           TX bytes:13229664 acl:18315 sco:0 commands:8760 errors:0

   hci0:   Type: Primary  Bus: UART
           BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
           DOWN
           RX bytes:0 acl:0 sco:0 events:0 errors:0
           TX bytes:20 acl:0 sco:0 commands:4 errors:0
   ```

   要在 `hci1` 上捕获 snoop 日志，请运行以下命令：

   ```text theme={null}
   hcidump -i hci1 --save-dump=/var/log/snoop.log
   ```

   **示例输出**

   ```text theme={null}
   sh-5.2# hcidump -i hci1 --save-dump=/var/log/snoop.log
   HCI sniffer - Bluetooth packet analyzer ver 5.72
   btsnoop version: 1 datalink type: 1002
   device: hci1 snap_len: 1500 filter: 0x0
   ```

### 启用 PipeWire 日志

要启用 PipeWire 日志，请在 SSH 中执行以下操作：

1. 在文本编辑器中打开 PipeWire 配置文件。

   **示例**

   要在 VI 编辑器中打开 `pipewire.conf` 文件，请运行以下命令：

   ```text theme={null}
   vi /usr/share/pipewire/pipewire.conf
   ```

2. 取消注释日志级别并将其设置为 `4` 或 `5`。

   ```text theme={null}
   #log.level = 4
   ```

3. 保存文件。

4. 运行以下命令重新加载 Bluetooth 守护进程：

   ```text theme={null}
   systemctl daemon-reload
   ```

5. 运行以下命令重启 PipeWire：

   ```text theme={null}
   systemctl restart pipewire
   ```

### 启用 WirePlumber 服务日志

要启用 WirePlumber 服务日志，请执行以下操作：

1. 运行以下命令验证 WirePlumber 服务的状态：

   ```text theme={null}
   systemctl status wireplumber
   ```

2. 在文本编辑器中打开 WirePlumber 服务文件。

   **示例**

   要在 VI 编辑器中打开 `wireplumber.service` 文件，请运行以下命令：

   ```text theme={null}
   vi /usr/lib/systemd/system/wireplumber.service
   ```

3. 将以下调试变量添加到文件中的所有服务部分：

   ```text theme={null}
   Environment=WIREPLUMBER_DEBUG=T
   ```

4. 保存文件。

5. 运行以下命令重新加载 Bluetooth 守护进程：

   ```text theme={null}
   systemctl daemon-reload
   ```

6. 运行以下命令重启 WirePlumber 服务：

   ```text theme={null}
   systemctl restart wireplumber
   ```

7. 验证服务状态，确认其是否以指定的标志运行。

### 启用 ofono 服务日志

要启用 ofono 服务日志，请在 SSH 中执行以下操作：

1. 运行以下命令验证 ofono 服务的状态：

   ```text theme={null}
   systemctl status ofono
   ```

   **示例输出**

   ```text theme={null}
   sh-5.1# systemctl status ofono
   * ofono.service - Telephony service
      Loaded: loaded (/lib/systemd/system/ofono.service; enabled; vendor preset: enabled)
      Active: active (running) since Sun 1980-01-06 00:00:00 UTC; 30min ago
      Main PID: 990 (ofonod)
      Tasks: 1 (limit: 6234)
      Memory: 3.8M
      CGroup: /system.slice/ofono.service
               `- 990 /usr/sbin/ofonod -n

   Jan 06 00:00:00 qcm6490 systemd[1]: Started Telephony service.
   sh-5.1# |
   ```

2. 在文本编辑器中打开 ofono 服务文件。

   **示例**

   要在 VI 编辑器中打开 `ofono.service` 文件，请运行以下命令：

   ```text theme={null}
   vi /lib/systemd/system/ofono.service
   ```

3. 在文件中的以下行末尾追加 `-d` 选项：

   ```text theme={null}
   ExecStart=/usr/sbin/ofonod -n -d
   ```

4. 保存文件。

5. 运行以下命令重新加载 Bluetooth 守护进程：

   ```text theme={null}
   systemctl daemon-reload
   ```

6. 运行以下命令重启 ofono 服务：

   ```text theme={null}
   systemctl restart ofono
   ```

7. 验证服务状态，确认其是否以指定的标志运行。

### 收集 SSR 转储日志

在 Qualcomm Linux 软件中，如果任何蓝牙子系统模块崩溃，SSR 功能会在蓝牙驱动中收集所需的固件崩溃转储，然后重启蓝牙子系统。崩溃转储文件位于 `/var/spool/crash/` 目录。

关于 SSR 日志记录，请注意以下几点：

* 要验证 SSR 日志是否已启用或禁用，请运行以下命令：

  ```text theme={null}
  cat /sys/class/devcoredump/disabled
  ```

  返回值：

  * `1`：SSR 日志记录已禁用。

  * `0`：SSR 日志记录已启用。

* 要启用 SSR 日志，请运行以下命令：

  ```text theme={null}
  echo 0 > /sys/class/devcoredump/disabled
  ```

* 要手动收集 SSR 日志，请执行以下操作：

  <Note>
    要手动收集 SSR 崩溃转储，请确保设备蓝牙已打开。
  </Note>

  1. 运行 `hcitool` 工具。

  2. 运行以下命令向控制器发送崩溃命令：

     ```text theme={null}
     hcitool cmd 0x3f 0c 26
     ```

     **示例输出**

     ```text theme={null}
     hcitool cmd 0x3f 0c 26
     < HCI Command: ogf 0x3f, ocf 0x000c, plen 1
        26
     > HCI Event: 0xff plen 246
        01 09 A5 7A 01 02 84 BD 4C 00 00 00 00 7C 0C 01 10 0C 8B 00
        00 00 02 00 61 0C 8B 00 00 0C FC 00 00 AC 08 02 00 B8 04 02
        00 08 08 08 08 09 09 09 09 10 10 10 10 11 11 11 11 04 00 00
        00 80 FF 06 00 CC DE 06 00 67 0C 01 10 4A 0F 01 10 00 00 00
        00 02 00 00 00 A0 E8 DE 06 00 0C 8B 00 00 0C FC 00 00 AC 08
        02 00 84 16 02 00 3F 42 01 10 04 00 00 00 06 00 00 00 0C 8B
        00 00 0C FC 00 00 3F 00 00 00 BD AE 02 00 04 00 00 00 FF FF
        00 00 0C 8B 00 00 0C FC 00 00 3F 00 00 00 B1 BB 0D 10 90 FD
        01 00 90 2B 01 00 10 36 01 00 4C 09 02 00 90 FD 01 00 15 C6
        0D 10 90 2B 01 00 49 E2 02 10 00 00 00 00 00 00 00 10 35 D5
        A5 2D 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
        02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
        02 02 02 02 02 02
     ```

     触发的崩溃会在 `/var/spool/crash/` 目录生成一个 BIN 文件。

     **示例输出**

     ```text theme={null}
     ls -l /var/spool/crash/
     total 904
     -r--------. 1 root root 458888 Jan  1 00:53 hci0_1970-01-01_00-53-36.bin
     -r--------. 1 root root 458888 Jan  1 00:58 hci0_1970-01-01_00-58-18.bin
     ```

  3. 确保已在 `/var/spool/crash/` 目录生成 BIN 文件。

<Note>
  默认情况下未安装用户空间转储收集工具。请安装或配置一个工具（例如 `systemd-coredump` 或 `kdump-tools`），将转储保存到 `/var/spool/crash/`。

  如果您观察到任何超时或蓝牙硬件错误，请联系 Qualcomm 并共享该 BIN 文件。
</Note>

<Warning>
  **IQ-9075 和 IQ-8275 上的 SSR 限制**

  在 IQ-9075 和 IQ-8275 平台上，SSR 存在一个已知限制：如果崩溃是由内存中损坏的 RAM 补丁数据引起的，仅靠 SSR 无法完全恢复蓝牙子系统。需要重启平台才能恢复正常运行。
</Warning>
