Commit graph zephyr/tests/bluetooth
Author SHA1 Message Date
Axel Le Bourhis
6b1dd1d959 bluetooth: mesh: fix BLOB flash double-program on ECC flash
The explicit-erase path in wr_chunk() programs a shared write block
twice when a chunk boundary is not write-block aligned, which corrupts
the ECC syndrome on flash that allows only one program per erase (e.g.
some NXP MCXW SoCs) and faults on the next read. Commit a9ad258c84
fixed only the non-erase path.

Add opt-in CONFIG_BT_MESH_BLOB_IO_FLASH_BLOCK_CACHE (default n) that
buffers a block in RAM and, on the chunk that completes the block,
programs it write-block-aligned once, so no write block is programmed
twice. The flush runs in wr() rather than block_end so a failed
flash_area_write is returned to the server (the chunk stays missing and
the client retries) and a sticky error prevents any later re-program;
an unaligned init offset is rejected up front. Default builds are
unchanged.

Signed-off-by: Axel Le Bourhis <axel.lebourhis@nxp.com>
2026-10-08 15:07:35 +02:00
Szymon Janc
478f9bfbf4 Bluetooth: Host: Fix advertising with NRPA with privacy enabled
With privacy enabled random address is set via
bt_id_set_adv_private_addr() which has a shortcut for NRPA
when BT_LE_ADV_OPT_USE_NRPA flag is set. Previously advertising
instance options were set at the very beginning of configuration
and this was working correctly. But now new options are set only
after configuration was successful and this resulted in RPA being
set by bt_id_set_adv_private_addr() since options were not yet
updated.

Pass new options to bt_id_set_adv_private_addr() directly allowing
it to take proper actions. This is also consistent with current design
of bt_id_set_adv_own_addr().

This is a regression after
commit 2548b7b100 ("Bluetooth: Host: Set adv->options only on success")

This is affecting GAP/BROB/BCST/BV-04-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2026-10-08 10:45:37 +02:00
Pisit Sawangvonganan
23efe07a22 tests: {application_development, bluetooth, boards, cmake}: fix typo
Utilize a code spell-checking tool to scan for and correct spelling errors
in all files within:
- `tests/application_development`
- `tests/bluetooth`
- `tests/boards`
- `tests/cmake`

Assisted-by: Claude:claude-sonnet-5-5 codespell
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-10-06 22:40:29 +02:00
Arkadiusz Grzelka
f7c11e0699 tests: Bluetooth: Host: Add a test for repeated settings_load() of keys
Store a bond with an IRK, then call settings_load() and start
advertising, using a native_sim fake HCI driver. Store a second bond and
repeat. Check that rl_entries is one after the first load and two after
the second, both with a Controller resolving list and with host-side
resolving, and that with a Controller resolving list LE Add Device To
Resolving List is sent only once for each bond.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
2026-10-06 07:25:11 +02:00
Sylvio Alves
21c5b3baea tests: bluetooth: shell: build with iso sync receiver only
Add a build-only scenario that keeps BT_ISO_SYNC_RECEIVER as the
only ISO role, so the shell is compiled without the broadcaster
and the unicast ISO code.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-10-06 07:22:49 +02:00
Jamie McCrae
7ad467351a tests: bluetooth: host: adv: Fix selecting deprecating Kconfig
Fixes a test which selected a deprecated assert Kconfig

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-10-03 09:02:05 -05:00
Emil Gydesen
a4e5cbf41b Bluetooth: Audio: Use bt_att_get_max_ntf_size
Use the public bt_att_get_max_ntf_size function to get the
current notification size, rather than using the
LE Audio specific one.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-30 12:42:59 +02:00
Szymon Janc
12e9bb79cd tests: Bluetooth: tester: Unify subgroups validationg in BAP BTP
Subgroups are now consistently validated during BTP command parsing.
Also behavior if number of provided subgroups exceeds supported number
is now consistent (BTP error is returned in all cases instead of
clamping to supported number)

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2026-09-30 12:36:56 +02:00
Szymon Janc
55a35c3ad7 tests: Bluetooth: tester: Fix BTP BAP commands size validation
Some commands defined as variable length were not validating if
provided length is valid.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2026-09-30 12:36:56 +02:00
Aleksandr Khromykh
6335ffe17e tests: bluetooth: mesh: settings: add store scheduler tests
Add a unit test suite that builds settings.c against stub handlers
on native_sim with distinct timeout values, and covers the no-wait,
replay-list and generic pending flag groups: each group is stored
on its own deadline, scheduling one group does not pull another
forward, a cancelled flag is not stored, and every pending flag
completes exactly once.

Adapt the existing replay protection list unit test to the reset flag
that bt_mesh_rpl_reset() and bt_mesh_rpl_clear() now schedule.

Assisted-by: Copilot:claude-opus-5
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-09-29 10:41:11 +02:00
Måns Ansgariusson
e6161ef3ad debug: add granular per-file assertions (ZASSERT)
Introduce ZASSERT, a self-contained assertion facility configured per
source file through a named module rather than the single global
CONFIG_ASSERT switch.

A file selects its module with ZASSERT_MODULE(); the level is resolved
from CONFIG_ASSERT_MODULE_<MODULE>_LEVEL and may be overridden per file.
Modules are defined with the Kconfig.template.assert template, which takes
module/module-str inputs following the logging template convention.
The four levels are:
- Off (compiled out)
- Terse (check only)
- On (check + location only)
- Verbose (Check, location, condition and message)

Since the level is known at compile time, disabled assertions are folded
away by the compiler, and below Verbose the optional message and its
arguments are as well.

zassert provides a set of __weak overridable hooks:
- zassert_fail() - called when an assertion fails
- zassert_vprint() - called to print the assertion failure message
- zassert_post_action() - the terminal action after an assertion failure

CONFIG_ASSERT remains the master switch. The assert Kconfig moves from
subsys/debug to lib/os/zassert, the legacy CONFIG_ASSERT_* symbols are kept
but deprecated (mapped onto the DEFAULT module), and lib/os/assert.c is
removed. The __ASSERT() family is preserved as a thin compatibility shim
over the DEFAULT module, so existing call sites keep working unchanged.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-09-25 10:01:43 +02:00
Taha Zarif
af4b150047 Bluetooth: Host: reject invalid identity in OOB lookup
Reject identity handles that are outside the current identity set or refer
to an empty deleted slot before producing local LE OOB data.

Add native_sim coverage for the first unused handle and a deleted non-tail
identity.

Assisted-by: ChatGPT:gpt-5.6-sol
Signed-off-by: Taha Zarif <tahazarif380@gmail.com>
2026-09-24 17:14:58 +02:00
Johan Hedberg
3c7615415e tests: Bluetooth: Host: Add a test for bt_disable() failures
Add a native_sim test with a fake HCI driver for the two ways in which
the driver can keep bt_disable() from closing the transport: a driver
built without a close() op, which must leave Bluetooth untouched and in
particular the controller not reset, and a close() that fails, after
which Bluetooth must not be ready, a second bt_disable() must be able
to finish the job and bt_enable() must work again.

The test binding sets no quirks, unlike the ones of the neighbouring
tests, which set "no-reset": the point is to see whether the Host
resets the controller.

Without the readiness handling in bt_disable() both cases fail: the
controller is reset before -ENOSYS is returned, and bt_is_ready() is
true after the failed close.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 12:05:28 +02:00
Alex Ciascai
ea1083c696 Bluetooth: Tester: BAP: Fix broadcast source reconfigure
Add a dedicated BTP_BAP_BROADCAST_SOURCE_RECONFIGURE (0x1C)
command and handler that look up the already allocated local
source by broadcast ID with a new
btp_bap_broadcast_local_source_from_brcst_id_get() helper,
update its QoS and codec configuration, call setup_broadcast_source()
to reconfigure the existing bap_broadcast instance in place, and push
the updated BASE through periodic advertising data. This keeps
allocation, setup and reconfiguration as separate, explicit operations:
SETUP/SETUP_V2 always create a new broadcast source, and RECONFIGURE
is the only command that reconfigures one, instead of overloading setup
to reconfigure on a duplicate broadcast ID.

Signed-off-by: Alex Ciascai <alexandru.ciascai@nordicsemi.no>
2026-09-24 10:01:05 +02:00
Emil Gydesen
d439b0abf2 Bluetooth: CCP: Add server support for bearer URI schemes
Add support for setting and getting the bearer URI schemes supported
list using the CCP API.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-23 19:17:27 +02:00
Emil Gydesen
4a39357776 Bluetooth: CCP: Client: Add support for read bearer URI schemes
Add support for reading the remote bearer URI schemes supported list.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-23 19:15:30 +02: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
0b9f82b4c9 Bluetooth: Add a reset entry point to the HCI lockstep helper
The helper documented that initializing it again restores the initial
command allowance, for a controller that has been reset by other means
than an HCI command. That is not safe: bt_hci_lockstep_init() calls
k_sem_init(), which with CONFIG_OBJ_CORE_SEM links the semaphore's
object core, so initializing the same helper twice links the same
object twice and corrupts the tracking list. No in-tree driver does it
today, the one user initializing the helper from its device
initialization function, so this is a contract that invites the defect
rather than an active one.

Add bt_hci_lockstep_reset(), which restores the allowance and forgets
the outstanding command without re-initializing the semaphore, and
document initialization as the once-only call it has to be. The
transport send function and the caller's timeout survive the reset, so
a driver that resets its controller while opening it does not have to
repeat what it set up at device initialization.

The reset may be called from any context and takes the helper's lock,
so it may run while packets are being fed, and a driver that is fed
from a callback it cannot stop can use it too. It signals the change of
state by giving the helper's semaphore, as feeding does, so a sender
that waits for the controller to allow its command goes ahead.

A driver is expected not to reset its controller while a command is
outstanding, since it cannot be known which side of the reset the
command ended up on. If it does, the command is abandoned: its response
is no longer consumed and its sender fails at its deadline, not
earlier, so that a response which still arrives cannot be taken for
that of a later command with the same opcode. What the reset cannot do
either is tell packets the controller sent before it from the responses
to what follows, so those are not to be fed afterwards, which the
documentation now says.

The helper keeps its view of the command allowance from one opening of
the transport to the next, so the group documentation now says when a
driver has to call the reset.

Five cases are added to the unit test: the allowance is restored after
a command that went unanswered, a repeated reset, which is what a
driver resetting its controller on every open performs, a reset that
releases a sender waiting for the allowance, the same from an ISR, and
a reset with a command outstanding, whose sender must not return before
its deadline.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-22 18:04:16 +02:00
Emil Gydesen
316219309d tests: Bluetooth: Audio: Shell: Change to to extra_conf_file
Previously audio.conf was a standalone configuration file, but
has now been changed to work as an extra_conf_file instead.
The purpose of this is to avoid having too many duplicate
configs in the shell application.

Additionally the LE audio tests in tests.yaml has been changed
to use YAML anchors to reduce the amount of duplicated
configurations in that file too, keep each test case simpler.

Some of these changes exposed some existing surpressed warnings
that were similarly fixed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-22 17:57:37 +02:00
Johan Hedberg
5f3ee983d4 tests: bluetooth: addr: Cover bt_addr_le_to_str and bt_addr_le_from_str
Add ZTEST suites for the two conversion APIs that use the prefix-based
LE address string format:

bt_addr_le_to_str
  - PUBLIC produces the 'P:' prefix, RANDOM produces 'R:'
  - PUBLIC_ID and RANDOM_ID are formatted by their base type
  - HCI-level extended types (resolved-RPA bit) are formatted by their
    base type
  - Byte order is preserved (display is most-significant first while
    a.val is stored on-air, little-endian)
  - BT_ADDR_LE_STR_LEN is large enough for the longest output
  - The UNRESOLVED and ANONYMOUS sentinels are formatted as random

bt_addr_le_from_str
  - 'P:..' / 'R:..' parse to the expected type, with the prefix and
    the hexadecimal digits accepted in either case
  - An unknown prefix, a missing prefix, a missing ':' separator,
    malformed addresses and truncated strings are rejected with -EINVAL
  - Roundtrip to_str -> from_str preserves the address

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-22 17:53:33 +02:00
Johan Hedberg
2b9422c426 Bluetooth: addr: Change LE address string format to prefix-based
Replace the "XX:XX:XX:XX:XX:XX (type)" string representation of LE
addresses with a compact form that carries the address type as a
single-character prefix:

- "P:XX:XX:XX:XX:XX:XX" for public addresses
- "R:XX:XX:XX:XX:XX:XX" for random addresses

The address and its type are now one whitespace-free token, which makes
shell input trivial to parse and lets an address be pasted from log or
shell output straight into a command.

bt_addr_le_to_str() produces the new format. Address type values that
carry HCI-level extension bits, such as the Controller-resolved
identity types, are formatted by their base type, and the unresolved-RPA
and anonymous sentinels as random addresses; the extra information has
to be conveyed separately by the caller. BT_ADDR_LE_STR_LEN shrinks from
30 to 20 bytes.

bt_addr_le_from_str() loses its separate type argument and accepts only
the new format, with the prefix, like the hexadecimal digits, accepted
in either case. Neither the old output nor the old two-token input form
is retained: the string representation was never documented as a
stable format, and the Bluetooth Working Group agreed to switch to the
new one directly rather than carry a deprecation period.

All shell commands taking an LE address (bt connect, disconnect,
select, info, clear, directed-adv, adv-create/adv-param directed,
per-adv-sync-create, oob-remote, fal-add, fal-rem, id-create, id-reset,
gatt resubscribe, bap_broadcast_assistant add_src, bap_scan_delegator
add_src and cap_commander broadcast_reception_start) now take the
address as a single argument. Their argument counts, positional
argument indices, help strings and shell documentation are updated
accordingly. While at it, bap_scan_delegator add_src is fixed to
reference the right argv slots in its error messages and metadata
parsing, and id-create no longer proceeds with an uninitialized address
after failing to parse its argument.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-22 17:53:33 +02:00
Sharon Lin
42742c9e2b Bluetooth: Host: Add bt_id_reset_irk API
Add bt_id_reset_irk(uint8_t id, uint8_t *irk) to replace the local
Identity Resolving Key for an identity without changing its identity
address.

The caller can provide an IRK, or pass NULL or an all-zero buffer to
have the stack generate one and return it in the buffer.

Reject the operation when the stack is not ready, any advertising set
is active, the identity has a created extended advertising set, the
default identity is used for scanning or initiating, or bonds exist.
Bonds must be removed with bt_unpair() before resetting the IRK.

Persist the new IRK when CONFIG_BT_SETTINGS is enabled.
Invalidate the current RPA state and the cached per-identity RPA
after a successful reset.
The API is available when CONFIG_BT_PRIVACY is enabled.
Preserve -ENOTSUP when random generation is unsupported and map other
random generation failures to -EIO.

Assisted-by: Augment:GPT-5.6
Signed-off-by: Sharon Lin <slin@atmosic.com>
2026-09-21 16:25:23 -04:00
Benjamin Cabé
f116f01dbe tests: bluetooth: gatt: guard the PSA key slot count
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT only exists when Mbed TLS provides the
PSA Crypto core; on a non-secure target TF-M provides it and the symbol
is undefined, so the leak test fails to compile. Fall back to zero and
skip the test there.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-21 11:27:33 +01:00
Jakub Zymelka
66cc57ec10 tests: bluetooth: gatt: increase main stack for PSA init
On qemu_cortex_m3, the Mbed TLS SYS_INIT hook runs psa_crypto_init()
before main(). Without an entropy driver, seeding the software
HMAC_DRBG peaks at 1344 bytes of main-thread stack.

Set MAIN_STACK_SIZE to 2048 to prevent pre-main memory corruption.

Signed-off-by: Jakub Zymelka <jakub.zymelka@nordicsemi.no>
2026-09-21 11:26:25 +01:00
Johan Hedberg
bf9cd11485 Bluetooth: Add HCI lockstep command helper
Add hci_lockstep.h, a helper on top of the HCI packet helpers for
sending HCI commands one at a time and waiting for their responses
through a caller-provided transport send function. The header lives
with the HCI driver API under include/zephyr/drivers/bluetooth, since
HCI drivers are its users, and the implementation in
subsys/bluetooth/common is part of every CONFIG_BT build, like the
packet helpers.

The helper is for HCI drivers that need to exchange HCI commands with
the controller over their own transport, typically for vendor-specific
controller initialization, without the Host's command machinery and
regardless of whether a Host is present in the build. It relies on the
HCI traffic being in lockstep during such initialization windows, so
it needs no opcode correlation state machine. Command flow control
still applies: the helper sends a command only once the controller
allows one, which every command response fed to it announces through
Num_HCI_Command_Packets, the NOP Command Complete included, so a
controller that allows no further command holds the next one until it
does.

The helper is shaped after what its users have: the transport send
function receives the HCI device, so a driver's own raw send function
serves as-is; received packets are fed as the bytes the driver holds
them in; a NULL command buffer stands for a command without parameters;
the command timeout, which covers both the wait for the controller to
allow the command and the wait for its response, defaults to the Host's
own 10 seconds; and every failure is logged with the opcode by the
helper, so that drivers need no error reporting of their own.

The helper's state is one byte under a short spinlock, with a single
semaphore that only signals a change of it, so an instance costs 40
bytes on Cortex-M, or 48 with CONFIG_POLL widening the semaphore.

Add a test suite for the lockstep behavior to the HCI packet helper
test, including feeding the helper from ISR context, the command flow
control and transport failures, and the documentation page and release
notes.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-18 11:15:45 +01:00
Johan Hedberg
2428d3c33f tests: bluetooth: addr: Cover bt_addr_le_is_resolved() and copy_resolved()
Add a ZTEST suite for the two internal helpers that translate the
address types found in HCI LE events:

  - bt_addr_le_is_resolved() is true for the two identity types only,
    and false for public, random and the anonymous and unresolved
    sentinels
  - bt_addr_le_copy_resolved() maps an identity type to its base type
    and keeps the address bytes

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-17 16:47:23 -07:00
Aric Radzin
05f23c5abb tests: bluetooth: host: Add LE Directed Advertising Report tests
Add tests for the LE Directed Advertising Report handling, driving the
host through a fake HCI driver on native_sim so that the LE event mask,
the meta event dispatch and the scanner state are exercised, and the
reports are observed where an application sees them, in the scan recv
callback.

The tests cover the event mask bit, the reported advertising type,
properties and target address for an unresolved target, events carrying
several reports, events that are truncated or empty, discarding reports
while no scanner is running, and that an ordinary LE Advertising Report
reports no target address. The fake Controller lets a test choose the LE
features it reports, so the case where the Extended Scanner Filter
Policies are unsupported is covered as well: the event stays masked off
and bt_le_scan_start() returns -ENOTSUP.

The suite is built three times. Whether a directed report for the local
identity is delivered depends on CONFIG_BT_SCAN_WITH_IDENTITY, so the
default configuration checks that such a report is still dropped and the
CONFIG_BT_SCAN_WITH_IDENTITY=y configuration checks that the identity
address type is converted. The CONFIG_BT_EXT_ADV=y configuration covers
the same advertisement arriving in an LE Extended Advertising Report,
whose target address must keep the BT_ADDR_LE_UNRESOLVED type.

This replaces a unit test that stubbed the HCI transport, the mutexes and
the own address setup and called the event handler directly, so it never
exercised the event mask, the meta event entry or the feature check.

The fake Controller also records the scanning filter policy the host asks
for, so the suite asserts that each combination of
BT_LE_SCAN_OPT_EXT_FILTER_POLICY and BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST
maps to the expected one of the four policies. The configurations cover
the legacy and the extended scan parameter commands between them.

34 test cases pass with west twister -p native_sim. Removing the
BT_ADDR_LE_UNRESOLVED handling from either report path makes them fail,
as does swapping the two extended filter policy constants.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
2026-09-17 16:41:20 -07:00
Aric Radzin
e4b42116ae Bluetooth: Host: shell: Add extended scanner filter policy scan option
Add a --ext-filter-policy flag to the bt scan command, so the shell can
start a scanner that uses the extended scanner filter policy. Like
--coded, the flag is always accepted by the parser and the stack rejects
it when the required Kconfig or Controller support is missing.

Print the target address of a directed advertisement on its own line,
marking it as unresolved when the Controller could not resolve it. The
existing report line is left untouched, as it is reproduced verbatim in
the shell documentation.

Tested by building tests/bluetooth/shell on native_sim with and without
CONFIG_BT_SCAN_EXT_FILTER_POLICY. The shell command itself was not
exercised on a target.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
2026-09-17 16:41:20 -07:00
Aric Radzin
3e5ff3a3e3 Bluetooth: Host: Add support for the extended scanner filter policy
The host has always requested one of the basic scanning filter policies,
BT_HCI_LE_SCAN_FP_BASIC_NO_FILTER or BT_HCI_LE_SCAN_FP_BASIC_FILTER, in
both start_le_scan_ext() and start_le_scan_legacy(). The extended
policies BT_HCI_LE_SCAN_FP_EXT_NO_FILTER and BT_HCI_LE_SCAN_FP_EXT_FILTER
were defined in hci_types.h but had no users, so there was no way for an
application to ask the Controller to report directed advertisements whose
target address is a resolvable private address it could not resolve.
Those advertisements were silently discarded by the Controller.

Add BT_LE_SCAN_OPT_EXT_FILTER_POLICY, which selects the extended variant
of whichever policy would otherwise be picked, so that all four policies
are now reachable. The option is gated by the new Kconfig symbol
BT_SCAN_EXT_FILTER_POLICY, which depends on the Controller advertising
support for the feature through BT_CTLR_EXT_SCAN_FP when the Controller
is built in tree.

Not every Link Layer supports the extended scanner filter policies, and a
Controller that does not shall reject the scan parameters with Invalid
HCI Command Parameters. Check LE feature bit 7 in bt_le_scan_start() and
return -ENOTSUP instead, so the application gets an unambiguous error
before any HCI command is sent. Bit 7 had no BT_FEAT_LE_*() accessor, so
add BT_FEAT_LE_EXT_SCAN() next to the other feature test macros.

Consuming the resulting reports is handled separately. Applications that
do not set the new option are unaffected: the option bit is rejected by
valid_le_scan_param() unless the Kconfig symbol is enabled, and the
filter policy sent to the Controller is unchanged otherwise.

Both scan start paths now select the filter policy through one helper,
which gates the filter accept list on BT_FILTER_ACCEPT_LIST. The legacy
path already did so, the extended one did not. This only changes the
extended path when BT_FILTER_ACCEPT_LIST is disabled and the application
sets BT_LE_SCAN_OPT_FILTER_ACCEPT_LIST anyway: it now asks for no
filtering instead of filtering against the accept list. Nothing can add
entries to that list in this configuration, as
bt_le_filter_accept_list_add() is compiled out, so the scanner used to
report nothing at all.

Tested by building tests/bluetooth/init with the new
prj_scan_ext_fp.conf on qemu_cortex_m3 and nrf52840dk/nrf52840, and by
checking that CONFIG_BT_SCAN_EXT_FILTER_POLICY resolves against
CONFIG_BT_CTLR_EXT_SCAN_FP on the latter.

Fixes #114103

Assisted-by: Claude:claude-opus-5
Signed-off-by: Aric Radzin <aric.radzin@gmail.com>
2026-09-17 16:41:20 -07:00
Taha Zarif
a8e8a7b0b8 Bluetooth: Host: add native_sim identity API tests
Add public-API coverage for bt_id_create(), bt_id_reset(), and
bt_id_delete() using a native_sim fake HCI driver. Cover generated,
invalid, and duplicate identity addresses, disabled-privacy IRKs,
identity-pool exhaustion, reset validation, and empty-slot reclamation.

This restores part of the id.c behavior coverage tracked by #117836
without mocking Bluetooth host internals.

Assisted-by: ChatGPT:gpt-5.6-sol
Signed-off-by: Taha Zarif <tahazarif380@gmail.com>
2026-09-16 07:40:31 +02:00
Johan Hedberg
456356419e Bluetooth: tester: Use the automatic Central Address Resolution read
Replace the tester's own read of the peer's Central Address Resolution
characteristic with the host's automatic read: the new completion
callback keeps reporting the result over BTP
(BTP_GAP_EV_PEER_CAR_RECEIVED), and the directed advertising command
checks the stored answer with bt_le_bond_addr_res_support(). This
keeps qualification testing on the same mechanism that applications
are expected to use.

Part of fixing #101955

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-16 07:29:35 +02:00
Måns Ansgariusson
0bde5ccbeb lib: ring_buffer: drop select/depends on RING_BUFFER
The slim ring buffer API is now header-only and always available and the
tree has already migrated from the _claim/_finish API, so the RING_BUFFER
symbol no longer gates any code.
Remove the now-redundant "select RING_BUFFER" and CONFIG_RING_BUFFER=y
entries across drivers, subsystems, samples and tests.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-09-16 07:29:22 +02:00
Måns Ansgariusson
6411514b9f lib: ring_buffer: new header-only implementation
The new implementation provides a full SPSC ring buffer API, reducing the
size of the ring_buffer struct to 12 bytes(on a 32-bit arch), and increases
the throughput of the ring buffers hot path by ~30% (measured on nRF5340).

The default variant drops the claim/finish and item APIs functionality to
reduce the struct size. During the deprecation period, the old APIs are
still reachable through the CONFIG_RING_BUFFER Kconfig option.

Signed-off-by: Måns Ansgariusson <mansgariusson@gmail.com>
2026-09-16 07:29:22 +02:00
Emil Gydesen
ae8212158e tests: Bluetooth: CAP: Unit tests for bt_cap_handover_cancel
Adds unit tests for the function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-16 07:28:23 +02:00
Emil Gydesen
1254bf165a Bluetooth: CAP: add subprocedure callbacks for unicast start and stop
The CAP unicast audio start and stop procedures consist of several
subprocedures, and applications may need to know when each of these have
completed, e.g. to reconfigure the unicast group after the streams have
been codec configured but before they are QoS configured.

Add new callbacks to bt_cap_initiator_cb for each subprocedure of the
unicast audio start and unicast audio stop procedures. The callbacks are
only called if at least one request was sent to a CAP acceptor as part of
the subprocedure, so that subprocedures that are skipped because all
streams are already in the requested state do not trigger a callback. To
support this a new subproc_initiated field has been added to the common
procedure struct, which is reset whenever a new subprocedure is set.

The unit tests have been extended to verify both that the callbacks are
called when the subprocedures are performed, and that they are not called
when the subprocedures are skipped, and the BSIM CAP initiator unicast
test now waits for the new callbacks as part of the start and stop
procedures.

Assisted-by: Copilot:claude-opus-4.5

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-14 08:42:10 -04:00
Taha Zarif
d64e3e04b4 Bluetooth: HCI: clarify pairing error scope
Clarify that HCI status 0x29, Pairing with Unit Key Not Supported,
is valid for BR/EDR connections only. Keep the stable API name while
making the public disconnect documentation and test helper reference
match the Bluetooth specification.

Signed-off-by: Taha Zarif <tahazarif380@gmail.com>
2026-09-12 07:53:37 -04:00
Emil Gydesen
b01df6e903 Bluetooth: ASCS: Refactor ASCS to use sys_wq for cp_rsp
Refactor ASCS to use the system workqueue for the control
point notification. This is to ensure that we always send
the notification, even if we may be out of ATT buffers at
any point, but also ensures that the control point notification
is sent before any ASE notifications triggered by that control
point write.

Some refactoring was done to account for the changes when cleaning
up the ASEs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-12 07:52:56 -04:00
Emil Gydesen
e544561871 tests: Bluetooth: Host: Adv: Add unit tests for SID
Add unit tests to verify that the SID is correctly set
and retrieved for extended and legacy advertising sets.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-11 17:34:52 +02:00
Johan Hedberg
b43799f5f1 tests: bluetooth: init: remove unused ISO conf files
prj_ctlr_broadcaster_iso.conf and prj_ctlr_sync_iso.conf were added by
commit 5a512fbe2f ("Bluetooth: controller: Implements ULL handling for
BIG create command") and commit 9d4d6d06a0 ("Bluetooth: controller:
Implements BIG sync commands in the ULL") without a scenario in the
twister configuration, and nothing has referenced them since.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-11 17:31:52 +02:00
Johan Hedberg
6a0156a0b2 tests: bluetooth: init: drop Controller scenarios bsim tests build and run
test_ctlr_peripheral and test_ctlr_peripheral_priv build the Zephyr
Controller with only the peripheral and broadcaster roles, without and
with privacy. The peripheral image of tests/bsim/bluetooth/host/att/
mtu_update and tests/bsim/bluetooth/ll/edtt/gatt_test_app build the same
combinations on nrf52_bsim and run them in CI. With --integration, CI
builds the two scenarios only on nrf52dk and nrf52840dk, which
nrf52_bsim represents.

The other role-only Controller scenarios stay. The bsim images that
match their enabled roles also enable a role they disable, and the
nrf51dk integration builds of test_ctlr_broadcaster_ext,
test_ctlr_per_adv and test_ctlr_central_iso use the low-latency
Controller configuration that no running test builds. The remaining
scenarios set Controller options no bsim test sets.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-11 17:31:52 +02:00
Johan Hedberg
38ae40c44a tests: bluetooth: init: drop host scenarios other tests build and run
tests/bluetooth/init is a build-only suite of Bluetooth Kconfig
combinations. Five of its host-only scenarios build a configuration that
another CI test already builds and runs on native_sim or qemu_x86, so
they only add build time to every Bluetooth pull request:

  test_0  BT only              tests/bluetooth/bluetooth (identical)
  test_1  peripheral           tests/bluetooth/gatt
  test_2  central              tests/bluetooth/addr
  test_4  peripheral, SMP      tests/bluetooth/l2cap
  test_5  central, SMP         tests/bluetooth/addr

A scenario counts as covered when the running test enables every
Bluetooth option the scenario enables and matches its explicit
assignments, with no Controller in either build. The comparison was
made on the .config files the scenarios generate, not on the prj files.

The default prj.conf scenario stays so the application builds without
CONF_FILE. The remaining scenarios enable options no running host-only
test enables (SC only, debug keys, GATT client, Classic, H:5, coding
selection) or combine the central and peripheral roles.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-11 17:31:52 +02:00
Johan Hedberg
3da48bd2a0 tests: Bluetooth: host_long_adv_recv: Add malformed periodic report test
Enable periodic advertising sync in the test configuration and add a
test which establishes a sync with the fake controller and sends
periodic advertising reports whose length field claims more data than
the event carries. The reports must be dropped without invoking the
receive callback, and the sync must remain usable afterwards.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-11 17:26:33 +02:00
Kai Cheng
28cc9af4c6 tests: bluetooth: classic: sdp: add unregister_sdp shell command and test
Add a shell command to unregister SDP service records by index, and
a pytest test case that verifies the full lifecycle:
1. Register a record and verify it is discoverable
2. Disconnect SDP, unregister, reconnect and verify it is gone
3. Re-register and verify it is discoverable again

Initialize the error status variable before calling shell_strtoul():
unlike strtoul(), shell_strtoul() does not clear the output error code
on the success path, so an uninitialized 'err' left a stale stack value
that made the 'Invalid index' guard trip and silently skipped the
actual unregister call.

Also enable CONFIG_ZTEST_SHELL (so the native_sim image stays in the
shell instead of exiting after an empty ztest run) and route the shell
UART to stdin/stdout via CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT, so the
pytest twister harness can drive the shell over the process pipes.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-09-11 05:22:43 -04:00
Zhijie Zhong
7906aaef02 Bluetooth: SMP: make the CTKD directions configurable
Cross-Transport Key Derivation is unconditional today. With
CONFIG_BT_CLASSIC enabled, Secure Connections pairing over LE always
asks for a derived BR/EDR link key, and the Security Manager over
BR/EDR always accepts deriving the LE LTK from the link key. A device
that must not end up with a bond on the other transport as a side
effect of pairing has no way to say so. Both decisions are device
global: the responder negotiates the key distribution before
bt_conn_set_security() is ever reached, and the fixed channel mask is
built during ACL setup, so Kconfig rather than an API.

Add BT_SMP_DERIVE_LTK and BT_SMP_DERIVE_LK, both default y, so
behaviour is unchanged unless a build opts out.

Without BT_SMP_DERIVE_LK, LINK_DIST expands to 0. That keeps the
negotiated key distribution and what goes on air consistent in both
roles without touching the PDU construction sites, and
ltk_derive_link_key_allowed() refuses the derivation as well.

Without BT_SMP_DERIVE_LTK, smp_br_pairing_allowed() refuses the
procedure and the BR/EDR Security Manager fixed channel is left out of
the L2CAP information response, so a peer does not start one that would
then be rejected. The channel stays registered, so a Pairing Request
that arrives anyway still gets the 0x0E failure.

Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
Assisted-by: Kiro:claude-opus-5
2026-09-09 18:13:56 -04:00
Johan Hedberg
8f2fea1756 tests: bluetooth: host_long_adv_recv: Add status to fabricated responses
The fake controller responds to LE Set Extended Scan Parameters, LE Set
Extended Scan Enable and Reset with Command Complete events that carry
no return parameters, although these commands return a status. The host
has been reading the status from beyond the fabricated event parameters,
which happened to yield success. Add the status return parameter, like
the other status-only commands in the table already have, in preparation
for the host validating command responses against the event length.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-09 10:38:37 -04:00
Johan Hedberg
8148680ac2 Bluetooth: Add HCI packet helpers
Add hci_pkt.h, stateless helpers for framing HCI command packets and
parsing the events that carry command responses, operating on
net_buf_simple buffers and on packet bytes, implemented in
subsys/bluetooth/common and built into every Bluetooth build (the
library is static, so unused helpers cost nothing).

The helpers are independent of the Bluetooth Host and of the HCI driver
interface, and usable in any build type. The intended users are the
Host itself and HCI drivers that need to exchange HCI commands with the
controller over their own transport, typically for vendor-specific
controller initialization. Today such drivers either call Host command
APIs like bt_hci_cmd_send_sync(), which are unavailable in
controller-only builds, or duplicate the command construction with raw
buffers.

The helpers keep the Host's encoding conventions: parameters are built
and decoded with the packed structures of hci_types.h and the
net_buf_simple API, the encoded length is the buffer length, and the
header push derives the parameter length from it. BT_HCI_PKT_CMD_DEFINE()
provides a command buffer with headroom for the packet prefix reserved.
A Command Complete for a command whose return parameters lack the
status they start with is reported as -ENODATA with the rest decoded
and BT_HCI_ERR_UNSPECIFIED as the status, so that callers can fail the
command instead of guessing.

Add a unit test covering framing and parsing, including the Command
Complete event with opcode 0x0000, which carries no return parameters,
the status-less Command Complete and malformed events, building the
implementation file directly so that it stays independent of the
Bluetooth stack, plus the documentation page and release notes entry.

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-09 10:38:37 -04:00
Alex Ciascai
fdfe0b7893 tests: Bluetooth: Tester: add Media Player Name support
Add BTP support for setting the Media Player Name.

Signed-off-by: Alex Ciascai <alexandru.ciascai@nordicsemi.no>
2026-09-08 11:12:35 +02:00
Emil Gydesen
76b7ec2585 tests: Bluetooth: Shell: Audio: Fix Kconfig warnings
Audio.conf was applied to both boards with single and dual
cores, which meant that for the latter the BT_CTLR values
caused build warnings.

This changes it so that a Kconfig with configdefaults
are applied instead for LE Audio builds that enables
BT_LL_SW_SPLIT, thus only affected devices like the
nRF52840.

Slightly modifies some Kconfig options in audio.conf as
well to better match the values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-07 21:07:40 -04:00
Benjamin Cabé
fa10eca091 doc: fix text wrongly rendered as e-mail links
Anything matching the reStructuredText e-mail address pattern is turned
into a mailto: link. Several places used "x@y" in prose where no address
was meant -- video capabilities, RF sensitivities, I2C addresses, board
targets -- and rendered as broken links.

Reword those as plain English or, where the text is an identifier, mark
it up as inline literal.

Fixes #118179

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-09-07 18:04:48 +02:00
Emil Gydesen
1be3dd3348 test: Bluetooth: Audio: Fix bad checks for codec_cfg_get_frame_dur
A check in the tester did not account for
bt_audio_codec_cfg_get_frame_dur returning 0 being valid.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-07 10:31:03 +02:00