Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate SEND_EVENT for Requester as recipient #2992

Merged
merged 1 commit into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions include/industry_standard/spdm.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
/* SPDM response code (1.3) */
#define SPDM_SUPPORTED_EVENT_TYPES 0x62
#define SPDM_SUBSCRIBE_EVENT_TYPES_ACK 0x70
#define SPDM_EVENT_ACK 0x71
#define SPDM_MEASUREMENT_EXTENSION_LOG 0x6F
#define SPDM_KEY_PAIR_INFO 0x7C
#define SPDM_SET_KEY_PAIR_INFO_ACK 0x7D
Expand Down Expand Up @@ -92,6 +93,7 @@
/* SPDM request code (1.3) */
#define SPDM_GET_SUPPORTED_EVENT_TYPES 0xE2
#define SPDM_SUBSCRIBE_EVENT_TYPES 0xF0
#define SPDM_SEND_EVENT 0xF1
#define SPDM_GET_MEASUREMENT_EXTENSION_LOG 0xEF
#define SPDM_GET_KEY_PAIR_INFO 0xFC
#define SPDM_SET_KEY_PAIR_INFO 0xFD
Expand Down Expand Up @@ -1305,6 +1307,20 @@ typedef struct {
* param2 == RSVD */
} spdm_subscribe_event_types_ack_response_t;

typedef struct {
spdm_message_header_t header;
/* param1 == RSVD
* param2 == RSVD */
uint32_t event_count;
/* event_list[event_count]*/
} spdm_send_event_request_t;

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

/* SPDM GET_MEASUREMENT_EXTENSION_LOG request */
typedef struct {
spdm_message_header_t header;
Expand Down Expand Up @@ -1415,8 +1431,6 @@ typedef struct {
* param2 == RSVD*/
} spdm_set_key_pair_info_ack_response_t;

#pragma pack()

#define SPDM_VERSION_1_1_BIN_CONCAT_LABEL "spdm1.1 "
#define SPDM_VERSION_1_2_BIN_CONCAT_LABEL "spdm1.2 "
#define SPDM_VERSION_1_3_BIN_CONCAT_LABEL "spdm1.3 "
Expand Down Expand Up @@ -1468,9 +1482,34 @@ typedef struct {
#define SPDM_DMTF_EVENT_TYPE_MEASUREMENT_PRE_UPDATE 3
#define SPDM_DMTF_EVENT_TYPE_CERTIFICATE_CHANGED 4

/* DMTF Event sizes in bytes. */
#define SPDM_DMTF_EVENT_TYPE_EVENT_LOST_SIZE 8
#define SPDM_DMTF_EVENT_TYPE_MEASUREMENT_CHANGED_SIZE 32
#define SPDM_DMTF_EVENT_TYPE_MEASUREMENT_PRE_UPDATE_SIZE 32
#define SPDM_DMTF_EVENT_TYPE_CERTIFICATE_CHANGED_SIZE 1

typedef struct {
uint32_t last_acked_event_inst_id;
uint32_t last_lost_event_inst_id;
} spdm_dmtf_event_type_event_lost_t;

typedef struct {
uint8_t changed_measurements[SPDM_DMTF_EVENT_TYPE_MEASUREMENT_CHANGED_SIZE];
} spdm_dmtf_event_type_measurement_changed_t;

typedef struct {
uint8_t pre_update_measurement_changes[SPDM_DMTF_EVENT_TYPE_MEASUREMENT_PRE_UPDATE_SIZE];
} spdm_dmtf_event_type_measurement_pre_update_t;

typedef struct {
uint8_t certificate_changed;
} spdm_dmtf_event_type_certificate_changed_t;

/*SPDM SET_KEY_PAIR_INFO operation*/
#define SPDM_SET_KEY_PAIR_INFO_CHANGE_OPERATION 0
#define SPDM_SET_KEY_PAIR_INFO_ERASE_OPERATION 1
#define SPDM_SET_KEY_PAIR_INFO_GENERATE_OPERATION 2

#pragma pack()

#endif /* SPDM_H */
15 changes: 15 additions & 0 deletions include/internal/libspdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ typedef struct {
libspdm_vendor_response_callback_func vendor_response_callback;
libspdm_vendor_get_id_callback_func vendor_response_get_id;
#endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */

#if LIBSPDM_EVENT_RECIPIENT_SUPPORT
libspdm_process_event_func process_event;
#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
} libspdm_context_t;

#define LIBSPDM_CONTEXT_SIZE_WITHOUT_SECURED_CONTEXT (sizeof(libspdm_context_t))
Expand Down Expand Up @@ -1780,4 +1784,15 @@ uint8_t libspdm_mask_mel_specification(libspdm_context_t *spdm_context, uint8_t
*/
uint32_t libspdm_mask_base_asym_algo(libspdm_context_t *spdm_context, uint32_t base_asym_algo);

/**
* Check if the combination of SVH ID and VendorIDLen are legal.
*
* @param id Registry or standards body identifier (SPDM_REGISTRY_ID_*).
* @param vendor_id_len Length, in bytes, of the VendorID field.
*
* @retval true The ID and VendorIDLen are legal.
* @retval false The ID and VendorIDLen are illegal.
*/
bool libspdm_validate_svh_vendor_id_len(uint8_t id, uint8_t vendor_id_len);

#endif /* SPDM_COMMON_LIB_INTERNAL_H */
10 changes: 9 additions & 1 deletion include/internal/libspdm_requester_lib.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2024 DMTF. All rights reserved.
* Copyright 2021-2025 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 @@ -473,6 +473,14 @@ libspdm_return_t libspdm_get_encap_response_key_update(void *spdm_context,
void *request,
size_t *response_size,
void *response);

#if LIBSPDM_EVENT_RECIPIENT_SUPPORT
libspdm_return_t libspdm_get_encap_response_event_ack(void *spdm_context,
size_t request_size,
void *request,
size_t *response_size,
void *response);
#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
#endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */

/**
Expand Down
42 changes: 42 additions & 0 deletions include/library/spdm_common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,48 @@ typedef libspdm_return_t (*libspdm_vendor_response_callback_func)(

#endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */

#if LIBSPDM_EVENT_RECIPIENT_SUPPORT
/**
* SPDM Event callback function.
*
* When an event is received the library performs basic validation to ensure that SVH ID and SVH
* VendorIDLen are legal. If the event is of a DMTF event type then the library will ensure that
* EventTypeId and EventDetailLen are legal. If a SEND_EVENT message contains multiple events then
* the library will call this function with sequentially-increasing Event Instance ID.
*
* @param spdm_context A pointer to the SPDM context.
* @param session_id Secure session ID.
* @param event_instance_id Counter that increases by one for each event.
* @param svh_id Registry or standards body identifier (SPDM_REGISTRY_ID_*).
* @param svh_vendor_id_len Length, in bytes, of the svh_vendor_id field.
* @param svh_vendor_id Vendor ID assigned by the Registry or Standards Body. If the value of
* svh_vendor_id_len is 0 then this is NULL.
* @param event_type_id Event type identifier. If svh_id is SPDM_REGISTRY_ID_ DMTF then this is
* one of the SPDM_DMTF_EVENT_TYPE_* macros.
* @param event_detail_len Size, in bytes, of event_detail.
* @param event_detail Details of the event.
**/
typedef libspdm_return_t (*libspdm_process_event_func)(void *spdm_context,
uint32_t session_id,
uint32_t event_instance_id,
uint8_t svh_id,
uint8_t svh_vendor_id_len,
void *svh_vendor_id,
uint16_t event_type_id,
uint16_t event_detail_len,
void *event_detail);

/**
* Register callback to process SPDM events.
*
* @param spdm_context A pointer to the SPDM context.
* @param process_event_func Function that processes individual SPDM events. If NULL then function
* will not be called as events are processed.
**/
void libspdm_register_event_callback(void *spdm_context,
libspdm_process_event_func process_event_func);
#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 12 additions & 1 deletion library/spdm_common_lib/libspdm_com_context_data.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright Notice:
* Copyright 2021-2024 DMTF. All rights reserved.
* Copyright 2021-2025 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 @@ -3278,3 +3278,14 @@ bool libspdm_negotiate_connection_version(spdm_version_number_t *common_version,
}
return false;
}

#if LIBSPDM_EVENT_RECIPIENT_SUPPORT
void libspdm_register_event_callback(void *context,
libspdm_process_event_func process_event_func)
{
libspdm_context_t *spdm_context;

spdm_context = context;
spdm_context->process_event = process_event_func;
}
#endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
23 changes: 23 additions & 0 deletions library/spdm_common_lib/libspdm_com_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,26 @@ uint16_t libspdm_mask_alg_supported(libspdm_context_t *spdm_context, uint8_t alg
return 0;
}
}

bool libspdm_validate_svh_vendor_id_len(uint8_t id, uint8_t vendor_id_len)
{
switch (id) {
case SPDM_REGISTRY_ID_DMTF:
case SPDM_REGISTRY_ID_VESA:
return (vendor_id_len == 0);
case SPDM_REGISTRY_ID_TCG:
case SPDM_REGISTRY_ID_USB:
case SPDM_REGISTRY_ID_PCISIG:
case SPDM_REGISTRY_ID_MIPI:
case SPDM_REGISTRY_ID_CXL:
case SPDM_REGISTRY_ID_JEDEC:
return ((vendor_id_len == 0) || (vendor_id_len == 2));
case SPDM_REGISTRY_ID_IANA:
case SPDM_REGISTRY_ID_HDBASET:
return ((vendor_id_len == 0) || (vendor_id_len == 4));
case SPDM_REGISTRY_ID_IANA_CBOR:
return true;
default:
return false;
}
}
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 @@ target_sources(spdm_requester_lib
libspdm_req_encap_digests.c
libspdm_req_encap_error.c
libspdm_req_encap_key_update.c
libspdm_req_encap_event_ack.c
libspdm_req_encap_request.c
libspdm_req_end_session.c
libspdm_req_finish.c
Expand Down
Loading
Loading