Skip to content

fix: select usable HCI adapter in BT_ON_OFF#429

Merged
bhargav0610 merged 2 commits intoqualcomm-linux:mainfrom
smuppand:Bluetooth-fix
Apr 28, 2026
Merged

fix: select usable HCI adapter in BT_ON_OFF#429
bhargav0610 merged 2 commits intoqualcomm-linux:mainfrom
smuppand:Bluetooth-fix

Conversation

@smuppand
Copy link
Copy Markdown
Contributor

@smuppand smuppand commented Apr 27, 2026

Fixes #427

This PR fixes BT_ON_OFF adapter selection on platforms with multiple HCI controllers.

Issue:

  • On iq-x7181-evk/Hamao, hci0 is a UART controller that can be DOWN and uninitialized with BD address 00:00:00:00:00:00.
  • hci1 is a USB controller that is UP/RUNNING with a valid BD address.
  • The existing test selected hci0 by default and skipped, even though hci1 was usable.

Changes:

  • Add reusable Bluetooth helper logic to identify usable HCI adapters.
  • Prefer adapters that are UP/RUNNING and have a valid non-zero BD address.
  • Avoid selecting DOWN or uninitialized controllers with 00:00:00:00:00:00.
  • Keep explicit BT_ADAPTER / --adapter override support.
  • Log all detected HCI candidates to make LAVA/CI failures easier to debug.
  • Fix the BT_ON_OFF YAML description typo.

Expected result:

  • BT_ON_OFF now auto-selects hci1 on Hamao when hci0 is DOWN/uninitialized.
  • The test only skips when no usable Bluetooth adapter is available.
root@iq-x7181-evk:/tmp/Runner/suites/Connectivity/Bluetooth/BT_ON_OFF# ./run.sh
[INFO] 2026-04-27 17:11:25 - ------------------------------------------------------------
[INFO] 2026-04-27 17:11:25 - Starting BT_ON_OFF Testcase
[INFO] 2026-04-27 17:11:25 - Checking dependency: bluetoothctl
[INFO] 2026-04-27 17:11:25 - Checking if bluetoothd is running...
[INFO] 2026-04-27 17:11:25 - bluetoothd is running
[INFO] 2026-04-27 17:11:25 - [bt-adapter] hci1 addr=8C:FD:F0:58:50:86 state='UP RUNNING' usable=yes
[INFO] 2026-04-27 17:11:25 - [bt-adapter] hci0 addr=00:00:00:00:00:00 state='DOWN' usable=no
[WARN] 2026-04-27 17:11:25 - bluetoothctl list returned no controllers in non-interactive mode.
[WARN] 2026-04-27 17:11:25 - On minimal/ramdisk images this can be normal; interactive bluetoothctl may still work.
[INFO] 2026-04-27 17:11:25 - Proceeding with interactive bluetoothctl for controller queries (non-interactive output incomplete on some images).
[WARN] 2026-04-27 17:11:25 - Bluetooth diagnostics: controller visibility is inconsistent
[WARN] 2026-04-27 17:11:25 - Adapter: hci1
[WARN] 2026-04-27 17:11:25 - hciconfig output:
[BT-DIAG] hci1: Type: Primary  Bus: USB
[BT-DIAG]       BD Address: 8C:FD:F0:58:50:86  ACL MTU: 1024:7  SCO MTU: 240:8
[BT-DIAG]       UP RUNNING
[BT-DIAG]       RX bytes:1902 acl:0 sco:0 events:149 errors:0
[BT-DIAG]       TX bytes:6113 acl:0 sco:0 commands:149 errors:0
[BT-DIAG]
[BT-DIAG] hci0: Type: Primary  Bus: UART
[BT-DIAG]       BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
[BT-DIAG]       DOWN
[BT-DIAG]       RX bytes:0 acl:0 sco:0 events:0 errors:0
[BT-DIAG]       TX bytes:20 acl:0 sco:0 commands:4 errors:0
[WARN] 2026-04-27 17:11:25 - systemctl status bluetooth:
[BT-DIAG] * bluetooth.service - Bluetooth service
[BT-DIAG]      Loaded: loaded (/usr/lib/systemd/system/bluetooth.service; enabled; preset: enabled)
[BT-DIAG]      Active: active (running) since Sun 1980-01-06 00:19:59 UTC; 46 years 3 months ago
[BT-DIAG]  Invocation: 3550d1ec30284240943717d1b0346333
[BT-DIAG]        Docs: man:bluetoothd(8)
[BT-DIAG]    Main PID: 876 (bluetoothd)
[BT-DIAG]      Status: "Running"
[BT-DIAG]       Tasks: 1 (limit: 76204)
[BT-DIAG]      Memory: 2.8M (peak: 3.8M)
[BT-DIAG]         CPU: 28ms
[BT-DIAG]      CGroup: /system.slice/bluetooth.service
[BT-DIAG]              `-876 /usr/libexec/bluetooth/bluetoothd
[BT-DIAG]
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_0
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_duplex_1
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_duplex_0
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/faststream
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/faststream_duplex
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/opus_05
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/opus_05
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/opus_05_duplex
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/opus_05_duplex
[BT-DIAG] Jan 06 00:19:59 iq-x7181-evk systemd[1]: Started Bluetooth service.
[WARN] 2026-04-27 17:11:25 - journalctl -u bluetooth -b (tail):
[BT-DIAG] Jan 06 00:19:57 iq-x7181-evk systemd[1]: Starting Bluetooth service...
[BT-DIAG] Jan 06 00:19:57 iq-x7181-evk (bluetoothd)[876]: bluetooth.service: ConfigurationDirectory 'bluetooth' already exists but the mode is different. (File system: 755 ConfigurationDirectoryMode: 555)
[BT-DIAG] Jan 06 00:19:57 iq-x7181-evk bluetoothd[876]: Bluetooth daemon 5.86
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Starting SDP server
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Bluetooth management interface 1.23 initialized
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Battery Provider Manager created
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Failed to set default system config for hci1
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: /usr/src/debug/bluez5/5.86/src/profile.c:register_profile() :1.8 tried to register 0000111e-0000-1000-8000-00805f9b34fb which is already registered
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/aptx_hd
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_hd
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/aptx
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/opus_g
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/opus_g
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/sbc
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/sbc
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_1
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_0
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_duplex_1
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/aptx_ll_duplex_0
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/faststream
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/faststream_duplex
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/opus_05
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/opus_05
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSink/opus_05_duplex
[BT-DIAG] Jan 06 00:19:58 iq-x7181-evk bluetoothd[876]: Endpoint registered: sender=:1.8 path=/MediaEndpoint/A2DPSource/opus_05_duplex
[BT-DIAG] Jan 06 00:19:59 iq-x7181-evk systemd[1]: Started Bluetooth service.
[WARN] 2026-04-27 17:11:25 - bluetoothctl list returned no controllers in non-interactive mode.
[WARN] 2026-04-27 17:11:25 - On minimal/ramdisk images this can be normal; interactive bluetoothctl may still work.
[INFO] 2026-04-27 17:11:25 - Proceeding with interactive bluetoothctl for controller queries (non-interactive output incomplete on some images).
[INFO] 2026-04-27 17:11:27 - Initial Powered = yes
[INFO] 2026-04-27 17:11:27 - Powering OFF...
[INFO] 2026-04-27 17:11:28 - btpower: requesting 'off' on hci1 (current=yes)
[INFO] 2026-04-27 17:11:31 - btpower: hci1 Powered=no after request.
[PASS] 2026-04-27 17:11:32 - Post-OFF verification: Powered=no (as expected).
[INFO] 2026-04-27 17:11:32 - Powering ON...
[INFO] 2026-04-27 17:11:33 - btpower: requesting 'on' on hci1 (current=no)
[INFO] 2026-04-27 17:11:36 - btpower: hci1 Powered=yes after request.
[PASS] 2026-04-27 17:11:37 - Post-ON verification: Powered=yes (as expected).
root@iq-x7181-evk:/tmp/Runner/suites/Connectivity/Bluetooth/BT_ON_OFF# cat BT_ON_OFF.res
BT_ON_OFF PASS
root@iq-x7181-evk:/tmp/Runner/suites/Connectivity/Bluetooth/BT_ON_OFF#

Add Bluetooth helper functions to identify usable HCI adapters based on
UP/RUNNING state and a valid non-zero BD address.

The new helpers log all available HCI candidates and prefer controllers that
are already usable, avoiding DOWN or uninitialized adapters such as UART hci0
with 00:00:00:00:00:00 when another valid controller is available.

Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
Update BT_ON_OFF adapter selection to prefer an UP/RUNNING controller with a
valid BD address when BT_ADAPTER is not explicitly provided.

This fixes platforms with multiple HCI devices where hci0 may be DOWN or
uninitialized while another adapter, such as USB hci1, is valid and usable.
The test now logs adapter candidates for CI debug and avoids incorrectly
skipping when a usable controller exists.

Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
Copy link
Copy Markdown

@Sreenivas8523 Sreenivas8523 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks correct and resolves the multi-HCI adapter selection issue. Approving.

Copy link
Copy Markdown

@Sreenivas8523 Sreenivas8523 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix resolves the multi-HCI adapter selection issue. Approving.

@bhargav0610 bhargav0610 merged commit 57f184a into qualcomm-linux:main Apr 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BT_ON_OFF test skips when UART hci0 is DOWN but USB hci1 is UP

3 participants