Commit graph zephyr/subsys/bluetooth
Author SHA1 Message Date
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
4b61c6b928 Bluetooth: Host: Monitor: fix timestamps of early boot log messages
The monitor log backend registered monitor_ts_get() as the logging
core's timestamp source from its init callback and then passed message
timestamps on to encode_hdr() unconverted, assuming they were already
in the monitor's 1/10th millisecond unit. Backends are however only
initialized once the logging subsystem starts up, which with the
default CONFIG_LOG_PROCESS_THREAD means when the logging thread first
gets to run. Everything logged before that point is stamped by the
logging core's default clock, i.e. the raw cycle counter (or uptime in
milliseconds for cycle counters above 1 MHz), and ends up in btmon in
the wrong unit.

With samples/bluetooth/observer on nrf52dk/nrf52832, where the cycle
counter runs at 32768 Hz, the logging thread does not run before main()
has returned, so the boot banner and all of the Bluetooth
initialization messages are affected and show up 3.2768 times too late:
the banner, logged at 0.3233 s right before bt_enable() sent the New
Index record, carried the timestamp 10595 (its cycle count) and was
displayed at 1.0595 s, 0.74 s after the HCI initialization that
followed it.

Fix this by leaving the logging core's clock alone and converting the
message timestamp through log_output_timestamp_to_us(), which knows
the rate of whatever clock the logging core is using, in
monitor_log_process(). HCI packets keep being stamped by
monitor_ts_get(), which by default derives from the same system timer
as the logging core's clock, so log messages and packets stay on a
common time base. With the fix the banner is displayed at 0.3046 s
against the New Index record at 0.3047 s, and the HW Platform message
falls between the Zephyr Read Version Info command complete event that
produces it and the next command. Also verified on xg24_rb4186c (32768 Hz
cycle counter as well) and on siwx917_rb4338a, whose 180 MHz SysTick makes
the logging core default to uptime in milliseconds: on all three boards
each "Device found" message is stamped within a millisecond of the
advertising report it is logged for. A side effect is that enabling the
monitor no longer changes the timestamp rate seen by all other log
backends, nor overrides a timestamp source registered by the
application.

For the packet timestamps to stay comparable with the converted message
timestamps in every configuration, monitor_ts_get() now follows the
logging core's choice of clock: the real-time clock with
CONFIG_LOG_TIMESTAMP_USE_REALTIME, and the (64-bit) tick counter where a
32-bit cycle counter runs above 1 MHz, since such a counter wraps within
minutes while the messages, stamped with uptime by the logging core, do
not. Verified on siwx917_rb4338a with its 64-bit cycle counter disabled
(CONFIG_CORTEX_M_SYSTICK_64BIT_CYCLE_COUNTER=n, the 180 MHz counter then
wraps every 24 s): a 60 s capture stays monotonic and the messages stay
within a millisecond of their advertising reports throughout. Also
verified with CONFIG_LOG_TIMESTAMP_USE_REALTIME on nrf52dk.

monitor_ts_get() is no longer a log_timestamp_get_t, so it and
encode_hdr() now use a plain uint64_t; the truncation to the 32-bit
wire format stays in encode_hdr().

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 13:44:48 +02:00
Johan Hedberg
709a1b354b Bluetooth: Host: Do not claim to be ready after a failed disable
bt_disable() resets the advertiser pool, stops RX processing, resets
the controller, tears down all connections and purges the command
queue before it asks the HCI driver to close its transport. When that
fails it set BT_DEV_READY again, "to avoid inconsistent stack state",
which is exactly what it produced: a Host that says it is ready on top
of a controller that has just been reset, whose event masks are back at
their defaults, and with its connection bookkeeping gone.

Six in-tree HCI drivers have no close() op at all (h5, psoc6_bless,
sf32lb, siwx91x, stm32wb0 and the generic SPI one), so for them every
bt_disable() took that path and returned -ENOSYS having done all of the
above.

Ask bt_hci_can_close() before anything is torn down, and return
-ENOSYS with Bluetooth left exactly as it was. When a driver that has
the op fails to close, leave the stack not ready: the transport is
still open, so BT_DEV_OPEN is kept, and the only thing left to do is to
call bt_disable() again, which the documentation now says.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 12:05:28 +02:00
Johan Hedberg
f113b791b2 Bluetooth: ATT: Guard the request retry state with its own option
The retry state in struct bt_att_req and the retry path in
bt_att_encrypt_change() are built whenever CONFIG_BT_SMP is enabled,
although only CONFIG_BT_ATT_RETRY_ON_SEC_ERR ever sets req->retrying.
commit c3c7b54ccf ("Bluetooth: Host: Option for disabling of ATT
auto retry") narrowed the security elevation and that assignment to
the new option but left the fields and the retry code behind the
CONFIG_BT_SMP guard, so a CONFIG_BT_SMP=y
CONFIG_BT_ATT_RETRY_ON_SEC_ERR=n build carries a retry path that can
never run: a flag that is always false and three request fields
nothing ever reads.

Guard them with CONFIG_BT_ATT_RETRY_ON_SEC_ERR, and make retrying a
bool since the bit-field shared its storage unit with nothing.

No functional change: bt_att_req_alloc() zeroes the request, so
retrying was already always false with the option disabled. On
samples/bluetooth/central_hr for nrf52840dk/nrf52840 the disabled
build loses 176 bytes of flash and 36 bytes of RAM, the enabled build
16 bytes of flash.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 12:04:48 +02:00
Johan Hedberg
ae51836d59 Bluetooth: ATT: Release the bearer when cancelling a retrying request
With CONFIG_BT_ATT_RETRY_ON_SEC_ERR a request rejected for insufficient
security stays on its bearer, marked retrying, while the host elevates
security: att_error_rsp() has consumed the error response and stopped
the ATT timeout, and bt_att_encrypt_change() resends or fails the
request once the security procedure completes.

Cancelling such a request left it in that state. bt_att_chan_req_cancel()
parked the cancel placeholder on the bearer, and the encryption change
handler only acts on a retrying request, so neither a response nor a
timeout was left to clear the placeholder. The bearer stayed busy until
disconnect and every request queued for it was never sent, for example
the CCC disable write of a bt_gatt_unsubscribe() that had cancelled its
pending enable write.

Release the bearer immediately when the cancelled request is waiting for
a retry and send the next queued request, as att_handle_rsp() does when
a response arrives.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-24 12:04:48 +02:00
Johan Hedberg
a6e17a176e Bluetooth: GATT: Reject CCC writes the characteristic cannot honour
The CCC write handler accepted any value without consulting the
properties of the characteristic the descriptor belongs to, so a client
could enable notifications on an indicate-only characteristic, or
indications on a notify-only one. The subscription was then recorded and
reported by bt_gatt_is_subscribed(), but nothing could ever be sent for
it.

Look up the properties of the nearest preceding characteristic
declaration and reject a configuration the characteristic does not
support with the error the spec reserves for this, Client Characteristic
Configuration Descriptor Improperly Configured. Writes that clear the
configuration are unaffected, since they request nothing.

If the declaration cannot be located or read, a warning is logged and
the write is let through unchanged, so a database that is not built from
the BT_GATT_CHARACTERISTIC macros keeps working as before.

Note that this rejects configurations previously accepted. A server whose
characteristic properties do not match what its clients subscribe to will
now see those subscriptions fail, which is the intended outcome: it makes
a mis-declared database visible instead of silently producing a
subscription that never delivers.

Fixes: #81005

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Assisted-by: Claude:claude-opus-5
Assisted-by: Claude:claude-fable-5
2026-09-24 12:01:19 +02:00
Make Shi
19bac481c6 Bluetooth: classic: l2cap: add QoS configuration option support
l2cap_br_conf_opt_qos() rejects the whole Configuration Request unless
the QoS bit is set both in the peer's extended feature mask and in
L2CAP_EXTENDED_FEAT_MASK, but the local mask never carried that bit, so
a peer including a QoS option could never complete channel
configuration. The handler was also not spec compliant in two ways: a
Guaranteed request was answered with Unacceptable Parameters while the
service type was echoed back unchanged, leaving the peer without a
usable counter-proposal, and an accepted QoS option was not returned in
the positive Configuration Response.

Add CONFIG_BT_L2CAP_QOS to advertise the QoS bit in the local extended
feature mask, and guard the QoS default values with it since only that
path uses them. Only the Best Effort service type has to be supported
(Core 5.4, Vol 3, Part A, 5.3), so counter-propose Best Effort when the
peer asks for the optional Guaranteed type, and add the agreed option
to the Configuration Response when the option is accepted.

Signed-off-by: Make Shi <make.shi@nxp.com>
2026-09-24 09:56:49 +02:00
harshit kudhial
58899593bc bluetooth: audio: fix null pointer deref in media proxy
Currently, synchronous controller functions in media_proxy.c blindly
dereference local player callbacks. This triggers a hard fault if a
local player has not been registered or if it does not implement all
optional callbacks (leaving some function pointers as NULL).

This commit adds validation guards to verify that mprx.local_player.calls
and the individual callback function pointers are not NULL across all
synchronous media control getters and setters. If a callback is
unimplemented, a safe fallback value (e.g., "" for strings, 0U for
integers) is returned instead.

Additionally, it relaxes the check in media_proxy_pl_register to allow
partial implementation of callbacks during player registration, as
allowed by the public contract in media_proxy.h, while still preventing
a completely NULL callback table from being registered.

Signed-off-by: harshit kudhial <harshitkudhial@gmail.com>
2026-09-24 09:54:31 +02:00
Lyle Zhu
4c97486741 bluetooth: classic: obex: improve error handling of client operations
Improve error handling consistency across OBEX client operations by
ensuring proper state recovery on all error paths.

Add `obex_client_restore_active_state()` helper function to restore
client state (`opcode` and `active_client`) on error paths.

Convert early returns to goto failed pattern to ensure cleanup happens
consistently. It is used to ensure internally allocated net buffer is
properly freed on all error paths. And also ensure the changed states
and flags are recovered on all error paths.

The changes ensure that client state is properly restored when
operations fail, preventing state corruption and resource leaks.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-09-24 09:53:22 +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
Arkadiusz Grzelka
b0ab7c9867 Bluetooth: BAP: BSNK: Fix copy of subgroups on encryption change
update_recv_state_encryption() copied sizeof(recv_state->num_subgroups)
bytes of the subgroups, which is a single byte, instead of the whole
array. The receive state written back when the BIG encryption changed
therefore lost the metadata of every subgroup and kept only one byte of
the BIS sync value of the first subgroup.

Copy the whole array, and check in the BAP broadcast assistant BSIM test
that the metadata is still set when the broadcast code is requested.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
2026-09-23 10:45:33 +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
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
Zhijie Zhong
75a69ff046 Bluetooth: SMP: refuse a second outstanding Security Request
Nothing stops smp_send_security_req() from running again while a
Security Request is still unanswered. SMP_FLAG_PAIRING is only set once
the peer replies, and the required_sec_level check in
bt_conn_set_security() only filters a repeat at the same level, so an
escalation or BT_SECURITY_FORCE_PAIR gets through. A second request puts
another PDU on air and re-runs smp_init(), which discards the nonce
generated for the request already in flight.

Claim SMP_FLAG_SEC_REQ with atomic_test_and_set_bit() and return
-EALREADY if it was already set, so two threads calling
bt_conn_set_security() cannot both start the procedure. smp_init()
clears smp->flags, so it now keeps that bit while clearing the rest. A
save and restore would not do: the bit would still read as clear for
the duration of the memset, which is enough for a concurrent caller to
pass the test.

bt_conn_set_security() overwrites required_sec_level and FORCE_PAIR
before calling in, so a rejected second call would lower the level the
in-flight request is held to. Restore both on -EALREADY and document it
in conn.h. Documenting the new return value is a backwards compatible
API change, so the bt_conn group patch version moves to 1.0.1.

Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
Assisted-by: Kiro:claude-opus-5
2026-09-22 17:55:40 +02:00
Zhijie Zhong
20f5f2cea6 Bluetooth: SMP: allow Pairing Request before sending Security Request
smp_send_security_req() sets SMP_FLAG_SEC_REQ and allows
BT_SMP_CMD_PAIRING_REQ only after bt_l2cap_send_pdu() returns.
bt_l2cap_send_pdu() only queues the PDU, and the Pairing Request that
answers it is handled by bt_smp_recv() on the Bluetooth RX thread, not on
the thread that called bt_conn_set_security(). The answer can therefore be
processed before the two atomic_set_bit() calls have run, in which case the
allowed_cmds check in bt_smp_recv() drops it without even sending a Pairing
Failed and the peer waits for a response that never comes.

Publish the state before handing the PDU to L2CAP, and roll it back if the
send fails.

Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
Assisted-by: Kiro:claude-opus-5
2026-09-22 17:55:40 +02:00
Johan Hedberg
87e3b399cb Bluetooth: Host: Log Controller resolved-bit alongside addresses
When the Controller resolves a Resolvable Private Address to an identity
address, it signals this by setting bit 1 of the Address_Type field in
the relevant HCI LE event (e.g. LE Enhanced Connection Complete, LE
Advertising Report, LE Scan Request Received). Previously the default
case of the address-type switch in bt_addr_le_to_str() printed the raw
type byte, so the resolved bit was preserved (as 0x02 or 0x03) in log
output.

With the move to the prefix-based string format bt_addr_le_to_str()
formats such values by their base type, so this information would be
silently dropped from logs. Print a " (resolved)" suffix at the
affected log sites so the indication remains visible in the log message
without leaking the HCI-specific extended type into the public API.

Use the existing bt_addr_le_is_resolved() helper from addr_internal.h
rather than introducing a new helper.

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
Emil Gydesen
2126bb20a1 Bluetooth: BAP: SD: Always call bis_sync_req on NO_PREF
If the remote device is requesting BT_BAP_BIS_SYNC_NO_PREF
then the scan delegator will no longer make a choice on whether this
counts like a new request, as that choice is left to the
higher layers.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-22 10:29:26 +02:00
Lyle Zhu
cb583765de bluetooth: le: audio: add LE connection type checks
There is an issue found that when both Bluetooth Classic and LE audio
are enabled, the LE audio driver may cause an assertion when a Classic
connection notification occurs because it doesn't check the connection
type.

Add `bt_conn_is_type()` checks to Bluetooth audio subsystem callback
functions to ensure they only process LE connections. This prevents
potential issues when BR/EDR or other connection types trigger these
callbacks.

The checks are added early in callback functions before accessing
LE-specific connection fields or performing LE-specific operations.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-09-22 10:27:21 +02:00
Jamie McCrae
1909f76910 kconfig: Correctly have EXPERIMENTAL prompt
Fixes various issues with Kconfigs, including:
  - Using the wrong indentation
  - Not having [EXPERIMENTAL] in the prompt, or not having it at
    the end
  - Wrongly stating the CONFIG_EXPERIMENTAL is needed to enable
    an experimental Kconfig

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-21 16:27:52 -04:00
Jamie McCrae
64d8dbe48b kconfig: Fix formatting, correctly select DEPRECATED and have prompt
Fixes various issues with Kconfigs, including:
  - Redundent `default n` on bools
  - Not select deprecated on supposed deprecated symbols
  - Using the wrong indentation
  - Not having [DEPRECATED] in the prompt, or not having it at the
    end

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-09-21 16:27:52 -04:00
Emil Gydesen
3996bbdab7 Bluetooth: CAP: Fix issue with started sub-cb for sink-only
When starting a set of sink streams only, the callback for the
start subprocedure was not called, because the subproc_initiated
was not set.

When we are starting sink streams only, there is also a race
condition between the CIS connected event and the ASE GATT
notification that was unhandled.

When get_next_proc_param returns NULL, we now check if that is the
case, and if all streams are already in the streaming state,
we can finish the procedure directly, or fail if they are not.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-21 16:27:11 -04: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
Johan Hedberg
7d713288b4 Bluetooth: Kconfig: Deprecate BT_CUSTOM
Mark the custom, non-HCI stack selection as deprecated. The option
dates from the early days of the subsystem, when a product offloaded
the whole Bluetooth Host behind the Zephyr Bluetooth API. Nothing in
the tree selects it, the placeholder for custom drivers under it has
been empty since it was added, and HCI transports are regular device
drivers today. Out-of-tree stacks add their own entry to the choice,
which stays as that extension point; only this entry goes after the
deprecation period.

A build with the option enabled has not compiled since commit
d382fca6ff ("Bluetooth: Controller: Fix HCI command buffer allocation
failure"), which added a static assertion on HCI-only buffer options to
a header the common code includes, and nobody reported it.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-20 19:06:48 +02: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
Cheng Chang
e753f31b64 bluetooth: shell: bip: Fix incorrect application parameter tag ID
Use BT_BIP_APPL_PARAM_TAG_ID_SERVICE_ID instead of
BT_BIP_APPL_PARAM_TAG_ID_STORE_FLAG when setting the service ID
application parameter in cmd_bip_client_start_print() and
cmd_bip_client_start_archive().

The service ID parameter should be used to identify the printing
and archiving services respectively, not the store flag parameter.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2026-09-18 11:18:47 +01:00
David Brown
fae6df2add Bluetooth: Classic: L2CAP: Bound BR/EDR SDU reassembly
bt_l2cap_br_recv_seg() reassembles an SDU from the segments of an
I-frame stream, for channels that supply an alloc_buf callback. It
takes the declared SDU length from a SAR_START segment and never
compares it against the channel's negotiated receive MTU, so the peer
can announce an SDU of up to 65535 bytes on a channel configured for
far less, and reassembly is not bounded by anything the two sides
agreed on. The seg_recv path in bt_l2cap_br_recv_seg_direct() already
rejects such an SDU; apply the same check here so the two paths agree.
Every in-tree profile using this path sets rx.mtu at or above the size
of the buffers its alloc_buf callback hands out, so none of them needs
to receive an SDU larger than the MTU it advertised.

The running total the function compares against that declared length is
also wrong. Segments are appended with net_buf_append_bytes(), which
chains a new fragment whenever the current buffer fills up, so once
reassembly spills past the head buffer the data lands in the fragment
chain and the head buffer's len stops growing. Every test written in
terms of _sdu->len then measures the head buffer alone rather than how
much has actually arrived: the overflow guard stops rejecting oversized
input, and the SAR_END completeness check rejects a complete SDU as
short. Use net_buf_frags_len() for all three reads of the accumulated
length, the debug log included, so they describe the whole chain.

Assisted-By: Claude:opus-5
Signed-off-by: David Brown <david.brown@linaro.org>
2026-09-18 11:17:35 +01:00
David Brown
412767b311 Bluetooth: Classic: GOEP: Do not wait for L2CAP RX buffers
The buffer callback of a GOEP v2 L2CAP channel allocates with
K_FOREVER. L2CAP calls it from the Bluetooth RX workqueue, both for a
new SDU and for every further fragment appended to it, and it is that
same workqueue that releases the buffers once the SDU has been handed
to OBEX. The pool is shared by all GOEP v2 channels and one SDU can
take several buffers, so once it runs dry the wait can never be
satisfied and it stops all HCI receive processing instead.

The callback also has no timeout parameter, so a caller that asks for
a non-blocking append has no way to say so; the callback has to
decide, and here the only workable answer is not to wait.

Allocate without waiting. L2CAP already turns a failed allocation on
this channel into -ENOBUFS and reports the channel as locally busy to
the peer, which is the back pressure the peer expects, unlike a
blocked host.

Compile-tested only; there is no GOEP v2 test coverage in the tree.

Assisted-By: Claude:opus-5
Signed-off-by: David Brown <david.brown@linaro.org>
2026-09-18 11:17:35 +01:00
tallplay lin
b0be80a30d Bluetooth: Host: shell: fix adv_set_opt bitmap indexing
The shell declared one option bitmap for all advertising sets instead
of one per set. Creating a second advertising set then wrote its
options past the end of that bitmap, corrupting adjacent state such
as adv_sets[0]: after "bt adv-create" twice, "bt adv-info" no longer
showed the first advertiser correctly.

Declare the set dimension inside ATOMIC_DEFINE so every advertising
set owns a complete option bitmap, and add a compile-time check that
the array size matches CONFIG_BT_EXT_ADV_MAX_ADV_SET.

Signed-off-by: tallplay lin <tlin@atmosic.com>
2026-09-18 11:16:57 +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
d3157a6d6d Bluetooth: Host: Fix bt_addr_le_is_resolved() matching non-identity types
bt_addr_le_is_resolved() tests bit 1 of the HCI address type. That bit
is set for the two Controller-resolved identity types (0x02 and 0x03),
but also for the sentinels the LE Extended Advertising Report event
uses for an anonymous advertiser (0xff) and for a directed address the
Controller could not resolve (0xfe).

le_adv_recv() checks for a resolved address before it checks for an
anonymous advertiser, so since commit baad0c300f ("BluetootH: Host:
add helper functions for resolved addresses") replaced the explicit
identity-type comparison with the helper, the anonymous branch has been
unreachable: reports from anonymous advertisers were passed through
bt_addr_le_copy_resolved() and delivered to scan callbacks with an
address of type 0xfd instead of BT_ADDR_LE_ANY, contrary to the
bt_le_scan_recv_info documentation.

Compare against the two identity types explicitly and document that in
the helper's contract.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-17 16:47:23 -07:00
Zhijie Zhong
8b38527130 bluetooth: host: gatt: silently cancel CCC write on unsubscribe
Subscribing and unsubscribing to a notification are asynchronous,
callback-driven procedures. Each is a CCC write, i.e. one ATT request,
and a single bt_gatt_subscribe_params backs one such write at a time
(one value, one list node, one flags word). bt_gatt_subscribe() sends
the enable CCC write to the peer as an ATT transaction with the
30-second ATT timeout running; an unsubscribe reuses the same params
for the disable write.

With the subscribe CCC write still in flight (WRITE_PENDING set),
bt_gatt_unsubscribe() called bt_gatt_cancel() to abort it.
bt_gatt_cancel() runs the aborted request's completion synchronously,
so gatt_write_ccc_rsp() ran with BT_ATT_ERR_UNLIKELY: the subscribe
callback saw a spurious failure and the subscription was torn down
(NULL notification, node removed). bt_gatt_unsubscribe() then queued
the disable write on the same params, whose completion delivered the
subscribe and NULL callbacks a second time. One unsubscribe thus
produced a spurious subscribe failure and duplicate completions, with
the params and its list node reused while the first completion was
still unwinding.

Cancel the in-flight write silently instead. Factor the body of
bt_gatt_cancel() into a helper taking whether to run the completion,
and call it from bt_gatt_unsubscribe() without the completion, clearing
WRITE_PENDING in its place. The superseded write's response is then
ignored, the disable write is queued behind it exactly as before, and
the application sees one NULL notification, as for any other
unsubscribe. No new flag, and no locking beyond what bt_gatt_cancel()
already takes.

Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
2026-09-17 16:42:54 -07:00
Zhijie Zhong
c8e360006a bluetooth: host: att: fix NULL channel request dereference
bt_att_find_req_by_user_data() walks every ATT channel on the
connection and dereferences chan->req unconditionally. A channel with
no request in flight has chan->req set to NULL, so the lookup faults as
soon as it visits such a channel. With EATT connected this is easy to
hit: the pending request sits on one channel while the others are idle.

The lookup is already reachable on this path today. bt_gatt_unsubscribe(),
called while a subscribe CCC write is still pending, uses bt_gatt_cancel()
to find that in-flight request; the traversal then dereferences an idle
channel's NULL req and crashes before any callback runs.

Guard the dereference with an explicit chan->req != NULL check. Also
reject a NULL user_data up front, which would otherwise match the first
request that happens to carry one. These are pre-existing defects with
no behaviour change, so they can be applied on their own.

Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Zhijie Zhong <zhongzhijie1@xiaomi.com>
2026-09-17 16:42:54 -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
ef3630ea64 Bluetooth: Controller: Mark unresolved TargetA in legacy ext adv reports
le_ext_adv_legacy_report() reports the target address of a directed
advertisement with the address type taken verbatim from the PDU, without
looking at node_rx->rx_ftr.direct. A directed advertisement that was
accepted only because the scanner uses an extended filter policy, and
whose target address the Controller was therefore unable to resolve, is
reported as an ordinary random address. The host cannot tell it apart
from a directed advertisement addressed to the local identity.

Report BT_ADDR_LE_UNRESOLVED for that case, as le_ext_adv_report()
already does through ext_adv_direct_addr_type(). This is the path taken
for legacy advertising PDUs received while scanning with the extended
scanning commands, so without it the extended scanner filter policies
only produce usable reports when the host uses the legacy scanning
commands.

The rx_ftr.direct field only exists when CONFIG_BT_CTLR_EXT_SCAN_FP is
enabled, so the new branch is compiled out otherwise and the reported
address type is unchanged there.

Tested by building tests/bluetooth/init on nrf52840dk/nrf52840 with
CONFIG_BT_CTLR_EXT_SCAN_FP both enabled and disabled. Not run on
hardware.

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
b98806c137 Bluetooth: Host: Add support for the LE Directed Advertising Report
The host had no support for the LE Directed Advertising Report event.
Its event code, structures and event mask bit were defined in
hci_types.h, but le_set_event_mask() never enabled the event and
meta_events[] had no handler for it, so a Controller was neither allowed
to generate it nor able to get it processed.

That event is how a Controller reports a directed advertisement whose
target address is a resolvable private address it was unable to resolve,
while scanning with one of the extended scanner filter policies. Without
it such an advertisement is invisible to the application, even though it
is the case the extended filter policies exist to surface.

Enable the event mask bit and add bt_hci_le_direct_adv_report(), which
turns each report into a bt_le_scan_recv_info and passes it to the
existing scan callbacks. The event mask bit is only set when the
Controller supports the Extended Scanner Filter Policies, as a Controller
may reject Set Event Mask with a bit it does not know.

Report the target address through the new bt_le_scan_recv_info.direct_addr
member. The extended advertising report carries the same address and it
was being discarded, so populate it from there as well. This gives one
representation for both scanning paths, which matters because the same
on-air advertisement is reported as an LE Directed Advertising Report
with the legacy scanning commands and as an LE Extended Advertising
Report with the extended ones. The address type is BT_ADDR_LE_UNRESOLVED
when the Controller could not resolve the target address. The legacy
event only reports an unresolved target address, and Core 6.3 Vol 4 Part
E 7.7.65.11 defines only BT_ADDR_LE_RANDOM for its Direct_Address_Type,
so normalise that address type to give the application one representation
across both report types.

le_adv_recv() drops directed reports when scanning explicitly without
privacy and without CONFIG_BT_SCAN_WITH_IDENTITY, to avoid reports for
the local identity while scanning with a non-resolvable private address.
An unresolved target address is by construction not the local identity,
so exclude that case from the rule. Without this the feature would be a
no-op in the default configuration. This cannot affect existing users:
per the specification a Controller only reports an unresolved target
address while using a filter policy that the host requests exclusively
for BT_LE_SCAN_OPT_EXT_FILTER_POLICY.

Tested by building tests/bluetooth/init with
CONFIG_BT_SCAN_EXT_FILTER_POLICY=y on qemu_cortex_m3 and
nrf52840dk/nrf52840, with CONFIG_BT_EXT_ADV both enabled and disabled,
and by confirming the existing configurations that set
CONFIG_BT_CTLR_EXT_SCAN_FP=n still build with the new symbol unavailable.

Fixes #114236

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
Keith Packard
9e92a8eb21 subsys/bluetooth: Cast OTS offset from off_t to long when logging
Log formats were using %ld, assuming that off_t was equivalent to
long. Place an explicit cast in the code so that when off_t is wider, the
value is still displayed correctly.

Signed-off-by: Keith Packard <keithp@keithp.com>
2026-09-17 12:12:05 +01:00
Johan Hedberg
8b4af37731 Bluetooth: Classic: AVRCP: Order static functions before their callers
cleanup_fragmentation_context() was forward-declared although nothing
forces its definition below avrcp_disconnected(): move it above its
first caller and drop the declaration. No functional change.

Assisted-by: Claude:claude-fable-5-1
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-16 21:34:58 +01:00
Vinayak Kariappa Chettimada
c91fb6ead2 Bluetooth: Controller: Fix flash sync unsigned underflow
Fix flash sync implementation unsigned underflow that caused
timeout with Bluetooth and settings enabled.

Fixed by using the Controller's EVENT_OVERHEAD_START_US CPU
overhead timing as the minimum interval between flash
operation in co-operation with Bluetooth tickers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2026-09-16 16:26:01 +01:00
Emil Gydesen
bcb44b68f8 Bluetooth: CAP: Move subproc_initiated assignment under lock
Modifications to `active_proc` shall be done while it is
locked.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-16 16:20:40 +01:00
Kai Cheng
e81355223f bluetooth: classic: shell: include the Report ID in Boot Protocol reports
The mouse report the hid_device shell sends on the Interrupt channel left
the Report ID out in Boot Protocol Mode, while the GET_REPORT response of
the same shell always included it. HID spec v1.1.2 Section 3.3.2 puts both
under one rule: every report a Device sends in Boot Protocol Mode, either
asynchronously on the Interrupt channel or in answer to GET_REPORT, has to
include the Report ID. A Host that follows this strips the first byte, so
what it read as the button bits was the Report ID and the whole report was
off by one.

Send it in both modes, which leaves the wheel byte as the only difference
between them and gives the two paths the same shape. The value does not
change: Boot Protocol Mode fixes the mouse Report ID to 2, and the
descriptor this shell registers declares 2 as well.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-09-16 09:23:53 +02:00
Emil Gydesen
503e06521b Bluetooth: BAP: SD: Re-request broadcast code after bad code
When a broadcast sink fails to decrypt a BIG due to a bad broadcast
code, the BASS receive state is left at Bad_Code. If the broadcast
assistant subsequently sends a Modify Source operation requesting BIS
sync again before providing a new broadcast code, the scan delegator
did not notify Broadcast_Code_Required again, leaving the assistant
with no indication that a new code is expected.

Reset the receive state back to Broadcast_Code_Required as soon as the
Modify Source operation requesting a BIS sync is received, matching
the BASS requirement to request a Broadcast_Code whenever the server
does not have a key to decrypt a BIS it is trying to sync to. This is
done directly in the scan delegator when the request is received,
rather than depending on the application calling
bt_bap_broadcast_sink_sync() again.

Extend the bsim BAP broadcast sink/assistant tests to cover the
retry-after-bad-code scenario: the assistant requests BIS sync again
before sending the correct code, and the test verifies the receive
state changes back to Broadcast_Code_Required instead of staying at
Bad_Code.

Tested by running the extended
bap_broadcast_audio_assistant_incorrect_code bsim test, which fails
without the fix (times out waiting for the repeated Broadcast_Code
notification) and passes with it. Also ran
bap_broadcast_audio_assistant, bap_broadcast_audio_encrypted and
bap_broadcast_audio_encrypted_incorrect_code to confirm no
regressions. Not built or tested on hardware.

Fixes #111790

Assisted-by: Copilot:claude-opus-5
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-16 07:39:34 +02:00
Emil Gydesen
81e9d94d00 Bluetooth: ISO: Add send_failed callback
Add callback to handle cases where an accepted send fails due to a
disconnect or a call to bt_disable.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-09-16 07:31:55 +02:00
Johan Hedberg
7e9d9d41ee Bluetooth: Host: Reject RPA-directed advertising the peer cannot receive
A directed advertisement with an RPA target address can only be
received by a peer that supports address resolution: an initiator
responds only to a directed advertisement that carries its own device
address (Core 6.3, Vol 6, Part B, 4.4.4.1), and an RPA target address
is only recognized as its own if the initiator resolves it with its
local IRK (Vol 6, Part B, 4.7 and 6.4). Starting such advertising
towards a peer known not to support address resolution can therefore
never lead to a connection.

Fail bt_le_adv_start(), bt_le_ext_adv_create() and
bt_le_ext_adv_update_param() with -ENOTSUP when
BT_LE_ADV_OPT_DIR_ADDR_RPA is used towards a bonded peer whose stored
Central Address Resolution value says address resolution is not
supported. An unknown value keeps the previous behaviour, as
recommended by Core 6.3, Vol 3, Part C, 12.4. This also aligns with
GAP, which allows a privacy-enabled Peripheral to use directed
connectable mode only when the peer supports address resolution in
the Controller (Vol 3, Part C, 10.7.1.1).

Fixes: #101955

Assisted-by: Claude:claude-fable-5
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-09-16 07:29:35 +02:00
Johan Hedberg
aa0bad8767 Bluetooth: GATT: Track the peer's Central Address Resolution support
The GAP section of the Core specification recommends that a Peripheral
checks whether its peer supports address resolution, by reading the
Central Address Resolution characteristic, before using directed
advertising with an RPA target address. The host has so far left both
the read and the conclusion entirely to the application.

Read the characteristic once when a bond is created, following the
same pattern as the other automatic GATT client operations, and store
the result in the bond. An absent characteristic means address
resolution is not supported (Core 6.3, Vol 3, Part C, 12.4). The read
is also triggered on an encrypted reconnection when the answer is
missing, which covers bonds created before this option existed. Errors
other than Attribute Not Found leave the answer unknown, to be read
again on the next connection.

The stored answer is available to the application through the new
bt_le_bond_addr_res_support(), so that it can take the peer's ability
into account when choosing how to advertise. The completion of the
read is reported through a new bt_conn_auth_info_cb callback, so that
the application knows when the answer is available.

The stored keys format is unchanged: the answer lives in two
previously unused bits of the flags field, so existing bonds load as
having an unknown value.

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
Lyle Zhu
54f07618dc bluetooth: classic: sdp: remove K_FOREVER from service buf allocation
Add a new function `sdp_svc_create_pdu()` that uses `K_NO_WAIT`
timeout to allocate the net buffer for SDP service role.

Add response buffer management to struct bt_sdp with `rsp_buf` field
to hold pre-allocated response buffers.

Call the function `sdp_svc_create_pdu()` to allocate response buffer
and save to `sdp->rsp_buf` in the function `bt_sdp_recv()`. And use
function `net_buf_take()` to take the pre-allocated buffer in the
functions `sdp_svc_search_req()`, `sdp_svc_att_req()`,
`sdp_svc_search_att_req()`, and `send_err_rsp()`.

Add receive buffer tracking with `recv_pending` and `recv_state` fields
to save incoming requests when response buffers are unavailable.

Implement `sdp_svc_work_handler()` to retry processing pending SDP
requests when net buffers become available.

Update `sdp_destroy()` callback to trigger retry of SDP service
processing by submitting sdp_svc_worker when buffers are freed.

Add cleanup of response and pending buffers in `bt_sdp_disconnected()`
to prevent memory leaks.

The changes prevent the `bt_workq` from blocking when there are no
available net buffers in `sdp_pool` for SDP service role.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-09-16 05:53:25 +02:00
Lyle Zhu
c43dcb2656 bluetooth: classic: sdp: remove K_FOREVER from client buf allocation
Add a new function sdp_client_create_pdu() that uses `K_NO_WAIT`
timeout to allocate the net buffer for SDP Client role.

Add error handling for buffer allocation failures in service search,
attribute search, and service attribute search functions.

Introduce a flag `SDP_CLIENT_FLAG_WAIT_FOR_TX_BUF` to track when client
is waiting for TX buffer availability.

Add retry logic in `sdp_client_work_handler()` to resume SDP record
discovery if the flag `SDP_CLIENT_FLAG_WAIT_FOR_TX_BUF` of the client
has been set.

Implement sdp_destroy() callback for the net pool `sdp_pool` to
trigger retry of SDP discovery when any net buffers become available.

Also, clear client flags during request cleanup.

The changes prevent the `bt_workq` from blocking when there are no
available net buffers in `sdp_pool`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-09-16 05:53:25 +02:00