Skip to content

Commit

Permalink
TDISP enlarge response buffer for error message.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Oct 17, 2024
1 parent c6ebab7 commit c643ad1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
4 changes: 3 additions & 1 deletion include/library/pci_tdisp_common_lib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https:/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand All @@ -14,4 +14,6 @@

#define LIBTDISP_INTERFACE_REPORT_PORTION_LEN 0x40

#define LIBTDISP_ERROR_MESSAGE_MAX_SIZE (sizeof(pci_tdisp_error_response_t))

#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https:/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -29,7 +29,8 @@ libspdm_return_t pci_tdisp_get_interface_state(const void *pci_doe_context,
libspdm_return_t status;
pci_tdisp_get_device_interface_state_request_t request;
size_t request_size;
pci_tdisp_device_interface_state_response_t response;
uint8_t res_buf[LIBTDISP_ERROR_MESSAGE_MAX_SIZE];
pci_tdisp_device_interface_state_response_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand All @@ -38,28 +39,29 @@ libspdm_return_t pci_tdisp_get_interface_state(const void *pci_doe_context,
request.header.interface_id.function_id = interface_id->function_id;

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = pci_tdisp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(pci_tdisp_device_interface_state_response_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.version != request.header.version) {
if (response->header.version != request.header.version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.message_type != PCI_TDISP_DEVICE_INTERFACE_STATE) {
if (response->header.message_type != PCI_TDISP_DEVICE_INTERFACE_STATE) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.interface_id.function_id != request.header.interface_id.function_id) {
if (response->header.interface_id.function_id != request.header.interface_id.function_id) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

*tdi_state = response.tdi_state;
*tdi_state = response->tdi_state;

return LIBSPDM_STATUS_SUCCESS;
}
20 changes: 11 additions & 9 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_get_version.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https:/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -36,7 +36,8 @@ libspdm_return_t pci_tdisp_get_version(const void *pci_doe_context,
libspdm_return_t status;
pci_tdisp_get_version_request_t request;
size_t request_size;
pci_tdisp_version_response_mine_t response;
uint8_t res_buf[LIBTDISP_ERROR_MESSAGE_MAX_SIZE];
pci_tdisp_version_response_mine_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand All @@ -45,31 +46,32 @@ libspdm_return_t pci_tdisp_get_version(const void *pci_doe_context,
request.header.interface_id.function_id = interface_id->function_id;

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = pci_tdisp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(pci_tdisp_version_response_mine_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.version != request.header.version) {
if (response->header.version != request.header.version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.message_type != PCI_TDISP_VERSION) {
if (response->header.message_type != PCI_TDISP_VERSION) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.interface_id.function_id != request.header.interface_id.function_id) {
if (response->header.interface_id.function_id != request.header.interface_id.function_id) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

if (response.version_num_count != 1) {
if (response->version_num_count != 1) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.version_num_entry[0] != PCI_TDISP_MESSAGE_VERSION_10) {
if (response->version_num_entry[0] != PCI_TDISP_MESSAGE_VERSION_10) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down
16 changes: 9 additions & 7 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_start_interface.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https:/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -29,7 +29,8 @@ libspdm_return_t pci_tdisp_start_interface(const void *pci_doe_context,
libspdm_return_t status;
pci_tdisp_start_interface_request_t request;
size_t request_size;
pci_tdisp_start_interface_response_t response;
uint8_t res_buf[LIBTDISP_ERROR_MESSAGE_MAX_SIZE];
pci_tdisp_start_interface_response_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand All @@ -40,10 +41,11 @@ libspdm_return_t pci_tdisp_start_interface(const void *pci_doe_context,
start_interface_nonce, PCI_TDISP_START_INTERFACE_NONCE_SIZE);

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = pci_tdisp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
libspdm_zero_mem (&request.start_interface_nonce, sizeof(request.start_interface_nonce));
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
Expand All @@ -52,13 +54,13 @@ libspdm_return_t pci_tdisp_start_interface(const void *pci_doe_context,
if (response_size != sizeof(pci_tdisp_start_interface_response_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.version != request.header.version) {
if (response->header.version != request.header.version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.message_type != PCI_TDISP_START_INTERFACE_RSP) {
if (response->header.message_type != PCI_TDISP_START_INTERFACE_RSP) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.interface_id.function_id != request.header.interface_id.function_id) {
if (response->header.interface_id.function_id != request.header.interface_id.function_id) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down
16 changes: 9 additions & 7 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_stop_interface.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2022 DMTF. All rights reserved.
* Copyright 2021-2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https:/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -28,7 +28,8 @@ libspdm_return_t pci_tdisp_stop_interface(const void *pci_doe_context,
libspdm_return_t status;
pci_tdisp_stop_interface_request_t request;
size_t request_size;
pci_tdisp_stop_interface_response_t response;
uint8_t res_buf[LIBTDISP_ERROR_MESSAGE_MAX_SIZE];
pci_tdisp_stop_interface_response_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand All @@ -37,24 +38,25 @@ libspdm_return_t pci_tdisp_stop_interface(const void *pci_doe_context,
request.header.interface_id.function_id = interface_id->function_id;

request_size = sizeof(request);
response_size = sizeof(response);
response = (void *)res_buf;
response_size = sizeof(res_buf);
status = pci_tdisp_send_receive_data(spdm_context, session_id,
&request, request_size,
&response, &response_size);
response, &response_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

if (response_size != sizeof(pci_tdisp_stop_interface_response_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}
if (response.header.version != request.header.version) {
if (response->header.version != request.header.version) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.message_type != PCI_TDISP_STOP_INTERFACE_RSP) {
if (response->header.message_type != PCI_TDISP_STOP_INTERFACE_RSP) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (response.header.interface_id.function_id != request.header.interface_id.function_id) {
if (response->header.interface_id.function_id != request.header.interface_id.function_id) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

Expand Down

0 comments on commit c643ad1

Please sign in to comment.