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 <jamie.mccrae@nordicsemi.no>
This commit is contained in:
parent
4c70bf6630
commit
cbd0d2d55a
9 changed files with 107 additions and 106 deletions
|
@ -16,7 +16,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @typedef hash_checksum_mgmt_handler_fn
|
/** @typedef fs_mgmt_hash_checksum_handler_fn
|
||||||
* @brief Function that gets called to generate a hash or checksum.
|
* @brief Function that gets called to generate a hash or checksum.
|
||||||
*
|
*
|
||||||
* @param file Opened file context
|
* @param file Opened file context
|
||||||
|
@ -26,14 +26,13 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @return 0 on success, negative error code on failure.
|
* @return 0 on success, negative error code on failure.
|
||||||
*/
|
*/
|
||||||
typedef int (*hash_checksum_mgmt_handler_fn)(struct fs_file_t *file,
|
typedef int (*fs_mgmt_hash_checksum_handler_fn)(struct fs_file_t *file, uint8_t *output,
|
||||||
uint8_t *output, size_t *out_len,
|
size_t *out_len, size_t len);
|
||||||
size_t len);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A collection of handlers for an entire hash/checksum group.
|
* @brief A collection of handlers for an entire hash/checksum group.
|
||||||
*/
|
*/
|
||||||
struct hash_checksum_mgmt_group {
|
struct fs_mgmt_hash_checksum_group {
|
||||||
/** Entry list node. */
|
/** Entry list node. */
|
||||||
sys_snode_t node;
|
sys_snode_t node;
|
||||||
|
|
||||||
|
@ -47,31 +46,31 @@ struct hash_checksum_mgmt_group {
|
||||||
uint8_t output_size;
|
uint8_t output_size;
|
||||||
|
|
||||||
/** Hash/checksum function pointer. */
|
/** Hash/checksum function pointer. */
|
||||||
hash_checksum_mgmt_handler_fn function;
|
fs_mgmt_hash_checksum_handler_fn function;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @typedef hash_checksum_mgmt_list_cb
|
/** @typedef fs_mgmt_hash_checksum_list_cb
|
||||||
* @brief Function that gets called with hash/checksum details
|
* @brief Function that gets called with hash/checksum details
|
||||||
*
|
*
|
||||||
* @param group Details about a supported hash/checksum
|
* @param group Details about a supported hash/checksum
|
||||||
* @param user_data User-supplied value to calling function
|
* @param user_data User-supplied value to calling function
|
||||||
*/
|
*/
|
||||||
typedef void (*hash_checksum_mgmt_list_cb)(const struct hash_checksum_mgmt_group *group,
|
typedef void (*fs_mgmt_hash_checksum_list_cb)(const struct fs_mgmt_hash_checksum_group *group,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers a full hash/checksum group.
|
* @brief Registers a full hash/checksum group.
|
||||||
*
|
*
|
||||||
* @param group The group to register.
|
* @param group The group to register.
|
||||||
*/
|
*/
|
||||||
void hash_checksum_mgmt_register_group(struct hash_checksum_mgmt_group *group);
|
void fs_mgmt_hash_checksum_register_group(struct fs_mgmt_hash_checksum_group *group);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unregisters a full hash/checksum group.
|
* @brief Unregisters a full hash/checksum group.
|
||||||
*
|
*
|
||||||
* @param group The group to register.
|
* @param group The group to register.
|
||||||
*/
|
*/
|
||||||
void hash_checksum_mgmt_unregister_group(struct hash_checksum_mgmt_group *group);
|
void fs_mgmt_hash_checksum_unregister_group(struct fs_mgmt_hash_checksum_group *group);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds a registered hash/checksum handler.
|
* @brief Finds a registered hash/checksum handler.
|
||||||
|
@ -81,7 +80,7 @@ void hash_checksum_mgmt_unregister_group(struct hash_checksum_mgmt_group *group)
|
||||||
* @return The requested hash/checksum handler on success;
|
* @return The requested hash/checksum handler on success;
|
||||||
* NULL on failure.
|
* NULL on failure.
|
||||||
*/
|
*/
|
||||||
const struct hash_checksum_mgmt_group *hash_checksum_mgmt_find_handler(const char *name);
|
const struct fs_mgmt_hash_checksum_group *fs_mgmt_hash_checksum_find_handler(const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Runs a callback with all supported hash/checksum types.
|
* @brief Runs a callback with all supported hash/checksum types.
|
||||||
|
@ -89,7 +88,7 @@ const struct hash_checksum_mgmt_group *hash_checksum_mgmt_find_handler(const cha
|
||||||
* @param cb The callback function to call with each hash/checksum type.
|
* @param cb The callback function to call with each hash/checksum type.
|
||||||
* @param user_data Data to pass back with the callback function.
|
* @param user_data Data to pass back with the callback function.
|
||||||
*/
|
*/
|
||||||
void hash_checksum_mgmt_find_handlers(hash_checksum_mgmt_list_cb cb, void *user_data);
|
void fs_mgmt_hash_checksum_find_handlers(fs_mgmt_hash_checksum_list_cb cb, void *user_data);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
|
@ -11,13 +11,13 @@
|
||||||
add_library(mgmt_mcumgr_grp_fs src/fs_mgmt.c)
|
add_library(mgmt_mcumgr_grp_fs src/fs_mgmt.c)
|
||||||
|
|
||||||
target_sources_ifdef(CONFIG_FS_MGMT_CHECKSUM_HASH
|
target_sources_ifdef(CONFIG_FS_MGMT_CHECKSUM_HASH
|
||||||
mgmt_mcumgr_grp_fs PRIVATE src/hash_checksum_mgmt.c
|
mgmt_mcumgr_grp_fs PRIVATE src/fs_mgmt_hash_checksum.c
|
||||||
)
|
)
|
||||||
target_sources_ifdef(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32
|
target_sources_ifdef(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32
|
||||||
mgmt_mcumgr_grp_fs PRIVATE src/hash_checksum_crc32.c
|
mgmt_mcumgr_grp_fs PRIVATE src/fs_mgmt_hash_checksum_crc32.c
|
||||||
)
|
)
|
||||||
target_sources_ifdef(CONFIG_FS_MGMT_HASH_SHA256
|
target_sources_ifdef(CONFIG_FS_MGMT_HASH_SHA256
|
||||||
mgmt_mcumgr_grp_fs PRIVATE src/hash_checksum_sha256.c)
|
mgmt_mcumgr_grp_fs PRIVATE src/fs_mgmt_hash_checksum_sha256.c)
|
||||||
|
|
||||||
if (CONFIG_FS_MGMT_CHECKSUM_HASH AND CONFIG_FS_MGMT_HASH_SHA256)
|
if (CONFIG_FS_MGMT_CHECKSUM_HASH AND CONFIG_FS_MGMT_HASH_SHA256)
|
||||||
if (NOT CONFIG_TINYCRYPT)
|
if (NOT CONFIG_TINYCRYPT)
|
||||||
|
|
|
@ -16,12 +16,12 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
* @brief Registers the IEEE CRC32 checksum mcumgr handler.
|
* @brief Registers the IEEE CRC32 checksum mcumgr handler.
|
||||||
*/
|
*/
|
||||||
void fs_hash_checksum_mgmt_register_crc32(void);
|
void fs_mgmt_hash_checksum_register_crc32(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Un-registers the IEEE CRC32 checksum mcumgr handler.
|
* @brief Un-registers the IEEE CRC32 checksum mcumgr handler.
|
||||||
*/
|
*/
|
||||||
void fs_hash_checksum_mgmt_unregister_crc32(void);
|
void fs_mgmt_hash_checksum_unregister_crc32(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
|
@ -16,12 +16,12 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
* @brief Registers the SHA256 hash mcumgr handler.
|
* @brief Registers the SHA256 hash mcumgr handler.
|
||||||
*/
|
*/
|
||||||
void fs_hash_checksum_mgmt_register_sha256(void);
|
void fs_mgmt_hash_checksum_register_sha256(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Un-registers the SHA256 hash mcumgr handler.
|
* @brief Un-registers the SHA256 hash mcumgr handler.
|
||||||
*/
|
*/
|
||||||
void fs_hash_checksum_mgmt_unregister_sha256(void);
|
void fs_mgmt_hash_checksum_unregister_sha256(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||||
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
#include <zephyr/mgmt/mcumgr/smp/smp.h>
|
||||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h>
|
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt.h>
|
||||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
|
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -25,11 +25,11 @@
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
|
||||||
|
|
||||||
#if defined(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32)
|
#if defined(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32)
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_crc32.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_crc32.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_FS_MGMT_HASH_SHA256)
|
#if defined(CONFIG_FS_MGMT_HASH_SHA256)
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_sha256.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_sha256.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS)
|
#if defined(CONFIG_MCUMGR_MGMT_NOTIFICATION_HOOKS)
|
||||||
|
@ -77,7 +77,7 @@ static const struct mgmt_handler fs_mgmt_handlers[];
|
||||||
|
|
||||||
#if defined(CONFIG_FS_MGMT_CHECKSUM_HASH)
|
#if defined(CONFIG_FS_MGMT_CHECKSUM_HASH)
|
||||||
/* Hash/checksum iterator information passing structure */
|
/* Hash/checksum iterator information passing structure */
|
||||||
struct hash_checksum_iterator_info {
|
struct fs_mgmt_hash_checksum_iterator_info {
|
||||||
zcbor_state_t *zse;
|
zcbor_state_t *zse;
|
||||||
bool ok;
|
bool ok;
|
||||||
};
|
};
|
||||||
|
@ -464,7 +464,7 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
|
||||||
struct zcbor_string name = { 0 };
|
struct zcbor_string name = { 0 };
|
||||||
size_t decoded;
|
size_t decoded;
|
||||||
struct fs_file_t file;
|
struct fs_file_t file;
|
||||||
const struct hash_checksum_mgmt_group *group = NULL;
|
const struct fs_mgmt_hash_checksum_group *group = NULL;
|
||||||
|
|
||||||
struct zcbor_map_decode_key_val fs_hash_checksum_decode[] = {
|
struct zcbor_map_decode_key_val fs_hash_checksum_decode[] = {
|
||||||
ZCBOR_MAP_DECODE_KEY_VAL(type, zcbor_tstr_decode, &type),
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for supported hash/checksum */
|
/* Search for supported hash/checksum */
|
||||||
group = hash_checksum_mgmt_find_handler(type_arr);
|
group = fs_mgmt_hash_checksum_find_handler(type_arr);
|
||||||
|
|
||||||
if (group == NULL) {
|
if (group == NULL) {
|
||||||
return MGMT_ERR_EINVAL;
|
return MGMT_ERR_EINVAL;
|
||||||
|
@ -591,10 +591,12 @@ static int fs_mgmt_file_hash_checksum(struct smp_streamer *ctxt)
|
||||||
|
|
||||||
#if defined(CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_CMD)
|
#if defined(CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_CMD)
|
||||||
/* Callback for supported hash/checksum types to encode details on one type into CBOR map */
|
/* Callback for supported hash/checksum types to encode details on one type into CBOR map */
|
||||||
static void supported_hash_checksum_callback(const struct hash_checksum_mgmt_group *group,
|
static void fs_mgmt_supported_hash_checksum_callback(
|
||||||
void *user_data)
|
const struct fs_mgmt_hash_checksum_group *group,
|
||||||
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct hash_checksum_iterator_info *ctx = (struct hash_checksum_iterator_info *)user_data;
|
struct fs_mgmt_hash_checksum_iterator_info *ctx =
|
||||||
|
(struct fs_mgmt_hash_checksum_iterator_info *)user_data;
|
||||||
|
|
||||||
if (!ctx->ok) {
|
if (!ctx->ok) {
|
||||||
return;
|
return;
|
||||||
|
@ -616,7 +618,7 @@ static int
|
||||||
fs_mgmt_supported_hash_checksum(struct smp_streamer *ctxt)
|
fs_mgmt_supported_hash_checksum(struct smp_streamer *ctxt)
|
||||||
{
|
{
|
||||||
zcbor_state_t *zse = ctxt->writer->zs;
|
zcbor_state_t *zse = ctxt->writer->zs;
|
||||||
struct hash_checksum_iterator_info itr_ctx = {
|
struct fs_mgmt_hash_checksum_iterator_info itr_ctx = {
|
||||||
.zse = zse,
|
.zse = zse,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -624,7 +626,7 @@ fs_mgmt_supported_hash_checksum(struct smp_streamer *ctxt)
|
||||||
|
|
||||||
zcbor_map_start_encode(zse, CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES);
|
zcbor_map_start_encode(zse, CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES);
|
||||||
|
|
||||||
hash_checksum_mgmt_find_handlers(supported_hash_checksum_callback, &itr_ctx);
|
fs_mgmt_hash_checksum_find_handlers(fs_mgmt_supported_hash_checksum_callback, &itr_ctx);
|
||||||
|
|
||||||
if (!itr_ctx.ok ||
|
if (!itr_ctx.ok ||
|
||||||
!zcbor_map_end_encode(zse, CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES)) {
|
!zcbor_map_end_encode(zse, CONFIG_MCUMGR_GRP_FS_CHECKSUM_HASH_SUPPORTED_MAX_TYPES)) {
|
||||||
|
@ -676,11 +678,11 @@ void fs_mgmt_register_group(void)
|
||||||
#if defined(CONFIG_FS_MGMT_CHECKSUM_HASH)
|
#if defined(CONFIG_FS_MGMT_CHECKSUM_HASH)
|
||||||
/* Register any supported hash or checksum functions */
|
/* Register any supported hash or checksum functions */
|
||||||
#if defined(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32)
|
#if defined(CONFIG_FS_MGMT_CHECKSUM_IEEE_CRC32)
|
||||||
fs_hash_checksum_mgmt_register_crc32();
|
fs_mgmt_hash_checksum_register_crc32();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_FS_MGMT_HASH_SHA256)
|
#if defined(CONFIG_FS_MGMT_HASH_SHA256)
|
||||||
fs_hash_checksum_mgmt_register_sha256();
|
fs_mgmt_hash_checksum_register_sha256();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
54
subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt_hash_checksum.c
Normal file
54
subsys/mgmt/mcumgr/grp/fs_mgmt/src/fs_mgmt_hash_checksum.c
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 Laird Connectivity
|
||||||
|
* Copyright (c) 2022 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
|
||||||
|
|
||||||
|
static sys_slist_t fs_mgmt_hash_checksum_group_list =
|
||||||
|
SYS_SLIST_STATIC_INIT(&fs_mgmt_hash_checksum_group_list);
|
||||||
|
|
||||||
|
void fs_mgmt_hash_checksum_unregister_group(struct fs_mgmt_hash_checksum_group *group)
|
||||||
|
{
|
||||||
|
(void)sys_slist_find_and_remove(&fs_mgmt_hash_checksum_group_list, &group->node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fs_mgmt_hash_checksum_register_group(struct fs_mgmt_hash_checksum_group *group)
|
||||||
|
{
|
||||||
|
sys_slist_append(&fs_mgmt_hash_checksum_group_list, &group->node);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct fs_mgmt_hash_checksum_group *fs_mgmt_hash_checksum_find_handler(const char *name)
|
||||||
|
{
|
||||||
|
/* Find the group with the specified group name */
|
||||||
|
struct fs_mgmt_hash_checksum_group *group = NULL;
|
||||||
|
sys_snode_t *snp, *sns;
|
||||||
|
|
||||||
|
SYS_SLIST_FOR_EACH_NODE_SAFE(&fs_mgmt_hash_checksum_group_list, snp, sns) {
|
||||||
|
struct fs_mgmt_hash_checksum_group *loop_group =
|
||||||
|
CONTAINER_OF(snp, struct fs_mgmt_hash_checksum_group, node);
|
||||||
|
if (strcmp(loop_group->group_name, name) == 0) {
|
||||||
|
group = loop_group;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fs_mgmt_hash_checksum_find_handlers(fs_mgmt_hash_checksum_list_cb cb, void *user_data)
|
||||||
|
{
|
||||||
|
/* Run a callback with all supported hash/checksums */
|
||||||
|
sys_snode_t *snp, *sns;
|
||||||
|
|
||||||
|
SYS_SLIST_FOR_EACH_NODE_SAFE(&fs_mgmt_hash_checksum_group_list, snp, sns) {
|
||||||
|
struct fs_mgmt_hash_checksum_group *group =
|
||||||
|
CONTAINER_OF(snp, struct fs_mgmt_hash_checksum_group, node);
|
||||||
|
cb(group, user_data);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,15 +8,15 @@
|
||||||
#include <zephyr/sys/crc.h>
|
#include <zephyr/sys/crc.h>
|
||||||
#include <zephyr/fs/fs.h>
|
#include <zephyr/fs/fs.h>
|
||||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
|
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_crc32.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_crc32.h>
|
||||||
|
|
||||||
#define CRC32_SIZE 4
|
#define CRC32_SIZE 4
|
||||||
|
|
||||||
static int fs_hash_checksum_mgmt_crc32(struct fs_file_t *file, uint8_t *output,
|
static int fs_mgmt_hash_checksum_crc32(struct fs_file_t *file, uint8_t *output,
|
||||||
size_t *out_len, size_t len)
|
size_t *out_len, size_t len)
|
||||||
{
|
{
|
||||||
/* Calculate IEEE CRC32 checksum of target file */
|
/* 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,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct hash_checksum_mgmt_group crc32 = {
|
static struct fs_mgmt_hash_checksum_group crc32 = {
|
||||||
.group_name = "crc32",
|
.group_name = "crc32",
|
||||||
.byte_string = false,
|
.byte_string = false,
|
||||||
.output_size = CRC32_SIZE,
|
.output_size = CRC32_SIZE,
|
||||||
.function = fs_hash_checksum_mgmt_crc32,
|
.function = fs_mgmt_hash_checksum_crc32,
|
||||||
};
|
};
|
||||||
|
|
||||||
void fs_hash_checksum_mgmt_register_crc32(void)
|
void fs_mgmt_hash_checksum_register_crc32(void)
|
||||||
{
|
{
|
||||||
hash_checksum_mgmt_register_group(&crc32);
|
fs_mgmt_hash_checksum_register_group(&crc32);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fs_hash_checksum_mgmt_unregister_crc32(void)
|
void fs_mgmt_hash_checksum_unregister_crc32(void)
|
||||||
{
|
{
|
||||||
hash_checksum_mgmt_unregister_group(&crc32);
|
fs_mgmt_hash_checksum_unregister_group(&crc32);
|
||||||
}
|
}
|
|
@ -7,11 +7,11 @@
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/fs/fs.h>
|
#include <zephyr/fs/fs.h>
|
||||||
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
#include <zephyr/mgmt/mcumgr/mgmt/mgmt.h>
|
||||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
|
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_config.h>
|
||||||
#include <mgmt/mcumgr/grp/fs_mgmt/hash_checksum_sha256.h>
|
#include <mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_hash_checksum_sha256.h>
|
||||||
|
|
||||||
#if defined(CONFIG_TINYCRYPT_SHA256)
|
#if defined(CONFIG_TINYCRYPT_SHA256)
|
||||||
#include <tinycrypt/constants.h>
|
#include <tinycrypt/constants.h>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#if defined(CONFIG_TINYCRYPT_SHA256)
|
#if defined(CONFIG_TINYCRYPT_SHA256)
|
||||||
/* Tinycrypt SHA256 implementation */
|
/* Tinycrypt SHA256 implementation */
|
||||||
static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
|
static int fs_mgmt_hash_checksum_sha256(struct fs_file_t *file, uint8_t *output,
|
||||||
size_t *out_len, size_t len)
|
size_t *out_len, size_t len)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
@ -72,7 +72,7 @@ static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* mbedtls SHA256 implementation */
|
/* mbedtls SHA256 implementation */
|
||||||
static int fs_hash_checksum_mgmt_sha256(struct fs_file_t *file, uint8_t *output,
|
static int fs_mgmt_hash_checksum_sha256(struct fs_file_t *file, uint8_t *output,
|
||||||
size_t *out_len, size_t len)
|
size_t *out_len, size_t len)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
@ -133,19 +133,19 @@ error:
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct hash_checksum_mgmt_group sha256 = {
|
static struct fs_mgmt_hash_checksum_group sha256 = {
|
||||||
.group_name = "sha256",
|
.group_name = "sha256",
|
||||||
.byte_string = true,
|
.byte_string = true,
|
||||||
.output_size = SHA256_DIGEST_SIZE,
|
.output_size = SHA256_DIGEST_SIZE,
|
||||||
.function = fs_hash_checksum_mgmt_sha256,
|
.function = fs_mgmt_hash_checksum_sha256,
|
||||||
};
|
};
|
||||||
|
|
||||||
void fs_hash_checksum_mgmt_register_sha256(void)
|
void fs_mgmt_hash_checksum_register_sha256(void)
|
||||||
{
|
{
|
||||||
hash_checksum_mgmt_register_group(&sha256);
|
fs_mgmt_hash_checksum_register_group(&sha256);
|
||||||
}
|
}
|
||||||
|
|
||||||
void fs_hash_checksum_mgmt_unregister_sha256(void)
|
void fs_mgmt_hash_checksum_unregister_sha256(void)
|
||||||
{
|
{
|
||||||
hash_checksum_mgmt_unregister_group(&sha256);
|
fs_mgmt_hash_checksum_unregister_group(&sha256);
|
||||||
}
|
}
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2022 Laird Connectivity
|
|
||||||
* Copyright (c) 2022 Nordic Semiconductor ASA
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <zephyr/mgmt/mcumgr/grp/fs_mgmt/fs_mgmt_chksum.h>
|
|
||||||
|
|
||||||
static sys_slist_t hash_checksum_mgmt_group_list =
|
|
||||||
SYS_SLIST_STATIC_INIT(&hash_checksum_mgmt_group_list);
|
|
||||||
|
|
||||||
void hash_checksum_mgmt_unregister_group(struct hash_checksum_mgmt_group *group)
|
|
||||||
{
|
|
||||||
(void)sys_slist_find_and_remove(&hash_checksum_mgmt_group_list, &group->node);
|
|
||||||
}
|
|
||||||
|
|
||||||
void hash_checksum_mgmt_register_group(struct hash_checksum_mgmt_group *group)
|
|
||||||
{
|
|
||||||
sys_slist_append(&hash_checksum_mgmt_group_list, &group->node);
|
|
||||||
}
|
|
||||||
|
|
||||||
const struct hash_checksum_mgmt_group *hash_checksum_mgmt_find_handler(const char *name)
|
|
||||||
{
|
|
||||||
/* Find the group with the specified group name */
|
|
||||||
struct hash_checksum_mgmt_group *group = NULL;
|
|
||||||
sys_snode_t *snp, *sns;
|
|
||||||
|
|
||||||
SYS_SLIST_FOR_EACH_NODE_SAFE(&hash_checksum_mgmt_group_list, snp, sns) {
|
|
||||||
struct hash_checksum_mgmt_group *loop_group =
|
|
||||||
CONTAINER_OF(snp, struct hash_checksum_mgmt_group, node);
|
|
||||||
if (strcmp(loop_group->group_name, name) == 0) {
|
|
||||||
group = loop_group;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
void hash_checksum_mgmt_find_handlers(hash_checksum_mgmt_list_cb cb, void *user_data)
|
|
||||||
{
|
|
||||||
/* Run a callback with all supported hash/checksums */
|
|
||||||
sys_snode_t *snp, *sns;
|
|
||||||
|
|
||||||
SYS_SLIST_FOR_EACH_NODE_SAFE(&hash_checksum_mgmt_group_list, snp, sns) {
|
|
||||||
struct hash_checksum_mgmt_group *group =
|
|
||||||
CONTAINER_OF(snp, struct hash_checksum_mgmt_group, node);
|
|
||||||
cb(group, user_data);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue