Skip to content

Commit cbd0d2d

Browse files
nordicjmstephanosio
authored andcommitted
mgmt: mcumgr: Add fs_mgmt prefix to hash/checksum functions/files
This aligns the naming of files in fs_mgmt so that files and functions relating to hash/checksum are prefixed with fs_mgmt. Signed-off-by: Jamie McCrae <[email protected]>
1 parent 4c70bf6 commit cbd0d2d

File tree

9 files changed

+107
-106
lines changed

9 files changed

+107
-106
lines changed

include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h renamed to include/zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
extern "C" {
1717
#endif
1818

19-
/** @typedef hash_checksum_mgmt_handler_fn
19+
/** @typedef fs_mgmt_hash_checksum_handler_fn
2020
* @brief Function that gets called to generate a hash or checksum.
2121
*
2222
* @param file Opened file context
@@ -26,14 +26,13 @@ extern "C" {
2626
*
2727
* @return 0 on success, negative error code on failure.
2828
*/
29-
typedef int (*hash_checksum_mgmt_handler_fn)(struct fs_file_t *file,
30-
uint8_t *output, size_t *out_len,
31-
size_t len);
29+
typedef int (*fs_mgmt_hash_checksum_handler_fn)(struct fs_file_t *file, uint8_t *output,
30+
size_t *out_len, size_t len);
3231

3332
/**
3433
* @brief A collection of handlers for an entire hash/checksum group.
3534
*/
36-
struct hash_checksum_mgmt_group {
35+
struct fs_mgmt_hash_checksum_group {
3736
/** Entry list node. */
3837
sys_snode_t node;
3938

@@ -47,31 +46,31 @@ struct hash_checksum_mgmt_group {
4746
uint8_t output_size;
4847

4948
/** Hash/checksum function pointer. */
50-
hash_checksum_mgmt_handler_fn function;
49+
fs_mgmt_hash_checksum_handler_fn function;
5150
};
5251

53-
/** @typedef hash_checksum_mgmt_list_cb
52+
/** @typedef fs_mgmt_hash_checksum_list_cb
5453
* @brief Function that gets called with hash/checksum details
5554
*
5655
* @param group Details about a supported hash/checksum
5756
* @param user_data User-supplied value to calling function
5857
*/
59-
typedef void (*hash_checksum_mgmt_list_cb)(const struct hash_checksum_mgmt_group *group,
60-
void *user_data);
58+
typedef void (*fs_mgmt_hash_checksum_list_cb)(const struct fs_mgmt_hash_checksum_group *group,
59+
void *user_data);
6160

6261
/**
6362
* @brief Registers a full hash/checksum group.
6463
*
6564
* @param group The group to register.
6665
*/
67-
void hash_checksum_mgmt_register_group(struct hash_checksum_mgmt_group *group);
66+
void fs_mgmt_hash_checksum_register_group(struct fs_mgmt_hash_checksum_group *group);
6867

6968
/**
7069
* @brief Unregisters a full hash/checksum group.
7170
*
7271
* @param group The group to register.
7372
*/
74-
void hash_checksum_mgmt_unregister_group(struct hash_checksum_mgmt_group *group);
73+
void fs_mgmt_hash_checksum_unregister_group(struct fs_mgmt_hash_checksum_group *group);
7574

7675
/**
7776
* @brief Finds a registered hash/checksum handler.
@@ -81,15 +80,15 @@ void hash_checksum_mgmt_unregister_group(struct hash_checksum_mgmt_group *group)
8180
* @return The requested hash/checksum handler on success;
8281
* NULL on failure.
8382
*/
84-
const struct hash_checksum_mgmt_group *hash_checksum_mgmt_find_handler(const char *name);
83+
const struct fs_mgmt_hash_checksum_group *fs_mgmt_hash_checksum_find_handler(const char *name);
8584

8685
/**
8786
* @brief Runs a callback with all supported hash/checksum types.
8887
*
8988
* @param cb The callback function to call with each hash/checksum type.
9089
* @param user_data Data to pass back with the callback function.
9190
*/
92-
void hash_checksum_mgmt_find_handlers(hash_checksum_mgmt_list_cb cb, void *user_data);
91+
void fs_mgmt_hash_checksum_find_handlers(fs_mgmt_hash_checksum_list_cb cb, void *user_data);
9392

9493
#ifdef __cplusplus
9594
}

subsys/mgmt/mcumgr/grp/fs_mgmt/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
add_library(mgmt_mcumgr_grp_fs src/fs_mgmt.c)
1212

1313
target_sources_ifdef(CONFIG_FS_MGMT_CHECKSUM_HASH
14-
mgmt_mcumgr_grp_fs PRIVATE src/hash_checksum_mgmt.c
14+
mgmt_mcumgr_grp_fs PRIVATE src/fs_mgmt_hash_checksum.c
1515
)
1616
target_sources_ifdef(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32
17-
mgmt_mcumgr_grp_fs PRIVATE src/hash_checksum_crc32.c
17+
mgmt_mcumgr_grp_fs PRIVATE src/fs_mgmt_hash_checksum_crc32.c
1818
)
1919
target_sources_ifdef(CONFIG_FS_MGMT_HASH_SHA256
20-
mgmt_mcumgr_grp_fs PRIVATE src/hash_checksum_sha256.c)
20+
mgmt_mcumgr_grp_fs PRIVATE src/fs_mgmt_hash_checksum_sha256.c)
2121

2222
if (CONFIG_FS_MGMT_CHECKSUM_HASH AND CONFIG_FS_MGMT_HASH_SHA256)
2323
if (NOT CONFIG_TINYCRYPT)

subsys/mgmt/mcumgr/grp/fs_mgmt/include/mgmt/mcumgr/grp/fs_mgmt/hash_checksum_crc32.h renamed to subsys/mgmt/mcumgr/grp/fs_mgmt/include/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_crc32.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ extern "C" {
1616
/**
1717
* @brief Registers the IEEE CRC32 checksum mcumgr handler.
1818
*/
19-
void fs_hash_checksum_mgmt_register_crc32(void);
19+
void fs_mgmt_hash_checksum_register_crc32(void);
2020

2121
/**
2222
* @brief Un-registers the IEEE CRC32 checksum mcumgr handler.
2323
*/
24-
void fs_hash_checksum_mgmt_unregister_crc32(void);
24+
void fs_mgmt_hash_checksum_unregister_crc32(void);
2525

2626
#ifdef __cplusplus
2727
}

subsys/mgmt/mcumgr/grp/fs_mgmt/include/mgmt/mcumgr/grp/fs_mgmt/hash_checksum_sha256.h renamed to subsys/mgmt/mcumgr/grp/fs_mgmt/include/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_sha256.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ extern "C" {
1616
/**
1717
* @brief Registers the SHA256 hash mcumgr handler.
1818
*/
19-
void fs_hash_checksum_mgmt_register_sha256(void);
19+
void fs_mgmt_hash_checksum_register_sha256(void);
2020

2121
/**
2222
* @brief Un-registers the SHA256 hash mcumgr handler.
2323
*/
24-
void fs_hash_checksum_mgmt_unregister_sha256(void);
24+
void fs_mgmt_hash_checksum_unregister_sha256(void);
2525

2626
#ifdef __cplusplus
2727
}

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
1313
#include <zephyr/mgmt/mcumgr/smp/smp.h>
1414
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h>
15-
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
15+
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
1616
#include <assert.h>
1717
#include <limits.h>
1818
#include <string.h>
@@ -25,11 +25,11 @@
2525
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
2626

2727
#if defined(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32)
28-
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_crc32.h>
28+
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_crc32.h>
2929
#endif
3030

3131
#if defined(CONFIG_FS_MGMT_HASH_SHA256)
32-
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_sha256.h>
32+
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_sha256.h>
3333
#endif
3434

3535
#if defined(CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS)
@@ -77,7 +77,7 @@ static const struct mgmt_handler fs_mgmt_handlers[];
7777

7878
#if defined(CONFIG_FS_MGMT_CHECKSUM_HASH)
7979
/* Hash/checksum iterator information passing structure */
80-
struct hash_checksum_iterator_info {
80+
struct fs_mgmt_hash_checksum_iterator_info {
8181
zcbor_state_t *zse;
8282
bool ok;
8383
};
@@ -464,7 +464,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
464464
struct zcbor_string name = { 0 };
465465
size_t decoded;
466466
struct fs_file_t file;
467-
const struct hash_checksum_mgmt_group *group = NULL;
467+
const struct fs_mgmt_hash_checksum_group *group = NULL;
468468

469469
struct zcbor_map_decode_key_val fs_hash_checksum_decode[] = {
470470
ZCBOR_MAP_DECODE_KEY_VAL(type, zcbor_tstr_decode, &type),
@@ -491,7 +491,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
491491
}
492492

493493
/* Search for supported hash/checksum */
494-
group = hash_checksum_mgmt_find_handler(type_arr);
494+
group = fs_mgmt_hash_checksum_find_handler(type_arr);
495495

496496
if (group == NULL) {
497497
return MGMT_ERR_EINVAL;
@@ -591,10 +591,12 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
591591

592592
#if defined(CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_CMD)
593593
/* Callback for supported hash/checksum types to encode details on one type into CBOR map */
594-
static void supported_hash_checksum_callback(const struct hash_checksum_mgmt_group *group,
595-
void *user_data)
594+
static void fs_mgmt_supported_hash_checksum_callback(
595+
const struct fs_mgmt_hash_checksum_group *group,
596+
void *user_data)
596597
{
597-
struct hash_checksum_iterator_info *ctx = (struct hash_checksum_iterator_info *)user_data;
598+
struct fs_mgmt_hash_checksum_iterator_info *ctx =
599+
(struct fs_mgmt_hash_checksum_iterator_info *)user_data;
598600

599601
if (!ctx->ok) {
600602
return;
@@ -616,15 +618,15 @@ static int
616618
fs_mgmt_supported_hash_checksum(struct smp_streamer *ctxt)
617619
{
618620
zcbor_state_t *zse = ctxt->writer->zs;
619-
struct hash_checksum_iterator_info itr_ctx = {
621+
struct fs_mgmt_hash_checksum_iterator_info itr_ctx = {
620622
.zse = zse,
621623
};
622624

623625
itr_ctx.ok = zcbor_tstr_put_lit(zse, "types");
624626

625627
zcbor_map_start_encode(zse, CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES);
626628

627-
hash_checksum_mgmt_find_handlers(supported_hash_checksum_callback, &itr_ctx);
629+
fs_mgmt_hash_checksum_find_handlers(fs_mgmt_supported_hash_checksum_callback, &itr_ctx);
628630

629631
if (!itr_ctx.ok ||
630632
!zcbor_map_end_encode(zse, CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES)) {
@@ -676,11 +678,11 @@ void fs_mgmt_register_group(void)
676678
#if defined(CONFIG_FS_MGMT_CHECKSUM_HASH)
677679
/* Register any supported hash or checksum functions */
678680
#if defined(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32)
679-
fs_hash_checksum_mgmt_register_crc32();
681+
fs_mgmt_hash_checksum_register_crc32();
680682
#endif
681683

682684
#if defined(CONFIG_FS_MGMT_HASH_SHA256)
683-
fs_hash_checksum_mgmt_register_sha256();
685+
fs_mgmt_hash_checksum_register_sha256();
684686
#endif
685687
#endif
686688
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2022 Laird Connectivity
3+
* Copyright (c) 2022 Nordic Semiconductor ASA
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#include <zephyr/kernel.h>
9+
#include <string.h>
10+
11+
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
12+
13+
static sys_slist_t fs_mgmt_hash_checksum_group_list =
14+
SYS_SLIST_STATIC_INIT(&fs_mgmt_hash_checksum_group_list);
15+
16+
void fs_mgmt_hash_checksum_unregister_group(struct fs_mgmt_hash_checksum_group *group)
17+
{
18+
(void)sys_slist_find_and_remove(&fs_mgmt_hash_checksum_group_list, &group->node);
19+
}
20+
21+
void fs_mgmt_hash_checksum_register_group(struct fs_mgmt_hash_checksum_group *group)
22+
{
23+
sys_slist_append(&fs_mgmt_hash_checksum_group_list, &group->node);
24+
}
25+
26+
const struct fs_mgmt_hash_checksum_group *fs_mgmt_hash_checksum_find_handler(const char *name)
27+
{
28+
/* Find the group with the specified group name */
29+
struct fs_mgmt_hash_checksum_group *group = NULL;
30+
sys_snode_t *snp, *sns;
31+
32+
SYS_SLIST_FOR_EACH_NODE_SAFE(&fs_mgmt_hash_checksum_group_list, snp, sns) {
33+
struct fs_mgmt_hash_checksum_group *loop_group =
34+
CONTAINER_OF(snp, struct fs_mgmt_hash_checksum_group, node);
35+
if (strcmp(loop_group->group_name, name) == 0) {
36+
group = loop_group;
37+
break;
38+
}
39+
}
40+
41+
return group;
42+
}
43+
44+
void fs_mgmt_hash_checksum_find_handlers(fs_mgmt_hash_checksum_list_cb cb, void *user_data)
45+
{
46+
/* Run a callback with all supported hash/checksums */
47+
sys_snode_t *snp, *sns;
48+
49+
SYS_SLIST_FOR_EACH_NODE_SAFE(&fs_mgmt_hash_checksum_group_list, snp, sns) {
50+
struct fs_mgmt_hash_checksum_group *group =
51+
CONTAINER_OF(snp, struct fs_mgmt_hash_checksum_group, node);
52+
cb(group, user_data);
53+
}
54+
}

subsys/mgmt/mcumgr/grp/fs_mgmt/src/hash_checksum_crc32.c renamed to subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt_hash_checksum_crc32.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#include <zephyr/sys/crc.h>
99
#include <zephyr/fs/fs.h>
1010
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
11-
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
11+
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
1212
#include <string.h>
1313

1414
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
15-
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_crc32.h>
15+
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_crc32.h>
1616

1717
#define CRC32_SIZE 4
1818

19-
static int fs_hash_checksum_mgmt_crc32(struct fs_file_t *file, uint8_t *output,
19+
static int fs_mgmt_hash_checksum_crc32(struct fs_file_t *file, uint8_t *output,
2020
size_t *out_len, size_t len)
2121
{
2222
/* Calculate IEEE CRC32 checksum of target file */
@@ -50,19 +50,19 @@ static int fs_hash_checksum_mgmt_crc32(struct fs_file_t *file, uint8_t *output,
5050
return 0;
5151
}
5252

53-
struct hash_checksum_mgmt_group crc32 = {
53+
static struct fs_mgmt_hash_checksum_group crc32 = {
5454
.group_name = "crc32",
5555
.byte_string = false,
5656
.output_size = CRC32_SIZE,
57-
.function = fs_hash_checksum_mgmt_crc32,
57+
.function = fs_mgmt_hash_checksum_crc32,
5858
};
5959

60-
void fs_hash_checksum_mgmt_register_crc32(void)
60+
void fs_mgmt_hash_checksum_register_crc32(void)
6161
{
62-
hash_checksum_mgmt_register_group(&crc32);
62+
fs_mgmt_hash_checksum_register_group(&crc32);
6363
}
6464

65-
void fs_hash_checksum_mgmt_unregister_crc32(void)
65+
void fs_mgmt_hash_checksum_unregister_crc32(void)
6666
{
67-
hash_checksum_mgmt_unregister_group(&crc32);
67+
fs_mgmt_hash_checksum_unregister_group(&crc32);
6868
}

subsys/mgmt/mcumgr/grp/fs_mgmt/src/hash_checksum_sha256.c renamed to subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt_hash_checksum_sha256.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/fs/fs.h>
99
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
10-
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
10+
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
1111
#include <string.h>
1212

1313
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
14-
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_sha256.h>
14+
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_sha256.h>
1515

1616
#if defined(CONFIG_TINYCRYPT_SHA256)
1717
#include <tinycrypt/constants.h>
@@ -25,7 +25,7 @@
2525

2626
#if defined(CONFIG_TINYCRYPT_SHA256)
2727
/* Tinycrypt SHA256 implementation */
28-
static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
28+
static int fs_mgmt_hash_checksum_sha256(struct fs_file_t *file, uint8_t *output,
2929
size_t *out_len, size_t len)
3030
{
3131
int rc = 0;
@@ -72,7 +72,7 @@ static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
7272
}
7373
#else
7474
/* mbedtls SHA256 implementation */
75-
static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
75+
static int fs_mgmt_hash_checksum_sha256(struct fs_file_t *file, uint8_t *output,
7676
size_t *out_len, size_t len)
7777
{
7878
int rc = 0;
@@ -133,19 +133,19 @@ static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
133133
}
134134
#endif
135135

136-
struct hash_checksum_mgmt_group sha256 = {
136+
static struct fs_mgmt_hash_checksum_group sha256 = {
137137
.group_name = "sha256",
138138
.byte_string = true,
139139
.output_size = SHA256_DIGEST_SIZE,
140-
.function = fs_hash_checksum_mgmt_sha256,
140+
.function = fs_mgmt_hash_checksum_sha256,
141141
};
142142

143-
void fs_hash_checksum_mgmt_register_sha256(void)
143+
void fs_mgmt_hash_checksum_register_sha256(void)
144144
{
145-
hash_checksum_mgmt_register_group(&sha256);
145+
fs_mgmt_hash_checksum_register_group(&sha256);
146146
}
147147

148-
void fs_hash_checksum_mgmt_unregister_sha256(void)
148+
void fs_mgmt_hash_checksum_unregister_sha256(void)
149149
{
150-
hash_checksum_mgmt_unregister_group(&sha256);
150+
fs_mgmt_hash_checksum_unregister_group(&sha256);
151151
}

0 commit comments

Comments
 (0)