Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
add auxiliary data support for VendorDefinedStruct.
Browse files Browse the repository at this point in the history
Currently, spdmlib can pass only vendor defined request payload to
callback, no any context/hardware information is included.
This patch is to provide the flexibility for integrator to attach
more information associated with vendor defined request payload to
gain context.

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Oct 31, 2023
1 parent 2352394 commit de4f6e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions idekm/src/pci_ide_km_responder/pci_ide_km_rsp_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ use spdmlib::{

pub const PCI_IDE_KM_INSTANCE: VendorDefinedStruct = VendorDefinedStruct {
vendor_defined_request_handler: pci_ide_km_rsp_dispatcher,
auxiliary_data: 0,
};

fn pci_ide_km_rsp_dispatcher(
_auxiliary_data: usize,
vendor_defined_req_payload_struct: &VendorDefinedReqPayloadStruct,
) -> SpdmResult<VendorDefinedRspPayloadStruct> {
if vendor_defined_req_payload_struct.req_length < 2 {
Expand Down
15 changes: 11 additions & 4 deletions spdmlib/src/message/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,21 @@ impl SpdmCodec for SpdmVendorDefinedResponsePayload {
#[derive(Clone, Copy)]
pub struct VendorDefinedStruct {
pub vendor_defined_request_handler:
fn(&VendorDefinedReqPayloadStruct) -> SpdmResult<VendorDefinedRspPayloadStruct>,
fn(usize, &VendorDefinedReqPayloadStruct) -> SpdmResult<VendorDefinedRspPayloadStruct>,
pub auxiliary_data: usize,
}

static VENDOR_DEFNIED: OnceCell<VendorDefinedStruct> = OnceCell::uninit();

static VENDOR_DEFNIED_DEFAULT: VendorDefinedStruct = VendorDefinedStruct {
vendor_defined_request_handler: |_vendor_defined_req_payload_struct: &VendorDefinedReqPayloadStruct|
-> SpdmResult<VendorDefinedRspPayloadStruct> { log::info!("not implement vendor defined struct!!!\n"); unimplemented!() },
vendor_defined_request_handler:
|_auxiliary_data: usize,
_vendor_defined_req_payload_struct: &VendorDefinedReqPayloadStruct|
-> SpdmResult<VendorDefinedRspPayloadStruct> {
log::info!("not implement vendor defined struct!!!\n");
unimplemented!()
},
auxiliary_data: 0,
};

pub fn register_vendor_defined_struct(context: VendorDefinedStruct) -> bool {
Expand All @@ -272,7 +279,7 @@ pub fn vendor_defined_request_handler(
vendor_defined_req_payload_struct: &VendorDefinedReqPayloadStruct,
) -> SpdmResult<VendorDefinedRspPayloadStruct> {
if let Ok(vds) = VENDOR_DEFNIED.try_get_or_init(|| VENDOR_DEFNIED_DEFAULT) {
(vds.vendor_defined_request_handler)(vendor_defined_req_payload_struct)
(vds.vendor_defined_request_handler)(vds.auxiliary_data, vendor_defined_req_payload_struct)
} else {
Err(SPDM_STATUS_INVALID_STATE_LOCAL)
}
Expand Down

0 comments on commit de4f6e9

Please sign in to comment.