treewide: mgmt: mcumgr: Change "ret" to "err" for SMP version 2

This is a stable API treewide change changing the newly introduced
"ret" response to "err" as it was overlooked that the shell_mgmt
group already used "ret" to return the exit code of the command
and this created a collision. Since SMP version 2 was only recently
introduced, there should not be any public implementations of it
as of yet, but the original function has been kept and marked as
deprecated.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
Jamie McCrae 2023-07-31 11:14:59 +01:00 committed by Carles Cufí
commit 5c88d45544
23 changed files with 425 additions and 426 deletions

View file

@ -193,7 +193,7 @@ Two types of errors can be returned, the ``rc`` parameter can be set to an
:c:enumerator:`mcumgr_err_t` error code and :c:enumerator:`MGMT_CB_ERROR_RC`
can be returned, or a group error code (introduced with version 2 of the MCUmgr
protocol) can be set by setting the ``group`` value to the group and ``rc``
value to the group error code and returning :c:enumerator:`MGMT_CB_ERROR_RET`.
value to the group error code and returning :c:enumerator:`MGMT_CB_ERROR_ERR`.
MCUmgr Command Callback Usage/Adding New Event Types
====================================================
@ -234,8 +234,8 @@ An example MCUmgr command handler:
static int test_command(struct mgmt_ctxt *ctxt)
{
int rc;
int ret_rc;
uint16_t ret_group;
int err_rc;
uint16_t err_group;
zcbor_state_t *zse = ctxt->cnbe->zs;
bool ok;
struct test_struct test_data = {
@ -243,17 +243,17 @@ An example MCUmgr command handler:
};
rc = mgmt_callback_notify(MGMT_EVT_OP_USER_ONE_FIRST, &test_data,
sizeof(test_data), &ret_rc, &ret_group);
sizeof(test_data), &err_rc, &err_group);
if (rc != MGMT_CB_OK) {
/* A handler returned a failure code */
if (rc == MGMT_CB_ERROR_RC) {
/* The failure code is the RC value */
return ret_rc;
return err_rc;
}
/* The failure is a group and ID error value */
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
goto end;
}

View file

@ -25,39 +25,39 @@ extern "C" {
/**
* Command result codes for file system management group.
*/
enum fs_mgmt_ret_code_t {
enum fs_mgmt_err_code_t {
/** No error, this is implied if there is no ret value in the response */
FS_MGMT_RET_RC_OK = 0,
FS_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
FS_MGMT_RET_RC_UNKNOWN,
FS_MGMT_ERR_UNKNOWN,
/** The specified file name is not valid. */
FS_MGMT_RET_RC_FILE_INVALID_NAME,
FS_MGMT_ERR_FILE_INVALID_NAME,
/** The specified file does not exist. */
FS_MGMT_RET_RC_FILE_NOT_FOUND,
FS_MGMT_ERR_FILE_NOT_FOUND,
/** The specified file is a directory, not a file. */
FS_MGMT_RET_RC_FILE_IS_DIRECTORY,
FS_MGMT_ERR_FILE_IS_DIRECTORY,
/** Error occurred whilst attempting to open a file. */
FS_MGMT_RET_RC_FILE_OPEN_FAILED,
FS_MGMT_ERR_FILE_OPEN_FAILED,
/** Error occurred whilst attempting to seek to an offset in a file. */
FS_MGMT_RET_RC_FILE_SEEK_FAILED,
FS_MGMT_ERR_FILE_SEEK_FAILED,
/** Error occurred whilst attempting to read data from a file. */
FS_MGMT_RET_RC_FILE_READ_FAILED,
FS_MGMT_ERR_FILE_READ_FAILED,
/** Error occurred whilst trying to truncate file. */
FS_MGMT_RET_RC_FILE_TRUNCATE_FAILED,
FS_MGMT_ERR_FILE_TRUNCATE_FAILED,
/** Error occurred whilst trying to delete file. */
FS_MGMT_RET_RC_FILE_DELETE_FAILED,
FS_MGMT_ERR_FILE_DELETE_FAILED,
/** Error occurred whilst attempting to write data to a file. */
FS_MGMT_RET_RC_FILE_WRITE_FAILED,
FS_MGMT_ERR_FILE_WRITE_FAILED,
/**
* The specified data offset is not valid, this could indicate that the file on the device
@ -66,13 +66,13 @@ enum fs_mgmt_ret_code_t {
* hash of the file could be requested and compared with the hash of the length of the
* file being uploaded to see if they match or not).
*/
FS_MGMT_RET_RC_FILE_OFFSET_NOT_VALID,
FS_MGMT_ERR_FILE_OFFSET_NOT_VALID,
/** The requested offset is larger than the size of the file on the device. */
FS_MGMT_RET_RC_FILE_OFFSET_LARGER_THAN_FILE,
FS_MGMT_ERR_FILE_OFFSET_LARGER_THAN_FILE,
/** The requested checksum or hash type was not found or is not supported by this build. */
FS_MGMT_RET_RC_CHECKSUM_HASH_NOT_FOUND,
FS_MGMT_ERR_CHECKSUM_HASH_NOT_FOUND,
};
#ifdef __cplusplus

View file

@ -60,102 +60,102 @@ extern "C" {
/**
* Command result codes for image management group.
*/
enum img_mgmt_ret_code_t {
enum img_mgmt_err_code_t {
/** No error, this is implied if there is no ret value in the response */
IMG_MGMT_RET_RC_OK = 0,
IMG_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
IMG_MGMT_RET_RC_UNKNOWN,
IMG_MGMT_ERR_UNKNOWN,
/** Failed to query flash area configuration. */
IMG_MGMT_RET_RC_FLASH_CONFIG_QUERY_FAIL,
IMG_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL,
/** There is no image in the slot. */
IMG_MGMT_RET_RC_NO_IMAGE,
IMG_MGMT_ERR_NO_IMAGE,
/** The image in the slot has no TLVs (tag, length, value). */
IMG_MGMT_RET_RC_NO_TLVS,
IMG_MGMT_ERR_NO_TLVS,
/** The image in the slot has an invalid TLV type and/or length. */
IMG_MGMT_RET_RC_INVALID_TLV,
IMG_MGMT_ERR_INVALID_TLV,
/** The image in the slot has multiple hash TLVs, which is invalid. */
IMG_MGMT_RET_RC_TLV_MULTIPLE_HASHES_FOUND,
IMG_MGMT_ERR_TLV_MULTIPLE_HASHES_FOUND,
/** The image in the slot has an invalid TLV size. */
IMG_MGMT_RET_RC_TLV_INVALID_SIZE,
IMG_MGMT_ERR_TLV_INVALID_SIZE,
/** The image in the slot does not have a hash TLV, which is required. */
IMG_MGMT_RET_RC_HASH_NOT_FOUND,
IMG_MGMT_ERR_HASH_NOT_FOUND,
/** There is no free slot to place the image. */
IMG_MGMT_RET_RC_NO_FREE_SLOT,
IMG_MGMT_ERR_NO_FREE_SLOT,
/** Flash area opening failed. */
IMG_MGMT_RET_RC_FLASH_OPEN_FAILED,
IMG_MGMT_ERR_FLASH_OPEN_FAILED,
/** Flash area reading failed. */
IMG_MGMT_RET_RC_FLASH_READ_FAILED,
IMG_MGMT_ERR_FLASH_READ_FAILED,
/** Flash area writing failed. */
IMG_MGMT_RET_RC_FLASH_WRITE_FAILED,
IMG_MGMT_ERR_FLASH_WRITE_FAILED,
/** Flash area erase failed. */
IMG_MGMT_RET_RC_FLASH_ERASE_FAILED,
IMG_MGMT_ERR_FLASH_ERASE_FAILED,
/** The provided slot is not valid. */
IMG_MGMT_RET_RC_INVALID_SLOT,
IMG_MGMT_ERR_INVALID_SLOT,
/** Insufficient heap memory (malloc failed). */
IMG_MGMT_RET_RC_NO_FREE_MEMORY,
IMG_MGMT_ERR_NO_FREE_MEMORY,
/** The flash context is already set. */
IMG_MGMT_RET_RC_FLASH_CONTEXT_ALREADY_SET,
IMG_MGMT_ERR_FLASH_CONTEXT_ALREADY_SET,
/** The flash context is not set. */
IMG_MGMT_RET_RC_FLASH_CONTEXT_NOT_SET,
IMG_MGMT_ERR_FLASH_CONTEXT_NOT_SET,
/** The device for the flash area is NULL. */
IMG_MGMT_RET_RC_FLASH_AREA_DEVICE_NULL,
IMG_MGMT_ERR_FLASH_AREA_DEVICE_NULL,
/** The offset for a page number is invalid. */
IMG_MGMT_RET_RC_INVALID_PAGE_OFFSET,
IMG_MGMT_ERR_INVALID_PAGE_OFFSET,
/** The offset parameter was not provided and is required. */
IMG_MGMT_RET_RC_INVALID_OFFSET,
IMG_MGMT_ERR_INVALID_OFFSET,
/** The length parameter was not provided and is required. */
IMG_MGMT_RET_RC_INVALID_LENGTH,
IMG_MGMT_ERR_INVALID_LENGTH,
/** The image length is smaller than the size of an image header. */
IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER,
IMG_MGMT_ERR_INVALID_IMAGE_HEADER,
/** The image header magic value does not match the expected value. */
IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER_MAGIC,
IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC,
/** The hash parameter provided is not valid. */
IMG_MGMT_RET_RC_INVALID_HASH,
IMG_MGMT_ERR_INVALID_HASH,
/** The image load address does not match the address of the flash area. */
IMG_MGMT_RET_RC_INVALID_FLASH_ADDRESS,
IMG_MGMT_ERR_INVALID_FLASH_ADDRESS,
/** Failed to get version of currently running application. */
IMG_MGMT_RET_RC_VERSION_GET_FAILED,
IMG_MGMT_ERR_VERSION_GET_FAILED,
/** The currently running application is newer than the version being uploaded. */
IMG_MGMT_RET_RC_CURRENT_VERSION_IS_NEWER,
IMG_MGMT_ERR_CURRENT_VERSION_IS_NEWER,
/** There is already an image operating pending. */
IMG_MGMT_RET_RC_IMAGE_ALREADY_PENDING,
IMG_MGMT_ERR_IMAGE_ALREADY_PENDING,
/** The image vector table is invalid. */
IMG_MGMT_RET_RC_INVALID_IMAGE_VECTOR_TABLE,
IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE,
/** The image it too large to fit. */
IMG_MGMT_RET_RC_INVALID_IMAGE_TOO_LARGE,
IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE,
/** The amount of data sent is larger than the provided image size. */
IMG_MGMT_RET_RC_INVALID_IMAGE_DATA_OVERRUN,
IMG_MGMT_ERR_INVALID_IMAGE_DATA_OVERRUN,
};
/**

View file

@ -28,15 +28,15 @@ extern "C" {
/**
* Command result codes for OS management group.
*/
enum os_mgmt_ret_code_t {
enum os_mgmt_err_code_t {
/** No error, this is implied if there is no ret value in the response */
OS_MGMT_RET_RC_OK = 0,
OS_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
OS_MGMT_RET_RC_UNKNOWN,
OS_MGMT_ERR_UNKNOWN,
/** The provided format value is not valid. */
OS_MGMT_RET_RC_INVALID_FORMAT,
OS_MGMT_ERR_INVALID_FORMAT,
};
/* Bitmask values used by the os info command handler. Note that the width of this variable is

View file

@ -20,18 +20,18 @@ extern "C" {
/**
* Command result codes for shell management group.
*/
enum shell_mgmt_ret_code_t {
enum shell_mgmt_err_code_t {
/** No error, this is implied if there is no ret value in the response */
SHELL_MGMT_RET_RC_OK = 0,
SHELL_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
SHELL_MGMT_RET_RC_UNKNOWN,
SHELL_MGMT_ERR_UNKNOWN,
/** The provided command to execute is too long. */
SHELL_MGMT_RET_RC_COMMAND_TOO_LONG,
SHELL_MGMT_ERR_COMMAND_TOO_LONG,
/** No command to execute was provided. */
SHELL_MGMT_RET_RC_EMPTY_COMMAND,
SHELL_MGMT_ERR_EMPTY_COMMAND,
};
#ifdef __cplusplus

View file

@ -21,24 +21,24 @@ extern "C" {
/**
* Command result codes for statistics management group.
*/
enum stat_mgmt_ret_code_t {
enum stat_mgmt_err_code_t {
/** No error, this is implied if there is no ret value in the response */
STAT_MGMT_RET_RC_OK = 0,
STAT_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
STAT_MGMT_RET_RC_UNKNOWN,
STAT_MGMT_ERR_UNKNOWN,
/** The provided statistic group name was not found. */
STAT_MGMT_RET_RC_INVALID_GROUP,
STAT_MGMT_ERR_INVALID_GROUP,
/** The provided statistic name was not found. */
STAT_MGMT_RET_RC_INVALID_STAT_NAME,
STAT_MGMT_ERR_INVALID_STAT_NAME,
/** The size of the statistic cannot be handled. */
STAT_MGMT_RET_RC_INVALID_STAT_SIZE,
STAT_MGMT_ERR_INVALID_STAT_SIZE,
/** Walk through of statistics was aborted. */
STAT_MGMT_RET_RC_WALK_ABORTED,
STAT_MGMT_ERR_WALK_ABORTED,
};
/**

View file

@ -18,21 +18,21 @@ extern "C" {
/**
* Command result codes for statistics management group.
*/
enum zephyr_basic_group_ret_code_t {
enum zephyr_basic_group_err_code_t {
/** No error, this is implied if there is no ret value in the response */
ZEPHYR_MGMT_GRP_CMD_RC_OK = 0,
ZEPHYRBASIC_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
ZEPHYR_MGMT_RET_RC_UNKNOWN,
ZEPHYRBASIC_MGMT_ERR_UNKNOWN,
/** Opening of the flash area has failed. */
ZEPHYR_MGMT_GRP_CMD_RC_FLASH_OPEN_FAILED,
ZEPHYRBASIC_MGMT_ERR_FLASH_OPEN_FAILED,
/** Querying the flash area parameters has failed. */
ZEPHYR_MGMT_GRP_CMD_RC_FLASH_CONFIG_QUERY_FAIL,
ZEPHYRBASIC_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL,
/** Erasing the flash area has failed. */
ZEPHYR_MGMT_GRP_CMD_RC_FLASH_ERASE_FAILED,
ZEPHYRBASIC_MGMT_ERR_FLASH_ERASE_FAILED,
};
#ifdef __cplusplus

View file

@ -58,16 +58,19 @@ enum mgmt_cb_return {
/** No error. */
MGMT_CB_OK,
/** SMP protocol error and ``ret_rc`` contains the #mcumgr_err_t error code. */
/** SMP protocol error and ``err_rc`` contains the #mcumgr_err_t error code. */
MGMT_CB_ERROR_RC,
/**
* Group (application-level) error and ``ret_group`` contains the group ID that caused
* the error and ``ret_rc`` contians the error code of that group to return.
* Group (application-level) error and ``err_group`` contains the group ID that caused
* the error and ``err_rc`` contians the error code of that group to return.
*/
MGMT_CB_ERROR_RET,
MGMT_CB_ERROR_ERR,
};
/* Deprecated after Zephyr 3.4, use MGMT_CB_ERROR_ERR instead */
#define MGMT_CB_ERROR_RET __DEPRECATED_MACRO MGMT_CB_ERROR_ERR
/**
* @typedef mgmt_cb
* @brief Function to be called on MGMT notification/event.
@ -80,16 +83,16 @@ enum mgmt_cb_return {
* is being called for a notification only, the return code will be ignored).
* @param rc If ``prev_status`` is #MGMT_CB_ERROR_RC then this is the SMP error that
* was returned by the first handler that failed. If ``prev_status`` is
* #MGMT_CB_ERROR_RET then this will be the group error rc code returned by
* #MGMT_CB_ERROR_ERR then this will be the group error rc code returned by
* the first handler that failed. If the handler wishes to raise an SMP
* error, this must be set to the #mcumgr_err_t status and #MGMT_CB_ERROR_RC
* must be returned by the function, if the handler wishes to raise a ret
* error, this must be set to the group ret status and #MGMT_CB_ERROR_RET
* error, this must be set to the group ret status and #MGMT_CB_ERROR_ERR
* must be returned by the function.
* @param group If ``prev_status`` is #MGMT_CB_ERROR_RET then this is the group of the
* @param group If ``prev_status`` is #MGMT_CB_ERROR_ERR then this is the group of the
* ret error that was returned by the first handler that failed. If the
* handler wishes to raise a ret error, this must be set to the group ret
* status and #MGMT_CB_ERROR_RET must be returned by the function.
* status and #MGMT_CB_ERROR_ERR must be returned by the function.
* @param abort_more Set to true to abort further processing by additional handlers.
* @param data Optional event argument.
* @param data_size Size of optional event argument (0 if no data is provided).
@ -249,18 +252,18 @@ uint8_t mgmt_evt_get_index(uint32_t event);
* @param event #mcumgr_op_t.
* @param data Optional event argument.
* @param data_size Size of optional event argument (0 if none).
* @param ret_rc Pointer to rc value.
* @param ret_group Pointer to group value.
* @param err_rc Pointer to rc value.
* @param err_group Pointer to group value.
*
* @return #mgmt_cb_return either #MGMT_CB_OK if all handlers returned it, or
* #MGMT_CB_ERROR_RC if the first failed handler returned an SMP error (in
* which case ``ret_rc`` will be updated with the SMP error) or
* #MGMT_CB_ERROR_RET if the first failed handler returned a ret group and
* error (in which case ``ret_group`` will be updated with the failed group
* ID and ``ret_rc`` will be updated with the group-specific error code).
* which case ``err_rc`` will be updated with the SMP error) or
* #MGMT_CB_ERROR_ERR if the first failed handler returned a ret group and
* error (in which case ``err_group`` will be updated with the failed group
* ID and ``err_rc`` will be updated with the group-specific error code).
*/
enum mgmt_cb_return mgmt_callback_notify(uint32_t event, void *data, size_t data_size,
int32_t *ret_rc, uint16_t *ret_group);
int32_t *err_rc, uint16_t *err_group);
/**
* @brief Register event callback function.

View file

@ -107,9 +107,9 @@ struct smp_streamer {
int smp_process_request_packet(struct smp_streamer *streamer, void *req);
/**
* @brief Appends a "ret" response
* @brief Appends an "err" response
*
* This appends a ret response to a pending outgoing response which contains a
* This appends an err response to a pending outgoing response which contains a
* result code for a specific group. Note that error codes are specific to the
* command group they are emitted from).
*
@ -119,17 +119,23 @@ int smp_process_request_packet(struct smp_streamer *streamer, void *req);
*
* @return true on success, false on failure (memory error).
*/
bool smp_add_cmd_ret(zcbor_state_t *zse, uint16_t group, uint16_t ret);
bool smp_add_cmd_err(zcbor_state_t *zse, uint16_t group, uint16_t ret);
/** @deprecated Deprecated after Zephyr 3.4, use smp_add_cmd_err() instead */
__deprecated inline bool smp_add_cmd_ret(zcbor_state_t *zse, uint16_t group, uint16_t ret)
{
return smp_add_cmd_err(zse, group, ret);
}
#if IS_ENABLED(CONFIG_MCUMGR_SMP_SUPPORT_ORIGINAL_PROTOCOL)
/** @typedef smp_translate_error_fn
* @brief Translates a SMP version 2 error response to a legacy SMP version 1 error code.
*
* @param ret The SMP version 2 error ret/rc value.
* @param ret The SMP version 2 group error value.
*
* @return #enum mcumgr_err_t Legacy SMP version 1 error code to return to client.
*/
typedef int (*smp_translate_error_fn)(uint16_t ret);
typedef int (*smp_translate_error_fn)(uint16_t err);
#endif
#ifdef __cplusplus

View file

@ -152,20 +152,20 @@ static int fs_mgmt_filelen(const char *path, size_t *out_len)
rc = fs_stat(path, &dirent);
if (rc == -EINVAL) {
return FS_MGMT_RET_RC_FILE_INVALID_NAME;
return FS_MGMT_ERR_FILE_INVALID_NAME;
} else if (rc == -ENOENT) {
return FS_MGMT_RET_RC_FILE_NOT_FOUND;
return FS_MGMT_ERR_FILE_NOT_FOUND;
} else if (rc != 0) {
return FS_MGMT_RET_RC_UNKNOWN;
return FS_MGMT_ERR_UNKNOWN;
}
if (dirent.type != FS_DIR_ENTRY_FILE) {
return FS_MGMT_RET_RC_FILE_IS_DIRECTORY;
return FS_MGMT_ERR_FILE_IS_DIRECTORY;
}
*out_len = dirent.size;
return FS_MGMT_RET_RC_OK;
return FS_MGMT_ERR_OK;
}
/**
@ -226,8 +226,8 @@ static int fs_mgmt_file_download(struct smp_streamer *ctxt)
};
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
ok = zcbor_map_decode_bulk(zsd, fs_download_decode, ARRAY_SIZE(fs_download_decode),
@ -251,14 +251,14 @@ static int fs_mgmt_file_download(struct smp_streamer *ctxt)
#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
/* Send request to application to check if access should be allowed or not */
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS, &file_access_data,
sizeof(file_access_data), &ret_rc, &ret_group);
sizeof(file_access_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
goto end;
}
#endif
@ -270,8 +270,8 @@ static int fs_mgmt_file_download(struct smp_streamer *ctxt)
if (fs_mgmt_ctxt.state == STATE_NO_UPLOAD_OR_DOWNLOAD) {
rc = fs_mgmt_filelen(path, &fs_mgmt_ctxt.len);
if (rc != FS_MGMT_RET_RC_OK) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
if (rc != FS_MGMT_ERR_OK) {
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
@ -281,14 +281,14 @@ static int fs_mgmt_file_download(struct smp_streamer *ctxt)
if (rc != 0) {
if (rc == -EINVAL) {
rc = FS_MGMT_RET_RC_FILE_INVALID_NAME;
rc = FS_MGMT_ERR_FILE_INVALID_NAME;
} else if (rc == -ENOENT) {
rc = FS_MGMT_RET_RC_FILE_NOT_FOUND;
rc = FS_MGMT_ERR_FILE_NOT_FOUND;
} else {
rc = FS_MGMT_RET_RC_UNKNOWN;
rc = FS_MGMT_ERR_UNKNOWN;
}
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
@ -302,8 +302,8 @@ static int fs_mgmt_file_download(struct smp_streamer *ctxt)
rc = fs_seek(&fs_mgmt_ctxt.file, off, FS_SEEK_SET);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_SEEK_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_SEEK_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -319,7 +319,7 @@ static int fs_mgmt_file_download(struct smp_streamer *ctxt)
bytes_read = fs_read(&fs_mgmt_ctxt.file, file_data, MCUMGR_GRP_FS_DL_CHUNK_SIZE);
if (bytes_read < 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, FS_MGMT_RET_RC_FILE_READ_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, FS_MGMT_ERR_FILE_READ_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -374,8 +374,8 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
};
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
ok = zcbor_map_decode_bulk(zsd, fs_upload_decode, ARRAY_SIZE(fs_upload_decode),
@ -400,14 +400,14 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
/* Send request to application to check if access should be allowed or not */
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS, &file_access_data,
sizeof(file_access_data), &ret_rc, &ret_group);
sizeof(file_access_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
goto end;
}
#endif
@ -423,14 +423,14 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
if (rc != 0) {
if (rc == -EINVAL) {
rc = FS_MGMT_RET_RC_FILE_INVALID_NAME;
rc = FS_MGMT_ERR_FILE_INVALID_NAME;
} else if (rc == -ENOENT) {
rc = FS_MGMT_RET_RC_FILE_NOT_FOUND;
rc = FS_MGMT_ERR_FILE_NOT_FOUND;
} else {
rc = FS_MGMT_RET_RC_UNKNOWN;
rc = FS_MGMT_ERR_UNKNOWN;
}
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
@ -449,7 +449,7 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
rc = fs_mgmt_filelen(file_name, &existing_file_size);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
fs_mgmt_cleanup();
goto end;
}
@ -457,7 +457,7 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
rc = fs_mgmt_filelen(file_name, &fs_mgmt_ctxt.off);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
fs_mgmt_cleanup();
goto end;
}
@ -466,7 +466,7 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
/* Verify that the data offset matches the expected offset (i.e. current size of file) */
if (off > 0 && off != fs_mgmt_ctxt.off) {
/* Offset mismatch, send file length, client needs to handle this */
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, FS_MGMT_RET_RC_FILE_OFFSET_NOT_VALID);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, FS_MGMT_ERR_FILE_OFFSET_NOT_VALID);
ok = zcbor_tstr_put_lit(zse, "len") &&
zcbor_uint64_put(zse, fs_mgmt_ctxt.off);
@ -487,8 +487,8 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
rc = fs_seek(&fs_mgmt_ctxt.file, 0, FS_SEEK_SET);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_SEEK_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_SEEK_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -503,8 +503,8 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
rc = fs_unlink(file_name);
if (rc < 0 && rc != -ENOENT) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_DELETE_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_DELETE_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -515,8 +515,8 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
if (rc < 0) {
/* Failed to truncate file */
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_TRUNCATE_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_TRUNCATE_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -528,8 +528,8 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
if (rc < 0) {
/* Failed to seek in file */
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_SEEK_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_SEEK_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -538,8 +538,8 @@ static int fs_mgmt_file_upload(struct smp_streamer *ctxt)
rc = fs_write(&fs_mgmt_ctxt.file, file_data.value, file_data.len);
if (rc < 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_WRITE_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_WRITE_FAILED);
fs_mgmt_cleanup();
goto end;
}
@ -584,8 +584,8 @@ static int fs_mgmt_file_status(struct smp_streamer *ctxt)
};
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
ok = zcbor_map_decode_bulk(zsd, fs_status_decode,
@ -602,14 +602,14 @@ static int fs_mgmt_file_status(struct smp_streamer *ctxt)
#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
/* Send request to application to check if access should be allowed or not */
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS, &file_access_data,
sizeof(file_access_data), &ret_rc, &ret_group);
sizeof(file_access_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
}
#endif
@ -618,7 +618,7 @@ static int fs_mgmt_file_status(struct smp_streamer *ctxt)
rc = fs_mgmt_filelen(path, &file_len);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
@ -676,8 +676,8 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
};
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
ok = zcbor_map_decode_bulk(zsd, fs_hash_checksum_decode,
@ -701,22 +701,22 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
group = fs_mgmt_hash_checksum_find_handler(type_arr);
if (group == NULL) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_CHECKSUM_HASH_NOT_FOUND);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_CHECKSUM_HASH_NOT_FOUND);
goto end;
}
#if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK)
/* Send request to application to check if access should be allowed or not */
status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS, &file_access_data,
sizeof(file_access_data), &ret_rc, &ret_group);
sizeof(file_access_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
}
#endif
@ -725,14 +725,14 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
rc = fs_mgmt_filelen(path, &file_len);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
if (file_len <= off) {
/* Requested offset is larger than target file size */
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_OFFSET_LARGER_THAN_FILE);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_OFFSET_LARGER_THAN_FILE);
goto end;
}
@ -742,14 +742,14 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
if (rc != 0) {
if (rc == -EINVAL) {
rc = FS_MGMT_RET_RC_FILE_INVALID_NAME;
rc = FS_MGMT_ERR_FILE_INVALID_NAME;
} else if (rc == -ENOENT) {
rc = FS_MGMT_RET_RC_FILE_NOT_FOUND;
rc = FS_MGMT_ERR_FILE_NOT_FOUND;
} else {
rc = FS_MGMT_RET_RC_UNKNOWN;
rc = FS_MGMT_ERR_UNKNOWN;
}
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
@ -758,8 +758,8 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
rc = fs_seek(&file, off, FS_SEEK_SET);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS,
FS_MGMT_RET_RC_FILE_SEEK_FAILED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS,
FS_MGMT_ERR_FILE_SEEK_FAILED);
fs_close(&file);
goto end;
}
@ -773,7 +773,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
/* Encode the response */
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_FS, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_FS, rc);
goto end;
}
@ -900,34 +900,24 @@ static int fs_mgmt_close_opened_file(struct smp_streamer *ctxt)
/*
* @brief Translate FS mgmt group error code into MCUmgr error code
*
* @param ret #fs_mgmt_ret_code_t error code
* @param ret #fs_mgmt_err_code_t error code
*
* @return #mcumgr_err_t error code
*/
static int fs_mgmt_translate_error_code(uint16_t ret)
static int fs_mgmt_translate_error_code(uint16_t err)
{
int rc;
switch (ret) {
case FS_MGMT_RET_RC_FILE_INVALID_NAME:
case FS_MGMT_RET_RC_CHECKSUM_HASH_NOT_FOUND:
rc = MGMT_ERR_EINVAL;
break;
case FS_MGMT_RET_RC_FILE_NOT_FOUND:
case FS_MGMT_RET_RC_FILE_IS_DIRECTORY:
rc = MGMT_ERR_ENOENT;
break;
case FS_MGMT_RET_RC_UNKNOWN:
case FS_MGMT_RET_RC_FILE_OPEN_FAILED:
case FS_MGMT_RET_RC_FILE_SEEK_FAILED:
case FS_MGMT_RET_RC_FILE_READ_FAILED:
case FS_MGMT_RET_RC_FILE_TRUNCATE_FAILED:
case FS_MGMT_RET_RC_FILE_DELETE_FAILED:
case FS_MGMT_RET_RC_FILE_WRITE_FAILED:
case FS_MGMT_RET_RC_FILE_OFFSET_NOT_VALID:
case FS_MGMT_RET_RC_FILE_OFFSET_LARGER_THAN_FILE:
switch (err) {
case FS_MGMT_ERR_UNKNOWN:
case FS_MGMT_ERR_FILE_OPEN_FAILED:
case FS_MGMT_ERR_FILE_SEEK_FAILED:
case FS_MGMT_ERR_FILE_READ_FAILED:
case FS_MGMT_ERR_FILE_TRUNCATE_FAILED:
case FS_MGMT_ERR_FILE_DELETE_FAILED:
case FS_MGMT_ERR_FILE_WRITE_FAILED:
case FS_MGMT_ERR_FILE_OFFSET_NOT_VALID:
case FS_MGMT_ERR_FILE_OFFSET_LARGER_THAN_FILE:
default:
rc = MGMT_ERR_EUNKNOWN;
}

View file

@ -130,13 +130,13 @@ static int img_mgmt_find_tlvs(int slot, size_t *start_off, size_t *end_off, uint
if (tlv_info.it_magic != magic) {
/* No TLVs. */
return IMG_MGMT_RET_RC_NO_TLVS;
return IMG_MGMT_ERR_NO_TLVS;
}
*start_off += sizeof(tlv_info);
*end_off = *start_off + tlv_info.it_tlv_tot;
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
int img_mgmt_active_slot(int image)
@ -175,7 +175,7 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
rc = img_mgmt_erased_val(image_slot, &erased_val);
if (rc != 0) {
return IMG_MGMT_RET_RC_FLASH_CONFIG_QUERY_FAIL;
return IMG_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL;
}
rc = img_mgmt_read(image_slot, 0, &hdr, sizeof(hdr));
@ -192,9 +192,9 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
memcpy(ver, &hdr.ih_ver, sizeof(*ver));
}
} else if (hdr.ih_magic == erased_val_32) {
return IMG_MGMT_RET_RC_NO_IMAGE;
return IMG_MGMT_ERR_NO_IMAGE;
} else {
return IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER_MAGIC;
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC;
}
if (flags != NULL) {
@ -218,7 +218,7 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
rc = img_mgmt_find_tlvs(image_slot, &data_off, &data_end, IMAGE_TLV_INFO_MAGIC);
if (rc != 0) {
return IMG_MGMT_RET_RC_NO_TLVS;
return IMG_MGMT_ERR_NO_TLVS;
}
hash_found = false;
@ -228,7 +228,7 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
return rc;
}
if (tlv.it_type == 0xff && tlv.it_len == 0xffff) {
return IMG_MGMT_RET_RC_INVALID_TLV;
return IMG_MGMT_ERR_INVALID_TLV;
}
if (tlv.it_type != IMAGE_TLV_SHA256 || tlv.it_len != IMAGE_HASH_LEN) {
/* Non-hash TLV. Skip it. */
@ -238,14 +238,14 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
if (hash_found) {
/* More than one hash. */
return IMG_MGMT_RET_RC_TLV_MULTIPLE_HASHES_FOUND;
return IMG_MGMT_ERR_TLV_MULTIPLE_HASHES_FOUND;
}
hash_found = true;
data_off += sizeof(tlv);
if (hash != NULL) {
if (data_off + IMAGE_HASH_LEN > data_end) {
return IMG_MGMT_RET_RC_TLV_INVALID_SIZE;
return IMG_MGMT_ERR_TLV_INVALID_SIZE;
}
rc = img_mgmt_read(image_slot, data_off, hash, IMAGE_HASH_LEN);
if (rc != 0) {
@ -255,7 +255,7 @@ int img_mgmt_read_info(int image_slot, struct image_version *ver, uint8_t *hash,
}
if (!hash_found) {
return IMG_MGMT_RET_RC_HASH_NOT_FOUND;
return IMG_MGMT_ERR_HASH_NOT_FOUND;
}
return 0;
@ -373,8 +373,8 @@ img_mgmt_erase(struct smp_streamer *ctxt)
/* Image info is valid. */
if (img_mgmt_slot_in_use(slot)) {
/* No free slot. */
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE,
IMG_MGMT_RET_RC_NO_FREE_SLOT);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE,
IMG_MGMT_ERR_NO_FREE_SLOT);
goto end;
}
}
@ -384,13 +384,13 @@ img_mgmt_erase(struct smp_streamer *ctxt)
if (rc != 0) {
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &ret_rc,
&ret_group);
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &err_rc,
&err_group);
#endif
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, rc);
goto end;
}
@ -487,8 +487,8 @@ img_mgmt_upload(struct smp_streamer *ctxt)
#if defined(CONFIG_MCUMGR_GRP_IMG_UPLOAD_CHECK_HOOK) || \
defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS) || \
defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
struct zcbor_map_decode_key_val image_upload_decode[] = {
@ -529,13 +529,13 @@ defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
rc = img_mgmt_upload_inspect(&req, &action);
if (rc != 0) {
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &ret_rc,
&ret_group);
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &err_rc,
&err_group);
#endif
MGMT_CTXT_SET_RC_RSN(ctxt, IMG_MGMT_UPLOAD_ACTION_RC_RSN(&action));
LOG_ERR("Image upload inspect failed: %d", rc);
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, rc);
goto end;
}
@ -553,17 +553,17 @@ defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
* request.
*/
status = mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CHUNK, &upload_check_data,
sizeof(upload_check_data), &ret_rc, &ret_group);
sizeof(upload_check_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(&action, img_mgmt_err_str_app_reject);
if (status == MGMT_CB_ERROR_RC) {
rc = ret_rc;
rc = err_rc;
ok = zcbor_tstr_put_lit(zse, "rc") &&
zcbor_int32_put(zse, rc);
} else {
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
}
goto end;
@ -586,8 +586,8 @@ defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
g_img_mgmt_state.off = 0;
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STARTED, NULL, 0, &ret_rc,
&ret_group);
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STARTED, NULL, 0, &err_rc,
&err_group);
#endif
#if defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
@ -639,7 +639,7 @@ defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
if (rc != 0) {
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(&action,
img_mgmt_err_str_flash_erase_failed);
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, rc);
goto end;
}
}
@ -675,7 +675,7 @@ defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
LOG_ERR("Irrecoverable error: flash write failed: %d", rc);
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, rc);
goto end;
}
@ -704,11 +704,11 @@ defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_PENDING, NULL, 0,
&ret_rc, &ret_group);
&err_rc, &err_group);
} else {
/* Notify that the write has completed */
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CHUNK_WRITE_COMPLETE,
NULL, 0, &ret_rc, &ret_group);
NULL, 0, &err_rc, &err_group);
#endif
}
}
@ -718,13 +718,13 @@ end:
#if defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
(void)mgmt_callback_notify(MGMT_EVT_OP_CMD_STATUS, &cmd_status_arg,
sizeof(cmd_status_arg), &ret_rc, &ret_group);
sizeof(cmd_status_arg), &err_rc, &err_group);
#endif
if (rc != 0) {
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &ret_rc,
&ret_group);
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_STOPPED, NULL, 0, &err_rc,
&err_group);
#endif
img_mgmt_reset_upload();
@ -764,58 +764,58 @@ int img_mgmt_my_version(struct image_version *ver)
/*
* @brief Translate IMG mgmt group error code into MCUmgr error code
*
* @param ret #img_mgmt_ret_code_t error code
* @param ret #img_mgmt_err_code_t error code
*
* @return #mcumgr_err_t error code
*/
static int img_mgmt_translate_error_code(uint16_t ret)
static int img_mgmt_translate_error_code(uint16_t err)
{
int rc;
switch (ret) {
case IMG_MGMT_RET_RC_NO_IMAGE:
case IMG_MGMT_RET_RC_NO_TLVS:
switch (err) {
case IMG_MGMT_ERR_NO_IMAGE:
case IMG_MGMT_ERR_NO_TLVS:
rc = MGMT_ERR_ENOENT;
break;
case IMG_MGMT_RET_RC_NO_FREE_SLOT:
case IMG_MGMT_RET_RC_CURRENT_VERSION_IS_NEWER:
case IMG_MGMT_RET_RC_IMAGE_ALREADY_PENDING:
case IMG_MGMT_ERR_NO_FREE_SLOT:
case IMG_MGMT_ERR_CURRENT_VERSION_IS_NEWER:
case IMG_MGMT_ERR_IMAGE_ALREADY_PENDING:
rc = MGMT_ERR_EBADSTATE;
break;
case IMG_MGMT_RET_RC_NO_FREE_MEMORY:
case IMG_MGMT_ERR_NO_FREE_MEMORY:
rc = MGMT_ERR_ENOMEM;
break;
case IMG_MGMT_RET_RC_INVALID_SLOT:
case IMG_MGMT_RET_RC_INVALID_PAGE_OFFSET:
case IMG_MGMT_RET_RC_INVALID_OFFSET:
case IMG_MGMT_RET_RC_INVALID_LENGTH:
case IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER:
case IMG_MGMT_RET_RC_INVALID_HASH:
case IMG_MGMT_RET_RC_INVALID_FLASH_ADDRESS:
case IMG_MGMT_ERR_INVALID_SLOT:
case IMG_MGMT_ERR_INVALID_PAGE_OFFSET:
case IMG_MGMT_ERR_INVALID_OFFSET:
case IMG_MGMT_ERR_INVALID_LENGTH:
case IMG_MGMT_ERR_INVALID_IMAGE_HEADER:
case IMG_MGMT_ERR_INVALID_HASH:
case IMG_MGMT_ERR_INVALID_FLASH_ADDRESS:
rc = MGMT_ERR_EINVAL;
break;
case IMG_MGMT_RET_RC_FLASH_CONFIG_QUERY_FAIL:
case IMG_MGMT_RET_RC_VERSION_GET_FAILED:
case IMG_MGMT_RET_RC_TLV_MULTIPLE_HASHES_FOUND:
case IMG_MGMT_RET_RC_TLV_INVALID_SIZE:
case IMG_MGMT_RET_RC_HASH_NOT_FOUND:
case IMG_MGMT_RET_RC_INVALID_TLV:
case IMG_MGMT_RET_RC_FLASH_OPEN_FAILED:
case IMG_MGMT_RET_RC_FLASH_READ_FAILED:
case IMG_MGMT_RET_RC_FLASH_WRITE_FAILED:
case IMG_MGMT_RET_RC_FLASH_ERASE_FAILED:
case IMG_MGMT_RET_RC_FLASH_CONTEXT_ALREADY_SET:
case IMG_MGMT_RET_RC_FLASH_CONTEXT_NOT_SET:
case IMG_MGMT_RET_RC_FLASH_AREA_DEVICE_NULL:
case IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER_MAGIC:
case IMG_MGMT_RET_RC_INVALID_IMAGE_VECTOR_TABLE:
case IMG_MGMT_RET_RC_INVALID_IMAGE_TOO_LARGE:
case IMG_MGMT_RET_RC_INVALID_IMAGE_DATA_OVERRUN:
case IMG_MGMT_RET_RC_UNKNOWN:
case IMG_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL:
case IMG_MGMT_ERR_VERSION_GET_FAILED:
case IMG_MGMT_ERR_TLV_MULTIPLE_HASHES_FOUND:
case IMG_MGMT_ERR_TLV_INVALID_SIZE:
case IMG_MGMT_ERR_HASH_NOT_FOUND:
case IMG_MGMT_ERR_INVALID_TLV:
case IMG_MGMT_ERR_FLASH_OPEN_FAILED:
case IMG_MGMT_ERR_FLASH_READ_FAILED:
case IMG_MGMT_ERR_FLASH_WRITE_FAILED:
case IMG_MGMT_ERR_FLASH_ERASE_FAILED:
case IMG_MGMT_ERR_FLASH_CONTEXT_ALREADY_SET:
case IMG_MGMT_ERR_FLASH_CONTEXT_NOT_SET:
case IMG_MGMT_ERR_FLASH_AREA_DEVICE_NULL:
case IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC:
case IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE:
case IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE:
case IMG_MGMT_ERR_INVALID_IMAGE_DATA_OVERRUN:
case IMG_MGMT_ERR_UNKNOWN:
default:
rc = MGMT_ERR_EUNKNOWN;
}

View file

@ -183,7 +183,7 @@ img_mgmt_state_set_pending(int slot, int permanent)
* run if it is a loader in a split image setup.
*/
if (state_flags & IMG_MGMT_STATE_F_CONFIRMED && slot != 0) {
rc = IMG_MGMT_RET_RC_IMAGE_ALREADY_PENDING;
rc = IMG_MGMT_ERR_IMAGE_ALREADY_PENDING;
goto done;
}
@ -204,21 +204,21 @@ img_mgmt_state_confirm(void)
int rc;
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
/* Confirm disallowed if a test is pending. */
if (img_mgmt_state_any_pending()) {
rc = IMG_MGMT_RET_RC_IMAGE_ALREADY_PENDING;
rc = IMG_MGMT_ERR_IMAGE_ALREADY_PENDING;
goto err;
}
rc = img_mgmt_write_confirmed();
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &ret_rc,
&ret_group);
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &err_rc,
&err_group);
#endif
err:
@ -305,8 +305,8 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
bool active = (slot == img_mgmt_active_slot(img_mgmt_active_image()));
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
if (active) {
@ -320,11 +320,11 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
/* Confirm disallowed if a test is pending. */
if (active && img_mgmt_state_any_pending()) {
return IMG_MGMT_RET_RC_IMAGE_ALREADY_PENDING;
return IMG_MGMT_ERR_IMAGE_ALREADY_PENDING;
}
if (flash_area_open(area_id, &fa) != 0) {
return IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
return IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
rc = boot_set_next(fa, active, confirm);
@ -338,13 +338,13 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
/* Translate from boot util error code to IMG mgmt group error code */
if (rc == BOOT_EFLASH) {
rc = IMG_MGMT_RET_RC_FLASH_WRITE_FAILED;
rc = IMG_MGMT_ERR_FLASH_WRITE_FAILED;
} else if (rc == BOOT_EBADVECT) {
rc = IMG_MGMT_RET_RC_INVALID_IMAGE_VECTOR_TABLE;
rc = IMG_MGMT_ERR_INVALID_IMAGE_VECTOR_TABLE;
} else if (rc == BOOT_EBADIMAGE) {
rc = IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER_MAGIC;
rc = IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC;
} else {
rc = IMG_MGMT_RET_RC_UNKNOWN;
rc = IMG_MGMT_ERR_UNKNOWN;
}
}
flash_area_close(fa);
@ -352,8 +352,8 @@ int img_mgmt_set_next_boot_slot(int slot, bool confirm)
#if defined(CONFIG_MCUMGR_GRP_IMG_STATUS_HOOKS)
if (active) {
/* Confirm event is only sent for active slot */
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &ret_rc,
&ret_group);
(void)mgmt_callback_notify(MGMT_EVT_OP_IMG_MGMT_DFU_CONFIRMED, NULL, 0, &err_rc,
&err_group);
}
#endif
@ -396,15 +396,15 @@ img_mgmt_state_write(struct smp_streamer *ctxt)
slot = img_mgmt_active_slot(img_mgmt_active_image());
} else {
/* A 'test' without a hash is invalid. */
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE,
IMG_MGMT_RET_RC_INVALID_HASH);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE,
IMG_MGMT_ERR_INVALID_HASH);
goto end;
}
} else if (zhash.len != IMAGE_HASH_LEN) {
/* The img_mgmt_find_by_hash does exact length compare
* so just fail here.
*/
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE, IMG_MGMT_RET_RC_INVALID_HASH);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, IMG_MGMT_ERR_INVALID_HASH);
goto end;
} else {
uint8_t hash[IMAGE_HASH_LEN];
@ -413,15 +413,15 @@ img_mgmt_state_write(struct smp_streamer *ctxt)
slot = img_mgmt_find_by_hash(hash, NULL);
if (slot < 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE,
IMG_MGMT_RET_RC_HASH_NOT_FOUND);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE,
IMG_MGMT_ERR_HASH_NOT_FOUND);
goto end;
}
}
rc = img_mgmt_set_next_boot_slot(slot, confirm);
if (rc != 0) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_IMAGE, rc);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_IMAGE, rc);
goto end;
}

View file

@ -106,7 +106,7 @@ static int img_mgmt_flash_check_empty_inner(const struct flash_area *fa)
rc = flash_area_read(fa, addr, data, bytes_to_read);
if (rc < 0) {
LOG_ERR("Failed to read data from flash area: %d", rc);
return IMG_MGMT_RET_RC_FLASH_READ_FAILED;
return IMG_MGMT_ERR_FLASH_READ_FAILED;
}
for (i = 0; i < bytes_to_read / 4; i++) {
@ -138,7 +138,7 @@ static int img_mgmt_flash_check_empty(uint8_t fa_id)
flash_area_close(fa);
} else {
LOG_ERR("Failed to open flash area ID %u: %d", fa_id, rc);
rc = IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
rc = IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
return rc;
@ -291,14 +291,14 @@ int img_mgmt_erase_slot(int slot)
int area_id = img_mgmt_flash_area_id(slot);
if (area_id < 0) {
return IMG_MGMT_RET_RC_INVALID_SLOT;
return IMG_MGMT_ERR_INVALID_SLOT;
}
rc = flash_area_open(area_id, &fa);
if (rc < 0) {
LOG_ERR("Failed to open flash area ID %u: %d", area_id, rc);
return IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
return IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
rc = img_mgmt_flash_check_empty_inner(fa);
@ -308,7 +308,7 @@ int img_mgmt_erase_slot(int slot)
if (rc != 0) {
LOG_ERR("Failed to erase flash area: %d", rc);
rc = IMG_MGMT_RET_RC_FLASH_ERASE_FAILED;
rc = IMG_MGMT_ERR_FLASH_ERASE_FAILED;
}
}
@ -322,16 +322,16 @@ int img_mgmt_write_pending(int slot, bool permanent)
int rc;
if (slot != 1 && !(CONFIG_MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER == 2 && slot == 3)) {
return IMG_MGMT_RET_RC_INVALID_SLOT;
return IMG_MGMT_ERR_INVALID_SLOT;
}
rc = boot_request_upgrade_multi(img_mgmt_slot_to_image(slot), permanent);
if (rc != 0) {
LOG_ERR("Failed to write pending flag for slot %d: %d", slot, rc);
return IMG_MGMT_RET_RC_FLASH_WRITE_FAILED;
return IMG_MGMT_ERR_FLASH_WRITE_FAILED;
}
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
int img_mgmt_write_confirmed(void)
@ -341,10 +341,10 @@ int img_mgmt_write_confirmed(void)
rc = boot_write_img_confirmed();
if (rc != 0) {
LOG_ERR("Failed to write confirmed flag: %d", rc);
return IMG_MGMT_RET_RC_FLASH_WRITE_FAILED;
return IMG_MGMT_ERR_FLASH_WRITE_FAILED;
}
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
int img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_bytes)
@ -354,13 +354,13 @@ int img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_byt
int area_id = img_mgmt_flash_area_id(slot);
if (area_id < 0) {
return IMG_MGMT_RET_RC_INVALID_SLOT;
return IMG_MGMT_ERR_INVALID_SLOT;
}
rc = flash_area_open(area_id, &fa);
if (rc != 0) {
LOG_ERR("Failed to open flash area ID %u: %d", area_id, rc);
return IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
return IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
rc = flash_area_read(fa, offset, dst, num_bytes);
@ -368,7 +368,7 @@ int img_mgmt_read(int slot, unsigned int offset, void *dst, unsigned int num_byt
if (rc != 0) {
LOG_ERR("Failed to read data from flash: %d", rc);
return IMG_MGMT_RET_RC_FLASH_READ_FAILED;
return IMG_MGMT_ERR_FLASH_READ_FAILED;
}
return 0;
@ -386,31 +386,31 @@ int img_mgmt_write_image_data(unsigned int offset, const void *data, unsigned in
BUILD_ASSERT(CONFIG_HEAP_MEM_POOL_SIZE >= (sizeof(struct flash_img_context)),
"Not enough heap mem for flash_img_context.");
int rc = IMG_MGMT_RET_RC_OK;
int rc = IMG_MGMT_ERR_OK;
static struct flash_img_context *ctx;
if (offset != 0 && ctx == NULL) {
return IMG_MGMT_RET_RC_FLASH_CONTEXT_NOT_SET;
return IMG_MGMT_ERR_FLASH_CONTEXT_NOT_SET;
}
if (offset == 0) {
if (ctx != NULL) {
return IMG_MGMT_RET_RC_FLASH_CONTEXT_ALREADY_SET;
return IMG_MGMT_ERR_FLASH_CONTEXT_ALREADY_SET;
}
ctx = k_malloc(sizeof(struct flash_img_context));
if (ctx == NULL) {
return IMG_MGMT_RET_RC_NO_FREE_MEMORY;
return IMG_MGMT_ERR_NO_FREE_MEMORY;
}
if (flash_img_init_id(ctx, g_img_mgmt_state.area_id) != 0) {
rc = IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
rc = IMG_MGMT_ERR_FLASH_OPEN_FAILED;
goto out;
}
}
if (flash_img_buffered_write(ctx, data, num_bytes, last) != 0) {
rc = IMG_MGMT_RET_RC_FLASH_WRITE_FAILED;
rc = IMG_MGMT_ERR_FLASH_WRITE_FAILED;
goto out;
}
@ -430,15 +430,15 @@ int img_mgmt_write_image_data(unsigned int offset, const void *data, unsigned in
if (offset == 0) {
if (flash_img_init_id(&ctx, g_img_mgmt_state.area_id) != 0) {
return IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
return IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
}
if (flash_img_buffered_write(&ctx, data, num_bytes, last) != 0) {
return IMG_MGMT_RET_RC_FLASH_WRITE_FAILED;
return IMG_MGMT_ERR_FLASH_WRITE_FAILED;
}
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
#endif
@ -448,14 +448,14 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
int rc;
if (off != 0) {
rc = IMG_MGMT_RET_RC_INVALID_OFFSET;
rc = IMG_MGMT_ERR_INVALID_OFFSET;
goto end;
}
rc = flash_area_open(g_img_mgmt_state.area_id, &fa);
if (rc != 0) {
LOG_ERR("Can't bind to the flash area (err %d)", rc);
rc = IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
rc = IMG_MGMT_ERR_FLASH_OPEN_FAILED;
goto end;
}
@ -463,7 +463,7 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
const struct device *dev = flash_area_get_device(fa);
if (dev == NULL) {
rc = IMG_MGMT_RET_RC_FLASH_AREA_DEVICE_NULL;
rc = IMG_MGMT_ERR_FLASH_AREA_DEVICE_NULL;
goto end_fa;
}
struct flash_pages_info page;
@ -472,7 +472,7 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
rc = flash_get_page_info_by_offs(dev, page_offset, &page);
if (rc != 0) {
LOG_ERR("bad offset (0x%lx)", (long)page_offset);
rc = IMG_MGMT_RET_RC_INVALID_PAGE_OFFSET;
rc = IMG_MGMT_ERR_INVALID_PAGE_OFFSET;
goto end_fa;
}
@ -483,7 +483,7 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
if (rc != 0) {
LOG_ERR("image slot erase of 0x%zx bytes failed (err %d)", erase_size,
rc);
rc = IMG_MGMT_RET_RC_FLASH_ERASE_FAILED;
rc = IMG_MGMT_ERR_FLASH_ERASE_FAILED;
goto end_fa;
}
@ -507,14 +507,14 @@ int img_mgmt_erase_image_data(unsigned int off, unsigned int num_bytes)
if (rc != 0) {
LOG_ERR("image slot trailer erase of 0x%zx bytes failed (err %d)",
erase_size, rc);
rc = IMG_MGMT_RET_RC_FLASH_ERASE_FAILED;
rc = IMG_MGMT_ERR_FLASH_ERASE_FAILED;
goto end_fa;
}
LOG_INF("Erased 0x%zx bytes of image slot trailer", erase_size);
}
#endif
rc = IMG_MGMT_RET_RC_OK;
rc = IMG_MGMT_ERR_OK;
end_fa:
flash_area_close(fa);
@ -565,7 +565,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
if (req->off == SIZE_MAX) {
/* Request did not include an `off` field. */
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_hdr_malformed);
return IMG_MGMT_RET_RC_INVALID_OFFSET;
return IMG_MGMT_ERR_INVALID_OFFSET;
}
if (req->off == 0) {
@ -575,24 +575,24 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
if (req->img_data.len < sizeof(struct image_header)) {
/* Image header is the first thing in the image */
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_hdr_malformed);
return IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER;
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER;
}
if (req->size == SIZE_MAX) {
/* Request did not include a `len` field. */
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_hdr_malformed);
return IMG_MGMT_RET_RC_INVALID_LENGTH;
return IMG_MGMT_ERR_INVALID_LENGTH;
}
action->size = req->size;
hdr = (struct image_header *)req->img_data.value;
if (hdr->ih_magic != IMAGE_MAGIC) {
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_magic_mismatch);
return IMG_MGMT_RET_RC_INVALID_IMAGE_HEADER_MAGIC;
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC;
}
if (req->data_sha.len > IMG_MGMT_DATA_SHA_LEN) {
return IMG_MGMT_RET_RC_INVALID_HASH;
return IMG_MGMT_ERR_INVALID_HASH;
}
/*
@ -605,7 +605,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
if ((g_img_mgmt_state.data_sha_len == req->data_sha.len) &&
!memcmp(g_img_mgmt_state.data_sha, req->data_sha.value,
req->data_sha.len)) {
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
}
@ -613,7 +613,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
if (action->area_id < 0) {
/* No slot where to upload! */
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_no_slot);
return IMG_MGMT_RET_RC_NO_FREE_SLOT;
return IMG_MGMT_ERR_NO_FREE_SLOT;
}
rc = flash_area_open(action->area_id, &fa);
@ -621,7 +621,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
img_mgmt_err_str_flash_open_failed);
LOG_ERR("Failed to open flash area ID %u: %d", action->area_id, rc);
return IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
return IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
/* Check that the area is of sufficient size to store the new image */
@ -630,7 +630,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
img_mgmt_err_str_image_too_large);
flash_area_close(fa);
LOG_ERR("Upload too large for slot: %u > %u", req->size, fa->fa_size);
return IMG_MGMT_RET_RC_INVALID_IMAGE_TOO_LARGE;
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE;
}
#if defined(CONFIG_MCUMGR_GRP_IMG_REJECT_DIRECT_XIP_MISMATCHED_SLOT)
@ -639,7 +639,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
img_mgmt_err_str_image_bad_flash_addr);
flash_area_close(fa);
return IMG_MGMT_RET_RC_INVALID_FLASH_ADDRESS;
return IMG_MGMT_ERR_INVALID_FLASH_ADDRESS;
}
}
#endif
@ -652,13 +652,13 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
*/
rc = img_mgmt_my_version(&cur_ver);
if (rc != 0) {
return IMG_MGMT_RET_RC_VERSION_GET_FAILED;
return IMG_MGMT_ERR_VERSION_GET_FAILED;
}
if (img_mgmt_vercmp(&cur_ver, &hdr->ih_ver) >= 0) {
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
img_mgmt_err_str_downgrade);
return IMG_MGMT_RET_RC_CURRENT_VERSION_IS_NEWER;
return IMG_MGMT_ERR_CURRENT_VERSION_IS_NEWER;
}
}
@ -680,7 +680,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
* Invalid offset. Drop the data, and respond with the offset we're
* expecting data for.
*/
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
if ((req->off + req->img_data.len) > action->size) {
@ -688,7 +688,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
* of the image that the client originally sent
*/
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_data_overrun);
return IMG_MGMT_RET_RC_INVALID_IMAGE_DATA_OVERRUN;
return IMG_MGMT_ERR_INVALID_IMAGE_DATA_OVERRUN;
}
}
@ -696,7 +696,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
action->proceed = true;
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, NULL);
return IMG_MGMT_RET_RC_OK;
return IMG_MGMT_ERR_OK;
}
int img_mgmt_erased_val(int slot, uint8_t *erased_val)
@ -706,13 +706,13 @@ int img_mgmt_erased_val(int slot, uint8_t *erased_val)
int area_id = img_mgmt_flash_area_id(slot);
if (area_id < 0) {
return IMG_MGMT_RET_RC_INVALID_SLOT;
return IMG_MGMT_ERR_INVALID_SLOT;
}
rc = flash_area_open(area_id, &fa);
if (rc != 0) {
LOG_ERR("Failed to open flash area ID %u: %d", area_id, rc);
return IMG_MGMT_RET_RC_FLASH_OPEN_FAILED;
return IMG_MGMT_ERR_FLASH_OPEN_FAILED;
}
*erased_val = flash_area_erased_val(fa);

View file

@ -318,8 +318,8 @@ static int os_mgmt_reset(struct smp_streamer *ctxt)
zcbor_state_t *zse = ctxt->writer->zs;
size_t decoded;
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
struct os_mgmt_reset_data reboot_data = {
.force = false
@ -334,16 +334,16 @@ static int os_mgmt_reset(struct smp_streamer *ctxt)
*/
(void)zcbor_map_decode_bulk(zsd, reset_decode, ARRAY_SIZE(reset_decode), &decoded);
status = mgmt_callback_notify(MGMT_EVT_OP_OS_MGMT_RESET, &reboot_data,
sizeof(reboot_data), &ret_rc, &ret_group);
sizeof(reboot_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
bool ok;
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
}
#endif
@ -413,8 +413,8 @@ static int os_mgmt_info(struct smp_streamer *ctxt)
#ifdef CONFIG_MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
if (zcbor_map_decode_bulk(zsd, fs_info_decode, ARRAY_SIZE(fs_info_decode), &decoded)) {
@ -491,12 +491,12 @@ static int os_mgmt_info(struct smp_streamer *ctxt)
#ifdef CONFIG_MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS
/* Run callbacks to see if any additional handlers will add options */
(void)mgmt_callback_notify(MGMT_EVT_OP_OS_MGMT_INFO_CHECK, &check_data,
sizeof(check_data), &ret_rc, &ret_group);
sizeof(check_data), &err_rc, &err_group);
#endif
if (valid_formats != format.len) {
/* A provided format specifier is not valid */
bool ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_OS, OS_MGMT_RET_RC_INVALID_FORMAT);
bool ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_OS, OS_MGMT_ERR_INVALID_FORMAT);
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
} else if (format_bitmask == 0) {
@ -657,16 +657,16 @@ static int os_mgmt_info(struct smp_streamer *ctxt)
#ifdef CONFIG_MCUMGR_GRP_OS_INFO_CUSTOM_HOOKS
/* Call custom handler command for additional output/processing */
status = mgmt_callback_notify(MGMT_EVT_OP_OS_MGMT_INFO_APPEND, &append_data,
sizeof(append_data), &ret_rc, &ret_group);
sizeof(append_data), &err_rc, &err_group);
if (status != MGMT_CB_OK) {
bool ok;
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
}
#endif
@ -685,20 +685,20 @@ fail:
/*
* @brief Translate OS mgmt group error code into MCUmgr error code
*
* @param ret #os_mgmt_ret_code_t error code
* @param ret #os_mgmt_err_code_t error code
*
* @return #mcumgr_err_t error code
*/
static int os_mgmt_translate_error_code(uint16_t ret)
static int os_mgmt_translate_error_code(uint16_t err)
{
int rc;
switch (ret) {
case OS_MGMT_RET_RC_INVALID_FORMAT:
switch (err) {
case OS_MGMT_ERR_INVALID_FORMAT:
rc = MGMT_ERR_EINVAL;
break;
case OS_MGMT_RET_RC_UNKNOWN:
case OS_MGMT_ERR_UNKNOWN:
default:
rc = MGMT_ERR_EUNKNOWN;
}

View file

@ -84,8 +84,8 @@ shell_mgmt_exec(struct smp_streamer *ctxt)
ok = zcbor_tstr_decode(zsd, &value);
if (ok) {
if ((len + value.len) >= (ARRAY_SIZE(line) - 1)) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_SHELL,
SHELL_MGMT_RET_RC_COMMAND_TOO_LONG);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_SHELL,
SHELL_MGMT_ERR_COMMAND_TOO_LONG);
goto end;
}
@ -104,7 +104,7 @@ shell_mgmt_exec(struct smp_streamer *ctxt)
if (len == 0) {
/* We do not bother to close decoder */
LOG_ERR("Failed to compose command line");
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_SHELL, SHELL_MGMT_RET_RC_EMPTY_COMMAND);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_SHELL, SHELL_MGMT_ERR_EMPTY_COMMAND);
goto end;
}
@ -132,17 +132,17 @@ end:
/*
* @brief Translate shell mgmt group error code into MCUmgr error code
*
* @param ret #shell_mgmt_ret_code_t error code
* @param ret #shell_mgmt_err_code_t error code
*
* @return #mcumgr_err_t error code
*/
static int shell_mgmt_translate_error_code(uint16_t ret)
static int shell_mgmt_translate_error_code(uint16_t err)
{
int rc;
switch (ret) {
case SHELL_MGMT_RET_RC_COMMAND_TOO_LONG:
case SHELL_MGMT_RET_RC_EMPTY_COMMAND:
switch (err) {
case SHELL_MGMT_ERR_COMMAND_TOO_LONG:
case SHELL_MGMT_ERR_EMPTY_COMMAND:
rc = MGMT_ERR_EINVAL;
break;

View file

@ -80,7 +80,7 @@ stat_mgmt_walk_cb(struct stats_hdr *hdr, void *arg, const char *name, uint16_t o
entry.value = *(uint64_t *) stat_val;
break;
default:
return STAT_MGMT_RET_RC_INVALID_STAT_SIZE;
return STAT_MGMT_ERR_INVALID_STAT_SIZE;
}
entry.name = name;
@ -96,7 +96,7 @@ stat_mgmt_foreach_entry(zcbor_state_t *zse, const char *group_name, stat_mgmt_fo
hdr = stats_group_find(group_name);
if (hdr == NULL) {
return STAT_MGMT_RET_RC_INVALID_GROUP;
return STAT_MGMT_ERR_INVALID_GROUP;
}
walk_arg = (struct stat_mgmt_walk_arg) {
@ -145,8 +145,8 @@ stat_mgmt_show(struct smp_streamer *ctxt)
if (stat_mgmt_count(stat_name, &counter) != 0) {
LOG_ERR("Invalid stat name: %s", stat_name);
ok = smp_add_cmd_ret(zse, ZEPHYR_MGMT_GRP_BASIC,
STAT_MGMT_RET_RC_INVALID_STAT_NAME);
ok = smp_add_cmd_err(zse, ZEPHYR_MGMT_GRP_BASIC,
STAT_MGMT_ERR_INVALID_STAT_NAME);
goto end;
}
@ -166,13 +166,13 @@ stat_mgmt_show(struct smp_streamer *ctxt)
int rc = stat_mgmt_foreach_entry(zse, stat_name,
stat_mgmt_cb_encode);
if (rc != STAT_MGMT_RET_RC_OK) {
if (rc != STAT_MGMT_RET_RC_INVALID_GROUP &&
rc != STAT_MGMT_RET_RC_INVALID_STAT_SIZE) {
rc = STAT_MGMT_RET_RC_WALK_ABORTED;
if (rc != STAT_MGMT_ERR_OK) {
if (rc != STAT_MGMT_ERR_INVALID_GROUP &&
rc != STAT_MGMT_ERR_INVALID_STAT_SIZE) {
rc = STAT_MGMT_ERR_WALK_ABORTED;
}
ok = smp_add_cmd_ret(zse, ZEPHYR_MGMT_GRP_BASIC, rc);
ok = smp_add_cmd_err(zse, ZEPHYR_MGMT_GRP_BASIC, rc);
}
}
@ -230,25 +230,25 @@ stat_mgmt_list(struct smp_streamer *ctxt)
/*
* @brief Translate stat mgmt group error code into MCUmgr error code
*
* @param ret #stat_mgmt_ret_code_t error code
* @param ret #stat_mgmt_err_code_t error code
*
* @return #mcumgr_err_t error code
*/
static int stat_mgmt_translate_error_code(uint16_t ret)
static int stat_mgmt_translate_error_code(uint16_t err)
{
int rc;
switch (ret) {
case STAT_MGMT_RET_RC_INVALID_GROUP:
case STAT_MGMT_RET_RC_INVALID_STAT_NAME:
switch (err) {
case STAT_MGMT_ERR_INVALID_GROUP:
case STAT_MGMT_ERR_INVALID_STAT_NAME:
rc = MGMT_ERR_ENOENT;
break;
case STAT_MGMT_RET_RC_INVALID_STAT_SIZE:
case STAT_MGMT_ERR_INVALID_STAT_SIZE:
rc = MGMT_ERR_EINVAL;
break;
case STAT_MGMT_RET_RC_WALK_ABORTED:
case STAT_MGMT_ERR_WALK_ABORTED:
default:
rc = MGMT_ERR_EUNKNOWN;
}

View file

@ -25,17 +25,17 @@ static int storage_erase(void)
if (rc < 0) {
LOG_ERR("Failed to open flash area");
rc = ZEPHYR_MGMT_GRP_CMD_RC_FLASH_OPEN_FAILED;
rc = ZEPHYRBASIC_MGMT_ERR_FLASH_OPEN_FAILED;
} else {
if (flash_area_get_device(fa) == NULL) {
LOG_ERR("Failed to get flash area device");
rc = ZEPHYR_MGMT_GRP_CMD_RC_FLASH_CONFIG_QUERY_FAIL;
rc = ZEPHYRBASIC_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL;
} else {
rc = flash_area_erase(fa, 0, fa->fa_size);
if (rc < 0) {
LOG_ERR("Failed to erase flash area");
rc = ZEPHYR_MGMT_GRP_CMD_RC_FLASH_ERASE_FAILED;
rc = ZEPHYRBASIC_MGMT_ERR_FLASH_ERASE_FAILED;
}
}
@ -53,8 +53,8 @@ static int storage_erase_handler(struct smp_streamer *ctxt)
rc = storage_erase();
if (rc != ZEPHYR_MGMT_GRP_CMD_RC_OK) {
ok = smp_add_cmd_ret(zse, ZEPHYR_MGMT_GRP_BASIC, rc);
if (rc != ZEPHYRBASIC_MGMT_ERR_OK) {
ok = smp_add_cmd_err(zse, ZEPHYR_MGMT_GRP_BASIC, rc);
}
if (!ok) {
@ -68,7 +68,7 @@ static int storage_erase_handler(struct smp_streamer *ctxt)
/*
* @brief Translate zephyr basic group error code into MCUmgr error code
*
* @param ret #zephyr_basic_group_ret_code_t error code
* @param ret #zephyr_basic_group_err_code_t error code
*
* @return #mcumgr_err_t error code
*/
@ -77,12 +77,12 @@ static int zephyr_basic_group_translate_error_code(uint16_t ret)
int rc;
switch (ret) {
case ZEPHYR_MGMT_GRP_CMD_RC_FLASH_OPEN_FAILED:
case ZEPHYRBASIC_MGMT_ERR_FLASH_OPEN_FAILED:
rc = MGMT_ERR_ENOENT;
break;
case ZEPHYR_MGMT_GRP_CMD_RC_FLASH_CONFIG_QUERY_FAIL:
case ZEPHYR_MGMT_GRP_CMD_RC_FLASH_ERASE_FAILED:
case ZEPHYRBASIC_MGMT_ERR_FLASH_CONFIG_QUERY_FAIL:
case ZEPHYRBASIC_MGMT_ERR_FLASH_ERASE_FAILED:
rc = MGMT_ERR_EOK;
break;

View file

@ -111,7 +111,7 @@ void mgmt_callback_unregister(struct mgmt_callback *callback)
}
enum mgmt_cb_return mgmt_callback_notify(uint32_t event, void *data, size_t data_size,
int32_t *ret_rc, uint16_t *ret_group)
int32_t *err_rc, uint16_t *err_group)
{
sys_snode_t *snp, *sns;
bool failed = false;
@ -119,8 +119,8 @@ enum mgmt_cb_return mgmt_callback_notify(uint32_t event, void *data, size_t data
uint16_t group = MGMT_EVT_GET_GROUP(event);
enum mgmt_cb_return return_status = MGMT_CB_OK;
*ret_rc = MGMT_ERR_EOK;
*ret_group = 0;
*err_rc = MGMT_ERR_EOK;
*err_group = 0;
/*
* Search through the linked list for entries that have registered for this event and
@ -139,24 +139,24 @@ enum mgmt_cb_return mgmt_callback_notify(uint32_t event, void *data, size_t data
(MGMT_EVT_GET_GROUP(loop_group->event_id) == group &&
(MGMT_EVT_GET_ID(event) & MGMT_EVT_GET_ID(loop_group->event_id)) ==
MGMT_EVT_GET_ID(event))) {
int32_t cached_rc = *ret_rc;
uint16_t cached_group = *ret_group;
int32_t cached_rc = *err_rc;
uint16_t cached_group = *err_group;
enum mgmt_cb_return status;
status = loop_group->callback(event, return_status, &cached_rc,
&cached_group, &abort_more, data,
data_size);
__ASSERT((status <= MGMT_CB_ERROR_RET),
__ASSERT((status <= MGMT_CB_ERROR_ERR),
"Invalid status returned by MCUmgr handler: %d", status);
if (status != MGMT_CB_OK && failed == false) {
failed = true;
return_status = status;
*ret_rc = cached_rc;
*err_rc = cached_rc;
if (status == MGMT_CB_ERROR_RET) {
*ret_group = cached_group;
if (status == MGMT_CB_ERROR_ERR) {
*err_group = cached_group;
}
}

View file

@ -31,11 +31,11 @@
* @brief Translate SMP version 2 error code to legacy SMP version 1 MCUmgr error code.
*
* @param group #mcumgr_group_t group ID
* @param ret Group-specific error code
* @param err Group-specific error code
*
* @return #mcumgr_err_t error code
*/
static int smp_translate_error_code(uint16_t group, uint16_t ret)
static int smp_translate_error_code(uint16_t group, uint16_t err)
{
smp_translate_error_fn translate_error_function = NULL;
@ -45,7 +45,7 @@ static int smp_translate_error_code(uint16_t group, uint16_t ret)
return MGMT_ERR_EUNKNOWN;
}
return translate_error_function(ret);
return translate_error_function(err);
}
#endif
@ -165,8 +165,8 @@ static int smp_handle_single_payload(struct smp_streamer *cbuf, const struct smp
#if defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
enum mgmt_cb_return status;
struct mgmt_evt_op_cmd_arg cmd_recv;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
handler = mgmt_find_handler(req_hdr->nh_group, req_hdr->nh_id);
@ -207,17 +207,17 @@ static int smp_handle_single_payload(struct smp_streamer *cbuf, const struct smp
/* Send request to application to check if handler should run or not. */
status = mgmt_callback_notify(MGMT_EVT_OP_CMD_RECV, &cmd_recv, sizeof(cmd_recv),
&ret_rc, &ret_group);
&err_rc, &err_group);
/* Skip running the command if a handler reported an error and return that
* instead.
*/
if (status != MGMT_CB_OK) {
if (status == MGMT_CB_ERROR_RC) {
rc = ret_rc;
rc = err_rc;
} else {
ok = smp_add_cmd_ret(cbuf->writer->zs, ret_group,
(uint16_t)ret_rc);
ok = smp_add_cmd_err(cbuf->writer->zs, err_group,
(uint16_t)err_rc);
rc = (ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE);
}
@ -374,8 +374,8 @@ int smp_process_request_packet(struct smp_streamer *streamer, void *vreq)
#if defined(CONFIG_MCUMGR_SMP_COMMAND_STATUS_HOOKS)
struct mgmt_evt_op_cmd_arg cmd_done_arg;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
rsp = NULL;
@ -446,7 +446,7 @@ int smp_process_request_packet(struct smp_streamer *streamer, void *vreq)
cmd_done_arg.err = MGMT_ERR_EOK;
(void)mgmt_callback_notify(MGMT_EVT_OP_CMD_DONE, &cmd_done_arg,
sizeof(cmd_done_arg), &ret_rc, &ret_group);
sizeof(cmd_done_arg), &err_rc, &err_group);
#endif
}
@ -460,7 +460,7 @@ int smp_process_request_packet(struct smp_streamer *streamer, void *vreq)
cmd_done_arg.err = rc;
(void)mgmt_callback_notify(MGMT_EVT_OP_CMD_DONE, &cmd_done_arg,
sizeof(cmd_done_arg), &ret_rc, &ret_group);
sizeof(cmd_done_arg), &err_rc, &err_group);
#endif
}
@ -473,7 +473,7 @@ int smp_process_request_packet(struct smp_streamer *streamer, void *vreq)
return rc;
}
bool smp_add_cmd_ret(zcbor_state_t *zse, uint16_t group, uint16_t ret)
bool smp_add_cmd_err(zcbor_state_t *zse, uint16_t group, uint16_t ret)
{
bool ok = true;
@ -485,7 +485,7 @@ bool smp_add_cmd_ret(zcbor_state_t *zse, uint16_t group, uint16_t ret)
container->error_ret = ret;
#endif
ok = zcbor_tstr_put_lit(zse, "ret") &&
ok = zcbor_tstr_put_lit(zse, "err") &&
zcbor_map_start_encode(zse, 2) &&
zcbor_tstr_put_lit(zse, "group") &&
zcbor_uint32_put(zse, (uint32_t)group) &&

View file

@ -24,18 +24,18 @@ extern "C" {
/**
* Command result codes for example management group.
*/
enum example_mgmt_ret_code_t {
enum example_mgmt_err_code_t {
/** No error, this is implied if there is no ret value in the response */
EXAMPLE_MGMT_RET_RC_OK = 0,
EXAMPLE_MGMT_ERR_OK = 0,
/** Unknown error occurred. */
EXAMPLE_MGMT_RET_RC_UNKNOWN,
EXAMPLE_MGMT_ERR_UNKNOWN,
/** The provided value is not wanted at this time. */
EXAMPLE_MGMT_RET_RC_NOT_WANTED,
EXAMPLE_MGMT_ERR_NOT_WANTED,
/** The provided value was rejected by a hook. */
EXAMPLE_MGMT_RET_RC_REJECTED_BY_HOOK,
EXAMPLE_MGMT_ERR_REJECTED_BY_HOOK,
};
#ifdef __cplusplus

View file

@ -56,7 +56,7 @@ static int example_mgmt_test(struct smp_streamer *ctxt)
/* If the value of "uint_key" is over 50, return an error of "not wanted" */
if (uint_value > 50) {
ok = smp_add_cmd_ret(zse, MGMT_GROUP_ID_EXAMPLE, EXAMPLE_MGMT_RET_RC_NOT_WANTED);
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_EXAMPLE, EXAMPLE_MGMT_ERR_NOT_WANTED);
goto end;
}
@ -86,8 +86,8 @@ static int example_mgmt_other(struct smp_streamer *ctxt)
#if defined(CONFIG_MCUMGR_GRP_EXAMPLE_OTHER_HOOK)
struct example_mgmt_other_data other_data;
enum mgmt_cb_return status;
int32_t ret_rc;
uint16_t ret_group;
int32_t err_rc;
uint16_t err_group;
#endif
LOG_DBG("Example other function called");
@ -106,17 +106,17 @@ static int example_mgmt_other(struct smp_streamer *ctxt)
/* Send request to application to check what to do */
other_data.user_value = user_value;
status = mgmt_callback_notify(MGMT_EVT_OP_EXAMPLE_OTHER, &other_data, sizeof(other_data),
&ret_rc, &ret_group);
&err_rc, &err_group);
if (status != MGMT_CB_OK) {
/* If a callback returned an RC error, exit out, if it returned a group error
* code, add the error code to the response and return to the calling function to
* have it sent back to the client
*/
if (status == MGMT_CB_ERROR_RC) {
return ret_rc;
return err_rc;
}
ok = smp_add_cmd_ret(zse, ret_group, (uint16_t)ret_rc);
ok = smp_add_cmd_err(zse, err_group, (uint16_t)err_rc);
goto end;
}
#endif
@ -140,20 +140,20 @@ end:
* only for general SMP/MCUmgr errors. The success/OK error code is not used in translation
* functions as it is automatically handled by the base SMP code.
*/
static int example_mgmt_translate_error_code(uint16_t ret)
static int example_mgmt_translate_error_code(uint16_t err)
{
int rc;
switch (ret) {
case EXAMPLE_MGMT_RET_RC_NOT_WANTED:
switch (err) {
case EXAMPLE_MGMT_ERR_NOT_WANTED:
rc = MGMT_ERR_ENOENT;
break;
case EXAMPLE_MGMT_RET_RC_REJECTED_BY_HOOK:
case EXAMPLE_MGMT_ERR_REJECTED_BY_HOOK:
rc = MGMT_ERR_EBADSTATE;
break;
case EXAMPLE_MGMT_RET_RC_UNKNOWN:
case EXAMPLE_MGMT_ERR_UNKNOWN:
default:
rc = MGMT_ERR_EUNKNOWN;
}

View file

@ -33,10 +33,10 @@ enum mgmt_cb_return test_function(uint32_t event, enum mgmt_cb_return prev_statu
if (last_run) {
/* Return a dummy error for a demo */
*group = MGMT_GROUP_ID_EXAMPLE;
*rc = EXAMPLE_MGMT_RET_RC_REJECTED_BY_HOOK;
*rc = EXAMPLE_MGMT_ERR_REJECTED_BY_HOOK;
LOG_INF("Received hook, rejecting!");
return MGMT_CB_ERROR_RET;
return MGMT_CB_ERROR_ERR;
}
LOG_INF("Received hook, allowing");

View file

@ -49,7 +49,7 @@ static const uint8_t response_old[] = {
/* Response to current packet */
static const uint8_t response_current[] = {
0x09, 0x00, 0x00, 0x13, 0x00, 0x00, 0x01, 0x07,
0xbf, 0x63, 0x72, 0x65, 0x74, 0xbf, 0x65, 0x67,
0xbf, 0x63, 0x65, 0x72, 0x72, 0xbf, 0x65, 0x67,
0x72, 0x6f, 0x75, 0x70, 0x00, 0x62, 0x72, 0x63,
0x02, 0xff, 0xff
};
@ -115,7 +115,7 @@ ZTEST(smp_version, test_legacy_command)
struct zcbor_map_decode_key_val output_decode[] = {
ZCBOR_MAP_DECODE_KEY_DECODER("output", zcbor_tstr_decode, &output),
ZCBOR_MAP_DECODE_KEY_DECODER("rc", zcbor_int32_decode, &rc),
ZCBOR_MAP_DECODE_KEY_DECODER("ret", mcumgr_ret_decode, &group_error),
ZCBOR_MAP_DECODE_KEY_DECODER("err", mcumgr_ret_decode, &group_error),
};
memset(buffer, 0, sizeof(buffer));
@ -173,7 +173,7 @@ ZTEST(smp_version, test_legacy_command)
zassert_equal(
zcbor_map_decode_bulk_key_found(output_decode, ARRAY_SIZE(output_decode),
"ret"), 0,
"err"), 0,
"Did not expect to get ret in response");
#ifdef CONFIG_MCUMGR_SMP_SUPPORT_ORIGINAL_PROTOCOL
@ -202,7 +202,7 @@ ZTEST(smp_version, test_current_command)
struct zcbor_map_decode_key_val output_decode[] = {
ZCBOR_MAP_DECODE_KEY_DECODER("output", zcbor_tstr_decode, &output),
ZCBOR_MAP_DECODE_KEY_DECODER("rc", zcbor_int32_decode, &rc),
ZCBOR_MAP_DECODE_KEY_DECODER("ret", mcumgr_ret_decode, &group_error),
ZCBOR_MAP_DECODE_KEY_DECODER("err", mcumgr_ret_decode, &group_error),
};
memset(buffer, 0, sizeof(buffer));
@ -260,14 +260,14 @@ ZTEST(smp_version, test_current_command)
zassert_equal(
zcbor_map_decode_bulk_key_found(output_decode, ARRAY_SIZE(output_decode),
"ret"), 1,
"err"), 1,
"Expected to get ret in response");
zassert_true(group_error.found, "Expected both group and rc in ret to be found");
zassert_equal(group_error.group, MGMT_GROUP_ID_OS,
"Expected to get MGMT_GROUP_ID_OS for ret group");
zassert_equal(group_error.rc, OS_MGMT_RET_RC_INVALID_FORMAT,
"Expected to get OS_MGMT_RET_RC_INVALID_FORMAT for ret rc");
zassert_equal(group_error.rc, OS_MGMT_ERR_INVALID_FORMAT,
"Expected to get OS_MGMT_ERR_INVALID_FORMAT for ret rc");
}
ZTEST(smp_version, test_new_command)
@ -288,7 +288,7 @@ ZTEST(smp_version, test_new_command)
struct zcbor_map_decode_key_val output_decode[] = {
ZCBOR_MAP_DECODE_KEY_DECODER("output", zcbor_tstr_decode, &output),
ZCBOR_MAP_DECODE_KEY_DECODER("rc", zcbor_int32_decode, &rc),
ZCBOR_MAP_DECODE_KEY_DECODER("ret", mcumgr_ret_decode, &group_error),
ZCBOR_MAP_DECODE_KEY_DECODER("err", mcumgr_ret_decode, &group_error),
};
memset(buffer, 0, sizeof(buffer));
@ -346,7 +346,7 @@ ZTEST(smp_version, test_new_command)
zassert_equal(
zcbor_map_decode_bulk_key_found(output_decode, ARRAY_SIZE(output_decode),
"ret"), 0,
"err"), 0,
"Did not expect to get ret in response");
zassert_equal(rc, MGMT_ERR_UNSUPPORTED_TOO_NEW,