Skip to content

Commit 01ea8a7

Browse files
Encapsulated SUPPORTED_EVENT_TYPES support
Signed-off-by: Steven Bellock <[email protected]>
1 parent 6f83128 commit 01ea8a7

File tree

8 files changed

+441
-3
lines changed

8 files changed

+441
-3
lines changed

include/internal/libspdm_requester_lib.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,13 @@ libspdm_return_t libspdm_get_encap_response_event_ack(void *spdm_context,
498498
size_t *response_size,
499499
void *response);
500500
#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
501+
#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
502+
libspdm_return_t libspdm_get_encap_supported_event_types(void *spdm_context,
503+
size_t request_size,
504+
void *request,
505+
size_t *response_size,
506+
void *response);
507+
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
501508
#if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
502509
libspdm_return_t libspdm_get_encap_response_endpoint_info(void *spdm_context,
503510
size_t request_size,

library/spdm_requester_lib/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ target_sources(spdm_requester_lib
2020
libspdm_req_encap_event_ack.c
2121
libspdm_req_encap_endpoint_info.c
2222
libspdm_req_encap_request.c
23+
libspdm_req_encap_supported_event_types.c
2324
libspdm_req_end_session.c
2425
libspdm_req_finish.c
2526
libspdm_req_get_capabilities.c
@@ -44,4 +45,4 @@ target_sources(spdm_requester_lib
4445
libspdm_req_get_measurement_extension_log.c
4546
libspdm_req_get_key_pair_info.c
4647
libspdm_req_set_key_pair_info.c
47-
)
48+
)

library/spdm_requester_lib/libspdm_req_encap_request.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ libspdm_get_encap_response_func_via_request_code(uint8_t request_response_code)
3535

3636
size_t index;
3737

38-
libspdm_get_encap_response_struct_t get_encap_response_struct[] = {
38+
const libspdm_get_encap_response_struct_t get_encap_response_struct[] = {
3939
#if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
4040
#if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
4141
{ SPDM_GET_DIGESTS, libspdm_get_encap_response_digest },
@@ -53,6 +53,10 @@ libspdm_get_encap_response_func_via_request_code(uint8_t request_response_code)
5353
{ SPDM_SEND_EVENT, libspdm_get_encap_response_event_ack },
5454
#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
5555

56+
#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
57+
{ SPDM_GET_SUPPORTED_EVENT_TYPES, libspdm_get_encap_supported_event_types },
58+
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
59+
5660
#if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
5761
{ SPDM_GET_ENDPOINT_INFO, libspdm_get_encap_response_endpoint_info },
5862
#endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* Copyright Notice:
3+
* Copyright 2025 DMTF. All rights reserved.
4+
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5+
**/
6+
7+
#include "internal/libspdm_requester_lib.h"
8+
#include "internal/libspdm_secured_message_lib.h"
9+
10+
#if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP)
11+
12+
libspdm_return_t libspdm_get_encap_supported_event_types(void *spdm_context,
13+
size_t request_size,
14+
void *request,
15+
size_t *response_size,
16+
void *response)
17+
{
18+
uint32_t session_id;
19+
spdm_supported_event_types_response_t *spdm_response;
20+
spdm_get_supported_event_types_request_t *spdm_request;
21+
const size_t response_buffer_size = *response_size;
22+
libspdm_context_t *context;
23+
libspdm_session_info_t *session_info;
24+
libspdm_session_state_t session_state;
25+
uint32_t supported_event_groups_list_len;
26+
uint8_t event_group_count;
27+
28+
context = spdm_context;
29+
spdm_request = request;
30+
31+
if (libspdm_get_connection_version(context) < SPDM_MESSAGE_VERSION_13) {
32+
return libspdm_generate_encap_error_response(
33+
context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, SPDM_GET_SUPPORTED_EVENT_TYPES,
34+
response_size, response);
35+
}
36+
if (spdm_request->header.spdm_version != libspdm_get_connection_version(context)) {
37+
return libspdm_generate_encap_error_response(
38+
context, SPDM_ERROR_CODE_VERSION_MISMATCH, 0, response_size, response);
39+
}
40+
if (!libspdm_is_capabilities_flag_supported(
41+
context, true, SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EVENT_CAP, 0)) {
42+
return libspdm_generate_encap_error_response(
43+
context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, SPDM_GET_SUPPORTED_EVENT_TYPES,
44+
response_size, response);
45+
}
46+
if (!context->last_spdm_request_session_id_valid) {
47+
return libspdm_generate_encap_error_response(
48+
context, SPDM_ERROR_CODE_SESSION_REQUIRED, 0, response_size, response);
49+
}
50+
51+
session_id = context->last_spdm_request_session_id;
52+
session_info = libspdm_get_session_info_via_session_id(context, session_id);
53+
if (session_info == NULL) {
54+
return libspdm_generate_encap_error_response(
55+
context, SPDM_ERROR_CODE_INVALID_REQUEST, 0, response_size, response);
56+
}
57+
58+
session_state = libspdm_secured_message_get_session_state(
59+
session_info->secured_message_context);
60+
if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) {
61+
return libspdm_generate_encap_error_response(
62+
context, SPDM_ERROR_CODE_INVALID_REQUEST, 0, response_size, response);
63+
}
64+
65+
libspdm_reset_message_buffer_via_request_code(context, session_info,
66+
spdm_request->header.request_response_code);
67+
68+
/* This message can only be in secured session.
69+
* Thus don't need to consider transport layer padding, just check its exact size. */
70+
if (request_size != sizeof(spdm_get_supported_event_types_request_t)) {
71+
return libspdm_generate_encap_error_response(
72+
context, SPDM_ERROR_CODE_INVALID_REQUEST, 0,
73+
response_size, response);
74+
}
75+
76+
spdm_response = response;
77+
78+
spdm_response->header.spdm_version = libspdm_get_connection_version(context);
79+
spdm_response->header.request_response_code = SPDM_SUPPORTED_EVENT_TYPES;
80+
spdm_response->header.param2 = 0;
81+
82+
supported_event_groups_list_len = (uint32_t)(response_buffer_size -
83+
sizeof(spdm_supported_event_types_response_t));
84+
85+
if (!libspdm_event_get_types(context, context->connection_info.version, session_id,
86+
(void *)(spdm_response + 1), &supported_event_groups_list_len,
87+
&event_group_count)) {
88+
return libspdm_generate_encap_error_response(context,
89+
SPDM_ERROR_CODE_UNSPECIFIED, 0,
90+
response_size, response);
91+
}
92+
93+
LIBSPDM_ASSERT(supported_event_groups_list_len > 0);
94+
LIBSPDM_ASSERT(supported_event_groups_list_len <=
95+
(response_buffer_size - sizeof(spdm_supported_event_types_response_t)));
96+
LIBSPDM_ASSERT(event_group_count > 0);
97+
98+
spdm_response->header.param1 = event_group_count;
99+
spdm_response->supported_event_groups_list_len = supported_event_groups_list_len;
100+
101+
*response_size = sizeof(spdm_supported_event_types_response_t) +
102+
supported_event_groups_list_len;
103+
104+
return LIBSPDM_STATUS_SUCCESS;
105+
}
106+
107+
#endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP) */

unit_test/test_spdm_requester/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ target_sources(test_spdm_requester
4141
encap_endpoint_info.c
4242
encap_key_update.c
4343
encap_request.c
44+
encap_supported_event_types.c
4445
set_certificate.c
4546
get_csr.c
4647
chunk_get.c
@@ -63,6 +64,7 @@ target_sources(test_spdm_requester
6364
error_test/encap_event_ack_err.c
6465
error_test/get_endpoint_info_err.c
6566
error_test/encap_endpoint_info_err.c
67+
error_test/encap_supported_event_types_err.c
6668
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/common.c
6769
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/algo.c
6870
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/support.c
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/**
2+
* Copyright Notice:
3+
* Copyright 2025 DMTF. All rights reserved.
4+
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5+
**/
6+
7+
#include "spdm_unit_test.h"
8+
#include "internal/libspdm_requester_lib.h"
9+
10+
#if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP)
11+
12+
static uint8_t m_spdm_request_buffer[0x1000];
13+
static uint8_t m_spdm_response_buffer[0x1000];
14+
15+
static const uint32_t m_session_id = 0xffffffff;
16+
17+
extern uint32_t g_supported_event_groups_list_len;
18+
extern uint8_t g_event_group_count;
19+
20+
static void set_standard_state(libspdm_context_t *spdm_context)
21+
{
22+
libspdm_session_info_t *session_info;
23+
24+
spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
25+
SPDM_VERSION_NUMBER_SHIFT_BIT;
26+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
27+
28+
spdm_context->connection_info.capability.flags |=
29+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
30+
spdm_context->connection_info.capability.flags |=
31+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP;
32+
spdm_context->connection_info.capability.flags |=
33+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
34+
spdm_context->connection_info.capability.flags |=
35+
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
36+
37+
spdm_context->local_context.capability.flags |=
38+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP;
39+
spdm_context->local_context.capability.flags |=
40+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP;
41+
spdm_context->local_context.capability.flags |=
42+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP;
43+
spdm_context->local_context.capability.flags |=
44+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
45+
spdm_context->local_context.capability.flags |=
46+
SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EVENT_CAP;
47+
48+
spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
49+
spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
50+
spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
51+
spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
52+
53+
spdm_context->latest_session_id = m_session_id;
54+
spdm_context->last_spdm_request_session_id_valid = true;
55+
spdm_context->last_spdm_request_session_id = m_session_id;
56+
session_info = &spdm_context->session_info[0];
57+
libspdm_session_info_init(spdm_context, session_info, m_session_id, true);
58+
libspdm_secured_message_set_session_state(
59+
session_info->secured_message_context,
60+
LIBSPDM_SESSION_STATE_ESTABLISHED);
61+
}
62+
63+
static void test_supported_event_types_case1(void **state)
64+
{
65+
libspdm_return_t status;
66+
libspdm_test_context_t *spdm_test_context;
67+
libspdm_context_t *spdm_context;
68+
spdm_get_supported_event_types_request_t *get_supported_event_types;
69+
size_t request_size;
70+
spdm_supported_event_types_response_t *supported_event_types;
71+
size_t response_size = sizeof(m_spdm_response_buffer);
72+
73+
spdm_test_context = *state;
74+
spdm_context = spdm_test_context->spdm_context;
75+
spdm_test_context->case_id = 0x01;
76+
77+
set_standard_state(spdm_context);
78+
79+
get_supported_event_types = (spdm_get_supported_event_types_request_t *)m_spdm_request_buffer;
80+
81+
get_supported_event_types->header.spdm_version = SPDM_MESSAGE_VERSION_13;
82+
get_supported_event_types->header.request_response_code = SPDM_GET_SUPPORTED_EVENT_TYPES;
83+
get_supported_event_types->header.param1 = 0;
84+
get_supported_event_types->header.param2 = 0;
85+
86+
request_size = sizeof(spdm_get_supported_event_types_request_t);
87+
88+
status = libspdm_get_encap_supported_event_types(spdm_context,
89+
request_size,
90+
m_spdm_request_buffer,
91+
&response_size,
92+
m_spdm_response_buffer);
93+
94+
supported_event_types = (spdm_supported_event_types_response_t *)m_spdm_response_buffer;
95+
96+
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
97+
assert_int_equal(supported_event_types->header.spdm_version, SPDM_MESSAGE_VERSION_13);
98+
assert_int_equal(supported_event_types->header.request_response_code, SPDM_SUPPORTED_EVENT_TYPES);
99+
assert_int_equal(supported_event_types->header.param1, g_event_group_count);
100+
assert_int_equal(supported_event_types->header.param2, 0);
101+
assert_int_equal(supported_event_types->supported_event_groups_list_len,
102+
g_supported_event_groups_list_len);
103+
104+
for (uint32_t index = 0; index < supported_event_types->supported_event_groups_list_len; index++)
105+
{
106+
assert_int_equal(((char *)(supported_event_types + 1))[index], (char)index);
107+
}
108+
109+
libspdm_dump_data(m_spdm_response_buffer, response_size);
110+
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n"));
111+
}
112+
113+
int libspdm_requester_encap_supported_event_types_test_main(void)
114+
{
115+
const struct CMUnitTest spdm_requester_supported_event_types_tests[] = {
116+
cmocka_unit_test(test_supported_event_types_case1),
117+
};
118+
119+
libspdm_test_context_t test_context = {
120+
LIBSPDM_TEST_CONTEXT_VERSION,
121+
false,
122+
};
123+
124+
libspdm_setup_test_context(&test_context);
125+
126+
return cmocka_run_group_tests(spdm_requester_supported_event_types_tests,
127+
libspdm_unit_test_group_setup,
128+
libspdm_unit_test_group_teardown);
129+
}
130+
131+
#endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP) */

0 commit comments

Comments
 (0)