@@ -133,6 +133,120 @@ int bt_l2cap_br_echo_req(struct bt_conn *conn, struct net_buf *buf);
133
133
*/
134
134
int bt_l2cap_br_echo_rsp (struct bt_conn * conn , uint8_t identifier , struct net_buf * buf );
135
135
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
+
136
250
#ifdef __cplusplus
137
251
}
138
252
#endif
0 commit comments