1 /*
2  * Copyright (c) 2021-2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 
9 #include "bootutil/bootutil_log.h"
10 #include "../boot_serial/src/boot_serial_priv.h"
11 #include <zcbor_encode.h>
12 #include <boot_serial/boot_serial_extensions.h>
13 
14 BOOT_LOG_MODULE_DECLARE(mcuboot);
15 
bs_peruser_system_specific(const struct nmgr_hdr * hdr,const char * buffer,int len,zcbor_state_t * cs)16 int bs_peruser_system_specific(const struct nmgr_hdr *hdr, const char *buffer,
17                                int len, zcbor_state_t *cs)
18 {
19     int mgmt_rc = MGMT_ERR_ENOTSUP;
20 
21     STRUCT_SECTION_FOREACH(mcuboot_bs_custom_handlers, function) {
22         if (function->handler) {
23             mgmt_rc = function->handler(hdr, buffer, len, cs);
24 
25             if (mgmt_rc != MGMT_ERR_ENOTSUP) {
26                 break;
27             }
28         }
29     }
30 
31     if (mgmt_rc == MGMT_ERR_ENOTSUP) {
32         zcbor_map_start_encode(cs, 10);
33         zcbor_tstr_put_lit(cs, "rc");
34         zcbor_uint32_put(cs, mgmt_rc);
35         zcbor_map_end_encode(cs, 10);
36     }
37 
38     return MGMT_ERR_OK;
39 }
40