1 /*
2  * Copyright (c) 2020 - 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef BT_GATT_OTS_L2CAP_H_
8 #define BT_GATT_OTS_L2CAP_H_
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include <zephyr/types.h>
15 #include <zephyr/sys/slist.h>
16 #include <sys/types.h>
17 
18 #include <zephyr/bluetooth/l2cap.h>
19 
20 struct bt_gatt_ots_l2cap_tx {
21 	uint8_t *data;
22 	uint32_t len;
23 	uint32_t len_sent;
24 };
25 
26 struct bt_gatt_ots_l2cap {
27 	sys_snode_t node;
28 	struct bt_l2cap_le_chan ot_chan;
29 	struct bt_gatt_ots_l2cap_tx tx;
30 	void (*tx_done)(struct bt_gatt_ots_l2cap *l2cap_ctx,
31 			struct bt_conn *conn);
32 	ssize_t (*rx_done)(struct bt_gatt_ots_l2cap *l2cap_ctx,
33 			   struct bt_conn *conn, struct net_buf *buf);
34 	void (*closed)(struct bt_gatt_ots_l2cap *l2cap_ctx,
35 			struct bt_conn *conn);
36 };
37 
38 bool bt_gatt_ots_l2cap_is_open(struct bt_gatt_ots_l2cap *l2cap_ctx,
39 				   struct bt_conn *conn);
40 
41 int bt_gatt_ots_l2cap_send(struct bt_gatt_ots_l2cap *l2cap_ctx,
42 			       uint8_t *data,
43 			       uint32_t len);
44 
45 int bt_gatt_ots_l2cap_register(struct bt_gatt_ots_l2cap *l2cap_ctx);
46 
47 int bt_gatt_ots_l2cap_unregister(struct bt_gatt_ots_l2cap *l2cap_ctx);
48 
49 /** @brief Connect OTS L2CAP channel
50  *
51  *  This function is for the OTS client to make an L2CAP connection to
52  *  the OTS server.  One of the available registered L2CAP contexts
53  *  will be used for the connection.
54  *
55  * @param[in]  conn       Connection pointer
56  * @param[out] l2cap_ctx  The context that was connected
57  *
58  * @return     0 in case of success or negative value in case of error
59  */
60 int bt_gatt_ots_l2cap_connect(struct bt_conn *conn,
61 			      struct bt_gatt_ots_l2cap **l2cap_ctx);
62 
63 int bt_gatt_ots_l2cap_disconnect(struct bt_gatt_ots_l2cap *l2cap_ctx);
64 
65 
66 #ifdef __cplusplus
67 }
68 #endif
69 
70 /**
71  * @}
72  */
73 
74 #endif /* BT_GATT_OTS_L2CAP_H_ */
75