Skip to content

Commit 0b3f572

Browse files
lylezhu2012jhedberg
authored andcommitted
Bluetooth: Classic: L2CAP: Add connectionless data reception feature
Add a Kconfig `BT_L2CAP_CONNLESS` to enable the feature. Add an API `bt_l2cap_br_connless_register()` to register the monitor to receive the unicast connectionless data. Add an API `bt_l2cap_br_connless_unregister()` to unregister the registered callbacks. Add an API `bt_l2cap_br_connless_send()` to send unicast connectionless data. Signed-off-by: Lyle Zhu <[email protected]>
1 parent d77b58a commit 0b3f572

File tree

4 files changed

+362
-2
lines changed

4 files changed

+362
-2
lines changed

include/zephyr/bluetooth/classic/l2cap_br.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,120 @@ int bt_l2cap_br_echo_req(struct bt_conn *conn, struct net_buf *buf);
133133
*/
134134
int bt_l2cap_br_echo_rsp(struct bt_conn *conn, uint8_t identifier, struct net_buf *buf);
135135

136+
/**
137+
* @brief Connectionless data channel callback structure.
138+
*
139+
* This structure is used for tracking the connectionless data channel frames.
140+
* It is registered with the help of the bt_l2cap_br_connless_register() API.
141+
* It's permissible to register multiple instances of this @ref bt_l2cap_br_connless_cb type,
142+
* in case different modules of an application are interested in tracking the connectionless
143+
* data channel frames.
144+
*/
145+
struct bt_l2cap_br_connless_cb {
146+
/** @brief Register PSM.
147+
*
148+
* For BR, possible values:
149+
*
150+
* The PSM field is at least two octets in length. All PSM values shall have the least
151+
* significant bit of the most significant octet equal to 0 and the least significant bit
152+
* of all other octets equal to 1.
153+
*
154+
* 0 Any connectionless data channel frame will be notified.
155+
*
156+
* 0x0001-0x0eff Standard, Bluetooth SIG-assigned fixed values.
157+
*
158+
* > 0x1000 Dynamically allocated. May be pre-set by the
159+
* application before server registration (not
160+
* recommended however), or auto-allocated by the
161+
* stack if the app gave 0 as the value.
162+
*/
163+
uint16_t psm;
164+
165+
/** Required minimum security level */
166+
bt_security_t sec_level;
167+
168+
/**
169+
* @brief A connectionless channel data has been received.
170+
*
171+
* This callback notifies the application of a connectionless channel data has been
172+
* received.
173+
*
174+
* @param conn The ACL connection object.
175+
* @param psm Protocol/Service Multiplexer.
176+
* @param buf Received connectionless channel data.
177+
*/
178+
void (*recv)(struct bt_conn *conn, uint16_t psm, struct net_buf *buf);
179+
180+
/** @internal Internally used field for list handling */
181+
sys_snode_t _node;
182+
};
183+
184+
/**
185+
* @brief Register connectionless data channel callbacks.
186+
*
187+
* Register callbacks to monitor and receive connectionless data channel frames.
188+
* This allows the application to receive data sent to a specific PSM without
189+
* establishing a connection.
190+
*
191+
* @param cb Callback struct. Must point to memory that remains valid.
192+
* The PSM field must be set to the desired Protocol/Service Multiplexer
193+
* value, or 0 to receive all connectionless data frames.
194+
*
195+
* @retval 0 Success.
196+
* @retval -EINVAL If @p cb is NULL, has invalid PSM value, has invalid `recv` callback,
197+
* or has invalid security level.
198+
* @retval -EEXIST If a callback with the same PSM was already registered.
199+
*/
200+
int bt_l2cap_br_connless_register(struct bt_l2cap_br_connless_cb *cb);
201+
202+
/**
203+
* @brief Unregister connectionless data channel callbacks.
204+
*
205+
* Unregister callbacks that are used to monitor and receive connectionless data channel frames.
206+
*
207+
* @param cb Registered cb.
208+
*
209+
* @retval 0 Success.
210+
* @retval -EINVAL If @p cb is NULL.
211+
* @retval -ENOENT if @p cb was not registered.
212+
*/
213+
int bt_l2cap_br_connless_unregister(struct bt_l2cap_br_connless_cb *cb);
214+
215+
/**
216+
* @brief L2CAP connectionless SDU header size.
217+
*/
218+
#define BT_L2CAP_CONNLESS_SDU_HDR_SIZE 2
219+
220+
/**
221+
* @brief Headroom needed for outgoing L2CAP PDU format within a connectionless data channel.
222+
*/
223+
#define BT_L2CAP_CONNLESS_RESERVE BT_L2CAP_BUF_SIZE(BT_L2CAP_CONNLESS_SDU_HDR_SIZE)
224+
225+
/**
226+
* @brief Send data over connectionless data channel
227+
*
228+
* Send data over a connectionless data channel. This function allows sending data to
229+
* a specific PSM without establishing the L2CAP channel connection.
230+
*
231+
* The application is required to have reserved @ref BT_L2CAP_CONNLESS_RESERVE bytes
232+
* in the buffer before sending.
233+
*
234+
* @param conn Connection object.
235+
* @param psm Protocol/Service Multiplexer identifying the destination service.
236+
* @param buf Buffer containing the data to be sent. The application is required to
237+
* have reserved enough headroom in the buffer for the L2CAP header.
238+
*
239+
* @retval 0 Success.
240+
* @retval -EINVAL If @p conn or @p buf is NULL, @p psm is invalid, the reference counter of @p buf
241+
* != 1, the head room of @p buf is less than @ref BT_L2CAP_CONNLESS_RESERVE, or
242+
* the `buf->user_data_size` is less than the size of `struct closure`.
243+
* @return -ENOTSUP If the connectionless reception feature is unsupported by remote.
244+
* @return -ENOTCONN If the L2CAP channel with connectionless channel is not found.
245+
* @return -EMSGSIZE If the data size exceeds the peer's connectionless channel MTU.
246+
* @retval -ESHUTDOWN If the L2CAP channel with connectionless channel is NULL in low level.
247+
*/
248+
int bt_l2cap_br_connless_send(struct bt_conn *conn, uint16_t psm, struct net_buf *buf);
249+
136250
#ifdef __cplusplus
137251
}
138252
#endif

subsys/bluetooth/host/classic/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ config BT_MAX_SCO_CONN
4444
Maximum number of simultaneous Bluetooth synchronous connections
4545
supported. The minimum (and default) number is 1.
4646

47+
config BT_L2CAP_CONNLESS
48+
bool "Bluetooth L2CAP connectionless data reception [EXPERIMENTAL]"
49+
select EXPERIMENTAL
50+
help
51+
This option enables Bluetooth L2CAP connectionless data reception
52+
4753
config BT_L2CAP_RET
4854
bool "Bluetooth L2CAP retransmission mode [EXPERIMENTAL]"
4955
select EXPERIMENTAL

0 commit comments

Comments
 (0)