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