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..9a5f9e47c0d7 --- /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..57a9073d46b5 --- /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 device_info_service_read_req uuid_read_req = { + .device_info_service_read_req_target.device_info_target_choice = device_info_target_UUID_c, + }; + + struct device_info_req read_req = { + .device_info_req_msg_choice = device_info_req_msg_device_info_service_read_req_m_c, + .device_info_req_msg_device_info_service_read_req_m = uuid_read_req + }; + + struct device_info_resp read_resp; + + err = ssf_client_send_request(&device_info_srvc, &read_req, &read_resp, &rsp_pkt); + if (err != 0) { + return err; + } + + struct device_info_service_read_resp uuid_read_resp = read_resp.device_info_resp_msg_device_info_service_read_resp_m; + if (read_resp.device_info_resp_msg_choice == device_info_resp_msg_device_info_service_read_resp_m_c) { + if (device_info_target_UUID_c == uuid_read_resp.device_info_service_read_resp_target.device_info_target_choice) { + ret = read_resp.device_info_resp_msg_device_info_service_read_resp_m.device_info_service_read_resp_status.device_info_status_choice; + if (device_info_status_SUCCESS_c != ret) { + ssf_client_decode_done(rsp_pkt); + return ret; + } + } else { + // not a read UUID response + ssf_client_decode_done(rsp_pkt); + return device_info_status_INTERNAL_ERROR_c; + } + + } else { + // not a read response + ssf_client_decode_done(rsp_pkt); + return device_info_status_INTERNAL_ERROR_c; + } + + size_t uuid_words_len = uuid_read_resp.device_info_service_read_resp_data_uint_count; + memcpy(uuid_words, uuid_read_resp.device_info_service_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 */ 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..15fe1b41848f --- /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 + +device_info_status = (SUCCESS: 0) / + (INTERNAL_ERROR: 16781313) / + (UNPROGRAMMED: 16781314) + +device_info_target = (UUID: 0) / + (TYPE: 1) / + (TESTIMPRINT: 2) / + (PARTNO: 3) / + (HWREVISION: 4) / + (PRODUCTIONREVISION: 5) + +; Device Info service request payload. +device_info_service_read_req = ( + 1, + target: device_info_target, +) + +device_info_service_write_req = ( + 2, + target: device_info_target, + data: [1*8 uint] ; table of at least 1 int - at most 8 int +) + +; Device Info service response to read data. +device_info_service_read_resp = ( + 1, + target: device_info_target, + status: device_info_status, + data: [1*8 uint] ; table of at least 1 int - at most 8 int +) + +; Device Info service response to write payload. +device_info_service_write_resp = ( + 2, + target: device_info_target, + status: device_info_status, +) + +device_info_req = [ + 3, + msg: ( + device_info_service_read_req / + device_info_service_write_req + ), +] + +device_info_resp = [ + 3, + msg: ( + device_info_service_read_resp / + device_info_service_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..2d9d880b6f8d --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.c @@ -0,0 +1,196 @@ +/* + * 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_device_info_target(zcbor_state_t *state, struct device_info_target_r *result); +static bool decode_device_info_service_read_req(zcbor_state_t *state, struct device_info_service_read_req *result); +static bool decode_device_info_service_write_req(zcbor_state_t *state, struct device_info_service_write_req *result); +static bool decode_device_info_req(zcbor_state_t *state, struct device_info_req *result); +static bool decode_device_info_status(zcbor_state_t *state, struct device_info_status_r *result); +static bool decode_device_info_service_read_resp(zcbor_state_t *state, struct device_info_service_read_resp *result); +static bool decode_device_info_service_write_resp(zcbor_state_t *state, struct device_info_service_write_resp *result); +static bool decode_device_info_resp(zcbor_state_t *state, struct device_info_resp *result); + + +static bool decode_device_info_target( + zcbor_state_t *state, struct device_info_target_r *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint_decode(state, &(*result).device_info_target_choice, sizeof((*result).device_info_target_choice)))) && ((((((*result).device_info_target_choice == device_info_target_UUID_c) && ((1))) + || (((*result).device_info_target_choice == device_info_target_TYPE_c) && ((1))) + || (((*result).device_info_target_choice == device_info_target_TESTIMPRINT_c) && ((1))) + || (((*result).device_info_target_choice == device_info_target_PARTNO_c) && ((1))) + || (((*result).device_info_target_choice == device_info_target_HWREVISION_c) && ((1))) + || (((*result).device_info_target_choice == device_info_target_PRODUCTIONREVISION_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))); + + log_result(state, res, __func__); + return res; +} + + +static bool decode_device_info_status( + zcbor_state_t *state, struct device_info_status_r *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint_decode(state, &(*result).device_info_status_choice, sizeof((*result).device_info_status_choice)))) && ((((((*result).device_info_status_choice == device_info_status_SUCCESS_c) && ((1))) + || (((*result).device_info_status_choice == device_info_status_INTERNAL_ERROR_c) && ((1))) + || (((*result).device_info_status_choice == device_info_status_UNPROGRAMMED_c) && ((1)))) || (zcbor_error(state, ZCBOR_ERR_WRONG_VALUE), false)))))); + + log_result(state, res, __func__); + return res; +} + + +static bool decode_device_info_service_read_resp( + zcbor_state_t *state, struct device_info_service_read_resp *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (1)))) + && ((decode_device_info_target(state, (&(*result).device_info_service_read_resp_target)))) + && ((decode_device_info_status(state, (&(*result).device_info_service_read_resp_status)))) + && ((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 8, &(*result).device_info_service_read_resp_data_uint_count, (zcbor_decoder_t *)zcbor_uint32_decode, state, (*&(*result).device_info_service_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).device_info_service_read_resp_data_uint)); + } + + log_result(state, res, __func__); + return res; +} + + +static bool decode_device_info_service_write_resp( + zcbor_state_t *state, struct device_info_service_write_resp *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (2)))) + && ((decode_device_info_target(state, (&(*result).device_info_service_write_resp_target)))) + && ((decode_device_info_status(state, (&(*result).device_info_service_write_resp_status))))))); + + 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_device_info_service_read_resp(state, (&(*result).device_info_resp_msg_device_info_service_read_resp_m)))) && (((*result).device_info_resp_msg_choice = device_info_resp_msg_device_info_service_read_resp_m_c), true)) + || (zcbor_union_elem_code(state) && (((decode_device_info_service_write_resp(state, (&(*result).device_info_resp_msg_device_info_service_write_resp_m)))) && (((*result).device_info_resp_msg_choice = device_info_resp_msg_device_info_service_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_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); +} + + +static bool decode_device_info_service_read_req( + zcbor_state_t *state, struct device_info_service_read_req *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (1)))) + && ((decode_device_info_target(state, (&(*result).device_info_service_read_req_target))))))); + + log_result(state, res, __func__); + return res; +} + + +static bool decode_device_info_service_write_req( + zcbor_state_t *state, struct device_info_service_write_req *result) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_expect(state, (2)))) + && ((decode_device_info_target(state, (&(*result).device_info_service_write_req_target)))) + && ((zcbor_list_start_decode(state) && ((zcbor_multi_decode(1, 8, &(*result).device_info_service_write_req_data_uint_count, (zcbor_decoder_t *)zcbor_uint32_decode, state, (*&(*result).device_info_service_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).device_info_service_write_req_data_uint)); + } + + 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_device_info_service_read_req(state, (&(*result).device_info_req_msg_device_info_service_read_req_m)))) && (((*result).device_info_req_msg_choice = device_info_req_msg_device_info_service_read_req_m_c), true)) + || (zcbor_union_elem_code(state) && (((decode_device_info_service_write_req(state, (&(*result).device_info_req_msg_device_info_service_write_req_m)))) && (((*result).device_info_req_msg_choice = device_info_req_msg_device_info_service_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; +} + + +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); +} 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..42775242f0a6 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_decode.h @@ -0,0 +1,44 @@ +/* + * 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..e50b5e86b10b --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_encode.c @@ -0,0 +1,185 @@ +/* + * 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_device_info_target(zcbor_state_t *state, const struct device_info_target_r *input); +static bool encode_device_info_service_read_req(zcbor_state_t *state, const struct device_info_service_read_req *input); +static bool encode_device_info_service_write_req(zcbor_state_t *state, const struct device_info_service_write_req *input); +static bool encode_device_info_req(zcbor_state_t *state, const struct device_info_req *input); +static bool encode_device_info_status(zcbor_state_t *state, const struct device_info_status_r *input); +static bool encode_device_info_service_read_resp(zcbor_state_t *state, const struct device_info_service_read_resp *input); +static bool encode_device_info_service_write_resp(zcbor_state_t *state, const struct device_info_service_write_resp *input); +static bool encode_device_info_resp(zcbor_state_t *state, const struct device_info_resp *input); + + +static bool encode_device_info_target( + zcbor_state_t *state, const struct device_info_target_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((*input).device_info_target_choice == device_info_target_UUID_c) ? ((zcbor_uint32_put(state, (0)))) + : (((*input).device_info_target_choice == device_info_target_TYPE_c) ? ((zcbor_uint32_put(state, (1)))) + : (((*input).device_info_target_choice == device_info_target_TESTIMPRINT_c) ? ((zcbor_uint32_put(state, (2)))) + : (((*input).device_info_target_choice == device_info_target_PARTNO_c) ? ((zcbor_uint32_put(state, (3)))) + : (((*input).device_info_target_choice == device_info_target_HWREVISION_c) ? ((zcbor_uint32_put(state, (4)))) + : (((*input).device_info_target_choice == device_info_target_PRODUCTIONREVISION_c) ? ((zcbor_uint32_put(state, (5)))) + : false)))))))); + + log_result(state, res, __func__); + return res; +} + + +static bool encode_device_info_status( + zcbor_state_t *state, const struct device_info_status_r *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((*input).device_info_status_choice == device_info_status_SUCCESS_c) ? ((zcbor_uint32_put(state, (0)))) + : (((*input).device_info_status_choice == device_info_status_INTERNAL_ERROR_c) ? ((zcbor_uint32_put(state, (16781313)))) + : (((*input).device_info_status_choice == device_info_status_UNPROGRAMMED_c) ? ((zcbor_uint32_put(state, (16781314)))) + : false))))); + + log_result(state, res, __func__); + return res; +} + + +static bool encode_device_info_service_read_resp( + zcbor_state_t *state, const struct device_info_service_read_resp *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (1)))) + && ((encode_device_info_target(state, (&(*input).device_info_service_read_resp_target)))) + && ((encode_device_info_status(state, (&(*input).device_info_service_read_resp_status)))) + && ((zcbor_list_start_encode(state, 8) && ((zcbor_multi_encode_minmax(1, 8, &(*input).device_info_service_read_resp_data_uint_count, (zcbor_encoder_t *)zcbor_uint32_encode, state, (*&(*input).device_info_service_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_device_info_service_write_resp( + zcbor_state_t *state, const struct device_info_service_write_resp *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (2)))) + && ((encode_device_info_target(state, (&(*input).device_info_service_write_resp_target)))) + && ((encode_device_info_status(state, (&(*input).device_info_service_write_resp_status))))))); + + 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).device_info_resp_msg_choice == device_info_resp_msg_device_info_service_read_resp_m_c) ? ((encode_device_info_service_read_resp(state, (&(*input).device_info_resp_msg_device_info_service_read_resp_m)))) + : (((*input).device_info_resp_msg_choice == device_info_resp_msg_device_info_service_write_resp_m_c) ? ((encode_device_info_service_write_resp(state, (&(*input).device_info_resp_msg_device_info_service_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_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); +} + + +static bool encode_device_info_service_read_req( + zcbor_state_t *state, const struct device_info_service_read_req *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (1)))) + && ((encode_device_info_target(state, (&(*input).device_info_service_read_req_target))))))); + + log_result(state, res, __func__); + return res; +} + + +static bool encode_device_info_service_write_req( + zcbor_state_t *state, const struct device_info_service_write_req *input) +{ + zcbor_log("%s\r\n", __func__); + + bool res = (((((zcbor_uint32_put(state, (2)))) + && ((encode_device_info_target(state, (&(*input).device_info_service_write_req_target)))) + && ((zcbor_list_start_encode(state, 8) && ((zcbor_multi_encode_minmax(1, 8, &(*input).device_info_service_write_req_data_uint_count, (zcbor_encoder_t *)zcbor_uint32_encode, state, (*&(*input).device_info_service_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_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).device_info_req_msg_choice == device_info_req_msg_device_info_service_read_req_m_c) ? ((encode_device_info_service_read_req(state, (&(*input).device_info_req_msg_device_info_service_read_req_m)))) + : (((*input).device_info_req_msg_choice == device_info_req_msg_device_info_service_write_req_m_c) ? ((encode_device_info_service_write_req(state, (&(*input).device_info_req_msg_device_info_service_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; +} + + +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); +} 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..8df85214bcd9 --- /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_resp( + uint8_t *payload, size_t payload_len, + const struct device_info_resp *input, + size_t *payload_len_out); + +int cbor_encode_device_info_req( + uint8_t *payload, size_t payload_len, + const struct device_info_req *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..888e608b90c4 --- /dev/null +++ b/subsys/sdfw_services/services/device_info/zcbor_generated/device_info_service_types.h @@ -0,0 +1,102 @@ +/* + * 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 device_info_target_r { + enum { + device_info_target_UUID_c = 0, + device_info_target_TYPE_c = 1, + device_info_target_TESTIMPRINT_c = 2, + device_info_target_PARTNO_c = 3, + device_info_target_HWREVISION_c = 4, + device_info_target_PRODUCTIONREVISION_c = 5, + } device_info_target_choice; +}; + +struct device_info_status_r { + enum { + device_info_status_SUCCESS_c = 0, + device_info_status_INTERNAL_ERROR_c = 16781313, + device_info_status_UNPROGRAMMED_c = 16781314, + } device_info_status_choice; +}; + + +struct device_info_service_read_req { + struct device_info_target_r device_info_service_read_req_target; +}; + +struct device_info_service_read_resp { + struct device_info_target_r device_info_service_read_resp_target; + struct device_info_status_r device_info_service_read_resp_status; + uint32_t device_info_service_read_resp_data_uint[8]; + size_t device_info_service_read_resp_data_uint_count; +}; + +struct device_info_service_write_req { + struct device_info_target_r device_info_service_write_req_target; + uint32_t device_info_service_write_req_data_uint[8]; + size_t device_info_service_write_req_data_uint_count; +}; + +struct device_info_service_write_resp { + struct device_info_target_r device_info_service_write_resp_target; + struct device_info_status_r device_info_service_write_resp_status; +}; + +struct device_info_req { + union { + struct device_info_service_read_req device_info_req_msg_device_info_service_read_req_m; + struct device_info_service_write_req device_info_req_msg_device_info_service_write_req_m; + }; + enum { + device_info_req_msg_device_info_service_read_req_m_c, + device_info_req_msg_device_info_service_write_req_m_c, + } device_info_req_msg_choice; +}; + +struct device_info_resp { + union { + struct device_info_service_read_resp device_info_resp_msg_device_info_service_read_resp_m; + struct device_info_service_write_resp device_info_resp_msg_device_info_service_write_resp_m; + }; + enum { + device_info_resp_msg_device_info_service_read_resp_m_c, + device_info_resp_msg_device_info_service_write_resp_m_c, + } device_info_resp_msg_choice; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* DEVICE_INFO_SERVICE_TYPES_H__ */