Skip to content

Commit 37fba0b

Browse files
ayla-nordicseminordicjm
authored andcommitted
subsys, sdfw_services: add device information service handler
Ref: NRFX-6558 Signed-off-by: Aymen LAOUINI <[email protected]>
1 parent 8636c68 commit 37fba0b

File tree

13 files changed

+766
-0
lines changed

13 files changed

+766
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef DEVICE_INFO_SERVICE_H__
8+
#define DEVICE_INFO_SERVICE_H__
9+
10+
#include <stddef.h>
11+
#include <stdint.h>
12+
13+
#include <sdfw/sdfw_services/ssf_errno.h>
14+
15+
#define UUID_BYTES_LENGTH 16UL
16+
17+
/**
18+
* @brief Read UUID value.
19+
*
20+
* @note UUID byte order is the same as read from the memory
21+
* and no endianness swapping is performed.
22+
*
23+
* @param[out] uuid_buff Local buffer for copying the UUID into.
24+
* use defined UUID_BYTES_LENGTH to specify its size.
25+
*
26+
* @return 0 on success, otherwise a negative errno defined in ssf_errno.h.
27+
* -SSF_ENOBUFS if invalid buffer.
28+
* -SSF_EPROTO if server code resulted in an error.
29+
* -SSF_EBADMSG if client received a bad response.
30+
*/
31+
int ssf_device_info_get_uuid(uint8_t *uuid_buff);
32+
33+
#endif /* DEVICE_INFO_SERVICE_H__ */

subsys/sdfw_services/services/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66

77
# Services
8+
add_subdirectory_ifdef(CONFIG_SSF_DEVICE_INFO_SERVICE_ENABLED device_info)
89
add_subdirectory_ifdef(CONFIG_SSF_ECHO_SERVICE_ENABLED echo)
910
add_subdirectory_ifdef(CONFIG_SSF_ENC_FW_SERVICE_ENABLED enc_fw)
1011
add_subdirectory_ifdef(CONFIG_SSF_EXTMEM_SERVICE_ENABLED extmem)

subsys/sdfw_services/services/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#
66

77
# Services
8+
rsource "device_info/Kconfig"
89
rsource "echo/Kconfig"
910
rsource "enc_fw/Kconfig"
1011
rsource "extmem/Kconfig"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
zephyr_sources(device_info_service.c)
8+
9+
generate_and_add_cbor_files(device_info_service.cddl zcbor_generated
10+
device_info_service_req
11+
device_info_service_rsp
12+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
service_name = DEVICE_INFO
8+
service_default_enabled = y
9+
service_id = 0x78
10+
service_version = 1
11+
service_buffer_size = 128
12+
service_name_str = Device Info
13+
rsource "../Kconfig.template.service"
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
;
2+
; Copyright (c) 2024 Nordic Semiconductor ASA
3+
;
4+
; SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
;
6+
7+
; .. include_startingpoint_device_info_cddl_rst
8+
9+
stat = (SUCCESS: 0) /
10+
(INTERNAL_ERROR: 16781313) /
11+
(UNPROGRAMMED: 16781314)
12+
13+
operation = (READ_DEVICE_INFO: 0) /
14+
(UNSUPPORTED: 1)
15+
16+
device_info = [
17+
uuid: bstr .size 16,
18+
type: uint,
19+
testimprint: bstr .size 32,
20+
partno: uint,
21+
hwrevision: uint,
22+
productionrevision: uint,
23+
]
24+
25+
read_req = (
26+
1,
27+
action: operation,
28+
)
29+
30+
; Device Info service response to read data.
31+
read_resp = (
32+
1,
33+
action: operation,
34+
status: stat,
35+
data: device_info,
36+
)
37+
38+
device_info_req = [
39+
2,
40+
msg: (
41+
read_req
42+
),
43+
]
44+
45+
device_info_resp = [
46+
2,
47+
msg: (
48+
read_resp
49+
),
50+
]
51+
52+
; .. include_endingpoint_device_info_cddl_rst
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
#
8+
# Generated using cmake macro generate_and_add_cbor_files.
9+
#
10+
11+
zephyr_sources(
12+
device_info_service_decode.c
13+
device_info_service_encode.c
14+
)
15+
16+
zephyr_include_directories(.)

0 commit comments

Comments
 (0)