Zephyr API 3.6.99
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 <stdint.h>
22#include <sys/types.h>
23
24#include <zephyr/sys/atomic.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
34#define BT_L2CAP_HDR_SIZE 4
35
37#define BT_L2CAP_TX_MTU (CONFIG_BT_L2CAP_TX_MTU)
38
40#define BT_L2CAP_RX_MTU (CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE)
41
49#define BT_L2CAP_BUF_SIZE(mtu) BT_BUF_ACL_SIZE(BT_L2CAP_HDR_SIZE + (mtu))
50
52#define BT_L2CAP_SDU_HDR_SIZE 2
53
62#define BT_L2CAP_SDU_TX_MTU (BT_L2CAP_TX_MTU - BT_L2CAP_SDU_HDR_SIZE)
63
74#define BT_L2CAP_SDU_RX_MTU (BT_L2CAP_RX_MTU - BT_L2CAP_SDU_HDR_SIZE)
75
85#define BT_L2CAP_SDU_BUF_SIZE(mtu) BT_L2CAP_BUF_SIZE(BT_L2CAP_SDU_HDR_SIZE + (mtu))
86
87struct bt_l2cap_chan;
88
94typedef void (*bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan);
95
121
126
133
136
137 /* Total number of status - must be at the end of the enum */
140
152
164
182
185
196#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
198 struct net_buf *_sdu;
199 uint16_t _sdu_len;
200#if defined(CONFIG_BT_L2CAP_SEG_RECV)
201 uint16_t _sdu_len_done;
202#endif /* CONFIG_BT_L2CAP_SEG_RECV */
203
204 struct k_work rx_work;
205 struct k_fifo rx_queue;
206
209 uint16_t psm;
211 uint8_t ident;
212 bt_security_t required_sec_level;
213
214 /* Response Timeout eXpired (RTX) timer */
215 struct k_work_delayable rtx_work;
216 struct k_work_sync rtx_sync;
217#endif
218
220 sys_snode_t _pdu_ready;
222 atomic_t _pdu_ready_lock;
224 size_t _pdu_remaining;
225};
226
236#define BT_L2CAP_LE_CHAN(_ch) CONTAINER_OF(_ch, struct bt_l2cap_le_chan, chan)
237
245
254 /* For internal use only */
256
263
264 /* Response Timeout eXpired (RTX) timer */
267
269 sys_snode_t _pdu_ready;
271 atomic_t _pdu_ready_lock;
273 struct k_fifo _pdu_tx_queue;
274};
275
288 void (*connected)(struct bt_l2cap_chan *chan);
289
298 void (*disconnected)(struct bt_l2cap_chan *chan);
299
315 void (*encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status);
316
328 struct net_buf *(*alloc_seg)(struct bt_l2cap_chan *chan);
329
342 struct net_buf *(*alloc_buf)(struct bt_l2cap_chan *chan);
343
361 int (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);
362
372 void (*sent)(struct bt_l2cap_chan *chan);
373
382 void (*status)(struct bt_l2cap_chan *chan, atomic_t *status);
383
384 /* @brief Channel released callback
385 *
386 * If this callback is set it is called when the stack has release all
387 * references to the channel object.
388 */
389 void (*released)(struct bt_l2cap_chan *chan);
390
399 void (*reconfigured)(struct bt_l2cap_chan *chan);
400
401#if defined(CONFIG_BT_L2CAP_SEG_RECV)
433 void (*seg_recv)(struct bt_l2cap_chan *chan, size_t sdu_len,
434 off_t seg_offset, struct net_buf_simple *seg);
435#endif /* CONFIG_BT_L2CAP_SEG_RECV */
436};
437
441#define BT_L2CAP_CHAN_SEND_RESERVE (BT_L2CAP_BUF_SIZE(0))
442
446#define BT_L2CAP_SDU_CHAN_SEND_RESERVE (BT_L2CAP_SDU_BUF_SIZE(0))
447
464
467
485 int (*accept)(struct bt_conn *conn, struct bt_l2cap_server *server,
486 struct bt_l2cap_chan **chan);
487
489};
490
511
523
540 struct bt_l2cap_chan **chans, uint16_t psm);
541
555
574 uint16_t mps);
575
597int bt_l2cap_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
598 uint16_t psm);
599
612
657int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
658
680int bt_l2cap_chan_give_credits(struct bt_l2cap_chan *chan, uint16_t additional_credits);
681
695 struct net_buf *buf);
696
697#ifdef __cplusplus
698}
699#endif
700
705#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:806
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:123
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:108
int bt_l2cap_chan_disconnect(struct bt_l2cap_chan *chan)
Disconnect L2CAP channel.
void(* bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan)
Channel destroy callback.
Definition l2cap.h:94
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.
int bt_l2cap_ecred_chan_reconfigure_explicit(struct bt_l2cap_chan **chans, uint16_t mtu, uint16_t mps)
Reconfigure Enhanced Credit Based L2CAP channels.
@ BT_L2CAP_STATUS_SHUTDOWN
Channel shutdown status.
Definition l2cap.h:132
@ BT_L2CAP_STATUS_OUT
Channel can send at least one PDU.
Definition l2cap.h:125
@ BT_L2CAP_NUM_STATUS
Definition l2cap.h:138
@ BT_L2CAP_STATUS_ENCRYPT_PENDING
Channel encryption pending status.
Definition l2cap.h:135
@ BT_L2CAP_DISCONNECTED
Channel disconnected.
Definition l2cap.h:110
@ BT_L2CAP_CONFIG
Channel in config state, BR/EDR specific.
Definition l2cap.h:114
@ BT_L2CAP_CONNECTED
Channel ready for upper layer traffic on it.
Definition l2cap.h:116
@ BT_L2CAP_DISCONNECTING
Channel in disconnecting state.
Definition l2cap.h:118
@ BT_L2CAP_CONNECTING
Channel in connecting state.
Definition l2cap.h:112
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:247
struct bt_l2cap_br_endpoint rx
Channel Receiving Endpoint.
Definition l2cap.h:251
struct k_work_delayable rtx_work
Definition l2cap.h:265
bt_security_t required_sec_level
Definition l2cap.h:262
uint16_t psm
Remote PSM to be connected.
Definition l2cap.h:259
struct k_work_sync rtx_sync
Definition l2cap.h:266
struct bt_l2cap_chan chan
Common L2CAP channel reference object.
Definition l2cap.h:249
bt_l2cap_chan_state_t state
Definition l2cap.h:257
struct bt_l2cap_br_endpoint tx
Channel Transmission Endpoint.
Definition l2cap.h:253
uint8_t ident
Helps match request context during CoC.
Definition l2cap.h:261
BREDR L2CAP Endpoint structure.
Definition l2cap.h:239
uint16_t mtu
Endpoint Maximum Transmission Unit.
Definition l2cap.h:243
uint16_t cid
Endpoint Channel Identifier (CID)
Definition l2cap.h:241
L2CAP Channel operations structure.
Definition l2cap.h:280
int(* recv)(struct bt_l2cap_chan *chan, struct net_buf *buf)
Channel recv callback.
Definition l2cap.h:361
void(* encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status)
Channel encrypt_change callback.
Definition l2cap.h:315
void(* disconnected)(struct bt_l2cap_chan *chan)
Channel disconnected callback.
Definition l2cap.h:298
void(* connected)(struct bt_l2cap_chan *chan)
Channel connected callback.
Definition l2cap.h:288
void(* status)(struct bt_l2cap_chan *chan, atomic_t *status)
Channel status callback.
Definition l2cap.h:382
void(* released)(struct bt_l2cap_chan *chan)
Definition l2cap.h:389
void(* sent)(struct bt_l2cap_chan *chan)
Channel sent callback.
Definition l2cap.h:372
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:433
void(* reconfigured)(struct bt_l2cap_chan *chan)
Channel reconfigured callback.
Definition l2cap.h:399
L2CAP Channel structure.
Definition l2cap.h:142
struct bt_conn * conn
Channel connection reference.
Definition l2cap.h:144
sys_snode_t node
Definition l2cap.h:147
const struct bt_l2cap_chan_ops * ops
Channel operations reference.
Definition l2cap.h:146
atomic_t status[ATOMIC_BITMAP_SIZE(BT_L2CAP_NUM_STATUS)]
Definition l2cap.h:150
bt_l2cap_chan_destroy_t destroy
Definition l2cap.h:148
LE L2CAP Channel structure.
Definition l2cap.h:166
struct bt_l2cap_le_endpoint tx
Channel Transmission Endpoint.
Definition l2cap.h:193
uint16_t pending_rx_mtu
Pending RX MTU on ECFC reconfigure, used internally by stack.
Definition l2cap.h:184
struct k_fifo tx_queue
Channel Transmission queue (for SDUs)
Definition l2cap.h:195
struct bt_l2cap_le_endpoint rx
Channel Receiving Endpoint.
Definition l2cap.h:181
struct bt_l2cap_chan chan
Common L2CAP channel reference object.
Definition l2cap.h:168
LE L2CAP Endpoint structure.
Definition l2cap.h:154
uint16_t mtu
Endpoint Maximum Transmission Unit.
Definition l2cap.h:158
uint16_t mps
Endpoint Maximum PDU payload Size.
Definition l2cap.h:160
atomic_t credits
Endpoint credits.
Definition l2cap.h:162
uint16_t cid
Endpoint Channel Identifier (CID)
Definition l2cap.h:156
L2CAP Server structure.
Definition l2cap.h:449
uint16_t psm
Server PSM.
Definition l2cap.h:463
sys_snode_t node
Definition l2cap.h:488
bt_security_t sec_level
Required minimum security level.
Definition l2cap.h:466
int(* accept)(struct bt_conn *conn, struct bt_l2cap_server *server, struct bt_l2cap_chan **chan)
Server accept callback.
Definition l2cap.h:485
Definition kernel.h:2468
A structure used to submit work after a delay.
Definition kernel.h:3985
A structure holding internal state for a pending synchronous operation on a work item or queue.
Definition kernel.h:4068
A structure used to submit work.
Definition kernel.h:3957
Simple network buffer representation.
Definition net_buf.h:89
Network buffer representation.
Definition net_buf.h:1006