Commit graph zephyr/drivers/bluetooth
Author SHA1 Message Date
Johan Hedberg
a412f2cd41 Bluetooth: HCI: userchan: Prefer real time only as the chosen HCI driver
BT_USERCHAN selects NATIVE_SIMULATOR_PREFER_REAL_TIME, since a
controller behind the HCI User Channel runs in real time. BT_USERCHAN
is enabled whenever its devicetree node is, and native_sim.dts always
enables the node. Tests that set the zephyr,bt-hci chosen node to a
test HCI driver therefore also run in real time, so their sleeps and
expiring timeouts take the same amount of wall-clock time.

Select NATIVE_SIMULATOR_PREFER_REAL_TIME only when the User Channel
driver is the chosen HCI driver. Builds that use it, such as the
Bluetooth samples and the tests/bluetooth/classic suites, keep running
in real time.

Tested with twister on native_sim over the 49 test directories that
enable Bluetooth: 604 of 604 test cases pass, and the total execution
time of their 66 run configurations drops from 74 s to under 3 s, 60 s
of which were tests/bluetooth/host_disable.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-28 22:52:38 -04:00
Johan Hedberg
192ca77c69 soc: native: Add an option for drivers that interact with real time
NATIVE_SIM_SLOWDOWN_TO_REAL_TIME defaults to y when BT_USERCHAN or
WIFI_NATIVE_SIM is enabled, because both drivers talk to something that
runs in real time. The native_sim board thereby has to know about every
such driver.

Add NATIVE_SIMULATOR_PREFER_REAL_TIME for these drivers to select, and
let the board default to real time when it is set. The symbol lives in
Kconfig.soc, which every build sources, so that drivers can select it
unconditionally. No functional change.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-28 22:52:38 -04:00
Flavio Ceolin
57bf6640df drivers: bluetooth: h5: Drop event packets without payload
The buffer for an HCI event packet is allocated in the PAYLOAD state,
once the event code is known. A header that declares an event packet
with no payload skips that state, so h5_process_complete_packet() took
a NULL buffer and passed it to the HCI receive path, which reads it.
A controller, or anything on the UART line, could crash the host with
one such frame.

Reject the packet in the HEADER state, as the other packet types
already do when no buffer can be allocated.

Signed-off-by: Flavio Ceolin <flavio@hubble.com>
2026-10-28 22:50:26 -04:00
Johan Hedberg
a6a701e882 Bluetooth: HCI: h4: Fix RX buffer race between rx_thread and the ISR
rx_thread allocated the buffer for a packet whose header was complete
while the ISR could still be receiving it. The ISR then allocated its
own buffer and read payload into it, rx_thread replaced it, and the
packet reached the host short while the ISR's buffer leaked, until no
RX buffer was left and reception stopped. Either a spare rx.ready token
(since commit 71ef6c6979 ("Drivers: Bluetooth: H4: Use a semaphore to
wake up HCI RX thread")) or a TX interrupt let the ISR in, as
uart_irq_rx_ready() need not depend on the RX interrupt being enabled.

Make the handover explicit: rx_thread allocates only after the ISR has
stopped RX for lack of a buffer, and only once it has delivered every
packet queued before that, whose buffer the allocation may need. Until
rx_thread hands the RX state back, the ISR leaves it alone and keeps RX
disabled. The header copy in read_header() was reachable only through
the race and goes.

Tested with the hci_uart bsim tests, also with every seventh allocation
in the ISR made to fail, and built for nucleo_h563zi. bsim does not run
the ISR in the middle of rx_thread, so the race was not reproduced.

Fixes #122956

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-28 22:45:28 -04:00
Johan Hedberg
24b4d49904 Bluetooth: HCI: h4: Fix buffer size check of the deferred allocation
When the ISR finds no free buffer, rx_thread allocates one and checks
that it holds the payload, but not the header copied in front of it. A
packet that fits only without its header is then written up to the
header length past the end of the buffer. read_header() has the same
check; commit ec970a635ea0 ("drivers: bluetooth: h4: Fix check for
sufficient buffer size") fixed only read_payload(). Check and copy the
header in one helper for all three.

Tested with the hci_uart bsim tests, also with every seventh allocation
in the ISR made to fail.

Fixes #122956

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-28 22:45:28 -04:00
William Markezana
59721db621 drivers: bluetooth: hci: bflb: select BFLB_PHYRF on BL60x and BL808
The BL60x and BL808 PHY libraries are linked when CONFIG_BFLB_PHYRF is
set, so have their BLE controllers select it.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-10-28 22:36:48 -04:00
Vincent Tardy
584ed746e5 drivers: bluetooth: stm32wba: fix low power exit
When the driver receives the PM_DEVICE_ACTION_RESUME notification,
the Link Layer deep-sleep exit function is called regardless of
the standby_entered value, and the NVIC configuration for the radio
is restored regardless of the Link Layer state.

Signed-off-by: Vincent Tardy <vincent.tardy@st.com>
2026-10-22 18:38:53 +02:00
Eric Mechin
d5b06ac92b drivers: bluetooth: hci: hci_stm32wba.c: fix flash access without BLE
FLASH synchronization must be bypassed when the BLE is disabled
(on Zephyr bt_disable() function call).
The FD_FLASHACCESS_RFTS_BYPASS flag must be set to ENABLE to avoid
a deadlock in the flash manager when waiting for a LL response that
do not exist.

Signed-off-by: Eric Mechin <eric.mechin@st.com>
2026-10-16 15:19:18 -05:00
Johan Hedberg
0f40a81ba0 Bluetooth: HCI: spi_st: Fix a stale start event ending the reset wait
The driver waits for the vendor event with which the controller reports
its start: in open() when the node has reset-event, and with SPI
protocol v1 after an HCI Reset. An event that no wait had taken, such
as one that came after a wait had timed out, stayed in its semaphore
and ended the next wait at once, before the controller had reported
its new start.

Clear the semaphore ahead of both waits: before the reset line is
released, and once the HCI Reset has gone out, while the bus is still
held so that the event that follows cannot have been read yet. The
wait after an HCI Reset now requires reset-event too, as the one in
open() does, so that no wait goes without the clear.

Not tested on hardware.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-15 00:52:19 +02:00
Johan Hedberg
bb82ff9dac Bluetooth: HCI: spi_st: Fix send() failing for a command that went out
An error from send() says that a command was not submitted: the Host
fails the command, restores the command credit and sends the next one,
and the lockstep helper, which the driver uses in open(), documents the
same for its send function. The driver also returned an error after
part of a command had gone out, when a later chunk failed, and after a
complete HCI Reset when the controller did not report its start in
time. The controller may still answer in both cases. Its response then
completes a retry of the same command, or its credit lets the next
command out while another one is unanswered.

Return 0 once a command has been on the bus and treat it as sent, which
for an HCI Reset includes the wait for the start of the controller.
What becomes of it shows in its response or, through the command
timeout, in the lack of one. Data packets and commands of which nothing
was sent are reported as before, and that includes a transfer for which
the controller had no room yet. The wait for the start of the
controller after an HCI Reset now checks the packet type too: it took
two bytes of any packet for the opcode.

Not tested on hardware.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-15 00:52:19 +02:00
Ryan Erickson
1783873470 Bluetooth: fix format specifiers for size_t/ssize_t
Several LOG_ and __ASSERT format strings use %u or %d for arguments
that are size_t or ssize_t, which produces -Wformat= warnings on
LP64 targets (e.g. AArch64). Switch to %zu / %zd.

* subsys/bluetooth/host/classic/sdp.c: three format strings that
  compare against sizeof() or use ssize_t counters.

* drivers/bluetooth/hci/hci_nxp_setup.c: matching V1 and V3
  "Out of sending buffer range" messages (both LOG_ERR and the
  neighbouring __ASSERT that uses the same string).

No functional change; eliminates 5 build warnings on
nitrogen93_smarc/mimx9352/a55/nx611.

Assisted-by: Claude:claude-opus-4.7
Signed-off-by: Ryan Erickson <ryan.erickson@ezurio.com>
2026-10-09 16:49:48 +02:00
Johan Hedberg
7056ec0b5a Bluetooth: HCI: nxp: Size each vendor command buffer for its command
nxp_bt_send_vs_command() framed every vendor command in one buffer
sized for the longest of them, the calibration data, with a length
check for the others. Every platform reserved that buffer, although
only those with CONFIG_HCI_NXP_SET_CAL_DATA send the command, and a
longer command added later would have had to change the constant the
buffer is sized by.

Each caller now defines a buffer from the size of its own parameters
and passes it to the helper, so there is no shared size to maintain
and a build frames only the commands it sends. Measured with
-fstack-usage, bt_nxp_open() on frdm_mcxw71, which sends the address
command only, needs 24 bytes less stack; on frdm_rw612, which sends
three of the commands, the compiler now inlines their callers into it
and the stack use grows by 8 bytes.

Build-tested with the peripheral_hr sample on frdm_mcxw71 (public
address) and frdm_rw612 (calibration data and automatic sleep). Not
run on hardware.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-10-08 08:05:59 +02:00
Michele Sardo
d4039f369d drivers: bluetooth: hci_stm32wba: report busy only on buffer exhaustion
Make BLECB_Indication() set ll_state_busy and return 1 only when packet
handling fails with -ENOMEM.

Previously, all receive errors were treated as a busy condition, including
malformed packets and other parsing failures. This could incorrectly signal
that the host was unable to accept data and trigger unnecessary
flow-control behavior.

Refactor treat_evt(), treat_acl(), and treat_iso() to return explicit error
codes and pass the received net_buf through an output parameter so the
caller can distinguish buffer exhaustion from other receive failures.

treat_evt() ignores discardable events on memory allocation failure without
returning an error

Fixes #118805

Signed-off-by: Michele Sardo <msmttchr@gmail.com>
2026-09-30 19:43:37 +02:00
William Markezana
ff92d02c68 soc: bflb: bl70x: add IEEE 802.15.4 support
Enable the IEEE 802.15.4 radio on the BL70x (BL702) series: add the
ieee802154 devicetree node, compile the RF/platform shim, link the
lmac154/RF blobs, and place the timing-critical lmac154 .tcm_code in ITCM
(otherwise those input sections become orphans at an unloaded address).
Provide CONFIG_BT_HCI_DRIVER_LOG_LEVEL for 802.15.4-only builds so the
shared BLE/802.15.4 platform shim compiles without Bluetooth enabled.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-09-29 15:49:54 +02:00
William Markezana
9ecdab44ae soc: bflb: bl70xl: add IEEE 802.15.4 support
Enable the IEEE 802.15.4 radio on the BL70xL (BL702L) series: add the
ieee802154 devicetree node, compile the RF/platform shim, place the
timing-critical lmac154 code in ITCM, and link the lmac154/RF blobs.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-09-29 15:49:54 +02:00
William Markezana
92a7e51369 soc: bflb: bl61x: add IEEE 802.15.4 support
Enable the IEEE 802.15.4 radio on the BL61x (BL616) series: add the
ieee802154 devicetree node, RF/PHY init via the shared wl_api blobs, the
TCM code section, and link the lmac154 blob. The GLB reset / memcpy shims
required by the BL616 blobs live with the other HAL shims.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-09-29 15:49:54 +02:00
William Markezana
ce4d17d9b7 drivers: bluetooth: hci: bflb: add BL808 support
Wire the BL808 on-chip controller into the Bouffalo Lab HCI driver:
add the SoC platform block and controller init/deinit, and set the
ACL TX and event RX buffer counts (7/8) to match the buffer size the
controller reports in LE Read Buffer Size.

Signed-off-by: William Markezana <william.markezana@gmail.com>
2026-09-28 14:31:01 -04:00
Johan Hedberg
c658ef70f3 Bluetooth: HCI: Deprecate the setup() driver API op
setup() is Host code living in the HCI driver vtable: most
implementations call bt_hci_cmd_send_sync(), which is why the op exists
at all, and why a driver's vendor-specific initialization has nowhere
to run in a build without a Host. A driver does that work inside open()
instead, over its own transport, with the packet and lockstep helpers,
taking the public address from bt_hci_get_public_addr().

Deprecate the op, bt_hci_setup(), its parameter structure and
BT_HCI_SETUP, so that an out-of-tree driver still implementing setup()
is pointed at the replacement. The Host keeps calling the op through
the deprecation window; the op, its Kconfig and the h4 vendor hook are
removed two releases from now.

No attribute is put on the op or the function: the Host reads the
member to call it, so an attribute would warn on the Host rather than
on the drivers the deprecation is for. Selecting the deprecated Kconfig
symbol is what makes a build say so, and that fires exactly for the
drivers that have not moved.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-28 10:54:05 -04:00
Johan Hedberg
947ecad570 Bluetooth: HCI: uart_infineon: Configure the controller from open()
Send the resets, the baud rate updates, the firmware download, the
public address and the SCO route from the H:4 driver's open-time hook
through the lockstep helper, instead of from bt_h4_vnd_setup() with
the Host's command API, so that a build without a Host, which did not
link, runs the same sequence. The public address comes from
bt_hci_get_public_addr(),
and the firmware blocks are sent from a static command buffer sized
for the longest command, off the caller's stack. The extension selects
BT_H4_VND_OPEN instead of BT_HCI_SETUP.

Build-tested with the peripheral_hr and hci_uart samples on
cy8cproto_062_4343w, the latter with an overlay choosing the c2h UART,
and with peripheral_hr on arduino_giga_r1/stm32h747xx/m7. Not run on
hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-28 07:37:26 -04:00
Johan Hedberg
a2c92882bf Bluetooth: HCI: nxp_setup: Configure the controller from open()
Send the baud rate update, the calibration data and the IR
configuration from the H:4 driver's open-time hook through the
lockstep helper, instead of from bt_h4_vnd_setup() with the Host's
command API. A build without a Host did not link, and would have
skipped the calibration commands, which returned success without being
sent; they are now sent in every build. The firmware upload stays in
bt_hci_transport_setup(), and the extension selects BT_H4_VND_OPEN
instead of BT_HCI_SETUP.

Build-tested with the peripheral_hr and hci_uart samples on
mimxrt1170_evk@B/mimxrt1176/cm7, the latter with an overlay choosing
the c2h UART, and with peripheral_hr on frdm_mcxn947/mcxn947/cpu0 with
the nxp_arduino_aw510_wifi_bt shield. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-28 07:37:26 -04:00
Johan Hedberg
0c382b603f Bluetooth: HCI: h4: Configure the controller from open() via a vendor hook
The vendor extensions of the H:4 driver initialize their controller
from bt_h4_vnd_setup(), called from the setup() op with the Host's
command API, so a controller-only build, which has no such API, does
not link, and the sequence could only ever run below a Host.

Add bt_h4_vnd_open(), which the driver calls last in open(), once the
UART is running, with a lockstep helper: the extension's commands go
through the driver's own TX path from a buffer of their own, and the
RX thread feeds every received packet to the helper before delivering
it. A failing hook fails open(), which then drops what is queued or
half received, as close() now does too, so that a retry starts clean.
bt_h4_vnd_setup() keeps working through the setup() op.

The extension's commands go through a buffer of up to
CONFIG_BT_BUF_CMD_TX_SIZE parameter bytes, the option for the longest
HCI command a build sends, which the Infineon extension already raises
for its firmware download; the driver fails a longer command with
-EMSGSIZE instead of overflowing the buffer.

Build-tested with the H:4 samples of the in-tree extensions, which the
following commits convert, and with peripheral_hr on arduino_portenta_c33,
whose H:4 driver has no extension. Not run on hardware.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-28 07:37:26 -04:00
Johan Hedberg
e3f93c99f1 Bluetooth: HCI: cyw208xx: Free the RX buffer of a packet that does not fit
A received packet longer than the buffer allocated for it was logged
and dropped, but the buffer was never freed, so every such packet cost
the pool one buffer for good.

Build-tested with the peripheral_hr sample on
cyw920829m2evk_02/cyw20829b0lkml. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:04:35 +02:00
Johan Hedberg
0fec868057 Bluetooth: HCI: cyw208xx: Do not send the asset's commands via the Host
wiced_bt_dev_vendor_specific_command() exists for the btstack-integration
asset to link, and sent the asset's vendor commands with the Host's
bt_hci_cmd_alloc() and bt_hci_cmd_send(), ignoring the completion
callback. Neither of the asset's callers is reached: the driver's
wiced_bt_stack_init_internal() drops the post stack initialization
callback that would enable the sleep mode, which
cyw208xx_bt_enable_low_power_mode() does instead, and the only caller of
cybt_prm_download(), cybt_patchram_download.c, is not part of the build.

Report the command as unsupported instead. This was the driver's last
use of a Host API, so a build without a Host, such as the hci_uart
sample, now links.

Build-tested with the peripheral_hr and hci_uart samples on
cyw920829m2evk_02/cyw20829b0lkml, the latter with an overlay choosing
the UART. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:04:35 +02:00
Johan Hedberg
2b59014b3d Bluetooth: HCI: cyw208xx: Configure the controller from open()
Reset the controller, download its firmware, set the public address and
enable the low power mode from within open(), through the HCI lockstep
helper and the driver's own send path, instead of implementing the
setup() driver API op on top of the Host's bt_hci_cmd_send_sync(). The
public address comes from bt_hci_get_public_addr(), which gives
BT_ADDR_ANY when none has been set, so the controller's hard-coded
default address is still always overridden. The responses are consumed
in the driver's receive path by feeding received packets to the helper
before they are delivered.

The platform task resets the controller every time it is started, so
open() restores the helper's initial command allowance with
bt_hci_lockstep_reset() before it sends the first command: the reset
controller allows one command again without announcing it.

The firmware blocks are sent from a static command buffer sized for the
longest HCI command, to keep it off the stack of the thread that opens
the driver; the caller serializes open().

A failing or unanswered command fails open() with an error instead of
failing the Host's HCI initialization later, and is logged by the
helper. open() then shuts the platform task down again, as close()
does, since a failed open() is not followed by close(), and a platform
task that fails to start makes open() return -EIO instead of the
asset's positive result code. open() moves below close() for that.

The raw send path is factored out of send() so that it serves both the
send() op and the helper. It takes the packet with its packet indicator
instead of pulling the indicator off the buffer, so a buffer that could
not be sent is returned to the caller unmodified.

The driver no longer selects BT_HCI_SETUP. BT_AIROC still selects it
for every AIROC part, because the H4 extension of the UART-attached
ones implements the setup hook, and the Host treats a missing setup()
op as nothing to do.

Build-tested with the peripheral_hr sample on
cyw920829m2evk_02/cyw20829b0lkml. Not run on hardware.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:04:35 +02:00
Johan Hedberg
02f556780e Bluetooth: HCI: nxp: Configure the controller from open()
Send the vendor-specific initialization commands, the calibration data,
the sleep configuration and the public address, from within open(),
through the HCI lockstep helper and the driver's own send path, instead
of implementing the setup() driver API op on top of the Host's
bt_hci_cmd_send_sync(). The public address comes from
bt_hci_get_public_addr(). The responses are consumed in the driver's
receive path by feeding received packets to the helper before they are
delivered.

Without a Host the helper function for these commands returned success
without sending anything, and setup() was not called there in the first
place, bt_enable_raw() opening the driver only, so a controller-only
build left the controller without its calibration data, sleep
configuration and address. They are now sent in every build, and the
driver no longer selects BT_HCI_SETUP.

A failing or unanswered command, or a failed HCI start, fails open()
with an error instead of failing the Host's HCI initialization later,
and open() then unregisters the receive callback again, as close()
does, since a failed open() is not followed by close(). open() moves
below close() for that. The helper's command allowance is restored at
every open() and after the controller's own reset that follows the
annex 55 calibration data, as neither reset announces one. The stale
comment claiming the address command gets no Command Complete goes: it
already went through bt_hci_cmd_send_sync(), which waits for one.

The raw send path is factored out of send() so that it serves both the
send() op, which keeps intercepting the vendor commands it handles
locally, and the helper.

Build-tested with the peripheral_hr sample on frdm_mcxw71 (public
address) and frdm_rw612 (calibration data and automatic sleep). Not run
on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:04:21 +02:00
Johan Hedberg
c4359e581e Bluetooth: HCI: spi_st: Configure the BlueNRG controller from open()
Send the BlueNRG ACI configuration commands, the link-layer-only mode
and the public address, from within open(), through the HCI lockstep
helper and the driver's own SPI send path, instead of implementing the
setup() driver API op on top of the Host's bt_hci_cmd_send_sync(). The
public address comes from bt_hci_get_public_addr(). The responses are
consumed in the driver's receive thread by feeding received packets to
the helper before they are delivered.

That also replaces the second way the driver had of sending the
link-layer-only command: in a controller-only build it called the raw
bt_send() from inside its own open(), before the transport was open to
its user, and left the response to reach the application. Both build
types now share one path, and the driver no longer selects
BT_HCI_SETUP.

A failing or unanswered command fails open() with an error instead of
failing the Host's HCI initialization later, and is logged by the
helper. open() stops the receive thread, aborting it if it does not
exit, and resets the controller when it fails after having started
them, which also covers the existing boot timeout, since a failed
open() is not followed by close(). open() moves below close() for that,
without other changes.

The raw send path is factored out of send() and takes the device, so
that it serves both the send() op and the helper.

Build-tested on disco_l475_iot1 (st,hci-spi-v1) with the peripheral_hr
and hci_uart samples, and on nucleo_l476rg with the x_nucleo_bnrg2a1
shield (st,hci-spi-v2) with peripheral_hr. Not run on hardware.

open() takes the controller out of reset through its reset line on
every call, so it also restores the helper's initial command allowance
with bt_hci_lockstep_reset(): the controller allows one command again
without announcing it.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:04:02 +02:00
Johan Hedberg
fbc4a69439 Bluetooth: HCI: stm32wba: Set the public address from open()
Write the public address into the controller from within open(), taking
it from bt_hci_get_public_addr(), instead of implementing the setup()
driver API op. The command goes through BleStack_Request() as before,
so no Host command API was involved and nothing else changes in how it
is sent.

The address is now also set in controller-only builds, where the driver
did not select BT_HCI_SETUP and bt_enable_raw() would not have called
setup() anyway: with no public address to set, which is always the case
there, it is the one derived from the device UID, as before. The driver
no longer selects BT_HCI_SETUP.

A failure to set the address fails open() instead of the Host's HCI
initialization later. open() then closes what it had opened, since a
failed open() is not followed by close(). open() moves below close()
and the address functions for that, without other changes.

Build-tested on nucleo_wba55cg with the peripheral_hr and hci_uart
samples. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-26 01:03:45 +02:00
Johan Hedberg
5929118ed7 Bluetooth: HCI: ambiq: Include the lockstep header in apollox_blue.h
apollox_blue.h declares bt_apollo_vnd_setup() with a struct
bt_hci_lockstep parameter but does not include the header that defines
the type, relying on its includers to have done so. Include it, and
document the parameter. Both includers already include it first, so
nothing changes for them.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 15:46:32 -07:00
Johan Hedberg
58cfb20a8c Bluetooth: HCI: ambiq: End the transport session when open() fails
A failed open() stops the RX thread and takes the controller down, but
leaves transport_open set and the session counter unchanged, so a send
that is waiting for the SPI semaphore, or sleeping between its attempts,
goes on to talk to a controller that is down, or to the one a later
open() brings up. End the session in the failed-open unwind the way
close() does. The semaphore take gets an explicit void cast: the
semaphore is never reset, so the take cannot fail, and there is nothing
the unwind could do about it if it did.

Build-tested on apollo4p_blue_kxr_evb. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 15:46:32 -07:00
Johan Hedberg
000d1bad5a Bluetooth: HCI: ambiq: Restore the command allowance after controller init
bt_apollo_controller_init() resets the controller through its reset
line and loads it over the raw SPI path, outside the lockstep helper,
so the helper's command allowance does not follow. After a close(), the
helper is left in whatever state the last command left it, and the
freshly started controller allows one command again without announcing
it. Restore the helper's initial allowance with bt_hci_lockstep_reset()
before the vendor setup sends its first command.

Build-tested on apollo4p_blue_kxr_evb. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 15:46:32 -07:00
Kai Cheng
609fc049e7 drivers: bluetooth: userchan: size RX frame buffer from BT_BUF_RX_SIZE
The rx_thread assembles a whole HCI packet in a single static frame
buffer before handing it to the host. That buffer was hardcoded to 512
bytes. A full ACL data packet can be larger than this: the host's
receive buffer is CONFIG_BT_BUF_ACL_RX_SIZE bytes and defaults up to
1300 for Classic, and an A2DP media packet fills it. When such a packet
arrives, frame_size reaches the buffer size, the driver logs "HCI Packet
is too big for frame (512 bytes). Dropping data" and discards it. The
host then sees the truncated stream and rejects it with "Unexpected
L2CAP continuation", so no A2DP media is ever received.

Size the frame buffer from BT_BUF_RX_SIZE, which the host already uses
for its RX buffers: it includes the H4 type octet and the maximum of the
ACL, event and ISO receive-buffer sizes, so the buffer holds every
packet type get_rx() accepts, including ISO packets whose MTU can exceed
both 512 and the ACL RX size.

Verified on native_sim with a real Bluetooth dongle (HCI User Channel):
before the fix A2DP media reception failed as described above; after it,
an A2DP SBC stream from a phone is received continuously (packets both
below and above the old 512-byte limit) with no dropped-frame or L2CAP
continuation errors.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-09-24 13:47:36 +02:00
Johan Hedberg
84a88dfdc6 Bluetooth: HCI: ipm_stm32wb: Do not go through the Host in close()
close() sent its vendor-specific reset command with
bt_hci_cmd_send_sync(), that is, through the Bluetooth Host. The Host
is only one possible user of the driver, which therefore cannot rely on
it, and close() was for that reason compiled only into builds with a
Host, leaving a controller-only build with a transport it could open
but not close. It did not work with the Host either: bt_disable() marks
the transport closed before it calls close(), after which the Host
refuses the command with -EHOSTDOWN, so bt_disable() failed.

Send the command with the HCI lockstep helper over the driver's own
transport instead, as open() does for its commands. The receive thread
is still running at that point and feeds the response to the helper; it
is stopped afterwards, as before. With that the driver calls no Host
API any more, and close() is part of every build.

Build-tested on nucleo_wb55rg with the peripheral_hr and hci_uart
samples. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 09:58:21 +02:00
Johan Hedberg
da07294a47 Bluetooth: HCI: ipm_stm32wb: Configure the controller from open()
Send the two vendor-specific initialization commands, the public
address derived from the device UID and the transmit power level, from
within open(), through the HCI lockstep helper and the driver's own
send path, instead of implementing the setup() driver API op on top of
the Host's bt_hci_cmd_send_sync(). The responses are consumed in the
driver's receive thread by feeding received packets to the lockstep
helper before delivering them to the host.

The commands no longer depend on the Host, so they now also run in
controller-only builds, where they were both compiled out and never
reached, bt_enable_raw() opening the driver without calling setup(), so
the controller kept its default address and transmit power. The driver
no longer selects BT_HCI_SETUP. A failing or unanswered command fails
open() with an error instead of failing the Host's HCI initialization
later, and is logged by the helper.

A failed address command fails open(), as it has failed setup() since
commit 19c58a5a3b ("Bluetooth: ipm_stm32wb: Fail setup when the
address write fails"). open() aborts the receive thread it started when
the vendor initialization fails, so that a second bt_enable() does not
create a thread that is still running.

When open() restarts the coprocessor after a close(), it also restores
the helper's initial command allowance with bt_hci_lockstep_reset():
the restarted coprocessor allows one command again without announcing
it.

The raw send path is factored out of send() and takes the device, so
that it serves both the send() op and the helper.

close() still sends its reset command through the Host and stays behind
CONFIG_BT_HCI_HOST.

Build-tested on nucleo_wb55rg with the peripheral_hr sample. Not run on
hardware.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 09:58:21 +02:00
Johan Hedberg
748dc62920 drivers: bluetooth: hci_da1469x: Build close() without the Host
close() has been compiled only with CONFIG_BT_HCI_HOST since the driver
was added, while the driver API table has always referenced it
unconditionally, so a build of this driver without the Bluetooth Host
fails with "'bt_da1469x_close' undeclared". The function disables the
CMAC interrupt and the CMAC core and uses nothing of the Host, so drop
the guard.

Compile-tested for da1469x_dk_pro: the driver object in a
CONFIG_BT_HCI_RAW configuration, which failed before, and the
peripheral_hr sample. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-23 10:51:10 +01:00
Johan Hedberg
cbe92bf15e Bluetooth: HCI: Provide the public address to drivers before open()
Store the public identity address that the Host hands to the driver's
setup() op also in the common HCI driver data, through the new
bt_hci_set_public_addr() API, before the HCI transport is opened. The
driver reads it with bt_hci_get_public_addr() and can apply it during
open(), i.e. from vendor-specific initialization that does not depend
on the Host's command APIs being available.

bt_hci_get_public_addr() returns BT_ADDR_ANY while no public address
has been set, which is what setup() receives in that case, so a driver
moving from one to the other keeps the check it has, and driver data
that has never been written needs no flag to say so. BT_ADDR_NONE is
the name that suggests itself for this, so the choice is spelled out
where a driver author looks: on both functions, with the check a driver
is expected to make, on the field, on the setup() parameter, which did
not document its value until now, and in the Kconfig help. The test
pins the value.

The channel is set on every bt_enable() and cleared when there is no
public identity, so that an address an earlier enable left behind is
not applied to the controller by a later one.

The setup() path keeps receiving the address as before; both channels
coexist until the drivers implementing setup() have migrated. So that
enabling the new channel no longer pulls in the mechanism it replaces,
BT_HCI_SET_PUBLIC_ADDR stops selecting BT_HCI_SETUP; the drivers that
apply the address in setup() (BlueNRG ACI, STM32WBA, CYW208XX) now
select BT_HCI_SETUP themselves, matching the conditions their setup()
implementations are compiled under.

Both functions are declared unconditionally, as coding guideline rule
A.1 requires of a header, so that their callers can select on the
option with IS_ENABLED() rather than the preprocessor, and defined in
a source file that is compiled only when the option is enabled, so
that a call that is not guarded fails to link rather than quietly
doing nothing. Only the field they work on is conditional, so a driver
that does not announce the capability pays nothing for it.

The driver API group version goes to 0.3.0 for the two functions added
to it.

The host identity test gains a scenario that creates a public identity
before bt_enable() and checks what the driver is handed while the
transport is opened, including that an enable without a public identity
hands it nothing rather than what the previous one left. The scenario
enables the capability through a prompt the test adds to it, since the
option is otherwise selected by drivers only. Its fake driver gains a
close() op, which the test needs in order to cycle the transport.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-23 10:45:13 +01:00
Johan Hedberg
d1a597400d Bluetooth: HCI: psoc6_bless: Set the public address from open()
Send the vendor-specific set-public-address command from within open(),
through the HCI lockstep helper and the driver's own send path, instead
of implementing the setup() driver API op on top of the Host's
bt_hci_cmd_send_sync(). The response is consumed in the driver's event
handler by feeding received packets to the lockstep helper before
delivering them to the host.

The driver no longer calls any Host command API, so the address is now
also configured in controller-only builds, where bt_enable_raw() only
opens the driver and never called setup(), and it no longer selects
BT_HCI_SETUP. A failing or unanswered command fails open() with an
error instead of failing the Host's HCI initialization later, and is
logged by the helper.

open() aborts the receive thread it started when the command fails, so
that a second bt_enable() does not create a thread that is still
running.

The raw send path is factored out of send() and takes the device, so
that it serves both the send() op and the helper. It now reports a
failed Cy_BLE_SoftHciSendAppPkt() to its caller instead of logging and
returning success, which the helper needs in order to tell a command
that was not submitted from one that went unanswered.

Build-tested on cy8cproto_063_ble with the peripheral_hr sample. Not run
on hardware.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-23 10:43:25 +01:00
Johan Hedberg
700c57643a Bluetooth: HCI: ambiq: Do not close the transport mid-transfer
close() takes the controller down and aborts the receive thread with no
regard for an SPI transfer in progress. The receive thread holds
sem_spi_available for the duration of a transfer, and
k_thread_abort() does not give the semaphore back, so a close() that
lands in a transfer leaves it taken and the next send blocks forever.
Before that, the controller is put in reset and its clocks are turned
off with the transfer still in flight.

Hold the semaphore across both, so that close() waits for the transfer
in progress to finish before it touches the controller or the thread.
bt_apollo_controller_deinit() does no SPI transfer of its own, so it
cannot wait for the semaphore close() holds.

Holding the semaphore does not stop a send that is already under way,
though: the send path gives it back between its attempts, which it
repeats for up to five seconds, so that the receive path can drain the
controller in the meantime. The driver therefore keeps track of whether
the transport is open and of how often that has changed. open() and
close() update both while holding the semaphore, and the send path
gives up with -ENETDOWN if on getting the semaphore the transport is
closed or the count has moved on since the send began. The count is
what stops a send that slept through a close() and the open() after it
from delivering the old session's packet to the new one; the flag is
what stops a send that starts while close() is finishing. The count is
atomic because a send notes it before it has the semaphore: what
counts is the session the call began in, not the one in which it first
gets the semaphore. open() makes its update before the controller
initialization, which already sends through the same path.

A close() from the receive callback aborts the calling thread, which
never returns to give the semaphore back, so that case gives it back
before the abort.

Build-tested on apollo4p_blue_kxr_evb and apollo3_evb with the
peripheral_hr sample. Not run on hardware.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-22 18:04:29 +02:00
Johan Hedberg
e66b9c678e Bluetooth: HCI: ambiq: Configure the controller from open()
Send the vendor-specific NVDS configuration command from within open(),
through the HCI lockstep helper and the driver's own SPI send path,
instead of implementing the setup() driver API op on top of the Host's
bt_hci_cmd_send_sync(). The responses are consumed in the driver's
receive thread by feeding received packets to the lockstep helper
before they reach the host.

The command no longer depends on the Host, so the two code paths that
existed for it, one building the packet by hand for controller-only
builds and one going through the Host, collapse into one, and the
driver no longer selects BT_HCI_SETUP. The hand-built path was in fact
unreachable: bt_enable_raw() opens the driver without calling setup(),
so a controller-only build sent neither the NVDS command nor the reset
that follows it. Both now run there. A failing or unanswered command
fails open() with an error instead of failing the Host's HCI
initialization later, and is logged by the helper.

The reset that makes the NVDS parameters take effect is now sent in
every build. Only the controller-only path sent it before; builds with
a Host relied on the Host's own reset, which follows a few HCI
transactions later.

open() aborts the receive thread it started when the controller
initialization or the vendor command fails, so that a second
bt_enable() does not create a thread that is still running.

The raw send path is factored out of send() and takes the device, so
that it serves both the send() op and the helper.

Build-tested on apollo4p_blue_kxr_evb and apollo3_evb with the
peripheral_hr sample. Not run on hardware.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-22 18:02:46 +02:00
Johan Hedberg
19c58a5a3b Bluetooth: ipm_stm32wb: Fail setup when the address write fails
bt_ipm_ble_init() logs an error when bt_ipm_set_addr() fails and
carries on regardless, so a controller that rejects
ACI_HAL_WRITE_CONFIG_DATA comes up with a silently different identity
address. Return the error instead, so that bt_enable() fails and the
caller learns that the controller is in an unexpected state.

The UID64 is factory programmed on every part, so bt_get_ble_addr()
returning NULL is not an expected case either and fails setup the same
way.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-21 16:26:18 -04:00
Michele Sardo
72687a911a Bluetooth: HCI: stm32wba: fixes in send API
- preserve buffer ownership on error paths, consistent with API
  expectations [See also bt_hci_send documentation], preventing
  double unref.
- fix the data length check as the pre-allocated event buffer
  already carried the H:4 indicator, so its tailroom was one byte
  short of the 71-byte Read Local Supported Commands response, and
  smaller responses only passed because net_buf_reset() discarded
  that byte before the copy.
- Factorize common code to improve maintainability, keeping flow
  control only in the indication

Signed-off-by: Michele Sardo <msmttchr@gmail.com>
2026-09-21 16:26:13 -04:00
Wai-Hong Tam
2ea7b9c4a1 Bluetooth: Kconfig: Only restrict system workqueue priority when needed
Enabling CONFIG_BT restricts SYSTEM_WORKQUEUE_PRIORITY to the
cooperative range for every build, but the requirement comes from the
individual components that submit work to the system workqueue, not
from Bluetooth being enabled.

An application that asks for a preemptible system workqueue therefore
cannot build with Bluetooth enabled at all, even when no Bluetooth
code uses that queue. Running the system workqueue below every other
thread is a common way to service a watchdog only while the whole
system is still making progress.

Add BT_SYSTEM_WORKQUEUE_COOP and apply the range only when it is set.
The components that need the system workqueue to stay cooperative
select the option themselves, so the requirement is recorded next to
the code that has it and a new work item cannot slip past it: the
host stack, the H:5 and STM32WB0 drivers, the NXP wake-on-BT LED
blink option, and BT_CTLR_PRIVACY when the split link layer builds
ull_filter.c.

Mesh, Audio and the other Host users need the Host, so they are
covered by its select; they get their own when the Host drops it.

No in-tree configuration changes behavior: SYSTEM_WORKQUEUE_PRIORITY
already defaults to -1, and no Bluetooth test or sample overrides it.

Signed-off-by: Wai-Hong Tam <waihong@google.com>
2026-09-20 19:06:12 +02:00
Johan Hedberg
caf9a9c174 Bluetooth: hci_silabs_siwx91x: Configure RF power from open()
Send the vendor-specific RF power mode command from within open(),
through the HCI lockstep helper and the driver's own send path, instead
of implementing the setup() driver API op on top of the Host's
bt_hci_cmd_send_sync(). The response is consumed in the driver's
receive callback by feeding received packets to the lockstep helper
before delivering them to the host.

The driver no longer calls any Host command API, so the configuration
now also runs in controller-only builds, and it no longer selects
BT_HCI_SETUP. A failing or unanswered command fails open() with an
error instead of failing the Host's HCI initialization later, and is
logged by the helper.

The raw send path is factored out of send() and takes the device, so
that it serves both the send() op and the helper. The helper is
initialized once, from the device init function, so that reopening the
transport does not re-initialize its semaphore.

Tested on siwx917_rb4338a with the peripheral_hr sample.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-18 11:15:45 +01:00
Aksel Skauge Mellbye
4a0c25208b drivers: bluetooth: hci: silabs: Add support for Series 3
Enable Bluetooth for Series 3 devices by adding new stubs for
symbols from blobs and increasing the link layer stack size.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2026-09-16 21:34:20 +01:00
Aksel Skauge Mellbye
cb4b5475ff soc: silabs: Rename SOC_GECKO_HAS_RADIO to match policy
Rename the Kconfig option to SOC_VENDOR_SILABS_HAS_RADIO to
match the guidelines requiring all Kconfig symbols in soc/
to have specific prefixes.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2026-09-16 21:34:20 +01:00
Michael Zimmermann
5a062f3a73 soc: silabs: move radio configs to silabs directory
Since this driver can and will also be used for series 1, move it one level
up into the respective if-guard.

Signed-off-by: Michael Zimmermann <michael.zimmermann@sevenlab.de>
Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2026-09-16 21:34:20 +01:00
Johan Hedberg
fa635fec2c Bluetooth: hci_spi_st: Gate and check the LL-only write in raw builds
The controller-only build sends the link layer only configuration from
open() for every BlueNRG ACI controller, while the Host build's setup()
sends it only when the device tree sets req-ll-only, as introduced for
the X-NUCLEO-WBA25A1 support in commit a8c09c2e34 ("drivers:
bluetooth: hci: Modify BLE driver to support X-Nucleo-WBA25A1"). Apply
the same condition in open(), and fail open() when the command cannot
be sent instead of ignoring the result.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-14 15:41:26 -04:00
Johan Hedberg
327a0aa361 Bluetooth: hci_spi_st: Check the result of the LL-only configuration
bt_spi_bluenrg_setup() ignores the return value of the
ACI_HAL_WRITE_CONFIG_DATA command that puts the BlueNRG into link layer
only mode, while checking the one that sets the public address a few
lines further down. The command was originally sent from the RX
thread's vendor event handler, where there was no caller to report to,
and kept its unchecked form when it moved into setup().

Link layer only mode is a precondition for the Zephyr Host, which needs
a plain HCI controller underneath, and the controller only accepts the
write as its first command after reset, so a failure cannot be retried
later. Return the error, so that bt_enable() fails instead of the stack
coming up on a controller whose embedded host is still active.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-14 15:41:26 -04:00
Johan Hedberg
b05a1fdf42 Bluetooth: hci_stm32wba: Serialize all BleStack_Request() calls
hci_lock exists to serialize the accesses to the controller through
BleStack_Request(), but only send() takes it: the vendor commands that
setup() and close() send bypass it. Nothing else calls into the
controller at those points of the current call sequence, so this is
not an observed race, but the invariant is the driver's own and is
cheap to hold unconditionally. Take the lock around both calls, with
the same error handling as send().

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-14 08:42:24 -04:00
Johan Hedberg
560b657df9 Bluetooth: hci_stm32wba: Remove unused aci_set_ble_addr structure
The structure has no users: bt_hci_stm32wba_setup() builds the
ACI_HAL_WRITE_CONFIG_DATA command in a byte array instead.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-14 08:42:24 -04:00
Sylvio Alves
597f9e1125 drivers: bluetooth: hci: add esp32c61 support
Enable the esp32 HCI driver on the ESP32-C61: extend the
controller Kconfig gates, report the C61 vendor hardware
variant id, add the hci devicetree node and enable it on the
esp32c61_devkitc board. The C61 BLE controller reuses the C6
controller sources and blobs through the hal.

Assisted-by: Claude:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-09-09 18:14:06 -04:00