Commit graph zephyr/subsys/bluetooth
Author SHA1 Message Date
Lyle Zhu
11c11b5834 bluetooth: classic: goep: refactor transport version handling
Refactor GOEP transport version handling to use explicit v1/v2
structure pointers instead of a boolean flag and union.

Replace the `_goep_v2` boolean flag and `_transport` union in
`struct bt_goep` with explicit `v1` and `v2` pointers to new
`bt_goep_transport_v1` and `bt_goep_transport_v2` structures. This
improves code clarity and type safety by making the transport version
explicit and avoiding union-based type punning.

The new structures contain:
- `bt_goep_transport_v1`: RFCOMM DLC and back-pointer to parent GOEP
- `bt_goep_transport_v2`: L2CAP channel and back-pointer to parent GOEP

Update all transport operations to use CONTAINER_OF to retrieve
the version-specific structure, then access the parent GOEP
instance through the back-pointer.

Update BIP and shell code to allocate and initialize both v1 and
v2 structures, setting the appropriate pointer based on the
transport type being used.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:20 +02:00
Lyle Zhu
e7fc0234be bluetooth: classic: shell: goep: Improve code style consistency
Replace implicit NULL and zero checks with explicit comparisons to
improve code readability and follow coding standards.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:20 +02:00
Thomas Hebb
00b733675d bluetooth: classic: Fix typo BT_DEVICE_VEDNOR_ID -> BT_DEVICE_VENDOR_ID
This is a breaking change, so note it in the migration guide too.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-06-02 20:22:04 -04:00
Yuan Ye
c3386f92fe Bluetooth: GATT: Enforce characteristic permissions
When a characteristic declaration is passed instead of a value
attribute, ensure the associated characteristic value attribute
permissions are checked before sending notifications, indications
or multiple notifications.

Signed-off-by: Yuan Ye <1275552818@qq.com>
2026-06-02 20:17:57 -04:00
Håvard Reierstad
f41665b12e bluetooth: mesh: default BT_BUF_EVT_DISCARDABLE_SIZE to 58
Extended advertising reports as of
https://github.com/zephyrproject-rtos/zephyr/pull/106374 use the
discardable event pool so fragmented chains can be dropped without. That
raised the default discardable buffer size to BT_BUF_EVT_RX_SIZE to fit
general ext-adv reassembly.

Mesh does not need that headroom. The advertising bearer uses
ADV_NONCONN_IND PDUs (Mesh Protocol v1.1 3.3.1), which are legacy
primary-channel advertisements, not fragmented extended advertising
chains. Mesh scan only accepts BT_GAP_ADV_TYPE_ADV_NONCONN_IND, and
legacy reports fit in 58 bytes, the minimum when BT_EXT_ADV is enabled.

Default to 58 for BT_MESH to save RAM.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2026-06-02 09:26:07 -05:00
Emil Gydesen
aaccb51555 Bluetooth: ASCS: Introduce ascs.h
Introduce a new header file for ASCS as a step
towards decoupling ASCS and BAP.

BAP has a depdendencey on ASCS, but ASCS does not have one
for BAP, and the code should reflect that.

This is a first step that simply removes the requirement
of the BAP Unicast Server in ASCS with minimal changes.

Tasks to follow up with:
- Remove any depedency on bap.h from ascs.c
- Rename everything from ascs.h from bt_bap to bt_ascs where
  applicable
- Add unit tests specific for BAP unicast server
- Move any BAP-only requirements from ASCS to the BAP unicast
  server implementation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-02 11:41:03 +02:00
Emil Gydesen
a978aa106b Bluetooth: BAP: UC: Fix race condition with long reads
There was a race condition where the att_buf could be used for a
write request before the att_buf, containing the result of a long
read, was properly handled first.

Now the unicast client is only marked as not busy after the buffer
has been parsed.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-02 11:39:25 +02:00
Lyle Zhu
9e8ffa269a bluetooth: classic: l2cap: Add headroom check in bt_l2cap_br_send_cb
Add a check to validate that the buffer has sufficient headroom
(BT_L2CAP_CHAN_SEND_RESERVE) before attempting to send data over
a classic L2CAP channel.

Without this validation, buffers allocated with insufficient headroom
could cause buffer corruption when `net_buf_push()` is called to add
the L2CAP header. In the case, the application will be asserted if
the assert is enabled.

The change ensures that callers properly reserve headroom when
allocating buffers for `bt_l2cap_chan_send()`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-01 12:41:13 -04:00
Lyle Zhu
81de8a05b3 bluetooth: classic: replace strncmp with memcmp for data comparison
Replace `strncmp()` with `memcmp()` for Bluetooth Classic part,
including in AT command parsing and HFP protocol handlers.

Due to the passed `n` of `memcmp()` has been checked and ensured to be
minimum size of the passed two memory blocks, the data of memory block
being compared is not necessarily null-terminated, making `memcmp()`
the more appropriate choice for binary-safe comparisons.

In addition, this change ensures that there are no type mismatch
warnings when using the function `strncmp()`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-01 12:41:02 -04:00
Dharun krithik k
4706f9383b Bluetooth: hci: Use net_buf_take() for sent_cmd transfer
Replace atomic_ptr_clear() with net_buf_take() to atomically
transfer ownership of the sent command buffer.

Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
2026-06-01 12:40:25 -04:00
Dharun krithik k
6c9ce1b24b Bluetooth: L2CAP: LE: Use net_buf_take() for SDU transfer
Use net_buf_take() when moving completed SDU buffer from channel
to local variable in LE receive path.

Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
2026-06-01 12:40:25 -04:00
Dharun krithik k
0a394af480 Bluetooth: host: Use net_buf_take() for ACL RX buffer
Replace manual pointer transfer with net_buf_take() when moving
completed L2CAP frame from connection rx buffer.

Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
2026-06-01 12:40:25 -04:00
Dharun krithik k
068faa81c5 Bluetooth: L2CAP: BR/EDR: Use net_buf_take() for SDU transfer
Use net_buf_take() when moving completed SDU buffer from channel
to local variable, replacing manual pointer operations.

Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
2026-06-01 12:40:25 -04:00
Dharun krithik k
54b160f1aa Bluetooth: ATT: Use net_buf_take() to transfer buffer ownership
Replace manual buf assignment and NULL setting with net_buf_take()
when releasing buffer to bt_l2cap_send_cb.

Signed-off-by: Dharun krithik k <dharunkrithik@aerlync.com>
2026-06-01 12:40:25 -04:00
Sam Friedman
c7292f2022 bluetooth: host: consistent notification of subscription termination
Ensure that the subscription params struct is not used after releasing
it back to the application.

Signed-off-by: Sam Friedman <sam@golioth.io>
2026-06-01 11:56:32 +02:00
Sam Friedman
a0fa5f80a7 bluetooth: mcc: check value instead of handle while unsubscribing
Checking `params->value` instead of `params->value_handle` is
a more straightforward and less brittle way to determine if a
ccc write response callback is performed due to a subscription
or unsubscription.

Signed-off-by: Sam Friedman <sam@golioth.io>
2026-06-01 11:56:32 +02:00
Emil Gydesen
3a92bb4d51 Bluetooth: Audio: Shell: Fix various print issues
Remove the use of printk, and replace with bt_shell_print
Remove any excess `\n` that seem to have been leftovers
from a previous fix.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-29 22:11:37 +02:00
Emil Gydesen
5932e6f11f Bluetooth: Audio: Add missing and sort includes
Add missing includes and sort where applicable.
This is to follow include-what-you-use.

Assisted-by: Claude:claude-sonnet-4.5

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-27 15:17:45 +01:00
Valerio Setti
c15cba4e7a modules: mbedtls: rename mbedTLS library and documentation usage
Having an interface library named "mbedTLS" and the real library named
"mbedtls" (as provided by the Mbed TLS module) is misleading.
This commit replaces:
- mbedTLS -> mbedtls_iface for the CMake library. "mbedTLS" is still
             available as alias to "mbedtls_iface" for backward
             compatibility, but this should be removed in the future.
- mbedTLS -> Mbed TLS in comments and documentation.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-05-27 15:16:06 +01:00
Aleksandr Khromykh
3a308dc06a bluetooth: mesh: fix adv restart races in provisioned disconnect paths
With CONFIG_BT_MAX_CONN=1, restarting connectable advertising from
the bt_conn_cb.disconnected callback fails with -ENOMEM because the
BLE host still holds a connection reference at that point. The
connection slot is only guaranteed free when bt_conn_cb.recycled fires.

Two code paths in gatt_disconnected() called bt_mesh_adv_gatt_update()
indirectly, triggering bt_le_ext_adv_start() before the connection
slot was freed:

pb_gatt_srv: on the provisioned path, bt_mesh_pb_gatt_srv_disable()
was called, which internally triggers bt_mesh_adv_gatt_update().

proxy_srv: when the proxy service was not yet registered upon
disconnect, bt_mesh_proxy_gatt_enable() was called, which also
triggers bt_mesh_adv_gatt_update().

Extract prov_gatt_service_unregister() and proxy_gatt_service_register()
as private helpers that perform only the GATT service operation without
triggering advertising. Have gatt_disconnected() call these helpers
and set adv_restart_pending = true in all branches, so conn_recycled()
safely handles the advertising restart after the connection is freed.

Assisted-by: GitHub Copilot:Claude Sonnet 4.6
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-05-22 21:56:18 +02:00
Aleksandr Khromykh
311153ea16 bluetooth: mesh: fix connectable adv restart after disconnect
When a PB-GATT or GATT Proxy connection disconnects on a device with
CONFIG_BT_MAX_CONN=1, the mesh stack attempts to restart connectable
advertising from the disconnected callback. This fails with -ENOMEM
because the BLE host still holds a reference to the connection object
at that point, and bt_le_ext_adv_start() cannot pre-allocate a new
connection slot.

Fix this by using the bt_conn_cb.recycled callback to trigger
advertising restart. The recycled callback fires only after the
connection object is fully released, guaranteeing a free slot is
available for connectable advertising.

Remove bt_mesh_adv_gatt_update() from bt_mesh_proxy_role_cleanup()
and instead set an adv_restart_pending flag in the disconnected
handler. The recycled callback checks this flag to avoid unnecessary
advertising restart attempts from unrelated disconnections.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-05-22 21:56:18 +02:00
Lyle Zhu
1d45168337 bluetooth: host: classic: l2cap_br: Fix conf req/rsp length validation
In `l2cap_br_conf_req()` and `l2cap_br_conf_rsp()`, `buf->len` is used
to validate the minimum packet size. However, `buf->len` may exceed the
actual command data length (the `len` parameter from the L2CAP
signaling header), as the buffer can contain data beyond the current
command.

When the command data length `len` is smaller than the minimum packet
size, but `buf->len` is not less than the minimum packet size, the
validation passes incorrectly. Subsequently, when calculating `opt_len`
(`len - sizeof(*req)`), an underflow occurs duw to the value of type
`uint16_t`, resulting in an out-of-bounds buffer access issue.

Fix by validating against the `len` parameter instead of `buf->len` in
both `l2cap_br_conf_req()` and `l2cap_br_conf_rsp()`, since `len`
reflects the actual command data length.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-05-22 10:50:37 +02:00
Flavio Ceolin
28080d80fc Bluetooth: Controller: Fix OOB read in ISOAL
When sc=0, a framed ISO PDU segment header includes a 3-byte time_offset
field, so seg_hdr->len must be at least PDU_ISO_SEG_TIMEOFFSET_SIZE.
isoal_check_seg_header() accepted segments with sc=0 and len<3 as valid,
allowing isoal_rx_framed_consume() to underflow, causing an
out-of-bounds read of up to 255 bytes of adjacent memory into an HCI ISO
packet delivered to the host.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2026-05-21 06:33:05 -04:00
Aleksandr Khromykh
3f3c37edf8 bluetooth: mesh: defer prov protocol timer reset past validity checks
In prov_msg_recv(), the protocol timer was reset unconditionally at
the top of the function, before the FCS check and before the
ADV_LINK_INVALID check. When the link has been marked invalid (e.g.
after a provisioning failure), any incoming PB-ADV packet with a
passing FCS would still reset the timer, preventing
protocol_timeout() from firing and closing the link via
prov_link_close().

Move k_work_reschedule() to after the ADV_LINK_INVALID check so the
timer is only reset for valid PDUs on an active, non-failed link.
Move the FCS check before the timer reset for the same reason.

Once ADV_LINK_INVALID is set the protocol timer is no longer
extended by incoming packets, and the link is closed by
protocol_timeout() as intended, after which the unprovisioned
device beacon and PB-ADV link acceptance are restored.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-05-20 20:06:45 -04:00
Nicolas Pitre
90d1963745 sys: util: move lowercase min/max/clamp to a new minmax.h
Since commit 37717b229f ("sys: util: rename Z_MIN Z_MAX Z_CLAMP to min
max and clamp"), <zephyr/sys/util.h> unconditionally defines function-
like macros named `min`, `max`, and `clamp` in the global namespace (in
C mode). util.h gets pulled in transitively by very broad headers,
including the POSIX layer's <pthread.h>, so any third-party C code that
uses these names as ordinary identifiers (e.g. XNNPACK's static `clamp`
helper and its public `clamp` struct field) fails to build as soon as
<pthread.h> is included.

Following the approach used by Linux, move the lowercase `min`, `max`,
`min3`, `max3`, and `clamp` macros (and their helpers) into a new
<zephyr/sys/minmax.h> header that has to be included explicitly by
source files that want them. util.h keeps the uppercase MIN/MAX/CLAMP,
so most code is unaffected; only the (much smaller) set of files that
actually use the lowercase variants needs to pick up the new include.

Fixes #107853.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-05-19 17:49:24 -04:00
Emil Gydesen
b7d149d3bd Bluetooth: CAP: Handover: Fix handling of reception stopped
The when the reception stopped callback was called, we should
call bt_cap_handover_broadcast_reception_stopped and not
cap_handover_broadcast_audio_stopped, as we need to stop the
broadcast as a result of it, and not just delete it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-19 14:58:41 +01:00
Emil Gydesen
eae67ce466 Bluetooth: Audio: Fix MISRA 13.3 violations
Fix expressions where increment or decrement operators are combined
with other side effects in the same full expression, violating
MISRA-C Rule 13.3.

Separate the increment and decrement operations into standalone
statements to ensure each full expression contains at most one
side effect.

Assisted-by: GitHub Copilot

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:18:51 +01:00
Emil Gydesen
6c592a4c24 Bluetooth: Audio: Add missing error checks
Add missing error checks for any function calls in the
affected files, as that is required by the Zephyr coding guidelines.

The call to bt_ots_client_register in mcc.c was moved to
avoid calling it mulitple times, causing it to fail if
bt_mcc_discover_mcs was called more than once.

Assisted-by: Copilot:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:18:42 +01:00
Emil Gydesen
27db10e692 Bluetooth: BAP: Unicast: Add common state and ops checks
Add functions to collect the ASE state transtion and ASE
operation checks

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:14:48 +01:00
Emil Gydesen
52300b3a98 Bluetooth: CAP: Add LOG_DBG for all aborts
Add a LOG_DBG for all aborts so that it is easier
to determine the exact reason for an aborted CAP
procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:13:55 +01:00
Emil Gydesen
5658386acb Bluetooth: CAP: Handover: Minor opt for valid metadata check
Minor change to valid_unicast_to_broadcast_metadata to break
the loop earlier if the unique_metadata_cnt is already too
large.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:13:55 +01:00
Emil Gydesen
f38c0cf7e5 tests: Bluetooth: CAP: Handover u->b unittests
Adds unittests for the handover from unicast to broadcast
APIs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:13:55 +01:00
Zihao Gao
c279c94cf3 bluetooth: classic: avdtp: fix delay report parsing
bt_avdtp_parse_capability_codec() returns immediately after parsing the
Media Codec service category, skipping any subsequent service categories
in the capability list. This causes the Delay Reporting service category
(0x08) to be missed when it appears after the Media Codec in a Set
Configuration command.

Fix by replacing 'return 0' with 'break' so the while loop continues
to parse remaining service categories. Also update the final return to
check whether a codec was actually found.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-05-18 10:20:25 +01:00
Emil Gydesen
d47e6fabbe Bluetooth: CAP: Document CAP unicast complete errors
Update the documentation for the uncast_x_complete callbacks
so that applications can better determine what `err` might be
and act according to the error.

It also makes the disconnect callback more unique, as well
as treating control point write rejects different from
invalid state changes.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 10:15:03 +01:00
Emil Gydesen
a2110e70fa Bluetooth: TBS: Rename features to optional opcodes
The characteristic name and definitions in the TBS spec for
the values are "optional opcodes" instead of "support features".

Additionally, the field is 16-bit, instead of the current 8-bit
in the register parameters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 10:14:52 +01:00
Tomi Fontanilles
b97f0ae81d modules: mbedtls: remove CONFIG_PSA_CRYPTO_CLIENT
It doesn't really serve a purpose since the addition of
CONFIG_PSA_CRYPTO.

Replace remaining uses of the former by the latter.

TF-M now implies CONFIG_PSA_CRYPTO the same way as
CONFIG_MBEDTLS because otherwise we get build failures
if we build Mbed TLS without CONFIG_PSA_CRYPTO enabled.
Hopefully we can remove these two in a later PR.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2026-05-14 21:55:23 +02:00
Vinayak Kariappa Chettimada
e25313f214 Bluetooth: Host: Add definition and decoding for Bluetooth version 6.3
Add definition and decoding for version 6.3.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2026-05-14 07:34:14 +02:00
Vinayak Kariappa Chettimada
77bea3198d Bluetooth: Host: Fix missing static const qualifier
Fix missing static const qualifier on the version number
look up array declaration.

Without this fix, str was an automatic array inside
bt_hci_get_ver_str(), consuming stack on each call.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2026-05-14 07:34:14 +02:00
Kai Cheng
53d25b0165 Bluetooth: Classic: shell: add change-packet-type command
Add shell support for the bt_conn_br_change_packet_type() API:

- Add 'br change-packet-type <hex>' shell command to allow
  changing ACL packet types on an established BR/EDR connection.
- Add br_packet_type_changed callback to print the
  HCI_Connection_Packet_Type_Changed event result.
- Register the callback in conn_callbacks.

This addresses the review feedback requesting shell/test support
for the change connection packet type feature.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-05-13 18:59:26 +01:00
Kai Cheng
92e59fd7b2 Bluetooth: Classic: add change connection packet type support
Add bt_conn_br_change_packet_type() API to dynamically change the
allowed packet types for an established BR/EDR connection. This
enables throughput optimization by selecting appropriate packet
types (DM/DH 1/3/5 slots) based on application requirements.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-05-13 18:59:26 +01:00
Lyle Zhu
366d130101 Bluetooth: Classic: RFCOMM: Refactor overhead size calculation
Introduce BT_RFCOMM_OVERHEAD_SIZE macro to calculate the RFCOMM frame
overhead, which includes the maximum header size, FCS size, and
credits size.

This refactoring:
- Defines BT_RFCOMM_CREDITS_SIZE (1 byte) as a public constant
- Consolidates overhead calculation in a single macro
- Updates all MTU calculations to use BT_RFCOMM_OVERHEAD_SIZE
- Removes redundant credits size adjustment in rfcomm_dlc_connected()
  since the overhead is now accounted for upfront in session MTU
  calculation
- Simplifies code in GOEP by using the new macro instead of manual
  header size calculations
- Change the range of BT_GOEP_RFCOMM_MTU to [265, BT_RFCOMM_L2CAP_MTU]

The change ensures consistent MTU calculations across RFCOMM and
dependent profiles (HFP, GOEP) and accounts for the credits field in
CFC-supported scenarios from the start.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-05-13 05:11:54 +02:00
Emil Gydesen
0cd61589ff Bluetooth: BAP: BA: Move att_buf to inst
Since the Broadcast Assistant implementation may have a
pending request _per_ instance, each instance needs its own
buffer to accomodate that, otherwise we may risk overwriting
data between instances. This follows the design used in the
BAP Unicast Client

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-12 11:17:40 +02:00
Aleksandr Khromykh
a9ad258c84 bluetooth: mesh: fix BLOB IO flash write alignment for non-erase devices
The wr_chunk function had a fast path for devices without explicit erase
(e.g. nRF54L RRAM) that wrote chunk data directly without aligning the
offset or size to the flash write block size. On RRAM with
write-block-size=16, this caused -EINVAL from the flash driver for every
chunk write since chunk_size (161) and most chunk offsets are not
16-byte aligned.

The failed writes caused the BLOB server to never mark chunks as
received, resulting in block_status_rsp always reporting all chunks
missing. This led to infinite retransmission of block 0 and eventual
DFU timeout.

Fix by using a read-modify-write approach for non-erase devices:
read existing data at the aligned boundaries, overlay the chunk data,
and write back the full aligned buffer. This satisfies the driver's
alignment requirements while preserving neighboring bytes.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-05-11 10:59:49 +02:00
Emil Gydesen
756b16b643 Bluetooth: ISO: Add missing buf->len checks in bt_iso_recv
bt_iso_recv pulls the SDU header (with or without) timestamp,
but did not check the length of `buf` before doing so.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-08 16:04:41 -05:00
alperen sener
67049acb23 bluetooth: host: gatt: add helper bt_gatt_is_db_hash_valid test function
Adding a helper test function to check if the DB hash is valid.

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2026-05-08 11:24:15 +02:00
alperen sener
78a53b541b bluetooth: host: gatt: destroy imported key in case psa mac sign fail
Imported key is not destroyed in case psa mac sign fails. This is a
potential memory leak.

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2026-05-08 11:24:15 +02:00
Egill Sigurdur
16ac4a5b78 kernel: mem_slab: add K_MEM_SLAB_DEFINE_TYPE for automatic alignment
Introduces K_MEM_SLAB_DEFINE_TYPE() and K_MEM_SLAB_DEFINE_STATIC_TYPE()
helpers to allow the user to declare slabs for types without having to
manually ensure the alignment is correct.

Manual slab alignment was very error-prone and this change fixes several
instances of misalignment that would be trapped by the undefined
behavior sanitizer when running on 64-bit targets.

Signed-off-by: Egill Sigurdur <egill@egill.xyz>
2026-05-07 18:09:41 -05:00
Tomi Fontanilles
7d65b380e2 modules: mbedtls: link to mbedTLS only when CONFIG_MBEDTLS_BUILTIN
393350fd65 made it so that the `mbedTLS`
library is only created when `CONFIG_MBEDTLS_BUILTIN`.

Before this commit, users of Mbed TLS did the following:
`zephyr_library_link_libraries_ifdef(CONFIG_MBEDTLS mbedTLS)`

If the `mbedTLS` CMake library doesn't exist but is still linked to
(as is the case when `CONFIG_MBEDTLS && !CONFIG_MBEDTLS_BUILTIN`),
the linker command is populated with `-lmbedTLS` which makes the build
fail because there is no `libmbedTLS.a` in the build.

Make it so that users of Mbed TLS only link to the `mbedTLS` CMake
library when the builtin version is used.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2026-05-07 09:11:36 +02:00
Håvard Reierstad
4feab28245 Bluetooth: Host: Change default BT_BUF_EVT_DISCARDABLE_SIZE
With adding discard-tracking of extended advertising reports, the
reports are allocated from the discardable event pool instead of the
"normal" event pool. This commit sets the default value of
BT_BUF_EVT_DISCARDABLE_SIZE to BT_BUF_EVT_RX_SIZE when BT_EXT_ADV
is enabled.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2026-05-06 16:29:15 +01:00
Håvard Reierstad
e3a3a8e685 Bluetooth: Host: add fragmented ext adv stress test
Extends the `host/scan/slow` bsim test to test that the reassembler
is able to recover from a discarded extended advertising report chain.

This requires tracking that extended advertising reports are in fact
received, and that the reassembler times out. Functions for this are
added to testing.h which is only compiled if BT_TESTING is enabled.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2026-05-06 16:29:15 +01:00