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