Skip to content

Commit

Permalink
Add device information service to secure domain
Browse files Browse the repository at this point in the history
  • Loading branch information
ayla-nordicsemi committed Dec 5, 2024
1 parent 8780ee9 commit 277a4a5
Show file tree
Hide file tree
Showing 13 changed files with 784 additions and 0 deletions.
31 changes: 31 additions & 0 deletions include/sdfw/sdfw_services/device_info_service.h
Original file line number Diff line number Diff line change
@@ -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 <stddef.h>
#include <stdint.h>

#include <sdfw/sdfw_services/ssf_errno.h>

/** .. 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__ */
1 change: 1 addition & 0 deletions subsys/sdfw_services/services/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions subsys/sdfw_services/services/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#

# Services
rsource "device_info/Kconfig"
rsource "echo/Kconfig"
rsource "enc_fw/Kconfig"
rsource "extmem/Kconfig"
Expand Down
12 changes: 12 additions & 0 deletions subsys/sdfw_services/services/device_info/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
13 changes: 13 additions & 0 deletions subsys/sdfw_services/services/device_info/Kconfig
Original file line number Diff line number Diff line change
@@ -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"
85 changes: 85 additions & 0 deletions subsys/sdfw_services/services/device_info/device_info_service.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

/** .. include_startingpoint_device_info_source_rst */
#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include <sdfw/sdfw_services/device_info_service.h>

#include "device_info_service_decode.h"
#include "device_info_service_encode.h"
#include "device_info_service_types.h"
#include <sdfw/sdfw_services/ssf_client.h>
#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);

Check warning on line 48 in subsys/sdfw_services/services/device_info/device_info_service.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

subsys/sdfw_services/services/device_info/device_info_service.c:48 line length of 106 exceeds 100 columns
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) {

Check warning on line 54 in subsys/sdfw_services/services/device_info/device_info_service.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

subsys/sdfw_services/services/device_info/device_info_service.c:54 Missing a blank line after declarations
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;

Check warning on line 56 in subsys/sdfw_services/services/device_info/device_info_service.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

subsys/sdfw_services/services/device_info/device_info_service.c:56 line length of 102 exceeds 100 columns
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));

Check warning on line 74 in subsys/sdfw_services/services/device_info/device_info_service.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

subsys/sdfw_services/services/device_info/device_info_service.c:74 line length of 110 exceeds 100 columns

Check warning on line 74 in subsys/sdfw_services/services/device_info/device_info_service.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LINE_SPACING

subsys/sdfw_services/services/device_info/device_info_service.c:74 Missing a blank line after declarations

ssf_client_decode_done(rsp_pkt);
} else {
/* invalid parameters */
err = -1;

}
return err;
}

/** .. include_endpoint_device_info_source_rst */

Check warning on line 85 in subsys/sdfw_services/services/device_info/device_info_service.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

MISSING_EOF_NEWLINE

subsys/sdfw_services/services/device_info/device_info_service.c:85 adding a line without newline at end of file
63 changes: 63 additions & 0 deletions subsys/sdfw_services/services/device_info/device_info_service.cddl
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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(.)
Loading

0 comments on commit 277a4a5

Please sign in to comment.