Skip to content

Commit

Permalink
mgmt: mcumgr: stat: Fix stat_mgmt_list behavior
Browse files Browse the repository at this point in the history
The MCUmgr statistics only work correctly when selecting
MCUMGR_SMP_LEGACY_RC_BEHAVIOUR option. Checks the option
flag on the stat_mgmt_list and fix the behavior.

Fixes: 80476

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
  • Loading branch information
nandojve committed Oct 27, 2024
1 parent 4b4bba4 commit 361f396
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ stat_mgmt_list(struct smp_streamer *ctxt)
{
const struct stats_hdr *cur = NULL;
zcbor_state_t *zse = ctxt->writer->zs;
bool ok;
bool ok = true;
size_t counter = 0;

do {
Expand All @@ -200,10 +200,15 @@ stat_mgmt_list(struct smp_streamer *ctxt)
}
} while (cur != NULL);

ok = zcbor_tstr_put_lit(zse, "rc") &&
zcbor_int32_put(zse, MGMT_ERR_EOK) &&
zcbor_tstr_put_lit(zse, "stat_list") &&
zcbor_list_start_encode(zse, counter);
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
ok = zcbor_tstr_put_lit(zse, "rc") &&
zcbor_int32_put(zse, MGMT_ERR_EOK);
}

if (ok) {
ok = zcbor_tstr_put_lit(zse, "stat_list") &&
zcbor_list_start_encode(zse, counter);
}

Check notice on line 211 in subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c:211 - ok = zcbor_tstr_put_lit(zse, "rc") && - zcbor_int32_put(zse, MGMT_ERR_EOK); + ok = zcbor_tstr_put_lit(zse, "rc") && zcbor_int32_put(zse, MGMT_ERR_EOK); } if (ok) { - ok = zcbor_tstr_put_lit(zse, "stat_list") && - zcbor_list_start_encode(zse, counter); + ok = zcbor_tstr_put_lit(zse, "stat_list") && zcbor_list_start_encode(zse, counter);

Check notice on line 211 in subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c:211 - ok = zcbor_tstr_put_lit(zse, "rc") && - zcbor_int32_put(zse, MGMT_ERR_EOK); + ok = zcbor_tstr_put_lit(zse, "rc") && zcbor_int32_put(zse, MGMT_ERR_EOK); } if (ok) { - ok = zcbor_tstr_put_lit(zse, "stat_list") && - zcbor_list_start_encode(zse, counter); + ok = zcbor_tstr_put_lit(zse, "stat_list") && zcbor_list_start_encode(zse, counter);

Check notice on line 211 in subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c:211 - ok = zcbor_tstr_put_lit(zse, "rc") && - zcbor_int32_put(zse, MGMT_ERR_EOK); + ok = zcbor_tstr_put_lit(zse, "rc") && zcbor_int32_put(zse, MGMT_ERR_EOK); } if (ok) { - ok = zcbor_tstr_put_lit(zse, "stat_list") && - zcbor_list_start_encode(zse, counter); + ok = zcbor_tstr_put_lit(zse, "stat_list") && zcbor_list_start_encode(zse, counter);

if (!ok) {
return MGMT_ERR_EMSGSIZE;
Expand All @@ -224,7 +229,7 @@ stat_mgmt_list(struct smp_streamer *ctxt)
return MGMT_ERR_EMSGSIZE;
}

return 0;
return MGMT_ERR_EOK;
}

#ifdef CONFIG_MCUMGR_SMP_SUPPORT_ORIGINAL_PROTOCOL
Expand Down

0 comments on commit 361f396

Please sign in to comment.