1use super::EventType;
16use crate::{guid, Guid, PhysicalAddress, Status};
17use bitflags::bitflags;
18use core::ffi::c_void;
19
20#[repr(C)]
22#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
23pub struct Tcg2Version {
24 pub major: u8,
26 pub minor: u8,
28}
29
30bitflags! {
31 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
33 #[repr(transparent)]
34 pub struct Tcg2EventLogBitmap: u32 {
35 const TCG_1_2 = 0x0000_0001;
37
38 const TCG_2 = 0x0000_0002;
40 }
41}
42
43pub type Tcg2EventLogFormat = Tcg2EventLogBitmap;
45
46bitflags! {
47 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
49 #[repr(transparent)]
50 pub struct Tcg2HashAlgorithmBitmap: u32 {
51 const SHA1 = 0x0000_0001;
53
54 const SHA256 = 0x0000_0002;
56
57 const SHA384 = 0x0000_0004;
59
60 const SHA512 = 0x0000_0008;
62
63 const SM3_256 = 0x0000_0010;
65 }
66}
67
68#[repr(C)]
70#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Ord, PartialOrd)]
71pub struct Tcg2BootServiceCapability {
72 pub size: u8,
74
75 pub structure_version: Tcg2Version,
77
78 pub protocol_version: Tcg2Version,
80
81 pub hash_algorithm_bitmap: Tcg2HashAlgorithmBitmap,
83
84 pub supported_event_logs: Tcg2EventLogBitmap,
86
87 pub tpm_present_flag: u8,
89
90 pub max_command_size: u16,
92
93 pub max_response_size: u16,
95
96 pub manufacturer_id: u32,
102
103 pub number_of_pcr_banks: u32,
105
106 pub active_pcr_banks: Tcg2HashAlgorithmBitmap,
111}
112
113bitflags! {
114 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
116 #[repr(transparent)]
117 pub struct Tcg2HashLogExtendEventFlags: u64 {
118 const EFI_TCG2_EXTEND_ONLY = 0x0000_0000_0000_0001;
120
121 const PE_COFF_IMAGE = 0x0000_0000_0000_0010;
123 }
124}
125
126#[derive(Clone, Copy, Debug, Eq, PartialEq)]
127#[repr(C, packed)]
128pub struct Tcg2EventHeader {
129 pub header_size: u32,
130 pub header_version: u16,
131 pub pcr_index: u32,
132 pub event_type: EventType,
133}
134
135#[derive(Debug)]
142#[repr(C)]
143pub struct Tcg2Protocol {
144 pub get_capability: unsafe extern "efiapi" fn(
145 this: *mut Self,
146 protocol_capability: *mut Tcg2BootServiceCapability,
147 ) -> Status,
148
149 pub get_event_log: unsafe extern "efiapi" fn(
150 this: *mut Self,
151 event_log_format: Tcg2EventLogFormat,
152 event_log_location: *mut PhysicalAddress,
153 event_log_last_entry: *mut PhysicalAddress,
154 event_log_truncated: *mut u8,
155 ) -> Status,
156
157 pub hash_log_extend_event: unsafe extern "efiapi" fn(
158 this: *mut Self,
159 flags: Tcg2HashLogExtendEventFlags,
160 data_to_hash: PhysicalAddress,
161 data_to_hash_len: u64,
162 event: *const c_void,
163 ) -> Status,
164
165 pub submit_command: unsafe extern "efiapi" fn(
166 this: *mut Self,
167 input_parameter_block_size: u32,
168 input_parameter_block: *const u8,
169 output_parameter_block_size: u32,
170 output_parameter_block: *mut u8,
171 ) -> Status,
172
173 pub get_active_pcr_banks: unsafe extern "efiapi" fn(
174 this: *mut Self,
175 active_pcr_banks: *mut Tcg2HashAlgorithmBitmap,
176 ) -> Status,
177
178 pub set_active_pcr_banks: unsafe extern "efiapi" fn(
179 this: *mut Self,
180 active_pcr_banks: Tcg2HashAlgorithmBitmap,
181 ) -> Status,
182
183 pub get_result_of_set_active_pcr_banks: unsafe extern "efiapi" fn(
184 this: *mut Self,
185 operation_present: *mut u32,
186 response: *mut u32,
187 ) -> Status,
188}
189
190impl Tcg2Protocol {
191 pub const GUID: Guid = guid!("607f766c-7455-42be-930b-e4d76db2720f");
192}