Skip to content

Commit 770482a

Browse files
nordicjmnashif
authored andcommitted
mgmt: mcumgr: grp: os_mgmt: Fix issues raised in comments
Fixes an issue with structure which was previously raised in a comment, and adds a new bool to the structure to enable this restructure to work Signed-off-by: Jamie McCrae <[email protected]>
1 parent ec2c5b0 commit 770482a

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

include/zephyr/mgmt/mcumgr/grp/os_mgmt/os_mgmt_callbacks.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ struct os_mgmt_bootloader_info_data {
4444

4545
/** Contains the value of the query parameter. */
4646
struct zcbor_string *query;
47+
48+
/**
49+
* Must be set to true to indicate a response has been added, otherwise will return the
50+
* #OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER error.
51+
*/
52+
bool *has_output;
4753
};
4854

4955
/**

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2018-2021 mcumgr authors
3-
* Copyright (c) 2021-2023 Nordic Semiconductor ASA
3+
* Copyright (c) 2021-2024 Nordic Semiconductor ASA
44
* Copyright (c) 2022 Laird Connectivity
55
*
66
* SPDX-License-Identifier: Apache-2.0
@@ -451,6 +451,7 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
451451
struct zcbor_string query = { 0 };
452452
size_t decoded;
453453
bool ok;
454+
bool has_output = false;
454455

455456
#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK)
456457
enum mgmt_cb_return status;
@@ -459,7 +460,8 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
459460
struct os_mgmt_bootloader_info_data bootloader_info_data = {
460461
.zse = zse,
461462
.decoded = &decoded,
462-
.query = &query
463+
.query = &query,
464+
.has_output = &has_output
463465
};
464466
#endif
465467

@@ -487,24 +489,29 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
487489
#endif
488490

489491
/* If no parameter is recognized then just introduce the bootloader. */
492+
if (!has_output) {
490493
#if defined(CONFIG_BOOTLOADER_MCUBOOT)
491-
if (decoded == 0) {
492-
ok = zcbor_tstr_put_lit(zse, "bootloader") &&
493-
zcbor_tstr_put_lit(zse, "MCUboot");
494-
} else if (zcbor_map_decode_bulk_key_found(bootloader_info, ARRAY_SIZE(bootloader_info),
495-
"query") &&
496-
(sizeof("mode") - 1) == query.len &&
497-
memcmp("mode", query.value, query.len) == 0) {
498-
499-
ok = zcbor_tstr_put_lit(zse, "mode") &&
500-
zcbor_int32_put(zse, BOOTLOADER_MODE);
494+
if (decoded == 0) {
495+
ok = zcbor_tstr_put_lit(zse, "bootloader") &&
496+
zcbor_tstr_put_lit(zse, "MCUboot");
497+
has_output = true;
498+
} else if (zcbor_map_decode_bulk_key_found(bootloader_info,
499+
ARRAY_SIZE(bootloader_info),
500+
"query") && (sizeof("mode") - 1) == query.len &&
501+
memcmp("mode", query.value, query.len) == 0) {
502+
503+
ok = zcbor_tstr_put_lit(zse, "mode") &&
504+
zcbor_int32_put(zse, BOOTLOADER_MODE);
501505
#ifdef CONFIG_MCUBOOT_BOOTLOADER_NO_DOWNGRADE
502-
ok = ok && zcbor_tstr_put_lit(zse, "no-downgrade") &&
503-
zcbor_bool_encode(zse, &(bool){true});
506+
ok = ok && zcbor_tstr_put_lit(zse, "no-downgrade") &&
507+
zcbor_bool_encode(zse, &(bool){true});
504508
#endif
505-
} else
509+
has_output = true;
510+
}
506511
#endif
507-
{
512+
}
513+
514+
if (!has_output) {
508515
ok = smp_add_cmd_err(zse, MGMT_GROUP_ID_OS, OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER);
509516
}
510517

0 commit comments

Comments
 (0)