1 /* l2cap_br.c - L2CAP BREDR internal interface
2  *
3  * This is the only interface between l2cap.c and l2cap_br.c.
4  *
5  * Copyright (c) 2024 Nordic Semiconductor ASA
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 /* Need a name different than bt_l2cap_fixed_chan for a different section */
11 struct bt_l2cap_br_fixed_chan {
12 	uint16_t		cid;
13 	int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan);
14 };
15 
16 #define BT_L2CAP_BR_CHANNEL_DEFINE(_name, _cid, _accept)		\
17 	const STRUCT_SECTION_ITERABLE(bt_l2cap_br_fixed_chan, _name) = { \
18 				.cid = _cid,			\
19 				.accept = _accept,		\
20 			}
21 
22 /* Initialize BR/EDR L2CAP signal layer */
23 void bt_l2cap_br_init(void);
24 
25 /* Notify BR/EDR L2CAP channels about established new ACL connection */
26 void bt_l2cap_br_connected(struct bt_conn *conn);
27 
28 /* Notify BR/EDR L2CAP channels about ACL disconnection*/
29 void bt_l2cap_br_disconnected(struct bt_conn *conn);
30 
31 /* Lookup BR/EDR L2CAP channel by Receiver CID */
32 struct bt_l2cap_chan *bt_l2cap_br_lookup_rx_cid(struct bt_conn *conn,
33 						uint16_t cid);
34 
35 /* Disconnects dynamic channel */
36 int bt_l2cap_br_chan_disconnect(struct bt_l2cap_chan *chan);
37 
38 /* Make connection to peer psm server */
39 int bt_l2cap_br_chan_connect(struct bt_conn *conn, struct bt_l2cap_chan *chan,
40 			     uint16_t psm);
41 
42 /* Send packet data to connected peer */
43 int bt_l2cap_br_chan_send(struct bt_l2cap_chan *chan, struct net_buf *buf);
44 int bt_l2cap_br_chan_send_cb(struct bt_l2cap_chan *chan, struct net_buf *buf, bt_conn_tx_cb_t cb,
45 			     void *user_data);
46 
47 /* Send a single PDU over a BR channel.
48  * Used by e.g. SMP.
49  */
50 int bt_l2cap_br_send_cb(struct bt_conn *conn, uint16_t cid, struct net_buf *buf,
51 			bt_conn_tx_cb_t cb, void *user_data);
52 
53 /*
54  * Handle security level changed on link passing HCI status of performed
55  * security procedure.
56  */
57 void l2cap_br_encrypt_change(struct bt_conn *conn, uint8_t hci_status);
58 
59 /* Handle received data */
60 void bt_l2cap_br_recv(struct bt_conn *conn, struct net_buf *buf);
61 
62 /* Pull HCI fragments from buffers intended for `conn` */
63 struct net_buf *l2cap_br_data_pull(struct bt_conn *conn,
64 				   size_t amount,
65 				   size_t *length);
66 
67 /* Find L2CAP BR channel by using specific cid on specific connection */
68 struct bt_l2cap_chan *bt_l2cap_br_lookup_tx_cid(struct bt_conn *conn,
69 						uint16_t cid);
70 
71 /* Get remote supported fixed channels */
72 uint8_t bt_l2cap_br_get_remote_fixed_chan(struct bt_conn *conn);
73