|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <stddef.h> |
| 8 | +#include <stdint.h> |
| 9 | +#include <string.h> |
| 10 | + |
| 11 | +#include <sdfw/sdfw_services/device_info_service.h> |
| 12 | + |
| 13 | +#include "device_info_service_decode.h" |
| 14 | +#include "device_info_service_encode.h" |
| 15 | +#include "device_info_service_types.h" |
| 16 | +#include <sdfw/sdfw_services/ssf_client.h> |
| 17 | +#include <sdfw/sdfw_services/ssf_errno.h> |
| 18 | +#include "ssf_client_os.h" |
| 19 | + |
| 20 | +/* Not exposed in header because not used by interface */ |
| 21 | +#define TESTIMPRINT_BYTES_LENGTH 32UL |
| 22 | + |
| 23 | +SSF_CLIENT_SERVICE_DEFINE(device_info_srvc, DEVICE_INFO, cbor_encode_device_info_req, |
| 24 | + cbor_decode_device_info_resp); |
| 25 | + |
| 26 | +static int get_device_info_data(struct device_info *device_info_data) |
| 27 | +{ |
| 28 | + int ret = -SSF_ENODATA; |
| 29 | + |
| 30 | + if (device_info_data != NULL) { |
| 31 | + const uint8_t *rsp_pkt; |
| 32 | + |
| 33 | + int stat = stat_INTERNAL_ERROR_c; |
| 34 | + |
| 35 | + struct device_info_req device_info_request = { |
| 36 | + .device_info_req_msg.read_req_action.operation_choice = |
| 37 | + operation_READ_DEVICE_INFO_c, |
| 38 | + }; |
| 39 | + |
| 40 | + struct device_info_resp device_info_response; |
| 41 | + |
| 42 | + ret = ssf_client_send_request(&device_info_srvc, &device_info_request, |
| 43 | + &device_info_response, &rsp_pkt); |
| 44 | + if (ret == 0) { |
| 45 | + if (device_info_response.device_info_resp_msg.read_resp_action |
| 46 | + .operation_choice == operation_READ_DEVICE_INFO_c) { |
| 47 | + stat = device_info_response.device_info_resp_msg.read_resp_status |
| 48 | + .stat_choice; |
| 49 | + if (stat == stat_SUCCESS_c) { |
| 50 | + |
| 51 | + /* copy device info data to provided struction */ |
| 52 | + device_info_data->device_info_partno = |
| 53 | + device_info_response.device_info_resp_msg |
| 54 | + .read_resp_data.device_info_partno; |
| 55 | + |
| 56 | + device_info_data->device_info_type = |
| 57 | + device_info_response.device_info_resp_msg |
| 58 | + .read_resp_data.device_info_type; |
| 59 | + |
| 60 | + device_info_data->device_info_hwrevision = |
| 61 | + device_info_response.device_info_resp_msg |
| 62 | + .read_resp_data.device_info_hwrevision; |
| 63 | + |
| 64 | + device_info_data->device_info_productionrevision = |
| 65 | + device_info_response.device_info_resp_msg |
| 66 | + .read_resp_data |
| 67 | + .device_info_productionrevision; |
| 68 | + |
| 69 | + memcpy((uint8_t *)(device_info_data->device_info_testimprint |
| 70 | + .value), |
| 71 | + (uint8_t *)(device_info_response.device_info_resp_msg |
| 72 | + .read_resp_data |
| 73 | + .device_info_testimprint.value), |
| 74 | + device_info_response.device_info_resp_msg |
| 75 | + .read_resp_data.device_info_testimprint.len); |
| 76 | + |
| 77 | + device_info_data->device_info_testimprint.len = |
| 78 | + device_info_response.device_info_resp_msg |
| 79 | + .read_resp_data.device_info_testimprint.len; |
| 80 | + |
| 81 | + memcpy((uint8_t *)(device_info_data->device_info_uuid |
| 82 | + .value), |
| 83 | + (uint8_t *)(device_info_response.device_info_resp_msg |
| 84 | + .read_resp_data.device_info_uuid |
| 85 | + .value), |
| 86 | + device_info_response.device_info_resp_msg |
| 87 | + .read_resp_data.device_info_uuid.len); |
| 88 | + |
| 89 | + device_info_data->device_info_uuid.len = |
| 90 | + device_info_response.device_info_resp_msg |
| 91 | + .read_resp_data.device_info_uuid.len; |
| 92 | + |
| 93 | + /* operation is successful */ |
| 94 | + ret = 0; |
| 95 | + } else { |
| 96 | + /* operation failed on server side */ |
| 97 | + ret = -SSF_EPROTO; |
| 98 | + } |
| 99 | + } else { |
| 100 | + /* the received response message is not a read device info response |
| 101 | + */ |
| 102 | + ret = -SSF_EBADMSG; |
| 103 | + } |
| 104 | + |
| 105 | + /* at least a response message was received, free response packet buffer */ |
| 106 | + ssf_client_decode_done(rsp_pkt); |
| 107 | + } else { |
| 108 | + /* ssf error, no response received, no need to free response packet */ |
| 109 | + /* return value will be returned by ssf_client_send_request call */ |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + return ret; |
| 114 | +} |
| 115 | + |
| 116 | +int ssf_device_info_get_uuid(uint8_t *uuid_buff) |
| 117 | +{ |
| 118 | + int err = -SSF_ENODATA; |
| 119 | + |
| 120 | + if (NULL != uuid_buff) { |
| 121 | + |
| 122 | + uint8_t testimprint_bytes[TESTIMPRINT_BYTES_LENGTH] = {0}; |
| 123 | + |
| 124 | + struct device_info device_info_data = { |
| 125 | + .device_info_partno = 0, |
| 126 | + .device_info_type = 0, |
| 127 | + .device_info_hwrevision = 0, |
| 128 | + .device_info_productionrevision = 0, |
| 129 | + .device_info_testimprint.value = testimprint_bytes, |
| 130 | + .device_info_testimprint.len = TESTIMPRINT_BYTES_LENGTH, |
| 131 | + /* caller provided buffer for UUID value */ |
| 132 | + .device_info_uuid.value = uuid_buff, |
| 133 | + .device_info_uuid.len = UUID_BYTES_LENGTH, |
| 134 | + }; |
| 135 | + |
| 136 | + err = get_device_info_data(&device_info_data); |
| 137 | + } else { |
| 138 | + err = -SSF_ENOBUFS; |
| 139 | + } |
| 140 | + |
| 141 | + return err; |
| 142 | +} |
0 commit comments