Skip to content

Commit b46e176

Browse files
nandojvemmahadevan108
authored andcommitted
mgmt: mcumgr: stat: Fix stat_mgmt_list behavior
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 <[email protected]>
1 parent 2fd8cc8 commit b46e176

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

subsys/mgmt/mcumgr/grp/stat_mgmt/src/stat_mgmt.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ stat_mgmt_list(struct smp_streamer *ctxt)
190190
{
191191
const struct stats_hdr *cur = NULL;
192192
zcbor_state_t *zse = ctxt->writer->zs;
193-
bool ok;
193+
bool ok = true;
194194
size_t counter = 0;
195195

196196
do {
@@ -200,10 +200,15 @@ stat_mgmt_list(struct smp_streamer *ctxt)
200200
}
201201
} while (cur != NULL);
202202

203-
ok = zcbor_tstr_put_lit(zse, "rc") &&
204-
zcbor_int32_put(zse, MGMT_ERR_EOK) &&
205-
zcbor_tstr_put_lit(zse, "stat_list") &&
206-
zcbor_list_start_encode(zse, counter);
203+
if (IS_ENABLED(CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR)) {
204+
ok = zcbor_tstr_put_lit(zse, "rc") &&
205+
zcbor_int32_put(zse, MGMT_ERR_EOK);
206+
}
207+
208+
if (ok) {
209+
ok = zcbor_tstr_put_lit(zse, "stat_list") &&
210+
zcbor_list_start_encode(zse, counter);
211+
}
207212

208213
if (!ok) {
209214
return MGMT_ERR_EMSGSIZE;
@@ -224,7 +229,7 @@ stat_mgmt_list(struct smp_streamer *ctxt)
224229
return MGMT_ERR_EMSGSIZE;
225230
}
226231

227-
return 0;
232+
return MGMT_ERR_EOK;
228233
}
229234

230235
#ifdef CONFIG_MCUMGR_SMP_SUPPORT_ORIGINAL_PROTOCOL

0 commit comments

Comments
 (0)