Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9f9d965
Bluetooth: Host: L2CAP: Fix seg_recv call on SDU overflow
sjanc Oct 23, 2024
329f68c
Bluetooth: Tester: Use BT_L2CAP_SEG_RECV for L2CAP tests
alwa-nordic Nov 12, 2024
c7d38a7
Bluetooth: L2CAP_BR: Use LOG_WRN for not enough room in user_data
makeshi Dec 12, 2024
d584550
Bluetooth: L2CAP_BR: Support dynamic PSM allocation
lylezhu2012 Dec 26, 2024
0ae2891
Bluetooth: Host: Classic: Fix allocated PSM comparison
jhedberg Feb 9, 2025
2bcbf45
Bluetooth: L2CAP_BR: Adaptation of L2CAP PSM dynamic allocation for m…
chejinxian Oct 29, 2025
7f2852a
Bluetoth: Host: Fix buffer allocation warnings in system workqueue
jhedberg Feb 21, 2025
aad5762
Bluetooth: L2CAP_BR: Reject the conn req if sec levels do not match
lylezhu2012 Mar 7, 2025
7bd7111
Bluetooth: SSP: Fix MITM flag incorrect issue in pairing
lylezhu2012 Mar 7, 2025
ea7057a
Bluetooth: L2CAP_BR: Adapt `bt_l2cap_br_get_max_sec_level` to support…
chejinxian Oct 29, 2025
4515779
Bluetooth: l2CAP_BR: Fix the response cannot be sent out issue
lylezhu2012 Mar 7, 2025
09d0de9
Bluetooth: L2CAP_BR: CID of data sending is invalid
lylezhu2012 Nov 8, 2024
6fd3b74
Bluetooth: L2CAP_BR: Code format
lylezhu2012 Mar 12, 2025
8e282b3
Bluetooth: Host: Fix format specifier warnings
jhedberg Mar 18, 2025
b51e380
Bluetooth: L2CAP_BR: Enable Retransmission and Flow control
lylezhu2012 Sep 20, 2024
1a1d089
Bluetooth: L2CAP_BR: Add mode optional support
lylezhu2012 Nov 8, 2024
8916a16
Bluetooth: L2CAP_BR: Sending multiple SDU at same time
lylezhu2012 Feb 28, 2025
9d7e561
Bluetooth: Classic: L2CAP: Fix building warnings
lylezhu2012 Mar 24, 2025
a82ba01
Bluetooth: Classic: L2CAP: Discard the response with a invalid `ident`
lylezhu2012 Mar 26, 2025
658c930
Bluetooth: Classic: L2CAP: Support `L2CAP_COMMAND_REJECT_RSP`
lylezhu2012 Mar 26, 2025
d9766a3
Bluetooth: Classic: L2CAP: Set the BR chan identifier for PENDING Case
makeshi Apr 18, 2025
7126c28
Bluetooth: Classic: L2CAP: Fix the FCS incorrect issue
lylezhu2012 Apr 23, 2025
9dabfb9
Bluetooth: Classic: L2CAP: Make TxWindow size on both sides the same
lylezhu2012 Apr 23, 2025
2917a77
Bluetooth: Classic: L2CAP: Handle shorter data length of the request
lylezhu2012 Apr 22, 2025
6b61c5d
Bluetooth: Classic: L2CAP: Fix seg_recv cannot work issue
lylezhu2012 Apr 28, 2025
568112d
Bluetooth: Host: L2CAP: Fix checking signaling packets size
sjanc May 16, 2025
73a5b3e
Bluetooth: Classic: L2CAP: Disconn channel if proposed MTU is invalid
lylezhu2012 May 19, 2025
7f8b57a
Bluetooth: Classic: L2CAP: implement ECHO REQ/RSP
lylezhu2012 Apr 21, 2025
85c60a5
Bluetooth: Classic: L2CAP: Adapt echo request handling and update ide…
chejinxian Oct 30, 2025
c1cf1bb
Bluetooth: Classic: L2CAP: Support zero-length SDU in none basic mode
lylezhu2012 Apr 28, 2025
0b707e5
Bluetooth: Classic: L2CAP: Fix issue is received data len less than 2
lylezhu2012 Apr 28, 2025
fbeb55f
Bluetooth: L2CAP: Limit BR/EDR L2CAP RX MTU to configured value
jerryyang35 Jun 26, 2025
f30998a
bluetooth: fix bug when destroying tx queue buffers on disconnect
mjchen0 Mar 6, 2025
7416749
Bluetooth: Classic: L2CAP: Set default value for BR timer timeout
makeshi Jun 17, 2025
243d4a0
Bluetooth: Classic: L2CAP: Fix issue that pending chan cannot be sent
lylezhu2012 Jul 4, 2025
20618a9
Bluetooth: Classic: L2CAP: Fix retransmission timer restarting
lylezhu2012 Jul 4, 2025
aff2046
Bluetooth: host: L2CAP: Fix configuration parameters not be checked
CC0918 Jul 8, 2025
055f2fd
Bluetooth: Host: l2cap: Fix MPS/MTU confusion
HaavardRei Jul 15, 2025
9f8f4df
Bluetooth: L2CAP: add br l2cap unregister interface
chengkai15 Jul 3, 2025
b26d52b
Bluetooth: L2CAP: Add multi-controller support for BR server unregister.
chejinxian Oct 30, 2025
dd6fec7
bt: host: Use proper flexible array
ceolin Nov 25, 2024
0e5768c
Bluetooth: Host: Add l2cap credit param checks
HaavardRei Jul 22, 2025
f737447
Bluetooth: Host: Add conn rsp param check
HaavardRei Jul 16, 2025
9b8f5ab
Bluetooth: Host: Add req/rsp l2cap validation
HaavardRei Aug 7, 2025
8ac05b7
Bluetooth: Classic: L2CAP: Add connectionless data reception feature
lylezhu2012 May 20, 2025
978bc53
bluetooth: host: iterate over connections in TX list
aahmed-dewinelabs Jan 10, 2025
7b898a5
bluetooth: host: Use critical section when making channel ready to send
PavelVPV Aug 13, 2025
187ad4e
bt: host/classic: Use proper flexible array
ceolin Aug 29, 2025
920a5d8
Bluetooth: Classic: l2cap: Fix ACL conn invalid issue
lylezhu2012 Sep 8, 2025
2a89880
bluetooth: host: l2cap: fix issue that can't get chan by psm
CC0918 Sep 15, 2025
9c2d79e
bluetooth: l2cap: support the classic l2cap rx flush timeout
MarkWangChinese Sep 1, 2025
eb38a69
bluetooth: l2cap: accept the default flush timeout (0xFFFF) in conf_rsp
MarkWangChinese Sep 2, 2025
a21db20
Bluetooth: Host: Add userdefined fixed l2cap chans
HaavardRei Sep 9, 2025
6ecdeaf
Bluetooth: Host: Add documentation for L2CAP tx buffer callbacks
alwa-nordic Oct 16, 2025
8c63514
Bluetooth: Host: Invoke tx callbacks when channel is deleted
alwa-nordic Oct 16, 2025
908fc94
Bluetooth: Host: Update L2CAP fixed channel extern declarations for c…
chejinxian Nov 3, 2025
0222a28
Bluetooth: Host: Update configuration macros and comment out unused s…
chejinxian Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions doc/connectivity/bluetooth/api/l2cap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,45 @@
Logical Link Control and Adaptation Protocol (L2CAP)
####################################################

L2CAP layer enables connection-oriented channels which can be enable with the
configuration option: :kconfig:option:`CONFIG_BT_L2CAP_DYNAMIC_CHANNEL`. This channels
L2CAP layer enables connection-oriented channels which can be enabled with the
configuration option: :kconfig:option:`CONFIG_BT_L2CAP_DYNAMIC_CHANNEL`. These channels
support segmentation and reassembly transparently, they also support credit
based flow control making it suitable for data streams.

The user can also define fixed channels using the :c:macro:`BT_L2CAP_FIXED_CHANNEL_DEFINE`
macro. Fixed channels are initialized upon connection, and do not support segmentation. An example
of how to define a fixed channel is shown below.

.. code-block:: c

static struct bt_l2cap_chan fixed_chan[CONFIG_BT_MAX_CONN];

/* Callbacks are assumed to be defined prior. */
static struct bt_l2cap_chan_ops ops = {
.recv = recv_cb,
.sent = sent_cb,
.connected = connected_cb,
.disconnected = disconnected_cb,
};

static int l2cap_fixed_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan)
{
uint8_t conn_index = bt_conn_index(conn);

*chan = &fixed_chan[conn_index];

**chan = (struct bt_l2cap_chan){
.ops = &ops,
};

return 0;
}

BT_L2CAP_FIXED_CHANNEL_DEFINE(fixed_channel) = {
.cid = 0x0010,
.accept = l2cap_fixed_accept,
};

Channels instances are represented by the :c:struct:`bt_l2cap_chan` struct which
contains the callbacks in the :c:struct:`bt_l2cap_chan_ops` struct to inform
when the channel has been connected, disconnected or when the encryption has
Expand Down
258 changes: 258 additions & 0 deletions include/zephyr/bluetooth/classic/l2cap_br.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
/** @file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* @brief Bluetooth L2CAP BR/EDR handling
*/

/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_BR_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_BR_H_

/**
* @brief L2CAP
* @defgroup bt_l2cap L2CAP
* @ingroup bluetooth
* @{
*/

#include <stddef.h>
#include <stdint.h>

#include <zephyr/bluetooth/buf.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/kernel.h>
#include <zephyr/net_buf.h>
#include <zephyr/sys/atomic.h>
#include <zephyr/sys/slist.h>
#include <zephyr/sys/util.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief ECHO request/response callback structure.
*
* This structure is used for tracking the ECHO request/response signaling packets of L2CAP BR.
* It is registered with the help of the bt_l2cap_br_echo_cb_register() API.
* It's permissible to register multiple instances of this @ref bt_l2cap_br_echo_cb type, in case
* different modules of an application are interested in tracking the ECHO request/response
* signaling packets. If a callback is not of interest for an instance, it may be set to NULL and
* will as a consequence not be used for that instance.
*/
struct bt_l2cap_br_echo_cb {
/**
* @brief A ECHO request has been received.
*
* This callback notifies the application of a ECHO request has been received.
* The ECHO response should be performed by calling the bt_l2cap_br_echo_rsp() API.
*
* @param conn The ACL connection object.
* @param identifier The identifier of the ECHO request.
* @param buf Received ECHO data.
*/
void (*req)(struct bt_conn *conn, uint8_t identifier, struct net_buf *buf);

/**
* @brief A ECHO response has been received.
*
* This callback notifies the application of a ECHO response has been received.
*
* @param conn The ACL connection object.
* @param buf Received ECHO data.
*/
void (*rsp)(struct bt_conn *conn, struct net_buf *buf);

/** @internal Internally used field for list handling */
sys_snode_t _node;
};

/**
* @brief Register ECHO callbacks.
*
* Register callbacks to monitor the packets of L2CAP BR echo request/response.
*
* @param cb Callback struct. Must point to memory that remains valid.
*
* @retval 0 Success.
* @retval -EEXIST if @p cb was already registered.
*/
int bt_l2cap_br_echo_cb_register(struct bt_l2cap_br_echo_cb *cb);
Copy link
Contributor

@gzh-terry gzh-terry Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "echo" the only callback for L2CAP BR?
I though it might be better if we have an bt_l2cap_br_register_cb, where echo_req and echo_rsp shall be the members.


/**
* @brief Unregister ECHO callbacks.
*
* Unregister callbacks that are used to monitor the packets of L2CAP BR echo request/response.
*
* @param cb Callback struct point to memory that remains valid.
*
* @retval 0 Success.
* @retval -EINVAL If @p cb is NULL.
* @retval -ENOENT if @p cb was not registered.
*/
int bt_l2cap_br_echo_cb_unregister(struct bt_l2cap_br_echo_cb *cb);

/**
* @brief Headroom needed for outgoing L2CAP ECHO REQ PDUs.
*/
#define BT_L2CAP_BR_ECHO_REQ_RESERVE BT_L2CAP_BUF_SIZE(4)

/**
* @brief Headroom needed for outgoing L2CAP ECHO RSP PDUs.
*/
#define BT_L2CAP_BR_ECHO_RSP_RESERVE BT_L2CAP_BUF_SIZE(4)

/**
* @brief Send ECHO data through ECHO request
*
* Send ECHO data through ECHO request. The application is required to have reserved
* @ref BT_L2CAP_BR_ECHO_REQ_RESERVE bytes in the buffer before sending.
*
* @param conn The ACL connection object.
* @param buf Sending ECHO data.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_l2cap_br_echo_req(struct bt_conn *conn, struct net_buf *buf);

/**
* @brief Send ECHO data through ECHO response
*
* Send ECHO data through ECHO response. The application is required to have reserved
* @ref BT_L2CAP_BR_ECHO_RSP_RESERVE bytes in the buffer before sending.
*
* @param conn The ACL connection object.
* @param identifier The identifier of the ECHO request.
* @param buf Sending ECHO data.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_l2cap_br_echo_rsp(struct bt_conn *conn, uint8_t identifier, struct net_buf *buf);

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* @brief Connectionless data channel callback structure.
*
* This structure is used for tracking the connectionless data channel frames.
* It is registered with the help of the bt_l2cap_br_connless_register() API.
* It's permissible to register multiple instances of this @ref bt_l2cap_br_connless_cb type,
* in case different modules of an application are interested in tracking the connectionless
* data channel frames.
*/
struct bt_l2cap_br_connless_cb {
/** @brief Register PSM.
*
* For BR, possible values:
*
* The PSM field is at least two octets in length. All PSM values shall have the least
* significant bit of the most significant octet equal to 0 and the least significant bit
* of all other octets equal to 1.
*
* 0 Any connectionless data channel frame will be notified.
*
* 0x0001-0x0eff Standard, Bluetooth SIG-assigned fixed values.
*
* > 0x1000 Dynamically allocated. May be pre-set by the
* application before server registration (not
* recommended however), or auto-allocated by the
* stack if the app gave 0 as the value.
*/
uint16_t psm;

/** Required minimum security level */
bt_security_t sec_level;

/**
* @brief A connectionless channel data has been received.
*
* This callback notifies the application of a connectionless channel data has been
* received.
*
* @param conn The ACL connection object.
* @param psm Protocol/Service Multiplexer.
* @param buf Received connectionless channel data.
*/
void (*recv)(struct bt_conn *conn, uint16_t psm, struct net_buf *buf);

/** @internal Internally used field for list handling */
sys_snode_t _node;
};

/**
* @brief Register connectionless data channel callbacks.
*
* Register callbacks to monitor and receive connectionless data channel frames.
* This allows the application to receive data sent to a specific PSM without
* establishing a connection.
*
* @param cb Callback struct. Must point to memory that remains valid.
* The PSM field must be set to the desired Protocol/Service Multiplexer
* value, or 0 to receive all connectionless data frames.
*
* @retval 0 Success.
* @retval -EINVAL If @p cb is NULL, has invalid PSM value, has invalid `recv` callback,
* or has invalid security level.
* @retval -EEXIST If a callback with the same PSM was already registered.
*/
int bt_l2cap_br_connless_register(struct bt_l2cap_br_connless_cb *cb);

/**
* @brief Unregister connectionless data channel callbacks.
*
* Unregister callbacks that are used to monitor and receive connectionless data channel frames.
*
* @param cb Registered cb.
*
* @retval 0 Success.
* @retval -EINVAL If @p cb is NULL.
* @retval -ENOENT if @p cb was not registered.
*/
int bt_l2cap_br_connless_unregister(struct bt_l2cap_br_connless_cb *cb);

/**
* @brief L2CAP connectionless SDU header size.
*/
#define BT_L2CAP_CONNLESS_SDU_HDR_SIZE 2

/**
* @brief Headroom needed for outgoing L2CAP PDU format within a connectionless data channel.
*/
#define BT_L2CAP_CONNLESS_RESERVE BT_L2CAP_BUF_SIZE(BT_L2CAP_CONNLESS_SDU_HDR_SIZE)

/**
* @brief Send data over connectionless data channel
*
* Send data over a connectionless data channel. This function allows sending data to
* a specific PSM without establishing the L2CAP channel connection.
*
* The application is required to have reserved @ref BT_L2CAP_CONNLESS_RESERVE bytes
* in the buffer before sending.
*
* @param conn Connection object.
* @param psm Protocol/Service Multiplexer identifying the destination service.
* @param buf Buffer containing the data to be sent. The application is required to
* have reserved enough headroom in the buffer for the L2CAP header.
*
* @retval 0 Success.
* @retval -EINVAL If @p conn or @p buf is NULL, @p psm is invalid, the reference counter of @p buf
* != 1, the head room of @p buf is less than @ref BT_L2CAP_CONNLESS_RESERVE, or
* the `buf->user_data_size` is less than the size of `struct closure`.
* @return -ENOTSUP If the connectionless reception feature is unsupported by remote.
* @return -ENOTCONN If the L2CAP channel with connectionless channel is not found.
* @return -EMSGSIZE If the data size exceeds the peer's connectionless channel MTU.
* @retval -ESHUTDOWN If the L2CAP channel with connectionless channel is NULL in low level.
*/
int bt_l2cap_br_connless_send(struct bt_conn *conn, uint16_t psm, struct net_buf *buf);

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_BR_H_ */
Loading