Commit graph zephyr/subsys/bluetooth
Author SHA1 Message Date
Emil Gydesen
fb892aaa42 Bluetooth: BAP: SD: Fix log of wrong err value
The `err` variable was overwritten by the k_mutex functions
before being logged, so it did not log the actual error.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-12 21:45:32 +02:00
Emil Gydesen
3877dead16 Bluetooth: BAP: UC: Add missing sys_cpu_to_le16 for SDU
Add missing sys_cpu_to_le16 when assigning SDU size to the QoS
configure operation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-12 15:46:51 +02:00
Emil Gydesen
5a90383263 Bluetooth: Audio: apply U suffix to unsigned integer literals
Apply the U suffix to unsigned integer literal constants used in
contexts involving unsigned types (uint8_t, uint16_t, uint32_t,
uint64_t, size_t, etc.) with coding guideline 40  which requires that
"A u or U suffix shall be applied to all integer constants that are
represented in an unsigned type".
In addition to this requirement, this commit also ads U to any unsigned
literal integer for the sake of completeness.

Changes are limited to literal values in assignments, initializations,
comparisons, and for-loop bounds where the context is unambiguously
unsigned.

Assisted-by: GitHub Copilot:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-12 15:46:35 +02:00
Emil Gydesen
af3d342f65 Bluetooth: BAP: Shell: Make it easier to copy broadcast IDs
The broadcast ID is printed in the shell various places. Often the
shell user wants to copy this value and use it for future commands.

Remove any following commas, so that the user can easier click-to-mark
the value to copy it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-12 15:34:28 +02:00
Emil Gydesen
ff26f33f35 Bluetooth: BAP: UC: Add check for stream->group for QoS notification
If the server wrongly sends us a QoS state notification before
the stream was ever added to a group, we should just ignore it
rather than hitting the assert or dereferencing the group
later.

Additionally, LOG_ERR should not be used when validating input
from a remote device.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-12 15:31:54 +02:00
Emil Gydesen
d0834666d1 Bluetooth: ASCS: Use is_valid_num_ases for is_valid_stop_len
Instead of just checking the lower limit, use
is_valid_num_ases to also test the upper limit.
This approach is used by all other control point operations.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-10 13:13:48 +02:00
Lyle Zhu
98e4c16d45 bluetooth: host: classic: fix SDP attribute parsing recursion check
Add missing type check in sdp_attr_parse() before recursively parsing
data element sequences. When checking the type of the next data if it
is a sequence, it did not first check if the current type is a
sequence.

It could lead to incorrect recursive parsing when the current type is
not a sequence but the next byte was incorrectly identified as a
sequence.

Fix the issue by checking the current data type firstly.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-10 13:12:11 +02:00
Emil Gydesen
9f5639ea75 Bluetooth: BAP: UC: Fix poorly worded "NULL is NULL" log
Fix poorly worded log statement.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-10 10:53:53 +02:00
Johan Hedberg
fe36ed31e5 Bluetooth: Host: Fix use-after-unref in bt_hci_le_enh_conn_complete
bt_hci_le_enh_conn_complete() obtains a reference via
find_pending_connect() but drops it immediately after the
bt_conn_connected() callback, while the function still dereferences
conn->role afterwards in the central-role scanner restart block.

Using a pointer after its reference has been dropped is a
use-after-free in API contract terms, even if in practice the
connection survives because other references (the conn array's
intrinsic reference, L2CAP, etc.) keep the object alive at this
point.

Move the bt_conn_unref() call to the end of the function so the
locally held reference outlives all uses of conn.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
7367ca6b8b Bluetooth: AVRCP: Fix use-after-unref in cover art L2CAP connect
bt_avrcp_cover_art_ct_l2cap_connect() obtains a reference to the ACL
connection via bt_avrcp_ct_get_acl_conn() but then immediately drops
that reference before continuing to use the conn pointer for
bt_conn_index() and bt_bip_l2cap_connect(). Using a pointer after
its reference has been dropped is a use-after-free in API contract
terms, even if in practice the underlying connection survives because
other references (e.g. the L2CAP channel, the ACL link itself) keep
the object alive while AVRCP cover art is in use.

Move the bt_conn_unref() call to after the last use of conn on each
return path so that the locally held reference outlives all uses.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
30cca0398f Bluetooth: Mesh: Use bt_conn_drop() where applicable
Replace the two-line pattern:

  bt_conn_unref(conn);
  conn = NULL;

(and equivalent if-guarded variants) with bt_conn_drop(&conn) which
performs both operations atomically in a single step. The guard is
unnecessary because bt_conn_drop() handles a NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
572b76130d Bluetooth: Classic: Use bt_conn_drop() where applicable
Replace the two-line pattern:

  bt_conn_unref(conn);
  conn = NULL;

(and equivalent if-guarded variants) with bt_conn_drop(&conn) which
performs both operations atomically in a single step. The guard is
unnecessary because bt_conn_drop() handles a NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
6455871bcf Bluetooth: Host: Use bt_conn_drop() where applicable
Replace the two-line pattern:

  bt_conn_unref(conn);
  conn = NULL;

(and equivalent if-guarded variants) with bt_conn_drop(&conn) which
performs both operations atomically in a single step. The guard is
unnecessary because bt_conn_drop() handles a NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
4c30188d60 Bluetooth: Audio: Use bt_conn_drop() where applicable
Replace the two-line pattern:

  bt_conn_unref(conn);
  conn = NULL;

(and equivalent if-guarded or take-then-unref-then-NULL variants) with
bt_conn_drop(&conn) which performs both operations atomically in a
single step. The guard is unnecessary because bt_conn_drop() handles a
NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
9cda39e08c Bluetooth: Host: Add bt_conn_drop() API
Add a new bt_conn_drop() function that atomically drops a connection
reference and clears the source pointer in a single step. This mirrors
the recently added net_buf_drop() API and replaces the common pattern:

  bt_conn_unref(conn);
  conn = NULL;

The new API handles a NULL pointer internally, so any guard around it
is unnecessary.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Johan Hedberg
18b85f7d06 Bluetooth: ISO: Use bt_conn_take() for ACL reference transfer
Replace the manual two-step pointer transfer:

  struct bt_conn *acl = iso->iso.acl;
  if (acl != NULL) {
          iso->iso.acl = NULL;
          ...
  }

with bt_conn_take(), which atomically extracts the reference and clears
the original pointer in a single step.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-10 10:53:36 +02:00
Emil Gydesen
b832650ee6 Bluetooth: Controller: ISO: Set cig->{p,c}_latency for periph
Add calculations to set the cig->c_latency and cig->p_latency
so that the CIS established event contains valid values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-06-08 16:33:01 +02:00
Johan Hedberg
1de8e9c1c5 Bluetooth: Host: L2CAP: Reject reconfiguration of non-dynamic CID
There was a missing check in le_ecred_reconf_req() that the provided CIDs
are dynamic (only those can be reconfigured). Add proper handling in case
a non-dynamic CID is encountered in the PDU.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-08 13:54:36 +02:00
Lyle Zhu
d64f781887 Bluetooth: host: fix unaligned access in LE LTK request event
The HCI LE LTK Request event parameters for `rand` and `ediv` should be
byte arrays, not integer types, to match the HCI specification and avoid
unaligned structure member access.

- Change `rand` from uint64_t to uint8_t[8]
- Change `ediv` from uint16_t to uint8_t[2]
- Add local variables in le_ltk_request() to convert byte arrays to
  integer types before passing to bt_smp_request_ltk()

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-08 10:38:01 +01:00
Lyle Zhu
b7599141fb Bluetooth: host: fix unaligned structure member access warnings
The HCI LE Start Encryption command parameters for `rand` and `ediv`
should be byte arrays, not integer types, to match the HCI specification
and avoid unaligned structure member access warnings.

- Change `rand` from uint64_t to uint8_t[8]
- Change `ediv` from uint16_t to uint8_t[2]
- Update memcpy calls to remove unnecessary address-of operators

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-08 10:38:01 +01:00
Johan Hedberg
41a7ab4e0d Bluetooth: Mesh: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(buf);
  buf = NULL;

with net_buf_drop(&buf) which performs both operations
atomically in a single step.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
a94eedce81 Bluetooth: Host: Use net_buf_drop() in complex init functions
In bt_set_adv_param() and bt_br_init(), response buffers were
unreferenced but the pointer left live for significant amounts of
subsequent code. Use net_buf_drop() to make the intent explicit and
guard against accidental use-after-free.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
110a2a7a12 Bluetooth: Classic: Shell: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(buf);
  buf = NULL;

with net_buf_drop(&buf) which performs both operations
atomically in a single step.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
4b8de276c1 Bluetooth: Classic: AVRCP: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(buf);
  buf = NULL;

with net_buf_drop(&buf) which performs both operations
atomically in a single step.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
8263d4db85 Bluetooth: Classic: Shell: PBAP: Use net_buf_drop() on error paths
g_pbap_app->tx_buf is a global struct member. On the error paths
the buffer was unconditionally unreferenced and cleared to NULL via
two separate statements with intervening code. Replace with
net_buf_drop() to combine both into a single atomic step.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
3259ed1f82 Bluetooth: Classic: L2CAP BR: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(br_chan->_sdu);
  br_chan->_sdu = NULL;

with net_buf_drop(&br_chan->_sdu) which performs both operations
atomically in a single step.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
c8e5352dcf Bluetooth: Classic: AVCTP: Use net_buf_drop() where applicable
Replace the if-guarded two-line pattern:

  if (avctp->reassembly_buf != NULL) {
          net_buf_unref(avctp->reassembly_buf);
          avctp->reassembly_buf = NULL;
  }

with net_buf_drop(&avctp->reassembly_buf) which performs both operations
atomically in a single step. The guard is unnecessary when there is no
other logic conditional on the pointer being non-NULL, because
net_buf_drop() handles a NULL pointer internally. Where the if-body
contains additional logging, the guard is kept.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
23ee3f8cbc Bluetooth: Classic: AVDTP: Use net_buf_drop() where applicable
Replace the if-guarded two-line pattern:

  if (session->reasm_buf != NULL) {
          net_buf_unref(session->reasm_buf);
          session->reasm_buf = NULL;
  }

with net_buf_drop(&session->reasm_buf) which performs both operations
atomically in a single step. The guard is unnecessary when there is no
other logic conditional on the pointer being non-NULL, because
net_buf_drop() handles a NULL pointer internally. Where the if-body
contains additional logging, the guard is kept.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
18295e62ae Bluetooth: Classic: SDP: Use net_buf_drop() where applicable
Replace the if-guarded two-line pattern:

  if (session->rec_buf != NULL) {
          net_buf_unref(session->rec_buf);
          session->rec_buf = NULL;
  }

with net_buf_drop(&session->rec_buf) which performs both operations
atomically in a single step. The guard is unnecessary because
net_buf_drop() handles a NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
66a137aeb5 Bluetooth: CS: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(*buf);
  *buf = NULL;

with net_buf_drop(buf) which performs both operations atomically in a
single step.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
b44119e28e Bluetooth: GATT: Use net_buf_drop() where applicable
Replace the if-guarded two-line pattern:

  if (*buf) {
          net_buf_unref(*buf);
          *buf = NULL;
  }

with net_buf_drop(buf) which performs both operations atomically in a
single step. The guard is unnecessary because net_buf_drop() handles a
NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
f5ae7737f1 Bluetooth: ATT: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(buf);
  buf = NULL;

(and equivalent if-guarded variants) with net_buf_drop(&buf) which
performs both operations atomically in a single step. The guard is
unnecessary because net_buf_drop() handles a NULL pointer internally.

Assisted-by: GitHub Copilot:claude-opus-4.7
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
2a7b1c60a7 Bluetooth: L2CAP: Use net_buf_drop() where applicable
Replace the two-line pattern:

  net_buf_unref(buf);
  buf = NULL;

with net_buf_drop(&buf) which performs both operations
atomically in a single step.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Johan Hedberg
85fa4fa455 Bluetooth: Host: Take advantage of net_buf_drop()
Simplify places which can take advantage of the new net_buf_drop() API.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-07 19:19:47 +02:00
Hayden Ball
dfdea9bad8 Bluetooth: Host: Fix use-after-free in bt_att_sent on disconnect
When the peer disconnects mid-transfer, the bt_att and bt_att_chan are
freed (att_chan_detach()/att_reset(), then bt_att_released()) while a
deferred unenhanced-ATT "sent" callback is still queued on the system
workqueue: the ATT TX buffer destroy work runs att_on_sent_cb() ->
bt_att_sent(), which dereferences the freed context and bus-faults in
sys_slist_get(&att->reqs).

att_on_sent_cb() already guards against a detached bearer, but it does
so by dereferencing meta->att_chan, which by then is a dangling pointer
(and faults once the channel slab slot has been reused).

Null any pending ATT TX metadata referencing the channel in
bt_att_released(), before the channel is freed, so the guard drops the
deferred callback instead of dereferencing freed memory. Teardown and
the destroy work both run on the cooperative system workqueue, so this
is serialized and needs no lock.

Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Hayden Ball <hayden@playerdata.com>
2026-06-05 13:22:43 +02:00
Aleksandr Khromykh
49825e90b2 Bluetooth: Mesh: Shell: Add LPN timing statistic commands
Add shell commands to retrieve and clear LPN friendship timing
statistics. Available as mesh stat lpn_get and mesh stat lpn_clear
when CONFIG_BT_MESH_LOW_POWER is enabled. Rename existing frame
statistic commands to mesh stat adv_get and mesh stat adv_clear.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-06-04 18:19:02 +02:00
Aleksandr Khromykh
f759749446 Bluetooth: Mesh: Add LPN friendship timing measurement
Add timestamp-based measurement of LPN friendship timing parameters
(ReceiveDelay and ReceiveWindow) to the statistic module. Timestamps
are captured at poll TX end, scanner enable, and response RX/timeout
using k_uptime_ticks(). Measured values are stored in microseconds.

Instrument the LPN state machine in lpn.c to call the statistic
update functions at each protocol event.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2026-06-04 18:19:02 +02:00
Johan Hedberg
91f9bf6d6d Bluetooth: Remove error return from bt_hci_recv()
Most HCI drivers have never handled the return value from the
driver-to-host receive path in any way, and they haven't really needed to
either since the buffer was always consumed regardless of success or
failure.

To be aligned with Zephyr coding guidelines without having to add
minimal value code to every driver, change bt_hci_recv() to return void
instead. A new bt_hci_recv_err() API is also added for any use case where
access to the error is needed.

There's also a related semantic change to the recv callback (passed to
bt_hci_open()) in that it's now expected to *not* consume the buffer in
case of error. There was only a single place in the host that needed an
update for this, while e.g. HCI raw always returned success.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-04 08:40:14 +02:00
Johan Hedberg
2f3cd95376 drivers: bluetooth: Remove unnecessary driver data structs
There's no point in having driver specific data structs if the only thing
they contain is the common data struct. Just declare the common data struct
directly as dev->data.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-04 08:40:14 +02:00
Johan Hedberg
7f3c897f96 drivers: bluetooth: Handle recv() callback in common layer
Now that we have a common data struct, we can take advantage of it and
move the recv callback into it. This way the common layer takes care of
assigning, dispatching and clearing the callback. Drivers now have to use
the new bt_hci_recv() API to pass data to the layer above them (typically
a host stack). Additionally, the drivers no longer get a recv parameter as
part of their open() callback, since that's all handled by the common
layer.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-04 08:40:14 +02:00
Johan Hedberg
b35b74b8e0 Bluetooth: Host: Get rid of public bt_hci_recv functions
Make these static (no need to export them) and also name them in a way that
doesn't class with the HCI driver API prefix.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-04 08:40:14 +02:00
Johan Hedberg
c5420dc137 drivers: bluetooth: Add support for mandatory data/config fields
Add support for the new common data & config fields for all in-tree
drivers.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2026-06-04 08:40:14 +02:00
Gobi M
997186d57f Bluetooth: Mesh: Replace PDU access macros with static functions
Replace the local PDU access macros in net.c with static helper
functions.

Using functions avoids preprocessor namespace pollution from common
macro names such as SRC while preserving the same behavior. The
functions are local to net.c and are expected to be inlined by the
compiler, resulting in no functional change.

Fixes #109401

Signed-off-by: Gobi M <gobi@aerlync.com>
2026-06-03 08:09:47 -05:00
Lingao Meng
f573da9f53 Bluetooth: Mesh: fix PrivateBeaconKey PSA key leak on subnet delete
subnet_keys_destroy() guarded the destroy of keys->priv_beacon with
#if defined(CONFIG_BT_MESH_V1d1), while net_keys_create() guards the
matching import with #if defined(CONFIG_BT_MESH_PRIV_BEACONS).

Commit 981c79b7ce ("Bluetooth: Mesh: Drop explicit support for
Bluetooth Mesh 1.0.1") removed the CONFIG_BT_MESH_V1d1 Kconfig but
left this stray reference behind. With V1d1 gone, the destroy branch
is permanently dead code, so every successful net_keys_create() leaks
one PSA key slot.

In a long-running test that repeatedly provisions and resets a node
(no persistent settings, in-RAM CDB only), the leak accumulates one
PSA volatile-key slot per provisioning round. With the default
CONFIG_MBEDTLS_PSA_KEY_SLOT_COUNT=16, bt_mesh_private_beacon_key()
fails after ~12 rounds with:

  <err> bt_mesh_net_keys: Unable to generate private beacon key
  <err> bt_mesh_net: Failed creating subnet
  <err> bt_mesh_main: Failed to create network

Align the destroy guard with the import guard so the leak goes away.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-06-03 13:05:17 +02:00
Thomas Hebb
68a329a70b style: Fix various typos across the tree
Some of these are in user-visible log messages, but none are breaking
changes for applications.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
2026-06-03 08:26:41 +02:00
Lyle Zhu
84d2fbb0bd bluetooth: host: classic: l2cap_br: Fix S-frame sending priority
The S-frame should only be sent when there are no I-frames to be sent,
as I-frames have higher priority. Previously, the S-frame flag was
checked in the same condition as other flags, which could cause S-frames
to be sent even when I-frames were available.

Fix by moving the S-frame check to a separate condition that first
verifies no I-frames are pending via `l2cap_br_send_i_frame()`. Also
move the clearing of `L2CAP_FLAG_SEND_S_FRAME` to the end of the
function to ensure it is cleared after any frame is sent, not just
when an S-frame is explicitly sent.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:42 +02:00
Lyle Zhu
da34235053 bluetooth: classic: goep: introduce init macros for transport setup
Introduce the helper macros `BT_GOEP_INIT_V1` and `BT_GOEP_INIT_V2`
to simplify and standardize GOEP and GOEP transport initialization for
the upper layer.

Add two new initialization macros that encapsulate the repetitive
pattern of setting up mutual back-pointers between `bt_goep` instances
and related GOEP version-specific transport structures:

- `BT_GOEP_INIT_V1`: Initializes GOEP v1 (RFCOMM) transport by setting
  the back-pointer from transport to GOEP, assigning the v1 pointer,
  and clearing the v2 pointer.

- `BT_GOEP_INIT_V2`: Initializes GOEP v2 (L2CAP) transport by setting
  the back-pointer from transport to GOEP, assigning the v2 pointer,
  and clearing the v1 pointer.

And adding type checking via `BUILD_ASSERT` and `SAME_TYPE` in these
two macros to ensure type consistent in building time.

Update all GOEP-based profiles (BIP, PBAP, MAP) and shell code to use
these new added macros.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:20 +02:00
Lyle Zhu
8f4df5f94a bluetooth: classic: goep: introduce unified transport structure
Introduce a unified `bt_goep_transport` structure to simplify GOEP
transport handling across all profiles.

The added new `bt_goep_transport` structure contains both `v1` and
`v2` transport instances. The upper layer profiles could include the
structure instead of requiring separate structure members when both
GOEP V1.1 and V2 transport are required at the same time.

Update all GOEP-based profiles (BIP, PBAP, MAP) and shell code to use
the unified `goep_transport` structure member instead of separate
`goep_transport_v1` and `goep_transport_v2` members. This reduces code
duplication and provides a consistent pattern across all profiles.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:20 +02:00
Lyle Zhu
a6f92a05dd bluetooth: classic: pbap: support GOEP v1/v2 transport structures
Add explicit GOEP v1 and v2 transport structures to PBAP instances
to support the refactored GOEP transport version handling.

Add `bt_goep_transport_v1` and `bt_goep_transport_v2` structure
members to both PBAP client (PCE) and server (PSE) instance types to
align with the refactored GOEP transport handling that uses explicit
version pointers instead of a boolean flag and union.

Initialize the appropriate v1 or v2 structure and set the
corresponding pointer in the parent GOEP instance based on the
transport type (RFCOMM for v1, L2CAP for v2) during connection
establishment and accept operations.

Add NULL parameter validation in PSE accept functions to prevent
potential null pointer dereferences before initializing the GOEP
transport structures.

The change completes the PBAP integration with the new GOEP transport
architecture.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:20 +02:00
Lyle Zhu
80e696f639 bluetooth: classic: map: support GOEP v1/v2 transport structures
Add explicit GOEP v1 and v2 transport structures to MAP instances
to support the refactored GOEP transport version handling.

Add `bt_goep_transport_v1` and `bt_goep_transport_v2` structure
members to all MAP instance types (MCE MAS, MCE MNS, MSE MAS, MSE
MNS) to align with the refactored GOEP transport handling that uses
explicit version pointers instead of a boolean flag and union.

Initialize the appropriate v1 or v2 structure and set the
corresponding pointer in the parent GOEP instance based on the
transport type (RFCOMM for v1, L2CAP for v2) during connection
establishment and accept operations.

The change completes the MAP integration with the new GOEP transport
architecture.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2026-06-03 08:25:20 +02:00