#![cfg_attr(not(feature = "tlcl"), allow(dead_code))]
use crate::LOG_DBG;
#[cfg(feature = "tlcl")]
use crate::{structs::SysinfoRollbackVersionResponse, tlcl::TlclRead, tpm_nv_read};
const FIRMWARE_ROLLBACK_NV_INDEX: u32 = 0x1007;
const KERNEL_ROLLBACK_NV_INDEX: u32 = 0x1008;
const FIRMWARE_MANAGEMENT_PARAMETERS_NV_INDEX: u32 = 0x100A;
#[cfg(feature = "tlcl")]
pub fn get_kernel_rollback_version() -> SysinfoRollbackVersionResponse {
tpm_nv_read!(KERNEL_ROLLBACK_NV_INDEX, 0x9, |buf: &[u8]| {
match buf[0] {
0x02 => u32::from_le_bytes(buf[0x5..0x9].try_into().unwrap()),
0x10 => u32::from_le_bytes(buf[0x4..0x8].try_into().unwrap()),
_ => u32::MAX,
}
})
}
#[cfg(feature = "tlcl")]
pub fn get_firmware_rollback_version() -> SysinfoRollbackVersionResponse {
tpm_nv_read!(FIRMWARE_ROLLBACK_NV_INDEX, 0x6, |buf: &[u8]| {
u32::from_le_bytes(buf[0x2..0x6].try_into().unwrap())
})
}
#[cfg(feature = "tlcl")]
pub fn get_firmware_management_parameters() -> SysinfoRollbackVersionResponse {
tpm_nv_read!(
FIRMWARE_MANAGEMENT_PARAMETERS_NV_INDEX,
0x8,
|buf: &[u8]| { u32::from_le_bytes(buf[0x4..0x8].try_into().unwrap()) }
)
}