mgmt: mcumgr: Make returning rc responses when status is OK legacy
This change changes the previous mcumgr behaviour of return result codes when the status is 0 (OK) to being legacy behaviour, instead it will skip the rc field for these responses. If there is only an rc field with status 0 to return, then mcumgr will now instead just return an empty map. Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
4b43f405b7
commit
b4c2b57f1b
4 changed files with 82 additions and 59 deletions
|
@ -118,6 +118,18 @@ config MCUMGR_SMP_COMMAND_STATUS_HOOKS
|
|||
This will enable SMP command status notification hooks for when an SMP message is
|
||||
received or processed.
|
||||
|
||||
config MCUMGR_SMP_LEGACY_RC_BEHAVIOUR
|
||||
bool "Legacy rc (result code) response behaviour"
|
||||
help
|
||||
This will enable legacy result code response behaviour of having rc
|
||||
present in responses when the status is 0. With this option disabled,
|
||||
mcumgr acts with new behaviour and will only return rc is the result
|
||||
code is non-zero (i.e. an error occurred).
|
||||
|
||||
If a command only returns a result code, this will mean that the
|
||||
response will be empty with the new behaviour enabled, as opposed to
|
||||
the old behaviour where the rc field will be present in the response.
|
||||
|
||||
menu "Command Handlers"
|
||||
|
||||
rsource "grp/Kconfig"
|
||||
|
|
|
@ -112,14 +112,15 @@ static int fs_mgmt_filelen(const char *path, size_t *out_len)
|
|||
*/
|
||||
static bool fs_mgmt_file_rsp(zcbor_state_t *zse, int rc, uint64_t off)
|
||||
{
|
||||
bool ok;
|
||||
bool ok = true;
|
||||
|
||||
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR) || rc != 0) {
|
||||
ok = zcbor_tstr_put_lit(zse, "rc") &&
|
||||
zcbor_int32_put(zse, rc) &&
|
||||
zcbor_tstr_put_lit(zse, "off") &&
|
||||
zcbor_uint64_put(zse, off);
|
||||
zcbor_int32_put(zse, rc);
|
||||
}
|
||||
|
||||
return ok;
|
||||
return ok && zcbor_tstr_put_lit(zse, "off") &&
|
||||
zcbor_uint64_put(zse, off);
|
||||
}
|
||||
|
||||
static int fs_mgmt_read(const char *path, size_t offset, size_t len,
|
||||
|
@ -425,17 +426,19 @@ static int fs_mgmt_file_status(struct smp_streamer *ctxt)
|
|||
/* Retrieve file size */
|
||||
rc = fs_mgmt_filelen(path, &file_len);
|
||||
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Encode the response. */
|
||||
if (rc == 0) {
|
||||
/* No error, only encode file status (length) */
|
||||
ok = zcbor_tstr_put_lit(zse, "len") &&
|
||||
zcbor_uint64_put(zse, file_len);
|
||||
} else {
|
||||
/* Error, only encode error result code */
|
||||
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
|
||||
ok = zcbor_tstr_put_lit(zse, "rc") &&
|
||||
zcbor_int32_put(zse, rc);
|
||||
}
|
||||
|
||||
ok = ok && zcbor_tstr_put_lit(zse, "len") &&
|
||||
zcbor_uint64_put(zse, file_len);
|
||||
|
||||
if (!ok) {
|
||||
return MGMT_ERR_EMSGSIZE;
|
||||
}
|
||||
|
@ -535,10 +538,10 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
|
|||
|
||||
/* Encode the response */
|
||||
if (rc != 0) {
|
||||
ok = zcbor_tstr_put_lit(zse, "rc") &&
|
||||
zcbor_int32_put(zse, rc);
|
||||
} else {
|
||||
ok = zcbor_tstr_put_lit(zse, "type") &&
|
||||
return rc;
|
||||
}
|
||||
|
||||
ok &= zcbor_tstr_put_lit(zse, "type") &&
|
||||
zcbor_tstr_put_term(zse, type_arr);
|
||||
|
||||
if (off != 0) {
|
||||
|
@ -580,7 +583,6 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
|
|||
|
||||
ok &= zcbor_uint64_put(zse, tmp_val);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
return MGMT_ERR_EMSGSIZE;
|
||||
|
|
|
@ -303,7 +303,8 @@ img_mgmt_erase(struct smp_streamer *ctxt)
|
|||
return rc;
|
||||
}
|
||||
|
||||
if (zcbor_tstr_put_lit(zse, "rc") && zcbor_int32_put(zse, 0)) {
|
||||
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR) && zcbor_tstr_put_lit(zse, "rc") &&
|
||||
zcbor_int32_put(zse, 0)) {
|
||||
return MGMT_ERR_EOK;
|
||||
}
|
||||
|
||||
|
@ -314,11 +315,14 @@ static int
|
|||
img_mgmt_upload_good_rsp(struct smp_streamer *ctxt)
|
||||
{
|
||||
zcbor_state_t *zse = ctxt->writer->zs;
|
||||
bool ok;
|
||||
bool ok = true;
|
||||
|
||||
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
|
||||
ok = zcbor_tstr_put_lit(zse, "rc") &&
|
||||
zcbor_int32_put(zse, MGMT_ERR_EOK) &&
|
||||
zcbor_tstr_put_lit(zse, "off") &&
|
||||
zcbor_int32_put(zse, MGMT_ERR_EOK);
|
||||
}
|
||||
|
||||
ok = ok && zcbor_tstr_put_lit(zse, "off") &&
|
||||
zcbor_size_put(zse, g_img_mgmt_state.off);
|
||||
|
||||
return ok ? MGMT_ERR_EOK : MGMT_ERR_EMSGSIZE;
|
||||
|
|
|
@ -155,12 +155,17 @@ stat_mgmt_show(struct smp_streamer *ctxt)
|
|||
return MGMT_ERR_EUNKNOWN;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
|
||||
ok = zcbor_tstr_put_lit(zse, "rc") &&
|
||||
zcbor_int32_put(zse, MGMT_ERR_EOK) &&
|
||||
zcbor_tstr_put_lit(zse, "name") &&
|
||||
zcbor_int32_put(zse, MGMT_ERR_EOK);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ok = zcbor_tstr_put_lit(zse, "name") &&
|
||||
zcbor_tstr_encode(zse, &value) &&
|
||||
zcbor_tstr_put_lit(zse, "fields") &&
|
||||
zcbor_map_start_encode(zse, counter);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
int rc = stat_mgmt_foreach_entry(zse, stat_name,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue