forked from DMTF/libspdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit for SUPPORTED_EVENT_TYPES
This commit implements the basic functionality of the Responder 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
1 parent
906eb39
commit 4c2817b
Showing
15 changed files
with
483 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* 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 | ||
**/ | ||
|
||
#ifndef EVENTLIB_H | ||
#define EVENTLIB_H | ||
|
||
#include "hal/base.h" | ||
#include "internal/libspdm_lib_config.h" | ||
#include "industry_standard/spdm.h" | ||
|
||
#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP | ||
/** | ||
* Populate the SupportedEventGroupsList field in the SUPPORTED_EVENT_TYPES response. | ||
* | ||
* The SPDM specification mandates that, at a minimum, the event notifier must support the DMTF | ||
* event types and the EventLost event. | ||
* | ||
* @param spdm_context A pointer to the SPDM context. | ||
* @param spdm_version Indicates the negotiated version. | ||
* @param supported_event_groups_list A pointer to the buffer that holds the list of event. | ||
* groups. | ||
* @param supported_event_groups_list_len On input, the size, in bytes, of the buffer to hold the | ||
* list of event groups. | ||
* On output, the size, in bytes, of the list of event | ||
* groups. This value must be greater than zero. | ||
* @param event_group_count The number of event groups in supported_event_groups_list. This value | ||
* must be greater than 0. | ||
* | ||
* @retval true The event groups list was successfully populated. | ||
* @retval false An error occurred when populating the event groups list. | ||
**/ | ||
extern bool libspdm_event_get_types( | ||
void *spdm_context, | ||
spdm_version_number_t spdm_version, | ||
void *supported_event_groups_list, | ||
uint32_t *supported_event_groups_list_len, | ||
uint8_t *event_group_count); | ||
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */ | ||
#endif /* EVENTLIB_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
library/spdm_responder_lib/libspdm_rsp_supported_event_types.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* 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_responder_lib.h" | ||
#include "internal/libspdm_secured_message_lib.h" | ||
|
||
#if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP | ||
|
||
libspdm_return_t libspdm_get_response_supported_event_types(libspdm_context_t *spdm_context, | ||
size_t request_size, | ||
const void *request, | ||
size_t *response_size, | ||
void *response) | ||
{ | ||
spdm_supported_event_types_response_t *spdm_response; | ||
const spdm_get_supported_event_types_request_t *spdm_request; | ||
const size_t response_buffer_size = *response_size; | ||
uint32_t supported_event_groups_list_len; | ||
uint8_t event_group_count; | ||
uint32_t session_id; | ||
libspdm_session_info_t *session_info; | ||
libspdm_session_state_t session_state; | ||
|
||
spdm_request = request; | ||
|
||
/* -=[Check Parameters Phase]=- */ | ||
LIBSPDM_ASSERT(spdm_request->header.request_response_code == SPDM_SUPPORTED_EVENT_TYPES); | ||
|
||
/* -=[Verify State Phase]=- */ | ||
if (spdm_context->response_state != LIBSPDM_RESPONSE_STATE_NORMAL) { | ||
return libspdm_responder_handle_response_state( | ||
spdm_context, | ||
spdm_request->header.request_response_code, | ||
response_size, response); | ||
} | ||
if (spdm_context->connection_info.connection_state < LIBSPDM_CONNECTION_STATE_NEGOTIATED) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_UNEXPECTED_REQUEST, | ||
0, response_size, response); | ||
} | ||
if (libspdm_get_connection_version(spdm_context) < SPDM_MESSAGE_VERSION_13) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, | ||
SPDM_GET_SUPPORTED_EVENT_TYPES, | ||
response_size, response); | ||
} | ||
if (!libspdm_is_capabilities_flag_supported( | ||
spdm_context, false, | ||
0, SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_EVENT_CAP)) { | ||
return libspdm_generate_error_response( | ||
spdm_context, SPDM_ERROR_CODE_UNSUPPORTED_REQUEST, | ||
SPDM_GET_SUPPORTED_EVENT_TYPES, response_size, response); | ||
} | ||
if (!spdm_context->last_spdm_request_session_id_valid) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_SESSION_REQUIRED, 0, | ||
response_size, response); | ||
} | ||
session_id = spdm_context->last_spdm_request_session_id; | ||
session_info = libspdm_get_session_info_via_session_id(spdm_context, session_id); | ||
if (session_info == NULL) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_SESSION_REQUIRED, 0, | ||
response_size, response); | ||
} | ||
session_state = libspdm_secured_message_get_session_state( | ||
session_info->secured_message_context); | ||
if (session_state != LIBSPDM_SESSION_STATE_ESTABLISHED) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_UNEXPECTED_REQUEST, 0, | ||
response_size, response); | ||
} | ||
/* This message can only be in secured session. | ||
* Thus don't need to consider transport layer padding, just check its exact size. */ | ||
if (request_size != sizeof(spdm_get_supported_event_types_request_t)) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_INVALID_REQUEST, 0, | ||
response_size, response); | ||
} | ||
if (spdm_request->header.spdm_version != libspdm_get_connection_version(spdm_context)) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_VERSION_MISMATCH, 0, | ||
response_size, response); | ||
} | ||
|
||
/* -=[Construct Response Phase]=- */ | ||
LIBSPDM_ASSERT(response_buffer_size >= sizeof(spdm_supported_event_types_response_t)); | ||
libspdm_zero_mem(response, response_buffer_size); | ||
spdm_response = response; | ||
|
||
spdm_response->header.spdm_version = libspdm_get_connection_version(spdm_context); | ||
spdm_response->header.request_response_code = SPDM_SUPPORTED_EVENT_TYPES; | ||
spdm_response->header.param2 = 0; | ||
|
||
supported_event_groups_list_len = (uint32_t)response_buffer_size - | ||
sizeof(spdm_supported_event_types_response_t); | ||
|
||
if (!libspdm_event_get_types(spdm_context, spdm_context->connection_info.version, | ||
(void *)(spdm_response + 1), &supported_event_groups_list_len, | ||
&event_group_count)) { | ||
return libspdm_generate_error_response(spdm_context, | ||
SPDM_ERROR_CODE_UNSPECIFIED, 0, | ||
response_size, response); | ||
} | ||
|
||
LIBSPDM_ASSERT(supported_event_groups_list_len > 0); | ||
LIBSPDM_ASSERT(supported_event_groups_list_len <= | ||
(response_buffer_size - sizeof(spdm_supported_event_types_response_t))); | ||
LIBSPDM_ASSERT(event_group_count > 0); | ||
|
||
spdm_response->header.param1 = event_group_count; | ||
spdm_response->supported_event_groups_list_len = supported_event_groups_list_len; | ||
|
||
*response_size = sizeof(spdm_supported_event_types_response_t) + | ||
supported_event_groups_list_len; | ||
|
||
return LIBSPDM_STATUS_SUCCESS; | ||
} | ||
|
||
#endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.