Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ license = "Apache-2.0 OR MIT"
repository = "https://github.com/solokeys/ctaphid-dispatch"

[workspace.dependencies]
heapless-bytes = "0.3"
heapless-bytes = "0.5"
trussed-core = "0.1.0"

[patch.crates-io]
ctaphid-app.path = "app"
trussed-core = { git = "https://github.com/trussed-dev/trussed.git", rev = "1e7b09a983dc8ae64a7ad8401ce541a9a77e5939"}
6 changes: 3 additions & 3 deletions app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_std]

use heapless_bytes::Bytes;
use heapless_bytes::BytesView;
use trussed_core::InterruptFlag;

mod command;
Expand All @@ -10,7 +10,7 @@ pub use command::{Command, VendorCommand};
/// trait interface for a CTAPHID application.
/// The application chooses which commands to register to, and will be called upon
/// when the commands are received in the CTAPHID layer. Only one application can be registered to a particular command.
pub trait App<'interrupt, const N: usize> {
pub trait App<'interrupt> {
/// Get access to the app interrupter
fn interrupt(&self) -> Option<&'interrupt InterruptFlag> {
None
Expand All @@ -27,7 +27,7 @@ pub trait App<'interrupt, const N: usize> {
&mut self,
command: Command,
request: &[u8],
response: &mut Bytes<N>,
response: &mut BytesView,
) -> Result<(), Error>;
}

Expand Down
15 changes: 7 additions & 8 deletions dispatch/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> {

fn find_app<'a, 'b>(
command: Command,
apps: &'a mut [&'b mut dyn App<'interrupt, N>],
) -> Option<&'a mut &'b mut dyn App<'interrupt, N>> {
apps: &'a mut [&'b mut dyn App<'interrupt>],
) -> Option<&'a mut &'b mut dyn App<'interrupt>> {
apps.iter_mut()
.find(|app| app.commands().contains(&command))
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> {
}

#[inline(never)]
fn call_app(&mut self, app: &mut dyn App<'interrupt, N>, command: Command, request: &Bytes<N>) {
fn call_app(&mut self, app: &mut dyn App<'interrupt>, command: Command, request: &[u8]) {
let response_buffer = self
.responder
.response_mut()
Expand Down Expand Up @@ -106,18 +106,17 @@ impl<'pipe, 'interrupt, const N: usize> Dispatch<'pipe, 'interrupt, N> {
}

#[inline(never)]
pub fn poll(&mut self, apps: &mut [&mut dyn App<'interrupt, N>]) -> bool {
pub fn poll(&mut self, apps: &mut [&mut dyn App<'interrupt>]) -> bool {
// We could call take_request directly, but for some reason this doubles stack usage.
let mut message_buffer = Bytes::new();
let mut buffer = Bytes::<N>::new();
if let Ok((command, message)) = self.responder.request() {
// info_now!("cmd: {}", u8::from(command));
// info_now!("cmd: {:?}", command);

message_buffer.extend_from_slice(message).unwrap();

buffer.extend_from_slice(message).unwrap();
if let Some(app) = Self::find_app(*command, apps) {
// match app.call(command, self.responder.response_mut().unwrap()) {
self.call_app(*app, *command, &message_buffer);
self.call_app(*app, *command, &buffer);
} else {
self.reply_with_error(Error::InvalidCommand);
}
Expand Down