|
1 | 1 | /* |
2 | | - * Copyright (c) 2020 Linumiz |
| 2 | + * Copyright (c) 2024 Vogl Electronic GmbH |
3 | 3 | * |
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | /** |
8 | | - * @brief hawkBit Firmware Over-the-Air for Zephyr Project. |
9 | | - * @defgroup hawkbit hawkBit Firmware Over-the-Air |
10 | | - * @ingroup third_party |
11 | | - * @{ |
| 8 | + * @file |
| 9 | + * @brief hawkBit legacy header file |
12 | 10 | */ |
| 11 | + |
13 | 12 | #ifndef ZEPHYR_INCLUDE_MGMT_HAWKBIT_H_ |
14 | 13 | #define ZEPHYR_INCLUDE_MGMT_HAWKBIT_H_ |
15 | 14 |
|
16 | | -#include <zephyr/net/tls_credentials.h> |
17 | | - |
18 | | -#define HAWKBIT_JSON_URL "/default/controller/v1" |
19 | | - |
20 | | -/** |
21 | | - * @brief Response message from hawkBit. |
22 | | - * |
23 | | - * @details These messages are used to inform the server and the |
24 | | - * user about the process status of the hawkBit and also |
25 | | - * used to standardize the errors that may occur. |
26 | | - * |
27 | | - */ |
28 | | -enum hawkbit_response { |
29 | | - HAWKBIT_NO_RESPONSE, |
30 | | - HAWKBIT_NETWORKING_ERROR, |
31 | | - HAWKBIT_UNCONFIRMED_IMAGE, |
32 | | - HAWKBIT_PERMISSION_ERROR, |
33 | | - HAWKBIT_METADATA_ERROR, |
34 | | - HAWKBIT_DOWNLOAD_ERROR, |
35 | | - HAWKBIT_OK, |
36 | | - HAWKBIT_UPDATE_INSTALLED, |
37 | | - HAWKBIT_NO_UPDATE, |
38 | | - HAWKBIT_CANCEL_UPDATE, |
39 | | - HAWKBIT_NOT_INITIALIZED, |
40 | | - HAWKBIT_PROBE_IN_PROGRESS, |
41 | | -}; |
42 | | - |
43 | | -/** |
44 | | - * @brief hawkBit configuration structure. |
45 | | - * |
46 | | - * @details This structure is used to store the hawkBit configuration |
47 | | - * settings. |
48 | | - */ |
49 | | -struct hawkbit_runtime_config { |
50 | | - char *server_addr; |
51 | | - uint16_t server_port; |
52 | | - char *auth_token; |
53 | | - sec_tag_t tls_tag; |
54 | | -}; |
55 | | - |
56 | | -/** |
57 | | - * @brief Callback to provide the custom data to the hawkBit server. |
58 | | - * |
59 | | - * @details This callback is used to provide the custom data to the hawkBit server. |
60 | | - * The custom data is used to provide the hawkBit server with the device specific |
61 | | - * data. |
62 | | - * |
63 | | - * @param device_id The device ID. |
64 | | - * @param buffer The buffer to store the json. |
65 | | - * @param buffer_size The size of the buffer. |
66 | | - */ |
67 | | -typedef int (*hawkbit_config_device_data_cb_handler_t)(const char *device_id, uint8_t *buffer, |
68 | | - const size_t buffer_size); |
69 | | - |
70 | | -/** |
71 | | - * @brief Set the custom data callback. |
72 | | - * |
73 | | - * @details This function is used to set the custom data callback. |
74 | | - * The callback is used to provide the custom data to the hawkBit server. |
75 | | - * |
76 | | - * @param cb The callback function. |
77 | | - * |
78 | | - * @retval 0 on success. |
79 | | - * @retval -EINVAL if the callback is NULL. |
80 | | - */ |
81 | | -int hawkbit_set_custom_data_cb(hawkbit_config_device_data_cb_handler_t cb); |
82 | | - |
83 | | -/** |
84 | | - * @brief Init the flash partition |
85 | | - * |
86 | | - * @retval 0 on success. |
87 | | - * @retval -errno if init fails. |
88 | | - */ |
89 | | -int hawkbit_init(void); |
90 | | - |
91 | | -/** |
92 | | - * @brief The hawkBit probe verify if there is some update to be performed. |
93 | | - * |
94 | | - * @retval HAWKBIT_NETWORKING_ERROR fail to connect to the hawkBit server. |
95 | | - * @retval HAWKBIT_UNCONFIRMED_IMAGE image is unconfirmed. |
96 | | - * @retval HAWKBIT_PERMISSION_ERROR fail to get the permission to access the hawkBit server. |
97 | | - * @retval HAWKBIT_METADATA_ERROR fail to parse or to encode the metadata. |
98 | | - * @retval HAWKBIT_DOWNLOAD_ERROR fail while downloading the update package. |
99 | | - * @retval HAWKBIT_OK if the image was already updated. |
100 | | - * @retval HAWKBIT_UPDATE_INSTALLED if an update was installed. Reboot is required to apply it. |
101 | | - * @retval HAWKBIT_NO_UPDATE if no update was available. |
102 | | - * @retval HAWKBIT_CANCEL_UPDATE if the update was cancelled by the server. |
103 | | - * @retval HAWKBIT_NOT_INITIALIZED if hawkBit is not initialized. |
104 | | - * @retval HAWKBIT_PROBE_IN_PROGRESS if probe is currently running. |
105 | | - */ |
106 | | -enum hawkbit_response hawkbit_probe(void); |
107 | | - |
108 | | -/** |
109 | | - * @brief Request system to reboot. |
110 | | - */ |
111 | | -void hawkbit_reboot(void); |
112 | | - |
113 | | -/** |
114 | | - * @brief Callback to get the device identity. |
115 | | - * |
116 | | - * @param id Pointer to the buffer to store the device identity |
117 | | - * @param id_max_len The maximum length of the buffer |
118 | | - */ |
119 | | -typedef bool (*hawkbit_get_device_identity_cb_handler_t)(char *id, int id_max_len); |
120 | | - |
121 | | -/** |
122 | | - * @brief Set the device identity callback. |
123 | | - * |
124 | | - * @details This function is used to set a custom device identity callback. |
125 | | - * |
126 | | - * @param cb The callback function. |
127 | | - * |
128 | | - * @retval 0 on success. |
129 | | - * @retval -EINVAL if the callback is NULL. |
130 | | - */ |
131 | | -int hawkbit_set_device_identity_cb(hawkbit_get_device_identity_cb_handler_t cb); |
132 | | - |
133 | | -/** |
134 | | - * @brief Set the hawkBit server configuration settings. |
135 | | - * |
136 | | - * @param config Configuration settings to set. |
137 | | - * @retval 0 on success. |
138 | | - * @retval -EAGAIN if probe is currently running. |
139 | | - */ |
140 | | -int hawkbit_set_config(struct hawkbit_runtime_config *config); |
141 | | - |
142 | | -/** |
143 | | - * @brief Get the hawkBit server configuration settings. |
144 | | - * |
145 | | - * @return Configuration settings. |
146 | | - */ |
147 | | -struct hawkbit_runtime_config hawkbit_get_config(void); |
148 | | - |
149 | | -/** |
150 | | - * @brief Set the hawkBit server address. |
151 | | - * |
152 | | - * @param addr_str Server address to set. |
153 | | - * @retval 0 on success. |
154 | | - * @retval -EAGAIN if probe is currently running. |
155 | | - */ |
156 | | -static inline int hawkbit_set_server_addr(char *addr_str) |
157 | | -{ |
158 | | - struct hawkbit_runtime_config set_config = { |
159 | | - .server_addr = addr_str, .server_port = 0, .auth_token = NULL, .tls_tag = 0}; |
160 | | - |
161 | | - return hawkbit_set_config(&set_config); |
162 | | -} |
163 | | - |
164 | | -/** |
165 | | - * @brief Set the hawkBit server port. |
166 | | - * |
167 | | - * @param port Server port to set. |
168 | | - * @retval 0 on success. |
169 | | - * @retval -EAGAIN if probe is currently running. |
170 | | - */ |
171 | | -static inline int hawkbit_set_server_port(uint16_t port) |
172 | | -{ |
173 | | - struct hawkbit_runtime_config set_config = { |
174 | | - .server_addr = NULL, .server_port = port, .auth_token = NULL, .tls_tag = 0}; |
175 | | - |
176 | | - return hawkbit_set_config(&set_config); |
177 | | -} |
178 | | - |
179 | | -/** |
180 | | - * @brief Set the hawkBit security token. |
181 | | - * |
182 | | - * @param token Security token to set. |
183 | | - * @retval 0 on success. |
184 | | - * @retval -EAGAIN if probe is currently running. |
185 | | - */ |
186 | | -static inline int hawkbit_set_ddi_security_token(char *token) |
187 | | -{ |
188 | | - struct hawkbit_runtime_config set_config = { |
189 | | - .server_addr = NULL, .server_port = 0, .auth_token = token, .tls_tag = 0}; |
190 | | - |
191 | | - return hawkbit_set_config(&set_config); |
192 | | -} |
193 | | - |
194 | | -/** |
195 | | - * @brief Set the hawkBit TLS tag |
196 | | - * |
197 | | - * @param tag TLS tag to set. |
198 | | - * @retval 0 on success. |
199 | | - * @retval -EAGAIN if probe is currently running. |
200 | | - */ |
201 | | -static inline int hawkbit_set_tls_tag(sec_tag_t tag) |
202 | | -{ |
203 | | - struct hawkbit_runtime_config set_config = { |
204 | | - .server_addr = NULL, .server_port = 0, .auth_token = NULL, .tls_tag = tag}; |
205 | | - |
206 | | - return hawkbit_set_config(&set_config); |
207 | | -} |
208 | | - |
209 | | -/** |
210 | | - * @brief Get the hawkBit server address. |
211 | | - * |
212 | | - * @return Server address. |
213 | | - */ |
214 | | -static inline char *hawkbit_get_server_addr(void) |
215 | | -{ |
216 | | - return hawkbit_get_config().server_addr; |
217 | | -} |
218 | | - |
219 | | -/** |
220 | | - * @brief Get the hawkBit server port. |
221 | | - * |
222 | | - * @return Server port. |
223 | | - */ |
224 | | -static inline uint16_t hawkbit_get_server_port(void) |
225 | | -{ |
226 | | - return hawkbit_get_config().server_port; |
227 | | -} |
228 | | - |
229 | | -/** |
230 | | - * @brief Get the hawkBit security token. |
231 | | - * |
232 | | - * @return Security token. |
233 | | - */ |
234 | | -static inline char *hawkbit_get_ddi_security_token(void) |
235 | | -{ |
236 | | - return hawkbit_get_config().auth_token; |
237 | | -} |
238 | | - |
239 | | -/** |
240 | | - * @brief Get the hawkBit TLS tag. |
241 | | - * |
242 | | - * @return TLS tag. |
243 | | - */ |
244 | | -static inline sec_tag_t hawkbit_get_tls_tag(void) |
245 | | -{ |
246 | | - return hawkbit_get_config().tls_tag; |
247 | | -} |
248 | | - |
249 | | -/** |
250 | | - * @brief Get the hawkBit action id. |
251 | | - * |
252 | | - * @return Action id. |
253 | | -
|
254 | | -*/ |
255 | | -int32_t hawkbit_get_action_id(void); |
256 | | - |
257 | | -/** |
258 | | - * @brief Get the hawkBit poll interval. |
259 | | - * |
260 | | - * @return Poll interval. |
261 | | - */ |
262 | | -uint32_t hawkbit_get_poll_interval(void); |
| 15 | +#warning "<zephyr/mgmt/hawkbit.h> is deprecated, include <zephyr/mgmt/hawkbit/hawkbit.h>, \ |
| 16 | +<zephyr/mgmt/hawkbit/config.h> and <zephyr/mgmt/hawkbit/autohandler.h> instead." |
263 | 17 |
|
264 | | -/** |
265 | | - * @brief Resets the hawkBit action id, that is saved in settings. |
266 | | - * |
267 | | - * @details This should be done after changing the hawkBit server. |
268 | | - * |
269 | | - * @retval 0 on success. |
270 | | - * @retval -EAGAIN if probe is currently running. |
271 | | - * @retval -EIO if the action id could not be reset. |
272 | | - * |
273 | | - */ |
274 | | -int hawkbit_reset_action_id(void); |
275 | | - |
276 | | -/** |
277 | | - * @brief hawkBit autohandler. |
278 | | - * @defgroup hawkbit_autohandler hawkBit autohandler |
279 | | - * @ingroup hawkbit |
280 | | - * @{ |
281 | | - */ |
282 | | - |
283 | | -/** |
284 | | - * @brief Runs hawkBit probe and hawkBit update automatically |
285 | | - * |
286 | | - * @details The hawkbit_autohandler handles the whole process |
287 | | - * in pre-determined time intervals. |
288 | | - * |
289 | | - * @param auto_reschedule If true, the handler will reschedule itself |
290 | | - */ |
291 | | -void hawkbit_autohandler(bool auto_reschedule); |
292 | | - |
293 | | -/** |
294 | | - * @brief Wait for the autohandler to finish. |
295 | | - * |
296 | | - * @param events Set of desired events on which to wait. Set to ::UINT32_MAX to wait for the |
297 | | - * autohandler to finish one run, or BIT() together with a value from |
298 | | - * ::hawkbit_response to wait for a specific event. |
299 | | - * @param timeout Waiting period for the desired set of events or one of the |
300 | | - * special values ::K_NO_WAIT and ::K_FOREVER. |
301 | | - * |
302 | | - * @retval HAWKBIT_OK if success. |
303 | | - * @retval HAWKBIT_NO_RESPONSE if matching events were not received within the specified time |
304 | | - * @retval HAWKBIT_NETWORKING_ERROR fail to connect to the hawkBit server. |
305 | | - * @retval HAWKBIT_UNCONFIRMED_IMAGE image is unconfirmed. |
306 | | - * @retval HAWKBIT_PERMISSION_ERROR fail to get the permission to access the hawkBit server. |
307 | | - * @retval HAWKBIT_METADATA_ERROR fail to parse or to encode the metadata. |
308 | | - * @retval HAWKBIT_DOWNLOAD_ERROR fail while downloading the update package. |
309 | | - * @retval HAWKBIT_UPDATE_INSTALLED if an update was installed. Reboot is required to apply it. |
310 | | - * @retval HAWKBIT_NO_UPDATE if no update was available. |
311 | | - * @retval HAWKBIT_CANCEL_UPDATE update was cancelled. |
312 | | - * @retval HAWKBIT_NOT_INITIALIZED if hawkBit is not initialized. |
313 | | - * @retval HAWKBIT_PROBE_IN_PROGRESS if probe is currently running. |
314 | | - */ |
315 | | -enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t timeout); |
316 | | - |
317 | | -/** |
318 | | - * @brief Cancel the run of the hawkBit autohandler. |
319 | | - * |
320 | | - * @return a value from k_work_cancel_delayable(). |
321 | | - */ |
322 | | -int hawkbit_autohandler_cancel(void); |
323 | | - |
324 | | -/** |
325 | | - * @brief Set the delay for the next run of the autohandler. |
326 | | - * |
327 | | - * @details This function will only delay the next run of the autohandler. The delay will not |
328 | | - * persist after the autohandler runs. |
329 | | - * |
330 | | - * @param timeout The delay to set. |
331 | | - * @param if_bigger If true, the delay will be set only if the new delay is bigger than the current |
332 | | - * one. |
333 | | - * |
334 | | - * @retval 0 if @a if_bigger was true and the current delay was bigger than the new one. |
335 | | - * @retval otherwise, a value from k_work_reschedule(). |
336 | | - */ |
337 | | -int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger); |
338 | | - |
339 | | -/** |
340 | | - * @} |
341 | | - * @} |
342 | | - */ |
| 18 | +#include <zephyr/mgmt/hawkbit/hawkbit.h> |
| 19 | +#include <zephyr/mgmt/hawkbit/config.h> |
| 20 | +#include <zephyr/mgmt/hawkbit/autohandler.h> |
343 | 21 |
|
344 | | -#endif /* _HAWKBIT_H_ */ |
| 22 | +#endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_H_ */ |
0 commit comments