Commit graph zephyr/subsys/bluetooth
Author SHA1 Message Date
Håvard Reierstad
41e3b91fcb Bluetooth: HCI: Allow discarding of ext adv reports
Implements a method for discarding fragmented extended advertising. In
order to acheive this, we need to consider past and future fragments
of the advertising report we discard.

The future fragments are on its way from the controller, and will result
in either a complete- or incomplete event. These are handled by tracking
the adv SID and address until the controller sends either a complete or
incomplete event. Once an advertising report is marked as discarded,
consecutive fragments will be silently discarded.

The past fragments are either already in the reassembler (in scan.c),
or on their way through the rx_queue. To handle these, and allow the
reassembler to recover from a in-progress reassembly which is discarded,
we add a work item which is rescheduled when each consecutive fragment
is received. The timeout is configurable through the new Kconfig option
`CONFIG_BT_EXT_ADV_REASSEMBLY_TIMEOUT`. On timeout, the reassembler will
change its state to discard incoming fragments from the same advertiser.
The reassembler will start assembling new fragments if it recognises a
new advertiser, or if a final fragment (either marked as complete
or incomplete) from the advertiser it is currently tracking is received.

This functionality needs to be added at a HCI driver level by using the
new `hci_ext_adv_report_process` function. It is added the the
IPC HCI driver to fix zephyrproject-rtos/zephyr#50786

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2026-05-06 16:29:15 +01:00
Emil Gydesen
7cb64ce38b Bluetooth: TBS: Fix out-of-bounds read in bt_tbs_valid_uri
The for loop could have read uri[uri_len] due to the i + 1.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-06 09:57:31 +01:00
Christoph Busold
dad5096f85 drivers: entropy: Add support for architectural entropy drivers
Add new inline function entropy_get_default_device which returns
the "zephyr,entropy" device or the architectural entropy device,
if the former is not set, and use that in all places to query the
entropy device.

This allows using architectural drivers which do not have a DT
node.

Signed-off-by: Christoph Busold <cbusold@qti.qualcomm.com>
2026-05-06 07:05:12 +02:00
Emil Gydesen
382e2efd33 Bluetooth: BAP: Shell: rm unused right_ring_buf_fail_cnt
The right_ring_buf_fail_cnt field was never read.
Remove the dead field.

Assisted-by: Claude:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-05 16:03:42 +01:00
Emil Gydesen
8fc67e6e31 Bluetooth: Audio: add ARG_UNUSED to unused function parameters
Apply ARG_UNUSED() to unused function arguments as per the Zephyr
coding guidelines

A few functions were modified to remove unused parameters
or to actually use the parameters.

Assisted-by: GitHub Copilot

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-04 22:08:33 +02:00
Emil Gydesen
44c50815e6 Bluetooth: MCC: Shell remove unused MCC track segments cache
Remove unused field

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-04 22:07:39 +02:00
Emil Gydesen
f1d872ebf4 Bluetooth: BAP: BA: remove unused scanning field
The scanning field was set to false in broadcast_assistant_reset() but
never read anywhere. The scanning state is tracked via the
BAP_BA_FLAG_SCANNING atomic bit; the bool field is leftover dead code.

Assisted-by: Claude:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-04 22:07:31 +02:00
Bhavin Umatiya
29cbe1d5b8 Bluetooth: Controller: Introduce timer tick conversion define
Introduce HAL_EVENT_TIMER_US_TO_TICKS macro to explicitly map the 1 MHz
hardware timer resolution to the radio configuration, preventing unintended
unit mixing between microseconds and hardware ticks.

Fixes #105085

Signed-off-by: Bhavin Umatiya <umatiyabhavin@gmail.com>
2026-05-04 21:55:03 +02:00
Emil Gydesen
2b7eaa153b Bluetooth: BAP: remove unused broadcast_sink from bt_bap_ep
The broadcast_sink pointer was written in three places (set and
cleared) in bap_broadcast_sink.c but never read or dereferenced
anywhere in the codebase. Remove the field, its three write sites,
and the now-unneeded forward declaration of struct bt_bap_broadcast_sink
in bap_endpoint.h.

Assisted-by: Claude:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-04 14:59:29 +02:00
Alperen Sener
246050f7f9 bluetooth: host: Add missing pending IRK update call for ext adv start
Adds IRK update call to internal bt_le_adv_start_ext. And rename it to
adv_start_ext to prevent confusion with public functions.

There are two paths to start ext advertising:
- bt_le_adv_start can start extended advertising if enabled by calling
internal bt_le_adv_start_ext else it starts legacy advertisements.
- bt_le_ext_adv_start specifically starts extended advertisements.

This commit misses the first path for ext advertisement:
6d137ae015

Signed-off-by: Alperen Sener <alperen.sener@nordicsemi.no>
2026-05-01 16:22:32 -05:00
Lyle Zhu
c67b59f891 bluetooth: classic: rfcomm: fix race condition in session disconnect
Fix a race condition in RFCOMM session disconnection when both local
and peer devices initiate disconnection simultaneously.

Add state check in `rfcomm_session_disconnected()` to only transition
to `DISCONNECTED` state if the session is not already in
`DISCONNECTING` state. This prevents the race condition where both
sides set the session to disconnected, causing the disconnection
process to not complete properly and leaving the L2CAP connection
unreleased.

Without this check, subsequent RFCOMM channel connection requests
would fail due to the invalid session state (the expected state is
`IDLE`, while the actual state is `DISCONNECTED`).

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-04-30 14:03:39 -04:00
Emil Gydesen
e60165f45b Bluetooth: TBS: Add enum, move and rename TECHNOLOGY
The technology values defined in tbs.h are actually defined
in assigned numbers under the HFP. They have been moved to
the assigned_numbers.h file, and name to match the placement
in Assigned Numbers. They have been defined in an enum instead
of multiple #define's, to more easily refer to them.

The callback for reading technology was likewise updated to use
the new enum.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-30 13:59:23 -04:00
Kai Cheng
1cb1d41335 Bluetooth: SPP: Add SPP test command set
Add SPP test shell commands, support client and server features.
include register, connect, send and disconnect.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-30 13:58:42 -04:00
Kai Cheng
6326394734 Bluetooh: RFCOMM: remove rfcomm test shell
remove rfcomm test shell, and instead
with spp test shell

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-30 13:58:42 -04:00
Kai Cheng
5b11f77fe3 Bluetooth: Classic: add sniff subrating support
Add bt_conn_br_set_sniff_subrating() API to configure sniff subrating
parameters for BR/EDR connections. Sniff subrating allows further
power savings by reducing the number of sniff anchor points the
device needs to listen on.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-30 07:50:34 +02:00
Kai Cheng
0cb96d2b2e Bluetooth: Classic: group BR/EDR callbacks into struct bt_conn_br_cb
Introduce struct bt_conn_br_cb to group all BR/EDR specific connection
callbacks (role_changed, mode_changed) into a dedicated sub-struct
within bt_conn_cb. This replaces the previously scattered callbacks
that were individually guarded by CONFIG_BT_CLASSIC or
CONFIG_BT_POWER_MODE_CONTROL.

Application code now uses the .br. accessor:
  .br.role_changed = my_role_changed_cb,
  .br.mode_changed = my_mode_changed_cb,

The br_ prefix is dropped from callback names since the struct
hierarchy already conveys the BR/EDR scope, aligning with the
pattern suggested during review.

Also fix bt_conn_notify_mode_changed() to use
BT_CONN_CB_DYNAMIC_FOREACH instead of SYS_SLIST_FOR_EACH_CONTAINER
for consistency with other callback notification functions.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-29 16:33:25 -04:00
Gaetan Perrot
65585a47fc bluetooth: audio: vcp: Fix possible NULL pointer dereference
The VOCS discover callback may call vcp_vol_ctlr_discover_complete()
with a NULL vol_ctlr when lookup_vcp_by_vocs() fails.

This leads to a potential NULL pointer dereference as
vcp_vol_ctlr_discover_complete() unconditionally accesses
vol_ctlr->flags.

Fix this by returning early when vol_ctlr is NULL.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-04-29 09:59:30 +02:00
Kyra Lengfeld
9f245e68f0 bluetooth: host: enable extended advertising to use spec range of intervals
Core spec defines the range of adv intervals for extended advertising to
0x0020 to 0xFFFFFF, but the code currently only allows up to 0x4000.
This change enables the full range of intervals for extended advertising

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2026-04-28 22:07:30 +02:00
Lyle Zhu
cd8c5ccd76 bluetooth: host: goep: Set MTU to configured maximum large
Remove the logic that silently clamps the MTU to valid ranges and
instead return an error if the configured MTU is below the minimum
required size.

The MTU is now always set to the maximum value that the configuration
can support, rather than conditionally using a default only when
set to 0.

Change log level from WRN to ERR for the minimum MTU check since
this now represents a fatal configuration error.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-04-28 15:23:28 +02:00
Emil Gydesen
531837b499 Bluetooth: ISO: Improve validate_send for conn state
ISO connections basically have 2 connection states:
1 for the `bt_iso_chan`, and one for the underlying
`bt_conn`. Due to how hci_disconn_complete_prio works,
these may be out of sync while disconnecting, and
bt_iso_chan_send could return 0 after we have received
a disconnect event from the controller. In this case
the number of pending SDUs in the host for the ISO
channel could be non-0, which could cause issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-28 15:21:19 +02:00
Maximilian Zimmermann
451cfb77b1 Bluetooth: CSIP: make size,lock and rank characteristic optional
Make the Coordinated Set Size, Set Member Lock and Set Member Rank
characteristic optional by adding three new Kconfig options
BT_CSIP_SET_MEMBER_SIZE_SUPPORT, BT_CSIP_SET_MEMBER_LOCK_SUPPORT and
BT_CSIP_SET_MEMBER_RANK_SUPPORT. Also updates the existing examples
and tests to compile correctly.

Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
2026-04-28 11:19:29 +02:00
Emil Gydesen
0601cc8c42 Bluetooth: CAP: Shell: Reorder code in cap_handover
Reorder some of the large and complex shell command
functions, to make each function simpler to follow.
This also makes the code pass the Sonarcloud complexity
rule.

This also contain a few other various fixes and updates.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-28 11:18:50 +02:00
Emil Gydesen
2945c0be98 Bluetooth: CAP: Shell: Share args between modules
Instead of defining the same arguments in all 3 CAP files,
we declare them in audio.h and initiate them in either
the initiator or commander, depending on their use.

The reason for this change, is that the CAP Handover API
require several of the parameter to be globally/statically
allocated, and cannot just rely on stack allocated parameters.
By doing this, we can use the same argument among the
CAP shell modules, while keeping the memory usage down.
This has the additional postive effect that we do not allocate
some of these arrays, which can be quite larger, on the stack.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-28 11:18:50 +02:00
Emil Gydesen
700d3d5d49 Bluetooth: CAP: Shell: Implement cmd_cap_handover_broadcast_to_unicast
Implement the shell command for handing over broadcast to
unicast. The command supports various configurations.

It is currently limited to cases with
- 1 connection and multiple streams
- Multiple connections and 1 stream
- Equal amount of streams and connections

Cases with e.g. 3 connections and 2 streams,
or vice versa, are not support given the complexity
of these cases.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-28 11:18:50 +02:00
Emil Gydesen
531ed72256 Bluetooth: CAP: Shell: Add handover u->b shell command
Add shell command for unicast to broadcast for the CAP handover
procedures.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-28 11:18:50 +02:00
Emil Gydesen
78d9b474e5 Bluetooth: BAP: BA: Remove start and end handles
The two cached handles did not provide anything useful
and can be removed, thus freeing up some memory.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:28:17 +02:00
Emil Gydesen
0f0fff91b9 Bluetooth: BAP: BA: Minor fix for disc_params.uuid
Instead of allocating a generic uuid and copying the BASS UUID
to it for each discovery, we can just use declare and use it
as a constant as it won't change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:27:22 +02:00
Lyle Zhu
dfac5224ab bluetooth: classic: sdp: Fix buffer length check in attribute parsing
Fix insufficient buffer length validation in bt_sdp_parse_attribute().
The original check only verified space for the type byte and attribute
ID, but did not account for the type variable itself that is read from
the buffer immediately after the check.

This could lead to a buffer over-read if the buffer contains exactly
sizeof(uint8_t) + sizeof(attr->id) bytes but not enough for the
additional type field.

Add sizeof(type) to the length check to ensure all required data is
present before parsing.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-04-27 17:25:52 +02:00
Emil Gydesen
028634623f Bluetooth: Audio: Add checks for UTF when getting broadcast name
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:22:20 +02:00
Emil Gydesen
a259ad8311 Bluetooth: Audio: Add checks for UTF when setting broadcast name
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:22:20 +02:00
Emil Gydesen
6548ed48af Bluetooth: CCP: Client: Add support for get bearer uci
Add support for getting the remote bearer UCI.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:21:17 +02:00
Emil Gydesen
7097c3ee0d Bluetooth: Audio: replace implicit integer-to-boolean checks
MISRA-C requires essentially boolean type in control flow.
Convert all if/while conditions using err or ret
as implicit booleans to explicit comparisons:

- if (err)  -> if (err != 0)
- Same rules applied to while statements and ret variable

Assisted-by: GitHub Copilot

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 14:22:32 +02:00
Lyle Zhu
4de2676eb7 bluetooth: classic: avrcp: Move initialization to callback registration
Move the AVRCP cover art initialization from bt_avrcp_init() to
bt_avrcp_tg_register_cb(). This ensures that cover art is initialized
only when the target callback is registered, aligning with the
initialization flow of other AVRCP target features.

Additionally, add a check in bt_avrcp_tg_cover_art_init() to prevent
re-initialization if the PSM is already set, returning success if
cover art is already initialized.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-04-27 14:15:45 +02:00
Emil Gydesen
01ad11b5f7 Bluetooth: BAP: Require security before discovery
The bt_bap_unicast_client_discover and
bt_bap_broadcast_assistant_discover functions now require security
to have already been done before any operations are done.

The BAP require a specific security level and properties,
and checking the security earlier will prevent any unncessary
operations if the expected security requirement cannot be met.

Additionally, ensuring that there is an appropriate pairing with
the provided connection, ensures that we can rely on CONFIG_BT_MAX_PAIR
for soem arrays in the future.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-25 08:21:49 +02:00
Emil Gydesen
a0a513667b Bluetooth: BAP/CAP: Make qos param const
Make the qos parameter of the BAP can CAP APIs const,
as they are now only used as one-time parameters, and not stored.
This also means that any uses of this can place the qos
parameter in the stack, rather than static memory.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-24 12:58:57 +02:00
Emil Gydesen
be842dfd31 Bluetooth: BAP: Make bt_bap_stream.qos const
The pointer represent the qos configuration
for a stream based on the ASE or broadcast configuration,
and serves as a read-only value. Changing it to `const` makes
this more clear.

Some minor changes were done to existing code to help
support this change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-24 12:58:57 +02:00
Emil Gydesen
52f25c903f Bluetooth: BAP: Fix issues with qos pointers
In some cases the stream->qos pointer pointed to the
qos argument, and sometimes it pointed to the ep->qos.

Now all qos arguments are copied to ep->qos, and
stream->qos always points to stream->ep.qos.

Some modules had some refactoring done to properly store
the QoS. The unicast client had some additional checks
done or redone, and some now-unused code removed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-24 12:58:57 +02:00
Gaetan Perrot
1cb9840462 bluetooth: shell: bt: unify bt_conn_get_info error handling
Standardize error handling for bt_conn_get_info()
across the Bluetooth shell.

- Use a local 'err' variable instead of inline calls
- Check for (err != 0) consistently
- Include error code in all error messages
- Improve log messages for better debugging context

This ensures consistent behavior and more
informative diagnostics when retrieving connection
information fails.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-04-24 10:55:21 +02:00
Gaetan Perrot
b919d61559 bluetooth: shell: bt: report bt_conn_get_info() error code
Use shell_error() instead of shell_print() when
bt_conn_get_info() fails and include the returned
error code in the log.

This makes failures easier to diagnose.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-04-24 10:55:21 +02:00
Gaetan Perrot
680a38a366 bluetooth: shell: bt: fix unchecked return value in disconnected
Coverity (CID 525133) reported that the return
value of bt_conn_get_info() was not checked in
disconnected(), which could lead to use of
uninitialized data.

Fix this by validating the return value before
using the connection info structure.

If retrieving the information fails, fall back to
using the generic connection type to preserve the
existing behavior.

This prevents undefined behavior while maintaining
the original logic.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-04-24 10:55:21 +02:00
Gaetan Perrot
8020b4c594 bluetooth: shell: bt: fix unchecked return value of bt_conn_get_info
Coverity (CID 333394) reported that the return
value of bt_conn_get_info() was not checked in
remote_info_available(), which could lead to use
of uninitialized data.

Fix this by checking the return value and aborting
early in case of error, ensuring that the
connection info structure is valid before use.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-04-24 10:55:21 +02:00
Emil Gydesen
db877f469f Bluetooth: CAP: Commander: Remove debug LOG_ERRs
Some LOG_ERRs from debugging was accidentally merged.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-23 07:11:07 -04:00
Johan Hedberg
be40f4440a Bluetooth: Host: shell: Add error handling for scan command parsing
Handle errors resulting from string to integer conversions.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-23 07:07:51 -04:00
Johan Hedberg
fa9155c4fe Bluetooth: Host: shell: Fix scan timeout parameter behaviour
The scan parameter is in units of 10ms in the Zephyr API, however the same
value was being treated differently for active and passive scanning. For
passive scanning the value got passed to the timeout as 10ms units, however
with active scanning it was treated as seconds by passing it to the
K_SECONDS() macro. Fix this by treating it as 10ms units in both cases.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-23 07:07:51 -04:00
Johan Hedberg
01e73e67cf Bluetooth: Host: shell: Add scan interval and window options
Add --interval and --window options to the scan command.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-23 07:07:51 -04:00
Johan Hedberg
6a7c726903 Bluetooth: Host: shell: Use getopt for scan command
Convert the scan command parameters to use getopt. While we're at it, get
rid of the confusing "dups" "nodups" options which actually behaved in the
inverse to their names ("nodups" would give you duplicate results while
"dups" would not). The new parameter is called the same as in the Zephyr
API and HCI, namely --filter-dups.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-23 07:07:51 -04:00
Johan Hedberg
e7cd3fe50f Bluetooth: Host: shell: Allow specifying advertising interval
Add support for specifying the exact advertising interval for the
"advertise" shell command. The new support is done with the help of
getopt, and since this is the first user of it in the Bluetooth shell the
appropriate select statement is added in Kconfig.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-23 07:07:51 -04:00
Can Wang
31a3544f64 Bluetooth: shell: add MAP shell support
Add Message Access Profile (MAP) shell command support to the
Bluetooth shell module.

Add map.c to the CMakeLists.txt build configuration when
CONFIG_BT_MAP is enabled, allowing MAP shell commands to be
compiled into the shell module.

Enable MAP configuration options in the Bluetooth shell test
configuration, including both MCE (Messaging Client Equipment)
and MSE (Messaging Server Equipment) functionality.

This enables testing and demonstration of MAP profile features
through the Bluetooth shell interface.

Signed-off-by: Can Wang <can.wang@nxp.com>
2026-04-23 07:06:09 -04:00
Can Wang
e438048f88 Bluetooth: MAP: add Message Access Profile support
Add source files and Kconfig options for Bluetooth Message Access
Profile (MAP) support.

MAP enables remote access to messages stored on a Messaging Server
Equipment (MSE) device from a Messaging Client Equipment (MCE) device.
The profile supports browsing folder hierarchies, listing messages,
retrieving message content, sending messages, and receiving event
notifications.

Add Kconfig options to enable MAP profile with separate options for
MCE and MSE functions.

Add logging configuration for MAP module.

Signed-off-by: Can Wang <can.wang@nxp.com>
2026-04-23 07:06:09 -04:00
Håvard Reierstad
bba9438df5 Bluetooth: shell: consistent gatt vendor read
Remove casting of the attr->user_data for short vendor value and
instead directly use the defined `vnd_value`.

Use the same defined max length for the long_vnd functions, instead
of the sizeof operator on one of the arrays.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2026-04-22 19:19:11 +02:00