Skip to content

Commit

Permalink
Stable blinking pattern
Browse files Browse the repository at this point in the history
Before, if the device gets a CTAP2 UP request and another channel sends
packets, the blinking pattern would have sped up.

The patch for the Tock USB implementation fixes a panic after a timeout
in send.
  • Loading branch information
kaczmarczyck committed Sep 5, 2024
1 parent 01d7ee3 commit 269578b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 3 additions & 4 deletions patches/tock/03-add-ctap-modules.patch
Original file line number Diff line number Diff line change
Expand Up @@ -559,10 +559,10 @@ index 000000000..30cac1323
+}
diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs
new file mode 100644
index 000000000..5ad2c44b3
index 000000000..fdf92a28e
--- /dev/null
+++ b/capsules/src/usb/usbc_ctap_hid.rs
@@ -0,0 +1,554 @@
@@ -0,0 +1,553 @@
+//! A USB HID client of the USB hardware interface
+
+use super::app::App;
Expand Down Expand Up @@ -927,9 +927,8 @@ index 000000000..5ad2c44b3
+ if self
+ .client
+ .map_or(false, |client| client.can_receive_packet(&app))
+ && self.pending_out.take()
+ {
+ assert!(self.pending_out.take());
+
+ // Clear any pending packet on the transmitting side.
+ // It's up to the client to handle the received packet and decide if this packet
+ // should be re-transmitted or not.
Expand Down
15 changes: 13 additions & 2 deletions src/env/tock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use alloc::vec::Vec;
use clock::TockClock;
use core::convert::TryFrom;
use core::marker::PhantomData;
use core::mem;
#[cfg(all(target_has_atomic = "8", not(feature = "std")))]
use core::sync::atomic::{AtomicBool, Ordering};
use libtock_console::{Console, ConsoleWriter};
Expand All @@ -26,6 +27,7 @@ use libtock_drivers::{rng, usb_ctap_hid};
use libtock_leds::Leds;
use libtock_platform as platform;
use libtock_platform::Syscalls;
use opensk::api::clock::Clock;
use opensk::api::connection::{HidConnection, RecvStatus, UsbEndpoint};
use opensk::api::crypto::software_crypto::SoftwareCrypto;
use opensk::api::customization::{CustomizationImpl, AAGUID_LENGTH, DEFAULT_CUSTOMIZATION};
Expand Down Expand Up @@ -118,6 +120,7 @@ pub struct TockEnv<
store: Store<Storage<S, C>>,
upgrade_storage: Option<UpgradeStorage<S, C>>,
blink_pattern: usize,
blink_timer: <TockClock<S> as Clock>::Timer,
clock: TockClock<S>,
c: PhantomData<C>,
}
Expand All @@ -141,6 +144,7 @@ impl<S: Syscalls, C: platform::subscribe::Config + platform::allow_ro::Config> D
store,
upgrade_storage,
blink_pattern: 0,
blink_timer: <TockClock<S> as Clock>::Timer::default(),
clock: TockClock::default(),
c: PhantomData,
}
Expand Down Expand Up @@ -295,8 +299,14 @@ where
packet: &mut [u8; 64],
timeout_ms: usize,
) -> UserPresenceWaitResult {
blink_leds::<S>(self.blink_pattern);
self.blink_pattern += 1;
let mut new_timer = self.clock.make_timer(timeout_ms);
mem::swap(&mut self.blink_timer, &mut new_timer);
if self.clock().is_elapsed(&new_timer) {
blink_leds::<S>(self.blink_pattern);
self.blink_pattern += 1;
} else {
mem::swap(&mut self.blink_timer, &mut new_timer);
}

let result =
UsbCtapHid::<S>::recv_with_buttons(packet, Duration::from_ms(timeout_ms as isize));
Expand All @@ -323,6 +333,7 @@ where

fn check_complete(&mut self) {
switch_off_leds::<S>();
self.blink_timer = <TockClock<S> as Clock>::Timer::default();
}
}

Expand Down

0 comments on commit 269578b

Please sign in to comment.