Skip to content

Commit

Permalink
Initial commit for GET_SUPPORTED_EVENT_TYPES
Browse files Browse the repository at this point in the history
This commit implements the basic functionality for the Requester portion of  `GET_SUPPORTED_EVENT_TYPES` / `SUPPORTED_EVENT_TYPES`. It includes simple unit tests that are to be fleshed out later on.

Signed-off-by: Steven Bellock <[email protected]>
  • Loading branch information
steven-bellock committed Mar 7, 2024
1 parent 425345b commit c0eaae4
Show file tree
Hide file tree
Showing 8 changed files with 804 additions and 2 deletions.
28 changes: 27 additions & 1 deletion include/industry_standard/spdm.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 @@ -54,6 +54,9 @@
#define SPDM_CHUNK_SEND_ACK 0x05
#define SPDM_CHUNK_RESPONSE 0x06

/* SPDM response code (1.3) */
#define SPDM_SUPPORTED_EVENT_TYPES 0x62

/* SPDM request code (1.0) */
#define SPDM_GET_DIGESTS 0x81
#define SPDM_GET_CERTIFICATE 0x82
Expand Down Expand Up @@ -82,6 +85,9 @@
#define SPDM_CHUNK_SEND 0x85
#define SPDM_CHUNK_GET 0x86

/* SPDM request code (1.3) */
#define SPDM_GET_SUPPORTED_EVENT_TYPES 0xE2

/* SPDM message header*/
typedef struct {
uint8_t spdm_version;
Expand Down Expand Up @@ -1151,6 +1157,20 @@ typedef struct {

#define SPDM_CHUNK_GET_RESPONSE_ATTRIBUTE_LAST_CHUNK (1 << 0)

typedef struct {
spdm_message_header_t header;
/* param1 == RSVD
* param2 == RSVD */
} spdm_get_supported_event_types_request_t;

typedef struct {
spdm_message_header_t header;
/* param1 == EventGroupCount
* param2 == RSVD */
uint32_t supported_event_groups_list_len;
/* uint8_t supported_event_groups_list[supported_event_groups_list_len] */
} spdm_supported_event_types_response_t;

#pragma pack()

#define SPDM_VERSION_1_1_BIN_CONCAT_LABEL "spdm1.1 "
Expand Down Expand Up @@ -1197,4 +1217,10 @@ typedef struct {
#define SPDM_OID_DMTF_SPDM_EXTENSION \
{ /*0x06, 0x0A,*/ 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1C, 0x82, 0x12, 0x06 }

/* DMTF Event Type IDs */
#define SPDM_DMTF_EVENT_TYPE_EVENT_LOST 1
#define SPDM_DMTF_EVENT_TYPE_MEASUREMENT_CHANGED 2
#define SPDM_DMTF_EVENT_TYPE_MEASUREMENT_PRE_UPDATE 3
#define SPDM_DMTF_EVENT_TYPE_CERTIFICATE_CHANGED 4

#endif /* SPDM_H */
5 changes: 4 additions & 1 deletion library/spdm_common_lib/libspdm_com_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const char *libspdm_get_code_str(uint8_t request_code)
{ SPDM_SET_CERTIFICATE_RSP, "SPDM_SET_CERTIFICATE_RSP" },
{ SPDM_CHUNK_SEND_ACK, "SPDM_CHUNK_SEND_ACK" },
{ SPDM_CHUNK_RESPONSE, "SPDM_CHUNK_RESPONSE" },
/* SPDM response code (1.3 )*/
{ SPDM_SUPPORTED_EVENT_TYPES, "SPDM_SUPPORTED_EVENT_TYPES" },
/* SPDM request code (1.0) */
{ SPDM_GET_DIGESTS, "SPDM_GET_DIGESTS" },
{ SPDM_GET_CERTIFICATE, "SPDM_GET_CERTIFICATE" },
Expand All @@ -66,7 +68,8 @@ const char *libspdm_get_code_str(uint8_t request_code)
{ SPDM_GET_CSR, "SPDM_GET_CSR" },
{ SPDM_SET_CERTIFICATE, "SPDM_SET_CERTIFICATE" },
{ SPDM_CHUNK_SEND, "SPDM_CHUNK_SEND" },
{ SPDM_CHUNK_GET, "SPDM_CHUNK_GET" }
{ SPDM_CHUNK_GET, "SPDM_CHUNK_GET" },
{ SPDM_GET_SUPPORTED_EVENT_TYPES, "SPDM_GET_SUPPORTED_EVENT_TYPES" }
};

for (index = 0; index < LIBSPDM_ARRAY_SIZE(code_str_struct); index++) {
Expand Down
1 change: 1 addition & 0 deletions library/spdm_requester_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SET(src_spdm_requester_lib
libspdm_req_get_capabilities.c
libspdm_req_get_certificate.c
libspdm_req_get_digests.c
libspdm_req_get_event_types.c
libspdm_req_get_measurements.c
libspdm_req_get_version.c
libspdm_req_handle_error_response.c
Expand Down
172 changes: 172 additions & 0 deletions library/spdm_requester_lib/libspdm_req_get_event_types.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/**
* Copyright Notice:
* Copyright 2024 DMTF. All rights reserved.
* License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
**/

#include "internal/libspdm_requester_lib.h"

#if LIBSPDM_EVENT_RECIPIENT_SUPPORT

static libspdm_return_t libspdm_try_get_event_types(libspdm_context_t *spdm_context,
uint32_t session_id,
uint8_t *event_group_count,
uint32_t *supported_event_groups_list_len,
void *supported_event_groups_list)
{
libspdm_return_t status;
libspdm_session_info_t *session_info;
spdm_get_supported_event_types_request_t *spdm_request;
size_t spdm_request_size;
spdm_supported_event_types_response_t *spdm_response;
size_t spdm_response_size;
size_t transport_header_size;
uint8_t *message;
size_t message_size;

/* -=[Check Parameters Phase]=- */
LIBSPDM_ASSERT(event_group_count != NULL);
LIBSPDM_ASSERT(supported_event_groups_list_len != NULL);
LIBSPDM_ASSERT(supported_event_groups_list != NULL);

session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id);

if (session_info == NULL) {
LIBSPDM_ASSERT(false);
return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
}
if (libspdm_secured_message_get_session_state(session_info->secured_message_context) !=
LIBSPDM_SESSION_STATE_ESTABLISHED) {
return LIBSPDM_STATUS_INVALID_STATE_LOCAL;
}

/* -=[Verify State Phase]=- */
if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) {
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
}
if (!libspdm_is_capabilities_flag_supported(
spdm_context, true, 0,
SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) {
return LIBSPDM_STATUS_UNSUPPORTED_CAP;
}

/* -=[Construct Request Phase]=- */
transport_header_size = spdm_context->local_context.capability.transport_header_size;
status = libspdm_acquire_sender_buffer (spdm_context, &message_size, (void **)&message);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_ASSERT (message_size >= transport_header_size +
spdm_context->local_context.capability.transport_tail_size);
spdm_request = (void *)(message + transport_header_size);
spdm_request_size = message_size - transport_header_size -
spdm_context->local_context.capability.transport_tail_size;

spdm_request->header.spdm_version = libspdm_get_connection_version(spdm_context);
spdm_request->header.request_response_code = SPDM_GET_SUPPORTED_EVENT_TYPES;
spdm_request->header.param1 = 0;
spdm_request->header.param2 = 0;
spdm_request_size = sizeof(spdm_heartbeat_request_t);

/* -=[Send Request Phase]=- */
status = libspdm_send_spdm_request(spdm_context, &session_id, spdm_request_size, spdm_request);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
libspdm_release_sender_buffer (spdm_context);
return status;
}
libspdm_release_sender_buffer (spdm_context);
spdm_request = (void *)spdm_context->last_spdm_request;

/* -=[Receive Response Phase]=- */
status = libspdm_acquire_receiver_buffer(spdm_context, &message_size, (void **)&message);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_ASSERT (message_size >= transport_header_size);
spdm_response = (void *)(message);
spdm_response_size = message_size;

libspdm_zero_mem(spdm_response, spdm_response_size);
status = libspdm_receive_spdm_response(
spdm_context, &session_id, &spdm_response_size, (void **)&spdm_response);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
goto receive_done;
}

/* -=[Validate Response Phase]=- */
if (spdm_response_size < sizeof(spdm_message_header_t)) {
status = LIBSPDM_STATUS_INVALID_MSG_SIZE;
goto receive_done;
}
if (spdm_response->header.spdm_version != spdm_request->header.spdm_version) {
status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
goto receive_done;
}
if (spdm_response->header.request_response_code == SPDM_ERROR) {
status = libspdm_handle_error_response_main(
spdm_context, &session_id,
&spdm_response_size, (void **)&spdm_response,
SPDM_GET_SUPPORTED_EVENT_TYPES, SPDM_SUPPORTED_EVENT_TYPES);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
goto receive_done;
}
} else if (spdm_response->header.request_response_code != SPDM_SUPPORTED_EVENT_TYPES) {
status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
goto receive_done;
}
if (spdm_response->header.param1 == 0) {
status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
goto receive_done;
}
if (spdm_response->supported_event_groups_list_len == 0) {
status = LIBSPDM_STATUS_INVALID_MSG_FIELD;
goto receive_done;
} else if (spdm_response->supported_event_groups_list_len > *supported_event_groups_list_len) {
status = LIBSPDM_STATUS_BUFFER_TOO_SMALL;
goto receive_done;
}

/* -=[Process Response Phase]=- */
*event_group_count = spdm_response->header.param1;
libspdm_copy_mem(supported_event_groups_list, *supported_event_groups_list_len,
spdm_response + 1, spdm_response->supported_event_groups_list_len);
*supported_event_groups_list_len = spdm_response->supported_event_groups_list_len;

receive_done:
libspdm_release_receiver_buffer(spdm_context);

return status;
}

libspdm_return_t libspdm_get_event_types(void *spdm_context,
uint32_t session_id,
uint8_t *event_group_count,
uint32_t *supported_event_groups_list_len,
void *supported_event_groups_list)
{
size_t retry;
uint64_t retry_delay_time;
libspdm_return_t status;
libspdm_context_t *context;

context = spdm_context;
context->crypto_request = true;
retry = context->retry_times;
retry_delay_time = context->retry_delay_time;
do {
status = libspdm_try_get_event_types(context,
session_id,
event_group_count,
supported_event_groups_list_len,
supported_event_groups_list);
if ((status != LIBSPDM_STATUS_BUSY_PEER) || (retry == 0)) {
return status;
}

libspdm_sleep(retry_delay_time);
} while (retry-- != 0);

return status;
}

#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
2 changes: 2 additions & 0 deletions unit_test/test_spdm_requester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SET(src_test_spdm_requester
get_digests.c
get_certificate.c
challenge.c
get_event_types.c
get_measurements.c
key_exchange.c
finish.c
Expand All @@ -47,6 +48,7 @@ SET(src_test_spdm_requester
error_test/get_digests_err.c
error_test/key_exchange_err.c
error_test/get_measurements_err.c
error_test/get_event_types_err.c
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/common.c
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/algo.c
${LIBSPDM_DIR}/unit_test/spdm_unit_test_common/support.c
Expand Down
Loading

0 comments on commit c0eaae4

Please sign in to comment.