Skip to content

Commit

Permalink
Add DOE Discovery Version
Browse files Browse the repository at this point in the history
DOE Discovery Version is first introduced in PCIE Spec 6.1 Section
6.30.1.1.

libspdm_pci_doe_decode_discovery_request is unchanged. New API
libspdm_pci_doe_decode_discovery_request_version is added to get the
version from doe_discovery_request. This is to prevent the building
broken for the exsting codes.

Signed-off-by: Min Xu <[email protected]>
  • Loading branch information
mxu9 committed Jul 30, 2024
1 parent 21d720c commit b641bcc
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
3 changes: 2 additions & 1 deletion include/industry_standard/pcidoe.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ typedef struct {

typedef struct {
uint8_t index;
uint8_t reserved[3];
uint8_t version;
uint8_t reserved[2];
} pci_doe_discovery_request_t;

typedef struct {
Expand Down
16 changes: 16 additions & 0 deletions include/library/spdm_transport_pcidoe_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ libspdm_return_t libspdm_transport_pci_doe_decode_message(
libspdm_return_t libspdm_pci_doe_decode_discovery_request(size_t transport_message_size,
const void *transport_message,
uint8_t *index);

/**
* Decode a DOE discovery request message to get the DOE Discovery Version field.
* DOE Discovery Version is introduced in PCIE Spec 6.1 Section 6.30.1.1.
*
* @param transport_message_size Size in bytes of the transport message data buffer.
* @param transport_message A pointer to a source buffer to store the transport message.
* @param version A pointer to a destination to store the DOE Discovery Version.
*
* @retval LIBSPDM_STATUS_SUCCESS The message is encoded successfully.
* @retval LIBSPDM_STATUS_INVALID_PARAMETER The message is NULL or the message_size is zero.
**/
libspdm_return_t libspdm_pci_doe_decode_discovery_request_version(size_t transport_message_size,
const void *transport_message,
uint8_t *version);

/**
* Decode a DOE discovery response message.
*
Expand Down
68 changes: 67 additions & 1 deletion library/spdm_transport_pcidoe_lib/libspdm_doe_pcidoe.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://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -301,6 +301,72 @@ libspdm_return_t libspdm_pci_doe_decode_discovery_request(size_t transport_messa
return LIBSPDM_STATUS_SUCCESS;
}

/**
* Decode a DOE discovery request message to get the DOE Discovery Version field.
* DOE Discovery Version is introduced in PCIE Spec 6.1 Section 6.30.1.1.
*
* @param transport_message_size Size in bytes of the transport message data buffer.
* @param transport_message A pointer to a source buffer to store the transport message.
* @param version A pointer to a destination to store the DOE Discovery Version.
*
* @retval LIBSPDM_STATUS_SUCCESS The message is encoded successfully.
* @retval LIBSPDM_STATUS_INVALID_PARAMETER The message is NULL or the message_size is zero.
**/
libspdm_return_t libspdm_pci_doe_decode_discovery_request_version(size_t transport_message_size,
const void *transport_message,
uint8_t *version)
{
const pci_doe_data_object_header_t *pci_doe_header;
uint32_t length;
const uint8_t *message;

LIBSPDM_ASSERT(transport_message_size > sizeof(pci_doe_data_object_header_t));
if (transport_message_size <= sizeof(pci_doe_data_object_header_t)) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}

pci_doe_header = transport_message;
if (pci_doe_header->vendor_id != PCI_DOE_VENDOR_ID_PCISIG) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}

switch (pci_doe_header->data_object_type) {
case PCI_DOE_DATA_OBJECT_TYPE_DOE_DISCOVERY:
/*
* Check to see if we received a DOE discovery message.
* DOE discovery is not part of the SPDM spec, instead it's part
* of the PCIe DOE spec. DOE discovery is mandatory for all
* implementations.
*
* DOE Discovery Version is introduced in PCIE Spec 6.1 Section 6.30.1.1.
* It is Byte-1 in DOE discovery request.
*/
message = (const uint8_t *)transport_message + sizeof(pci_doe_data_object_header_t) + 1;
if (version != NULL) {
*version = *message;
}
break;
default:
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
}

if (pci_doe_header->reserved != 0) {
return LIBSPDM_STATUS_INVALID_MSG_FIELD;
}
if (pci_doe_header->length >= PCI_DOE_MAX_SIZE_IN_DW) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
} else if (pci_doe_header->length == 0) {
length = PCI_DOE_MAX_SIZE_IN_BYTE;
} else {
length = pci_doe_header->length * sizeof(uint32_t);
}
if (length != transport_message_size) {
return LIBSPDM_STATUS_INVALID_MSG_SIZE;
}

return LIBSPDM_STATUS_SUCCESS;
}

libspdm_return_t libspdm_pci_doe_decode_discovery_response(size_t transport_message_size,
void *transport_message,
uint16_t *vendor_id,
Expand Down
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://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -52,10 +52,15 @@ void libspdm_test_transport_pci_doe_decode_discovery(void **State)

if (is_requester) {
uint8_t index = 0;
uint8_t version = 0;

libspdm_pci_doe_decode_discovery_request(spdm_test_context->test_buffer_size,
spdm_test_context->test_buffer,
&index);

libspdm_pci_doe_decode_discovery_request_version(spdm_test_context->test_buffer_size,
spdm_test_context->test_buffer,
&version);
} else {
uint16_t vendor_id = 0;
uint8_t protocol = 0;
Expand Down

0 comments on commit b641bcc

Please sign in to comment.