1 /*
2  * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _ESP_BLE_MESH_CONFIG_MODEL_API_H_
8 #define _ESP_BLE_MESH_CONFIG_MODEL_API_H_
9 
10 #include "esp_ble_mesh_defs.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /** @def    ESP_BLE_MESH_MODEL_CFG_SRV
17  *
18  *  @brief  Define a new Config Server Model.
19  *
20  *  @note   The Config Server Model can only be included by a Primary Element.
21  *
22  *  @param  srv_data Pointer to a unique Config Server Model user_data.
23  *
24  *  @return New Config Server Model instance.
25  */
26 #define ESP_BLE_MESH_MODEL_CFG_SRV(srv_data)                              \
27         ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_CONFIG_SRV,          \
28                   NULL, NULL, srv_data)
29 
30 /** @def    ESP_BLE_MESH_MODEL_CFG_CLI
31  *
32  *  @brief  Define a new Config Client Model.
33  *
34  *  @note   The Config Client Model can only be included by a Primary Element.
35  *
36  *  @param  cli_data Pointer to a unique struct esp_ble_mesh_client_t.
37  *
38  *  @return New Config Client Model instance.
39  */
40 #define ESP_BLE_MESH_MODEL_CFG_CLI(cli_data)                              \
41         ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_CONFIG_CLI,          \
42                   NULL, NULL, cli_data)
43 
44 /** Configuration Server Model context */
45 typedef struct esp_ble_mesh_cfg_srv {
46     esp_ble_mesh_model_t *model;    /*!< Pointer to Configuration Server Model */
47 
48     uint8_t net_transmit;           /*!< Network Transmit state */
49     uint8_t relay;                  /*!< Relay Mode state */
50     uint8_t relay_retransmit;       /*!< Relay Retransmit state */
51     uint8_t beacon;                 /*!< Secure Network Beacon state */
52     uint8_t gatt_proxy;             /*!< GATT Proxy state */
53     uint8_t friend_state;           /*!< Friend state */
54     uint8_t default_ttl;            /*!< Default TTL */
55 
56     /** Heartbeat Publication */
57     struct {
58         struct k_delayed_work timer;    /*!< Heartbeat Publication timer */
59 
60         uint16_t dst;                   /*!< Destination address for Heartbeat messages */
61         uint16_t count;                 /*!< Number of Heartbeat messages to be sent */
62         uint8_t  period;                /*!< Period for sending Heartbeat messages */
63         uint8_t  ttl;                   /*!< TTL to be used when sending Heartbeat messages */
64         uint16_t feature;               /*!< Bit field indicating features that trigger Heartbeat messages when changed */
65         uint16_t net_idx;               /*!< NetKey Index used by Heartbeat Publication */
66     } heartbeat_pub;
67 
68     /** Heartbeat Subscription */
69     struct {
70         int64_t  expiry;                /*!< Timestamp when Heartbeat subscription period is expired */
71 
72         uint16_t src;                   /*!< Source address for Heartbeat messages */
73         uint16_t dst;                   /*!< Destination address for Heartbeat messages */
74         uint16_t count;                 /*!< Number of Heartbeat messages received */
75         uint8_t  min_hops;              /*!< Minimum hops when receiving Heartbeat messages */
76         uint8_t  max_hops;              /*!< Maximum hops when receiving Heartbeat messages */
77 
78         /** Optional heartbeat subscription tracking function */
79         esp_ble_mesh_cb_t heartbeat_recv_cb;
80     } heartbeat_sub;
81 } esp_ble_mesh_cfg_srv_t;
82 
83 /** Parameters of Config Composition Data Get. */
84 typedef struct {
85     uint8_t page;                   /*!< Page number of the Composition Data. */
86 } esp_ble_mesh_cfg_composition_data_get_t;
87 
88 /** Parameters of Config Model Publication Get. */
89 typedef struct {
90     uint16_t element_addr;          /*!< The element address */
91     uint16_t model_id;              /*!< The model id */
92     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
93 } esp_ble_mesh_cfg_model_pub_get_t;
94 
95 /** Parameters of Config SIG Model Subscription Get. */
96 typedef struct {
97     uint16_t element_addr;          /*!< The element address */
98     uint16_t model_id;              /*!< The model id */
99 } esp_ble_mesh_cfg_sig_model_sub_get_t;
100 
101 /** Parameters of Config Vendor Model Subscription Get. */
102 typedef struct {
103     uint16_t element_addr;          /*!< The element address */
104     uint16_t model_id;              /*!< The model id */
105     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
106 } esp_ble_mesh_cfg_vnd_model_sub_get_t;
107 
108 /** Parameters of Config AppKey Get. */
109 typedef struct {
110     uint16_t net_idx;               /*!< The network key index */
111 } esp_ble_mesh_cfg_app_key_get_t;
112 
113 /** Parameters of Config Node Identity Get. */
114 typedef struct {
115     uint16_t net_idx;               /*!< The network key index */
116 } esp_ble_mesh_cfg_node_identity_get_t;
117 
118 /** Parameters of Config SIG Model App Get. */
119 typedef struct {
120     uint16_t element_addr;          /*!< The element address */
121     uint16_t model_id;              /*!< The model id */
122 } esp_ble_mesh_cfg_sig_model_app_get_t;
123 
124 /** Parameters of Config Vendor Model App Get. */
125 typedef struct {
126     uint16_t element_addr;          /*!< The element address */
127     uint16_t model_id;              /*!< The model id */
128     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
129 } esp_ble_mesh_cfg_vnd_model_app_get_t;
130 
131 /** Parameters of Config Key Refresh Phase Get. */
132 typedef struct {
133     uint16_t net_idx;               /*!< The network key index */
134 } esp_ble_mesh_cfg_kr_phase_get_t;
135 
136 /** Parameters of Config Low Power Node PollTimeout Get. */
137 typedef struct {
138     uint16_t lpn_addr;              /*!< The unicast address of the Low Power node */
139 } esp_ble_mesh_cfg_lpn_polltimeout_get_t;
140 
141 /** Parameters of Config Beacon Set. */
142 typedef struct {
143     uint8_t beacon;                 /*!< New Secure Network Beacon state */
144 } esp_ble_mesh_cfg_beacon_set_t;
145 
146 /** Parameters of Config Default TTL Set. */
147 typedef struct {
148     uint8_t ttl;                    /*!< The default TTL state value */
149 } esp_ble_mesh_cfg_default_ttl_set_t;
150 
151 /** Parameters of Config Friend Set. */
152 typedef struct {
153     uint8_t friend_state;           /*!< The friend state value */
154 } esp_ble_mesh_cfg_friend_set_t;
155 
156 /** Parameters of Config GATT Proxy Set. */
157 typedef struct {
158     uint8_t gatt_proxy;             /*!< The GATT Proxy state value */
159 } esp_ble_mesh_cfg_gatt_proxy_set_t;
160 
161 /** Parameters of Config Relay Set. */
162 typedef struct {
163     uint8_t relay;                  /*!< The relay value */
164     uint8_t relay_retransmit;       /*!< The relay retransmit value */
165 } esp_ble_mesh_cfg_relay_set_t;
166 
167 /** Parameters of Config NetKey Add. */
168 typedef struct {
169     uint16_t net_idx;               /*!< The network key index */
170     uint8_t  net_key[16];           /*!< The network key value */
171 } esp_ble_mesh_cfg_net_key_add_t;
172 
173 /** Parameters of Config AppKey Add. */
174 typedef struct {
175     uint16_t net_idx;               /*!< The network key index */
176     uint16_t app_idx;               /*!< The app key index */
177     uint8_t  app_key[16];           /*!< The app key value */
178 } esp_ble_mesh_cfg_app_key_add_t;
179 
180 /** Parameters of Config Model App Bind. */
181 typedef struct {
182     uint16_t element_addr;          /*!< The element address */
183     uint16_t model_app_idx;         /*!< Index of the app key to bind with the model */
184     uint16_t model_id;              /*!< The model id */
185     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
186 } esp_ble_mesh_cfg_model_app_bind_t;
187 
188 /** Parameters of Config Model Publication Set. */
189 typedef struct {
190     uint16_t element_addr;          /*!< The element address */
191     uint16_t publish_addr;          /*!< Value of the publish address */
192     uint16_t publish_app_idx;       /*!< Index of the application key */
193     bool     cred_flag;             /*!< Value of the Friendship Credential Flag */
194     uint8_t  publish_ttl;           /*!< Default TTL value for the publishing messages */
195     uint8_t  publish_period;        /*!< Period for periodic status publishing */
196     uint8_t  publish_retransmit;    /*!< Number of retransmissions and number of 50-millisecond steps between retransmissions */
197     uint16_t model_id;              /*!< The model id */
198     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
199 } esp_ble_mesh_cfg_model_pub_set_t;
200 
201 /** Parameters of Config Model Subscription Add. */
202 typedef struct {
203     uint16_t element_addr;          /*!< The element address */
204     uint16_t sub_addr;              /*!< The address to be added to the Subscription List */
205     uint16_t model_id;              /*!< The model id */
206     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
207 } esp_ble_mesh_cfg_model_sub_add_t;
208 
209 /** Parameters of Config Model Subscription Delete. */
210 typedef struct {
211     uint16_t element_addr;          /*!< The element address */
212     uint16_t sub_addr;              /*!< The address to be removed from the Subscription List */
213     uint16_t model_id;              /*!< The model id */
214     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
215 } esp_ble_mesh_cfg_model_sub_delete_t;
216 
217 /** Parameters of Config Model Subscription Overwrite. */
218 typedef struct {
219     uint16_t element_addr;          /*!< The element address */
220     uint16_t sub_addr;              /*!< The address to be added to the Subscription List */
221     uint16_t model_id;              /*!< The model id */
222     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
223 } esp_ble_mesh_cfg_model_sub_overwrite_t;
224 
225 /** Parameters of Config Model Subscription Virtual Address Add. */
226 typedef struct {
227     uint16_t element_addr;          /*!< The element address */
228     uint8_t  label_uuid[16];        /*!< The Label UUID of the virtual address to be added to the Subscription List */
229     uint16_t model_id;              /*!< The model id */
230     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
231 } esp_ble_mesh_cfg_model_sub_va_add_t;
232 
233 /** Parameters of Config Model Subscription Virtual Address Delete. */
234 typedef struct {
235     uint16_t element_addr;          /*!< The element address */
236     uint8_t  label_uuid[16];        /*!< The Label UUID of the virtual address to be removed from the Subscription List */
237     uint16_t model_id;              /*!< The model id */
238     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
239 } esp_ble_mesh_cfg_model_sub_va_delete_t;
240 
241 /** Parameters of Config Model Subscription Virtual Address Overwrite. */
242 typedef struct {
243     uint16_t element_addr;          /*!< The element address */
244     uint8_t  label_uuid[16];        /*!< The Label UUID of the virtual address to be added to the Subscription List */
245     uint16_t model_id;              /*!< The model id */
246     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
247 } esp_ble_mesh_cfg_model_sub_va_overwrite_t;
248 
249 /** Parameters of Config Model Publication Virtual Address Set. */
250 typedef struct {
251     uint16_t element_addr;          /*!< The element address */
252     uint8_t  label_uuid[16];        /*!< Value of the Label UUID publish address */
253     uint16_t publish_app_idx;       /*!< Index of the application key */
254     bool     cred_flag;             /*!< Value of the Friendship Credential Flag */
255     uint8_t  publish_ttl;           /*!< Default TTL value for the publishing messages */
256     uint8_t  publish_period;        /*!< Period for periodic status publishing */
257     uint8_t  publish_retransmit;    /*!< Number of retransmissions and number of 50-millisecond steps between retransmissions */
258     uint16_t model_id;              /*!< The model id */
259     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
260 } esp_ble_mesh_cfg_model_pub_va_set_t;
261 
262 /** Parameters of Config Model Subscription Delete All. */
263 typedef struct {
264     uint16_t element_addr;          /*!< The element address */
265     uint16_t model_id;              /*!< The model id */
266     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
267 } esp_ble_mesh_cfg_model_sub_delete_all_t;
268 
269 /** Parameters of Config NetKey Update. */
270 typedef struct {
271     uint16_t net_idx;               /*!< The network key index */
272     uint8_t  net_key[16];           /*!< The network key value */
273 } esp_ble_mesh_cfg_net_key_update_t;
274 
275 /** Parameters of Config NetKey Delete. */
276 typedef struct {
277     uint16_t net_idx;               /*!< The network key index */
278 } esp_ble_mesh_cfg_net_key_delete_t;
279 
280 /** Parameters of Config AppKey Update. */
281 typedef struct {
282     uint16_t net_idx;               /*!< The network key index */
283     uint16_t app_idx;               /*!< The app key index */
284     uint8_t  app_key[16];           /*!< The app key value */
285 } esp_ble_mesh_cfg_app_key_update_t;
286 
287 /** Parameters of Config AppKey Delete. */
288 typedef struct {
289     uint16_t net_idx;               /*!< The network key index */
290     uint16_t app_idx;               /*!< The app key index */
291 } esp_ble_mesh_cfg_app_key_delete_t;
292 
293 /** Parameters of Config Node Identity Set. */
294 typedef struct {
295     uint16_t net_idx;               /*!< The network key index */
296     uint8_t  identity;              /*!< New Node Identity state */
297 } esp_ble_mesh_cfg_node_identity_set_t;
298 
299 /** Parameters of Config Model App Unbind. */
300 typedef struct {
301     uint16_t element_addr;          /*!< The element address */
302     uint16_t model_app_idx;         /*!< Index of the app key to bind with the model */
303     uint16_t model_id;              /*!< The model id */
304     uint16_t company_id;            /*!< The company id, if not a vendor model, shall set to 0xFFFF */
305 } esp_ble_mesh_cfg_model_app_unbind_t;
306 
307 /** Parameters of Config Key Refresh Phase Set. */
308 typedef struct {
309     uint16_t net_idx;               /*!< The network key index */
310     uint8_t  transition;            /*!< New Key Refresh Phase Transition */
311 } esp_ble_mesh_cfg_kr_phase_set_t;
312 
313 /** Parameters of Config Network Transmit Set. */
314 typedef struct {
315     uint8_t net_transmit;           /*!< Network Transmit State */
316 } esp_ble_mesh_cfg_net_transmit_set_t;
317 
318 /** Parameters of Config Model Heartbeat Publication Set. */
319 typedef struct  {
320     uint16_t dst;                   /*!< Destination address for Heartbeat messages */
321     uint8_t  count;                 /*!< Number of Heartbeat messages to be sent */
322     uint8_t  period;                /*!< Period for sending Heartbeat messages */
323     uint8_t  ttl;                   /*!< TTL to be used when sending Heartbeat messages */
324     uint16_t feature;               /*!< Bit field indicating features that trigger Heartbeat messages when changed */
325     uint16_t net_idx;               /*!< NetKey Index */
326 } esp_ble_mesh_cfg_heartbeat_pub_set_t;
327 
328 /** Parameters of Config Model Heartbeat Subscription Set. */
329 typedef struct {
330     uint16_t src;                   /*!< Source address for Heartbeat messages */
331     uint16_t dst;                   /*!< Destination address for Heartbeat messages */
332     uint8_t  period;                /*!< Period for receiving Heartbeat messages */
333 } esp_ble_mesh_cfg_heartbeat_sub_set_t;
334 
335 /**
336  * @brief For ESP_BLE_MESH_MODEL_OP_BEACON_GET
337  *            ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET
338  *            ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET
339  *            ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET
340  *            ESP_BLE_MESH_MODEL_OP_RELAY_GET
341  *            ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET
342  *            ESP_BLE_MESH_MODEL_OP_FRIEND_GET
343  *            ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET
344  *            ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET
345  * the get_state parameter in the esp_ble_mesh_config_client_get_state function should not be set to NULL.
346  */
347 typedef union {
348     esp_ble_mesh_cfg_model_pub_get_t         model_pub_get;     /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET. */
349     esp_ble_mesh_cfg_composition_data_get_t  comp_data_get;     /*!< For ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET. */
350     esp_ble_mesh_cfg_sig_model_sub_get_t     sig_model_sub_get; /*!< For ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET */
351     esp_ble_mesh_cfg_vnd_model_sub_get_t     vnd_model_sub_get; /*!< For ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET */
352     esp_ble_mesh_cfg_app_key_get_t           app_key_get;       /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_GET. */
353     esp_ble_mesh_cfg_node_identity_get_t     node_identity_get; /*!< For ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET. */
354     esp_ble_mesh_cfg_sig_model_app_get_t     sig_model_app_get; /*!< For ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET */
355     esp_ble_mesh_cfg_vnd_model_app_get_t     vnd_model_app_get; /*!< For ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET */
356     esp_ble_mesh_cfg_kr_phase_get_t          kr_phase_get;      /*!< For ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET */
357     esp_ble_mesh_cfg_lpn_polltimeout_get_t   lpn_pollto_get;    /*!< For ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET */
358 } esp_ble_mesh_cfg_client_get_state_t;
359 
360 /**
361  * @brief For ESP_BLE_MESH_MODEL_OP_BEACON_SET
362  *            ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET
363  *            ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET
364  *            ESP_BLE_MESH_MODEL_OP_RELAY_SET
365  *            ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET
366  *            ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD
367  *            ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD
368  *            ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE
369  *            ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE
370  *            ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE
371  *            ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE
372  *            ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD
373  *            ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD
374  *            ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND
375  *            ESP_BLE_MESH_MODEL_OP_NODE_RESET
376  *            ESP_BLE_MESH_MODEL_OP_FRIEND_SET
377  *            ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET
378  *            ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET
379  * the set_state parameter in the esp_ble_mesh_config_client_set_state function should not be set to NULL.
380  */
381 typedef union {
382     esp_ble_mesh_cfg_beacon_set_t             beacon_set;             /*!< For ESP_BLE_MESH_MODEL_OP_BEACON_SET */
383     esp_ble_mesh_cfg_default_ttl_set_t        default_ttl_set;        /*!< For ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET */
384     esp_ble_mesh_cfg_friend_set_t             friend_set;             /*!< For ESP_BLE_MESH_MODEL_OP_FRIEND_SET */
385     esp_ble_mesh_cfg_gatt_proxy_set_t         gatt_proxy_set;         /*!< For ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET */
386     esp_ble_mesh_cfg_relay_set_t              relay_set;              /*!< For ESP_BLE_MESH_MODEL_OP_RELAY_SET */
387     esp_ble_mesh_cfg_net_key_add_t            net_key_add;            /*!< For ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD */
388     esp_ble_mesh_cfg_app_key_add_t            app_key_add;            /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD */
389     esp_ble_mesh_cfg_model_app_bind_t         model_app_bind;         /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND */
390     esp_ble_mesh_cfg_model_pub_set_t          model_pub_set;          /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET */
391     esp_ble_mesh_cfg_model_sub_add_t          model_sub_add;          /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD */
392     esp_ble_mesh_cfg_model_sub_delete_t       model_sub_delete;       /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE */
393     esp_ble_mesh_cfg_model_sub_overwrite_t    model_sub_overwrite;    /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE */
394     esp_ble_mesh_cfg_model_sub_va_add_t       model_sub_va_add;       /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD */
395     esp_ble_mesh_cfg_model_sub_va_delete_t    model_sub_va_delete;    /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE */
396     esp_ble_mesh_cfg_model_sub_va_overwrite_t model_sub_va_overwrite; /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE */
397     esp_ble_mesh_cfg_heartbeat_pub_set_t      heartbeat_pub_set;      /*!< For ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET */
398     esp_ble_mesh_cfg_heartbeat_sub_set_t      heartbeat_sub_set;      /*!< For ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET */
399     esp_ble_mesh_cfg_model_pub_va_set_t       model_pub_va_set;       /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET */
400     esp_ble_mesh_cfg_model_sub_delete_all_t   model_sub_delete_all;   /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL */
401     esp_ble_mesh_cfg_net_key_update_t         net_key_update;         /*!< For ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE */
402     esp_ble_mesh_cfg_net_key_delete_t         net_key_delete;         /*!< For ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE */
403     esp_ble_mesh_cfg_app_key_update_t         app_key_update;         /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE */
404     esp_ble_mesh_cfg_app_key_delete_t         app_key_delete;         /*!< For ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE */
405     esp_ble_mesh_cfg_node_identity_set_t      node_identity_set;      /*!< For ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET */
406     esp_ble_mesh_cfg_model_app_unbind_t       model_app_unbind;       /*!< For ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND */
407     esp_ble_mesh_cfg_kr_phase_set_t           kr_phase_set;           /*!< For ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET */
408     esp_ble_mesh_cfg_net_transmit_set_t       net_transmit_set;       /*!< For ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET */
409 } esp_ble_mesh_cfg_client_set_state_t;
410 
411 /** Parameter of Config Beacon Status */
412 typedef struct {
413     uint8_t beacon;                     /*!< Secure Network Beacon state value */
414 } esp_ble_mesh_cfg_beacon_status_cb_t;
415 
416 /** Parameters of Config Composition Data Status */
417 typedef struct {
418     uint8_t page;                              /*!< Page number of the Composition Data */
419     struct net_buf_simple *composition_data;   /*!< Pointer to Composition Data for the identified page */
420 } esp_ble_mesh_cfg_comp_data_status_cb_t;
421 
422 /** Parameter of Config Default TTL Status */
423 typedef struct {
424     uint8_t default_ttl;                /*!< Default TTL state value */
425 } esp_ble_mesh_cfg_default_ttl_status_cb_t;
426 
427 /** Parameter of Config GATT Proxy Status */
428 typedef struct {
429     uint8_t gatt_proxy;                 /*!< GATT Proxy state value */
430 } esp_ble_mesh_cfg_gatt_proxy_status_cb_t;
431 
432 /** Parameters of Config Relay Status */
433 typedef struct {
434     uint8_t relay;                      /*!< Relay state value */
435     uint8_t retransmit;                 /*!< Relay retransmit value(number of retransmissions and number of 10-millisecond steps between retransmissions) */
436 } esp_ble_mesh_cfg_relay_status_cb_t;
437 
438 /** Parameters of Config Model Publication Status */
439 typedef struct {
440     uint8_t  status;                    /*!< Status Code for the request message */
441     uint16_t element_addr;              /*!< Address of the element */
442     uint16_t publish_addr;              /*!< Value of the publish address */
443     uint16_t app_idx;                   /*!< Index of the application key */
444     bool     cred_flag;                 /*!< Value of the Friendship Credential Flag */
445     uint8_t  ttl;                       /*!< Default TTL value for the outgoing messages */
446     uint8_t  period;                    /*!< Period for periodic status publishing */
447     uint8_t  transmit;                  /*!< Number of retransmissions and number of 50-millisecond steps between retransmissions */
448     uint16_t company_id;                /*!< Company ID */
449     uint16_t model_id;                  /*!< Model ID */
450 } esp_ble_mesh_cfg_model_pub_status_cb_t;
451 
452 /** Parameters of Config Model Subscription Status */
453 typedef struct {
454     uint8_t  status;                    /*!< Status Code for the request message */
455     uint16_t element_addr;              /*!< Address of the element */
456     uint16_t sub_addr;                  /*!< Value of the address */
457     uint16_t company_id;                /*!< Company ID */
458     uint16_t model_id;                  /*!< Model ID */
459 } esp_ble_mesh_cfg_model_sub_status_cb_t;
460 
461 /** Parameters of Config NetKey Status */
462 typedef struct {
463     uint8_t  status;                    /*!< Status Code for the request message */
464     uint16_t net_idx;                   /*!< Index of the NetKey */
465 } esp_ble_mesh_cfg_net_key_status_cb_t;
466 
467 /** Parameters of Config AppKey Status */
468 typedef struct {
469     uint8_t  status;                    /*!< Status Code for the request message */
470     uint16_t net_idx;                   /*!< Index of the NetKey */
471     uint16_t app_idx;                   /*!< Index of the application key */
472 } esp_ble_mesh_cfg_app_key_status_cb_t;
473 
474 /** Parameters of Config Model App Status */
475 typedef struct {
476     uint8_t  status;                    /*!< Status Code for the request message */
477     uint16_t element_addr;              /*!< Address of the element */
478     uint16_t app_idx;                   /*!< Index of the application key */
479     uint16_t company_id;                /*!< Company ID */
480     uint16_t model_id;                  /*!< Model ID */
481 } esp_ble_mesh_cfg_mod_app_status_cb_t;
482 
483 /** Parameter of Config Friend Status */
484 typedef struct {
485     uint8_t friend_state;               /*!< Friend state value */
486 } esp_ble_mesh_cfg_friend_status_cb_t;
487 
488 /** Parameters of Config Heartbeat Publication Status */
489 typedef struct {
490     uint8_t  status;                    /*!< Status Code for the request message */
491     uint16_t dst;                       /*!< Destination address for Heartbeat messages */
492     uint8_t  count;                     /*!< Number of Heartbeat messages remaining to be sent */
493     uint8_t  period;                    /*!< Period for sending Heartbeat messages */
494     uint8_t  ttl;                       /*!< TTL to be used when sending Heartbeat messages */
495     uint16_t features;                  /*!< Features that trigger Heartbeat messages when changed */
496     uint16_t net_idx;                   /*!< Index of the NetKey */
497 } esp_ble_mesh_cfg_hb_pub_status_cb_t;
498 
499 /** Parameters of Config Heartbeat Subscription Status */
500 typedef struct {
501     uint8_t  status;                    /*!< Status Code for the request message */
502     uint16_t src;                       /*!< Source address for Heartbeat messages */
503     uint16_t dst;                       /*!< Destination address for Heartbeat messages */
504     uint8_t  period;                    /*!< Remaining Period for processing Heartbeat messages */
505     uint8_t  count;                     /*!< Number of Heartbeat messages received */
506     uint8_t  min_hops;                  /*!< Minimum hops when receiving Heartbeat messages */
507     uint8_t  max_hops;                  /*!< Maximum hops when receiving Heartbeat messages */
508 } esp_ble_mesh_cfg_hb_sub_status_cb_t;
509 
510 /** Parameters of Config Network Transmit Status */
511 typedef struct {
512     uint8_t net_trans_count: 3;         /*!< Number of transmissions for each Network PDU originating from the node */
513     uint8_t net_trans_step : 5;         /*!< Maximum hops when receiving Heartbeat messages */
514 } esp_ble_mesh_cfg_net_trans_status_cb_t;
515 
516 /** Parameters of Config SIG/Vendor Subscription List */
517 typedef struct {
518     uint8_t  status;                    /*!< Status Code for the request message */
519     uint16_t element_addr;              /*!< Address of the element */
520     uint16_t company_id;                /*!< Company ID */
521     uint16_t model_id;                  /*!< Model ID */
522     struct net_buf_simple *sub_addr;    /*!< A block of all addresses from the Subscription List */
523 } esp_ble_mesh_cfg_model_sub_list_cb_t;
524 
525 /** Parameter of Config NetKey List */
526 typedef struct {
527     struct net_buf_simple *net_idx;     /*!< A list of NetKey Indexes known to the node */
528 } esp_ble_mesh_cfg_net_key_list_cb_t;
529 
530 /** Parameters of Config AppKey List */
531 typedef struct {
532     uint8_t  status;                    /*!< Status Code for the request message */
533     uint16_t net_idx;                   /*!< NetKey Index of the NetKey that the AppKeys are bound to */
534     struct net_buf_simple *app_idx;     /*!< A list of AppKey indexes that are bound to the NetKey identified by NetKeyIndex */
535 } esp_ble_mesh_cfg_app_key_list_cb_t;
536 
537 /** Parameters of Config Node Identity Status */
538 typedef struct {
539     uint8_t  status;                    /*!< Status Code for the request message */
540     uint16_t net_idx;                   /*!< Index of the NetKey */
541     uint8_t  identity;                  /*!< Node Identity state */
542 } esp_ble_mesh_cfg_node_id_status_cb_t;
543 
544 /** Parameters of Config SIG/Vendor Model App List */
545 typedef struct {
546     uint8_t  status;                    /*!< Status Code for the request message */
547     uint16_t element_addr;              /*!< Address of the element */
548     uint16_t company_id;                /*!< Company ID */
549     uint16_t model_id;                  /*!< Model ID */
550     struct net_buf_simple *app_idx;     /*!< All AppKey indexes bound to the Model */
551 } esp_ble_mesh_cfg_model_app_list_cb_t;
552 
553 /** Parameters of Config Key Refresh Phase Status */
554 typedef struct {
555     uint8_t  status;                    /*!< Status Code for the request message */
556     uint16_t net_idx;                   /*!< Index of the NetKey */
557     uint8_t  phase;                     /*!< Key Refresh Phase state */
558 } esp_ble_mesh_cfg_kr_phase_status_cb_t;
559 
560 /** Parameters of Config Low Power Node PollTimeout Status */
561 typedef struct {
562     uint16_t lpn_addr;                  /*!< The unicast address of the Low Power node */
563     int32_t  poll_timeout;              /*!< The current value of the PollTimeout timer of the Low Power node */
564 } esp_ble_mesh_cfg_lpn_pollto_status_cb_t;
565 
566 /**
567  * @brief Configuration Client Model received message union
568  */
569 typedef union {
570     esp_ble_mesh_cfg_beacon_status_cb_t      beacon_status;         /*!< The beacon status value */
571     esp_ble_mesh_cfg_comp_data_status_cb_t   comp_data_status;      /*!< The composition data status value */
572     esp_ble_mesh_cfg_default_ttl_status_cb_t default_ttl_status;    /*!< The default_ttl status value */
573     esp_ble_mesh_cfg_gatt_proxy_status_cb_t  gatt_proxy_status;     /*!< The gatt_proxy status value */
574     esp_ble_mesh_cfg_relay_status_cb_t       relay_status;          /*!< The relay status value */
575     esp_ble_mesh_cfg_model_pub_status_cb_t   model_pub_status;      /*!< The model publication status value */
576     esp_ble_mesh_cfg_model_sub_status_cb_t   model_sub_status;      /*!< The model subscription status value */
577     esp_ble_mesh_cfg_net_key_status_cb_t     netkey_status;         /*!< The netkey status value */
578     esp_ble_mesh_cfg_app_key_status_cb_t     appkey_status;         /*!< The appkey status value */
579     esp_ble_mesh_cfg_mod_app_status_cb_t     model_app_status;      /*!< The model app status value */
580     esp_ble_mesh_cfg_friend_status_cb_t      friend_status;         /*!< The friend status value */
581     esp_ble_mesh_cfg_hb_pub_status_cb_t      heartbeat_pub_status;  /*!< The heartbeat publication status value */
582     esp_ble_mesh_cfg_hb_sub_status_cb_t      heartbeat_sub_status;  /*!< The heartbeat subscription status value */
583     esp_ble_mesh_cfg_net_trans_status_cb_t   net_transmit_status;   /*!< The network transmit status value */
584     esp_ble_mesh_cfg_model_sub_list_cb_t     model_sub_list;        /*!< The model subscription list value */
585     esp_ble_mesh_cfg_net_key_list_cb_t       netkey_list;           /*!< The network key index list value */
586     esp_ble_mesh_cfg_app_key_list_cb_t       appkey_list;           /*!< The application key index list value */
587     esp_ble_mesh_cfg_node_id_status_cb_t     node_identity_status;  /*!< The node identity status value */
588     esp_ble_mesh_cfg_model_app_list_cb_t     model_app_list;        /*!< The model application key index list value */
589     esp_ble_mesh_cfg_kr_phase_status_cb_t    kr_phase_status;       /*!< The key refresh phase status value */
590     esp_ble_mesh_cfg_lpn_pollto_status_cb_t  lpn_timeout_status;    /*!< The low power node poll timeout status value */
591 } esp_ble_mesh_cfg_client_common_cb_param_t;
592 
593 /** Configuration Client Model callback parameters */
594 typedef struct {
595     int error_code;                                         /*!< Appropriate error code */
596     esp_ble_mesh_client_common_param_t       *params;       /*!< The client common parameters */
597     esp_ble_mesh_cfg_client_common_cb_param_t status_cb;    /*!< The config status message callback values */
598 } esp_ble_mesh_cfg_client_cb_param_t;
599 
600 /** This enum value is the event of Configuration Client Model */
601 typedef enum {
602     ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT,
603     ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT,
604     ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT,
605     ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT,
606     ESP_BLE_MESH_CFG_CLIENT_EVT_MAX,
607 } esp_ble_mesh_cfg_client_cb_event_t;
608 
609 /**
610  * @brief Configuration Server model related context.
611  */
612 
613 typedef struct {
614     uint16_t element_addr;      /*!< Element Address */
615     uint16_t pub_addr;          /*!< Publish Address */
616     uint16_t app_idx;           /*!< AppKey Index */
617     bool     cred_flag;         /*!< Friendship Credential Flag */
618     uint8_t  pub_ttl;           /*!< Publish TTL */
619     uint8_t  pub_period;        /*!< Publish Period */
620     uint8_t  pub_retransmit;    /*!< Publish Retransmit */
621     uint16_t company_id;        /*!< Company ID */
622     uint16_t model_id;          /*!< Model ID */
623 } esp_ble_mesh_state_change_cfg_mod_pub_set_t;
624 
625 /** Parameters of Config Model Subscription Add */
626 typedef struct {
627     uint16_t element_addr;      /*!< Element Address */
628     uint16_t sub_addr;          /*!< Subscription Address */
629     uint16_t company_id;        /*!< Company ID */
630     uint16_t model_id;          /*!< Model ID */
631 } esp_ble_mesh_state_change_cfg_model_sub_add_t;
632 
633 /** Parameters of Config Model Subscription Delete */
634 typedef struct {
635     uint16_t element_addr;      /*!< Element Address */
636     uint16_t sub_addr;          /*!< Subscription Address */
637     uint16_t company_id;        /*!< Company ID */
638     uint16_t model_id;          /*!< Model ID */
639 } esp_ble_mesh_state_change_cfg_model_sub_delete_t;
640 
641 /** Parameters of Config NetKey Add */
642 typedef struct {
643     uint16_t net_idx;           /*!< NetKey Index */
644     uint8_t  net_key[16];       /*!< NetKey */
645 } esp_ble_mesh_state_change_cfg_netkey_add_t;
646 
647 /** Parameters of Config NetKey Update */
648 typedef struct {
649     uint16_t net_idx;           /*!< NetKey Index */
650     uint8_t  net_key[16];       /*!< NetKey */
651 } esp_ble_mesh_state_change_cfg_netkey_update_t;
652 
653 /** Parameter of Config NetKey Delete */
654 typedef struct {
655     uint16_t net_idx;           /*!< NetKey Index */
656 } esp_ble_mesh_state_change_cfg_netkey_delete_t;
657 
658 /** Parameters of Config AppKey Add */
659 typedef struct {
660     uint16_t net_idx;           /*!< NetKey Index */
661     uint16_t app_idx;           /*!< AppKey Index */
662     uint8_t  app_key[16];       /*!< AppKey */
663 } esp_ble_mesh_state_change_cfg_appkey_add_t;
664 
665 /** Parameters of Config AppKey Update */
666 typedef struct {
667     uint16_t net_idx;           /*!< NetKey Index */
668     uint16_t app_idx;           /*!< AppKey Index */
669     uint8_t  app_key[16];       /*!< AppKey */
670 } esp_ble_mesh_state_change_cfg_appkey_update_t;
671 
672 /** Parameters of Config AppKey Delete */
673 typedef struct {
674     uint16_t net_idx;           /*!< NetKey Index */
675     uint16_t app_idx;           /*!< AppKey Index */
676 } esp_ble_mesh_state_change_cfg_appkey_delete_t;
677 
678 /** Parameters of Config Model App Bind */
679 typedef struct {
680     uint16_t element_addr;      /*!< Element Address */
681     uint16_t app_idx;           /*!< AppKey Index */
682     uint16_t company_id;        /*!< Company ID */
683     uint16_t model_id;          /*!< Model ID */
684 } esp_ble_mesh_state_change_cfg_model_app_bind_t;
685 
686 /** Parameters of Config Model App Unbind */
687 typedef struct {
688     uint16_t element_addr;      /*!< Element Address */
689     uint16_t app_idx;           /*!< AppKey Index */
690     uint16_t company_id;        /*!< Company ID */
691     uint16_t model_id;          /*!< Model ID */
692 } esp_ble_mesh_state_change_cfg_model_app_unbind_t;
693 
694 /** Parameters of Config Key Refresh Phase Set */
695 typedef struct {
696     uint16_t net_idx;           /*!< NetKey Index */
697     uint8_t  kr_phase;          /*!< New Key Refresh Phase Transition */
698 } esp_ble_mesh_state_change_cfg_kr_phase_set_t;
699 
700 /**
701  * @brief Configuration Server model state change value union
702  */
703 typedef union {
704     /**
705      * The recv_op in ctx can be used to decide which state is changed.
706      */
707     esp_ble_mesh_state_change_cfg_mod_pub_set_t         mod_pub_set;        /*!< Config Model Publication Set */
708     esp_ble_mesh_state_change_cfg_model_sub_add_t       mod_sub_add;        /*!< Config Model Subscription Add */
709     esp_ble_mesh_state_change_cfg_model_sub_delete_t    mod_sub_delete;     /*!< Config Model Subscription Delete */
710     esp_ble_mesh_state_change_cfg_netkey_add_t          netkey_add;         /*!< Config NetKey Add */
711     esp_ble_mesh_state_change_cfg_netkey_update_t       netkey_update;      /*!< Config NetKey Update */
712     esp_ble_mesh_state_change_cfg_netkey_delete_t       netkey_delete;      /*!< Config NetKey Delete */
713     esp_ble_mesh_state_change_cfg_appkey_add_t          appkey_add;         /*!< Config AppKey Add */
714     esp_ble_mesh_state_change_cfg_appkey_update_t       appkey_update;      /*!< Config AppKey Update */
715     esp_ble_mesh_state_change_cfg_appkey_delete_t       appkey_delete;      /*!< Config AppKey Delete */
716     esp_ble_mesh_state_change_cfg_model_app_bind_t      mod_app_bind;       /*!< Config Model App Bind */
717     esp_ble_mesh_state_change_cfg_model_app_unbind_t    mod_app_unbind;     /*!< Config Model App Unbind */
718     esp_ble_mesh_state_change_cfg_kr_phase_set_t        kr_phase_set;       /*!< Config Key Refresh Phase Set */
719 } esp_ble_mesh_cfg_server_state_change_t;
720 
721 /**
722  * @brief Configuration Server model callback value union
723  */
724 typedef union {
725     esp_ble_mesh_cfg_server_state_change_t state_change;  /*!< ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT */
726 } esp_ble_mesh_cfg_server_cb_value_t;
727 
728 /** Configuration Server model callback parameters */
729 typedef struct {
730     esp_ble_mesh_model_t  *model;   /*!< Pointer to the server model structure */
731     esp_ble_mesh_msg_ctx_t ctx;     /*!< Context of the received message */
732     esp_ble_mesh_cfg_server_cb_value_t value;   /*!< Value of the received configuration messages */
733 } esp_ble_mesh_cfg_server_cb_param_t;
734 
735 /** This enum value is the event of Configuration Server model */
736 typedef enum {
737     ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT,
738     ESP_BLE_MESH_CFG_SERVER_EVT_MAX,
739 } esp_ble_mesh_cfg_server_cb_event_t;
740 
741 /**
742  *  @brief Bluetooth Mesh Config Client and Server Model functions.
743  */
744 
745 /**
746  * @brief   Configuration Client Model callback function type
747  * @param   event: Event type
748  * @param   param: Pointer to callback parameter
749  */
750 typedef void (* esp_ble_mesh_cfg_client_cb_t)(esp_ble_mesh_cfg_client_cb_event_t event,
751                                               esp_ble_mesh_cfg_client_cb_param_t *param);
752 
753 /**
754  * @brief   Configuration Server Model callback function type
755  * @param   event: Event type
756  * @param   param: Pointer to callback parameter
757  */
758 typedef void (* esp_ble_mesh_cfg_server_cb_t)(esp_ble_mesh_cfg_server_cb_event_t event,
759                                               esp_ble_mesh_cfg_server_cb_param_t *param);
760 
761 /**
762  * @brief         Register BLE Mesh Config Client Model callback.
763  *
764  * @param[in]     callback: Pointer to the callback function.
765  *
766  * @return        ESP_OK on success or error code otherwise.
767  *
768  */
769 esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_cb_t callback);
770 
771 /**
772  * @brief         Register BLE Mesh Config Server Model callback.
773  *
774  * @param[in]     callback: Pointer to the callback function.
775  *
776  * @return        ESP_OK on success or error code otherwise.
777  *
778  */
779 esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_cb_t callback);
780 
781 /**
782  * @brief         Get the value of Config Server Model states using the Config Client Model get messages.
783  *
784  * @note          If you want to find the opcodes and corresponding meanings accepted by this API,
785  *                please refer to esp_ble_mesh_opcode_config_client_get_t in esp_ble_mesh_defs.h
786  *
787  * @param[in]     params:    Pointer to BLE Mesh common client parameters.
788  * @param[in]     get_state: Pointer to a union, each kind of opcode corresponds to one structure inside.
789  *                           Shall not be set to NULL.
790  *
791  * @return        ESP_OK on success or error code otherwise.
792  *
793  */
794 esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
795                                                esp_ble_mesh_cfg_client_get_state_t *get_state);
796 
797 /**
798  * @brief         Set the value of the Configuration Server Model states using the Config Client Model set messages.
799  *
800  * @note          If you want to find the opcodes and corresponding meanings accepted by this API,
801  *                please refer to esp_ble_mesh_opcode_config_client_set_t in esp_ble_mesh_defs.h
802  *
803  * @param[in]     params:    Pointer to BLE Mesh common client parameters.
804  * @param[in]     set_state: Pointer to a union, each kind of opcode corresponds to one structure inside.
805  *                           Shall not be set to NULL.
806  *
807  * @return        ESP_OK on success or error code otherwise.
808  *
809  */
810 esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
811                                                esp_ble_mesh_cfg_client_set_state_t *set_state);
812 
813 #ifdef __cplusplus
814 }
815 #endif
816 
817 #endif /* _ESP_BLE_MESH_CONFIG_MODEL_API_H_ */
818