xref: /btstack/src/mesh/mesh_configuration_client.h (revision 7cdc89a533ca236b2c2564b759993b788bae89d3)
1 /*
2  * Copyright (C) 2019 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 #ifndef __MESH_CONFIGURATION_CLIENT_H
39 #define __MESH_CONFIGURATION_CLIENT_H
40 
41 #include <stdint.h>
42 
43 #include "mesh/mesh_access.h"
44 
45 #ifdef __cplusplus
46 extern "C"
47 {
48 #endif
49 
50 
51 typedef struct {
52     const uint8_t * models;
53     uint16_t size;
54     uint16_t offset;
55 
56     uint32_t id;
57 } mesh_model_id_iterator_t;
58 
59 typedef struct {
60     const uint8_t * elements;
61     uint16_t size;
62     uint16_t offset;
63 
64     uint16_t loc;
65 
66     mesh_model_id_iterator_t sig_model_iterator;
67     mesh_model_id_iterator_t vendor_model_iterator;
68 } mesh_composite_data_iterator_t;
69 
70 typedef struct {
71     uint16_t publish_address_unicast;
72     uint8_t  publish_address_virtual[16];
73     uint16_t appkey_index;
74     uint8_t  credential_flag;
75     uint8_t  publish_ttl;
76     uint8_t  publish_period;
77     uint8_t  publish_retransmit_count;
78     uint8_t  publish_retransmit_interval_steps;
79 } mesh_publication_model_config_t;
80 
81 const mesh_operation_t * mesh_configuration_client_get_operations(void);
82 
83 /**
84  * @brief Initialize iterator for element descriptions list from Composition data in MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA event
85  * @param iterator
86  * @param elements
87  * @param size
88  */
89 void mesh_composition_data_iterator_init(mesh_composite_data_iterator_t * iterator, const uint8_t * elements, uint16_t size);
90 
91 /**
92  * @brief Check if there is another element description in the list
93  * @param iterator
94  * @return has_next_element
95  */
96 bool mesh_composition_data_iterator_has_next_element(mesh_composite_data_iterator_t * iterator);
97 
98 /**
99  * @brief Select the next element
100  * @param iterator
101  */
102 void mesh_composition_data_iterator_next_element(mesh_composite_data_iterator_t * iterator);
103 
104 /**
105  * @brief Get the element location descriptor for the current element
106  * @param iterator
107  * @return loc
108  */
109 uint16_t mesh_composition_data_iterator_element_loc(mesh_composite_data_iterator_t * iterator);
110 
111 /**
112  * @brief Check if there is another SIG model in current element
113  * @param iterator
114  * @return has_next_sig_model
115  */
116 bool mesh_composition_data_iterator_has_next_sig_model(mesh_composite_data_iterator_t * iterator);
117 
118 /**
119  * @brief Select the next SIG model
120  * @param iterator
121  */
122 void mesh_composition_data_iterator_next_sig_model(mesh_composite_data_iterator_t * iterator);
123 
124 /**
125  * @brief Get the SIG model ID for the current SIG model of the current element
126  * @param iterator
127  * @return loc
128  */
129 uint16_t mesh_composition_data_iterator_sig_model_id(mesh_composite_data_iterator_t * iterator);
130 
131 
132 /**
133  * @brief Check if there is another vendor model in current element
134  * @param iterator
135  * @return has_next_vendor_model
136  */
137 bool mesh_composition_data_iterator_has_next_vendor_model(mesh_composite_data_iterator_t * iterator);
138 
139 /**
140  * @brief Select the next VVendor model
141  * @param iterator
142  */
143 void mesh_composition_data_iterator_next_vendor_model(mesh_composite_data_iterator_t * iterator);
144 
145 /**
146  * @brief Get the Vendor model ID for the current vendor model of the current element
147  * @param iterator
148  * @return loc
149  */
150 uint32_t mesh_composition_data_iterator_vendor_model_id(mesh_composite_data_iterator_t * iterator);
151 
152 /**
153  * @brief Get field page from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
154  * @param event packet
155  * @return page
156  * @note: btstack_type 1
157  */
158 uint8_t mesh_subevent_configuration_composition_data_get_page(const uint8_t * event);
159 
160 /**
161  * @brief Get field cid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
162  * @param event packet
163  * @return cid
164  * @note: btstack_type 2
165  */
166 uint16_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event);
167 
168 /**
169  * @brief Get field pid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
170  * @param event packet
171  * @return pid
172  * @note: btstack_type 2
173  */
174 uint16_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event);
175 
176 /**
177  * @brief Get field vid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
178  * @param event packet
179  * @return vid
180  * @note: btstack_type 2
181  */
182 uint16_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event);
183 
184 /**
185  * @brief Get field crpl from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
186  * @param event packet
187  * @return crpl
188  * @note: btstack_type 2
189  */
190 uint16_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event);
191 
192 /**
193  * @brief Get field features from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
194  * @param event packet
195  * @return features
196  * @note: btstack_type 2
197  */
198 uint16_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event);
199 
200 /**
201  * @brief Get number elements from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
202  **/
203 uint16_t mesh_subevent_configuration_composition_data_get_num_elements(const uint8_t * event, uint16_t size);
204 
205 
206 /**
207  * @brief Register packet handler
208  * @param configuration_client_model
209  * @param events_packet_handler
210  */
211 void mesh_configuration_client_register_packet_handler(mesh_model_t *configuration_client_model, btstack_packet_handler_t events_packet_handler);
212 
213 /**
214  * @brief Get the current Secure Network Beacon state of a node.
215  * @param mesh_model
216  * @param dest
217  * @param netkey_index
218  * @param appkey_index
219  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
220  */
221 uint8_t mesh_configuration_client_send_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
222 
223 /**
224  * @brief Get the current Secure Network Beacon state of a node.
225  * @param mesh_model
226  * @param dest
227  * @param netkey_index
228  * @param appkey_index
229  * @param Beacon        0x01 The node is broadcasting a Secure Network beacon, 0x00 broadcastinis  off
230  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
231  */
232 uint8_t mesh_configuration_client_send_beacon_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t beacon);
233 
234 /**
235  * @brief Read one page of the Composition Data.
236  * @param mesh_model
237  * @param dest
238  * @param netkey_index
239  * @param appkey_index
240  * @param page          Page number of the Composition Data
241  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
242  */
243 uint8_t mesh_configuration_client_send_composition_data_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t page);
244 
245 /**
246  * @brief Get the current Default TTL state of a node
247  * @param mesh_model
248  * @param dest
249  * @param netkey_index
250  * @param appkey_index
251  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
252  */
253 uint8_t mesh_configuration_client_send_default_ttl_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
254 
255 /**
256  * @brief Set Default TTL state of a node
257  * @param mesh_model
258  * @param dest
259  * @param netkey_index
260  * @param appkey_index
261  * @param ttl           allowed values: 0x00, 0x02–0x7F
262  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
263  */
264 uint8_t mesh_configuration_client_send_default_ttl_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t ttl);
265 
266 /**
267  * @brief Get the current Default GATT proxy state of a node
268  * @param mesh_model
269  * @param dest
270  * @param netkey_index
271  * @param appkey_index
272  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
273  */
274 uint8_t mesh_configuration_client_send_gatt_proxy_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
275 
276 /**
277  * @brief Set Default GATT proxy state of a node
278  * @param mesh_model
279  * @param dest
280  * @param netkey_index
281  * @param appkey_index
282  * @param gatt_proxy_state        0 - the proxy feature is supported and disabled, 1 - supported and enabled, 2 - not supported
283  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
284  */
285 uint8_t mesh_configuration_client_send_gatt_proxy_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t gatt_proxy_state);
286 
287 
288 /**
289  * @brief Get the current Relay and Relay Retransmit states of a node
290  * @param mesh_model
291  * @param dest
292  * @param netkey_index
293  * @param appkey_index
294  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
295  */
296 uint8_t mesh_configuration_client_send_relay_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
297 
298 /**
299  * @brief Set the current Relay and Relay Retransmit states of a node
300  * @param mesh_model
301  * @param dest
302  * @param netkey_index
303  * @param appkey_index
304  * @param relay
305  * @param relay_retransmit_count
306  * @param relay_retransmit_interval_steps
307  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
308  */
309 uint8_t mesh_configuration_client_send_relay_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t relay, uint8_t relay_retransmit_count, uint8_t relay_retransmit_interval_steps);
310 
311 /**
312  * @brief Get the publish address and parameters of an outgoing message that originates from a model
313  * @param mesh_model
314  * @param dest         element_address
315  * @param netkey_index
316  * @param appkey_index
317  * @param model_id
318  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
319  */
320 uint8_t mesh_configuration_client_send_model_publication_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint32_t model_id);
321 
322 /**
323  * @brief Set the Model Publication state of an outgoing message that originates from a model.
324  * @param mesh_model
325  * @param dest         element_address
326  * @param netkey_index
327  * @param appkey_index
328  * @param model_id
329  * @param publication_config
330  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
331  */
332 uint8_t mesh_configuration_client_send_model_publication_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint32_t model_id, mesh_publication_model_config_t * publication_config);
333 
334 /**
335  * @brief Set the Model Publication state of an outgoing message that originates from a model.
336  * @param mesh_model
337  * @param dest         element_address
338  * @param netkey_index
339  * @param appkey_index
340  * @param model_id
341  * @param publication_config
342  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
343  */
344 uint8_t mesh_configuration_client_send_model_publication_virtual_address_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint32_t model_id, mesh_publication_model_config_t * publication_config);
345 
346 /**
347  * @brief Add an address to a Subscription List of a model
348  * @param mesh_model
349  * @param dest         element_address
350  * @param netkey_index
351  * @param appkey_index
352  * @param address
353  * @param model_id
354  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
355  */
356 uint8_t mesh_configuration_client_send_model_subscription_add(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t address, uint32_t model_id);
357 uint8_t mesh_configuration_client_send_model_subscription_virtual_address_add(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t * address, uint32_t model_id);
358 
359 /**
360  * @brief Delete an address from a Subscription List of a model
361  * @param mesh_model
362  * @param dest         element_address
363  * @param netkey_index
364  * @param appkey_index
365  * @param address
366  * @param model_id
367  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
368  */
369 uint8_t mesh_configuration_client_send_model_subscription_delete(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t address, uint32_t model_id);
370 uint8_t mesh_configuration_client_send_model_subscription_virtual_address_delete(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t * address, uint32_t model_id);
371 
372 /**
373  * @brief Discard the Subscription List and add an address to the cleared Subscription List of a model
374  * @param mesh_model
375  * @param dest         element_address
376  * @param netkey_index
377  * @param appkey_index
378  * @param address
379  * @param model_id
380  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
381  */
382 uint8_t mesh_configuration_client_send_model_subscription_overwrite(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t address, uint32_t model_id);
383 uint8_t mesh_configuration_client_send_model_subscription_virtual_address_overwrite(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t * address, uint32_t model_id);
384 
385 /**
386  * @brief Discard the Subscription List of a model
387  * @param mesh_model
388  * @param dest         element_address
389  * @param netkey_index
390  * @param appkey_index
391  * @param address
392  * @param model_id
393  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
394  */
395 uint8_t mesh_configuration_client_send_model_subscription_delete_all(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t address, uint32_t model_id);
396 
397 #ifdef __cplusplus
398 } /* end of extern "C" */
399 #endif
400 
401 #endif
402