Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Add ctap hid api #539

Draft
wants to merge 4 commits into
base: dev/opensk
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions crates/api-desc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ api-store = ["internal-api-store"]
api-store-fragment = ["internal-api-store"]
api-timer = []
api-uart = []
api-usb-ctap = ["internal-api-usb"]
api-usb-serial = ["internal-api-usb"]
# Enables all API features.
full-api = [
Expand All @@ -59,6 +60,7 @@ full-api = [
"api-store-fragment",
"api-timer",
"api-uart",
"api-usb-ctap",
"api-usb-serial",
]
# Internal features.
Expand Down
79 changes: 79 additions & 0 deletions crates/api-desc/src/usb/ctap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::*;

pub(crate) fn new() -> Item {
let docs = docs!();
let name = "ctap".into();
let items = vec![
item! {
/// Reads from USB serial into a buffer.
///
/// Returns the number of bytes read. This function does not block and may return zero.
Comment on lines +22 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Reads from USB serial into a buffer.
///
/// Returns the number of bytes read. This function does not block and may return zero.
/// Reads a CTAP packet (64 bytes) from USB.
///
/// Returns whether a packet was read. This function does not block.

fn read "usr" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to allocate new unique identifiers, e.g. changing the us prefix into uc.

/// Address of the buffer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Address of the buffer.
/// Address of the buffer (must be at least 64 bytes).

ptr: *mut u8,

/// Length of the buffer in bytes.
len: usize,
Comment on lines +29 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this now that we fix the packet size

} -> usize
},
item! {
/// Writes to USB serial from a buffer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar changes here as for read

///
/// Returns the number of bytes written. This function does not block and may return
/// zero.
fn write "usw" {
/// Address of the buffer.
ptr: *const u8,

/// Length of the buffer in bytes.
len: usize,
} -> usize
},
item! {
/// USB serial events.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// USB serial events.
/// USB CTAP events.

enum Event {
/// Ready for read.
Read = 0,
/// Ready for write.
Write = 1,
}
},
item! {
/// Registers a callback when USB serial is ready.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Registers a callback when USB serial is ready.
/// Registers a callback when USB CTAP is ready.

///
/// It is possible that the callback is spuriously called. The callback is only
/// guaranteed to be called after the associated operation processed less bytes than the
/// buffer size.
Comment on lines +59 to +60
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// guaranteed to be called after the associated operation processed less bytes than the
/// buffer size.
/// guaranteed to be called after the associated operation returned false.

fn register "use" {
event: usize,
handler_func: fn { data: *const void },
handler_data: *const void,
} -> ()
},
item! {
/// Unregisters a callback.
fn unregister "usd" {
event: usize,
} -> ()
},
item! {
/// Flushs the USB serial.
fn flush "usf" {} -> ()
},
Comment on lines +73 to +76
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this function is needed. Let's remove it.

];
Item::Mod(Mod { docs, name, items })
}
1 change: 1 addition & 0 deletions crates/api-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ api-store = ["wasefire-applet-api-desc/api-store"]
api-store-fragment = ["wasefire-applet-api-desc/api-store-fragment"]
api-timer = ["wasefire-applet-api-desc/api-timer"]
api-uart = ["wasefire-applet-api-desc/api-uart"]
api-usb-ctap = ["wasefire-applet-api-desc/api-usb-ctap"]
api-usb-serial = ["wasefire-applet-api-desc/api-usb-serial"]

[lints]
Expand Down
2 changes: 2 additions & 0 deletions crates/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ api-store = ["wasefire-applet-api-macro/api-store"]
api-store-fragment = ["wasefire-applet-api-macro/api-store-fragment"]
api-timer = ["wasefire-applet-api-macro/api-timer"]
api-uart = ["wasefire-applet-api-macro/api-uart"]
api-usb-ctap = ["wasefire-applet-api-macro/api-usb-ctap"]
api-usb-serial = ["wasefire-applet-api-macro/api-usb-serial"]
# Enables all API features (unstable for host).
full-api = [
Expand All @@ -66,6 +67,7 @@ full-api = [
"api-store-fragment",
"api-timer",
"api-uart",
"api-usb-ctap",
"api-usb-serial",
]
# Implements the API with weak symbols to permit custom definitions (only
Expand Down
Loading