From 277a4a5b6e0134c09b99b73ff31e45416302158b Mon Sep 17 00:00:00 2001 From: Aymen LAOUINI Date: Thu, 5 Dec 2024 09:09:04 +0200 Subject: [PATCH] Add device information service to secure domain --- .../sdfw/sdfw_services/device_info_service.h | 31 +++ subsys/sdfw_services/services/CMakeLists.txt | 1 + subsys/sdfw_services/services/Kconfig | 1 + .../services/device_info/CMakeLists.txt | 12 ++ .../services/device_info/Kconfig | 13 ++ .../device_info/device_info_service.c | 85 ++++++++ .../device_info/device_info_service.cddl | 63 ++++++ .../zcbor_generated/CMakeLists.txt | 16 ++ .../device_info_service_decode.c | 191 ++++++++++++++++++ .../device_info_service_decode.h | 46 +++++ .../device_info_service_encode.c | 179 ++++++++++++++++ .../device_info_service_encode.h | 45 +++++ .../device_info_service_types.h | 101 +++++++++ 13 files changed, 784 insertions(+) create mode 100644 include/sdfw/sdfw_services/device_info_service.h create mode 100644 subsys/sdfw_services/services/device_info/CMakeLists.txt create mode 100644 subsys/sdfw_services/services/device_info/Kconfig create mode 100644 subsys/sdfw_services/services/device_info/device_info_service.c create mode 100644 subsys/sdfw_services/services/device_info/device_info_service.cddl create mode 100644 subsys/sdfw_services/services/device_info/zcbor_generated/CMakeLists.txt create mode 100644 subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.c create mode 100644 subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.h create mode 100644 subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.c create mode 100644 subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.h create mode 100644 subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_types.h diff --git a/include/sdfw/sdfw_services/device_info_service.h b/include/sdfw/sdfw_services/device_info_service.h new file mode 100644 index 000000000000..cf267b98c9a7 --- /dev/null +++ b/include/sdfw/sdfw_services/device_info_service.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +#ifndef DEVICE_INFO_SERVICE_H__ +#define DEVICE_INFO_SERVICE_H__ + +#include +#include + +#include + +/** .. include_startingpoint_device_info_header_rst */ +/** + * @brief Read UUID value. + * + * @note UUID is provided in words, byte order is the same as + * read from the memory and no endianness swapping is performed. + * + * @param[out] uuid_words Local buffer for copying the UUID words into. + * @param[in] uuid_words_count Size of local buffer, should be at least 4 words. + * + * @return 0 on success, otherwise a negative errno. + */ +int ssf_device_info_get_uuid(uint32_t *uuid_words, size_t uuid_words_count); + +/** .. include_endpoint_device_info_header_rst */ + +#endif /* DEVICE_INFO_SERVICE_H__ */ diff --git a/subsys/sdfw_services/services/CMakeLists.txt b/subsys/sdfw_services/services/CMakeLists.txt index 7c323f72f28e..3ea43a16d78b 100644 --- a/subsys/sdfw_services/services/CMakeLists.txt +++ b/subsys/sdfw_services/services/CMakeLists.txt @@ -5,6 +5,7 @@ # # Services +add_subdirectory_ifdef(CONFIG_SSF_DEVICE_INFO_SERVICE_ENABLED device_info) add_subdirectory_ifdef(CONFIG_SSF_ECHO_SERVICE_ENABLED echo) add_subdirectory_ifdef(CONFIG_SSF_ENC_FW_SERVICE_ENABLED enc_fw) add_subdirectory_ifdef(CONFIG_SSF_EXTMEM_SERVICE_ENABLED extmem) diff --git a/subsys/sdfw_services/services/Kconfig b/subsys/sdfw_services/services/Kconfig index a9ed5a5dd52a..a1edb63ab9f7 100644 --- a/subsys/sdfw_services/services/Kconfig +++ b/subsys/sdfw_services/services/Kconfig @@ -5,6 +5,7 @@ # # Services +rsource "device_info/Kconfig" rsource "echo/Kconfig" rsource "enc_fw/Kconfig" rsource "extmem/Kconfig" diff --git a/subsys/sdfw_services/services/device_info/CMakeLists.txt b/subsys/sdfw_services/services/device_info/CMakeLists.txt new file mode 100644 index 000000000000..c34b4469d8f7 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +zephyr_sources(device_info_service.c) + +generate_and_add_cbor_files(device_info_service.cddl zcbor_generated + device_info_service_req + device_info_service_rsp +) diff --git a/subsys/sdfw_services/services/device_info/Kconfig b/subsys/sdfw_services/services/device_info/Kconfig new file mode 100644 index 000000000000..a55885cea70d --- /dev/null +++ b/subsys/sdfw_services/services/device_info/Kconfig @@ -0,0 +1,13 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +service_name = DEVICE_INFO +service_default_enabled = y +service_id = 0x78 +service_version = 1 +service_buffer_size = 128 +service_name_str = Device Info +rsource "../Kconfig.template.service" diff --git a/subsys/sdfw_services/services/device_info/device_info_service.c b/subsys/sdfw_services/services/device_info/device_info_service.c new file mode 100644 index 000000000000..ad00c86203fd --- /dev/null +++ b/subsys/sdfw_services/services/device_info/device_info_service.c @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/** .. include_startingpoint_device_info_source_rst */ +#include +#include +#include + +#include + +#include "device_info_service_decode.h" +#include "device_info_service_encode.h" +#include "device_info_service_types.h" +#include +#include "ssf_client_os.h" + +#define UUID_BYTES_LENGTH 16UL + +SSF_CLIENT_LOG_REGISTER(device_info_service, CONFIG_SSF_DEVICE_INFO_SERVICE_LOG_LEVEL); + +SSF_CLIENT_SERVICE_DEFINE(device_info_srvc, DEVICE_INFO, cbor_encode_device_info_req, + cbor_decode_device_info_resp); + + +int ssf_device_info_get_uuid(uint32_t *uuid_words, size_t uuid_words_count) +{ + int err = -1; /* initialize with negative value for error */ + + if ((NULL != uuid_words) && (uuid_words_count >= UUID_BYTES_LENGTH)) { + /* valid parameters */ + int ret = -1; /* initialize with negative value for error */ + const uint8_t *rsp_pkt; /* For freeing response packet after copying rsp_str. */ + + struct read_req uuid_read_request = { + .read_req_target.entity_choice = entity_UUID_c, + }; + + struct device_info_req read_request = { + .req_msg_choice = req_msg_read_req_m_c, + .req_msg_read_req_m = uuid_read_request + }; + + struct device_info_resp read_response; + + err = ssf_client_send_request(&device_info_srvc, &read_request, &read_response, &rsp_pkt); + if (err != 0) { + return err; + } + + struct read_resp uuid_read_response = read_response.resp_msg_read_resp_m; + if (read_response.resp_msg_choice == resp_msg_read_resp_m_c) { + if (entity_UUID_c == uuid_read_response.read_resp_target.entity_choice) { + ret = read_response.resp_msg_read_resp_m.read_resp_status.stat_choice; + if (stat_SUCCESS_c != ret) { + ssf_client_decode_done(rsp_pkt); + return ret; + } + } else { + /* not a read UUID response */ + ssf_client_decode_done(rsp_pkt); + return stat_INTERNAL_ERROR_c; + } + + } else { + /* not a read response */ + ssf_client_decode_done(rsp_pkt); + return stat_INTERNAL_ERROR_c; + } + + size_t uuid_words_len = uuid_read_response.read_resp_data_uint_count; + memcpy(uuid_words, uuid_read_response.read_resp_data_uint, uuid_words_len * sizeof(uint32_t)); + + ssf_client_decode_done(rsp_pkt); + } else { + /* invalid parameters */ + err = -1; + + } + return err; +} + +/** .. include_endpoint_device_info_source_rst */ \ No newline at end of file diff --git a/subsys/sdfw_services/services/device_info/device_info_service.cddl b/subsys/sdfw_services/services/device_info/device_info_service.cddl new file mode 100644 index 000000000000..67014980d6e9 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/device_info_service.cddl @@ -0,0 +1,63 @@ +; +; Copyright (c) 2024 Nordic Semiconductor ASA +; +; SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +; + +; .. include_startingpoint_device_info_cddl_rst + +stat = (SUCCESS: 0) / + (INTERNAL_ERROR: 16781313) / + (UNPROGRAMMED: 16781314) + +entity = (UUID: 0) / + (TYPE: 1) / + (TESTIMPRINT: 2) / + (PARTNO: 3) / + (HWREVISION: 4) / + (PRODUCTIONREVISION: 5) + +; Device Info service request payload. +read_req = ( + 1, + target: entity, +) + +write_req = ( + 2, + target: entity, + data: [1*8 uint] ; table of at least 1 int - at most 8 int +) + +; Device Info service response to read data. +read_resp = ( + 1, + target: entity, + status: stat, + data: [1*8 uint] ; table of at least 1 int - at most 8 int +) + +; Device Info service response to write payload. +write_resp = ( + 2, + target: entity, + status: stat, +) + +device_info_req = [ + 3, + msg: ( + read_req / + write_req + ), +] + +device_info_resp = [ + 3, + msg: ( + read_resp / + write_resp + ), +] + +; .. include_endingpoint_device_info_cddl_rst diff --git a/subsys/sdfw_services/services/device_info/zcbor_generated/CMakeLists.txt b/subsys/sdfw_services/services/device_info/zcbor_generated/CMakeLists.txt new file mode 100644 index 000000000000..b052baf14b11 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause +# + +# +# Generated using cmake macro generate_and_add_cbor_files. +# + +zephyr_sources( + device_info_service_decode.c + device_info_service_encode.c +) + +zephyr_include_directories(.) diff --git a/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.c b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.c new file mode 100644 index 000000000000..aacaa4921868 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.c @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/* + * Generated using zcbor version 0.9.0 + * https://github.com/NordicSemiconductor/zcbor + * Generated with a --default-max-qty of 3 + */ + +#include +#include +#include +#include +#include "zcbor_decode.h" +#include "device_info_service_decode.h" +#include "zcbor_print.h" + +#if DEFAULT_MAX_QTY != 3 +#error "The type file was generated with a different default_max_qty than this file" +#endif + +#define log_result(state, result, func) do { \ + if (!result) { \ + zcbor_trace_file(state); \ + zcbor_log("%s error: %s\r\n", func, zcbor_error_str(zcbor_peek_error(state))); \ + } else { \ + zcbor_log("%s success\r\n", func); \ + } \ +} while(0) + +static bool decode_entity(zcbor_state_t *state, struct entity_r *result); +static bool decode_stat(zcbor_state_t *state, struct stat_r *result); +static bool decode_read_req(zcbor_state_t *state, struct read_req *result); +static bool decode_write_req(zcbor_state_t *state, struct write_req *result); +static bool decode_read_resp(zcbor_state_t *state, struct read_resp *result); +static bool decode_write_resp(zcbor_state_t *state, struct write_resp *result); +static bool decode_device_info_req(zcbor_state_t *state, struct device_info_req *result); +static bool decode_device_info_resp(zcbor_state_t *state, struct device_info_resp *result); + + +static bool decode_entity( + zcbor_state_t *state, struct entity_r *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint_decode(state, &(*result).entity_choice, sizeof((*result).entity_choice)))) && ((((((*result).entity_choice == entity_UUID_c) && ((1))) + || (((*result).entity_choice == entity_TYPE_c) && ((1))) + || (((*result).entity_choice == entity_TESTIMPRINT_c) && ((1))) + || (((*result).entity_choice == entity_PARTNO_c) && ((1))) + || (((*result).entity_choice == entity_HWREVISION_c) && ((1))) + || (((*result).entity_choice == entity_PRODUCTIONREVISION_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))); + + log_result(state, res, __func__); + return res; +} + +static bool decode_stat( + zcbor_state_t *state, struct stat_r *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint_decode(state, &(*result).stat_choice, sizeof((*result).stat_choice)))) && ((((((*result).stat_choice == stat_SUCCESS_c) && ((1))) + || (((*result).stat_choice == stat_INTERNAL_ERROR_c) && ((1))) + || (((*result).stat_choice == stat_UNPROGRAMMED_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))); + + log_result(state, res, __func__); + return res; +} + +static bool decode_read_req( + zcbor_state_t *state, struct read_req *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (1)))) + && ((decode_entity(state, (&(*result).read_req_target))))))); + + log_result(state, res, __func__); + return res; +} + +static bool decode_write_req( + zcbor_state_t *state, struct write_req *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (2)))) + && ((decode_entity(state, (&(*result).write_req_target)))) + && ((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 8, &(*result).write_req_data_uint_count, (zcbor_decoder_t *)zcbor_uint32_decode, state, (*&(*result).write_req_data_uint), sizeof(uint32_t))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))))); + + if (false) { + /* For testing that the types of the arguments are correct. + * A compiler error here means a bug in zcbor. + */ + zcbor_uint32_decode(state, (*&(*result).write_req_data_uint)); + } + + log_result(state, res, __func__); + return res; +} + +static bool decode_read_resp( + zcbor_state_t *state, struct read_resp *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (1)))) + && ((decode_entity(state, (&(*result).read_resp_target)))) + && ((decode_stat(state, (&(*result).read_resp_status)))) + && ((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 8, &(*result).read_resp_data_uint_count, (zcbor_decoder_t *)zcbor_uint32_decode, state, (*&(*result).read_resp_data_uint), sizeof(uint32_t))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))))); + + if (false) { + /* For testing that the types of the arguments are correct. + * A compiler error here means a bug in zcbor. + */ + zcbor_uint32_decode(state, (*&(*result).read_resp_data_uint)); + } + + log_result(state, res, __func__); + return res; +} + +static bool decode_write_resp( + zcbor_state_t *state, struct write_resp *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (2)))) + && ((decode_entity(state, (&(*result).write_resp_target)))) + && ((decode_stat(state, (&(*result).write_resp_status))))))); + + log_result(state, res, __func__); + return res; +} + +static bool decode_device_info_req( + zcbor_state_t *state, struct device_info_req *result) +{ + zcbor_log("%s\r\n", __func__); + bool int_res; + + bool res = (((zcbor_list_start_decode(state) && ((((zcbor_uint32_expect(state, (3)))) + && ((zcbor_union_start_code(state) && (int_res = ((((decode_read_req(state, (&(*result).req_msg_read_req_m)))) && (((*result).req_msg_choice = req_msg_read_req_m_c), true)) + || (zcbor_union_elem_code(state) && (((decode_write_req(state, (&(*result).req_msg_write_req_m)))) && (((*result).req_msg_choice = req_msg_write_req_m_c), true)))), zcbor_union_end_code(state), int_res)))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); + + log_result(state, res, __func__); + return res; +} + +static bool decode_device_info_resp( + zcbor_state_t *state, struct device_info_resp *result) +{ + zcbor_log("%s\r\n", __func__); + bool int_res; + + bool res = (((zcbor_list_start_decode(state) && ((((zcbor_uint32_expect(state, (3)))) + && ((zcbor_union_start_code(state) && (int_res = ((((decode_read_resp(state, (&(*result).resp_msg_read_resp_m)))) && (((*result).resp_msg_choice = resp_msg_read_resp_m_c), true)) + || (zcbor_union_elem_code(state) && (((decode_write_resp(state, (&(*result).resp_msg_write_resp_m)))) && (((*result).resp_msg_choice = resp_msg_write_resp_m_c), true)))), zcbor_union_end_code(state), int_res)))) || (zcbor_list_map_end_force_decode(state), false)) && zcbor_list_end_decode(state)))); + + log_result(state, res, __func__); + return res; +} + + + +int cbor_decode_device_info_req( + const uint8_t *payload, size_t payload_len, + struct device_info_req *result, + size_t *payload_len_out) +{ + zcbor_state_t states[5]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_device_info_req, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + + +int cbor_decode_device_info_resp( + const uint8_t *payload, size_t payload_len, + struct device_info_resp *result, + size_t *payload_len_out) +{ + zcbor_state_t states[5]; + + return zcbor_entry_function(payload, payload_len, (void *)result, payload_len_out, states, + (zcbor_decoder_t *)decode_device_info_resp, sizeof(states) / sizeof(zcbor_state_t), 1); +} diff --git a/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.h b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.h new file mode 100644 index 000000000000..79196c792edc --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/* + * Generated using zcbor version 0.9.0 + * https://github.com/NordicSemiconductor/zcbor + * Generated with a --default-max-qty of 3 + */ + +#ifndef DEVICE_INFO_SERVICE_DECODE_H__ +#define DEVICE_INFO_SERVICE_DECODE_H__ + +#include +#include +#include +#include +#include "device_info_service_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if DEFAULT_MAX_QTY != 3 +#error "The type file was generated with a different default_max_qty than this file" +#endif + + +int cbor_decode_device_info_req( + const uint8_t *payload, size_t payload_len, + struct device_info_req *result, + size_t *payload_len_out); + +int cbor_decode_device_info_resp( + const uint8_t *payload, size_t payload_len, + struct device_info_resp *result, + size_t *payload_len_out); + + +#ifdef __cplusplus +} +#endif + +#endif /* DEVICE_INFO_SERVICE_DECODE_H__ */ diff --git a/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.c b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.c new file mode 100644 index 000000000000..209be6152c7a --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/* + * Generated using zcbor version 0.9.0 + * https://github.com/NordicSemiconductor/zcbor + * Generated with a --default-max-qty of 3 + */ + +#include +#include +#include +#include +#include "zcbor_encode.h" +#include "device_info_service_encode.h" +#include "zcbor_print.h" + +#if DEFAULT_MAX_QTY != 3 +#error "The type file was generated with a different default_max_qty than this file" +#endif + +#define log_result(state, result, func) do { \ + if (!result) { \ + zcbor_trace_file(state); \ + zcbor_log("%s error: %s\r\n", func, zcbor_error_str(zcbor_peek_error(state))); \ + } else { \ + zcbor_log("%s success\r\n", func); \ + } \ +} while(0) + +static bool encode_entity(zcbor_state_t *state, const struct entity_r *input); +static bool encode_stat(zcbor_state_t *state, const struct stat_r *input); +static bool encode_read_req(zcbor_state_t *state, const struct read_req *input); +static bool encode_write_req(zcbor_state_t *state, const struct write_req *input); +static bool encode_read_resp(zcbor_state_t *state, const struct read_resp *input); +static bool encode_write_resp(zcbor_state_t *state, const struct write_resp *input); +static bool encode_device_info_req(zcbor_state_t *state, const struct device_info_req *input); +static bool encode_device_info_resp(zcbor_state_t *state, const struct device_info_resp *input); + + +static bool encode_entity( + zcbor_state_t *state, const struct entity_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((*input).entity_choice == entity_UUID_c) ? ((zcbor_uint32_put(state, (0)))) + : (((*input).entity_choice == entity_TYPE_c) ? ((zcbor_uint32_put(state, (1)))) + : (((*input).entity_choice == entity_TESTIMPRINT_c) ? ((zcbor_uint32_put(state, (2)))) + : (((*input).entity_choice == entity_PARTNO_c) ? ((zcbor_uint32_put(state, (3)))) + : (((*input).entity_choice == entity_HWREVISION_c) ? ((zcbor_uint32_put(state, (4)))) + : (((*input).entity_choice == entity_PRODUCTIONREVISION_c) ? ((zcbor_uint32_put(state, (5)))) + : false)))))))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_stat( + zcbor_state_t *state, const struct stat_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((*input).stat_choice == stat_SUCCESS_c) ? ((zcbor_uint32_put(state, (0)))) + : (((*input).stat_choice == stat_INTERNAL_ERROR_c) ? ((zcbor_uint32_put(state, (16781313)))) + : (((*input).stat_choice == stat_UNPROGRAMMED_c) ? ((zcbor_uint32_put(state, (16781314)))) + : false))))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_read_req( + zcbor_state_t *state, const struct read_req *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (1)))) + && ((encode_entity(state, (&(*input).read_req_target))))))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_write_req( + zcbor_state_t *state, const struct write_req *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (2)))) + && ((encode_entity(state, (&(*input).write_req_target)))) + && ((zcbor_list_start_encode(state, 8) && ((zcbor_multi_encode_minmax(1, 8, &(*input).write_req_data_uint_count, (zcbor_encoder_t *)zcbor_uint32_encode, state, (*&(*input).write_req_data_uint), sizeof(uint32_t))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 8)))))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_read_resp( + zcbor_state_t *state, const struct read_resp *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (1)))) + && ((encode_entity(state, (&(*input).read_resp_target)))) + && ((encode_stat(state, (&(*input).read_resp_status)))) + && ((zcbor_list_start_encode(state, 8) && ((zcbor_multi_encode_minmax(1, 8, &(*input).read_resp_data_uint_count, (zcbor_encoder_t *)zcbor_uint32_encode, state, (*&(*input).read_resp_data_uint), sizeof(uint32_t))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 8)))))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_write_resp( + zcbor_state_t *state, const struct write_resp *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (2)))) + && ((encode_entity(state, (&(*input).write_resp_target)))) + && ((encode_stat(state, (&(*input).write_resp_status))))))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_device_info_req( + zcbor_state_t *state, const struct device_info_req *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((zcbor_list_start_encode(state, 4) && ((((zcbor_uint32_put(state, (3)))) + && ((((*input).req_msg_choice == req_msg_read_req_m_c) ? ((encode_read_req(state, (&(*input).req_msg_read_req_m)))) + : (((*input).req_msg_choice == req_msg_write_req_m_c) ? ((encode_write_req(state, (&(*input).req_msg_write_req_m)))) + : false)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 4)))); + + log_result(state, res, __func__); + return res; +} + +static bool encode_device_info_resp( + zcbor_state_t *state, const struct device_info_resp *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((zcbor_list_start_encode(state, 5) && ((((zcbor_uint32_put(state, (3)))) + && ((((*input).resp_msg_choice == resp_msg_read_resp_m_c) ? ((encode_read_resp(state, (&(*input).resp_msg_read_resp_m)))) + : (((*input).resp_msg_choice == resp_msg_write_resp_m_c) ? ((encode_write_resp(state, (&(*input).resp_msg_write_resp_m)))) + : false)))) || (zcbor_list_map_end_force_encode(state), false)) && zcbor_list_end_encode(state, 5)))); + + log_result(state, res, __func__); + return res; +} + + + +int cbor_encode_device_info_req( + uint8_t *payload, size_t payload_len, + const struct device_info_req *input, + size_t *payload_len_out) +{ + zcbor_state_t states[5]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_device_info_req, sizeof(states) / sizeof(zcbor_state_t), 1); +} + + + +int cbor_encode_device_info_resp( + uint8_t *payload, size_t payload_len, + const struct device_info_resp *input, + size_t *payload_len_out) +{ + zcbor_state_t states[5]; + + return zcbor_entry_function(payload, payload_len, (void *)input, payload_len_out, states, + (zcbor_decoder_t *)encode_device_info_resp, sizeof(states) / sizeof(zcbor_state_t), 1); +} diff --git a/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.h b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.h new file mode 100644 index 000000000000..cda4a70156e1 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/* + * Generated using zcbor version 0.9.0 + * https://github.com/NordicSemiconductor/zcbor + * Generated with a --default-max-qty of 3 + */ + +#ifndef DEVICE_INFO_SERVICE_ENCODE_H__ +#define DEVICE_INFO_SERVICE_ENCODE_H__ + +#include +#include +#include +#include +#include "device_info_service_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if DEFAULT_MAX_QTY != 3 +#error "The type file was generated with a different default_max_qty than this file" +#endif + +int cbor_encode_device_info_req( + uint8_t *payload, size_t payload_len, + const struct device_info_req *input, + size_t *payload_len_out); + +int cbor_encode_device_info_resp( + uint8_t *payload, size_t payload_len, + const struct device_info_resp *input, + size_t *payload_len_out); + + +#ifdef __cplusplus +} +#endif + +#endif /* DEVICE_INFO_SERVICE_ENCODE_H__ */ diff --git a/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_types.h b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_types.h new file mode 100644 index 000000000000..8b4ad7a4f6e1 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_types.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ + +/* + * Generated using zcbor version 0.9.0 + * https://github.com/NordicSemiconductor/zcbor + * Generated with a --default-max-qty of 3 + */ + +#ifndef DEVICE_INFO_SERVICE_TYPES_H__ +#define DEVICE_INFO_SERVICE_TYPES_H__ + +#include +#include +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/** Which value for --default-max-qty this file was created with. + * + * The define is used in the other generated file to do a build-time + * compatibility check. + * + * See `zcbor --help` for more information about --default-max-qty + */ +#define DEFAULT_MAX_QTY 3 + +struct entity_r { + enum { + entity_UUID_c = 0, + entity_TYPE_c = 1, + entity_TESTIMPRINT_c = 2, + entity_PARTNO_c = 3, + entity_HWREVISION_c = 4, + entity_PRODUCTIONREVISION_c = 5, + } entity_choice; +}; + +struct stat_r { + enum { + stat_SUCCESS_c = 0, + stat_INTERNAL_ERROR_c = 16781313, + stat_UNPROGRAMMED_c = 16781314, + } stat_choice; +}; + +struct read_req { + struct entity_r read_req_target; +}; + +struct write_req { + struct entity_r write_req_target; + uint32_t write_req_data_uint[8]; + size_t write_req_data_uint_count; +}; + +struct read_resp { + struct entity_r read_resp_target; + struct stat_r read_resp_status; + uint32_t read_resp_data_uint[8]; + size_t read_resp_data_uint_count; +}; + +struct write_resp { + struct entity_r write_resp_target; + struct stat_r write_resp_status; +}; + +struct device_info_req { + union { + struct read_req req_msg_read_req_m; + struct write_req req_msg_write_req_m; + }; + enum { + req_msg_read_req_m_c, + req_msg_write_req_m_c, + } req_msg_choice; +}; + +struct device_info_resp { + union { + struct read_resp resp_msg_read_resp_m; + struct write_resp resp_msg_write_resp_m; + }; + enum { + resp_msg_read_resp_m_c, + resp_msg_write_resp_m_c, + } resp_msg_choice; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* DEVICE_INFO_SERVICE_TYPES_H__ */