-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subsys, sdfw_services: add device information service handler
Ref: NRFX-6558 Signed-off-by: Aymen LAOUINI <[email protected]>
- Loading branch information
1 parent
568a7d4
commit c966f97
Showing
13 changed files
with
730 additions
and
0 deletions.
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,35 @@ | ||
/* | ||
* 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 <errno.h> | ||
|
||
#include <sdfw/sdfw_services/ssf_errno.h> | ||
|
||
#define UUID_BYTES_LENGTH 16UL | ||
|
||
/** .. 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_buff Local buffer for copying the UUID into. | ||
* @param[out] uuid_buff_size UUID buffer size, use defined UUID_BYTES_LENGTH | ||
* to specify its size. | ||
* | ||
* @return 0 on success, otherwise a negative errno. | ||
*/ | ||
int ssf_device_info_get_uuid(uint8_t* uuid_buff, const size_t uuid_buff_size); | ||
|
||
/** .. include_endpoint_device_info_header_rst */ | ||
|
||
#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" |
104 changes: 104 additions & 0 deletions
104
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,104 @@ | ||
/* | ||
* 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 <errno.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" | ||
|
||
/* Not exposed in header because not used by interface */ | ||
#define TESTIMPRINT_BYTES_LENGTH 32UL | ||
|
||
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(uint8_t *uuid_buff, const size_t uuid_buff_size) | ||
{ | ||
int err = -ENODATA; | ||
if ((NULL != uuid_buff) && (uuid_buff_size >= UUID_BYTES_LENGTH)) { | ||
Check warning on line 32 in subsys/sdfw_services/services/device_info/device_info_service.c GitHub Actions / Run compliance checks on patch series (PR)LINE_SPACING
|
||
int ret = -ENODATA; | ||
const uint8_t *rsp_pkt; | ||
|
||
struct device_info_req device_info_request = { | ||
.device_info_req_msg.read_req_action.operation_choice = | ||
operation_READ_DEVICE_INFO_c, | ||
}; | ||
|
||
uint8_t uuid_bytes[UUID_BYTES_LENGTH] = {0}; | ||
uint8_t testimprint_bytes[TESTIMPRINT_BYTES_LENGTH] = {0}; | ||
|
||
struct read_resp response_message = { | ||
.read_resp_action.operation_choice = operation_UNSUPPORTED_c, | ||
.read_resp_status.stat_choice = stat_UNPROGRAMMED_c, | ||
.read_resp_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, | ||
.device_info_uuid.value = uuid_bytes, | ||
.device_info_uuid.len = UUID_BYTES_LENGTH, | ||
}}; | ||
|
||
struct device_info_resp device_info_response = { | ||
.device_info_resp_msg = response_message, | ||
}; | ||
|
||
err = ssf_client_send_request(&device_info_srvc, &device_info_request, | ||
&device_info_response, &rsp_pkt); | ||
if (err != 0) { | ||
/* return ssf error value */ | ||
return err; | ||
} | ||
|
||
if (device_info_response.device_info_resp_msg.read_resp_action.operation_choice == | ||
operation_READ_DEVICE_INFO_c) { | ||
ret = device_info_response.device_info_resp_msg.read_resp_status | ||
.stat_choice; | ||
if (ret == stat_SUCCESS_c) { | ||
|
||
if (device_info_response.device_info_resp_msg.read_resp_data | ||
.device_info_uuid.len == UUID_BYTES_LENGTH) { | ||
memcpy(uuid_buff, | ||
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); | ||
} else { | ||
/* message has the wrong size */ | ||
ssf_client_decode_done(rsp_pkt); | ||
return -EMSGSIZE; | ||
} | ||
} else { | ||
/* operation failed on server side */ | ||
ssf_client_decode_done(rsp_pkt); | ||
return -EPROTO; | ||
} | ||
} else { | ||
/* the received response message is not a read device info response */ | ||
ssf_client_decode_done(rsp_pkt); | ||
return -EBADMSG; | ||
} | ||
|
||
ssf_client_decode_done(rsp_pkt); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
/** .. include_endpoint_device_info_source_rst */ |
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.