Skip to content

Commit

Permalink
Add send/receive to spdm_common_lib
Browse files Browse the repository at this point in the history
Once secure session is established, in application phase both SPDM Requester and SPDM Responder can send/receive messages.
Added patch which will enable SPDM Responders also to send message during Appication phase.

Resolves issue: DMTF#2571

Signed-off-by: Prithvi A Pai <prithvi.a.pai@intel.com>
  • Loading branch information
PrithviAPai committed Feb 29, 2024
1 parent e0cda37 commit c9365ea
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 513 deletions.
38 changes: 38 additions & 0 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1716,4 +1716,42 @@ static inline uint64_t libspdm_le_to_be_64(uint64_t value)
((value & 0xff00000000000000) >> 56));
}

/**
* Send an SPDM or an APP request to a device.
*
* @param spdm_context The SPDM context for the device.
* @param session_id Indicate if the request is a secured message.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param request_size Size in bytes of the request data buffer.
* @param request A pointer to a destination buffer to store the request.
* The caller is responsible for having either implicit or explicit ownership
* of the buffer.
* For normal message, requester pointer point to transport_message + transport header size
* For secured message, requester pointer will point to the scratch buffer + transport header size in spdm_context.
**/
libspdm_return_t libspdm_send_request(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
size_t request_size, void *request);

/**
* Receive an SPDM or an APP response from a device.
*
* @param spdm_context The SPDM context for the device.
* @param session_id Indicate if the response is a secured message.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param response_size Size in bytes of the response data buffer.
* @param response A pointer to a destination buffer to store the response.
* The caller is responsible for having either implicit or explicit
* ownership of the buffer.
* For normal message, response pointer still point to original transport_message.
* For secured message, response pointer will point to the scratch buffer in spdm_context.
**/
libspdm_return_t libspdm_receive_response(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
size_t *response_size, void **response);

#endif /* SPDM_COMMON_LIB_INTERNAL_H */
40 changes: 1 addition & 39 deletions include/internal/libspdm_requester_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://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand All @@ -12,44 +12,6 @@
#include "internal/libspdm_common_lib.h"
#include "hal/library/requester/timelib.h"

/**
* Send an SPDM or an APP request to a device.
*
* @param spdm_context The SPDM context for the device.
* @param session_id Indicate if the request is a secured message.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param request_size Size in bytes of the request data buffer.
* @param request A pointer to a destination buffer to store the request.
* The caller is responsible for having either implicit or explicit ownership
* of the buffer.
* For normal message, requester pointer point to transport_message + transport header size
* For secured message, requester pointer will point to the scratch buffer + transport header size in spdm_context.
**/
libspdm_return_t libspdm_send_request(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
size_t request_size, void *request);

/**
* Receive an SPDM or an APP response from a device.
*
* @param spdm_context The SPDM context for the device.
* @param session_id Indicate if the response is a secured message.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param response_size Size in bytes of the response data buffer.
* @param response A pointer to a destination buffer to store the response.
* The caller is responsible for having either implicit or explicit
* ownership of the buffer.
* For normal message, response pointer still point to original transport_message.
* For secured message, response pointer will point to the scratch buffer in spdm_context.
**/
libspdm_return_t libspdm_receive_response(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
size_t *response_size, void **response);

/**
* This function handles simple error code.
*
Expand Down
79 changes: 78 additions & 1 deletion include/library/spdm_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://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

Expand Down Expand Up @@ -1002,4 +1002,81 @@ typedef libspdm_return_t (*libspdm_vendor_response_callback_func)(

#endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */

/**
* Send an SPDM or APP message.
*
* The SPDM message can be a normal message or a secured message in SPDM session.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param request A pointer to the request data.
* @param request_size Size in bytes of the request data.
**/
libspdm_return_t libspdm_send_data(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
const void *request, size_t request_size);

/**
* Receive an SPDM or APP message.
*
* The SPDM message can be a normal message or a secured message in SPDM session.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param response A pointer to the response data.
* @param response_size Size in bytes of the response data.
* On input, it means the size in bytes of response data buffer.
* On output, it means the size in bytes of copied response data buffer if
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
* returned.
**/
libspdm_return_t libspdm_receive_data(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
void *response, size_t *response_size);

/**
* Send and receive an SPDM or APP message.
*
* The SPDM message can be a normal message or a secured message in SPDM session.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param request A pointer to the request data.
* @param request_size Size in bytes of the request data.
* @param response A pointer to the response data.
* @param response_size Size in bytes of the response data.
* On input, it means the size in bytes of response data buffer.
* On output, it means the size in bytes of copied response data buffer if
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
* returned.
**/
libspdm_return_t libspdm_send_receive_data(void *spdm_context,
const uint32_t *session_id,
bool is_app_message,
const void *request, size_t request_size,
void *response, size_t *response_size);

#endif /* SPDM_COMMON_LIB_H */
77 changes: 0 additions & 77 deletions include/library/spdm_requester_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,83 +456,6 @@ libspdm_return_t libspdm_stop_session(void *spdm_context, uint32_t session_id,
uint8_t end_session_attributes);
#endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */

/**
* Send an SPDM or APP message.
*
* The SPDM message can be a normal message or a secured message in SPDM session.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param request A pointer to the request data.
* @param request_size Size in bytes of the request data.
**/
libspdm_return_t libspdm_send_data(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
const void *request, size_t request_size);

/**
* Receive an SPDM or APP message.
*
* The SPDM message can be a normal message or a secured message in SPDM session.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param response A pointer to the response data.
* @param response_size Size in bytes of the response data.
* On input, it means the size in bytes of response data buffer.
* On output, it means the size in bytes of copied response data buffer if
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
* returned.
**/
libspdm_return_t libspdm_receive_data(void *spdm_context, const uint32_t *session_id,
bool is_app_message,
void *response, size_t *response_size);

/**
* Send and receive an SPDM or APP message.
*
* The SPDM message can be a normal message or a secured message in SPDM session.
*
* The APP message is encoded to a secured message directly in SPDM session.
* The APP message format is defined by the transport layer.
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Indicates if it is a secured message protected via SPDM session.
* If session_id is NULL, it is a normal message.
* If session_id is NOT NULL, it is a secured message.
* @param is_app_message Indicates if it is an APP message or SPDM message.
* @param request A pointer to the request data.
* @param request_size Size in bytes of the request data.
* @param response A pointer to the response data.
* @param response_size Size in bytes of the response data.
* On input, it means the size in bytes of response data buffer.
* On output, it means the size in bytes of copied response data buffer if
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
* returned.
**/
libspdm_return_t libspdm_send_receive_data(void *spdm_context,
const uint32_t *session_id,
bool is_app_message,
const void *request, size_t request_size,
void *response, size_t *response_size);

/**
* This function sends HEARTBEAT
* to an SPDM Session.
Expand Down
1 change: 1 addition & 0 deletions library/spdm_common_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SET(src_spdm_common_lib
libspdm_com_opaque_data.c
libspdm_com_support.c
libspdm_com_msg_log.c
libspdm_com_send_receive.c
)

ADD_LIBRARY(spdm_common_lib STATIC ${src_spdm_common_lib})

0 comments on commit c9365ea

Please sign in to comment.