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
This commit is contained in:
Robin Krahl
2023-07-12 15:50:34 +02:00
parent e78883847f
commit d002d47f33
+18 -1
View File
@@ -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<S, D = CoreOnly> = ClientImplementation<Service<S, D>, D>;
pub type InitPlatform<S> = Box<dyn Fn(&mut Platform<S>)>;
@@ -106,6 +119,10 @@ impl<'interrupt, S: StoreProvider, D: Dispatch, A: Apps<'interrupt, Client<S, D>
#[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));