Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
l2cap.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2015-2016 Intel Corporation
7 * Copyright (c) 2023 Nordic Semiconductor
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11#ifndef ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_
12#define ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_
13
21#include <sys/types.h>
22
23#include <zephyr/sys/atomic.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
33#define BT_L2CAP_HDR_SIZE 4
34
36#define BT_L2CAP_TX_MTU (CONFIG_BT_L2CAP_TX_MTU)
37
39#define BT_L2CAP_RX_MTU (CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE)
40
48#define BT_L2CAP_BUF_SIZE(mtu) BT_BUF_ACL_SIZE(BT_L2CAP_HDR_SIZE + (mtu))
49
51#define BT_L2CAP_SDU_HDR_SIZE 2
52
61#define BT_L2CAP_SDU_TX_MTU (BT_L2CAP_TX_MTU - BT_L2CAP_SDU_HDR_SIZE)
62
73#define BT_L2CAP_SDU_RX_MTU (BT_L2CAP_RX_MTU - BT_L2CAP_SDU_HDR_SIZE)
74
84#define BT_L2CAP_SDU_BUF_SIZE(mtu) BT_L2CAP_BUF_SIZE(BT_L2CAP_SDU_HDR_SIZE + (mtu))
85
86struct bt_l2cap_chan;
87
93typedef void (*bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan);
94
118
120
125
132
135
136 /* Total number of status - must be at the end of the enum */
139
143 struct bt_conn *conn;
145 const struct bt_l2cap_chan_ops *ops;
148
150};
151
162};
163
181
184
195#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
197 struct net_buf *_sdu;
198 uint16_t _sdu_len;
199#if defined(CONFIG_BT_L2CAP_SEG_RECV)
200 uint16_t _sdu_len_done;
201#endif /* CONFIG_BT_L2CAP_SEG_RECV */
202
203 struct k_work rx_work;
204 struct k_fifo rx_queue;
205
208 uint16_t psm;
210 uint8_t ident;
211 bt_security_t required_sec_level;
212
213 /* Response Timeout eXpired (RTX) timer */
214 struct k_work_delayable rtx_work;
215 struct k_work_sync rtx_sync;
216#endif
217
219 sys_snode_t _pdu_ready;
221 atomic_t _pdu_ready_lock;
223 size_t _pdu_remaining;
224};
225
235#define BT_L2CAP_LE_CHAN(_ch) CONTAINER_OF(_ch, struct bt_l2cap_le_chan, chan)
236
243};
244
253 /* For internal use only */
255
262
263 /* Response Timeout eXpired (RTX) timer */
266
268 sys_snode_t _pdu_ready;
270 atomic_t _pdu_ready_lock;
272 struct k_fifo _pdu_tx_queue;
273};
274
284 void (*connected)(struct bt_l2cap_chan *chan);
285
294 void (*disconnected)(struct bt_l2cap_chan *chan);
295
311 void (*encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status);
312
324 struct net_buf *(*alloc_seg)(struct bt_l2cap_chan *chan);
325
338 struct net_buf *(*alloc_buf)(struct bt_l2cap_chan *chan);
339
353 int (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);
354
364 void (*sent)(struct bt_l2cap_chan *chan);
365
374 void (*status)(struct bt_l2cap_chan *chan, atomic_t *status);
375
376 /* @brief Channel released callback
377 *
378 * If this callback is set it is called when the stack has release all
379 * references to the channel object.
380 */
381 void (*released)(struct bt_l2cap_chan *chan);
382
391 void (*reconfigured)(struct bt_l2cap_chan *chan);
392
393#if defined(CONFIG_BT_L2CAP_SEG_RECV)
425 void (*seg_recv)(struct bt_l2cap_chan *chan, size_t sdu_len,
426 off_t seg_offset, struct net_buf_simple *seg);
427#endif /* CONFIG_BT_L2CAP_SEG_RECV */
428};
429
433#define BT_L2CAP_CHAN_SEND_RESERVE (BT_L2CAP_BUF_SIZE(0))
434
438#define BT_L2CAP_SDU_CHAN_SEND_RESERVE (BT_L2CAP_SDU_BUF_SIZE(0))
439
456
459
474 int (*accept)(struct bt_conn *conn, struct bt_l2cap_server *server,
475 struct bt_l2cap_chan **chan);
476
478};
479
500
512
526 struct bt_l2cap_chan **chans, uint16_t psm);
527
541
560int bt_l2cap_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
561 uint16_t psm);
562
575
616int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
617
639int bt_l2cap_chan_give_credits(struct bt_l2cap_chan *chan, uint16_t additional_credits);
640
654 struct net_buf *buf);
655
656#ifdef __cplusplus
657}
658#endif
659
664#endif /* ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_ */
long atomic_t
Definition: atomic_types.h:15
Bluetooth data buffer API.
Bluetooth connection handling.
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition: atomic.h:111
bt_security_t
Security level.
Definition: conn.h:408
int bt_l2cap_ecred_chan_reconfigure(struct bt_l2cap_chan **chans, uint16_t mtu)
Reconfigure Enhanced Credit Based L2CAP channels.
int bt_l2cap_server_register(struct bt_l2cap_server *server)
Register L2CAP server.
bt_l2cap_chan_status
Status of L2CAP channel.
Definition: l2cap.h:122
enum bt_l2cap_chan_status bt_l2cap_chan_status_t
Status of L2CAP channel.
int bt_l2cap_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan, uint16_t psm)
Connect L2CAP channel.
enum bt_l2cap_chan_state bt_l2cap_chan_state_t
Life-span states of L2CAP CoC channel.
int bt_l2cap_br_server_register(struct bt_l2cap_server *server)
Register L2CAP server on BR/EDR oriented connection.
bt_l2cap_chan_state
Life-span states of L2CAP CoC channel.
Definition: l2cap.h:107
int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan)
Disconnect L2CAP channel.
int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf)
Send data to L2CAP channel.
int bt_l2cap_chan_give_credits(struct bt_l2cap_chan *chan, uint16_t additional_credits)
Give credits to the remote.
int bt_l2cap_chan_recv_complete(struct bt_l2cap_chan *chan, struct net_buf *buf)
Complete receiving L2CAP channel data.
int bt_l2cap_ecred_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan **chans, uint16_t psm)
Connect Enhanced Credit Based L2CAP channels.
void(* bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan)
Channel destroy callback.
Definition: l2cap.h:93
@ BT_L2CAP_STATUS_SHUTDOWN
Channel shutdown status.
Definition: l2cap.h:131
@ BT_L2CAP_STATUS_OUT
Channel can send at least one PDU.
Definition: l2cap.h:124
@ BT_L2CAP_NUM_STATUS
Definition: l2cap.h:137
@ BT_L2CAP_STATUS_ENCRYPT_PENDING
Channel encryption pending status.
Definition: l2cap.h:134
@ BT_L2CAP_DISCONNECTED
Channel disconnected.
Definition: l2cap.h:109
@ BT_L2CAP_CONFIG
Channel in config state, BR/EDR specific.
Definition: l2cap.h:113
@ BT_L2CAP_CONNECTED
Channel ready for upper layer traffic on it.
Definition: l2cap.h:115
@ BT_L2CAP_DISCONNECTING
Channel in disconnecting state.
Definition: l2cap.h:117
@ BT_L2CAP_CONNECTING
Channel in connecting state.
Definition: l2cap.h:111
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
__INTPTR_TYPE__ off_t
Definition: types.h:36
flags
Definition: parser.h:96
state
Definition: parser_state.h:29
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
BREDR L2CAP Channel structure.
Definition: l2cap.h:246
struct bt_l2cap_br_endpoint rx
Channel Receiving Endpoint.
Definition: l2cap.h:250
struct k_work_delayable rtx_work
Definition: l2cap.h:264
bt_security_t required_sec_level
Definition: l2cap.h:261
uint16_t psm
Remote PSM to be connected.
Definition: l2cap.h:258
struct k_work_sync rtx_sync
Definition: l2cap.h:265
struct bt_l2cap_chan chan
Common L2CAP channel reference object.
Definition: l2cap.h:248
bt_l2cap_chan_state_t state
Definition: l2cap.h:256
struct bt_l2cap_br_endpoint tx
Channel Transmission Endpoint.
Definition: l2cap.h:252
uint8_t ident
Helps match request context during CoC.
Definition: l2cap.h:260
BREDR L2CAP Endpoint structure.
Definition: l2cap.h:238
uint16_t mtu
Endpoint Maximum Transmission Unit.
Definition: l2cap.h:242
uint16_t cid
Endpoint Channel Identifier (CID)
Definition: l2cap.h:240
L2CAP Channel operations structure.
Definition: l2cap.h:276
int(* recv)(struct bt_l2cap_chan *chan, struct net_buf *buf)
Channel recv callback.
Definition: l2cap.h:353
void(* encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status)
Channel encrypt_change callback.
Definition: l2cap.h:311
void(* disconnected)(struct bt_l2cap_chan *chan)
Channel disconnected callback.
Definition: l2cap.h:294
void(* connected)(struct bt_l2cap_chan *chan)
Channel connected callback.
Definition: l2cap.h:284
void(* status)(struct bt_l2cap_chan *chan, atomic_t *status)
Channel status callback.
Definition: l2cap.h:374
void(* released)(struct bt_l2cap_chan *chan)
Definition: l2cap.h:381
void(* sent)(struct bt_l2cap_chan *chan)
Channel sent callback.
Definition: l2cap.h:364
void(* seg_recv)(struct bt_l2cap_chan *chan, size_t sdu_len, off_t seg_offset, struct net_buf_simple *seg)
Handle L2CAP segments directly.
Definition: l2cap.h:425
void(* reconfigured)(struct bt_l2cap_chan *chan)
Channel reconfigured callback.
Definition: l2cap.h:391
L2CAP Channel structure.
Definition: l2cap.h:141
struct bt_conn * conn
Channel connection reference.
Definition: l2cap.h:143
sys_snode_t node
Definition: l2cap.h:146
const struct bt_l2cap_chan_ops * ops
Channel operations reference.
Definition: l2cap.h:145
atomic_t status[ATOMIC_BITMAP_SIZE(BT_L2CAP_NUM_STATUS)]
Definition: l2cap.h:149
bt_l2cap_chan_destroy_t destroy
Definition: l2cap.h:147
LE L2CAP Channel structure.
Definition: l2cap.h:165
struct bt_l2cap_le_endpoint tx
Channel Transmission Endpoint.
Definition: l2cap.h:192
uint16_t pending_rx_mtu
Pending RX MTU on ECFC reconfigure, used internally by stack.
Definition: l2cap.h:183
struct k_fifo tx_queue
Channel Transmission queue (for SDUs)
Definition: l2cap.h:194
struct bt_l2cap_le_endpoint rx
Channel Receiving Endpoint.
Definition: l2cap.h:180
struct bt_l2cap_chan chan
Common L2CAP channel reference object.
Definition: l2cap.h:167
LE L2CAP Endpoint structure.
Definition: l2cap.h:153
uint16_t mtu
Endpoint Maximum Transmission Unit.
Definition: l2cap.h:157
uint16_t mps
Endpoint Maximum PDU payload Size.
Definition: l2cap.h:159
atomic_t credits
Endpoint credits.
Definition: l2cap.h:161
uint16_t cid
Endpoint Channel Identifier (CID)
Definition: l2cap.h:155
L2CAP Server structure.
Definition: l2cap.h:441
uint16_t psm
Server PSM.
Definition: l2cap.h:455
sys_snode_t node
Definition: l2cap.h:477
bt_security_t sec_level
Required minimum security level.
Definition: l2cap.h:458
int(* accept)(struct bt_conn *conn, struct bt_l2cap_server *server, struct bt_l2cap_chan **chan)
Server accept callback.
Definition: l2cap.h:474
Definition: kernel.h:2388
A structure used to submit work after a delay.
Definition: kernel.h:3903
A structure holding internal state for a pending synchronous operation on a work item or queue.
Definition: kernel.h:3986
A structure used to submit work.
Definition: kernel.h:3875
Simple network buffer representation.
Definition: buf.h:87
Network buffer representation.
Definition: buf.h:1004