use super::types::*;
use crate::impl_const_id;
use iocuddle::{Group, Ioctl, WriteRead};
use std::marker::PhantomData;
impl_const_id! {
pub Id => u32;
PlatformReset = 0x0,
PlatformStatus = 0x1,
PekGen = 0x2,
PekCsr<'_> = 0x3,
PdhGen = 0x4,
PdhCertExport<'_> = 0x5,
PekCertImport<'_> = 0x6,
GetId<'_> = 0x8,
}
const CSV: Group = Group::new(b'S');
pub const PLATFORM_RESET: Ioctl<WriteRead, &Command<PlatformReset>> = unsafe { CSV.write_read(0) };
pub const PLATFORM_STATUS: Ioctl<WriteRead, &Command<PlatformStatus>> =
unsafe { CSV.write_read(0) };
pub const PEK_GEN: Ioctl<WriteRead, &Command<PekGen>> = unsafe { CSV.write_read(0) };
pub const PEK_CSR: Ioctl<WriteRead, &Command<PekCsr<'_>>> = unsafe { CSV.write_read(0) };
pub const PDH_GEN: Ioctl<WriteRead, &Command<PdhGen>> = unsafe { CSV.write_read(0) };
pub const PDH_CERT_EXPORT: Ioctl<WriteRead, &Command<PdhCertExport<'_>>> =
unsafe { CSV.write_read(0) };
pub const PEK_CERT_IMPORT: Ioctl<WriteRead, &Command<PekCertImport<'_>>> =
unsafe { CSV.write_read(0) };
pub const GET_ID: Ioctl<WriteRead, &Command<GetId<'_>>> = unsafe { CSV.write_read(0) };
#[repr(C, packed)]
pub struct Command<'a, T: Id> {
pub code: u32,
pub data: u64,
pub error: u32,
_phantom: PhantomData<&'a T>,
}
impl<'a, T: Id> Command<'a, T> {
pub fn from_mut(subcmd: &'a mut T) -> Self {
Command {
code: T::ID,
data: subcmd as *mut T as u64,
error: 0,
_phantom: PhantomData,
}
}
pub fn from(subcmd: &'a T) -> Self {
Command {
code: T::ID,
data: subcmd as *const T as u64,
error: 0,
_phantom: PhantomData,
}
}
}