tpm: drop cmd from Emulator struct
The command is not done asynchronously. And there is no way to propagate
this error anywhere.
@@ -72,7 +72,6 @@ pub struct BackendCmd {
}
pub struct Emulator {
- cmd: Option<BackendCmd>,
caps: PtmCap, /* capabilities of the TPM */
control_socket: SocketDev,
data_fd: RawFd,
@@ -100,7 +99,6 @@ impl Emulator {
})?;
let mut emulator = Self {
- cmd: None,
caps: 0,
control_socket: socket,
data_fd: -1,
@@ -287,13 +285,12 @@ impl Emulator {
}
/// Function to write to data socket and read the response from it
- fn unix_tx_bufs(&mut self) -> Result<()> {
+ fn unix_tx_bufs(&mut self, cmd: &mut BackendCmd) -> Result<()> {
let isselftest: bool;
// SAFETY: type "sockaddr_storage" is valid with an all-zero byte-pattern value
let mut addr: sockaddr_storage = unsafe { mem::zeroed() };
let mut len = mem::size_of::<sockaddr_storage>() as socklen_t;
- if let Some(ref mut cmd) = self.cmd {
cmd.selftest_done = false;
isselftest = is_selftest(cmd.input.to_vec(), cmd.input_len);
@@ -362,34 +359,20 @@ impl Emulator {
errcode.copy_from_slice(&cmd.output[6..6 + 4]);
cmd.selftest_done = u32::from_ne_bytes(errcode).to_be() == 0;
}
- }
Ok(())
}
- pub fn deliver_request(&mut self, in_cmd: &mut BackendCmd) -> Result<Vec<u8>> {
- if self.cmd.is_some() {
- //previous request did not finish cleanly
- return Err(Error::DeliverRequest(anyhow!(
- "Cannot deliver tpm Request as previous cmd did not complete."
- )));
- }
- self.cmd = Some(in_cmd.clone());
-
- self.unix_tx_bufs()?;
+ pub fn deliver_request(&mut self, cmd: &mut BackendCmd) -> Result<Vec<u8>> {
+ self.unix_tx_bufs(cmd)?;
- let output = self.cmd.as_ref().unwrap().output.clone();
- in_cmd.output.fill(0);
- in_cmd.output.clone_from(&output);
+ let output = cmd.output.clone();
+ cmd.output.fill(0);
+ cmd.output.clone_from(&output);
- self.backend_request_completed();
Ok(output)
}
- pub fn backend_request_completed(&mut self) {
- self.cmd = None;
- }
-
pub fn cancel_cmd(&mut self) -> Result<()> {
let mut res: PtmResult = 0;
