Skip to content

Commit bc2c5e6

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

File tree

9 files changed

+81
-225
lines changed

9 files changed

+81
-225
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
@@ -676,7 +676,6 @@ typedef struct {
676676

677677
#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
678678
libspdm_vendor_response_callback_func vendor_response_callback;
679-
libspdm_vendor_get_id_callback_func vendor_response_get_id;
680679
#endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
681680

682681
#if LIBSPDM_EVENT_RECIPIENT_SUPPORT

include/library/spdm_common_lib.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -945,24 +945,6 @@ bool libspdm_get_fips_mode(void);
945945

946946
#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
947947

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

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
@@ -11,15 +11,6 @@
1111
/* expected number of bytes for VENDOR MESSAGE HEADERS */
1212
#define SPDM_VENDOR_DEFINED_FIXED_HEADER_LEN 7
1313

14-
libspdm_return_t libspdm_register_vendor_get_id_callback_func(void *spdm_context,
15-
libspdm_vendor_get_id_callback_func resp_callback)
16-
{
17-
18-
libspdm_context_t *context = (libspdm_context_t *)spdm_context;
19-
context->vendor_response_get_id = resp_callback;
20-
return LIBSPDM_STATUS_SUCCESS;
21-
}
22-
2314
libspdm_return_t libspdm_register_vendor_callback_func(void *spdm_context,
2415
libspdm_vendor_response_callback_func resp_callback)
2516
{
@@ -79,9 +70,8 @@ libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_con
7970
session_id = &session_info->session_id;
8071
}
8172

82-
/* Check if caller is using the old Vendor Defined API. */
83-
if ((spdm_context->vendor_response_callback == NULL ||
84-
spdm_context->vendor_response_get_id == NULL)) {
73+
/* Check if vendor callback is registered. */
74+
if (spdm_context->vendor_response_callback == NULL) {
8575
if (spdm_context->get_response_func != NULL) {
8676
return ((libspdm_get_response_func)spdm_context->get_response_func)(
8777
spdm_context,
@@ -221,9 +211,13 @@ libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_con
221211
* Len2 bytes Response Payload
222212
*/
223213

224-
/* replace capacity with size */
225-
spdm_response->len = SPDM_MAX_VENDOR_ID_LENGTH;
226-
resp_data = ((uint8_t *)response) + sizeof(spdm_vendor_defined_response_msg_t);
214+
/* Set up pointers for the callback */
215+
spdm_response->standard_id = spdm_request->standard_id;
216+
spdm_response->len = spdm_request->len;
217+
libspdm_copy_mem(((uint8_t *)response) + sizeof(spdm_vendor_defined_response_msg_t),
218+
spdm_request->len,
219+
req_vendor_id,
220+
spdm_request->len);
227221

228222
if (use_large_payload) {
229223
req_data = ((const uint8_t *)request) +
@@ -237,31 +231,29 @@ libspdm_return_t libspdm_get_vendor_defined_response(libspdm_context_t *spdm_con
237231
sizeof(uint16_t);
238232
}
239233

240-
status = spdm_context->vendor_response_get_id(
241-
spdm_context,
242-
session_id,
243-
&spdm_response->standard_id,
244-
&spdm_response->len,
245-
resp_data);
246-
247-
/* move pointer and adjust buffer size */
234+
/* move pointer */
235+
resp_data = ((uint8_t *)response) + header_length;
236+
/* adjust buffer size */
248237
if (use_large_payload) {
249-
resp_data += spdm_response->len + sizeof(uint16_t) + sizeof(uint32_t);
250-
response_capacity -= spdm_response->len + sizeof(uint16_t) + sizeof(uint32_t);
251238
resp_size = (uint32_t)response_capacity;
252239
} else {
253-
resp_data += spdm_response->len + sizeof(uint16_t);
254-
response_capacity -= spdm_response->len + sizeof(uint16_t);
255240
resp_size = (uint16_t)response_capacity;
256241
}
257242

258-
status = spdm_context->vendor_response_callback(spdm_context,
259-
session_id,
260-
spdm_request->standard_id,
261-
spdm_request->len,
262-
req_vendor_id, req_size, req_data,
263-
&resp_size,
264-
resp_data);
243+
status = spdm_context->vendor_response_callback(
244+
spdm_context,
245+
session_id,
246+
spdm_request->standard_id,
247+
spdm_request->len,
248+
req_vendor_id,
249+
req_size,
250+
req_data,
251+
&resp_size,
252+
resp_data);
253+
254+
if (LIBSPDM_STATUS_IS_ERROR(status)) {
255+
return status;
256+
}
265257

266258
/* store back the response payload size */
267259
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: 6 additions & 50 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,
@@ -74,18 +49,15 @@ static libspdm_return_t libspdm_vendor_response_func_err_test(
7449
uint32_t *resp_size,
7550
void *resp_data)
7651
{
77-
/* get pointer to response data payload and populate */
52+
/* Validate required parameters */
53+
if (resp_size == NULL || *resp_size == 0 || req_data == NULL || resp_data == NULL)
54+
return LIBSPDM_STATUS_INVALID_PARAMETER;
55+
56+
/* Set response payload */
7857
uint8_t *resp_payload = (uint8_t *)resp_data;
79-
/* get pointer to response length and populate */
8058
*resp_size = VENDOR_DEFINED_RESPONSE_PAYLOAD_SIZE;
81-
/* store length of response */
8259
libspdm_set_mem(resp_payload, *resp_size, 0xFF);
8360

84-
if (resp_size == NULL || *resp_size == 0)
85-
return LIBSPDM_STATUS_INVALID_PARAMETER;
86-
87-
/* TBD make an error here, like response len 65000, but different this time. */
88-
8961
printf("Got request 0x%x, sent response 0x%x\n",
9062
((const uint8_t*)req_data)[0], ((uint8_t*)resp_data)[0]);
9163

@@ -174,7 +146,6 @@ static void libspdm_test_responder_vendor_cmds_err_case2(void **state)
174146
set_standard_state(spdm_context);
175147

176148
status = libspdm_register_vendor_callback_func(spdm_context, NULL);
177-
status = libspdm_register_vendor_get_id_callback_func(spdm_context, NULL);
178149

179150
request.header.spdm_version = SPDM_MESSAGE_VERSION_10;
180151
request.header.request_response_code = SPDM_VENDOR_DEFINED_REQUEST;
@@ -197,7 +168,7 @@ static void libspdm_test_responder_vendor_cmds_err_case2(void **state)
197168
response_size = sizeof(response_buffer);
198169

199170
status = libspdm_get_vendor_defined_response(spdm_context, sizeof(request),
200-
&request, &response_size, &response_buffer);
171+
request_buffer, &response_size, response_buffer);
201172

202173
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
203174
assert_int_equal(response_size, sizeof(spdm_error_response_t));
@@ -241,9 +212,6 @@ static void libspdm_test_responder_vendor_cmds_err_case3(void **state)
241212
spdm_context->local_context.capability.flags = 0; /* responder not support large payload */
242213
spdm_context->local_context.is_requester = false;
243214

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);
247215
status = libspdm_register_vendor_callback_func(spdm_context,
248216
libspdm_vendor_response_func_err_test);
249217
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -313,9 +281,6 @@ static void libspdm_test_responder_vendor_cmds_err_case4(void **state)
313281
spdm_context->local_context.capability.flags = 0;
314282
spdm_context->local_context.is_requester = false;
315283

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);
319284
status = libspdm_register_vendor_callback_func(spdm_context,
320285
libspdm_vendor_response_func_err_test);
321286
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -382,9 +347,6 @@ static void libspdm_test_responder_vendor_cmds_err_case5(void **state)
382347
spdm_context->local_context.capability.flags = 0;
383348
spdm_context->local_context.is_requester = false;
384349

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);
388350
status = libspdm_register_vendor_callback_func(spdm_context,
389351
libspdm_vendor_response_func_err_test);
390352
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -451,9 +413,6 @@ static void libspdm_test_responder_vendor_cmds_err_case6(void **state)
451413
spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_LARGE_RESP_CAP;
452414
spdm_context->local_context.is_requester = false;
453415

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);
457416
status = libspdm_register_vendor_callback_func(spdm_context,
458417
libspdm_vendor_response_func_err_test);
459418
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);
@@ -523,9 +482,6 @@ static void libspdm_test_responder_vendor_cmds_err_case7(void **state)
523482
spdm_context->local_context.capability.flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_LARGE_RESP_CAP;
524483
spdm_context->local_context.is_requester = false;
525484

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);
529485
status = libspdm_register_vendor_callback_func(spdm_context,
530486
libspdm_vendor_response_func_err_test);
531487
assert_int_equal(status, LIBSPDM_STATUS_SUCCESS);

0 commit comments

Comments
 (0)