xref: /btstack/src/mesh/mesh_configuration_client.h (revision f2ca42dfa8727a13ba9db535d0f82645147781ed)
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 /**
82  * @brief Initialize iterator for element descriptions list from Composition data in MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA event
83  * @param iterator
84  * @param elements
85  * @param size
86  */
87 void mesh_composition_data_iterator_init(mesh_composite_data_iterator_t * iterator, const uint8_t * elements, uint16_t size);
88 
89 /**
90  * @brief Check if there is another element description in the list
91  * @param iterator
92  * @return has_next_element
93  */
94 bool mesh_composition_data_iterator_has_next_element(mesh_composite_data_iterator_t * iterator);
95 
96 /**
97  * @brief Select the next element
98  * @param iterator
99  */
100 void mesh_composition_data_iterator_next_element(mesh_composite_data_iterator_t * iterator);
101 
102 /**
103  * @brief Get the element location descriptor for the current element
104  * @param iterator
105  * @return loc
106  */
107 uint16_t mesh_composition_data_iterator_element_loc(mesh_composite_data_iterator_t * iterator);
108 
109 /**
110  * @brief Check if there is another SIG model in current element
111  * @param iterator
112  * @return has_next_sig_model
113  */
114 bool mesh_composition_data_iterator_has_next_sig_model(mesh_composite_data_iterator_t * iterator);
115 
116 /**
117  * @brief Select the next SIG model
118  * @param iterator
119  */
120 void mesh_composition_data_iterator_next_sig_model(mesh_composite_data_iterator_t * iterator);
121 
122 /**
123  * @brief Get the SIG model ID for the current SIG model of the current element
124  * @param iterator
125  * @return loc
126  */
127 uint16_t mesh_composition_data_iterator_sig_model_id(mesh_composite_data_iterator_t * iterator);
128 
129 
130 /**
131  * @brief Check if there is another vendor model in current element
132  * @param iterator
133  * @return has_next_vendor_model
134  */
135 bool mesh_composition_data_iterator_has_next_vendor_model(mesh_composite_data_iterator_t * iterator);
136 
137 /**
138  * @brief Select the next VVendor model
139  * @param iterator
140  */
141 void mesh_composition_data_iterator_next_vendor_model(mesh_composite_data_iterator_t * iterator);
142 
143 /**
144  * @brief Get the Vendor model ID for the current vendor model of the current element
145  * @param iterator
146  * @return loc
147  */
148 uint32_t mesh_composition_data_iterator_vendor_model_id(mesh_composite_data_iterator_t * iterator);
149 
150 /**
151  * @brief Get field page from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
152  * @param event packet
153  * @return page
154  * @note: btstack_type 1
155  */
156 uint8_t mesh_subevent_configuration_composition_data_get_page(const uint8_t * event);
157 
158 /**
159  * @brief Get field cid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
160  * @param event packet
161  * @return cid
162  * @note: btstack_type 2
163  */
164 uint16_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event);
165 
166 /**
167  * @brief Get field pid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
168  * @param event packet
169  * @return pid
170  * @note: btstack_type 2
171  */
172 uint16_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event);
173 
174 /**
175  * @brief Get field vid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
176  * @param event packet
177  * @return vid
178  * @note: btstack_type 2
179  */
180 uint16_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event);
181 
182 /**
183  * @brief Get field crpl from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
184  * @param event packet
185  * @return crpl
186  * @note: btstack_type 2
187  */
188 uint16_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event);
189 
190 /**
191  * @brief Get field features from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
192  * @param event packet
193  * @return features
194  * @note: btstack_type 2
195  */
196 uint16_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event);
197 
198 /**
199  * @brief Get number elements from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
200  **/
201 uint16_t mesh_subevent_configuration_composition_data_get_num_elements(const uint8_t * event, uint16_t size);
202 
203 
204 /**
205  * @brief Register packet handler
206  * @param configuration_client_model
207  * @param events_packet_handler
208  */
209 void mesh_configuration_client_register_packet_handler(mesh_model_t *configuration_client_model, btstack_packet_handler_t events_packet_handler);
210 
211 /**
212  * @brief Get the current Secure Network Beacon state of a node.
213  * @param mesh_model
214  * @param dest
215  * @param netkey_index
216  * @param appkey_index
217  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
218  */
219 uint8_t mesh_configuration_client_send_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
220 
221 /**
222  * @brief Get the current Secure Network Beacon state of a node.
223  * @param mesh_model
224  * @param dest
225  * @param netkey_index
226  * @param appkey_index
227  * @param Beacon        0x01 The node is broadcasting a Secure Network beacon, 0x00 broadcastinis  off
228  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
229  */
230 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);
231 
232 /**
233  * @brief Read one page of the Composition Data.
234  * @param mesh_model
235  * @param dest
236  * @param netkey_index
237  * @param appkey_index
238  * @param page          Page number of the Composition Data
239  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
240  */
241 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);
242 
243 /**
244  * @brief Get the current Default TTL state of a node
245  * @param mesh_model
246  * @param dest
247  * @param netkey_index
248  * @param appkey_index
249  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
250  */
251 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);
252 
253 /**
254  * @brief Set Default TTL state of a node
255  * @param mesh_model
256  * @param dest
257  * @param netkey_index
258  * @param appkey_index
259  * @param ttl           allowed values: 0x00, 0x02–0x7F
260  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
261  */
262 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);
263 
264 /**
265  * @brief Get the current Default GATT proxy state of a node
266  * @param mesh_model
267  * @param dest
268  * @param netkey_index
269  * @param appkey_index
270  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
271  */
272 uint8_t mesh_configuration_client_send_default_gatt_proxy_state_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
273 
274 /**
275  * @brief Set Default GATT proxy state of a node
276  * @param mesh_model
277  * @param dest
278  * @param netkey_index
279  * @param appkey_index
280  * @param gatt_proxy_state        0 - the proxy feature is supported and disabled, 1 - supported and enabled, 2 - not supported
281  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
282  */
283 uint8_t mesh_configuration_client_send_default_gatt_proxy_state_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t gatt_proxy_state);
284 
285 /**
286  * @brief Get the publish address and parameters of an outgoing message that originates from a model
287  * @param mesh_model
288  * @param dest         element_address
289  * @param netkey_index
290  * @param appkey_index
291  * @param model_id
292  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
293  */
294 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);
295 
296 /**
297  * @brief Set the Model Publication state of an outgoing message that originates from a model.
298  * @param mesh_model
299  * @param dest         element_address
300  * @param netkey_index
301  * @param appkey_index
302  * @param model_id
303  * @param publication_config
304  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
305  */
306 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);
307 
308 /**
309  * @brief Set the Model Publication state of an outgoing message that originates from a model.
310  * @param mesh_model
311  * @param dest         element_address
312  * @param netkey_index
313  * @param appkey_index
314  * @param model_id
315  * @param publication_config
316  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
317  */
318 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);
319 
320 #ifdef __cplusplus
321 } /* end of extern "C" */
322 #endif
323 
324 #endif
325