From ec57c12d9adb2ac0e71ed31699a08badbb8a09bc Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Mon, 24 Jan 2022 19:15:56 -0600 Subject: [PATCH 1/3] only send keepalive ctaphid messages while handling cbor messages --- components/usbd-ctaphid/src/pipe.rs | 39 ++++++++++++++++++++--------- runners/lpc55/Cargo.toml | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/components/usbd-ctaphid/src/pipe.rs b/components/usbd-ctaphid/src/pipe.rs index 54cda63e..988a70ef 100644 --- a/components/usbd-ctaphid/src/pipe.rs +++ b/components/usbd-ctaphid/src/pipe.rs @@ -150,6 +150,8 @@ pub struct Pipe<'alloc, Bus: UsbBus> { // a "read once" indicator if now we're waiting on the application processing started_processing: bool, + + needs_keepalive: bool, } impl<'alloc, Bus: UsbBus> Pipe<'alloc, Bus> { @@ -176,6 +178,7 @@ impl<'alloc, Bus: UsbBus> Pipe<'alloc, Bus> { implements: 0x80, last_milliseconds: initial_milliseconds, started_processing: false, + needs_keepalive: false, } } @@ -469,6 +472,11 @@ impl<'alloc, Bus: UsbBus> Pipe<'alloc, Bus> { }, _ => { + if request.command == Command::Cbor { + self.needs_keepalive = true; + } else { + self.needs_keepalive = false; + } if self.interchange.state() == interchange::State::Responded { info!("dumping stale response"); self.interchange.take_response(); @@ -502,23 +510,30 @@ impl<'alloc, Bus: UsbBus> Pipe<'alloc, Bus> { pub fn send_keepalive(&mut self, is_waiting_for_user_presence: bool) -> bool { if let State::WaitingOnAuthenticator(request) = &self.state { - info!("keepalive"); + if !self.needs_keepalive { + // let response go out normally in idle loop + info!("cmd does not need keepalive messages"); + false + } else { - let mut packet = [0u8; PACKET_SIZE]; + info!("keepalive"); - packet[..4].copy_from_slice(&request.channel.to_be_bytes()); - packet[4] = 0x80 | 0x3B; - packet[5..7].copy_from_slice(&1u16.to_be_bytes()); + let mut packet = [0u8; PACKET_SIZE]; - if is_waiting_for_user_presence { - packet[7] = KeepaliveStatus::UpNeeded as u8; - } else { - packet[7] = KeepaliveStatus::Processing as u8; - } + packet[..4].copy_from_slice(&request.channel.to_be_bytes()); + packet[4] = 0x80 | 0x3B; + packet[5..7].copy_from_slice(&1u16.to_be_bytes()); + + if is_waiting_for_user_presence { + packet[7] = KeepaliveStatus::UpNeeded as u8; + } else { + packet[7] = KeepaliveStatus::Processing as u8; + } - self.write_endpoint.write(&packet).ok(); + self.write_endpoint.write(&packet).ok(); - true + true + } } else { info!("keepalive done"); false diff --git a/runners/lpc55/Cargo.toml b/runners/lpc55/Cargo.toml index 2b99e8e8..97e611c0 100644 --- a/runners/lpc55/Cargo.toml +++ b/runners/lpc55/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "runner" -version = "1.0.8" +version = "1.0.9" authors = ["Nicolas Stalder ", "Conor Patrick "] edition = "2018" resolver = "2" From 35e505f9ecf0d572a1c16d2b1d841431774df125 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 25 Jan 2022 14:49:34 +0100 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e618803..67459dd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Unreleased + +Update to upstream release 1.0.9. + +## Bugfixes + +- usbd-ctaphid: fix ctaphid keepalive messages - fixes "busy" issue under Windows ([#21][]) + + +[#21]: https://github.com/Nitrokey/nitrokey-3-firmware/issues/21 + # v1.0.1 (2022-01-15) ## Bugfixes From dff0019643c450533ee5bf39ec7ea5ad2dd7a9e7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 25 Jan 2022 17:15:27 +0100 Subject: [PATCH 3/3] Bump version to 1.0.2-rc.1 --- runners/lpc55/Cargo.lock | 2 +- runners/lpc55/Cargo.toml | 2 +- runners/lpc55/config/commands.bd | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/runners/lpc55/Cargo.lock b/runners/lpc55/Cargo.lock index 328ea2d2..042e950d 100644 --- a/runners/lpc55/Cargo.lock +++ b/runners/lpc55/Cargo.lock @@ -1288,7 +1288,7 @@ dependencies = [ [[package]] name = "runner" -version = "1.0.1" +version = "1.0.2-rc.1" dependencies = [ "admin-app", "apdu-dispatch", diff --git a/runners/lpc55/Cargo.toml b/runners/lpc55/Cargo.toml index 0fc72d55..f7e84597 100644 --- a/runners/lpc55/Cargo.toml +++ b/runners/lpc55/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "runner" -version = "1.0.1" +version = "1.0.2-rc.1" authors = ["Nicolas Stalder ", "Conor Patrick "] edition = "2018" resolver = "2" diff --git a/runners/lpc55/config/commands.bd b/runners/lpc55/config/commands.bd index 51b6a29a..12622e23 100644 --- a/runners/lpc55/config/commands.bd +++ b/runners/lpc55/config/commands.bd @@ -1,8 +1,8 @@ options { flags = 0x8; buildNumber = 0x1; - productVersion = "1.0.1"; - componentVersion = "1.0.1"; + productVersion = "1.0.2"; + componentVersion = "1.0.2"; secureBinaryVersion = "2.1"; } @@ -11,8 +11,8 @@ sources { } section (0) { - version_check sec 4194305; - version_check nsec 4194305; + version_check sec 4194306; + version_check nsec 4194306; erase 0x0..0x93000; load inputFile > 0x0; }