Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: L2CAP: simplify codepath for SDU TX #67212

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions doc/releases/migration-guide-3.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ Bluetooth
Any pointer to a UUID must be prefixed with `const`, otherwise there will be a compilation warning.
For example change ``struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)`` to
``const struct bt_uuid *uuid = BT_UUID_DECLARE_16(xx)``. (:github:`66136`)
* The :c:func:`bt_l2cap_chan_send` API now doesn't return the number of bytes sent.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should go in the change log. Also add that it never returned anything useful.

* The :c:func:`bt_l2cap_chan_send` API now requires the application to reserve
enough bytes for the L2CAP headers. Call ``net_buf_reserve(buf,
BT_L2CAP_SDU_CHAN_SEND_RESERVE);`` to do so.

* Mesh

Expand Down
29 changes: 18 additions & 11 deletions include/zephyr/bluetooth/l2cap.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,22 +579,29 @@ int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan);
* size the buffers for the for the outgoing buffer pool.
*
* When sending L2CAP data over an LE connection the application is sending
* L2CAP SDUs. The application can optionally reserve
* L2CAP SDUs. The application shall reserve
* @ref BT_L2CAP_SDU_CHAN_SEND_RESERVE bytes in the buffer before sending.
* By reserving bytes in the buffer the stack can use this buffer as a segment
* directly, otherwise it will have to allocate a new segment for the first
* segment.
* If the application is reserving the bytes it should use the
* BT_L2CAP_BUF_SIZE() helper to correctly size the buffers for the for the
* outgoing buffer pool.
* When segmenting an L2CAP SDU into L2CAP PDUs the stack will first attempt
* to allocate buffers from the original buffer pool of the L2CAP SDU before
* using the stacks own buffer pool.
*
* The application can use the BT_L2CAP_SDU_BUF_SIZE() helper to correctly size
* the buffers for the outgoing buffer pool.
Comment on lines +585 to +586
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* The application can use the BT_L2CAP_SDU_BUF_SIZE() helper to correctly size
* the buffers for the outgoing buffer pool.
* The application can use the BT_L2CAP_SDU_BUF_SIZE() helper to correctly size
* the buffers to account for the reserved headroom.

*
* When segmenting an L2CAP SDU into L2CAP PDUs the stack will first attempt to
* allocate buffers from the channel's `alloc_seg` callback and will fallback
* on the stack's global buffer pool (sized
* @kconfig{CONFIG_BT_L2CAP_TX_BUF_COUNT}).
*
* @note Buffer ownership is transferred to the stack in case of success, in
* case of an error the caller retains the ownership of the buffer.
*
* @return Bytes sent in case of success or negative value in case of error.
* @return 0 in case of success or negative value in case of error. See below.
* @return -EINVAL if `buf` or `chan` is NULL.
Copy link
Collaborator

Choose a reason for hiding this comment

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

retval

* @return -EINVAL if `chan` is not either BR/EDR or LE credit-based.
* @return -EINVAL if buffer doesn't have enough bytes reserved to fit header.
* @return -ENOBUFS if L2CAP TX context couldn't be allocated. Retry later.
* @return -EMSGSIZE if `buf` is larger than `chan`'s MTU.
* @return -ENOTCONN if underlying conn is disconnected.
* @return -ESHUTDOWN if L2CAP channel is disconnected.
* @return a negative value on error (from lower layers) if chan is BR/EDR.
*/
int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);

Expand Down
Loading
Loading