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
fs_mgmt_hash_checksum_unregister_group(struct fs_mgmt_hash_checksum_group * group)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
fs_mgmt_hash_checksum_register_group(struct fs_mgmt_hash_checksum_group * group)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
fs_mgmt_hash_checksum_find_handler(const char * name)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
fs_mgmt_hash_checksum_find_handlers(fs_mgmt_hash_checksum_list_cb cb,void * user_data)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 }
55