xref: /btstack/src/mesh/mesh_configuration_client.h (revision 0561b2d8d5dba972c7daa57d5e677f7a1327edfd)
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 
71 /**
72  * @brief Initialize iterator for element descriptions list from Composition data in MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA event
73  * @param iterator
74  * @param elements
75  * @param size
76  */
77 void mesh_composition_data_iterator_init(mesh_composite_data_iterator_t * iterator, const uint8_t * elements, uint16_t size);
78 
79 /**
80  * @brief Check if there is another element description in the list
81  * @param iterator
82  * @return has_next_element
83  */
84 bool mesh_composition_data_iterator_has_next_element(mesh_composite_data_iterator_t * iterator);
85 
86 /**
87  * @brief Select the next element
88  * @param iterator
89  */
90 void mesh_composition_data_iterator_next_element(mesh_composite_data_iterator_t * iterator);
91 
92 /**
93  * @brief Get the element location descriptor for the current element
94  * @param iterator
95  * @return loc
96  */
97 uint16_t mesh_composition_data_iterator_element_loc(mesh_composite_data_iterator_t * iterator);
98 
99 /**
100  * @brief Check if there is another SIG model in current element
101  * @param iterator
102  * @return has_next_sig_model
103  */
104 bool mesh_composition_data_iterator_has_next_sig_model(mesh_composite_data_iterator_t * iterator);
105 
106 /**
107  * @brief Select the next SIG model
108  * @param iterator
109  */
110 void mesh_composition_data_iterator_next_sig_model(mesh_composite_data_iterator_t * iterator);
111 
112 /**
113  * @brief Get the SIG model ID for the current SIG model of the current element
114  * @param iterator
115  * @return loc
116  */
117 uint16_t mesh_composition_data_iterator_sig_model_id(mesh_composite_data_iterator_t * iterator);
118 
119 
120 /**
121  * @brief Check if there is another vendor model in current element
122  * @param iterator
123  * @return has_next_vendor_model
124  */
125 bool mesh_composition_data_iterator_has_next_vendor_model(mesh_composite_data_iterator_t * iterator);
126 
127 /**
128  * @brief Select the next VVendor model
129  * @param iterator
130  */
131 void mesh_composition_data_iterator_next_vendor_model(mesh_composite_data_iterator_t * iterator);
132 
133 /**
134  * @brief Get the Vendor model ID for the current vendor model of the current element
135  * @param iterator
136  * @return loc
137  */
138 uint32_t mesh_composition_data_iterator_vendor_model_id(mesh_composite_data_iterator_t * iterator);
139 
140 /**
141  * @brief Get field page from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
142  * @param event packet
143  * @return page
144  * @note: btstack_type 1
145  */
146 uint8_t mesh_subevent_configuration_composition_data_get_page(const uint8_t * event);
147 
148 /**
149  * @brief Get field cid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
150  * @param event packet
151  * @return cid
152  * @note: btstack_type 2
153  */
154 uint16_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event);
155 
156 /**
157  * @brief Get field pid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
158  * @param event packet
159  * @return pid
160  * @note: btstack_type 2
161  */
162 uint16_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event);
163 
164 /**
165  * @brief Get field vid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
166  * @param event packet
167  * @return vid
168  * @note: btstack_type 2
169  */
170 uint16_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event);
171 
172 /**
173  * @brief Get field crpl from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
174  * @param event packet
175  * @return crpl
176  * @note: btstack_type 2
177  */
178 uint16_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event);
179 
180 /**
181  * @brief Get field features from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
182  * @param event packet
183  * @return features
184  * @note: btstack_type 2
185  */
186 uint16_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event);
187 
188 /**
189  * @brief Get number elements from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
190  **/
191 uint16_t mesh_subevent_configuration_composition_data_get_num_elements(const uint8_t * event, uint16_t size);
192 
193 
194 /**
195  * @brief Register packet handler
196  * @param configuration_client_model
197  * @param events_packet_handler
198  */
199 void mesh_configuration_client_register_packet_handler(mesh_model_t *configuration_client_model, btstack_packet_handler_t events_packet_handler);
200 
201 /**
202  * @brief Get the current Secure Network Beacon state of a node.
203  * @param mesh_model
204  * @param dest
205  * @param netkey_index
206  * @param appkey_index
207  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
208  */
209 uint8_t mesh_configuration_client_send_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
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  * @param Beacon        0x01 The node is broadcasting a Secure Network beacon, 0x00 broadcastinis  off
218  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
219  */
220 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);
221 
222 /**
223  * @brief Read one page of the Composition Data.
224  * @param mesh_model
225  * @param dest
226  * @param netkey_index
227  * @param appkey_index
228  * @param page          Page number of the Composition Data
229  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
230  */
231 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);
232 
233 /**
234  * @brief Get the current Default TTL state of a node
235  * @param mesh_model
236  * @param dest
237  * @param netkey_index
238  * @param appkey_index
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_default_ttl_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
242 
243 /**
244  * @brief Set Default TTL state of a node
245  * @param mesh_model
246  * @param dest
247  * @param netkey_index
248  * @param appkey_index
249  * @param ttl           allowed values: 0x00, 0x02–0x7F
250  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
251  */
252 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);
253 
254 /**
255  * @brief Get the current Default GATT proxy state of a node
256  * @param mesh_model
257  * @param dest
258  * @param netkey_index
259  * @param appkey_index
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_gatt_proxy_state_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
263 
264 /**
265  * @brief Set Default GATT proxy state of a node
266  * @param mesh_model
267  * @param dest
268  * @param netkey_index
269  * @param appkey_index
270  * @param gatt_proxy_state        0 - the proxy feature is supported and disabled, 1 - supported and enabled, 2 - not supported
271  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
272  */
273 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);
274 
275 #ifdef __cplusplus
276 } /* end of extern "C" */
277 #endif
278 
279 #endif
280