|
| 1 | +// Licensed under the Apache-2.0 license |
| 2 | + |
| 3 | +//! GET_MEASUREMENTS and MEASURMENTS command types and logic |
| 4 | +
|
| 5 | +/// Requester logic for GET_MEASUREMENTS and MEASURMENTS |
| 6 | +pub mod request; |
| 7 | +/// Responder logic for GET_MEASUREMENTS and MEASURMENTS |
| 8 | +pub mod response; |
| 9 | + |
| 10 | +use crate::codec::CommonCodec; |
| 11 | +use crate::protocol::*; |
| 12 | +use bitfield::bitfield; |
| 13 | +use zerocopy::{FromBytes, Immutable, IntoBytes}; |
| 14 | + |
| 15 | +const RESPONSE_FIXED_FIELDS_SIZE: usize = 8; |
| 16 | +const MAX_RESPONSE_VARIABLE_FIELDS_SIZE: usize = |
| 17 | + NONCE_LEN + size_of::<u32>() + size_of::<RequesterContext>(); |
| 18 | + |
| 19 | +#[derive(FromBytes, IntoBytes, Immutable)] |
| 20 | +#[repr(C)] |
| 21 | +struct GetMeasurementsReqCommon { |
| 22 | + req_attr: GetMeasurementsReqAttr, |
| 23 | + meas_op: u8, |
| 24 | +} |
| 25 | +impl CommonCodec for GetMeasurementsReqCommon {} |
| 26 | + |
| 27 | +#[derive(FromBytes, IntoBytes, Immutable)] |
| 28 | +#[repr(C)] |
| 29 | +struct GetMeasurementsReqSignature { |
| 30 | + requester_nonce: [u8; NONCE_LEN], |
| 31 | + slot_id: u8, |
| 32 | +} |
| 33 | +impl CommonCodec for GetMeasurementsReqSignature {} |
| 34 | + |
| 35 | +bitfield! { |
| 36 | + #[derive(FromBytes, IntoBytes, Immutable)] |
| 37 | + #[repr(C)] |
| 38 | + struct GetMeasurementsReqAttr(u8); |
| 39 | + impl Debug; |
| 40 | + u8; |
| 41 | + pub signature_requested, _: 0, 0; |
| 42 | + pub raw_bitstream_requested, _: 1, 1; |
| 43 | + pub new_measurement_requested, _: 2, 2; |
| 44 | + reserved, _: 7, 3; |
| 45 | +} |
| 46 | + |
| 47 | +bitfield! { |
| 48 | + #[derive(FromBytes, IntoBytes, Immutable)] |
| 49 | + #[repr(C)] |
| 50 | + struct MeasurementsRspFixed([u8]); |
| 51 | + impl Debug; |
| 52 | + u8; |
| 53 | + pub spdm_version, set_spdm_version: 7, 0; |
| 54 | + pub req_resp_code, set_req_resp_code: 15, 8; |
| 55 | + pub total_measurement_indices, set_total_measurement_indices: 23, 16; |
| 56 | + pub slot_id, set_slot_id: 27, 24; |
| 57 | + pub content_changed, set_content_changed: 29, 28; |
| 58 | + reserved, _: 31, 30; |
| 59 | + pub num_blocks, set_num_blocks: 39, 32; |
| 60 | + pub measurement_record_len_byte0, set_measurement_record_len_byte0: 47, 40; |
| 61 | + pub measurement_record_len_byte1, set_measurement_record_len_byte1: 55, 48; |
| 62 | + pub measurement_record_len_byte2, set_measurement_record_len_byte2: 63, 56; |
| 63 | +} |
| 64 | + |
| 65 | +impl MeasurementsRspFixed<[u8; RESPONSE_FIXED_FIELDS_SIZE]> { |
| 66 | + pub fn set_measurement_record_len(&mut self, len: u32) { |
| 67 | + self.set_measurement_record_len_byte0((len & 0xFF) as u8); |
| 68 | + self.set_measurement_record_len_byte1(((len >> 8) & 0xFF) as u8); |
| 69 | + self.set_measurement_record_len_byte2(((len >> 16) & 0xFF) as u8); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +impl Default for MeasurementsRspFixed<[u8; RESPONSE_FIXED_FIELDS_SIZE]> { |
| 74 | + fn default() -> Self { |
| 75 | + Self([0; RESPONSE_FIXED_FIELDS_SIZE]) |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +impl CommonCodec for MeasurementsRspFixed<[u8; RESPONSE_FIXED_FIELDS_SIZE]> {} |
0 commit comments