Zephyr Project API  3.3.0
A Scalable Open Source RTOS
l2cap.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2015-2016 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_
11#define ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_
12
20#include <zephyr/sys/atomic.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
30#define BT_L2CAP_HDR_SIZE 4
31
33#define BT_L2CAP_TX_MTU (CONFIG_BT_L2CAP_TX_MTU)
34
36#define BT_L2CAP_RX_MTU (CONFIG_BT_BUF_ACL_RX_SIZE - BT_L2CAP_HDR_SIZE)
37
45#define BT_L2CAP_BUF_SIZE(mtu) BT_BUF_ACL_SIZE(BT_L2CAP_HDR_SIZE + (mtu))
46
48#define BT_L2CAP_SDU_HDR_SIZE 2
49
58#define BT_L2CAP_SDU_TX_MTU (BT_L2CAP_TX_MTU - BT_L2CAP_SDU_HDR_SIZE)
59
70#define BT_L2CAP_SDU_RX_MTU (BT_L2CAP_RX_MTU - BT_L2CAP_SDU_HDR_SIZE)
71
81#define BT_L2CAP_SDU_BUF_SIZE(mtu) BT_L2CAP_BUF_SIZE(BT_L2CAP_SDU_HDR_SIZE + (mtu))
82
83struct bt_l2cap_chan;
84
90typedef void (*bt_l2cap_chan_destroy_t)(struct bt_l2cap_chan *chan);
91
97typedef enum bt_l2cap_chan_state {
108
110
115
122
125
126 /* Total number of status - must be at the end of the enum */
129
133 struct bt_conn *conn;
135 const struct bt_l2cap_chan_ops *ops;
138
140};
141
154};
155
169
172
182 struct net_buf *_sdu;
183 uint16_t _sdu_len;
184
187
188#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
191 uint16_t psm;
193 uint8_t ident;
194 bt_security_t required_sec_level;
195
196 /* Response Timeout eXpired (RTX) timer */
197 struct k_work_delayable rtx_work;
198 struct k_work_sync rtx_sync;
199#endif
200};
201
211#define BT_L2CAP_LE_CHAN(_ch) CONTAINER_OF(_ch, struct bt_l2cap_le_chan, chan)
212
219};
220
229 /* For internal use only */
231
238
239 /* Response Timeout eXpired (RTX) timer */
242};
243
253 void (*connected)(struct bt_l2cap_chan *chan);
254
263 void (*disconnected)(struct bt_l2cap_chan *chan);
264
280 void (*encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status);
281
293 struct net_buf *(*alloc_seg)(struct bt_l2cap_chan *chan);
294
307 struct net_buf *(*alloc_buf)(struct bt_l2cap_chan *chan);
308
322 int (*recv)(struct bt_l2cap_chan *chan, struct net_buf *buf);
323
331 void (*sent)(struct bt_l2cap_chan *chan);
332
341 void (*status)(struct bt_l2cap_chan *chan, atomic_t *status);
342
343 /* @brief Channel released callback
344 *
345 * If this callback is set it is called when the stack has release all
346 * references to the channel object.
347 */
348 void (*released)(struct bt_l2cap_chan *chan);
349
358 void (*reconfigured)(struct bt_l2cap_chan *chan);
359};
360
364#define BT_L2CAP_CHAN_SEND_RESERVE (BT_L2CAP_BUF_SIZE(0))
365
369#define BT_L2CAP_SDU_CHAN_SEND_RESERVE (BT_L2CAP_SDU_BUF_SIZE(0))
370
387
390
404 int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan);
405
407};
408
429
441
455 struct bt_l2cap_chan **chans, uint16_t psm);
456
470
489int bt_l2cap_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
490 uint16_t psm);
491
504
536int bt_l2cap_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
537
551 struct net_buf *buf);
552
553#ifdef __cplusplus
554}
555#endif
556
561#endif /* ZEPHYR_INCLUDE_BLUETOOTH_L2CAP_H_ */
long atomic_t
Definition: atomic.h:22
Bluetooth data buffer API.
Bluetooth connection handling.
#define ATOMIC_DEFINE(name, num_bits)
Define an array of atomic variables.
Definition: atomic.h:114
bt_security_t
Definition: conn.h:339
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:112
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:97
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_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:90
@ BT_L2CAP_STATUS_SHUTDOWN
Channel shutdown status.
Definition: l2cap.h:121
@ BT_L2CAP_STATUS_OUT
Definition: l2cap.h:114
@ BT_L2CAP_NUM_STATUS
Definition: l2cap.h:127
@ BT_L2CAP_STATUS_ENCRYPT_PENDING
Channel encryption pending status.
Definition: l2cap.h:124
@ BT_L2CAP_DISCONNECTED
Definition: l2cap.h:99
@ BT_L2CAP_CONFIG
Definition: l2cap.h:103
@ BT_L2CAP_CONNECTED
Definition: l2cap.h:105
@ BT_L2CAP_DISCONNECTING
Definition: l2cap.h:107
@ BT_L2CAP_CONNECTING
Definition: l2cap.h:101
flags
Definition: parser.h:96
state
Definition: parser_state.h:29
struct _snode sys_snode_t
Definition: slist.h:33
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
BREDR L2CAP Channel structure.
Definition: l2cap.h:222
struct bt_l2cap_br_endpoint rx
Definition: l2cap.h:226
struct k_work_delayable rtx_work
Definition: l2cap.h:240
bt_security_t required_sec_level
Definition: l2cap.h:237
uint16_t psm
Definition: l2cap.h:234
struct k_work_sync rtx_sync
Definition: l2cap.h:241
struct bt_l2cap_chan chan
Definition: l2cap.h:224
bt_l2cap_chan_state_t state
Definition: l2cap.h:232
struct bt_l2cap_br_endpoint tx
Definition: l2cap.h:228
uint8_t ident
Definition: l2cap.h:236
BREDR L2CAP Endpoint structure.
Definition: l2cap.h:214
uint16_t mtu
Definition: l2cap.h:218
uint16_t cid
Definition: l2cap.h:216
L2CAP Channel operations structure.
Definition: l2cap.h:245
int(* recv)(struct bt_l2cap_chan *chan, struct net_buf *buf)
Channel recv callback.
Definition: l2cap.h:322
void(* encrypt_change)(struct bt_l2cap_chan *chan, uint8_t hci_status)
Channel encrypt_change callback.
Definition: l2cap.h:280
void(* disconnected)(struct bt_l2cap_chan *chan)
Channel disconnected callback.
Definition: l2cap.h:263
void(* connected)(struct bt_l2cap_chan *chan)
Channel connected callback.
Definition: l2cap.h:253
void(* status)(struct bt_l2cap_chan *chan, atomic_t *status)
Channel status callback.
Definition: l2cap.h:341
void(* released)(struct bt_l2cap_chan *chan)
Definition: l2cap.h:348
void(* sent)(struct bt_l2cap_chan *chan)
Channel sent callback.
Definition: l2cap.h:331
void(* reconfigured)(struct bt_l2cap_chan *chan)
Channel reconfigured callback.
Definition: l2cap.h:358
L2CAP Channel structure.
Definition: l2cap.h:131
struct bt_conn * conn
Definition: l2cap.h:133
sys_snode_t node
Definition: l2cap.h:136
const struct bt_l2cap_chan_ops * ops
Definition: l2cap.h:135
atomic_t status[ATOMIC_BITMAP_SIZE(BT_L2CAP_NUM_STATUS)]
Definition: l2cap.h:139
bt_l2cap_chan_destroy_t destroy
Definition: l2cap.h:137
LE L2CAP Channel structure.
Definition: l2cap.h:157
struct bt_l2cap_le_endpoint tx
Definition: l2cap.h:174
struct k_work rx_work
Definition: l2cap.h:185
uint16_t pending_rx_mtu
Definition: l2cap.h:171
struct k_fifo tx_queue
Definition: l2cap.h:176
struct bt_l2cap_le_endpoint rx
Channel Receiving Endpoint.
Definition: l2cap.h:168
struct bt_l2cap_chan chan
Definition: l2cap.h:159
struct k_fifo rx_queue
Definition: l2cap.h:186
struct k_work tx_work
Definition: l2cap.h:180
struct net_buf * tx_buf
Definition: l2cap.h:178
LE L2CAP Endpoint structure.
Definition: l2cap.h:143
uint16_t mtu
Definition: l2cap.h:147
uint16_t init_credits
Definition: l2cap.h:151
uint16_t mps
Definition: l2cap.h:149
atomic_t credits
Definition: l2cap.h:153
uint16_t cid
Definition: l2cap.h:145
L2CAP Server structure.
Definition: l2cap.h:372
uint16_t psm
Server PSM.
Definition: l2cap.h:386
sys_snode_t node
Definition: l2cap.h:406
bt_security_t sec_level
Definition: l2cap.h:389
int(* accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan)
Server accept callback.
Definition: l2cap.h:404
Definition: kernel.h:2252
A structure used to submit work after a delay.
Definition: kernel.h:3735
A structure holding internal state for a pending synchronous operation on a work item or queue.
Definition: kernel.h:3818
A structure used to submit work.
Definition: kernel.h:3707
Network buffer representation.
Definition: buf.h:905