-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Mcumgr handlers for group enumeration #70704
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Copyright (c) 2018-2021 mcumgr authors | ||
# Copyright (c) 2024 Extreme Engineering Solutions | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# Enumeration management group public API is exported by MCUmgr interface API, | ||
# when Enumeration Management is enabled. | ||
zephyr_library(mgmt_mcumgr_grp_enum) | ||
zephyr_library_sources(src/enum_mgmt.c) | ||
|
||
zephyr_library_include_directories(include) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright (c) 2024 Extreme Engineering Solutions, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
config MCUMGR_GRP_ENUM | ||
bool "MCUmgr handlers for enumeration management" | ||
help | ||
Enables MCUmgr handlers for enumeration management. This includes | ||
a single command which returns a list of all registered groups. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (c) - 2024 Extreme Engineering Solutions | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/sys/util.h> | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/sys/slist.h> | ||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h> | ||
#include <zephyr/mgmt/mcumgr/smp/smp.h> | ||
#include <zephyr/mgmt/mcumgr/mgmt/handlers.h> | ||
#include <zephyr/logging/log.h> | ||
#include <assert.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include <zcbor_common.h> | ||
#include <zcbor_encode.h> | ||
#include <zcbor_decode.h> | ||
|
||
#include <mgmt/mcumgr/util/zcbor_bulk.h> | ||
|
||
#define ENUMERATION_MGMT_LIST 0 | ||
#define ENUMERATION_MGMT_GP_ID 10 | ||
|
||
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .h file |
||
static bool encode_id(sys_snode_t *group_node, zcbor_state_t *zse) { | ||
Check failure on line 27 in subsys/mgmt/mcumgr/grp/enum_mgmt/src/enum_mgmt.c GitHub Actions / Run compliance checks on patch series (PR)OPEN_BRACE
|
||
struct mgmt_group *group = CONTAINER_OF(group_node, struct mgmt_group, node); | ||
return zcbor_uint32_put(group->mg_group_id); | ||
} | ||
|
||
static int enumeration_mgmt_list(struct smp_streamer *ctxt) | ||
{ | ||
zcbor_state_t *zse = ctxt->writer->zs; | ||
sys_slist_t *groups; | ||
sys_snode_t *snp, *sns; | ||
int count; | ||
|
||
groups = mgmt_get_group_list(); | ||
count = sys_slist_len(groups); | ||
|
||
ok = zcbor_tstr_put_lit(zse, "groups") && | ||
zcbor_list_start_encode(zse, count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. count needs to be more e.g. if canonical mode is enabled |
||
|
||
SYS_SLIST_FOR_EACH_NODE_SAFE(&groups, snp, sns) { | ||
ok = encode_id(sns, zse); | ||
if (!ok) { | ||
return MGMT_ERR_EBADSTATE; | ||
} | ||
} | ||
|
||
ok = zcbor_list_end_encode(zse, count); | ||
|
||
return ok ? MGMT_ERR_EOK : MGMT_ERR_ECORRUPT; | ||
} | ||
|
||
static const struct mgmt_handler enumeration_mgmt_group_handlers[] = { | ||
[ENUMERATION_MGMT_LIST] = {enumeration_mgmt_list, NULL}, | ||
}; | ||
|
||
static struct mgmt_group enumeration_mgmt_group = { | ||
.mg_handlers = enumeration_mgmt_group_handlers, | ||
.mg_handlers_count = ARRAY_SIZE(enumeration_mgmt_group_handlers), | ||
.mg_group_id = ENUMERATION_MGMT_GP_ID, | ||
}; | ||
|
||
static void enumeration_mgmt_register_group(void) | ||
{ | ||
mgmt_register_group(&enumeration_mgmt_group); | ||
} | ||
|
||
MCUMGR_HANDLER_DEFINE(enumerationg_mgmt, enumeration_mgmt_register_group); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* | ||
* Copyright (c) 2018-2021 mcumgr authors | ||
* Copyright (c) 2022-2023 Nordic Semiconductor ASA | ||
* Copyright (c) 2024 Extreme Engineering Solutions | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
@@ -29,7 +30,7 @@ | |
void | ||
mgmt_unregister_group(struct mgmt_group *group) | ||
{ | ||
(void)sys_slist_find_and_remove(&mgmt_group_list, &group->node); | ||
sys_slist_find_and_remove(&mgmt_group_list, &group->node); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? |
||
} | ||
|
||
const struct mgmt_handler * | ||
|
@@ -133,6 +134,11 @@ | |
sys_slist_append(&mgmt_group_list, &group->node); | ||
} | ||
|
||
sys_slist_t *mgmt_get_group_list() | ||
Check failure on line 137 in subsys/mgmt/mcumgr/mgmt/src/mgmt.c GitHub Actions / Run compliance checks on patch series (PR)FUNCTION_WITHOUT_ARGS
|
||
{ | ||
return &mgmt_group_list; | ||
} | ||
|
||
#if defined(CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS) | ||
void mgmt_callback_register(struct mgmt_callback *callback) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a function that calls a callback multiple times, once per group, and returns the group object, it should not be just returning a list directly or using sys_slist_t when the type should be the mgmt_group type (should also be const in the callback)