Skip to content

Commit e4b0193

Browse files
committed
Fix : vendor_response_get_id should not exist
Signed-off-by: Shital Jumbad <[email protected]>
1 parent e9cc874 commit e4b0193

File tree

9 files changed

+68
-211
lines changed

9 files changed

+68
-211
lines changed

doc/user_guide.md

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -453,42 +453,25 @@ Refer to spdm_server_init() in [spdm_responder.c](https://github.com/DMTF/spdm-e
453453
454454
libspdm_register_get_response_func (spdm_context, libspdm_get_response);
455455
```
456-
3.2 This callbacks handle SPDM Vendor Defined Commands
457-
```C
458-
libspdm_return_t libspdm_vendor_get_id_func(
459-
void *spdm_context,
460-
uint16_t *resp_standard_id,
461-
uint8_t *resp_vendor_id_len,
462-
void *resp_vendor_id)
463-
{
464-
// return responder vendor id
465-
...
466-
467-
return LIBSPDM_STATUS_SUCCESS;
468-
}
469-
470-
vendor_response_get_id
471-
libspdm_return_t libspdm_vendor_response_func(
472-
void *spdm_context,
473-
uint16_t req_standard_id,
474-
uint8_t req_vendor_id_len,
475-
const void *req_vendor_id,
476-
uint16_t req_size,
477-
const void *req_data,
478-
uint16_t *resp_size,
479-
void *resp_data)
480-
{
481-
// process request and create response
482-
...
483-
// populate response header and payload
484-
...
485-
486-
return LIBSPDM_STATUS_SUCCESS;
487-
}
456+
3.2 This callback handles SPDM Vendor Defined Commands
457+
```C
458+
libspdm_return_t libspdm_vendor_response_func(
459+
void *spdm_context,
460+
const uint32_t *session_id,
461+
uint16_t req_standard_id,
462+
uint8_t req_vendor_id_len,
463+
const void *req_vendor_id,
464+
uint32_t req_size,
465+
const void *req_data,
466+
uint32_t *resp_size,
467+
void *resp_data)
468+
{
469+
// write payload to resp_data and set *resp_size to payload size
470+
return LIBSPDM_STATUS_SUCCESS;
471+
}
488472
489-
libspdm_register_vendor_get_id_callback_func(spdm_context, libspdm_vendor_get_id_func);
490-
libspdm_register_vendor_callback_func(spdm_context, libspdm_vendor_response_func);
491-
```
473+
libspdm_register_vendor_callback_func(spdm_context, libspdm_vendor_response_func);
474+
```
492475

493476
4. Free the memory of contexts within the SPDM context when all flow is over.
494477
This function does not free the SPDM context itself.

include/internal/libspdm_common_lib.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ typedef struct {
681681

682682
#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
683683
libspdm_vendor_response_callback_func vendor_response_callback;
684-
libspdm_vendor_get_id_callback_func vendor_response_get_id;
685684
#endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
686685

687686
#if LIBSPDM_EVENT_RECIPIENT_SUPPORT

include/library/spdm_common_lib.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -944,24 +944,6 @@ bool libspdm_get_fips_mode(void);
944944

945945
#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
946946

947-
/**
948-
* Vendor Response Get Vendor ID Callback Function Pointer.
949-
* Required to be able to compose the Vendor Defined Response correctly
950-
*
951-
* @param spdm_context A pointer to the SPDM context.
952-
* @param session_id If non-NULL then message is within a secure session.
953-
* If NULL then message is outside a secure session.
954-
* @param resp_standard_id Registry or Standards body used for response
955-
* @param resp_vendor_id_len Length in bytes of the vendor id field for the response
956-
* @param resp_vendor_id Vendor ID assigned by the Registry or Standards Body. Little-endian format
957-
**/
958-
typedef libspdm_return_t (*libspdm_vendor_get_id_callback_func)(
959-
void *spdm_context,
960-
const uint32_t *session_id,
961-
uint16_t *resp_standard_id,
962-
uint8_t *resp_vendor_id_len,
963-
void *resp_vendor_id);
964-
965947
/**
966948
* Vendor Response Callback Function Pointer.
967949
*

include/library/spdm_responder_lib.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -285,26 +285,12 @@ void libspdm_register_cert_chain_buffer(
285285
#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
286286

287287
/**
288-
* This function registers the callback function for getting the Vendor ID for a VENDOR_DEFINED_RESPONSE to the device.
288+
* Register the request-aware vendor-defined response callback.
289289
*
290290
* This is useful for creating unique responses to devices.
291291
*
292292
* @param spdm_context A pointer to the SPDM context.
293-
* @param resp_callback_func Response callback function
294-
*
295-
* @retval LIBSPDM_STATUS_SUCCESS Success
296-
* @retval LIBSPDM_STATUS_INVALID_PARAMETER Some parameters invalid or NULL
297-
**/
298-
libspdm_return_t libspdm_register_vendor_get_id_callback_func(void *spdm_context,
299-
libspdm_vendor_get_id_callback_func resp_callback);
300-
301-
/**
302-
* This function registers the callback function for doing a VENDOR_DEFINED_RESPONSE to the device.
303-
*
304-
* This is useful for creating unique responses to devices.
305-
*
306-
* @param spdm_context A pointer to the SPDM context.
307-
* @param resp_callback_func Response callback function
293+
* @param resp_callback Response callback function
308294
*
309295
* @retval LIBSPDM_STATUS_SUCCESS Success
310296
* @retval LIBSPDM_STATUS_INVALID_PARAMETER Some parameters invalid or NULL

library/spdm_responder_lib/libspdm_rsp_vendor_response.c

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88

99
#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
1010

11-
libspdm_return_t libspdm_register_vendor_get_id_callback_func(void *spdm_context,
12-
libspdm_vendor_get_id_callback_func resp_callback)
13-
{
14-
15-
libspdm_context_t *context = (libspdm_context_t *)spdm_context;
16-
context->vendor_response_get_id = resp_callback;
17-
return LIBSPDM_STATUS_SUCCESS;
18-
}
19-
2011
libspdm_return_t libspdm_register_vendor_callback_func(void *spdm_context,
2112
libspdm_vendor_response_callback_func resp_callback)
2213
{
@@ -76,9 +67,8 @@ libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_con
7667
session_id = &session_info->session_id;
7768
}
7869

79-
/* Check if caller is using the old Vendor Defined API. */
80-
if ((spdm_context->vendor_response_callback == NULL ||
81-
spdm_context->vendor_response_get_id == NULL)) {
70+
/* Check if vendor callback is registered. */
71+
if (spdm_context->vendor_response_callback == NULL) {
8272
if (spdm_context->get_response_func != NULL) {
8373
return ((libspdm_get_response_func)spdm_context->get_response_func)(
8474
spdm_context,
@@ -216,9 +206,13 @@ libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_con
216206
* Len2 bytes Response Payload
217207
*/
218208

219-
/* replace capacity with size */
220-
spdm_response->len = SPDM_MAX_VENDOR_ID_LENGTH;
221-
resp_data = ((uint8_t *)response) + sizeof(spdm_vendor_defined_response_msg_t);
209+
/* Set up pointers for the callback */
210+
spdm_response->standard_id = spdm_request->standard_id;
211+
spdm_response->len = spdm_request->len;
212+
libspdm_copy_mem(((uint8_t *)response) + sizeof(spdm_vendor_defined_response_msg_t),
213+
spdm_request->len,
214+
req_vendor_id,
215+
spdm_request->len);
222216

223217
if (use_large_payload) {
224218
req_data = ((const uint8_t *)request) +
@@ -232,31 +226,29 @@ libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_con
232226
sizeof(uint16_t);
233227
}
234228

235-
status = spdm_context->vendor_response_get_id(
236-
spdm_context,
237-
session_id,
238-
&spdm_response->standard_id,
239-
&spdm_response->len,
240-
resp_data);
241-
242-
/* move pointer and adjust buffer size */
229+
/* move pointer */
230+
resp_data = ((uint8_t *)response) + header_length;
231+
/* adjust buffer size */
243232
if (use_large_payload) {
244-
resp_data += spdm_response->len + sizeof(uint16_t) + sizeof(uint32_t);
245-
response_capacity -= spdm_response->len + sizeof(uint16_t) + sizeof(uint32_t);
246233
resp_size = (uint32_t)response_capacity;
247234
} else {
248-
resp_data += spdm_response->len + sizeof(uint16_t);
249-
response_capacity -= spdm_response->len + sizeof(uint16_t);
250235
resp_size = (uint16_t)response_capacity;
251236
}
252237

253-
status = spdm_context->vendor_response_callback(spdm_context,
254-
session_id,
255-
spdm_request->standard_id,
256-
spdm_request->len,
257-
req_vendor_id, req_size, req_data,
258-
&resp_size,
259-
resp_data);
238+
status = spdm_context->vendor_response_callback(
239+
spdm_context,
240+
session_id,
241+
spdm_request->standard_id,
242+
spdm_request->len,
243+
req_vendor_id,
244+
req_size,
245+
req_data,
246+
&resp_size,
247+
resp_data);
248+
249+
if (LIBSPDM_STATUS_IS_ERROR(status)) {
250+
return status;
251+
}
260252

261253
/* store back the response payload size */
262254
if (use_large_payload) {

unit_test/fuzzing/test_responder/test_spdm_responder_vendor_cmds/vendor_cmds.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ size_t libspdm_get_max_buffer_size(void)
1515
return LIBSPDM_MAX_SPDM_MSG_SIZE;
1616
}
1717

18-
libspdm_return_t libspdm_vendor_get_id_func_test(
19-
void *spdm_context,
20-
const uint32_t *session_id,
21-
uint16_t *resp_standard_id,
22-
uint8_t *resp_vendor_id_len,
23-
void *resp_vendor_id)
24-
{
25-
return LIBSPDM_STATUS_SUCCESS;
26-
}
27-
2818
libspdm_return_t libspdm_vendor_response_func_test(
2919
void *spdm_context,
3020
const uint32_t *session_id,
@@ -36,6 +26,12 @@ libspdm_return_t libspdm_vendor_response_func_test(
3626
uint32_t *resp_size,
3727
void *resp_data)
3828
{
29+
/* Validate required parameters */
30+
if (resp_size == NULL || resp_data == NULL)
31+
return LIBSPDM_STATUS_INVALID_PARAMETER;
32+
33+
/* Set response payload */
34+
*resp_size = 0;
3935
return LIBSPDM_STATUS_SUCCESS;
4036
}
4137

@@ -59,8 +55,6 @@ void libspdm_test_responder_vendor_cmds_case1(void **State)
5955
LIBSPDM_CONNECTION_STATE_NEGOTIATED;
6056
spdm_context->local_context.is_requester = true;
6157

62-
libspdm_register_vendor_get_id_callback_func(spdm_context,
63-
libspdm_vendor_get_id_func_test);
6458
libspdm_register_vendor_callback_func(spdm_context,
6559
libspdm_vendor_response_func_test);
6660

unit_test/test_spdm_responder/error_test/vendor_response_err.c

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,6 @@ static void set_standard_state(libspdm_context_t *spdm_context)
3838
spdm_context->response_state = LIBSPDM_RESPONSE_STATE_NORMAL;
3939
}
4040

41-
static libspdm_return_t libspdm_vendor_get_id_func_err_test(
42-
void *spdm_context,
43-
const uint32_t *session_id,
44-
uint16_t *resp_standard_id,
45-
uint8_t *resp_vendor_id_len,
46-
void *resp_vendor_id)
47-
{
48-
if (resp_standard_id == NULL ||
49-
resp_vendor_id_len == NULL ||
50-
resp_vendor_id == NULL)
51-
return LIBSPDM_STATUS_INVALID_PARAMETER;
52-
53-
/* vendor id length in bytes */
54-
if (*resp_vendor_id_len < 2)
55-
return LIBSPDM_STATUS_INVALID_PARAMETER;
56-
57-
*resp_standard_id = 6;
58-
/* vendor id length in bytes */
59-
*resp_vendor_id_len = 2;
60-
((uint8_t*)resp_vendor_id)[0] = 0xAA;
61-
((uint8_t*)resp_vendor_id)[1] = 0xAA;
62-
63-
return LIBSPDM_STATUS_SUCCESS;
64-
}
65-
6641
static libspdm_return_t libspdm_vendor_response_func_err_test(
6742
void *spdm_context,
6843
const uint32_t *session_id,
@@ -84,8 +59,6 @@ static libspdm_return_t libspdm_vendor_response_func_err_test(
8459
if (resp_size == NULL || *resp_size == 0)
8560
return LIBSPDM_STATUS_INVALID_PARAMETER;
8661

87-
/* TBD make an error here, like response len 65000, but different this time. */
88-
8962
printf("Got request 0x%x, sent response 0x%x\n",
9063
((const uint8_t*)req_data)[0], ((uint8_t*)resp_data)[0]);
9164

@@ -174,7 +147,6 @@ static void libspdm_test_responder_vendor_cmds_err_case2(void **state)
174147
set_standard_state(spdm_context);
175148

176149
status = libspdm_register_vendor_callback_func(spdm_context, NULL);
177-
status = libspdm_register_vendor_get_id_callback_func(spdm_context, NULL);
178150

179151
request.header.spdm_version = SPDM_MESSAGE_VERSION_10;
180152
request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
@@ -197,7 +169,7 @@ static void libspdm_test_responder_vendor_cmds_err_case2(void **state)
197169
response_size = sizeof(response_buffer);
198170

199171
status = libspdm_get_vendor_defined_response(spdm_context, sizeof(request),
200-
&request, &response_size, &response_buffer);
172+
request_buffer, &response_size, response_buffer);
201173

202174
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
203175
assert_int_equal(response_size, sizeof(spdm_error_response_t));
@@ -241,9 +213,6 @@ static void libspdm_test_responder_vendor_cmds_err_case3(void **state)
241213
spdm_context->local_context.capability.flags = 0; /* responder not support large payload */
242214
spdm_context->local_context.is_requester = false;
243215

244-
status = libspdm_register_vendor_get_id_callback_func(spdm_context,
245-
libspdm_vendor_get_id_func_err_test);
246-
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
247216
status = libspdm_register_vendor_callback_func(spdm_context,
248217
libspdm_vendor_response_func_err_test);
249218
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -313,9 +282,6 @@ static void libspdm_test_responder_vendor_cmds_err_case4(void **state)
313282
spdm_context->local_context.capability.flags = 0;
314283
spdm_context->local_context.is_requester = false;
315284

316-
status = libspdm_register_vendor_get_id_callback_func(spdm_context,
317-
libspdm_vendor_get_id_func_err_test);
318-
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
319285
status = libspdm_register_vendor_callback_func(spdm_context,
320286
libspdm_vendor_response_func_err_test);
321287
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -382,9 +348,6 @@ static void libspdm_test_responder_vendor_cmds_err_case5(void **state)
382348
spdm_context->local_context.capability.flags = 0;
383349
spdm_context->local_context.is_requester = false;
384350

385-
status = libspdm_register_vendor_get_id_callback_func(spdm_context,
386-
libspdm_vendor_get_id_func_err_test);
387-
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
388351
status = libspdm_register_vendor_callback_func(spdm_context,
389352
libspdm_vendor_response_func_err_test);
390353
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -451,9 +414,6 @@ static void libspdm_test_responder_vendor_cmds_err_case6(void **state)
451414
spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_LARGE_RESP_CAP;
452415
spdm_context->local_context.is_requester = false;
453416

454-
status = libspdm_register_vendor_get_id_callback_func(spdm_context,
455-
libspdm_vendor_get_id_func_err_test);
456-
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
457417
status = libspdm_register_vendor_callback_func(spdm_context,
458418
libspdm_vendor_response_func_err_test);
459419
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -523,9 +483,6 @@ static void libspdm_test_responder_vendor_cmds_err_case7(void **state)
523483
spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_LARGE_RESP_CAP;
524484
spdm_context->local_context.is_requester = false;
525485

526-
status = libspdm_register_vendor_get_id_callback_func(spdm_context,
527-
libspdm_vendor_get_id_func_err_test);
528-
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
529486
status = libspdm_register_vendor_callback_func(spdm_context,
530487
libspdm_vendor_response_func_err_test);
531488
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);

unit_test/test_spdm_responder/receive_send.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ typedef struct {
2222
/* uint8_t vendor_defined_payload[payload_length];*/
2323
} my_spdm_vendor_defined_request_msg_t;
2424

25-
libspdm_return_t my_test_get_vendor_id_func(
26-
void *spdm_context,
27-
const uint32_t *session_id,
28-
uint16_t *resp_standard_id,
29-
uint8_t *resp_vendor_id_len,
30-
void *resp_vendor_id)
31-
{
32-
*resp_standard_id = 6;
33-
*resp_vendor_id_len = 2;
34-
((uint8_t*)resp_vendor_id)[0] = 0xAA;
35-
((uint8_t*)resp_vendor_id)[1] = 0xAA;
36-
37-
return LIBSPDM_STATUS_SUCCESS;
38-
}
3925

4026
libspdm_return_t my_test_get_response_func(
4127
void *spdm_context, const uint32_t *session_id, bool is_app_message,
@@ -340,7 +326,6 @@ void libspdm_test_responder_receive_send_rsp_case3(void** state)
340326
libspdm_zero_mem(response, response_size);
341327

342328
/* Make response message size greater than the sending transmit buffer size of responder */
343-
libspdm_register_vendor_get_id_callback_func(spdm_context, my_test_get_vendor_id_func);
344329
libspdm_register_vendor_callback_func(spdm_context, my_test_get_response_func2);
345330

346331
status = libspdm_build_response(spdm_context, NULL, false,

0 commit comments

Comments
 (0)