Line data Source code
1 : /**
2 : * Copyright Notice:
3 : * Copyright 2021-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 : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG \
11 : (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
12 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP)
13 :
14 : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11 \
15 : (SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
16 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHAL_CAP | \
17 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP | \
18 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP | \
19 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MUT_AUTH_CAP | \
20 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP | \
21 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_PSK_CAP_REQUESTER | \
22 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP | \
23 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HBEAT_CAP | \
24 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_UPD_CAP | \
25 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
26 :
27 : #define LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12 SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP
28 :
29 : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 \
30 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP | \
31 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP | \
32 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP | \
33 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG | \
34 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP | \
35 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP | \
36 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP | \
37 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP | \
38 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP | \
39 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP_RESPONDER_WITH_CONTEXT | \
40 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP | \
41 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HBEAT_CAP | \
42 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_UPD_CAP | \
43 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP)
44 :
45 : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 \
46 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP | \
47 : SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CERT_CAP | \
48 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ALIAS_CERT_CAP | \
49 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP)
50 :
51 : #define LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13 \
52 : (LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 | \
53 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12 | \
54 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EP_INFO_CAP_NO_SIG | \
55 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEL_CAP | \
56 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP | \
57 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MULTI_KEY_CAP_ONLY | \
58 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_GET_KEY_PAIR_INFO_CAP)
59 :
60 : static size_t m_libspdm_local_buffer_size;
61 : static uint8_t m_libspdm_local_buffer[LIBSPDM_MAX_MESSAGE_VCA_BUFFER_SIZE];
62 :
63 11 : static libspdm_return_t send_message(
64 : void *spdm_context, size_t request_size, const void *request, uint64_t timeout)
65 : {
66 : libspdm_test_context_t *spdm_test_context;
67 :
68 11 : spdm_test_context = libspdm_get_test_context();
69 11 : switch (spdm_test_context->case_id) {
70 0 : case 0x1:
71 0 : return LIBSPDM_STATUS_SEND_FAIL;
72 1 : case 0x2:
73 1 : return LIBSPDM_STATUS_SUCCESS;
74 0 : case 0x3:
75 0 : return LIBSPDM_STATUS_SUCCESS;
76 0 : case 0x4:
77 0 : return LIBSPDM_STATUS_SUCCESS;
78 0 : case 0x5:
79 0 : return LIBSPDM_STATUS_SUCCESS;
80 2 : case 0x6:
81 2 : return LIBSPDM_STATUS_SUCCESS;
82 0 : case 0x7:
83 0 : return LIBSPDM_STATUS_SUCCESS;
84 0 : case 0x8:
85 0 : return LIBSPDM_STATUS_SUCCESS;
86 0 : case 0x9:
87 0 : return LIBSPDM_STATUS_SUCCESS;
88 1 : case 0xa:
89 1 : return LIBSPDM_STATUS_SUCCESS;
90 1 : case 0xb:
91 1 : return LIBSPDM_STATUS_SUCCESS;
92 1 : case 0xc:
93 1 : return LIBSPDM_STATUS_SUCCESS;
94 0 : case 0xd:
95 0 : return LIBSPDM_STATUS_SUCCESS;
96 0 : case 0xe:
97 0 : return LIBSPDM_STATUS_SUCCESS;
98 0 : case 0xf:
99 0 : return LIBSPDM_STATUS_SUCCESS;
100 1 : case 0x10:
101 1 : return LIBSPDM_STATUS_SUCCESS;
102 0 : case 0x11:
103 0 : return LIBSPDM_STATUS_SUCCESS;
104 0 : case 0x12:
105 0 : return LIBSPDM_STATUS_SUCCESS;
106 0 : case 0x13:
107 0 : return LIBSPDM_STATUS_SUCCESS;
108 0 : case 0x14:
109 0 : return LIBSPDM_STATUS_SUCCESS;
110 0 : case 0x15:
111 0 : return LIBSPDM_STATUS_SUCCESS;
112 0 : case 0x16:
113 0 : return LIBSPDM_STATUS_SUCCESS;
114 0 : case 0x17:
115 0 : return LIBSPDM_STATUS_SUCCESS;
116 0 : case 0x18:
117 0 : return LIBSPDM_STATUS_SUCCESS;
118 0 : case 0x19:
119 0 : return LIBSPDM_STATUS_SUCCESS;
120 0 : case 0x1a:
121 0 : return LIBSPDM_STATUS_SUCCESS;
122 0 : case 0x1b:
123 0 : return LIBSPDM_STATUS_SUCCESS;
124 0 : case 0x1c:
125 0 : return LIBSPDM_STATUS_SUCCESS;
126 0 : case 0x1d:
127 0 : return LIBSPDM_STATUS_SUCCESS;
128 0 : case 0x1E:
129 0 : return LIBSPDM_STATUS_SUCCESS;
130 0 : case 0x1F:
131 0 : return LIBSPDM_STATUS_SUCCESS;
132 1 : case 0x20: {
133 1 : const uint8_t *ptr = (const uint8_t *)request;
134 :
135 1 : m_libspdm_local_buffer_size = 0;
136 1 : libspdm_copy_mem(m_libspdm_local_buffer, sizeof(m_libspdm_local_buffer), &ptr[1],
137 : request_size - 1);
138 1 : m_libspdm_local_buffer_size += (request_size - 1);
139 : }
140 1 : return LIBSPDM_STATUS_SUCCESS;
141 1 : case 0x21:
142 1 : return LIBSPDM_STATUS_SUCCESS;
143 0 : case 0x22:
144 0 : return LIBSPDM_STATUS_SUCCESS;
145 1 : case 0x23:
146 1 : return LIBSPDM_STATUS_SUCCESS;
147 1 : case 0x24:
148 1 : return LIBSPDM_STATUS_SUCCESS;
149 0 : default:
150 0 : return LIBSPDM_STATUS_SEND_FAIL;
151 : }
152 : }
153 :
154 11 : static libspdm_return_t receive_message(
155 : void *spdm_context, size_t *response_size, void **response, uint64_t timeout)
156 : {
157 : libspdm_test_context_t *spdm_test_context;
158 :
159 11 : spdm_test_context = libspdm_get_test_context();
160 11 : switch (spdm_test_context->case_id) {
161 0 : case 0x1:
162 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
163 :
164 1 : case 0x2: {
165 : spdm_capabilities_response_t *spdm_response;
166 : size_t spdm_response_size;
167 : size_t transport_header_size;
168 :
169 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
170 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
171 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
172 :
173 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
174 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
175 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
176 1 : spdm_response->header.param1 = 0;
177 1 : spdm_response->header.param2 = 0;
178 1 : spdm_response->ct_exponent = 0;
179 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
180 :
181 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
182 : false, spdm_response_size,
183 : spdm_response,
184 : response_size, response);
185 : }
186 1 : return LIBSPDM_STATUS_SUCCESS;
187 :
188 0 : case 0x3: {
189 : spdm_capabilities_response_t *spdm_response;
190 : size_t spdm_response_size;
191 : size_t transport_header_size;
192 :
193 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
194 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
195 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
196 :
197 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
198 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
199 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
200 0 : spdm_response->header.param1 = 0;
201 0 : spdm_response->header.param2 = 0;
202 0 : spdm_response->ct_exponent = 0;
203 0 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
204 :
205 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
206 : false, spdm_response_size,
207 : spdm_response,
208 : response_size, response);
209 : }
210 0 : return LIBSPDM_STATUS_SUCCESS;
211 :
212 0 : case 0x4: {
213 : spdm_error_response_t *spdm_response;
214 : size_t spdm_response_size;
215 : size_t transport_header_size;
216 :
217 0 : spdm_response_size = sizeof(spdm_error_response_t);
218 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
219 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
220 :
221 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
222 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
223 0 : spdm_response->header.request_response_code = SPDM_ERROR;
224 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_INVALID_REQUEST;
225 0 : spdm_response->header.param2 = 0;
226 :
227 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
228 : false, spdm_response_size,
229 : spdm_response,
230 : response_size, response);
231 : }
232 0 : return LIBSPDM_STATUS_SUCCESS;
233 :
234 0 : case 0x5: {
235 : spdm_error_response_t *spdm_response;
236 : size_t spdm_response_size;
237 : size_t transport_header_size;
238 :
239 0 : spdm_response_size = sizeof(spdm_error_response_t);
240 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
241 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
242 :
243 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
244 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
245 0 : spdm_response->header.request_response_code = SPDM_ERROR;
246 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
247 0 : spdm_response->header.param2 = 0;
248 :
249 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
250 : false, spdm_response_size,
251 : spdm_response,
252 : response_size, response);
253 : }
254 0 : return LIBSPDM_STATUS_SUCCESS;
255 :
256 2 : case 0x6: {
257 : static size_t sub_index1 = 0;
258 2 : if (sub_index1 == 0) {
259 : spdm_error_response_t *spdm_response;
260 : size_t spdm_response_size;
261 : size_t transport_header_size;
262 :
263 1 : spdm_response_size = sizeof(spdm_error_response_t);
264 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
265 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
266 :
267 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
268 1 : spdm_response->header.spdm_version =
269 : SPDM_MESSAGE_VERSION_10;
270 1 : spdm_response->header.request_response_code = SPDM_ERROR;
271 1 : spdm_response->header.param1 = SPDM_ERROR_CODE_BUSY;
272 1 : spdm_response->header.param2 = 0;
273 :
274 1 : libspdm_transport_test_encode_message(
275 : spdm_context, NULL, false, false,
276 : spdm_response_size, spdm_response,
277 : response_size, response);
278 1 : } else if (sub_index1 == 1) {
279 : spdm_capabilities_response_t *spdm_response;
280 : size_t spdm_response_size;
281 : size_t transport_header_size;
282 :
283 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
284 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
285 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
286 :
287 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
288 1 : spdm_response->header.spdm_version =
289 : SPDM_MESSAGE_VERSION_10;
290 1 : spdm_response->header.request_response_code =
291 : SPDM_CAPABILITIES;
292 1 : spdm_response->header.param1 = 0;
293 1 : spdm_response->header.param2 = 0;
294 1 : spdm_response->ct_exponent = 0;
295 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
296 :
297 1 : libspdm_transport_test_encode_message(
298 : spdm_context, NULL, false, false,
299 : spdm_response_size, spdm_response,
300 : response_size, response);
301 : }
302 2 : sub_index1++;
303 : }
304 2 : return LIBSPDM_STATUS_SUCCESS;
305 :
306 0 : case 0x7: {
307 : spdm_error_response_t *spdm_response;
308 : size_t spdm_response_size;
309 : size_t transport_header_size;
310 :
311 0 : spdm_response_size = sizeof(spdm_error_response_t);
312 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
313 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
314 :
315 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
316 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
317 0 : spdm_response->header.request_response_code = SPDM_ERROR;
318 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_REQUEST_RESYNCH;
319 0 : spdm_response->header.param2 = 0;
320 :
321 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
322 : false, spdm_response_size,
323 : spdm_response,
324 : response_size, response);
325 : }
326 0 : return LIBSPDM_STATUS_SUCCESS;
327 :
328 0 : case 0x8: {
329 : spdm_error_response_data_response_not_ready_t *spdm_response;
330 : size_t spdm_response_size;
331 : size_t transport_header_size;
332 :
333 0 : spdm_response_size = sizeof(spdm_error_response_data_response_not_ready_t);
334 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
335 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
336 :
337 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
338 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
339 0 : spdm_response->header.request_response_code = SPDM_ERROR;
340 0 : spdm_response->header.param1 = SPDM_ERROR_CODE_RESPONSE_NOT_READY;
341 0 : spdm_response->header.param2 = 0;
342 0 : spdm_response->extend_error_data.rd_exponent = 1;
343 0 : spdm_response->extend_error_data.rd_tm = 2;
344 0 : spdm_response->extend_error_data.request_code = SPDM_GET_CAPABILITIES;
345 0 : spdm_response->extend_error_data.token = 0;
346 :
347 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
348 : false, spdm_response_size,
349 : spdm_response,
350 : response_size, response);
351 : }
352 0 : return LIBSPDM_STATUS_SUCCESS;
353 :
354 0 : case 0x9:
355 0 : return LIBSPDM_STATUS_SUCCESS;
356 :
357 1 : case 0xa: {
358 : spdm_capabilities_response_t *spdm_response;
359 : size_t spdm_response_size;
360 : size_t transport_header_size;
361 :
362 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
363 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
364 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
365 :
366 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
367 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
368 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
369 1 : spdm_response->header.param1 = 0;
370 1 : spdm_response->header.param2 = 0;
371 1 : spdm_response->ct_exponent = 0;
372 1 : spdm_response->flags =
373 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
374 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
375 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
376 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
377 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP);
378 :
379 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
380 : false, spdm_response_size,
381 : spdm_response,
382 : response_size, response);
383 : }
384 1 : return LIBSPDM_STATUS_SUCCESS;
385 :
386 1 : case 0xb: {
387 : spdm_capabilities_response_t *spdm_response;
388 : size_t spdm_response_size;
389 : size_t transport_header_size;
390 :
391 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
392 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
393 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
394 :
395 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
396 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
397 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
398 1 : spdm_response->header.param1 = 0;
399 1 : spdm_response->header.param2 = 0;
400 1 : spdm_response->ct_exponent = 0;
401 1 : spdm_response->flags =
402 : !(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
403 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
404 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
405 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
406 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP);
407 :
408 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
409 : false, spdm_response_size,
410 : spdm_response,
411 : response_size, response);
412 : }
413 1 : return LIBSPDM_STATUS_SUCCESS;
414 :
415 1 : case 0xc: {
416 : spdm_capabilities_response_t *spdm_response;
417 : size_t spdm_response_size;
418 : size_t transport_header_size;
419 :
420 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
421 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
422 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
423 :
424 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
425 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
426 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
427 1 : spdm_response->header.param1 = 0;
428 1 : spdm_response->header.param2 = 0;
429 1 : spdm_response->ct_exponent = 0;
430 1 : spdm_response->flags = SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP |
431 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG;
432 :
433 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
434 : false, spdm_response_size,
435 : spdm_response,
436 : response_size, response);
437 : }
438 1 : return LIBSPDM_STATUS_SUCCESS;
439 :
440 0 : case 0xd: {
441 : spdm_capabilities_response_t *spdm_response;
442 : size_t spdm_response_size;
443 : size_t transport_header_size;
444 :
445 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
446 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
447 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
448 :
449 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
450 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
451 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
452 0 : spdm_response->header.param1 = 0;
453 0 : spdm_response->header.param2 = 0;
454 :
455 0 : libspdm_transport_test_encode_message(
456 : spdm_context, NULL, false, false,
457 : sizeof(spdm_message_header_t), spdm_response,
458 : response_size, response);
459 : }
460 0 : return LIBSPDM_STATUS_SUCCESS;
461 :
462 0 : case 0xe: {
463 : spdm_capabilities_response_t *spdm_response;
464 : size_t spdm_response_size;
465 : size_t transport_header_size;
466 :
467 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
468 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
469 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
470 :
471 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
472 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
473 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
474 0 : spdm_response->header.param1 = 0;
475 0 : spdm_response->header.param2 = 0;
476 0 : spdm_response->ct_exponent = 0;
477 0 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
478 :
479 0 : libspdm_transport_test_encode_message(
480 : spdm_context, NULL, false, false,
481 : sizeof(spdm_capabilities_response_t) + sizeof(uint8_t), spdm_response,
482 : response_size, response);
483 : }
484 0 : return LIBSPDM_STATUS_INVALID_MSG_SIZE;
485 :
486 0 : case 0xf: {
487 : spdm_capabilities_response_t *spdm_response;
488 : size_t spdm_response_size;
489 : size_t transport_header_size;
490 :
491 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
492 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
493 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
494 :
495 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
496 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_10;
497 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
498 0 : spdm_response->header.param1 = 0;
499 0 : spdm_response->header.param2 = 0;
500 0 : spdm_response->ct_exponent = 0;
501 0 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
502 :
503 0 : libspdm_transport_test_encode_message(
504 : spdm_context, NULL, false, false,
505 : sizeof(spdm_capabilities_response_t) - sizeof(uint8_t), spdm_response,
506 : response_size, response);
507 : }
508 0 : return LIBSPDM_STATUS_INVALID_MSG_SIZE;
509 :
510 1 : case 0x10: {
511 : spdm_capabilities_response_t *spdm_response;
512 : size_t spdm_response_size;
513 : size_t transport_header_size;
514 :
515 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
516 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
517 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
518 :
519 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
520 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
521 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
522 1 : spdm_response->header.param1 = 0;
523 1 : spdm_response->header.param2 = 0;
524 1 : spdm_response->ct_exponent = 0;
525 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
526 :
527 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
528 : false, spdm_response_size,
529 : spdm_response,
530 : response_size, response);
531 : }
532 1 : return LIBSPDM_STATUS_SUCCESS;
533 :
534 0 : case 0x11: {
535 : spdm_capabilities_response_t *spdm_response;
536 : size_t spdm_response_size;
537 : size_t transport_header_size;
538 :
539 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
540 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
541 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
542 :
543 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
544 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
545 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
546 0 : spdm_response->header.param1 = 0;
547 0 : spdm_response->header.param2 = 0;
548 0 : spdm_response->ct_exponent = 0;
549 0 : spdm_response->flags =
550 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
551 : (0xFFFFFFFF ^
552 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
553 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
554 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
555 :
556 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
557 : false, spdm_response_size,
558 : spdm_response,
559 : response_size, response);
560 : }
561 0 : return LIBSPDM_STATUS_SUCCESS;
562 :
563 0 : case 0x12: {
564 : spdm_capabilities_response_t *spdm_response;
565 : size_t spdm_response_size;
566 : size_t transport_header_size;
567 :
568 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
569 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
570 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
571 :
572 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
573 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
574 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
575 0 : spdm_response->header.param1 = 0;
576 0 : spdm_response->header.param2 = 0;
577 0 : spdm_response->ct_exponent = 0;
578 0 : spdm_response->flags =
579 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
580 : (0xFFFFFFFF ^
581 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
582 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
583 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
584 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
585 :
586 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
587 : false, spdm_response_size,
588 : spdm_response,
589 : response_size, response);
590 : }
591 0 : return LIBSPDM_STATUS_SUCCESS;
592 :
593 0 : case 0x13: {
594 : spdm_capabilities_response_t *spdm_response;
595 : size_t spdm_response_size;
596 : size_t transport_header_size;
597 :
598 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
599 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
600 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
601 :
602 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
603 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
604 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
605 0 : spdm_response->header.param1 = 0;
606 0 : spdm_response->header.param2 = 0;
607 0 : spdm_response->ct_exponent = 0;
608 0 : spdm_response->flags =
609 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
610 : (0xFFFFFFFF ^
611 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
612 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
613 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
614 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
615 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
616 : false, spdm_response_size,
617 : spdm_response,
618 : response_size, response);
619 : }
620 0 : return LIBSPDM_STATUS_SUCCESS;
621 :
622 0 : case 0x14: {
623 : spdm_capabilities_response_t *spdm_response;
624 : size_t spdm_response_size;
625 : size_t transport_header_size;
626 :
627 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
628 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
629 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
630 :
631 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
632 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
633 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
634 0 : spdm_response->header.param1 = 0;
635 0 : spdm_response->header.param2 = 0;
636 0 : spdm_response->ct_exponent = 0;
637 0 : spdm_response->flags =
638 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
639 : (0xFFFFFFFF ^
640 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
641 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
642 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
643 :
644 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
645 : false, spdm_response_size,
646 : spdm_response,
647 : response_size, response);
648 : }
649 0 : return LIBSPDM_STATUS_SUCCESS;
650 :
651 0 : case 0x15: {
652 : spdm_capabilities_response_t *spdm_response;
653 : size_t spdm_response_size;
654 : size_t transport_header_size;
655 :
656 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
657 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
658 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
659 :
660 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
661 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
662 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
663 0 : spdm_response->header.param1 = 0;
664 0 : spdm_response->header.param2 = 0;
665 0 : spdm_response->ct_exponent = 0;
666 0 : spdm_response->flags =
667 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
668 : (0xFFFFFFFF ^
669 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
670 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
671 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP |
672 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
673 :
674 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
675 : false, spdm_response_size,
676 : spdm_response,
677 : response_size, response);
678 : }
679 0 : return LIBSPDM_STATUS_SUCCESS;
680 :
681 0 : case 0x16: {
682 : spdm_capabilities_response_t *spdm_response;
683 : size_t spdm_response_size;
684 : size_t transport_header_size;
685 :
686 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
687 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
688 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
689 :
690 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
691 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
692 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
693 0 : spdm_response->header.param1 = 0;
694 0 : spdm_response->header.param2 = 0;
695 0 : spdm_response->ct_exponent = 0;
696 0 : spdm_response->flags =
697 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
698 : (0xFFFFFFFF ^
699 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
700 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
701 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP |
702 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_HANDSHAKE_IN_THE_CLEAR_CAP));
703 :
704 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
705 : false, spdm_response_size,
706 : spdm_response,
707 : response_size, response);
708 : }
709 0 : return LIBSPDM_STATUS_SUCCESS;
710 :
711 0 : case 0x17: {
712 : spdm_capabilities_response_t *spdm_response;
713 : size_t spdm_response_size;
714 : size_t transport_header_size;
715 :
716 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
717 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
718 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
719 :
720 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
721 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
722 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
723 0 : spdm_response->header.param1 = 0;
724 0 : spdm_response->header.param2 = 0;
725 0 : spdm_response->ct_exponent = 0;
726 0 : spdm_response->flags =
727 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
728 : (0xFFFFFFFF ^
729 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP));
730 :
731 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
732 : false, spdm_response_size,
733 : spdm_response,
734 : response_size, response);
735 : }
736 0 : return LIBSPDM_STATUS_SUCCESS;
737 :
738 0 : case 0x18: {
739 : spdm_capabilities_response_t *spdm_response;
740 : size_t spdm_response_size;
741 : size_t transport_header_size;
742 :
743 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
744 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
745 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
746 :
747 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
748 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
749 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
750 0 : spdm_response->header.param1 = 0;
751 0 : spdm_response->header.param2 = 0;
752 0 : spdm_response->ct_exponent = 0;
753 0 : spdm_response->flags =
754 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
755 : (0xFFFFFFFF ^
756 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP));
757 :
758 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
759 : false, spdm_response_size,
760 : spdm_response,
761 : response_size, response);
762 : }
763 0 : return LIBSPDM_STATUS_SUCCESS;
764 :
765 0 : case 0x19: {
766 : spdm_capabilities_response_t *spdm_response;
767 : size_t spdm_response_size;
768 : size_t transport_header_size;
769 :
770 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
771 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
772 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
773 :
774 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
775 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
776 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
777 0 : spdm_response->header.param1 = 0;
778 0 : spdm_response->header.param2 = 0;
779 0 : spdm_response->ct_exponent = 0;
780 0 : spdm_response->flags =
781 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 &
782 : (0xFFFFFFFF ^
783 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP |
784 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP |
785 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PSK_CAP));
786 :
787 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
788 : false, spdm_response_size,
789 : spdm_response,
790 : response_size, response);
791 : }
792 0 : return LIBSPDM_STATUS_SUCCESS;
793 :
794 0 : case 0x1a: {
795 : spdm_capabilities_response_t *spdm_response;
796 : size_t spdm_response_size;
797 : size_t transport_header_size;
798 :
799 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
800 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
801 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
802 :
803 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
804 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
805 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
806 0 : spdm_response->header.param1 = 0;
807 0 : spdm_response->header.param2 = 0;
808 0 : spdm_response->ct_exponent = 0;
809 0 : spdm_response->flags =
810 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11 |
811 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_PUB_KEY_ID_CAP;
812 :
813 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
814 : false, spdm_response_size,
815 : spdm_response,
816 : response_size, response);
817 : }
818 0 : return LIBSPDM_STATUS_SUCCESS;
819 :
820 0 : case 0x1b: {
821 : spdm_capabilities_response_t *spdm_response;
822 : size_t spdm_response_size;
823 : size_t transport_header_size;
824 :
825 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
826 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
827 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
828 :
829 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
830 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
831 0 : spdm_response->header.request_response_code =
832 : SPDM_GET_CAPABILITIES;
833 0 : spdm_response->header.param1 = 0;
834 0 : spdm_response->header.param2 = 0;
835 0 : spdm_response->ct_exponent = 0;
836 0 : spdm_response->flags =
837 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
838 :
839 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
840 : false, spdm_response_size,
841 : spdm_response,
842 : response_size, response);
843 : }
844 0 : return LIBSPDM_STATUS_SUCCESS;
845 :
846 0 : case 0x1c: {
847 : spdm_capabilities_response_t *spdm_response;
848 : size_t spdm_response_size;
849 : size_t transport_header_size;
850 :
851 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
852 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
853 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
854 :
855 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
856 0 : spdm_response->header.spdm_version = 0xFF;
857 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
858 0 : spdm_response->header.param1 = 0;
859 0 : spdm_response->header.param2 = 0;
860 0 : spdm_response->ct_exponent = 0;
861 0 : spdm_response->flags =
862 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
863 :
864 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
865 : false, spdm_response_size,
866 : spdm_response,
867 : response_size, response);
868 : }
869 0 : return LIBSPDM_STATUS_SUCCESS;
870 :
871 0 : case 0x1d:
872 : {
873 : static uint16_t error_code = LIBSPDM_ERROR_CODE_RESERVED_00;
874 :
875 : spdm_error_response_t *spdm_response;
876 : size_t spdm_response_size;
877 : size_t transport_header_size;
878 :
879 0 : spdm_response_size = sizeof(spdm_error_response_t);
880 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
881 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
882 :
883 0 : if(error_code <= 0xff) {
884 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
885 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
886 0 : spdm_response->header.request_response_code = SPDM_ERROR;
887 0 : spdm_response->header.param1 = (uint8_t) error_code;
888 0 : spdm_response->header.param2 = 0;
889 :
890 0 : libspdm_transport_test_encode_message (spdm_context, NULL, false, false,
891 : spdm_response_size, spdm_response,
892 : response_size, response);
893 : }
894 :
895 0 : error_code++;
896 0 : if(error_code == SPDM_ERROR_CODE_BUSY) { /*busy is treated in cases 5 and 6*/
897 0 : error_code = SPDM_ERROR_CODE_UNEXPECTED_REQUEST;
898 : }
899 0 : if(error_code == LIBSPDM_ERROR_CODE_RESERVED_0D) { /*skip some reserved error codes (0d to 3e)*/
900 0 : error_code = LIBSPDM_ERROR_CODE_RESERVED_3F;
901 : }
902 0 : if(error_code == SPDM_ERROR_CODE_RESPONSE_NOT_READY) { /*skip response not ready, request resync, and some reserved codes (44 to fc)*/
903 0 : error_code = LIBSPDM_ERROR_CODE_RESERVED_FD;
904 : }
905 : }
906 0 : return LIBSPDM_STATUS_SUCCESS;
907 :
908 0 : case 0x1F:
909 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
910 :
911 1 : case 0x20: {
912 : spdm_capabilities_response_t *spdm_response;
913 : size_t spdm_response_size;
914 : size_t transport_header_size;
915 :
916 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
917 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
918 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
919 :
920 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
921 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_11;
922 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
923 1 : spdm_response->header.param1 = 0;
924 1 : spdm_response->header.param2 = 0;
925 1 : spdm_response->ct_exponent = 0;
926 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11;
927 :
928 1 : spdm_response_size = sizeof(spdm_capabilities_response_t) -
929 : sizeof(spdm_response->data_transfer_size) -
930 : sizeof(spdm_response->max_spdm_msg_size);
931 :
932 1 : libspdm_copy_mem(&m_libspdm_local_buffer[m_libspdm_local_buffer_size],
933 : sizeof(m_libspdm_local_buffer) - m_libspdm_local_buffer_size,
934 : (uint8_t *)spdm_response, spdm_response_size);
935 1 : m_libspdm_local_buffer_size += spdm_response_size;
936 :
937 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
938 : false, spdm_response_size,
939 : spdm_response,
940 : response_size, response);
941 : }
942 1 : return LIBSPDM_STATUS_SUCCESS;
943 :
944 1 : case 0x21: {
945 : spdm_capabilities_response_t *spdm_response;
946 : size_t spdm_response_size;
947 : size_t transport_header_size;
948 :
949 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
950 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
951 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
952 :
953 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
954 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
955 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
956 1 : spdm_response->header.param1 = 0;
957 1 : spdm_response->header.param2 = 0;
958 1 : spdm_response->ct_exponent = 0;
959 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12;
960 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
961 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
962 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
963 : false, spdm_response_size,
964 : spdm_response,
965 : response_size, response);
966 : }
967 1 : return LIBSPDM_STATUS_SUCCESS;
968 0 : case 0x22: {
969 : spdm_capabilities_response_t *spdm_response;
970 : size_t spdm_response_size;
971 : size_t transport_header_size;
972 :
973 0 : spdm_response_size = sizeof(spdm_capabilities_response_t);
974 0 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
975 0 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
976 :
977 0 : libspdm_zero_mem(spdm_response, spdm_response_size);
978 0 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
979 0 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
980 0 : spdm_response->header.param1 = 0;
981 0 : spdm_response->header.param2 = 0;
982 0 : spdm_response->ct_exponent = 0;
983 0 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
984 0 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
985 0 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
986 :
987 0 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
988 : false, spdm_response_size,
989 : spdm_response,
990 : response_size, response);
991 : }
992 0 : return LIBSPDM_STATUS_SUCCESS;
993 1 : case 0x23: {
994 : spdm_capabilities_response_t *spdm_response;
995 : size_t spdm_response_size;
996 : size_t transport_header_size;
997 :
998 1 : spdm_response_size = sizeof(spdm_capabilities_response_t);
999 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1000 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1001 :
1002 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
1003 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1004 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
1005 1 : spdm_response->header.param1 = 0;
1006 1 : spdm_response->header.param2 = 0;
1007 1 : spdm_response->ct_exponent = 0;
1008 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13;
1009 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
1010 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
1011 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1012 : false, spdm_response_size,
1013 : spdm_response,
1014 : response_size, response);
1015 : }
1016 1 : return LIBSPDM_STATUS_SUCCESS;
1017 1 : case 0x24: {
1018 : spdm_capabilities_response_t *spdm_response;
1019 : size_t spdm_response_size;
1020 : size_t transport_header_size;
1021 :
1022 1 : spdm_response_size = sizeof(spdm_capabilities_response_t) +
1023 : sizeof(spdm_supported_algorithms_block_t) + 4*
1024 : sizeof(spdm_negotiate_algorithms_common_struct_table_t);
1025 1 : transport_header_size = LIBSPDM_TEST_TRANSPORT_HEADER_SIZE;
1026 1 : spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1027 :
1028 1 : libspdm_zero_mem(spdm_response, spdm_response_size);
1029 1 : spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_13;
1030 1 : spdm_response->header.request_response_code = SPDM_CAPABILITIES;
1031 1 : spdm_response->header.param1 = 0;
1032 1 : spdm_response->header.param2 = 0;
1033 1 : spdm_response->ct_exponent = 0;
1034 1 : spdm_response->flags = LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13;
1035 1 : spdm_response->data_transfer_size = LIBSPDM_DATA_TRANSFER_SIZE;
1036 1 : spdm_response->max_spdm_msg_size = LIBSPDM_MAX_SPDM_MSG_SIZE;
1037 :
1038 : /* Allocate space for the supported_algorithms block at the end of the response */
1039 1 : spdm_supported_algorithms_block_t *supported_algorithms =
1040 : (spdm_supported_algorithms_block_t*)((uint8_t*)spdm_response +
1041 : sizeof(spdm_capabilities_response_t) );
1042 :
1043 1 : supported_algorithms->param1 = 4;
1044 1 : supported_algorithms->param2 = 0;
1045 1 : supported_algorithms->length = sizeof(spdm_supported_algorithms_block_t) +
1046 : 4 *
1047 : sizeof(
1048 : spdm_negotiate_algorithms_common_struct_table_t);
1049 1 : supported_algorithms->measurement_specification =
1050 : SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1051 1 : supported_algorithms->other_params_support = 0;
1052 1 : supported_algorithms->base_asym_algo = m_libspdm_use_asym_algo;
1053 1 : supported_algorithms->base_hash_algo = m_libspdm_use_hash_algo;
1054 1 : supported_algorithms->ext_asym_count = 0;
1055 1 : supported_algorithms->ext_hash_count = 0;
1056 1 : supported_algorithms->mel_specification = SPDM_MEL_SPECIFICATION_DMTF;
1057 :
1058 1 : spdm_negotiate_algorithms_common_struct_table_t *struct_table =
1059 : (spdm_negotiate_algorithms_common_struct_table_t *)(supported_algorithms + 1);
1060 :
1061 1 : struct_table[0].alg_type =
1062 : SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_DHE;
1063 1 : struct_table[0].alg_count = 0x20;
1064 1 : struct_table[0].alg_supported =
1065 : SPDM_ALGORITHMS_DHE_NAMED_GROUP_SECP_256_R1;
1066 :
1067 1 : struct_table[1].alg_type =
1068 : SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_AEAD;
1069 1 : struct_table[1].alg_count = 0x20;
1070 1 : struct_table[1].alg_supported =
1071 : SPDM_ALGORITHMS_AEAD_CIPHER_SUITE_AES_256_GCM;;
1072 :
1073 1 : struct_table[2].alg_type =
1074 : SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_REQ_BASE_ASYM_ALG;
1075 1 : struct_table[2].alg_count = 0x20;
1076 1 : struct_table[2].alg_supported =
1077 : SPDM_ALGORITHMS_BASE_ASYM_ALGO_TPM_ALG_RSASSA_2048;
1078 :
1079 1 : struct_table[3].alg_type =
1080 : SPDM_NEGOTIATE_ALGORITHMS_STRUCT_TABLE_ALG_TYPE_KEY_SCHEDULE;
1081 1 : struct_table[3].alg_count = 0x20;
1082 1 : struct_table[3].alg_supported =
1083 : SPDM_ALGORITHMS_KEY_SCHEDULE_SPDM;
1084 :
1085 1 : libspdm_transport_test_encode_message(spdm_context, NULL, false,
1086 : false, spdm_response_size,
1087 : spdm_response,
1088 : response_size, response);
1089 : }
1090 1 : return LIBSPDM_STATUS_SUCCESS;
1091 0 : default:
1092 0 : return LIBSPDM_STATUS_RECEIVE_FAIL;
1093 : }
1094 : }
1095 :
1096 : /*
1097 : * static void req_get_capabilities_case1(void **state)
1098 : * {
1099 : * }
1100 : */
1101 :
1102 1 : static void req_get_capabilities_case2(void **state)
1103 : {
1104 : libspdm_return_t status;
1105 : libspdm_test_context_t *spdm_test_context;
1106 : libspdm_context_t *spdm_context;
1107 :
1108 1 : spdm_test_context = *state;
1109 1 : spdm_context = spdm_test_context->spdm_context;
1110 1 : spdm_test_context->case_id = 0x2;
1111 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1112 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1113 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1114 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1115 : spdm_context->transcript.message_m.buffer_size =
1116 : spdm_context->transcript.message_m.max_buffer_size;
1117 : #endif
1118 :
1119 1 : spdm_context->local_context.capability.ct_exponent = 0;
1120 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1121 1 : status = libspdm_get_capabilities(spdm_context);
1122 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1123 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1124 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1125 : LIBSPDM_DEFAULT_CAPABILITY_FLAG);
1126 : #if LIBSPDM_RECORD_TRANSCRIPT_DATA_SUPPORT
1127 : assert_int_equal(spdm_context->transcript.message_m.buffer_size, 0);
1128 : #endif
1129 1 : }
1130 :
1131 : /*
1132 : * static void req_get_capabilities_case3(void **state)
1133 : * {
1134 : * }
1135 : */
1136 :
1137 : /*
1138 : * static void req_get_capabilities_case4(void **state)
1139 : * {
1140 : * }
1141 : */
1142 :
1143 : /*
1144 : * static void req_get_capabilities_case5(void **state)
1145 : * {
1146 : * }
1147 : */
1148 :
1149 1 : static void req_get_capabilities_case6(void **state)
1150 : {
1151 : libspdm_return_t status;
1152 : libspdm_test_context_t *spdm_test_context;
1153 : libspdm_context_t *spdm_context;
1154 :
1155 1 : spdm_test_context = *state;
1156 1 : spdm_context = spdm_test_context->spdm_context;
1157 1 : spdm_test_context->case_id = 0x6;
1158 1 : spdm_context->retry_times = 3;
1159 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1160 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1161 1 : spdm_context->connection_info.connection_state =
1162 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1163 :
1164 1 : spdm_context->local_context.capability.ct_exponent = 0;
1165 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1166 1 : status = libspdm_get_capabilities(spdm_context);
1167 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1168 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1169 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1170 : LIBSPDM_DEFAULT_CAPABILITY_FLAG);
1171 1 : }
1172 :
1173 : /*
1174 : * static void req_get_capabilities_case7(void **state)
1175 : * {
1176 : * }
1177 : */
1178 :
1179 : /*
1180 : * static void req_get_capabilities_case8(void **state)
1181 : * {
1182 : * }
1183 : */
1184 :
1185 : /*
1186 : * static void req_get_capabilities_case9(void **state)
1187 : * {
1188 : * }
1189 : */
1190 :
1191 1 : static void req_get_capabilities_case10(void **state)
1192 : {
1193 : libspdm_return_t status;
1194 : libspdm_test_context_t *spdm_test_context;
1195 : libspdm_context_t *spdm_context;
1196 :
1197 1 : spdm_test_context = *state;
1198 1 : spdm_context = spdm_test_context->spdm_context;
1199 1 : spdm_test_context->case_id = 0xa;
1200 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1201 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1202 1 : spdm_context->connection_info.connection_state =
1203 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1204 :
1205 1 : spdm_context->local_context.capability.ct_exponent = 0;
1206 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1207 1 : status = libspdm_get_capabilities(spdm_context);
1208 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1209 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1210 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1211 : (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
1212 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
1213 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
1214 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
1215 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP));
1216 1 : }
1217 :
1218 1 : static void req_get_capabilities_case11(void **state)
1219 : {
1220 : libspdm_return_t status;
1221 : libspdm_test_context_t *spdm_test_context;
1222 : libspdm_context_t *spdm_context;
1223 :
1224 1 : spdm_test_context = *state;
1225 1 : spdm_context = spdm_test_context->spdm_context;
1226 1 : spdm_test_context->case_id = 0xb;
1227 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1228 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1229 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1230 :
1231 1 : spdm_context->local_context.capability.ct_exponent = 0;
1232 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1233 1 : status = libspdm_get_capabilities(spdm_context);
1234 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1235 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1236 1 : assert_int_equal(
1237 : spdm_context->connection_info.capability.flags,
1238 : !(SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CACHE_CAP |
1239 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
1240 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHAL_CAP |
1241 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG |
1242 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP));
1243 1 : }
1244 :
1245 1 : static void req_get_capabilities_case12(void **state)
1246 : {
1247 : libspdm_return_t status;
1248 : libspdm_test_context_t *spdm_test_context;
1249 : libspdm_context_t *spdm_context;
1250 :
1251 1 : spdm_test_context = *state;
1252 1 : spdm_context = spdm_test_context->spdm_context;
1253 1 : spdm_test_context->case_id = 0xc;
1254 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_10 <<
1255 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1256 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1257 :
1258 1 : spdm_context->local_context.capability.ct_exponent = 0;
1259 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG;
1260 1 : status = libspdm_get_capabilities(spdm_context);
1261 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1262 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1263 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1264 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_NO_SIG |
1265 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_FRESH_CAP);
1266 1 : }
1267 :
1268 : /*
1269 : * static void req_get_capabilities_case13(void **state)
1270 : * {
1271 : * }
1272 : */
1273 :
1274 : /*
1275 : * static void req_get_capabilities_case14(void **state)
1276 : * {
1277 : * }
1278 : */
1279 :
1280 : /*
1281 : * static void req_get_capabilities_case15(void **state)
1282 : * {
1283 : * }
1284 : */
1285 :
1286 1 : static void req_get_capabilities_case16(void **state)
1287 : {
1288 : libspdm_return_t status;
1289 : libspdm_test_context_t *spdm_test_context;
1290 : libspdm_context_t *spdm_context;
1291 :
1292 1 : spdm_test_context = *state;
1293 1 : spdm_context = spdm_test_context->spdm_context;
1294 1 : spdm_test_context->case_id = 0x10;
1295 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1296 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1297 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1298 :
1299 1 : spdm_context->local_context.capability.ct_exponent = 0;
1300 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1301 1 : status = libspdm_get_capabilities(spdm_context);
1302 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1303 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1304 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1305 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11);
1306 1 : }
1307 :
1308 : /*
1309 : * static void req_get_capabilities_case17(void **state)
1310 : * {
1311 : * }
1312 : */
1313 :
1314 : /*
1315 : * static void req_get_capabilities_case18(void **state)
1316 : * {
1317 : * }
1318 : */
1319 :
1320 : /*
1321 : * static void req_get_capabilities_case19(void **state)
1322 : * {
1323 : * }
1324 : */
1325 :
1326 : /*
1327 : * static void req_get_capabilities_case20(void **state)
1328 : * {
1329 : * }
1330 : */
1331 :
1332 : /*
1333 : * static void req_get_capabilities_case21(void **state)
1334 : * {
1335 : * }
1336 : */
1337 :
1338 : /*
1339 : * static void req_get_capabilities_case22(void **state)
1340 : * {
1341 : * }
1342 : */
1343 :
1344 : /*
1345 : * static void req_get_capabilities_case23(void **state)
1346 : * {
1347 : * }
1348 : */
1349 :
1350 : /*
1351 : * static void req_get_capabilities_case24(void **state)
1352 : * {
1353 : * }
1354 : */
1355 :
1356 : /*
1357 : * static void req_get_capabilities_case25(void **state)
1358 : * {
1359 : * }
1360 : */
1361 :
1362 : /*
1363 : * static void req_get_capabilities_case26(void **state)
1364 : * {
1365 : * }
1366 : */
1367 :
1368 : /*
1369 : * static void req_get_capabilities_case27(void **state)
1370 : * {
1371 : * }
1372 : */
1373 :
1374 : /*
1375 : * static void req_get_capabilities_case28(void **state)
1376 : * {
1377 : * }
1378 : */
1379 :
1380 : /*
1381 : * static void req_get_capabilities_case29(void **state)
1382 : * {
1383 : * }
1384 : */
1385 :
1386 : /*
1387 : * static void req_get_capabilities_case30(void **state)
1388 : * {
1389 : * }
1390 : */
1391 :
1392 : /*
1393 : * static void req_get_capabilities_case31(void **state)
1394 : * {
1395 : * }
1396 : */
1397 :
1398 1 : static void req_get_capabilities_case32(void **state)
1399 : {
1400 : libspdm_return_t status;
1401 : libspdm_test_context_t *spdm_test_context;
1402 : libspdm_context_t *spdm_context;
1403 : size_t arbitrary_size;
1404 :
1405 1 : spdm_test_context = *state;
1406 1 : spdm_context = spdm_test_context->spdm_context;
1407 1 : spdm_test_context->case_id = 0x20;
1408 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_11 <<
1409 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1410 1 : spdm_context->connection_info.connection_state =
1411 : LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1412 :
1413 : /*filling A with arbitrary data*/
1414 1 : arbitrary_size = 10;
1415 1 : libspdm_set_mem(spdm_context->transcript.message_a.buffer, arbitrary_size, (uint8_t) 0xFF);
1416 1 : spdm_context->transcript.message_a.buffer_size = arbitrary_size;
1417 :
1418 1 : spdm_context->local_context.capability.ct_exponent = 0;
1419 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_11;
1420 1 : status = libspdm_get_capabilities(spdm_context);
1421 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1422 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1423 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1424 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_11);
1425 1 : libspdm_dump_hex(spdm_context->transcript.message_a.buffer,
1426 : spdm_context->transcript.message_a.buffer_size);
1427 1 : assert_int_equal(spdm_context->transcript.message_a.buffer_size,
1428 : arbitrary_size + m_libspdm_local_buffer_size);
1429 1 : LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "m_libspdm_local_buffer (0x%zx):\n",
1430 : m_libspdm_local_buffer_size));
1431 1 : libspdm_dump_hex(m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1432 1 : assert_memory_equal(spdm_context->transcript.message_a.buffer + arbitrary_size,
1433 : m_libspdm_local_buffer, m_libspdm_local_buffer_size);
1434 1 : }
1435 :
1436 1 : static void req_get_capabilities_case33(void **state)
1437 : {
1438 : libspdm_return_t status;
1439 : libspdm_test_context_t *spdm_test_context;
1440 : libspdm_context_t *spdm_context;
1441 :
1442 1 : spdm_test_context = *state;
1443 1 : spdm_context = spdm_test_context->spdm_context;
1444 1 : spdm_test_context->case_id = 0x21;
1445 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
1446 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1447 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1448 :
1449 1 : spdm_context->local_context.capability.ct_exponent = 0;
1450 1 : spdm_context->local_context.capability.flags = LIBSPDM_DEFAULT_CAPABILITY_FLAG_VERSION_12;
1451 1 : status = libspdm_get_capabilities(spdm_context);
1452 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1453 1 : assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
1454 : LIBSPDM_MAX_SPDM_MSG_SIZE);
1455 1 : assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
1456 : LIBSPDM_DATA_TRANSFER_SIZE);
1457 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1458 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1459 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_12);
1460 1 : }
1461 :
1462 :
1463 : /*
1464 : * static void req_get_capabilities_case34(void **state)
1465 : * {
1466 : * }
1467 : */
1468 :
1469 1 : static void req_get_capabilities_case35(void **state)
1470 : {
1471 : libspdm_return_t status;
1472 : libspdm_test_context_t *spdm_test_context;
1473 : libspdm_context_t *spdm_context;
1474 :
1475 1 : spdm_test_context = *state;
1476 1 : spdm_context = spdm_test_context->spdm_context;
1477 1 : spdm_test_context->case_id = 0x23;
1478 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1479 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1480 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1481 1 : spdm_context->local_context.capability.ct_exponent = 0;
1482 :
1483 1 : status = libspdm_get_capabilities(spdm_context);
1484 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1485 1 : assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
1486 : LIBSPDM_MAX_SPDM_MSG_SIZE);
1487 1 : assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
1488 : LIBSPDM_DATA_TRANSFER_SIZE);
1489 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1490 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1491 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13);
1492 1 : }
1493 :
1494 1 : static void req_get_capabilities_case36(void **state)
1495 : {
1496 : libspdm_return_t status;
1497 : libspdm_test_context_t *spdm_test_context;
1498 : libspdm_context_t *spdm_context;
1499 : uint8_t supported_algs_buffer[1024];
1500 1 : size_t supported_algs_length = sizeof(supported_algs_buffer);
1501 :
1502 1 : spdm_test_context = *state;
1503 1 : spdm_context = spdm_test_context->spdm_context;
1504 1 : spdm_test_context->case_id = 0x24;
1505 1 : spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 <<
1506 : SPDM_VERSION_NUMBER_SHIFT_BIT;
1507 1 : spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_VERSION;
1508 1 : spdm_context->local_context.capability.ct_exponent = 0;
1509 :
1510 1 : spdm_context->local_context.algorithm.measurement_spec = SPDM_MEASUREMENT_SPECIFICATION_DMTF;
1511 1 : spdm_context->local_context.algorithm.other_params_support = 0;
1512 1 : spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
1513 1 : spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
1514 1 : spdm_context->local_context.algorithm.mel_spec = SPDM_MEL_SPECIFICATION_DMTF;
1515 :
1516 1 : spdm_context->connection_info.capability.flags |=
1517 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP;
1518 1 : spdm_context->connection_info.capability.flags |=
1519 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP;
1520 1 : spdm_context->connection_info.capability.flags |=
1521 : SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MUT_AUTH_CAP;
1522 :
1523 1 : spdm_context->local_context.algorithm.dhe_named_group = m_libspdm_use_dhe_algo;
1524 1 : spdm_context->local_context.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo;
1525 1 : spdm_context->local_context.algorithm.req_base_asym_alg = m_libspdm_use_req_asym_algo;
1526 1 : spdm_context->local_context.algorithm.key_schedule = m_libspdm_use_key_schedule_algo;
1527 1 : status = libspdm_get_capabilities_with_supported_algs(spdm_context, &supported_algs_length,
1528 : &supported_algs_buffer);
1529 :
1530 1 : assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
1531 1 : assert_int_equal(spdm_context->connection_info.capability.max_spdm_msg_size,
1532 : LIBSPDM_MAX_SPDM_MSG_SIZE);
1533 1 : assert_int_equal(spdm_context->connection_info.capability.data_transfer_size,
1534 : LIBSPDM_DATA_TRANSFER_SIZE);
1535 1 : assert_int_equal(spdm_context->connection_info.capability.ct_exponent, 0);
1536 1 : assert_int_equal(spdm_context->connection_info.capability.flags,
1537 : LIBSPDM_DEFAULT_CAPABILITY_RESPONSE_FLAG_VERSION_13);
1538 1 : }
1539 :
1540 1 : int libspdm_req_get_capabilities_test(void)
1541 : {
1542 1 : const struct CMUnitTest test_cases[] = {
1543 : /* cmocka_unit_test(req_get_capabilities_case1), */
1544 : cmocka_unit_test(req_get_capabilities_case2),
1545 : /* cmocka_unit_test(req_get_capabilities_case3),
1546 : * cmocka_unit_test(req_get_capabilities_case4),
1547 : * cmocka_unit_test(req_get_capabilities_case5), */
1548 : cmocka_unit_test(req_get_capabilities_case6),
1549 : /* cmocka_unit_test(req_get_capabilities_case7),
1550 : * cmocka_unit_test(req_get_capabilities_case8),
1551 : * cmocka_unit_test(req_get_capabilities_case9), */
1552 : cmocka_unit_test(req_get_capabilities_case10),
1553 : cmocka_unit_test(req_get_capabilities_case11),
1554 : cmocka_unit_test(req_get_capabilities_case12),
1555 : /* cmocka_unit_test(req_get_capabilities_case13),
1556 : * cmocka_unit_test(req_get_capabilities_case14),
1557 : * cmocka_unit_test(req_get_capabilities_case15), */
1558 : cmocka_unit_test(req_get_capabilities_case16),
1559 : /* cmocka_unit_test(req_get_capabilities_case17),
1560 : * cmocka_unit_test(req_get_capabilities_case18),
1561 : * cmocka_unit_test(req_get_capabilities_case19),
1562 : * cmocka_unit_test(req_get_capabilities_case20),
1563 : * cmocka_unit_test(req_get_capabilities_case21),
1564 : * cmocka_unit_test(req_get_capabilities_case22),
1565 : * cmocka_unit_test(req_get_capabilities_case23),
1566 : * cmocka_unit_test(req_get_capabilities_case24),
1567 : * cmocka_unit_test(req_get_capabilities_case25),
1568 : * cmocka_unit_test(req_get_capabilities_case26),
1569 : * cmocka_unit_test(req_get_capabilities_case27),
1570 : * cmocka_unit_test(req_get_capabilities_case28),
1571 : * cmocka_unit_test(req_get_capabilities_case29),
1572 : * cmocka_unit_test(req_get_capabilities_case30),
1573 : * cmocka_unit_test(req_get_capabilities_case31), */
1574 : cmocka_unit_test(req_get_capabilities_case32),
1575 : cmocka_unit_test(req_get_capabilities_case33),
1576 : /* cmocka_unit_test(req_get_capabilities_case34), */
1577 : cmocka_unit_test(req_get_capabilities_case35),
1578 : cmocka_unit_test(req_get_capabilities_case36),
1579 : };
1580 :
1581 1 : libspdm_test_context_t test_context = {
1582 : LIBSPDM_TEST_CONTEXT_VERSION,
1583 : true,
1584 : send_message,
1585 : receive_message,
1586 : };
1587 :
1588 1 : libspdm_setup_test_context(&test_context);
1589 :
1590 1 : return cmocka_run_group_tests(test_cases,
1591 : libspdm_unit_test_group_setup,
1592 : libspdm_unit_test_group_teardown);
1593 : }
|