Commit graph zephyr/subsys/bluetooth
Author SHA1 Message Date
Johan Hedberg
7b7c746cd5 Bluetooth: Host: Take advantage of the new inline string helpers
Take advantage of the new string conversion helpers to avoid having to
declare explicit on-stack variables.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-14 22:24:10 -04:00
Johan Hedberg
0a59ae3155 Bluetooth: Host: Add inline string conversion helper for connections
Add a helper API to convert inline (on the stack) the peer address of a
connection to a string.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-14 22:24:10 -04:00
Johan Hedberg
9197132047 Bluetooth: Introduce public address to string inline APIs
The Bluetooth stack has until now had private helpers to return an inline
pointer to a string - something which can be useful e.g. as part of
printk()/printf() call parameters. The reason these were never made public
is that they are not safe when a format string contains more than one
invocation of these.

This commit introduces replacement APIs which allocate an on-stack buffer,
thereby allowing arbitrary number of calls within the parameters of an
output formatting call. The new APIs are defines, since the solution uses
an encapsulating struct to force an on-stack copy, which then requires a
translation to access the struct-internal string member variable.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-04-14 22:24:10 -04:00
Emil Gydesen
f1320a331e Bluetooth: Services: Replace CHECKIF with if
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:21:26 -04:00
Kai Cheng
7f6ef32400 Bluetooth: Shell: Add write-eir-name command for BR/EDR
Add a new bt write-eir-name shell command to set the Extended
Inquiry Response (EIR) name for BR/EDR connections.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-14 22:14:25 -04:00
Kai Cheng
c515cfc862 Bluetooth: Classic: add extended inquiry response support
Add bt_br_write_eir() API to set the extended inquiry response (EIR)
data for BR/EDR device discovery. EIR allows remote devices to
obtain more information during the inquiry process without needing
to establish a connection.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-14 22:14:25 -04:00
Emil Gydesen
8fce7382ba Bluetooth: BAP: Broadcast: Add assert for subgroup == NULL
Add an initial assign and check for subgroup == NULL before
calling  SYS_SLIST_PEEK_NEXT_CONTAINER as some compilers
consider subgroup otherwise considers it uninitialized:

In function ‘z_snode_next_peek’,
    inlined from ‘sys_slist_peek_next_no_check’ at
	/__w/zephyr/zephyr/include/zephyr/sys/slist.h:281:1,
    inlined from ‘sys_slist_peek_next’ at
	/__w/zephyr/zephyr/include/zephyr/sys/slist.h:292:1,
    inlined from ‘bt_bap_broadcast_source_reconfig’ at
	/__w/zephyr/zephyr/subsys/bluetooth/audio/bap_broadcast_source.c:1008:15:
/__w/zephyr/zephyr/include/zephyr/sys/slist.h:213:20: error:
	‘subgroup’ may be used uninitialized [-Werror=maybe-uninitialized]
  213 |         return node->next;
      |                ~~~~^~~~~~
/__w/zephyr/zephyr/subsys/bluetooth/audio/bap_broadcast_source.c:
	In function ‘bt_bap_broadcast_source_reconfig’:
/__w/zephyr/zephyr/subsys/bluetooth/audio/bap_broadcast_source.c:975:43:
	note: ‘subgroup’ was declared here
  975 |         struct bt_bap_broadcast_subgroup *subgroup;

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:08:12 -04:00
Emil Gydesen
9969e524ad Bluetooth: BAP: Make codec_cfg param const
Make the codec_cfg 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 codec_cfg
parameter in the stack, rather than static memory.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:08:12 -04:00
Emil Gydesen
b1c2d5450e Bluetooth: BAP: Make bt_bap_stream.codec_cfg const
The pointer represent the codec 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-14 22:08:12 -04:00
Emil Gydesen
0f400e0c1e Bluetooth: BAP: Fix issues with codec_cfg pointers
In some cases the codec_cfg pointer pointed to the
codec_cfg argument, and sometimes it pointed to the ep->codec_cfg.

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

This also fixes a bug where metadata updates initiated
by the server was not properly stored by the client.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:08:12 -04:00
Mark Wang
040c811210 bluetooth: avdtp: Rename avdtp_tx_signal to avdtp_tx_single
The function name `avdtp_tx_signal` is misleading as it is used to
transmit single-fragment packets, not specifically signal packets.
Rename it to `avdtp_tx_single` to better reflect its actual purpose
and improve code clarity. Rename `avdtp_tx_frags` as `avdtp_tx_multi`
because AVDTP spec use `multi`.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2026-04-14 22:07:18 -04:00
Emil Gydesen
656d29b799 Bluetooth: MCS: Protect resources by mutex
Some resources in MCS were accessed (both read and write) by
multiple threads without any thread protection.

This commit adds a mutex to ensure thread safety.
Since the flags were previously using atomic to
prevent race condition between threads, and since there is
now a mutex, those flags have been modified to be simple
boolean values instead.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:07:07 -04:00
Kai Cheng
943d7f4e62 Bluetooth: Classic: add write supervision timeout feature
Add bt_conn_br_set_supervision_timeout() API to configure the
link supervision timeout for a BR/EDR connection via the HCI
Write Link Supervision Timeout command.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-14 22:05:26 -04:00
Kai Cheng
647c650eae Bluetooth: Classic: add read supervision timeout feature
Add bt_conn_br_get_supervision_timeout() API to read the current
link supervision timeout value for a BR/EDR connection via the
HCI Read Link Supervision Timeout command.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-04-14 22:05:26 -04:00
Maximilian Zimmermann
93411b3a23 Bluetooth: TBS: replace GTBS/TBS instance locks with global lock
Remove separate instance locks and replace all locking
and unlocking with a single global lock.

Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
2026-04-07 11:33:13 -05:00
Artur Dobrynin
eeef8ad2b1 Bluetooth: Host: rotate NRPA
NRPA should be rotated every TGAP(private_addr_int)
according to spec, which is also checked in PTS.

Signed-off-by: Artur Dobrynin <artur.dobrynin@nordicsemi.no>
2026-04-01 15:12:17 -05:00
alperen sener
6d137ae015 bluetooth: host: defer IRK resolving list update to scan/adv start
Stop scheduling bt_id_add() as workqueue work during settings load.
Mark keys BT_KEYS_ID_PENDING_ADD only, then flush them synchronously
in start_scan(), adv_start_legacy()/bt_le_ext_adv_start(),
bt_conn_le_create and bt_conn_le_create_auto when
BT_DEV_ID_PENDING is set.

We don't necessarily need to update resolving list in controller
unless actively start using it, also eliminates a race where a
workqueue-issued bt_id_add() blocks on HCI while bt_keys_clear()
concurrently zeroes the same key slot.

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2026-03-31 10:34:08 -05:00
Oleh Konko
09ad7174e9 bluetooth: l2cap: validate alloc_buf user data
validate the assumptions about buffers returned by alloc_buf() in the
LE CoC receive path.

if the returned buffer does not provide enough user_data space for the
internal segment counter, disconnect and drop the buffer instead of
reading or writing past the metadata area.

also document that alloc_buf() must return a buffer with at least
sizeof(uint16_t) bytes of user_data.

Signed-off-by: Oleh Konko <security@1seal.org>
2026-03-27 20:22:31 -04:00
Aleksandr Khromykh
6c80ebb51b bluetooth: mesh: increase settings workq stack
Commit increases mesh settings workq stack size.
Thread analyze shows 100% consumption.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-03-27 08:18:08 -04:00
Aleksandr Khromykh
ed7adfd635 bluetooth: mesh: fix solicitation data length
Commit fixes potential solicitation data length underflow.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-03-25 15:07:41 -04:00
Emil Gydesen
d66266dfa7 Bluetooth: GATT: Fix bad error from bt_gatt_attr_read_included
If `attr` or `attr->user_data` is NULL, then the include
characteristic is invalid. However the function,
bt_gatt_attr_read_included, should not return an errno value, but
a GATT error. The reason why errno cannot be used, is that the
return value is parsed through err_to_att which would make
-EINVAL become 0x16 (depending on the libc implementation),
which is an invalid ATT error code.

This was incorrectly introduced by commit
5a8189bf2a.

Changed the return value from errno to a proper GATT/ATT error.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-24 07:07:06 -04:00
Alberto Escolar Piedras
87d5f6c9d9 manifest: Update nRF hw models to latest
Update the HW models module to:
63ccab2988bf4c144b3cd324a0277e03206fa413

Including the following:
63ccab2 RADIO: Adjust Tx rampup timings
72d7680 RADIO: Correct note

AND

Adjust Bluetooth controller radio hal timings to match this new timings.

AND

Change the random seed in a very long test which is relatively sensitive
to timing, and fails due to this rampup timing change.

Repeat of note from 63ccab2:
--
IMPORTANT!: This commit changes the timing of the radio model, and
therefore requires controller SW to adjust its constants accordingly.
Even after such an adjustment it is likely some tests timing will change
marginally (if for example some advertisement event anchoring is done
as soon as possible by the controller or the like), and therefore that
some tests execution will change, and that too time sensitive test may
fail.
--

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-03-24 09:54:27 +01:00
Emil Gydesen
ec15acb69c Bluetooth: BAP: Add callback and subscribe of supported ctxs
The supported contexts were read but never provided to the
upper layers. Additionally if the supported contexts are
notifible we also subscribe to it.

This commit also fixed some other various things related
to the change to supported contexts.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 12:33:18 -05:00
Emil Gydesen
0962ac8759 Bluetooth: TBS: Make originate consistent between local and remote
If we get a remote request to originate a call via a control
point write, we lookup a TBS instance based on the URI.
However for the local API function bt_tbs_originate we did
not, so the same operation, if the target bearer was GTBS,
had different behavior depending on whether it was locally or
remotely invoked.

This commit makes the two behave the same.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 10:40:11 -04:00
Szymon Janc
49edc839d2 bluetooth: host: Allow to tune L2CAP RTX timer value
This allows to tune L2CAP RTX timer value for L2CAP connection
requests. Allowed range is 1-60 seconds while defaults to 40.
Since this is mainly useful for BI (behavior invalid) qualification
tests allows to tune it only if BT_TESTING is selected.

This is required for running L2CAP/COS/CED/BI-29-C qualification
test in reasonable time since it requires 255 iterations of
failed (timed out) connection requests.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2026-03-23 10:37:57 -04:00
Szymon Janc
8617f73e16 bluetooth: host: Fix typo in Kconfig.l2cap description
This is for L2CAP options.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2026-03-23 10:37:57 -04:00
Maximilian Zimmermann
69e2ab8152 Bluetooth: TBS: clear pending GTBS notifications on disconnect
Add missing notification clearing for the GTBS instance
in the disconnected callback.

Fixes #104568

Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
2026-03-23 08:56:23 -04:00
Hanliang Xu
baaf8fb0b4 Bluetooth: TBS: Clear pending notifications on unsub
If the client removes its subscription to any of the TBS
characteristics at any time, the pending appropriate flags
are now being cleared.

Fixes zephyrproject-rtos/zephyr#104511

Signed-off-by: Hanliang Xu <leonxu2004@outlook.com>
2026-03-23 08:56:14 -04:00
Emil Gydesen
4cf2cc054d Bluetooth: BAP: Dont attempt disconnect on detach
This removes dead code. Since bt_bap_stream_detach sets
stream->ep = NULL then the call to bt_bap_stream_iso_chan_get
will always return NULL since stream->ep is NULL, and thus
the call to bt_bap_stream_disconnect would always be a no-op.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 08:56:05 -04:00
Emil Gydesen
2b198cf2cc Bluetooth: Audio: Make "foreach" functions consistent
Modify foreach functions in LE Audio to follow the same pattern:
Return true to continue iterating.
Return false to stop iterating.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 08:53:33 -04:00
Emil Gydesen
c9a0257e8f Bluetooth: Host: Replace CHECKIF with if
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 08:49:13 -04:00
Emil Gydesen
735f101c95 Bluetooth: Mesh: Remove checks in bt_rand
Remove the NULL and 0-length checks in bt_rand, as they
are probably not necessary.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 08:49:02 -04:00
Emil Gydesen
8070ee277b Bluetooth: Mesh: Replace CHECKIF with if
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 08:49:02 -04:00
Emil Gydesen
60f8fac0dd Bluetooth: Classic: Replace CHECKIF with if
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 10:25:36 +01:00
Pisit Sawangvonganan
2ea93f9e10 bluetooth: fix typo
Use a code spell-checking tool to detect and fix spelling errors in
the files under `subsys/bluetooth`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2026-03-23 10:25:26 +01:00
Emil Gydesen
e35cc4e6cd Bluetooth: CCP: Make CCP server thread safe
Guard any calls that accesses the bearer with a mutex

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 10:15:25 +01:00
Håvard Reierstad
850f5006dc Bluetooth: Shell: Fix vendor gatt read size
When reading the value of the vendor attribute, strlen was used instead
of sizeof, causing a unpredictable read size. This commit changes the
implementation to use sizeof instead.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2026-03-20 12:37:11 -05:00
Titouan Christophe
6e1a9e6c52 bluetooth: host: monitor: fix build with 64b log timestamps
If CONFIG_LOG_TIMESTAMP_64BIT is enabled, then the call to
log_set_timestamp_func in the Bluetooth monitor is type-invalid,
which may fail to build with -Werror.

To avoid this type inconsistency let's use the type `log_timestamp_t`,
which accounts for the correct size, depending on selected config.

Even though the monitoring protocol only seems to support 32b timestamps,
the rest of the module is already based on 64b timestamps, so the
truncation is only done when encoding the timestamp for transmission
to the host in encode_hdr()

Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
2026-03-20 18:19:35 +09:00
Alberto Escolar Piedras
c6a4721474 Bluetooth: Controller: nRF5x: Trivial maintainability issue fixes
Fix a few trivial complains from Sonar Cloud in these files
* Methods should not be empty c:S1186
https://sonarcloud.io/organizations/zephyrproject-rtos/rules?open=c%3AS1186&rule_key=c%3AS1186
* "default" clauses should be first or last c:S4524
https://sonarcloud.io/organizations/zephyrproject-rtos/rules?open=c%3AS4524&rule_key=c%3AS4524

This commit introduced no functional changes.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-03-19 17:16:11 -05:00
Emil Gydesen
bc37305998 Bluetooth: ASCS: Hotfix for failing ASCS unittests
The way that ASCS registers and unregisters for the ASCS
unittests does not work properly with UUIDs and local variables.

Hotfix is to use a `static` backup instead of a stack-allocated
backup. A proper fix will be provided later.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-19 14:56:35 -05:00
Emil Gydesen
fa87a67169 Bluetooth: ISO: Replace CHECKIF with if
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-19 11:38:12 +00:00
Kai Cheng
f3c178192e Bluetooth: UUID: add bt_uuid_compress helper
Add bt_uuid_compress() to compact a 128-bit Bluetooth UUID into its
16-bit or 32-bit short form when it matches the Bluetooth Base UUID.

If the UUID does not match the Base UUID pattern the 128-bit value is
copied unchanged and -ENOTSUP is returned, allowing callers to
distinguish compressible from non-compressible UUIDs.

16-bit and 32-bit source UUIDs are copied as-is.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-03-19 11:36:39 +00:00
Kai Cheng
63420b0098 Bluetooth: UUID: add string to UUID conversion function
Implement bt_uuid_from_str() function to convert string representations
to Bluetooth UUID structures. This provides bidirectional conversion
between UUID structures and their string representations, complementing
the existing bt_uuid_to_str() function.

Features:
- Supports 16-bit UUID format (4 hex characters, e.g., "180d")
- Supports 32-bit UUID format (8 hex characters, e.g., "abcdef12")
- Supports 128-bit UUID standard format (with hyphens)
- Comprehensive input validation and error handling
- Automatic UUID type detection based on string length

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-03-19 11:36:39 +00:00
Kai Cheng
898c4877a2 Bluetooth: UUID: refactor to use generic UUID library
Refactor the Bluetooth UUID module to use the generic UUID library
(lib/uuid) instead of hand-rolled byte manipulation.

Changes:
- Replace bt_uuid_128-based base UUID with struct uuid (RFC 9562 order)
- Replace uuid_to_uuid128() with bt_uuid_to_uuid() for BT-to-generic
  UUID conversion using proper big-endian / byte-swap operations
- Simplify bt_uuid_to_str() 128-bit case via uuid_to_string()
- Add Kconfig 'select UUID' dependency for BT_HCI_HOST

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-03-19 11:36:39 +00:00
Lyle Zhu
f21c79f310 bluetooth: host: avrcp: fix return value handling in command handlers
Fix three command handlers that were incorrectly returning the result
of callback functions with void return type:
- avrcp_unit_info_cmd_handler
- avrcp_subunit_info_cmd_handler
- avrcp_pass_through_cmd_handler

Split the callback invocation and return statement to properly handle
the void return type, avoiding potential compiler warnings or errors.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-03-19 12:28:15 +09:00
Emil Gydesen
3d5b7275e8 Bluetooth: Audio: Spring cleaning
Add missing header files, remove unused header files,
fix typos and missing static.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-18 17:42:55 -05:00
Johan Hedberg
6f9999f48e Bluetooth: Remove bt_hci_cmd_create()
The bt_hci_cmd_create() function was deprecated several releases ago (in
Zephyr 4.2) and can therefore now be removed.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-03-18 15:23:03 -05:00
Emil Gydesen
9fafa1288d Bluetooth: TBS: Add check before memcpy of URI scheme
Add a check of the URI scheme length before comparing it
to any instance's supported URI schemes. If the incoming
URI scheme is longer than what we support, then there's
no point in checking if we support it, as we cannot.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-18 08:44:27 -05:00
Vedant Malkar
e49a5c1bc2 Bluetooth: MCS: Remove the GATT include service when OTS is disabled
The BT_GATT_INCLUDE_SERVICE is always included in
BT_MCS_SERVICE_DEFINITION even when CONFIG_BT_OTS=n,
this fixes it such that it is only included when OTS is enabled.

Fixes zephyrproject-rtos#105345

Signed-off-by: Vedant Malkar <vedantitsme@gmail.com>
2026-03-18 08:42:34 -05:00
Kai Cheng
77e1d6a86c Bluetooth: host: call bt_br_init() for Classic init in hci_init
When the controller supports BR/EDR and CONFIG_BT_CLASSIC is
enabled, call bt_br_init() to perform the full BR/EDR Classic
initialization (SSP mode, inquiry mode, local name, Class of
Device, etc.).

For non-Classic builds that still need BR/EDR buffer sizes,
gate the hci_read_buffer_size() fallback with
IS_ENABLED(CONFIG_BT_CONN) to make the build-time condition
explicit at the call site.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-03-18 08:35:43 -05:00