1
1
/**
2
2
* Copyright Notice:
3
- * Copyright 2021-2024 DMTF. All rights reserved.
3
+ * Copyright 2021-2025 DMTF. All rights reserved.
4
4
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
5
5
**/
6
6
@@ -15,6 +15,10 @@ static size_t m_libspdm_local_certificate_chain_size_test_case_1;
15
15
16
16
static uint8_t m_libspdm_local_large_response_buffer [LIBSPDM_MAX_SPDM_MSG_SIZE ];
17
17
18
+ #define BUFFER_SIZE_FOR_CHUNK_SEQ_NO_WRAP_TEST 0x200000
19
+ static uint8_t m_libspdm_local_response_buffer_for_chunk_seq_no_wrap_test [
20
+ BUFFER_SIZE_FOR_CHUNK_SEQ_NO_WRAP_TEST ];
21
+
18
22
static size_t m_libspdm_local_buffer_size ;
19
23
static uint8_t m_libspdm_local_buffer [LIBSPDM_MAX_MESSAGE_M1M2_BUFFER_SIZE ];
20
24
@@ -259,6 +263,29 @@ void libspdm_requester_chunk_get_test_case4_build_digest_response(
259
263
spdm_response -> header .param2 |= (0xFF << 0 );
260
264
}
261
265
266
+ void libspdm_requester_chunk_get_test_case5_build_vendor_response (
267
+ void * context , void * response , size_t * response_size )
268
+ {
269
+ spdm_vendor_defined_response_msg_t * spdm_response ;
270
+
271
+ /* For exceed max chunk seq no */
272
+ * response_size =
273
+ (CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE -
274
+ sizeof (spdm_chunk_response_response_t )) * 65536 - sizeof (uint32_t ) + 0x10 ;
275
+
276
+ libspdm_set_mem (response , * response_size , 0xff );
277
+
278
+ spdm_response = response ;
279
+
280
+ spdm_response -> header .spdm_version = SPDM_MESSAGE_VERSION_12 ;
281
+ spdm_response -> header .request_response_code = SPDM_VENDOR_DEFINED_RESPONSE ;
282
+ spdm_response -> header .param1 = 0 ;
283
+ spdm_response -> header .param2 = 0 ;
284
+
285
+ spdm_response -> standard_id = 6 ;
286
+ spdm_response -> len = 2 ;
287
+ }
288
+
262
289
libspdm_return_t libspdm_requester_chunk_get_test_send_message (
263
290
void * spdm_context , size_t request_size , const void * request ,
264
291
uint64_t timeout )
@@ -431,6 +458,9 @@ libspdm_return_t libspdm_requester_chunk_get_test_receive_message(
431
458
} else if (spdm_test_context -> case_id == 0x4 ) {
432
459
build_response_func =
433
460
libspdm_requester_chunk_get_test_case4_build_digest_response ;
461
+ } else if (spdm_test_context -> case_id == 0x5 ) {
462
+ build_response_func =
463
+ libspdm_requester_chunk_get_test_case5_build_vendor_response ;
434
464
} else {
435
465
LIBSPDM_ASSERT (0 );
436
466
return LIBSPDM_STATUS_RECEIVE_FAIL ;
@@ -453,6 +483,12 @@ libspdm_return_t libspdm_requester_chunk_get_test_receive_message(
453
483
454
484
sub_rsp = (spdm_message_header_t * ) m_libspdm_local_large_response_buffer ;
455
485
sub_rsp_size = sizeof (m_libspdm_local_large_response_buffer );
486
+ if (spdm_test_context -> case_id == 0x5 ) {
487
+ sub_rsp =
488
+ (spdm_message_header_t * )
489
+ m_libspdm_local_response_buffer_for_chunk_seq_no_wrap_test ;
490
+ sub_rsp_size = sizeof (m_libspdm_local_response_buffer_for_chunk_seq_no_wrap_test );
491
+ }
456
492
libspdm_zero_mem (sub_rsp , sub_rsp_size );
457
493
458
494
build_response_func (spdm_context , sub_rsp , & sub_rsp_size );
@@ -832,6 +868,57 @@ void libspdm_test_requester_chunk_get_case4(void** state)
832
868
}
833
869
#endif
834
870
871
+ #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
872
+ static void libspdm_test_requester_chunk_get_case5 (void * * state )
873
+ {
874
+ /* Copied from Vendor Request case 1*/
875
+ libspdm_return_t status ;
876
+ libspdm_test_context_t * spdm_test_context ;
877
+ libspdm_context_t * spdm_context ;
878
+
879
+ uint16_t standard_id = 6 ;
880
+ uint8_t vendor_id_len = 2 ;
881
+ uint8_t vendor_id [SPDM_MAX_VENDOR_ID_LENGTH ] = {0xAA , 0xAA };
882
+ uint16_t data_len = 16 ;
883
+ uint8_t data [16 ];
884
+
885
+ spdm_test_context = * state ;
886
+ spdm_context = spdm_test_context -> spdm_context ;
887
+ spdm_test_context -> case_id = 0x5 ;
888
+ spdm_context -> connection_info .version = SPDM_MESSAGE_VERSION_12 <<
889
+ SPDM_VERSION_NUMBER_SHIFT_BIT ;
890
+ /* Large response need a large scratch buffer. */
891
+ spdm_context -> connection_info .capability .max_spdm_msg_size =
892
+ BUFFER_SIZE_FOR_CHUNK_SEQ_NO_WRAP_TEST ;
893
+ spdm_context -> local_context .capability .max_spdm_msg_size =
894
+ BUFFER_SIZE_FOR_CHUNK_SEQ_NO_WRAP_TEST ;
895
+ spdm_context -> connection_info .connection_state =
896
+ LIBSPDM_CONNECTION_STATE_NEGOTIATED ;
897
+ spdm_context -> connection_info .capability .data_transfer_size =
898
+ CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE ;
899
+ spdm_context -> local_context .capability .sender_data_transfer_size =
900
+ CHUNK_GET_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE ;
901
+ spdm_context -> local_context .is_requester = true;
902
+
903
+ spdm_test_context -> scratch_buffer_size =
904
+ libspdm_get_sizeof_required_scratch_buffer (spdm_context );
905
+ spdm_test_context -> scratch_buffer = (void * )malloc (spdm_test_context -> scratch_buffer_size );
906
+ libspdm_set_scratch_buffer (spdm_context ,
907
+ spdm_test_context -> scratch_buffer ,
908
+ spdm_test_context -> scratch_buffer_size );
909
+
910
+ libspdm_set_mem (data , sizeof (data ), 0xAA );
911
+
912
+ status = libspdm_vendor_send_request_receive_response (spdm_context , NULL ,
913
+ standard_id , vendor_id_len , vendor_id ,
914
+ data_len , data ,
915
+ & standard_id , & vendor_id_len , vendor_id ,
916
+ & data_len , data );
917
+
918
+ assert_int_equal (status , LIBSPDM_STATUS_RECEIVE_FAIL );
919
+ }
920
+ #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
921
+
835
922
int libspdm_requester_chunk_get_test_main (void )
836
923
{
837
924
/* Test the CHUNK_GET handlers in various requester handlers */
@@ -851,6 +938,10 @@ int libspdm_requester_chunk_get_test_main(void)
851
938
#if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
852
939
/* Request Digests */
853
940
cmocka_unit_test (libspdm_test_requester_chunk_get_case4 ),
941
+ #endif
942
+ #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
943
+ /* Request Vendor Specific Response and chunk seq no wrapped */
944
+ cmocka_unit_test (libspdm_test_requester_chunk_get_case5 ),
854
945
#endif
855
946
};
856
947
0 commit comments