1use bitfield_struct::bitfield;
8use guid::Guid;
9use open_enum::open_enum;
10use serde::Deserialize;
11use serde::Serialize;
12
13pub type DevLoopCompatOption<T> = Option<T>;
23
24#[derive(Debug, Default, Deserialize, Serialize)]
25#[serde(rename_all = "PascalCase")]
26pub struct DevicePlatformSettingsV2Json {
27 pub v1: HclDevicePlatformSettings,
28 pub v2: HclDevicePlatformSettingsV2,
29}
30
31#[derive(Debug, Default, Deserialize, Serialize)]
37#[serde(default, rename_all = "PascalCase")]
38pub struct HclDevicePlatformSettings {
39 pub secure_boot_enabled: bool,
40 pub secure_boot_template_id: HclSecureBootTemplateId,
41 pub enable_battery: bool,
42 pub enable_processor_idle: bool,
43 pub enable_tpm: bool,
44 pub enable_ipmi: bool,
45 pub com1: HclUartSettings,
46 pub com2: HclUartSettings,
47 #[serde(with = "serde_helpers::as_string")]
48 pub bios_guid: Guid,
49 pub console_mode: u8,
50 pub enable_firmware_debugging: bool,
51 pub enable_hibernation: bool,
52 pub serial_number: String,
53 pub base_board_serial_number: String,
54 pub chassis_serial_number: String,
55 pub chassis_asset_tag: String,
56}
57
58#[derive(Debug, Default, Deserialize, Serialize)]
60#[serde(rename_all = "PascalCase")]
61pub enum HclSecureBootTemplateId {
62 #[serde(rename = "None")]
63 #[default]
64 None,
65 #[serde(rename = "MicrosoftWindows")]
66 MicrosoftWindows,
67 #[serde(rename = "MicrosoftUEFICertificateAuthority")]
68 MicrosoftUEFICertificateAuthority,
69}
70
71#[derive(Debug, Default, Deserialize, Serialize)]
73#[serde(default, rename_all = "PascalCase")]
74pub struct HclUartSettings {
75 pub enable_port: bool,
76 pub debugger_mode: bool,
77 pub enable_vmbus_redirector: bool,
78}
79
80#[derive(Debug, Default, Deserialize, Serialize)]
81#[serde(rename_all = "PascalCase")]
82pub struct HclDevicePlatformSettingsV2 {
83 pub r#static: HclDevicePlatformSettingsV2Static,
84 pub dynamic: HclDevicePlatformSettingsV2Dynamic,
85}
86
87#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
89pub enum PcatBootDevice {
90 Floppy,
91 Optical,
92 HardDrive,
93 Network,
94}
95
96#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
98pub enum GuestStateLifetime {
99 #[default]
100 Default,
101 ReprovisionOnFailure,
102 Reprovision,
103 Ephemeral,
104}
105
106#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
108pub enum GuestStateEncryptionPolicy {
109 #[default]
116 Auto,
117 None,
122 GspById,
129 GspKey,
135 HardwareSealing,
139}
140
141open_enum! {
142 #[derive(Default, Deserialize, Serialize)]
144 pub enum EfiDiagnosticsLogLevelType: u32 {
145 DEFAULT = 0,
147 INFO = 1,
149 FULL = 2,
151 }
152}
153
154#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
165pub enum HardwareSealingPolicy {
166 #[default]
168 None,
169 Hash,
171 Signer,
173}
174
175#[bitfield(u64)]
177#[derive(Deserialize, Serialize)]
178#[serde(transparent)]
179pub struct ManagementVtlFeatures {
180 pub strict_encryption_policy: bool,
181 pub load_firmware_supported: bool,
184 pub control_ak_cert_provisioning: bool,
185 pub attempt_ak_cert_callback: bool,
186 pub tx_only_serial_port: bool,
187 _flag5: bool, pub use_tpm_138_by_default: bool,
189 pub use_tpm_185_by_default: bool,
190 #[bits(56)]
191 pub _reserved2: u64,
192}
193
194#[derive(Debug, Default, Deserialize, Serialize)]
195#[serde(rename_all = "PascalCase")]
196pub struct HclDevicePlatformSettingsV2Static {
197 pub legacy_memory_map: bool,
199 pub pause_after_boot_failure: bool,
200 pub pxe_ip_v6: bool,
201 pub measure_additional_pcrs: bool,
202 pub disable_frontpage: bool,
203 pub disable_sha384_pcr: bool,
204 pub media_present_enabled_by_default: bool,
205 pub memory_protection_mode: u8,
206 #[serde(default)]
207 pub default_boot_always_attempt: bool,
208
209 pub vpci_boot_enabled: bool,
211 #[serde(default)]
212 #[serde(with = "serde_helpers::opt_guid_str")]
213 pub vpci_instance_filter: Option<Guid>,
214
215 pub num_lock_enabled: bool,
217 pub pcat_boot_device_order: Option<[PcatBootDevice; 4]>,
218
219 pub smbios: HclDevicePlatformSettingsV2StaticSmbios,
220
221 #[serde(default)]
226 #[serde(with = "serde_helpers::opt_base64_vec")]
227 pub vtl2_settings: Option<Vec<u8>>,
228
229 pub vmbus_redirection_enabled: bool,
230 pub no_persistent_secrets: bool,
231 pub watchdog_enabled: bool,
232 #[serde(default)]
235 pub firmware_mode_is_pcat: bool,
236 #[serde(default)]
237 pub always_relay_host_mmio: bool,
238 #[serde(default)]
239 pub imc_enabled: bool,
240 #[serde(default)]
241 pub cxl_memory_enabled: bool,
242 #[serde(default)]
243 pub guest_state_lifetime: GuestStateLifetime,
244 #[serde(default)]
245 pub guest_state_encryption_policy: GuestStateEncryptionPolicy,
246 #[serde(default)]
247 pub efi_diagnostics_log_level: EfiDiagnosticsLogLevelType,
248 #[serde(default)]
249 pub management_vtl_features: ManagementVtlFeatures,
250 #[serde(default)]
251 pub force_dma_bounce_enabled: bool,
252 #[serde(default)]
253 pub hardware_sealing_policy_id: HardwareSealingPolicy,
254}
255
256#[derive(Debug, Default, Deserialize, Serialize)]
257#[serde(rename_all = "PascalCase")]
258pub struct HclDevicePlatformSettingsV2StaticSmbios {
259 pub system_manufacturer: String,
260 pub system_product_name: String,
261 pub system_version: String,
262 #[serde(rename = "SystemSKUNumber")]
263 pub system_sku_number: String,
264 pub system_family: String,
265 pub bios_lock_string: String,
266 pub memory_device_serial_number: String,
267}
268
269#[derive(Debug, Default, Deserialize, Serialize)]
270#[serde(rename_all = "PascalCase")]
271pub struct HclDevicePlatformSettingsV2Dynamic {
272 pub nvdimm_count: u16,
273 pub enable_psp: bool,
274 pub generation_id_low: u64,
275 pub generation_id_high: u64,
276 pub smbios: HclDevicePlatformSettingsV2DynamicSmbios,
277 pub is_servicing_scenario: bool,
278
279 #[serde(default)]
280 #[serde(with = "serde_helpers::vec_base64_vec")]
281 pub acpi_tables: Vec<Vec<u8>>,
282}
283
284#[derive(Debug, Default, Deserialize, Serialize)]
285#[serde(rename_all = "PascalCase")]
286pub struct HclDevicePlatformSettingsV2DynamicSmbios {
287 #[serde(with = "serde_helpers::base64_vec")]
288 pub processor_manufacturer: Vec<u8>,
289 #[serde(with = "serde_helpers::base64_vec")]
290 pub processor_version: Vec<u8>,
291
292 #[serde(rename = "ProcessorID")]
293 pub processor_id: u64,
294 pub external_clock: u16,
295 pub max_speed: u16,
296 pub current_speed: u16,
297 pub processor_characteristics: u16,
298 pub processor_family2: u16,
299 pub processor_type: u8,
300 pub voltage: u8,
301 pub status: u8,
302 pub processor_upgrade: u8,
303}
304
305#[cfg(test)]
306mod test {
307 use super::*;
308
309 #[test]
310 fn smoke_test_sample() {
311 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
312 "dps_test_json.json"
313 ))
314 .unwrap();
315 }
316
317 #[test]
318 fn smoke_test_sample_with_vtl2settings() {
319 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
320 "dps_test_json_with_vtl2settings.json"
321 ))
322 .unwrap();
323 }
324}