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 <jiewen.yao@intel.com>
  • Loading branch information
jyao1 committed Oct 17, 2024
1 parent c6ebab7 commit 6b2fd0f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
2 changes: 2 additions & 0 deletions include/library/pci_tdisp_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

#define LIBTDISP_INTERFACE_REPORT_PORTION_LEN 0x40

#define LIBTDISP_ERROR_MESSAGE_MAX_SIZE (sizeof(pci_tdisp_error_response_t))

#endif
16 changes: 9 additions & 7 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_get_capabilities.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ libspdm_return_t pci_tdisp_get_capabilities(const void *pci_doe_context,
libspdm_return_t status;
pci_tdisp_get_capabilities_request_t request;
size_t request_size;
pci_tdisp_capabilities_response_t response;
uint8_t res_buf[LIBTDISP_ERROR_MESSAGE_MAX_SIZE];
pci_tdisp_capabilities_response_t *response;
size_t response_size;

libspdm_zero_mem (&request, sizeof(request));
Expand All @@ -40,28 +41,29 @@ libspdm_return_t pci_tdisp_get_capabilities(const void *pci_doe_context,
libspdm_copy_mem (&request.req_caps, sizeof(request.req_caps), req_caps, sizeof(*req_caps));

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_capabilities_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_CAPABILITIES) {
if (response->header.message_type != PCI_TDISP_CAPABILITIES) {
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;
}

libspdm_copy_mem (rsp_caps, sizeof(*rsp_caps), &response.rsp_caps, sizeof(response.rsp_caps));
libspdm_copy_mem (rsp_caps, sizeof(*rsp_caps), &response->rsp_caps, sizeof(response->rsp_caps));

return LIBSPDM_STATUS_SUCCESS;
}
Original file line number Diff line number Diff line change
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;
}
18 changes: 10 additions & 8 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_get_version.c
Original file line number Diff line number Diff line change
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
14 changes: 8 additions & 6 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_start_interface.c
Original file line number Diff line number Diff line change
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
14 changes: 8 additions & 6 deletions library/pci_tdisp_requester_lib/pci_tdisp_req_stop_interface.c
Original file line number Diff line number Diff line change
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 6b2fd0f

Please sign in to comment.