diff --git a/Cargo.lock b/Cargo.lock index 8c54e35..f9ec61f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1453,7 +1453,7 @@ dependencies = [ [[package]] name = "trussed" version = "0.1.0" -source = "git+https://github.com/trussed-dev/trussed.git?rev=6bba8fde36d05c0227769eb63345744e87d84b2b#6bba8fde36d05c0227769eb63345744e87d84b2b" +source = "git+https://github.com/trussed-dev/trussed.git?rev=805fe7657e79e06b3220324481cd6325b94877d7#805fe7657e79e06b3220324481cd6325b94877d7" dependencies = [ "aes", "bitflags 2.6.0", diff --git a/Cargo.toml b/Cargo.toml index 311be6a..e2c2d81 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ delog = { version = "0.1.6", features = ["std-log"] } heapless-bytes = "0.3" littlefs2-core = "0.1" pretty_env_logger = "0.4.0" -trussed = { version = "0.1", features = ["clients-1"] } +trussed = "0.1" [features] default = ["ctaphid", "ccid"] @@ -34,4 +34,4 @@ ctaphid = ["ctaphid-dispatch", "usbd-ctaphid"] ccid = ["apdu-dispatch", "usbd-ccid"] [patch.crates-io] -trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "6bba8fde36d05c0227769eb63345744e87d84b2b" } +trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "805fe7657e79e06b3220324481cd6325b94877d7" } diff --git a/examples/dummy.rs b/examples/dummy.rs index 3b8dcf0..2267792 100644 --- a/examples/dummy.rs +++ b/examples/dummy.rs @@ -18,11 +18,12 @@ use clap::Parser; use clap_num::maybe_hex; use littlefs2_core::path; use trussed::{ - backend::CoreOnly, - client::{Client, ClientBuilder}, + backend::{CoreOnly, NoId}, + client::Client, + pipe::{ServiceEndpoint, TrussedChannel}, service::Service, syscall, - types::Vec, + types::{CoreContext, NoData}, virt::{self, Platform, StoreProvider}, }; use trussed_usbip::Syscall; @@ -57,7 +58,7 @@ struct DummyApp { } impl DummyApp { - fn rng(&mut self, response: &mut Vec) { + fn rng(&mut self, response: &mut heapless_bytes::Bytes) { let bytes = syscall!(self.client.random_bytes(57)).bytes; response.extend_from_slice(&bytes).unwrap(); } @@ -95,11 +96,17 @@ impl<'a, S: StoreProvider> trussed_usbip::Apps<'a, S, CoreOnly> { type Data = (); - fn new(service: &mut Service, CoreOnly>, syscall: Syscall, _data: ()) -> Self { - let client = ClientBuilder::new(path!("dummy")) - .prepare(service) - .unwrap() - .build(syscall); + fn new( + _service: &mut Service, CoreOnly>, + endpoints: &mut Vec>, + syscall: Syscall, + _data: (), + ) -> Self { + static CHANNEL: TrussedChannel = TrussedChannel::new(); + let (requester, responder) = CHANNEL.split().unwrap(); + let context = CoreContext::new(path!("dummy").into()); + endpoints.push(ServiceEndpoint::new(responder, context, &[])); + let client = trussed_usbip::Client::new(requester, syscall, None); let dummy = DummyApp { client }; Self { dummy } } diff --git a/src/lib.rs b/src/lib.rs index 60ebe8d..16033ad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,7 @@ use std::{ use trussed::{ backend::{CoreOnly, Dispatch}, + pipe::ServiceEndpoint, service::Service, virt::{self, Platform, StoreProvider}, ClientImplementation, @@ -31,7 +32,7 @@ pub fn set_waiting(waiting: bool) { IS_WAITING.store(waiting, Ordering::Relaxed) } -pub type Client = ClientImplementation; +pub type Client = ClientImplementation<'static, Syscall, D>; pub type InitPlatform = Box)>; @@ -52,7 +53,12 @@ impl Options { pub trait Apps<'interrupt, S: StoreProvider, D: Dispatch> { type Data; - fn new(service: &mut Service, D>, syscall: Syscall, data: Self::Data) -> Self; + fn new( + service: &mut Service, D>, + endpoints: &mut Vec>, + syscall: Syscall, + data: Self::Data, + ) -> Self; #[cfg(feature = "ctaphid")] fn with_ctaphid_apps( @@ -80,7 +86,11 @@ pub struct Runner { _marker: PhantomData, } -impl<'interrupt, S: StoreProvider, D: Dispatch, A: Apps<'interrupt, S, D>> Runner { +impl<'interrupt, S: StoreProvider, D: Dispatch, A: Apps<'interrupt, S, D>> Runner +where + D::BackendId: Send + Sync, + D::Context: Send + Sync, +{ pub fn builder(store: S, options: Options) -> Builder { Builder::new(store, options) } @@ -107,9 +117,10 @@ impl<'interrupt, S: StoreProvider, D: Dispatch, A: Apps<'interrupt, S, D>> Runne let mut usb_device = build_device(&bus_allocator, &self.options); let mut service = Service::with_dispatch(platform, self.dispatch); + let mut endpoints = Vec::new(); let (syscall_sender, syscall_receiver) = mpsc::channel(); let syscall = Syscall(syscall_sender); - let mut apps = A::new(&mut service, syscall, data); + let mut apps = A::new(&mut service, &mut endpoints, syscall, data); log::info!("Ready for work"); thread::scope(|s| { @@ -140,7 +151,7 @@ impl<'interrupt, S: StoreProvider, D: Dispatch, A: Apps<'interrupt, S, D>> Runne // trussed task s.spawn(move || { for _ in syscall_receiver.iter() { - service.process() + service.process(&mut endpoints) } });