Skip to content

Commit c9365ea

Browse files
committed
Add send/receive to spdm_common_lib
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: #2571 Signed-off-by: Prithvi A Pai <[email protected]>
1 parent e0cda37 commit c9365ea

File tree

8 files changed

+522
-513
lines changed

8 files changed

+522
-513
lines changed

include/internal/libspdm_common_lib.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,4 +1716,42 @@ static inline uint64_t libspdm_le_to_be_64(uint64_t value)
17161716
((value & 0xff00000000000000) >> 56));
17171717
}
17181718

1719+
/**
1720+
* Send an SPDM or an APP request to a device.
1721+
*
1722+
* @param spdm_context The SPDM context for the device.
1723+
* @param session_id Indicate if the request is a secured message.
1724+
* If session_id is NULL, it is a normal message.
1725+
* If session_id is NOT NULL, it is a secured message.
1726+
* @param is_app_message Indicates if it is an APP message or SPDM message.
1727+
* @param request_size Size in bytes of the request data buffer.
1728+
* @param request A pointer to a destination buffer to store the request.
1729+
* The caller is responsible for having either implicit or explicit ownership
1730+
* of the buffer.
1731+
* For normal message, requester pointer point to transport_message + transport header size
1732+
* For secured message, requester pointer will point to the scratch buffer + transport header size in spdm_context.
1733+
**/
1734+
libspdm_return_t libspdm_send_request(void *spdm_context, const uint32_t *session_id,
1735+
bool is_app_message,
1736+
size_t request_size, void *request);
1737+
1738+
/**
1739+
* Receive an SPDM or an APP response from a device.
1740+
*
1741+
* @param spdm_context The SPDM context for the device.
1742+
* @param session_id Indicate if the response is a secured message.
1743+
* If session_id is NULL, it is a normal message.
1744+
* If session_id is NOT NULL, it is a secured message.
1745+
* @param is_app_message Indicates if it is an APP message or SPDM message.
1746+
* @param response_size Size in bytes of the response data buffer.
1747+
* @param response A pointer to a destination buffer to store the response.
1748+
* The caller is responsible for having either implicit or explicit
1749+
* ownership of the buffer.
1750+
* For normal message, response pointer still point to original transport_message.
1751+
* For secured message, response pointer will point to the scratch buffer in spdm_context.
1752+
**/
1753+
libspdm_return_t libspdm_receive_response(void *spdm_context, const uint32_t *session_id,
1754+
bool is_app_message,
1755+
size_t *response_size, void **response);
1756+
17191757
#endif /* SPDM_COMMON_LIB_INTERNAL_H */

include/internal/libspdm_requester_lib.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2022 DMTF. All rights reserved.
3+
* Copyright 2021-2024 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -12,44 +12,6 @@
1212
#include "internal/libspdm_common_lib.h"
1313
#include "hal/library/requester/timelib.h"
1414

15-
/**
16-
* Send an SPDM or an APP request to a device.
17-
*
18-
* @param spdm_context The SPDM context for the device.
19-
* @param session_id Indicate if the request is a secured message.
20-
* If session_id is NULL, it is a normal message.
21-
* If session_id is NOT NULL, it is a secured message.
22-
* @param is_app_message Indicates if it is an APP message or SPDM message.
23-
* @param request_size Size in bytes of the request data buffer.
24-
* @param request A pointer to a destination buffer to store the request.
25-
* The caller is responsible for having either implicit or explicit ownership
26-
* of the buffer.
27-
* For normal message, requester pointer point to transport_message + transport header size
28-
* For secured message, requester pointer will point to the scratch buffer + transport header size in spdm_context.
29-
**/
30-
libspdm_return_t libspdm_send_request(void *spdm_context, const uint32_t *session_id,
31-
bool is_app_message,
32-
size_t request_size, void *request);
33-
34-
/**
35-
* Receive an SPDM or an APP response from a device.
36-
*
37-
* @param spdm_context The SPDM context for the device.
38-
* @param session_id Indicate if the response is a secured message.
39-
* If session_id is NULL, it is a normal message.
40-
* If session_id is NOT NULL, it is a secured message.
41-
* @param is_app_message Indicates if it is an APP message or SPDM message.
42-
* @param response_size Size in bytes of the response data buffer.
43-
* @param response A pointer to a destination buffer to store the response.
44-
* The caller is responsible for having either implicit or explicit
45-
* ownership of the buffer.
46-
* For normal message, response pointer still point to original transport_message.
47-
* For secured message, response pointer will point to the scratch buffer in spdm_context.
48-
**/
49-
libspdm_return_t libspdm_receive_response(void *spdm_context, const uint32_t *session_id,
50-
bool is_app_message,
51-
size_t *response_size, void **response);
52-
5315
/**
5416
* This function handles simple error code.
5517
*

include/library/spdm_common_lib.h

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Copyright Notice:
3-
* Copyright 2021-2022 DMTF. All rights reserved.
3+
* Copyright 2021-2024 DMTF. All rights reserved.
44
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
55
**/
66

@@ -1002,4 +1002,81 @@ typedef libspdm_return_t (*libspdm_vendor_response_callback_func)(
10021002

10031003
#endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
10041004

1005+
/**
1006+
* Send an SPDM or APP message.
1007+
*
1008+
* The SPDM message can be a normal message or a secured message in SPDM session.
1009+
*
1010+
* The APP message is encoded to a secured message directly in SPDM session.
1011+
* The APP message format is defined by the transport layer.
1012+
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
1013+
*
1014+
* @param spdm_context A pointer to the SPDM context.
1015+
* @param session_id Indicates if it is a secured message protected via SPDM session.
1016+
* If session_id is NULL, it is a normal message.
1017+
* If session_id is NOT NULL, it is a secured message.
1018+
* @param is_app_message Indicates if it is an APP message or SPDM message.
1019+
* @param request A pointer to the request data.
1020+
* @param request_size Size in bytes of the request data.
1021+
**/
1022+
libspdm_return_t libspdm_send_data(void *spdm_context, const uint32_t *session_id,
1023+
bool is_app_message,
1024+
const void *request, size_t request_size);
1025+
1026+
/**
1027+
* Receive an SPDM or APP message.
1028+
*
1029+
* The SPDM message can be a normal message or a secured message in SPDM session.
1030+
*
1031+
* The APP message is encoded to a secured message directly in SPDM session.
1032+
* The APP message format is defined by the transport layer.
1033+
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
1034+
*
1035+
* @param spdm_context A pointer to the SPDM context.
1036+
* @param session_id Indicates if it is a secured message protected via SPDM session.
1037+
* If session_id is NULL, it is a normal message.
1038+
* If session_id is NOT NULL, it is a secured message.
1039+
* @param is_app_message Indicates if it is an APP message or SPDM message.
1040+
* @param response A pointer to the response data.
1041+
* @param response_size Size in bytes of the response data.
1042+
* On input, it means the size in bytes of response data buffer.
1043+
* On output, it means the size in bytes of copied response data buffer if
1044+
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
1045+
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
1046+
* returned.
1047+
**/
1048+
libspdm_return_t libspdm_receive_data(void *spdm_context, const uint32_t *session_id,
1049+
bool is_app_message,
1050+
void *response, size_t *response_size);
1051+
1052+
/**
1053+
* Send and receive an SPDM or APP message.
1054+
*
1055+
* The SPDM message can be a normal message or a secured message in SPDM session.
1056+
*
1057+
* The APP message is encoded to a secured message directly in SPDM session.
1058+
* The APP message format is defined by the transport layer.
1059+
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
1060+
*
1061+
* @param spdm_context A pointer to the SPDM context.
1062+
* @param session_id Indicates if it is a secured message protected via SPDM session.
1063+
* If session_id is NULL, it is a normal message.
1064+
* If session_id is NOT NULL, it is a secured message.
1065+
* @param is_app_message Indicates if it is an APP message or SPDM message.
1066+
* @param request A pointer to the request data.
1067+
* @param request_size Size in bytes of the request data.
1068+
* @param response A pointer to the response data.
1069+
* @param response_size Size in bytes of the response data.
1070+
* On input, it means the size in bytes of response data buffer.
1071+
* On output, it means the size in bytes of copied response data buffer if
1072+
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
1073+
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
1074+
* returned.
1075+
**/
1076+
libspdm_return_t libspdm_send_receive_data(void *spdm_context,
1077+
const uint32_t *session_id,
1078+
bool is_app_message,
1079+
const void *request, size_t request_size,
1080+
void *response, size_t *response_size);
1081+
10051082
#endif /* SPDM_COMMON_LIB_H */

include/library/spdm_requester_lib.h

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -456,83 +456,6 @@ libspdm_return_t libspdm_stop_session(void *spdm_context, uint32_t session_id,
456456
uint8_t end_session_attributes);
457457
#endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
458458

459-
/**
460-
* Send an SPDM or APP message.
461-
*
462-
* The SPDM message can be a normal message or a secured message in SPDM session.
463-
*
464-
* The APP message is encoded to a secured message directly in SPDM session.
465-
* The APP message format is defined by the transport layer.
466-
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
467-
*
468-
* @param spdm_context A pointer to the SPDM context.
469-
* @param session_id Indicates if it is a secured message protected via SPDM session.
470-
* If session_id is NULL, it is a normal message.
471-
* If session_id is NOT NULL, it is a secured message.
472-
* @param is_app_message Indicates if it is an APP message or SPDM message.
473-
* @param request A pointer to the request data.
474-
* @param request_size Size in bytes of the request data.
475-
**/
476-
libspdm_return_t libspdm_send_data(void *spdm_context, const uint32_t *session_id,
477-
bool is_app_message,
478-
const void *request, size_t request_size);
479-
480-
/**
481-
* Receive an SPDM or APP message.
482-
*
483-
* The SPDM message can be a normal message or a secured message in SPDM session.
484-
*
485-
* The APP message is encoded to a secured message directly in SPDM session.
486-
* The APP message format is defined by the transport layer.
487-
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
488-
*
489-
* @param spdm_context A pointer to the SPDM context.
490-
* @param session_id Indicates if it is a secured message protected via SPDM session.
491-
* If session_id is NULL, it is a normal message.
492-
* If session_id is NOT NULL, it is a secured message.
493-
* @param is_app_message Indicates if it is an APP message or SPDM message.
494-
* @param response A pointer to the response data.
495-
* @param response_size Size in bytes of the response data.
496-
* On input, it means the size in bytes of response data buffer.
497-
* On output, it means the size in bytes of copied response data buffer if
498-
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
499-
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
500-
* returned.
501-
**/
502-
libspdm_return_t libspdm_receive_data(void *spdm_context, const uint32_t *session_id,
503-
bool is_app_message,
504-
void *response, size_t *response_size);
505-
506-
/**
507-
* Send and receive an SPDM or APP message.
508-
*
509-
* The SPDM message can be a normal message or a secured message in SPDM session.
510-
*
511-
* The APP message is encoded to a secured message directly in SPDM session.
512-
* The APP message format is defined by the transport layer.
513-
* Take MCTP as example: APP message == MCTP header (MCTP_MESSAGE_TYPE_SPDM) + SPDM message
514-
*
515-
* @param spdm_context A pointer to the SPDM context.
516-
* @param session_id Indicates if it is a secured message protected via SPDM session.
517-
* If session_id is NULL, it is a normal message.
518-
* If session_id is NOT NULL, it is a secured message.
519-
* @param is_app_message Indicates if it is an APP message or SPDM message.
520-
* @param request A pointer to the request data.
521-
* @param request_size Size in bytes of the request data.
522-
* @param response A pointer to the response data.
523-
* @param response_size Size in bytes of the response data.
524-
* On input, it means the size in bytes of response data buffer.
525-
* On output, it means the size in bytes of copied response data buffer if
526-
* LIBSPDM_STATUS_SUCCESS is returned, and means the size in bytes of
527-
* desired response data buffer if LIBSPDM_STATUS_BUFFER_TOO_SMALL is
528-
* returned.
529-
**/
530-
libspdm_return_t libspdm_send_receive_data(void *spdm_context,
531-
const uint32_t *session_id,
532-
bool is_app_message,
533-
const void *request, size_t request_size,
534-
void *response, size_t *response_size);
535-
536459
/**
537460
* This function sends HEARTBEAT
538461
* to an SPDM Session.

library/spdm_common_lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ SET(src_spdm_common_lib
1010
libspdm_com_opaque_data.c
1111
libspdm_com_support.c
1212
libspdm_com_msg_log.c
13+
libspdm_com_send_receive.c
1314
)
1415

1516
ADD_LIBRARY(spdm_common_lib STATIC ${src_spdm_common_lib})

0 commit comments

Comments
 (0)