-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subsys: sdfw services: add device information service. #19278
Merged
nordicjm
merged 1 commit into
nrfconnect:main
from
ayla-nordicsemi:add_device_info_service_to_secure_domain
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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> | ||
|
||
#define UUID_BYTES_LENGTH 16UL | ||
|
||
/** | ||
* @brief Read UUID value. | ||
* | ||
* @note UUID byte order is the same as read from the memory | ||
* and no endianness swapping is performed. | ||
* | ||
* @param[out] uuid_buff Local buffer for copying the UUID into. | ||
* use defined UUID_BYTES_LENGTH to specify its size. | ||
* | ||
* @return 0 on success, otherwise a negative errno defined in ssf_errno.h. | ||
* -SSF_ENOBUFS if invalid buffer. | ||
* -SSF_EPROTO if server code resulted in an error. | ||
* -SSF_EBADMSG if client received a bad response. | ||
*/ | ||
int ssf_device_info_get_uuid(uint8_t *uuid_buff); | ||
|
||
#endif /* DEVICE_INFO_SERVICE_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
142 changes: 142 additions & 0 deletions
142
subsys/sdfw_services/services/device_info/device_info_service.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright (c) 2024 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#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 <sdfw/sdfw_services/ssf_errno.h> | ||
#include "ssf_client_os.h" | ||
|
||
/* Not exposed in header because not used by interface */ | ||
#define TESTIMPRINT_BYTES_LENGTH 32UL | ||
|
||
SSF_CLIENT_SERVICE_DEFINE(device_info_srvc, DEVICE_INFO, cbor_encode_device_info_req, | ||
cbor_decode_device_info_resp); | ||
|
||
static int get_device_info_data(struct device_info *device_info_data) | ||
{ | ||
int ret = -SSF_ENODATA; | ||
|
||
if (device_info_data != NULL) { | ||
const uint8_t *rsp_pkt; | ||
|
||
int stat = stat_INTERNAL_ERROR_c; | ||
|
||
struct device_info_req device_info_request = { | ||
.device_info_req_msg.read_req_action.operation_choice = | ||
operation_READ_DEVICE_INFO_c, | ||
}; | ||
|
||
struct device_info_resp device_info_response; | ||
|
||
ret = ssf_client_send_request(&device_info_srvc, &device_info_request, | ||
&device_info_response, &rsp_pkt); | ||
if (ret == 0) { | ||
if (device_info_response.device_info_resp_msg.read_resp_action | ||
.operation_choice == operation_READ_DEVICE_INFO_c) { | ||
stat = device_info_response.device_info_resp_msg.read_resp_status | ||
.stat_choice; | ||
if (stat == stat_SUCCESS_c) { | ||
|
||
/* copy device info data to provided struction */ | ||
device_info_data->device_info_partno = | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_partno; | ||
|
||
device_info_data->device_info_type = | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_type; | ||
|
||
device_info_data->device_info_hwrevision = | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_hwrevision; | ||
|
||
device_info_data->device_info_productionrevision = | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data | ||
.device_info_productionrevision; | ||
|
||
memcpy((uint8_t *)(device_info_data->device_info_testimprint | ||
.value), | ||
(uint8_t *)(device_info_response.device_info_resp_msg | ||
.read_resp_data | ||
.device_info_testimprint.value), | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_testimprint.len); | ||
|
||
device_info_data->device_info_testimprint.len = | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_testimprint.len; | ||
|
||
memcpy((uint8_t *)(device_info_data->device_info_uuid | ||
.value), | ||
(uint8_t *)(device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_uuid | ||
.value), | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_uuid.len); | ||
|
||
device_info_data->device_info_uuid.len = | ||
device_info_response.device_info_resp_msg | ||
.read_resp_data.device_info_uuid.len; | ||
|
||
/* operation is successful */ | ||
ret = 0; | ||
} else { | ||
/* operation failed on server side */ | ||
ret = -SSF_EPROTO; | ||
} | ||
} else { | ||
/* the received response message is not a read device info response | ||
*/ | ||
ret = -SSF_EBADMSG; | ||
} | ||
|
||
/* at least a response message was received, free response packet buffer */ | ||
ssf_client_decode_done(rsp_pkt); | ||
anhmolt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
/* ssf error, no response received, no need to free response packet */ | ||
/* return value will be returned by ssf_client_send_request call */ | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
int ssf_device_info_get_uuid(uint8_t *uuid_buff) | ||
{ | ||
int err = -SSF_ENODATA; | ||
|
||
if (NULL != uuid_buff) { | ||
|
||
uint8_t testimprint_bytes[TESTIMPRINT_BYTES_LENGTH] = {0}; | ||
|
||
struct device_info device_info_data = { | ||
.device_info_partno = 0, | ||
.device_info_type = 0, | ||
.device_info_hwrevision = 0, | ||
.device_info_productionrevision = 0, | ||
.device_info_testimprint.value = testimprint_bytes, | ||
.device_info_testimprint.len = TESTIMPRINT_BYTES_LENGTH, | ||
/* caller provided buffer for UUID value */ | ||
.device_info_uuid.value = uuid_buff, | ||
.device_info_uuid.len = UUID_BYTES_LENGTH, | ||
}; | ||
|
||
err = get_device_info_data(&device_info_data); | ||
} else { | ||
err = -SSF_ENOBUFS; | ||
} | ||
|
||
return err; | ||
} |
52 changes: 52 additions & 0 deletions
52
subsys/sdfw_services/services/device_info/device_info_service.cddl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
; | ||
; 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) | ||
|
||
operation = (READ_DEVICE_INFO: 0) / | ||
(UNSUPPORTED: 1) | ||
|
||
device_info = [ | ||
uuid: bstr .size 16, | ||
type: uint, | ||
testimprint: bstr .size 32, | ||
partno: uint, | ||
hwrevision: uint, | ||
productionrevision: uint, | ||
] | ||
|
||
read_req = ( | ||
1, | ||
action: operation, | ||
) | ||
|
||
; Device Info service response to read data. | ||
read_resp = ( | ||
1, | ||
action: operation, | ||
status: stat, | ||
data: device_info, | ||
) | ||
|
||
device_info_req = [ | ||
2, | ||
msg: ( | ||
read_req | ||
), | ||
] | ||
|
||
device_info_resp = [ | ||
2, | ||
msg: ( | ||
read_resp | ||
), | ||
] | ||
|
||
; .. include_endingpoint_device_info_cddl_rst |
16 changes: 16 additions & 0 deletions
16
subsys/sdfw_services/services/device_info/zcbor_generated/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(.) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we need to cast to u8 pointers as the C standard function API has them as void pointers?
Memcpy function call returns void pointer, so the return value could be explicitly casted to void to show the intent of programmer.
https://en.cppreference.com/w/c/string/byte/memcpy
But nevertheless this code probably works as is. Might be something that static code analysis would nag about.