|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <suit_manifest_variables.h> |
| 8 | +#include <sdfw/sdfw_services/ssf_client.h> |
| 9 | +#include "suit_service_decode.h" |
| 10 | +#include "suit_service_encode.h" |
| 11 | +#include "suit_service_types.h" |
| 12 | +#include "suit_service_utils.h" |
| 13 | + |
| 14 | +#include <zephyr/logging/log.h> |
| 15 | +LOG_MODULE_REGISTER(suit_mfst_var, CONFIG_SSF_SUIT_SERVICE_LOG_LEVEL); |
| 16 | + |
| 17 | +extern const struct ssf_client_srvc suit_srvc; |
| 18 | + |
| 19 | +suit_plat_err_t suit_mfst_var_get(uint32_t id, uint32_t *val) |
| 20 | +{ |
| 21 | + int err; |
| 22 | + struct suit_req req = {0}; |
| 23 | + struct suit_rsp rsp = {0}; |
| 24 | + struct suit_get_manifest_var_req *req_data = NULL; |
| 25 | + struct suit_get_manifest_var_rsp *rsp_data = NULL; |
| 26 | + const uint8_t *rsp_pkt = NULL; |
| 27 | + |
| 28 | + if (val == NULL) { |
| 29 | + return SUIT_PLAT_ERR_INVAL; |
| 30 | + } |
| 31 | + |
| 32 | + req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(get_manifest_var); |
| 33 | + req_data = &req.SSF_SUIT_REQ(get_manifest_var); |
| 34 | + |
| 35 | + req_data->SSF_SUIT_REQ_ARG(get_manifest_var, id) = id; |
| 36 | + |
| 37 | + err = ssf_client_send_request(&suit_srvc, &req, &rsp, &rsp_pkt); |
| 38 | + if (err != 0) { |
| 39 | + LOG_ERR("ssf_client_send_request failed"); |
| 40 | + return SUIT_PLAT_ERR_IPC; |
| 41 | + } |
| 42 | + |
| 43 | + rsp_data = &rsp.SSF_SUIT_RSP(get_manifest_var); |
| 44 | + err = rsp_data->SSF_SUIT_RSP_ARG(get_manifest_var, ret); |
| 45 | + if (err != SUIT_PLAT_SUCCESS) { |
| 46 | + ssf_client_decode_done(rsp_pkt); |
| 47 | + LOG_ERR("ssf_client response return code: %d", err); |
| 48 | + return err; |
| 49 | + } |
| 50 | + |
| 51 | + *val = rsp_data->SSF_SUIT_RSP_ARG(get_manifest_var, value); |
| 52 | + ssf_client_decode_done(rsp_pkt); |
| 53 | + |
| 54 | + LOG_INF("suit_mfst_var_get, id: %d, value: %d", id, *val); |
| 55 | + |
| 56 | + return SUIT_PLAT_SUCCESS; |
| 57 | +} |
| 58 | + |
| 59 | +suit_plat_err_t suit_mfst_var_set(uint32_t id, uint32_t val) |
| 60 | +{ |
| 61 | + int err; |
| 62 | + struct suit_req req = {0}; |
| 63 | + struct suit_rsp rsp = {0}; |
| 64 | + struct suit_set_manifest_var_req *req_data = NULL; |
| 65 | + |
| 66 | + LOG_INF("suit_mfst_var_set, id: %d, value: %d", id, val); |
| 67 | + |
| 68 | + req.suit_req_msg_choice = SSF_SUIT_REQ_CHOICE(set_manifest_var); |
| 69 | + req_data = &req.SSF_SUIT_REQ(set_manifest_var); |
| 70 | + |
| 71 | + req_data->SSF_SUIT_REQ_ARG(set_manifest_var, id) = id; |
| 72 | + req_data->SSF_SUIT_REQ_ARG(set_manifest_var, value) = val; |
| 73 | + |
| 74 | + err = ssf_client_send_request(&suit_srvc, &req, &rsp, NULL); |
| 75 | + if (err != 0) { |
| 76 | + LOG_ERR("ssf_client_send_request failed"); |
| 77 | + return SUIT_PLAT_ERR_IPC; |
| 78 | + } |
| 79 | + |
| 80 | + return rsp.SSF_SUIT_RSP(set_manifest_var).SSF_SUIT_RSP_ARG(set_manifest_var, ret); |
| 81 | +} |
0 commit comments