1 /*  Bluetooth Mesh */
2 
3 /*
4  * Copyright (c) 2017 Intel Corporation
5  * Copyright (c) 2021 Lingao Meng
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_
11 #define ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_
12 
13 #include <zephyr/bluetooth/gatt.h>
14 
15 #define PDU_TYPE(data)     (data[0] & BIT_MASK(6))
16 #define CFG_FILTER_SET     0x00
17 #define CFG_FILTER_ADD     0x01
18 #define CFG_FILTER_REMOVE  0x02
19 #define CFG_FILTER_STATUS  0x03
20 
21 #define BT_MESH_PROXY_NET_PDU   0x00
22 #define BT_MESH_PROXY_BEACON    0x01
23 #define BT_MESH_PROXY_CONFIG    0x02
24 #define BT_MESH_PROXY_PROV      0x03
25 
26 #define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
27 
28 struct bt_mesh_proxy_role;
29 
30 typedef int (*proxy_send_cb_t)(struct bt_conn *conn,
31 			       const void *data, uint16_t len,
32 			       bt_gatt_complete_func_t end, void *user_data);
33 
34 typedef void (*proxy_recv_cb_t)(struct bt_mesh_proxy_role *role);
35 
36 struct bt_mesh_proxy_role {
37 	struct bt_conn *conn;
38 	uint8_t msg_type;
39 
40 	struct {
41 		proxy_send_cb_t send;
42 		proxy_recv_cb_t recv;
43 	} cb;
44 
45 	struct k_work_delayable sar_timer;
46 	struct net_buf_simple buf;
47 };
48 
49 ssize_t bt_mesh_proxy_msg_recv(struct bt_conn *conn,
50 			       const void *buf, uint16_t len);
51 int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type,
52 			   struct net_buf_simple *msg,
53 			   bt_gatt_complete_func_t end, void *user_data);
54 int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf);
55 struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(struct bt_conn *conn,
56 						    proxy_send_cb_t send,
57 						    proxy_recv_cb_t recv);
58 void bt_mesh_proxy_role_cleanup(struct bt_mesh_proxy_role *role);
59 
60 bool bt_mesh_proxy_has_avail_conn(void);
61 
62 #endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_PROXY_MSG_H_ */
63