Skip to content

Commit c689c87

Browse files
Use SPDM 1.3 NoPendingRequests
Fix #3007. Signed-off-by: Steven Bellock <sbellock@nvidia.com>
1 parent 5e071c2 commit c689c87

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

library/spdm_responder_lib/libspdm_rsp_encap_response.c

+12-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,18 @@ libspdm_return_t libspdm_get_response_encapsulated_request(
224224
}
225225
if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_PROCESSING_ENCAP) {
226226
if (spdm_context->response_state == LIBSPDM_RESPONSE_STATE_NORMAL) {
227-
return libspdm_generate_error_response(
228-
spdm_context,
229-
SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
230-
response_size, response);
227+
if (libspdm_get_connection_version(spdm_context) >= SPDM_MESSAGE_VERSION_13) {
228+
return libspdm_generate_error_response(
229+
spdm_context,
230+
SPDM_ERROR_CODE_NO_PENDING_REQUESTS, 0,
231+
response_size, response);
232+
233+
} else {
234+
return libspdm_generate_error_response(
235+
spdm_context,
236+
SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0,
237+
response_size, response);
238+
}
231239
}
232240
return libspdm_responder_handle_response_state(
233241
spdm_context,

unit_test/test_spdm_responder/encap_response.c

+49-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2022 DMTF. All rights reserved.
3+
* Copyright 2021-2025 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -378,6 +378,51 @@ void libspdm_test_get_response_encapsulated_request_case6(void **State)
378378
free(data);
379379
}
380380

381+
void libspdm_test_get_response_encapsulated_request_case7(void **State)
382+
{
383+
libspdm_return_t status;
384+
libspdm_test_context_t *spdm_test_context;
385+
spdm_error_response_t *spdm_response_requester;
386+
libspdm_context_t *spdm_context;
387+
size_t response_size;
388+
uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE];
389+
uint8_t m_local_certificate_chain[LIBSPDM_MAX_CERT_CHAIN_SIZE];
390+
391+
spdm_test_context = *State;
392+
spdm_context = spdm_test_context->spdm_context;
393+
spdm_test_context->case_id = 0x7;
394+
395+
spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
396+
SPDM_VERSION_NUMBER_SHIFT_BIT;
397+
spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
398+
spdm_context->connection_info.capability.flags |= SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP;
399+
spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP;
400+
401+
spdm_context->encap_context.current_request_op_code = 0;
402+
spdm_context->encap_context.request_id = 0;
403+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED;
404+
spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP;
405+
spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
406+
spdm_context->local_context.local_cert_chain_provision[0] = m_local_certificate_chain;
407+
spdm_context->local_context.local_cert_chain_provision_size[0] =
408+
sizeof(m_local_certificate_chain);
409+
libspdm_set_mem(m_local_certificate_chain, sizeof(m_local_certificate_chain), 0xFF);
410+
411+
response_size = sizeof(response);
412+
status = libspdm_get_response_encapsulated_request(spdm_context,
413+
m_libspdm_encapsulated_request_t1_size,
414+
&m_libspdm_encapsulated_request_t1,
415+
&response_size,
416+
response);
417+
418+
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
419+
assert_int_equal(response_size, sizeof(spdm_error_response_t));
420+
spdm_response_requester = (void *)response;
421+
assert_int_equal(spdm_response_requester->header.request_response_code, SPDM_ERROR);
422+
assert_int_equal(spdm_response_requester->header.param1, SPDM_ERROR_CODE_NO_PENDING_REQUESTS);
423+
assert_int_equal(spdm_response_requester->header.param2, 0);
424+
}
425+
381426
void libspdm_test_get_response_encapsulated_response_ack_case1(void **State)
382427
{
383428
libspdm_return_t status;
@@ -1047,7 +1092,7 @@ int libspdm_responder_encapsulated_response_test_main(void)
10471092
cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case1),
10481093
/*Success Case current_request_op_code: SPDM_GET_CERTIFICATE */
10491094
cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case2),
1050-
/*response_state : LIBSPDM_RESPONSE_STATE_NORMAL */
1095+
/*response_state : LIBSPDM_RESPONSE_STATE_NORMAL with UnexpectedRequest error. */
10511096
cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case3),
10521097
/*response_state : LIBSPDM_RESPONSE_STATE_NEED_RESYNC */
10531098
cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case4),
@@ -1058,6 +1103,8 @@ int libspdm_responder_encapsulated_response_test_main(void)
10581103
#endif
10591104
/* Success Case current_request_op_code: SPDM_KEY_UPDATE */
10601105
cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case6),
1106+
/*response_state : LIBSPDM_RESPONSE_STATE_NORMAL with NoPendingRequests error. */
1107+
cmocka_unit_test(libspdm_test_get_response_encapsulated_request_case7),
10611108
#if (LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP) && (LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT)
10621109
/*Success Case current_request_op_code: SPDM_GET_DIGESTS*/
10631110
cmocka_unit_test(libspdm_test_get_response_encapsulated_response_ack_case1),

0 commit comments

Comments
 (0)