1 /*
2  * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _PROXY_CLIENT_H_
8 #define _PROXY_CLIENT_H_
9 
10 #include "net.h"
11 #include "mesh_bearer_adapt.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #define BLE_MESH_PROXY_ADV_NET_ID           0x00
18 #define BLE_MESH_PROXY_ADV_NODE_ID          0x01
19 
20 #define BLE_MESH_PROXY_NET_PDU              0x00
21 #define BLE_MESH_PROXY_BEACON               0x01
22 #define BLE_MESH_PROXY_CONFIG               0x02
23 #define BLE_MESH_PROXY_PROV                 0x03
24 
25 #define BLE_MESH_PROXY_CFG_FILTER_SET       0x00
26 #define BLE_MESH_PROXY_CFG_FILTER_ADD       0x01
27 #define BLE_MESH_PROXY_CFG_FILTER_REMOVE    0x02
28 #define BLE_MESH_PROXY_CFG_FILTER_STATUS    0x03
29 
30 typedef union {
31     struct {
32         uint8_t  net_id[8];
33         uint16_t net_idx;
34     } net_id;
35     struct {
36         uint16_t src;
37     } node_id;
38 } bt_mesh_proxy_adv_ctx_t;
39 
40 struct bt_mesh_proxy_net_pdu {
41     struct net_buf_simple *val;
42 };
43 
44 struct bt_mesh_proxy_cfg_pdu {
45     uint8_t opcode;
46     union {
47         struct cfg_filter_set {
48             uint8_t filter_type;
49         } set;
50         struct cfg_addr_add {
51             uint16_t *addr;
52             uint16_t  addr_num;
53         } add;
54         struct cfg_addr_remove {
55             uint16_t *addr;
56             uint16_t  addr_num;
57         } remove;
58     };
59 };
60 
61 typedef struct {
62     uint8_t type;
63     union {
64         struct bt_mesh_proxy_net_pdu net;
65         struct bt_mesh_proxy_cfg_pdu cfg;
66     };
67 } bt_mesh_proxy_client_pdu_t;
68 
69 int bt_mesh_proxy_client_send(struct bt_mesh_conn *conn, uint8_t type,
70                               struct net_buf_simple *msg);
71 
72 int bt_mesh_proxy_client_prov_enable(void);
73 int bt_mesh_proxy_client_prov_disable(void);
74 
75 int bt_mesh_proxy_client_gatt_enable(void);
76 int bt_mesh_proxy_client_gatt_disable(void);
77 
78 typedef void (*proxy_client_recv_adv_cb_t)(const bt_mesh_addr_t *addr, uint8_t type,
79                                            bt_mesh_proxy_adv_ctx_t *ctx, int8_t rssi);
80 typedef void (*proxy_client_connect_cb_t)(const bt_mesh_addr_t *addr,
81                                           uint8_t conn_handle, uint16_t net_idx);
82 typedef void (*proxy_client_disconnect_cb_t)(const bt_mesh_addr_t *addr, uint8_t conn_handle,
83                                              uint16_t net_idx, uint8_t reason);
84 typedef void (*proxy_client_recv_filter_status_cb_t)(uint8_t conn_handle, uint16_t src, uint16_t net_idx,
85                                                      uint8_t filter_type, uint16_t list_size);
86 
87 void bt_mesh_proxy_client_set_adv_recv_cb(proxy_client_recv_adv_cb_t cb);
88 void bt_mesh_proxy_client_set_conn_cb(proxy_client_connect_cb_t cb);
89 void bt_mesh_proxy_client_set_disconn_cb(proxy_client_disconnect_cb_t cb);
90 void bt_mesh_proxy_client_set_filter_status_cb(proxy_client_recv_filter_status_cb_t cb);
91 
92 void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf,
93                                         const bt_mesh_addr_t *addr, int8_t rssi);
94 
95 int bt_mesh_proxy_client_connect(const uint8_t addr[6], uint8_t addr_type, uint16_t net_idx);
96 int bt_mesh_proxy_client_disconnect(uint8_t conn_handle);
97 
98 bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub);
99 
100 bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst);
101 
102 int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,
103                                   struct bt_mesh_proxy_cfg_pdu *pdu);
104 
105 int bt_mesh_proxy_client_init(void);
106 int bt_mesh_proxy_client_deinit(void);
107 
108 #ifdef __cplusplus
109 }
110 #endif
111 
112 #endif /* _PROXY_CLIENT_H_ */
113