xref: /btstack/src/mesh/mesh_configuration_client.h (revision 873d831b6a3983c246f9676d22eb5eee1036f498)
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 Register packet handler
142  * @param configuration_client_model
143  * @param events_packet_handler
144  */
145 void mesh_configuration_client_register_packet_handler(mesh_model_t *configuration_client_model, btstack_packet_handler_t events_packet_handler);
146 
147 /**
148  * @brief Get the current Secure Network Beacon state of a node.
149  * @param mesh_model
150  * @param dest
151  * @param netkey_index
152  * @param appkey_index
153  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
154  */
155 uint8_t mesh_configuration_client_send_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index);
156 
157 /**
158  * @brief Get the current Secure Network Beacon state of a node.
159  * @param mesh_model
160  * @param dest
161  * @param netkey_index
162  * @param appkey_index
163  * @param Beacon        0x01 The node is broadcasting a Secure Network beacon, 0x00 broadcastinis  off
164  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
165  */
166 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);
167 
168 /**
169  * @brief Read one page of the Composition Data.
170  * @param mesh_model
171  * @param dest
172  * @param netkey_index
173  * @param appkey_index
174  * @param page          Page number of the Composition Data
175  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
176  */
177 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);
178 
179 /**
180  * @brief Get field cid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
181  **/
182 uint8_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event);
183 
184 /**
185  * @brief Get field pid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
186  **/
187 uint8_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event);
188 
189 /**
190  * @brief Get field vid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
191  **/
192 uint8_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event);
193 
194 /**
195  * @brief Get field crpl from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
196  **/
197 uint8_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event);
198 
199 /**
200  * @brief Get field features from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
201  **/
202 uint8_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event);
203 
204 /**
205  * @brief Get number elements from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
206  **/
207 uint16_t mesh_subevent_configuration_composition_data_get_num_elements(const uint8_t * event, uint16_t size);
208 
209 /**
210  * @brief Get the current Default TTL state of a node
211  * @param mesh_model
212  * @param dest
213  * @param netkey_index
214  * @param appkey_index
215  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
216  */
217 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);
218 
219 /**
220  * @brief Set Default TTL state of a node
221  * @param mesh_model
222  * @param dest
223  * @param netkey_index
224  * @param appkey_index
225  * @param ttl           allowed values: 0x00, 0x02–0x7F
226  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
227  */
228 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);
229 
230 /**
231  * @brief Get the current Default GATT proxy state of a node
232  * @param mesh_model
233  * @param dest
234  * @param netkey_index
235  * @param appkey_index
236  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
237  */
238 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);
239 
240 /**
241  * @brief Set Default GATT proxy state of a node
242  * @param mesh_model
243  * @param dest
244  * @param netkey_index
245  * @param appkey_index
246  * @param gatt_proxy_state        0 - the proxy feature is supported and disabled, 1 - supported and enabled, 2 - not supported
247  * @return status       ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE
248  */
249 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);
250 
251 #ifdef __cplusplus
252 } /* end of extern "C" */
253 #endif
254 
255 #endif
256