mgmt: mcumgr: grp: os_mgmt: Add optional bootloader info hook
Adds an optional hook that allows for appending additional responses to the bootloader info command Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
adb83d26bf
commit
87a18400dd
|
@ -28,6 +28,24 @@ struct os_mgmt_reset_data {
|
|||
bool force;
|
||||
};
|
||||
|
||||
/**
|
||||
* Structure provided in the #MGMT_EVT_OP_OS_MGMT_BOOTLOADER_INFO notification callback: This
|
||||
* callback function is used to add new fields to the bootloader info response.
|
||||
*/
|
||||
struct os_mgmt_bootloader_info_data {
|
||||
/**
|
||||
* The zcbor encoder which is currently being used to output group information, additional
|
||||
* fields to the group can be added using this.
|
||||
*/
|
||||
zcbor_state_t *zse;
|
||||
|
||||
/** Contains the number of decoded parameters. */
|
||||
const size_t *decoded;
|
||||
|
||||
/** Contains the value of the query parameter. */
|
||||
struct zcbor_string *query;
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -206,10 +206,16 @@ enum os_mgmt_group_events {
|
|||
MGMT_EVT_OP_OS_MGMT_INFO_APPEND = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 2),
|
||||
|
||||
/** Callback when a datetime get command has been received. */
|
||||
MGMT_EVT_OP_OS_MGMT_DATETIME_GET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 3),
|
||||
MGMT_EVT_OP_OS_MGMT_DATETIME_GET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 3),
|
||||
|
||||
/** Callback when a datetime set command has been received, data is struct rtc_time(). */
|
||||
MGMT_EVT_OP_OS_MGMT_DATETIME_SET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 4),
|
||||
MGMT_EVT_OP_OS_MGMT_DATETIME_SET = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 4),
|
||||
|
||||
/**
|
||||
* Callback when a bootloader info command has been received, data is
|
||||
* os_mgmt_bootloader_info_data.
|
||||
*/
|
||||
MGMT_EVT_OP_OS_MGMT_BOOTLOADER_INFO = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_OS, 5),
|
||||
|
||||
/** Used to enable all os_mgmt_group events. */
|
||||
MGMT_EVT_OP_OS_MGMT_ALL = MGMT_DEF_EVT_OP_ALL(MGMT_EVT_GRP_OS),
|
||||
|
|
|
@ -202,6 +202,13 @@ config MCUMGR_GRP_OS_BOOTLOADER_INFO
|
|||
Allows to query MCUmgr about bootloader used by device and various bootloader
|
||||
parameters.
|
||||
|
||||
config MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK
|
||||
bool "Bootloader info hooks"
|
||||
depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
|
||||
help
|
||||
Supports adding custom responses to the bootloader info command by using registered
|
||||
callbacks. Data can be appended to the struct provided in the callback.
|
||||
|
||||
endif # BOOTLOADER_MCUBOOT
|
||||
|
||||
module = MCUMGR_GRP_OS
|
||||
|
|
|
@ -450,6 +450,17 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
|
|||
size_t decoded;
|
||||
bool ok;
|
||||
|
||||
#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK)
|
||||
enum mgmt_cb_return status;
|
||||
int32_t err_rc;
|
||||
uint16_t err_group;
|
||||
struct os_mgmt_bootloader_info_data bootloader_info_data = {
|
||||
.zse = zse,
|
||||
.decoded = &decoded,
|
||||
.query = &query
|
||||
};
|
||||
#endif
|
||||
|
||||
struct zcbor_map_decode_key_val bootloader_info[] = {
|
||||
ZCBOR_MAP_DECODE_KEY_DECODER("query", zcbor_tstr_decode, &query),
|
||||
};
|
||||
|
@ -458,6 +469,21 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
|
|||
return MGMT_ERR_EINVAL;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK)
|
||||
status = mgmt_callback_notify(MGMT_EVT_OP_OS_MGMT_BOOTLOADER_INFO, &bootloader_info_data,
|
||||
sizeof(bootloader_info_data), &err_rc, &err_group);
|
||||
|
||||
if (status != MGMT_CB_OK) {
|
||||
if (status == MGMT_CB_ERROR_RC) {
|
||||
return err_rc;
|
||||
}
|
||||
|
||||
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
|
||||
|
||||
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If no parameter is recognized then just introduce the bootloader. */
|
||||
if (decoded == 0) {
|
||||
ok = zcbor_tstr_put_lit(zse, "bootloader") &&
|
||||
|
|
Loading…
Reference in New Issue