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 com1: HclUartSettings,
45 pub com2: HclUartSettings,
46 #[serde(with = "serde_helpers::as_string")]
47 pub bios_guid: Guid,
48 pub console_mode: u8,
49 pub enable_firmware_debugging: bool,
50 pub enable_hibernation: bool,
51 pub serial_number: String,
52 pub base_board_serial_number: String,
53 pub chassis_serial_number: String,
54 pub chassis_asset_tag: String,
55}
56
57#[derive(Debug, Default, Deserialize, Serialize)]
59#[serde(rename_all = "PascalCase")]
60pub enum HclSecureBootTemplateId {
61 #[serde(rename = "None")]
62 #[default]
63 None,
64 #[serde(rename = "MicrosoftWindows")]
65 MicrosoftWindows,
66 #[serde(rename = "MicrosoftUEFICertificateAuthority")]
67 MicrosoftUEFICertificateAuthority,
68}
69
70#[derive(Debug, Default, Deserialize, Serialize)]
72#[serde(default, rename_all = "PascalCase")]
73pub struct HclUartSettings {
74 pub enable_port: bool,
75 pub debugger_mode: bool,
76 pub enable_vmbus_redirector: bool,
77}
78
79#[derive(Debug, Default, Deserialize, Serialize)]
80#[serde(rename_all = "PascalCase")]
81pub struct HclDevicePlatformSettingsV2 {
82 pub r#static: HclDevicePlatformSettingsV2Static,
83 pub dynamic: HclDevicePlatformSettingsV2Dynamic,
84}
85
86#[derive(Debug, Copy, Clone, Deserialize, Serialize)]
88pub enum PcatBootDevice {
89 Floppy,
90 Optical,
91 HardDrive,
92 Network,
93}
94
95#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
97pub enum GuestStateLifetime {
98 #[default]
99 Default,
100 ReprovisionOnFailure,
101 Reprovision,
102 Ephemeral,
103}
104
105#[derive(Debug, Copy, Clone, Deserialize, Serialize, Default)]
107pub enum GuestStateEncryptionPolicy {
108 #[default]
115 Auto,
116 None,
121 GspById,
128 GspKey,
134 HardwareSealing,
137}
138
139open_enum! {
140 #[derive(Default, Deserialize, Serialize)]
142 pub enum EfiDiagnosticsLogLevelType: u32 {
143 DEFAULT = 0,
145 INFO = 1,
147 FULL = 2,
149 }
150}
151
152#[bitfield(u64)]
154#[derive(Deserialize, Serialize)]
155#[serde(transparent)]
156pub struct ManagementVtlFeatures {
157 pub strict_encryption_policy: bool,
158 pub _reserved1: bool,
159 pub control_ak_cert_provisioning: bool,
160 pub attempt_ak_cert_callback: bool,
161 pub tx_only_serial_port: bool,
162 #[bits(59)]
163 pub _reserved2: u64,
164}
165
166#[derive(Debug, Default, Deserialize, Serialize)]
167#[serde(rename_all = "PascalCase")]
168pub struct HclDevicePlatformSettingsV2Static {
169 pub legacy_memory_map: bool,
171 pub pause_after_boot_failure: bool,
172 pub pxe_ip_v6: bool,
173 pub measure_additional_pcrs: bool,
174 pub disable_frontpage: bool,
175 pub disable_sha384_pcr: bool,
176 pub media_present_enabled_by_default: bool,
177 pub memory_protection_mode: u8,
178 #[serde(default)]
179 pub default_boot_always_attempt: bool,
180
181 pub vpci_boot_enabled: bool,
183 #[serde(default)]
184 #[serde(with = "serde_helpers::opt_guid_str")]
185 pub vpci_instance_filter: Option<Guid>,
186
187 pub num_lock_enabled: bool,
189 pub pcat_boot_device_order: Option<[PcatBootDevice; 4]>,
190
191 pub smbios: HclDevicePlatformSettingsV2StaticSmbios,
192
193 #[serde(default)]
198 #[serde(with = "serde_helpers::opt_base64_vec")]
199 pub vtl2_settings: Option<Vec<u8>>,
200
201 pub vmbus_redirection_enabled: bool,
202 pub no_persistent_secrets: bool,
203 pub watchdog_enabled: bool,
204 #[serde(default)]
207 pub firmware_mode_is_pcat: bool,
208 #[serde(default)]
209 pub always_relay_host_mmio: bool,
210 #[serde(default)]
211 pub imc_enabled: bool,
212 #[serde(default)]
213 pub cxl_memory_enabled: bool,
214 #[serde(default)]
215 pub guest_state_lifetime: GuestStateLifetime,
216 #[serde(default)]
217 pub guest_state_encryption_policy: GuestStateEncryptionPolicy,
218 #[serde(default)]
219 pub efi_diagnostics_log_level: EfiDiagnosticsLogLevelType,
220 #[serde(default)]
221 pub management_vtl_features: ManagementVtlFeatures,
222 #[serde(default)]
223 pub hv_sint_enabled: bool,
224 #[serde(default)]
225 pub azi_hsm_enabled: bool,
226}
227
228#[derive(Debug, Default, Deserialize, Serialize)]
229#[serde(rename_all = "PascalCase")]
230pub struct HclDevicePlatformSettingsV2StaticSmbios {
231 pub system_manufacturer: String,
232 pub system_product_name: String,
233 pub system_version: String,
234 #[serde(rename = "SystemSKUNumber")]
235 pub system_sku_number: String,
236 pub system_family: String,
237 pub bios_lock_string: String,
238 pub memory_device_serial_number: String,
239}
240
241#[derive(Debug, Default, Deserialize, Serialize)]
242#[serde(rename_all = "PascalCase")]
243pub struct HclDevicePlatformSettingsV2Dynamic {
244 pub nvdimm_count: u16,
245 pub enable_psp: bool,
246 pub generation_id_low: u64,
247 pub generation_id_high: u64,
248 pub smbios: HclDevicePlatformSettingsV2DynamicSmbios,
249 pub is_servicing_scenario: bool,
250
251 #[serde(default)]
252 #[serde(with = "serde_helpers::vec_base64_vec")]
253 pub acpi_tables: Vec<Vec<u8>>,
254}
255
256#[derive(Debug, Default, Deserialize, Serialize)]
257#[serde(rename_all = "PascalCase")]
258pub struct HclDevicePlatformSettingsV2DynamicSmbios {
259 #[serde(with = "serde_helpers::base64_vec")]
260 pub processor_manufacturer: Vec<u8>,
261 #[serde(with = "serde_helpers::base64_vec")]
262 pub processor_version: Vec<u8>,
263
264 #[serde(rename = "ProcessorID")]
265 pub processor_id: u64,
266 pub external_clock: u16,
267 pub max_speed: u16,
268 pub current_speed: u16,
269 pub processor_characteristics: u16,
270 pub processor_family2: u16,
271 pub processor_type: u8,
272 pub voltage: u8,
273 pub status: u8,
274 pub processor_upgrade: u8,
275}
276
277#[cfg(test)]
278mod test {
279 use super::*;
280
281 #[test]
282 fn smoke_test_sample() {
283 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
284 "dps_test_json.json"
285 ))
286 .unwrap();
287 }
288
289 #[test]
290 fn smoke_test_sample_with_vtl2settings() {
291 serde_json::from_slice::<DevicePlatformSettingsV2Json>(include_bytes!(
292 "dps_test_json_with_vtl2settings.json"
293 ))
294 .unwrap();
295 }
296}