mgmt: hawkbit: seperate header files

seperate the hawkbit header files, to make
it clearer.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
Fin Maaß 2024-06-05 11:13:56 +02:00 committed by Fabio Baltieri
parent dce3d2de66
commit 94bad9d9ac
10 changed files with 432 additions and 337 deletions

View file

@ -2714,6 +2714,7 @@ hawkBit:
- maass-hamburg
files:
- subsys/mgmt/hawkbit/
- include/zephyr/mgmt/hawkbit/
- include/zephyr/mgmt/hawkbit.h
- samples/subsys/mgmt/hawkbit/
labels:

View file

@ -1,344 +1,22 @@
/*
* Copyright (c) 2020 Linumiz
* Copyright (c) 2024 Vogl Electronic GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @brief hawkBit Firmware Over-the-Air for Zephyr Project.
* @defgroup hawkbit hawkBit Firmware Over-the-Air
* @ingroup third_party
* @{
* @file
* @brief hawkBit legacy header file
*/
#ifndef ZEPHYR_INCLUDE_MGMT_HAWKBIT_H_
#define ZEPHYR_INCLUDE_MGMT_HAWKBIT_H_
#include <zephyr/net/tls_credentials.h>
#warning "<zephyr/mgmt/hawkbit.h> is deprecated, include <zephyr/mgmt/hawkbit/hawkbit.h>, \
<zephyr/mgmt/hawkbit/config.h> and <zephyr/mgmt/hawkbit/autohandler.h> instead."
#define HAWKBIT_JSON_URL "/default/controller/v1"
#include <zephyr/mgmt/hawkbit/hawkbit.h>
#include <zephyr/mgmt/hawkbit/config.h>
#include <zephyr/mgmt/hawkbit/autohandler.h>
/**
* @brief Response message from hawkBit.
*
* @details These messages are used to inform the server and the
* user about the process status of the hawkBit and also
* used to standardize the errors that may occur.
*
*/
enum hawkbit_response {
HAWKBIT_NO_RESPONSE,
HAWKBIT_NETWORKING_ERROR,
HAWKBIT_UNCONFIRMED_IMAGE,
HAWKBIT_PERMISSION_ERROR,
HAWKBIT_METADATA_ERROR,
HAWKBIT_DOWNLOAD_ERROR,
HAWKBIT_OK,
HAWKBIT_UPDATE_INSTALLED,
HAWKBIT_NO_UPDATE,
HAWKBIT_CANCEL_UPDATE,
HAWKBIT_NOT_INITIALIZED,
HAWKBIT_PROBE_IN_PROGRESS,
};
/**
* @brief hawkBit configuration structure.
*
* @details This structure is used to store the hawkBit configuration
* settings.
*/
struct hawkbit_runtime_config {
char *server_addr;
uint16_t server_port;
char *auth_token;
sec_tag_t tls_tag;
};
/**
* @brief Callback to provide the custom data to the hawkBit server.
*
* @details This callback is used to provide the custom data to the hawkBit server.
* The custom data is used to provide the hawkBit server with the device specific
* data.
*
* @param device_id The device ID.
* @param buffer The buffer to store the json.
* @param buffer_size The size of the buffer.
*/
typedef int (*hawkbit_config_device_data_cb_handler_t)(const char *device_id, uint8_t *buffer,
const size_t buffer_size);
/**
* @brief Set the custom data callback.
*
* @details This function is used to set the custom data callback.
* The callback is used to provide the custom data to the hawkBit server.
*
* @param cb The callback function.
*
* @retval 0 on success.
* @retval -EINVAL if the callback is NULL.
*/
int hawkbit_set_custom_data_cb(hawkbit_config_device_data_cb_handler_t cb);
/**
* @brief Init the flash partition
*
* @retval 0 on success.
* @retval -errno if init fails.
*/
int hawkbit_init(void);
/**
* @brief The hawkBit probe verify if there is some update to be performed.
*
* @retval HAWKBIT_NETWORKING_ERROR fail to connect to the hawkBit server.
* @retval HAWKBIT_UNCONFIRMED_IMAGE image is unconfirmed.
* @retval HAWKBIT_PERMISSION_ERROR fail to get the permission to access the hawkBit server.
* @retval HAWKBIT_METADATA_ERROR fail to parse or to encode the metadata.
* @retval HAWKBIT_DOWNLOAD_ERROR fail while downloading the update package.
* @retval HAWKBIT_OK if the image was already updated.
* @retval HAWKBIT_UPDATE_INSTALLED if an update was installed. Reboot is required to apply it.
* @retval HAWKBIT_NO_UPDATE if no update was available.
* @retval HAWKBIT_CANCEL_UPDATE if the update was cancelled by the server.
* @retval HAWKBIT_NOT_INITIALIZED if hawkBit is not initialized.
* @retval HAWKBIT_PROBE_IN_PROGRESS if probe is currently running.
*/
enum hawkbit_response hawkbit_probe(void);
/**
* @brief Request system to reboot.
*/
void hawkbit_reboot(void);
/**
* @brief Callback to get the device identity.
*
* @param id Pointer to the buffer to store the device identity
* @param id_max_len The maximum length of the buffer
*/
typedef bool (*hawkbit_get_device_identity_cb_handler_t)(char *id, int id_max_len);
/**
* @brief Set the device identity callback.
*
* @details This function is used to set a custom device identity callback.
*
* @param cb The callback function.
*
* @retval 0 on success.
* @retval -EINVAL if the callback is NULL.
*/
int hawkbit_set_device_identity_cb(hawkbit_get_device_identity_cb_handler_t cb);
/**
* @brief Set the hawkBit server configuration settings.
*
* @param config Configuration settings to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
int hawkbit_set_config(struct hawkbit_runtime_config *config);
/**
* @brief Get the hawkBit server configuration settings.
*
* @return Configuration settings.
*/
struct hawkbit_runtime_config hawkbit_get_config(void);
/**
* @brief Set the hawkBit server address.
*
* @param addr_str Server address to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_server_addr(char *addr_str)
{
struct hawkbit_runtime_config set_config = {
.server_addr = addr_str, .server_port = 0, .auth_token = NULL, .tls_tag = 0};
return hawkbit_set_config(&set_config);
}
/**
* @brief Set the hawkBit server port.
*
* @param port Server port to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_server_port(uint16_t port)
{
struct hawkbit_runtime_config set_config = {
.server_addr = NULL, .server_port = port, .auth_token = NULL, .tls_tag = 0};
return hawkbit_set_config(&set_config);
}
/**
* @brief Set the hawkBit security token.
*
* @param token Security token to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_ddi_security_token(char *token)
{
struct hawkbit_runtime_config set_config = {
.server_addr = NULL, .server_port = 0, .auth_token = token, .tls_tag = 0};
return hawkbit_set_config(&set_config);
}
/**
* @brief Set the hawkBit TLS tag
*
* @param tag TLS tag to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_tls_tag(sec_tag_t tag)
{
struct hawkbit_runtime_config set_config = {
.server_addr = NULL, .server_port = 0, .auth_token = NULL, .tls_tag = tag};
return hawkbit_set_config(&set_config);
}
/**
* @brief Get the hawkBit server address.
*
* @return Server address.
*/
static inline char *hawkbit_get_server_addr(void)
{
return hawkbit_get_config().server_addr;
}
/**
* @brief Get the hawkBit server port.
*
* @return Server port.
*/
static inline uint16_t hawkbit_get_server_port(void)
{
return hawkbit_get_config().server_port;
}
/**
* @brief Get the hawkBit security token.
*
* @return Security token.
*/
static inline char *hawkbit_get_ddi_security_token(void)
{
return hawkbit_get_config().auth_token;
}
/**
* @brief Get the hawkBit TLS tag.
*
* @return TLS tag.
*/
static inline sec_tag_t hawkbit_get_tls_tag(void)
{
return hawkbit_get_config().tls_tag;
}
/**
* @brief Get the hawkBit action id.
*
* @return Action id.
*/
int32_t hawkbit_get_action_id(void);
/**
* @brief Get the hawkBit poll interval.
*
* @return Poll interval.
*/
uint32_t hawkbit_get_poll_interval(void);
/**
* @brief Resets the hawkBit action id, that is saved in settings.
*
* @details This should be done after changing the hawkBit server.
*
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
* @retval -EIO if the action id could not be reset.
*
*/
int hawkbit_reset_action_id(void);
/**
* @brief hawkBit autohandler.
* @defgroup hawkbit_autohandler hawkBit autohandler
* @ingroup hawkbit
* @{
*/
/**
* @brief Runs hawkBit probe and hawkBit update automatically
*
* @details The hawkbit_autohandler handles the whole process
* in pre-determined time intervals.
*
* @param auto_reschedule If true, the handler will reschedule itself
*/
void hawkbit_autohandler(bool auto_reschedule);
/**
* @brief Wait for the autohandler to finish.
*
* @param events Set of desired events on which to wait. Set to ::UINT32_MAX to wait for the
* autohandler to finish one run, or BIT() together with a value from
* ::hawkbit_response to wait for a specific event.
* @param timeout Waiting period for the desired set of events or one of the
* special values ::K_NO_WAIT and ::K_FOREVER.
*
* @retval HAWKBIT_OK if success.
* @retval HAWKBIT_NO_RESPONSE if matching events were not received within the specified time
* @retval HAWKBIT_NETWORKING_ERROR fail to connect to the hawkBit server.
* @retval HAWKBIT_UNCONFIRMED_IMAGE image is unconfirmed.
* @retval HAWKBIT_PERMISSION_ERROR fail to get the permission to access the hawkBit server.
* @retval HAWKBIT_METADATA_ERROR fail to parse or to encode the metadata.
* @retval HAWKBIT_DOWNLOAD_ERROR fail while downloading the update package.
* @retval HAWKBIT_UPDATE_INSTALLED if an update was installed. Reboot is required to apply it.
* @retval HAWKBIT_NO_UPDATE if no update was available.
* @retval HAWKBIT_CANCEL_UPDATE update was cancelled.
* @retval HAWKBIT_NOT_INITIALIZED if hawkBit is not initialized.
* @retval HAWKBIT_PROBE_IN_PROGRESS if probe is currently running.
*/
enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t timeout);
/**
* @brief Cancel the run of the hawkBit autohandler.
*
* @return a value from k_work_cancel_delayable().
*/
int hawkbit_autohandler_cancel(void);
/**
* @brief Set the delay for the next run of the autohandler.
*
* @details This function will only delay the next run of the autohandler. The delay will not
* persist after the autohandler runs.
*
* @param timeout The delay to set.
* @param if_bigger If true, the delay will be set only if the new delay is bigger than the current
* one.
*
* @retval 0 if @a if_bigger was true and the current delay was bigger than the new one.
* @retval otherwise, a value from k_work_reschedule().
*/
int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger);
/**
* @}
* @}
*/
#endif /* _HAWKBIT_H_ */
#endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_H_ */

View file

@ -0,0 +1,73 @@
/*
* Copyright (c) 2024 Vogl Electronic GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief hawkBit autohandler header file
*/
/**
* @brief hawkBit autohandler API.
* @defgroup hawkbit_autohandler hawkBit autohandler API
* @ingroup hawkbit
* @{
*/
#ifndef ZEPHYR_INCLUDE_MGMT_HAWKBIT_AUTOHANDLER_H_
#define ZEPHYR_INCLUDE_MGMT_HAWKBIT_AUTOHANDLER_H_
#include <zephyr/mgmt/hawkbit/hawkbit.h>
/**
* @brief Runs hawkBit probe and hawkBit update automatically
*
* @details The hawkbit_autohandler handles the whole process
* in pre-determined time intervals.
*
* @param auto_reschedule If true, the handler will reschedule itself
*/
void hawkbit_autohandler(bool auto_reschedule);
/**
* @brief Wait for the autohandler to finish.
*
* @param events Set of desired events on which to wait. Set to ::UINT32_MAX to wait for the
* autohandler to finish one run, or BIT() together with a value from
* ::hawkbit_response to wait for a specific event.
* @param timeout Waiting period for the desired set of events or one of the
* special values ::K_NO_WAIT and ::K_FOREVER.
*
* @return A value from ::hawkbit_response.
*/
enum hawkbit_response hawkbit_autohandler_wait(uint32_t events, k_timeout_t timeout);
/**
* @brief Cancel the run of the hawkBit autohandler.
*
* @return a value from k_work_cancel_delayable().
*/
int hawkbit_autohandler_cancel(void);
/**
* @brief Set the delay for the next run of the autohandler.
*
* @details This function will only delay the next run of the autohandler. The delay will not
* persist after the autohandler runs.
*
* @param timeout The delay to set.
* @param if_bigger If true, the delay will be set only if the new delay is bigger than the current
* one.
*
* @retval 0 if @a if_bigger was true and the current delay was bigger than the new one.
* @retval otherwise, a value from k_work_reschedule().
*/
int hawkbit_autohandler_set_delay(k_timeout_t timeout, bool if_bigger);
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_AUTOHANDLER_H_ */

View file

@ -0,0 +1,192 @@
/*
* Copyright (c) 2024 Vogl Electronic GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief hawkBit configuration header file
*/
/**
* @brief hawkBit configuration API.
* @defgroup hawkbit_config hawkBit configuration API
* @ingroup hawkbit
* @{
*/
#ifndef ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_
#define ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_
#include <stdint.h>
#include <zephyr/net/tls_credentials.h>
/**
* @brief hawkBit configuration structure.
*
* @details This structure is used to store the hawkBit configuration
* settings.
*/
struct hawkbit_runtime_config {
/** Server address */
char *server_addr;
/** Server port */
uint16_t server_port;
/** Security token */
char *auth_token;
/** TLS tag */
sec_tag_t tls_tag;
};
/**
* @brief Set the hawkBit server configuration settings.
*
* @param config Configuration settings to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
int hawkbit_set_config(struct hawkbit_runtime_config *config);
/**
* @brief Get the hawkBit server configuration settings.
*
* @return Configuration settings.
*/
struct hawkbit_runtime_config hawkbit_get_config(void);
/**
* @brief Set the hawkBit server address.
*
* @param addr_str Server address to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_server_addr(char *addr_str)
{
struct hawkbit_runtime_config set_config = {
.server_addr = addr_str,
.server_port = 0,
.auth_token = NULL,
.tls_tag = 0,
};
return hawkbit_set_config(&set_config);
}
/**
* @brief Set the hawkBit server port.
*
* @param port Server port to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_server_port(uint16_t port)
{
struct hawkbit_runtime_config set_config = {
.server_addr = NULL,
.server_port = port,
.auth_token = NULL,
.tls_tag = 0,
};
return hawkbit_set_config(&set_config);
}
/**
* @brief Set the hawkBit security token.
*
* @param token Security token to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_ddi_security_token(char *token)
{
struct hawkbit_runtime_config set_config = {
.server_addr = NULL,
.server_port = 0,
.auth_token = token,
.tls_tag = 0,
};
return hawkbit_set_config(&set_config);
}
/**
* @brief Set the hawkBit TLS tag
*
* @param tag TLS tag to set.
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
*/
static inline int hawkbit_set_tls_tag(sec_tag_t tag)
{
struct hawkbit_runtime_config set_config = {
.server_addr = NULL,
.server_port = 0,
.auth_token = NULL,
.tls_tag = tag,
};
return hawkbit_set_config(&set_config);
}
/**
* @brief Get the hawkBit server address.
*
* @return Server address.
*/
static inline char *hawkbit_get_server_addr(void)
{
return hawkbit_get_config().server_addr;
}
/**
* @brief Get the hawkBit server port.
*
* @return Server port.
*/
static inline uint16_t hawkbit_get_server_port(void)
{
return hawkbit_get_config().server_port;
}
/**
* @brief Get the hawkBit security token.
*
* @return Security token.
*/
static inline char *hawkbit_get_ddi_security_token(void)
{
return hawkbit_get_config().auth_token;
}
/**
* @brief Get the hawkBit TLS tag.
*
* @return TLS tag.
*/
static inline sec_tag_t hawkbit_get_tls_tag(void)
{
return hawkbit_get_config().tls_tag;
}
/**
* @brief Get the hawkBit action id.
*
* @return Action id.
*/
int32_t hawkbit_get_action_id(void);
/**
* @brief Get the hawkBit poll interval.
*
* @return Poll interval.
*/
uint32_t hawkbit_get_poll_interval(void);
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_CONFIG_H_ */

View file

@ -0,0 +1,144 @@
/*
* Copyright (c) 2020 Linumiz
* Copyright (c) 2024 Vogl Electronic GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief hawkBit main header file
*/
/**
* @brief hawkBit Firmware Over-the-Air for Zephyr Project.
* @defgroup hawkbit hawkBit Firmware Over-the-Air
* @ingroup third_party
* @{
*/
#define HAWKBIT_JSON_URL "/default/controller/v1"
#ifndef ZEPHYR_INCLUDE_MGMT_HAWKBIT_HAWKBIT_H_
#define ZEPHYR_INCLUDE_MGMT_HAWKBIT_HAWKBIT_H_
#include <stdint.h>
/**
* @brief Response message from hawkBit.
*
* @details These messages are used to inform the server and the
* user about the process status of the hawkBit and also
* used to standardize the errors that may occur.
*
*/
enum hawkbit_response {
/** matching events were not received within the specified time */
HAWKBIT_NO_RESPONSE,
/** fail to connect to the hawkBit server */
HAWKBIT_NETWORKING_ERROR,
/** image is unconfirmed */
HAWKBIT_UNCONFIRMED_IMAGE,
/** fail to get the permission to access the hawkBit server */
HAWKBIT_PERMISSION_ERROR,
/** fail to parse or to encode the metadata */
HAWKBIT_METADATA_ERROR,
/** fail while downloading the update package */
HAWKBIT_DOWNLOAD_ERROR,
/** image was already updated */
HAWKBIT_OK,
/** an update was installed. Reboot is required to apply it */
HAWKBIT_UPDATE_INSTALLED,
/** no update was available */
HAWKBIT_NO_UPDATE,
/** update was cancelled by the server */
HAWKBIT_CANCEL_UPDATE,
/** hawkBit is not initialized */
HAWKBIT_NOT_INITIALIZED,
/** probe is currently running */
HAWKBIT_PROBE_IN_PROGRESS,
};
/**
* @brief Callback to provide the custom data to the hawkBit server.
*
* @details This callback is used to provide the custom data to the hawkBit server.
* The custom data is used to provide the hawkBit server with the device specific
* data.
*
* @param device_id The device ID.
* @param buffer The buffer to store the json.
* @param buffer_size The size of the buffer.
*/
typedef int (*hawkbit_config_device_data_cb_handler_t)(const char *device_id, uint8_t *buffer,
const size_t buffer_size);
/**
* @brief Set the custom data callback.
*
* @details This function is used to set the custom data callback.
* The callback is used to provide the custom data to the hawkBit server.
*
* @param cb The callback function.
*
* @retval 0 on success.
* @retval -EINVAL if the callback is NULL.
*/
int hawkbit_set_custom_data_cb(hawkbit_config_device_data_cb_handler_t cb);
/**
* @brief Init the flash partition
*
* @retval 0 on success.
* @retval -errno if init fails.
*/
int hawkbit_init(void);
/**
* @brief The hawkBit probe verify if there is some update to be performed.
*
* @return A value from ::hawkbit_response.
*/
enum hawkbit_response hawkbit_probe(void);
/**
* @brief Request system to reboot.
*/
void hawkbit_reboot(void);
/**
* @brief Callback to get the device identity.
*
* @param id Pointer to the buffer to store the device identity
* @param id_max_len The maximum length of the buffer
*/
typedef bool (*hawkbit_get_device_identity_cb_handler_t)(char *id, int id_max_len);
/**
* @brief Set the device identity callback.
*
* @details This function is used to set a custom device identity callback.
*
* @param cb The callback function.
*
* @retval 0 on success.
* @retval -EINVAL if the callback is NULL.
*/
int hawkbit_set_device_identity_cb(hawkbit_get_device_identity_cb_handler_t cb);
/**
* @brief Resets the hawkBit action id, that is saved in settings.
*
* @details This should be done after changing the hawkBit server.
*
* @retval 0 on success.
* @retval -EAGAIN if probe is currently running.
* @retval -EIO if the action id could not be reset.
*
*/
int hawkbit_reset_action_id(void);
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_MGMT_HAWKBIT_HAWKBIT_H_ */

View file

@ -5,7 +5,9 @@
*/
#include <zephyr/kernel.h>
#include <zephyr/mgmt/hawkbit.h>
#include <zephyr/mgmt/hawkbit/hawkbit.h>
#include <zephyr/mgmt/hawkbit/config.h>
#include <zephyr/mgmt/hawkbit/autohandler.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/reboot.h>

View file

@ -17,7 +17,8 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/logging/log_ctrl.h>
#include <zephyr/mgmt/hawkbit.h>
#include <zephyr/mgmt/hawkbit/hawkbit.h>
#include <zephyr/mgmt/hawkbit/config.h>
#include <zephyr/net/dns_resolve.h>
#include <zephyr/net/http/client.h>
#include <zephyr/net/net_ip.h>

View file

@ -6,7 +6,9 @@
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/mgmt/hawkbit.h>
#include <zephyr/mgmt/hawkbit/hawkbit.h>
#include <zephyr/mgmt/hawkbit/config.h>
#include <zephyr/mgmt/hawkbit/autohandler.h>
LOG_MODULE_DECLARE(hawkbit);

View file

@ -5,7 +5,7 @@
*/
#include "hawkbit_device.h"
#include <string.h>
#include <zephyr/mgmt/hawkbit.h>
#include <zephyr/mgmt/hawkbit/hawkbit.h>
static bool hawkbit_get_device_identity_default(char *id, int id_max_len);

View file

@ -9,7 +9,9 @@
#include <zephyr/drivers/flash.h>
#include <zephyr/dfu/mcuboot.h>
#include <zephyr/dfu/flash_img.h>
#include <zephyr/mgmt/hawkbit.h>
#include <zephyr/mgmt/hawkbit/hawkbit.h>
#include <zephyr/mgmt/hawkbit/config.h>
#include <zephyr/mgmt/hawkbit/autohandler.h>
#include "hawkbit_firmware.h"
#include "hawkbit_device.h"