Skip to content
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

Conversation

ayla-nordicsemi
Copy link
Contributor

Enable reading device information (UUID for instance) as a service requested by a client and executed by the secure domain.

@CLAassistant
Copy link

CLAassistant commented Dec 5, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Dec 5, 2024
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Dec 5, 2024

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 27

Inputs:

Sources:

sdk-nrf: PR head: 5f25abc9c0584ead37b7f90d470ddc050f2c3003

more details

sdk-nrf:

PR head: 5f25abc9c0584ead37b7f90d470ddc050f2c3003
merge base: 46924418b10722a4c4084220151f16b6ca72e3df
target head (main): 4989dd10e20f684616dda81e4b9bb41bea81154c
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (13)
include
│  ├── sdfw
│  │  ├── sdfw_services
│  │  │  │ device_info_service.h
subsys
│  ├── sdfw_services
│  │  ├── services
│  │  │  ├── CMakeLists.txt
│  │  │  ├── Kconfig
│  │  │  ├── device_info
│  │  │  │  ├── CMakeLists.txt
│  │  │  │  ├── Kconfig
│  │  │  │  ├── device_info_service.c
│  │  │  │  ├── device_info_service.cddl
│  │  │  │  ├── zcbor_generated
│  │  │  │  │  ├── CMakeLists.txt
│  │  │  │  │  ├── device_info_service_decode.c
│  │  │  │  │  ├── device_info_service_decode.h
│  │  │  │  │  ├── device_info_service_encode.c
│  │  │  │  │  ├── device_info_service_encode.h
│  │  │  │  │  │ device_info_service_types.h

Outputs:

Toolchain

Version: b77d8c1312
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:b77d8c1312_912848a074

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 141
  • ✅ Integration tests
    • ✅ test-sdk-dfu
    • ⚠️ test-sdk-dfu
Disabled integration tests
    • desktop52_verification
    • doc-internal
    • test_ble_nrf_config
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-boot
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_mosh
    • test-fw-nrfconnect-nrf-iot_nrf_provisioning
    • test-fw-nrfconnect-nrf-iot_positioning
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-ps
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread
    • test-fw-nrfconnect-zigbee
    • test-low-level
    • test-sdk-audio
    • test-sdk-find-my
    • test-sdk-mcuboot
    • test-sdk-pmic-samples
    • test-sdk-sidewalk
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

@NordicBuilder
Copy link
Contributor

You can find the documentation preview for this PR at this link. It will be updated about 10 minutes after the documentation build succeeds.

Note: This comment is automatically posted by the Documentation Publish GitHub Action.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch from a232655 to 277a4a5 Compare December 5, 2024 14:35
{
int err = -1; /* initialize with negative value for error */

if ((NULL != uuid_words) && (uuid_words_count >= UUID_BYTES_LENGTH)) {
Copy link

@parttimaa parttimaa Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some reason for having the bigger than or equal >= instead of equals ==?` I'd assume UUID is always fixed in length.

Copy link
Contributor Author

@ayla-nordicsemi ayla-nordicsemi Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the read buffer and its size are provided by the user, it is okay to provide bigger than necessary buffer. In any case, the API will ALWAYS copy only 16 bytes to the output since, as you mentioned, the UUID has a fixed size.

Copy link
Contributor

@jonathannilsen jonathannilsen Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess uuid_words_count could also be omitted from the API then, since the length is known and fixed? Maybe it would be better to define a struct with a fixed length array member? For example:

struct ssf_device_info_uuid {
    uint8_t value[UUID_BYTES_LENGTH];
};

int ssf_device_info_get_uuid(struct ssf_device_info_uuid *uuid);

Or if you agree with my suggestion below (#19278 (comment)) of combining all the device info reads into one request, you could make a single struct for this, for example

struct ssf_device_info {
    uint8_t uuid[16];
    uint32_t type;
    uint8_t testimprint[32];
    uint32_t partno;
    uint32_t hwrevision;
    uint32_t productionrevision;
};

int ssf_device_info_get(struct ssf_device_info *info);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, I've reworked the generated files and the service API.
now the device info handler on the secure side returns all the OICR register content at once in the device_info structure, the device_info.h header offers an API that assumes the uuid_buffer size to be 16 bytes.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch 3 times, most recently from cba6b88 to b2f5472 Compare December 10, 2024 07:23
Comment on lines 50 to 75
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) {
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;
if (stat_SUCCESS_c != ret) {
ssf_client_decode_done(rsp_pkt);
return ret;
}
} else {
/* the received response message is not a read UUID response */
ssf_client_decode_done(rsp_pkt);
return stat_INTERNAL_ERROR_c;
}

} else {
/* the received response message is 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare variables at top of functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch 4 times, most recently from 0c03ce0 to fc6e850 Compare December 10, 2024 12:47
{
int err = -1; /* initialize with negative value for error */

if ((NULL != uuid_words) && (uuid_words_count >= UUID_BYTES_LENGTH)) {
Copy link
Contributor

@jonathannilsen jonathannilsen Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess uuid_words_count could also be omitted from the API then, since the length is known and fixed? Maybe it would be better to define a struct with a fixed length array member? For example:

struct ssf_device_info_uuid {
    uint8_t value[UUID_BYTES_LENGTH];
};

int ssf_device_info_get_uuid(struct ssf_device_info_uuid *uuid);

Or if you agree with my suggestion below (#19278 (comment)) of combining all the device info reads into one request, you could make a single struct for this, for example

struct ssf_device_info {
    uint8_t uuid[16];
    uint32_t type;
    uint8_t testimprint[32];
    uint32_t partno;
    uint32_t hwrevision;
    uint32_t productionrevision;
};

int ssf_device_info_get(struct ssf_device_info *info);

Comment on lines 32 to 38
; 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
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I think it would be preferable if each of the returned data types had a well defined type in this schema. Currently the length of the responses is not enforced by the protocol, and the lengths are not actually defined anywhere except for in a macro internal to device_info_service.c.

Unless there is a good reason to read/write the individual parts of the data you could consider combining them in a single request - that might help keep the client code size low as well as reduce the IPC overhead if you need to request multiple of these in a row. I think that would be pretty reasonable since the full data would be 64 bytes total. For example:

device_info = [
    uuid: bstr .size 16,
    type: uint,
    testimprint: bstr .size 32,
    partno: uint,
    hwrevision: uint,
    productionrevision: uint,
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for suggesting this !
it required some dipper changes to the handler / service files but it is now done.

@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch from fc6e850 to c966f97 Compare December 12, 2024 16:06
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch 2 times, most recently from ff27f4f to a0bd0b8 Compare December 13, 2024 10:55
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch 5 times, most recently from 735715c to 4e38232 Compare December 16, 2024 11:01
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch from 4e38232 to 0af7815 Compare December 18, 2024 12:04
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch 3 times, most recently from 6a00573 to 809e4a6 Compare December 18, 2024 14:54
@ayla-nordicsemi ayla-nordicsemi force-pushed the add_device_info_service_to_secure_domain branch from 809e4a6 to 5f25abc Compare December 19, 2024 11:13
.read_resp_data
.device_info_productionrevision;

memcpy((uint8_t *)(device_info_data->device_info_testimprint

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.

@nordicjm nordicjm merged commit 37fba0b into nrfconnect:main Dec 20, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants