1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef H_BOOT_SERIAL_EXTENTIONS_
8 #define H_BOOT_SERIAL_EXTENTIONS_
9 
10 #include <zephyr/kernel.h>
11 #include <zephyr/sys/util_macro.h>
12 #include <zephyr/sys/iterable_sections.h>
13 
14 /**
15  * Callback handler prototype for boot serial extensions.
16  *
17  * @param[in]   hdr       MCUmgr header
18  * @param[in]   buffer    Buffer with first MCUmgr message
19  * @param[in]   len       Length of data in buffer
20  * @param[out]  cs        Response
21  *
22  * @return      MGMT_ERR_ENOTSUP to run other handlers, other MGMT_ERR_* value
23  *              when expected handler has ran.
24  */
25 typedef int (*bs_custom_handler_cb)(const struct nmgr_hdr *hdr,
26                                     const char *buffer, int len,
27                                     zcbor_state_t *cs);
28 
29 struct mcuboot_bs_custom_handlers {
30     const bs_custom_handler_cb handler;
31 };
32 
33 /* Used to create an iterable section containing a boot serial handler
34  * function
35  */
36 #define MCUMGR_HANDLER_DEFINE(name, _handler)                          \
37         STRUCT_SECTION_ITERABLE(mcuboot_bs_custom_handlers, name) = {  \
38             .handler = _handler,                                       \
39         }
40 
41 #endif /* H_BOOT_SERIAL_EXTENTIONS_ */
42