diff --git a/fuzz-target/requester/vendor_req/src/main.rs b/fuzz-target/requester/vendor_req/src/main.rs index 8c59f323..734efdd3 100644 --- a/fuzz-target/requester/vendor_req/src/main.rs +++ b/fuzz-target/requester/vendor_req/src/main.rs @@ -46,8 +46,16 @@ async fn fuzz_send_spdm_vendor_defined_request(fuzzdata: Arc>) { vendor_defined_req_payload: [0u8; config::MAX_SPDM_MSG_SIZE - 7 - 2], }; + let mut rsp_payload_struct = spdmlib::message::VendorDefinedRspPayloadStruct::default(); + let _ = requester - .send_spdm_vendor_defined_request(None, standard_id, vendor_idstruct, req_payload_struct) + .send_spdm_vendor_defined_request( + None, + standard_id, + vendor_idstruct, + &req_payload_struct, + &mut rsp_payload_struct, + ) .await .is_ok(); } diff --git a/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_prog.rs b/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_prog.rs index 105e6351..92384b15 100644 --- a/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_prog.rs +++ b/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_prog.rs @@ -35,6 +35,7 @@ impl IdekmReqContext { key_iv: Aes256GcmKeyBuffer, // OUT kp_ack_status: &mut KpAckStatus, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -56,18 +57,19 @@ impl IdekmReqContext { .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let kp_ack_data_object = KpAckDataObject::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload + [..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_go.rs b/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_go.rs index 60ecd4ad..5a4b818c 100644 --- a/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_go.rs +++ b/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_go.rs @@ -32,6 +32,7 @@ impl IdekmReqContext { key_direction: u8, key_sub_stream: u8, port_index: u8, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -52,18 +53,19 @@ impl IdekmReqContext { .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let kgo_stop_ack_data_object = KGoStopAckDataObject::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload + [..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_stop.rs b/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_stop.rs index 428f2346..f8f652c9 100644 --- a/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_stop.rs +++ b/idekm/src/pci_ide_km_requester/pci_ide_km_req_key_set_stop.rs @@ -32,6 +32,7 @@ impl IdekmReqContext { key_direction: u8, key_sub_stream: u8, port_index: u8, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -52,18 +53,19 @@ impl IdekmReqContext { .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let kgo_stop_ack_data_object = KGoStopAckDataObject::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload + [..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/idekm/src/pci_ide_km_requester/pci_ide_km_req_query.rs b/idekm/src/pci_ide_km_requester/pci_ide_km_req_query.rs index cead6319..b002fc4a 100644 --- a/idekm/src/pci_ide_km_requester/pci_ide_km_req_query.rs +++ b/idekm/src/pci_ide_km_requester/pci_ide_km_req_query.rs @@ -32,6 +32,7 @@ impl IdekmReqContext { max_port_index: &mut u8, ide_reg_block: &mut [u32; PCI_IDE_KM_IDE_REG_BLOCK_MAX_COUNT], ide_reg_block_cnt: &mut usize, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -46,18 +47,19 @@ impl IdekmReqContext { .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let query_resp_data_object = QueryRespDataObject::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload + [..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/spdmlib/src/message/vendor.rs b/spdmlib/src/message/vendor.rs index adef2230..eff33eb3 100644 --- a/spdmlib/src/message/vendor.rs +++ b/spdmlib/src/message/vendor.rs @@ -144,6 +144,15 @@ pub struct VendorDefinedRspPayloadStruct { pub vendor_defined_rsp_payload: [u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], } +impl Default for VendorDefinedRspPayloadStruct { + fn default() -> Self { + Self { + rsp_length: 0, + vendor_defined_rsp_payload: [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], + } + } +} + impl Codec for VendorDefinedRspPayloadStruct { fn encode(&self, bytes: &mut Writer) -> Result { let mut cnt = 0usize; diff --git a/spdmlib/src/requester/vendor_req.rs b/spdmlib/src/requester/vendor_req.rs index f2b0202c..dfaa7107 100644 --- a/spdmlib/src/requester/vendor_req.rs +++ b/spdmlib/src/requester/vendor_req.rs @@ -13,8 +13,9 @@ impl RequesterContext { session_id: Option, standard_id: RegistryOrStandardsBodyID, vendor_id_struct: VendorIDStruct, - req_payload_struct: VendorDefinedReqPayloadStruct, - ) -> SpdmResult { + req_payload_struct: &VendorDefinedReqPayloadStruct, + rsp_payload_struct: &mut VendorDefinedRspPayloadStruct, + ) -> SpdmResult { info!("send vendor defined request\n"); self.common.reset_buffer_via_request_code( @@ -33,7 +34,7 @@ impl RequesterContext { SpdmVendorDefinedRequestPayload { standard_id, vendor_id: vendor_id_struct, - req_payload: req_payload_struct, + req_payload: req_payload_struct.clone(), }, ), }; @@ -48,14 +49,19 @@ impl RequesterContext { .receive_message(session_id, &mut receive_buffer, false) .await?; - self.handle_spdm_vendor_defined_respond(session_id, &receive_buffer[..receive_used]) + self.handle_spdm_vendor_defined_respond( + session_id, + &receive_buffer[..receive_used], + rsp_payload_struct, + ) } pub fn handle_spdm_vendor_defined_respond( &mut self, session_id: Option, receive_buffer: &[u8], - ) -> SpdmResult { + rsp_payload_struct: &mut VendorDefinedRspPayloadStruct, + ) -> SpdmResult { let mut reader = Reader::init(receive_buffer); match SpdmMessageHeader::read(&mut reader) { Some(message_header) => { @@ -69,7 +75,9 @@ impl RequesterContext { &mut reader, ) { Some(spdm_vendor_defined_response_payload) => { - Ok(spdm_vendor_defined_response_payload.rsp_payload) + *rsp_payload_struct = + spdm_vendor_defined_response_payload.rsp_payload; + Ok(()) } None => Err(SPDM_STATUS_INVALID_MSG_FIELD), } diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_bind_p2p_stream_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_bind_p2p_stream_request.rs index 4b8098a1..5d41dc3a 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_bind_p2p_stream_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_bind_p2p_stream_request.rs @@ -32,6 +32,7 @@ pub async fn pci_tdisp_req_bind_p2p_stream_request( p2p_stream_id: u8, // OUT tdisp_error_code: &mut Option, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -56,18 +57,18 @@ pub async fn pci_tdisp_req_bind_p2p_stream_request( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; if let Ok(tdisp_error) = RspTdispError::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD) { @@ -76,8 +77,7 @@ pub async fn pci_tdisp_req_bind_p2p_stream_request( } let rsp_bind_p2_pstream_response = RspBindP2PStreamResponse::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_report.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_report.rs index efa64944..c3bba1ef 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_report.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_report.rs @@ -36,6 +36,7 @@ pub async fn pci_tdisp_req_get_device_interface_report( report: &mut [u8; MAX_DEVICE_REPORT_BUFFER], report_size: &mut usize, tdisp_error_code: &mut Option, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut offset = 0u16; let length = MAX_PORTION_LENGTH as u16; @@ -67,18 +68,19 @@ pub async fn pci_tdisp_req_get_device_interface_report( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; if let Ok(tdisp_error) = RspTdispError::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload + [..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD) { @@ -87,8 +89,8 @@ pub async fn pci_tdisp_req_get_device_interface_report( } let rsp_device_interface_report = RspDeviceInterfaceReport::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload + [..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_state.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_state.rs index 8e97029f..6c7d9f18 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_state.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_device_interface_state.rs @@ -30,6 +30,7 @@ pub async fn pci_tdisp_req_get_device_interface_state( interface_id: InterfaceId, // OUT tdi_state: &mut TdiState, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -53,18 +54,18 @@ pub async fn pci_tdisp_req_get_device_interface_state( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let rsp_device_interface_state = RspDeviceInterfaceState::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_capabilities.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_capabilities.rs index 3b898382..7dd5b088 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_capabilities.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_capabilities.rs @@ -37,6 +37,7 @@ pub async fn pci_tdisp_req_get_tdisp_capabilities( num_req_this: &mut u8, num_req_all: &mut u8, req_msgs_supported: &mut [u8; 16], + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -60,18 +61,18 @@ pub async fn pci_tdisp_req_get_tdisp_capabilities( .encode(&mut writer) .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let rsp_tdisp_capabilities = RspTdispCapabilities::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_version.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_version.rs index 8dd6b87d..e8bb59a4 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_version.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_get_tdisp_version.rs @@ -1,71 +1,73 @@ -// Copyright (c) 2023 Intel Corporation -// -// SPDX-License-Identifier: Apache-2.0 or MIT - -use codec::Codec; -use codec::Writer; -use spdmlib::error::SPDM_STATUS_BUFFER_FULL; -use spdmlib::error::SPDM_STATUS_INVALID_MSG_FIELD; -use spdmlib::{ - error::SpdmResult, - message::{VendorDefinedReqPayloadStruct, MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE}, - requester::RequesterContext, -}; - -use crate::pci_tdisp::vendor_id; -use crate::pci_tdisp::RspTdispVersion; -use crate::pci_tdisp::STANDARD_ID; -use crate::pci_tdisp::{ReqGetTdispVersion, TdispVersion}; -use crate::pci_tdisp_requester::InterfaceId; - -#[maybe_async::maybe_async] -pub async fn pci_tdisp_req_get_tdisp_version( - // IN - spdm_requester: &mut RequesterContext, - session_id: u32, - interface_id: InterfaceId, -) -> SpdmResult { - let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { - req_length: 0, - vendor_defined_req_payload: [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], - }; - - let mut writer = - Writer::init(&mut vendor_defined_req_payload_struct.vendor_defined_req_payload); - - vendor_defined_req_payload_struct.req_length = ReqGetTdispVersion { interface_id } - .encode(&mut writer) - .map_err(|_| SPDM_STATUS_BUFFER_FULL)? - as u16; - - let vendor_defined_rsp_payload_struct = spdm_requester - .send_spdm_vendor_defined_request( - Some(session_id), - STANDARD_ID, - vendor_id(), - vendor_defined_req_payload_struct, - ) - .await?; - - let rsp_tdisp_version = RspTdispVersion::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], - ) - .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; - - if rsp_tdisp_version.interface_id != interface_id { - return Err(SPDM_STATUS_INVALID_MSG_FIELD); - } - - if rsp_tdisp_version.version_num_count == 1 - && rsp_tdisp_version.version_num_entry[0] - == (TdispVersion { - major_version: 1, - minor_version: 0, - }) - { - Ok(()) - } else { - Err(SPDM_STATUS_INVALID_MSG_FIELD) - } -} +// Copyright (c) 2023 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 or MIT + +use codec::Codec; +use codec::Writer; +use spdmlib::error::SPDM_STATUS_BUFFER_FULL; +use spdmlib::error::SPDM_STATUS_INVALID_MSG_FIELD; +use spdmlib::{ + error::SpdmResult, + message::{VendorDefinedReqPayloadStruct, MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE}, + requester::RequesterContext, +}; + +use crate::pci_tdisp::vendor_id; +use crate::pci_tdisp::RspTdispVersion; +use crate::pci_tdisp::STANDARD_ID; +use crate::pci_tdisp::{ReqGetTdispVersion, TdispVersion}; +use crate::pci_tdisp_requester::InterfaceId; + +#[maybe_async::maybe_async] +pub async fn pci_tdisp_req_get_tdisp_version( + // IN + spdm_requester: &mut RequesterContext, + session_id: u32, + interface_id: InterfaceId, + // OUT + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, +) -> SpdmResult { + let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { + req_length: 0, + vendor_defined_req_payload: [0u8; MAX_SPDM_VENDOR_DEFINED_PAYLOAD_SIZE], + }; + + let mut writer = + Writer::init(&mut vendor_defined_req_payload_struct.vendor_defined_req_payload); + + vendor_defined_req_payload_struct.req_length = ReqGetTdispVersion { interface_id } + .encode(&mut writer) + .map_err(|_| SPDM_STATUS_BUFFER_FULL)? + as u16; + + spdm_requester + .send_spdm_vendor_defined_request( + Some(session_id), + STANDARD_ID, + vendor_id(), + &vendor_defined_req_payload_struct, + rsp_payload_struct, + ) + .await?; + + let rsp_tdisp_version = RspTdispVersion::read_bytes( + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], + ) + .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; + + if rsp_tdisp_version.interface_id != interface_id { + return Err(SPDM_STATUS_INVALID_MSG_FIELD); + } + + if rsp_tdisp_version.version_num_count == 1 + && rsp_tdisp_version.version_num_entry[0] + == (TdispVersion { + major_version: 1, + minor_version: 0, + }) + { + Ok(()) + } else { + Err(SPDM_STATUS_INVALID_MSG_FIELD) + } +} diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_lock_interface_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_lock_interface_request.rs index a5da8d98..62e720c0 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_lock_interface_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_lock_interface_request.rs @@ -40,6 +40,7 @@ pub async fn pci_tdisp_req_lock_interface_request( // OUT start_interface_nonce: &mut [u8; START_INTERFACE_NONCE_LEN], tdisp_error_code: &mut Option, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -67,18 +68,18 @@ pub async fn pci_tdisp_req_lock_interface_request( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; if let Ok(tdisp_error) = RspTdispError::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD) { @@ -87,8 +88,7 @@ pub async fn pci_tdisp_req_lock_interface_request( } let rsp_lock_interface_response = RspLockInterfaceResponse::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_set_mmio_attribute_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_set_mmio_attribute_request.rs index 9aa6e609..a488810f 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_set_mmio_attribute_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_set_mmio_attribute_request.rs @@ -32,6 +32,7 @@ pub async fn pci_tdisp_req_set_mmio_attribute_request( mmio_range: TdispMmioRange, // OUT tdisp_error_code: &mut Option, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -56,18 +57,18 @@ pub async fn pci_tdisp_req_set_mmio_attribute_request( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; if let Ok(tdisp_error) = RspTdispError::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD) { @@ -76,8 +77,7 @@ pub async fn pci_tdisp_req_set_mmio_attribute_request( } let rsp_set_mmio_attribute_response = RspSetMmioAttributeResponse::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_start_interface_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_start_interface_request.rs index deadcafa..3a78314d 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_start_interface_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_start_interface_request.rs @@ -34,6 +34,7 @@ pub async fn pci_tdisp_req_start_interface_request( start_interface_nonce: &[u8; START_INTERFACE_NONCE_LEN], // OUT tdisp_error_code: &mut Option, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -58,18 +59,18 @@ pub async fn pci_tdisp_req_start_interface_request( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; if let Ok(tdisp_error) = RspTdispError::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD) { @@ -78,8 +79,7 @@ pub async fn pci_tdisp_req_start_interface_request( } let rsp_start_interface_response = RspStartInterfaceResponse::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_stop_interface_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_stop_interface_request.rs index 1b804c52..3af693f1 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_stop_interface_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_stop_interface_request.rs @@ -27,6 +27,8 @@ pub async fn pci_tdisp_req_stop_interface_request( spdm_requester: &mut RequesterContext, session_id: u32, interface_id: InterfaceId, + // OUT + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -50,18 +52,18 @@ pub async fn pci_tdisp_req_stop_interface_request( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; let rsp_stop_interface_response = RspStopInterfaceResponse::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_unbind_p2p_stream_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_unbind_p2p_stream_request.rs index ce1e6d96..9fc20bfc 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_unbind_p2p_stream_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_unbind_p2p_stream_request.rs @@ -31,6 +31,7 @@ pub async fn pci_tdisp_req_unbind_p2p_stream_request( p2p_stream_id: u8, // OUT tdisp_error_code: &mut Option, + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, ) -> SpdmResult { let mut vendor_defined_req_payload_struct = VendorDefinedReqPayloadStruct { req_length: 0, @@ -55,18 +56,18 @@ pub async fn pci_tdisp_req_unbind_p2p_stream_request( .map_err(|_| SPDM_STATUS_BUFFER_FULL)? as u16; - let vendor_defined_rsp_payload_struct = spdm_requester + spdm_requester .send_spdm_vendor_defined_request( Some(session_id), STANDARD_ID, vendor_id(), - vendor_defined_req_payload_struct, + &vendor_defined_req_payload_struct, + rsp_payload_struct, ) .await?; if let Ok(tdisp_error) = RspTdispError::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD) { @@ -75,8 +76,7 @@ pub async fn pci_tdisp_req_unbind_p2p_stream_request( } let rsp_un_bind_p2_pstream_response = RspUnBindP2PStreamResponse::read_bytes( - &vendor_defined_rsp_payload_struct.vendor_defined_rsp_payload - [..vendor_defined_rsp_payload_struct.rsp_length as usize], + &rsp_payload_struct.vendor_defined_rsp_payload[..rsp_payload_struct.rsp_length as usize], ) .ok_or(SPDM_STATUS_INVALID_MSG_FIELD)?; diff --git a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_vdm_request.rs b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_vdm_request.rs index ffd9eb7c..c9bc8138 100644 --- a/tdisp/src/pci_tdisp_requester/pci_tdisp_req_vdm_request.rs +++ b/tdisp/src/pci_tdisp_requester/pci_tdisp_req_vdm_request.rs @@ -1,37 +1,38 @@ -// Copyright (c) 2023 Intel Corporation -// -// SPDX-License-Identifier: Apache-2.0 or MIT - -use spdmlib::error::SPDM_STATUS_INVALID_PARAMETER; -use spdmlib::message::VendorDefinedRspPayloadStruct; -use spdmlib::{ - error::SpdmResult, message::VendorDefinedReqPayloadStruct, requester::RequesterContext, -}; - -use crate::pci_tdisp::vendor_id; -use crate::pci_tdisp::STANDARD_ID; -use crate::pci_tdisp::TDISP_PROTOCOL_ID; - -#[maybe_async::maybe_async] -pub async fn pci_tdisp_req_vdm_request( - // IN - spdm_requester: &mut RequesterContext, - session_id: u32, - vendor_defined_req_payload_struct: VendorDefinedReqPayloadStruct, - // OUT -) -> SpdmResult { - if vendor_defined_req_payload_struct.req_length < 1 - || vendor_defined_req_payload_struct.vendor_defined_req_payload[0] != TDISP_PROTOCOL_ID - { - Err(SPDM_STATUS_INVALID_PARAMETER) - } else { - spdm_requester - .send_spdm_vendor_defined_request( - Some(session_id), - STANDARD_ID, - vendor_id(), - vendor_defined_req_payload_struct, - ) - .await - } -} +// Copyright (c) 2023 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 or MIT + +use spdmlib::error::SPDM_STATUS_INVALID_PARAMETER; +use spdmlib::{ + error::SpdmResult, message::VendorDefinedReqPayloadStruct, requester::RequesterContext, +}; + +use crate::pci_tdisp::vendor_id; +use crate::pci_tdisp::STANDARD_ID; +use crate::pci_tdisp::TDISP_PROTOCOL_ID; + +#[maybe_async::maybe_async] +pub async fn pci_tdisp_req_vdm_request( + // IN + spdm_requester: &mut RequesterContext, + session_id: u32, + vendor_defined_req_payload_struct: &VendorDefinedReqPayloadStruct, + // OUT + rsp_payload_struct: &mut spdmlib::message::VendorDefinedRspPayloadStruct, +) -> SpdmResult { + if vendor_defined_req_payload_struct.req_length < 1 + || vendor_defined_req_payload_struct.vendor_defined_req_payload[0] != TDISP_PROTOCOL_ID + { + Err(SPDM_STATUS_INVALID_PARAMETER) + } else { + spdm_requester + .send_spdm_vendor_defined_request( + Some(session_id), + STANDARD_ID, + vendor_id(), + vendor_defined_req_payload_struct, + rsp_payload_struct, + ) + .await + } +} diff --git a/test/spdm-requester-emu/src/main.rs b/test/spdm-requester-emu/src/main.rs index b378cb8a..e4c2f854 100644 --- a/test/spdm-requester-emu/src/main.rs +++ b/test/spdm-requester-emu/src/main.rs @@ -628,6 +628,7 @@ async fn test_idekm_tdisp( // ide_km test let mut idekm_req_context = IdekmReqContext; + let mut rsp_payload_struct = VendorDefinedRspPayloadStruct::default(); // ide_km query let port_index = 0u8; let mut dev_func_num = 0u8; @@ -647,6 +648,7 @@ async fn test_idekm_tdisp( &mut max_port_index, &mut ide_reg_block, &mut ide_reg_block_cnt, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -680,6 +682,7 @@ async fn test_idekm_tdisp( port_index, key_iv, &mut kp_ack_status, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -721,6 +724,7 @@ async fn test_idekm_tdisp( port_index, key_iv, &mut kp_ack_status, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -762,6 +766,7 @@ async fn test_idekm_tdisp( port_index, key_iv, &mut kp_ack_status, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -803,6 +808,7 @@ async fn test_idekm_tdisp( port_index, key_iv, &mut kp_ack_status, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -844,6 +850,7 @@ async fn test_idekm_tdisp( port_index, key_iv, &mut kp_ack_status, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -885,6 +892,7 @@ async fn test_idekm_tdisp( port_index, key_iv, &mut kp_ack_status, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -912,6 +920,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -930,6 +939,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -948,6 +958,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -966,6 +977,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -984,6 +996,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1002,6 +1015,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1020,6 +1034,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1038,6 +1053,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1056,6 +1072,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1074,6 +1091,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1092,6 +1110,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1110,6 +1129,7 @@ async fn test_idekm_tdisp( key_direction, key_sub_stream, port_index, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1124,9 +1144,14 @@ async fn test_idekm_tdisp( }, }; - pci_tdisp_req_get_tdisp_version(&mut context, session_id, interface_id) - .await - .unwrap(); + pci_tdisp_req_get_tdisp_version( + &mut context, + session_id, + interface_id, + &mut rsp_payload_struct, + ) + .await + .unwrap(); println!("Successful Get Tdisp Version!"); let tsm_caps = 0; @@ -1147,6 +1172,7 @@ async fn test_idekm_tdisp( &mut num_req_this, &mut num_req_all, &mut req_msgs_supported, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1158,6 +1184,7 @@ async fn test_idekm_tdisp( session_id, interface_id, &mut tdi_state, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1180,6 +1207,7 @@ async fn test_idekm_tdisp( bind_p2p_address_mask, &mut start_interface_nonce, &mut tdisp_error_code, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1194,6 +1222,7 @@ async fn test_idekm_tdisp( session_id, interface_id, &mut tdi_state, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1209,6 +1238,7 @@ async fn test_idekm_tdisp( &mut report, &mut report_size, &mut tdisp_error_code, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1225,6 +1255,7 @@ async fn test_idekm_tdisp( interface_id, &start_interface_nonce, &mut tdisp_error_code, + &mut rsp_payload_struct, ) .await .unwrap(); @@ -1236,15 +1267,21 @@ async fn test_idekm_tdisp( session_id, interface_id, &mut tdi_state, + &mut rsp_payload_struct, ) .await .unwrap(); assert_eq!(tdi_state, TdiState::RUN); println!("Successful Get Tdisp State: {:X?}!", tdi_state); - pci_tdisp_req_stop_interface_request(&mut context, session_id, interface_id) - .await - .unwrap(); + pci_tdisp_req_stop_interface_request( + &mut context, + session_id, + interface_id, + &mut rsp_payload_struct, + ) + .await + .unwrap(); println!("Successful Stop Interface!"); pci_tdisp_req_get_device_interface_state( @@ -1252,6 +1289,7 @@ async fn test_idekm_tdisp( session_id, interface_id, &mut tdi_state, + &mut rsp_payload_struct, ) .await .unwrap(); diff --git a/test/spdmlib-test/src/requester_tests/vendor_req.rs b/test/spdmlib-test/src/requester_tests/vendor_req.rs index 2cbf3824..58b43b0b 100644 --- a/test/spdmlib-test/src/requester_tests/vendor_req.rs +++ b/test/spdmlib-test/src/requester_tests/vendor_req.rs @@ -63,12 +63,15 @@ fn test_case0_send_spdm_vendor_defined_request() { vendor_defined_req_payload: [0u8; config::MAX_SPDM_MSG_SIZE - 7 - 2], }; + let mut rsp_payload_struct = spdmlib::message::VendorDefinedRspPayloadStruct::default(); + let status = requester .send_spdm_vendor_defined_request( Some(session_id), standard_id, vendor_idstruct, - req_payload_struct, + &req_payload_struct, + &mut rsp_payload_struct, ) .await .is_ok();