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 M Xu <[email protected]>
  • Loading branch information
mxu9 committed Jul 30, 2024
1 parent 21d720c commit 9da04f1
Show file tree
Hide file tree
Showing 4 changed files with 68 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
45 changes: 44 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,49 @@ 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 uint8_t *message;
libspdm_return_t status;

/*
* Calling libspdm_pci_doe_decode_discovery_request to check the format of transport_message.
* So that the duplicated checking code is skipped.
*/
status = libspdm_pci_doe_decode_discovery_request(transport_message_size, transport_message, NULL);
if(LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

/*
* 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;
}

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 9da04f1

Please sign in to comment.