From d002d47f336e0da61c2e590170f044f2e4e7b548 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 12 Jul 2023 14:42:47 +0200 Subject: [PATCH] Add keepalive messages This patch adds keepalive messages for ctaphid and ccid. To send correct ctaphid keepalive messages, runners need to call set_waiting from their UI implementation. Fixes: https://github.com/trussed-dev/pc-usbip-runner/issues/27 --- src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 736d9fb..65afe95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,14 @@ mod ccid; #[cfg(feature = "ctaphid")] mod ctaphid; -use std::{cell::RefCell, marker::PhantomData, rc::Rc, thread, time::Duration}; +use std::{ + cell::RefCell, + marker::PhantomData, + rc::Rc, + sync::atomic::{AtomicBool, Ordering}, + thread, + time::Duration, +}; use trussed::{ backend::{BackendId, CoreOnly, Dispatch}, @@ -17,6 +24,12 @@ use usb_device::{ }; use usbip_device::UsbIpBus; +static IS_WAITING: AtomicBool = AtomicBool::new(false); + +pub fn set_waiting(waiting: bool) { + IS_WAITING.store(waiting, Ordering::Relaxed) +} + pub type Client = ClientImplementation, D>; pub type InitPlatform = Box)>; @@ -106,6 +119,10 @@ impl<'interrupt, S: StoreProvider, D: Dispatch, A: Apps<'interrupt, Client #[cfg(feature = "ccid")] &mut ccid, ]); + #[cfg(feature = "ctaphid")] + ctaphid.send_keepalive(IS_WAITING.load(Ordering::Relaxed)); + #[cfg(feature = "ccid")] + ccid.send_wait_extension(); }); loop { thread::sleep(Duration::from_millis(5));