diff --git a/include/zephyr/mgmt/hawkbit.h b/include/zephyr/mgmt/hawkbit.h index 5111cf8087f..3516650a920 100644 --- a/include/zephyr/mgmt/hawkbit.h +++ b/include/zephyr/mgmt/hawkbit.h @@ -219,6 +219,26 @@ static inline char *hawkbit_get_ddi_security_token(void) return hawkbit_get_config().auth_token; } +/** + * @brief Get the hawkBit action id. + * + * @return Action id. + +*/ +int32_t hawkbit_get_action_id(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); + /** * @} */ diff --git a/subsys/mgmt/hawkbit/hawkbit.c b/subsys/mgmt/hawkbit/hawkbit.c index 5ecb0454fd4..f9da2ddd31a 100644 --- a/subsys/mgmt/hawkbit/hawkbit.c +++ b/subsys/mgmt/hawkbit/hawkbit.c @@ -477,6 +477,23 @@ static int hawkbit_device_acid_update(int32_t new_value) return 0; } +int hawkbit_reset_action_id(void) +{ + int ret; + + if (k_sem_take(&probe_sem, K_NO_WAIT) == 0) { + ret = hawkbit_device_acid_update(0); + k_sem_give(&probe_sem); + return ret; + } + return -EAGAIN; +} + +int32_t hawkbit_get_action_id(void) +{ + return hb_cfg.action_id; +} + /* * Update sleep interval, based on results from hawkBit base polling * resource diff --git a/subsys/mgmt/hawkbit/shell.c b/subsys/mgmt/hawkbit/shell.c index d05c98e357b..7f1efbd36af 100644 --- a/subsys/mgmt/hawkbit/shell.c +++ b/subsys/mgmt/hawkbit/shell.c @@ -80,6 +80,7 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv) hawkbit_get_firmware_version(firmware_version, BOOT_IMG_VER_STRLEN_MAX); hawkbit_get_device_identity(device_id, DEVICE_ID_HEX_MAX_SIZE); + shell_print(sh, "Action id: %d", hawkbit_get_action_id()); shell_fprintf(sh, SHELL_NORMAL, "Unique device id: %s\n", device_id); shell_fprintf(sh, SHELL_NORMAL, "Firmware Version: %s\n", firmware_version); @@ -105,6 +106,18 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv) return 0; } +static int cmd_reset(const struct shell *sh, size_t argc, char *argv) +{ + ARG_UNUSED(argc); + ARG_UNUSED(argv); + + int ret = hawkbit_reset_action_id(); + + shell_print(sh, "Reset action id %s", (ret == 0) ? "success" : "failed"); + + return 0; +} + #ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME static int cmd_set_addr(const struct shell *sh, size_t argc, char **argv) @@ -160,6 +173,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE( SHELL_CMD(info, NULL, "Dump hawkBit information", cmd_info), SHELL_CMD(init, NULL, "Initialize hawkBit", cmd_init), SHELL_CMD(run, NULL, "Trigger an hawkBit update run", cmd_run), + SHELL_CMD(reset, NULL, "Reset the hawkBit action id", cmd_reset), #ifdef CONFIG_HAWKBIT_SET_SETTINGS_RUNTIME SHELL_CMD(set, &sub_hawkbit_set, "Set hawkBit settings", NULL), #endif