Merge branch 'master' into fix-workflows

This commit is contained in:
gendx
2020-09-24 14:41:26 +02:00
committed by GitHub
3 changed files with 182 additions and 145 deletions

View File

@@ -1,16 +1,111 @@
diff --git a/boards/components/src/lib.rs b/boards/components/src/lib.rs
index dc56c94d2..917497af4 100644
--- a/boards/components/src/lib.rs
+++ b/boards/components/src/lib.rs
@@ -36,3 +36,4 @@ pub mod spi;
pub mod st7735;
pub mod temperature;
pub mod touch;
+pub mod usb_ctap;
diff --git a/boards/components/src/usb_ctap.rs b/boards/components/src/usb_ctap.rs
new file mode 100644
index 000000000..69e95c3c7
--- /dev/null
+++ b/boards/components/src/usb_ctap.rs
@@ -0,0 +1,88 @@
+//! Component for CTAP over USB.
+
+use capsules::usb::usb_ctap::CtapUsbSyscallDriver;
+use capsules::usb::usbc_ctap_hid::ClientCtapHID;
+use core::mem::MaybeUninit;
+use kernel::capabilities;
+use kernel::component::Component;
+use kernel::create_capability;
+use kernel::hil;
+use kernel::static_init_half;
+
+// Setup static space for the objects.
+#[macro_export]
+macro_rules! usb_ctap_component_buf {
+ ($C:ty) => {{
+ use capsules::usb::usb_ctap::CtapUsbSyscallDriver;
+ use capsules::usb::usbc_ctap_hid::ClientCtapHID;
+ use core::mem::MaybeUninit;
+ static mut BUF1: MaybeUninit<ClientCtapHID<'static, 'static, $C>> = MaybeUninit::uninit();
+ static mut BUF2: MaybeUninit<CtapUsbSyscallDriver<'static, 'static, $C>> =
+ MaybeUninit::uninit();
+ (&mut BUF1, &mut BUF2)
+ };};
+}
+
+pub struct UsbCtapComponent<C: 'static + hil::usb::UsbController<'static>> {
+ board_kernel: &'static kernel::Kernel,
+ controller: &'static C,
+ max_ctrl_packet_size: u8,
+ vendor_id: u16,
+ product_id: u16,
+ strings: &'static [&'static str],
+}
+
+impl<C: 'static + hil::usb::UsbController<'static>> UsbCtapComponent<C> {
+ pub fn new(
+ board_kernel: &'static kernel::Kernel,
+ controller: &'static C,
+ max_ctrl_packet_size: u8,
+ vendor_id: u16,
+ product_id: u16,
+ strings: &'static [&'static str],
+ ) -> Self {
+ Self {
+ board_kernel,
+ controller,
+ max_ctrl_packet_size,
+ vendor_id,
+ product_id,
+ strings,
+ }
+ }
+}
+
+impl<C: 'static + hil::usb::UsbController<'static>> Component for UsbCtapComponent<C> {
+ type StaticInput = (
+ &'static mut MaybeUninit<ClientCtapHID<'static, 'static, C>>,
+ &'static mut MaybeUninit<CtapUsbSyscallDriver<'static, 'static, C>>,
+ );
+ type Output = &'static CtapUsbSyscallDriver<'static, 'static, C>;
+
+ unsafe fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
+ let grant_cap = create_capability!(capabilities::MemoryAllocationCapability);
+
+ let usb_ctap = static_init_half!(
+ static_buffer.0,
+ ClientCtapHID<'static, 'static, C>,
+ ClientCtapHID::new(
+ self.controller,
+ self.max_ctrl_packet_size,
+ self.vendor_id,
+ self.product_id,
+ self.strings,
+ )
+ );
+ self.controller.set_client(usb_ctap);
+
+ // Configure the USB userspace driver
+ let usb_driver = static_init_half!(
+ static_buffer.1,
+ CtapUsbSyscallDriver<'static, 'static, C>,
+ CtapUsbSyscallDriver::new(usb_ctap, self.board_kernel.create_grant(&grant_cap))
+ );
+ usb_ctap.set_client(usb_driver);
+
+ usb_driver
+ }
+}
diff --git a/boards/nordic/nrf52840_dongle/src/main.rs b/boards/nordic/nrf52840_dongle/src/main.rs
index d72d204..8b97f8d 100644
index d72d20482..118ea6d68 100644
--- a/boards/nordic/nrf52840_dongle/src/main.rs
+++ b/boards/nordic/nrf52840_dongle/src/main.rs
@@ -15,6 +15,7 @@ use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferred
use kernel::component::Component;
#[allow(unused_imports)]
use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init};
+use kernel::hil::usb::UsbController;
use nrf52840::gpio::Pin;
use nrf52_components::{self, UartChannel, UartPins};
@@ -45,6 +46,17 @@ const PAN_ID: u16 = 0xABCD;
@@ -45,6 +45,17 @@ const PAN_ID: u16 = 0xABCD;
/// UART Writer
pub mod io;
@@ -28,7 +123,7 @@ index d72d204..8b97f8d 100644
// State for loading and holding applications.
// How should the kernel respond when a process faults.
const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic;
@@ -96,6 +108,11 @@ pub struct Platform {
@@ -96,6 +107,11 @@ pub struct Platform {
capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
>,
nvmc: &'static nrf52840::nvmc::SyscallDriver,
@@ -40,7 +135,7 @@ index d72d204..8b97f8d 100644
}
impl kernel::Platform for Platform {
@@ -115,6 +132,7 @@ impl kernel::Platform for Platform {
@@ -115,6 +131,7 @@ impl kernel::Platform for Platform {
capsules::temperature::DRIVER_NUM => f(Some(self.temp)),
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)),
@@ -48,57 +143,29 @@ index d72d204..8b97f8d 100644
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
_ => f(None),
}
@@ -323,6 +341,49 @@ pub unsafe fn reset_handler() {
@@ -323,6 +340,21 @@ pub unsafe fn reset_handler() {
)
);
+ // Enable power events to be sent to USB controller
+ nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD);
+ nrf52840::power::POWER.enable_interrupts();
+
+ // Configure USB controller
+ let usb:
+ &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver<
+ 'static,
+ 'static,
+ nrf52840::usbd::Usbd<'static>,
+ > = {
+ let usb_ctap = static_init!(
+ capsules::usb::usbc_ctap_hid::ClientCtapHID<
+ 'static,
+ 'static,
+ nrf52840::usbd::Usbd<'static>,
+ >,
+ capsules::usb::usbc_ctap_hid::ClientCtapHID::new(
+ &nrf52840::usbd::USBD,
+ capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840,
+ VENDOR_ID,
+ PRODUCT_ID,
+ STRINGS,
+ )
+ );
+ nrf52840::usbd::USBD.set_client(usb_ctap);
+
+ // Enable power events to be sent to USB controller
+ nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD);
+ nrf52840::power::POWER.enable_interrupts();
+
+ // Configure the USB userspace driver
+ let usb_driver = static_init!(
+ capsules::usb::usb_ctap::CtapUsbSyscallDriver<
+ 'static,
+ 'static,
+ nrf52840::usbd::Usbd<'static>,
+ >,
+ capsules::usb::usb_ctap::CtapUsbSyscallDriver::new(
+ usb_ctap,
+ board_kernel.create_grant(&memory_allocation_capability)
+ )
+ );
+ usb_ctap.set_client(usb_driver);
+ usb_driver as &'static _
+ };
+ let usb = components::usb_ctap::UsbCtapComponent::new(
+ board_kernel,
+ &nrf52840::usbd::USBD,
+ capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840,
+ VENDOR_ID,
+ PRODUCT_ID,
+ STRINGS,
+ )
+ .finalize(components::usb_ctap_component_buf!(nrf52840::usbd::Usbd));
+
nrf52_components::NrfClockComponent::new().finalize(());
let platform = Platform {
@@ -338,6 +399,7 @@ pub unsafe fn reset_handler() {
@@ -338,6 +370,7 @@ pub unsafe fn reset_handler() {
alarm,
analog_comparator,
nvmc,
@@ -107,18 +174,10 @@ index d72d204..8b97f8d 100644
};
diff --git a/boards/nordic/nrf52840dk/src/main.rs b/boards/nordic/nrf52840dk/src/main.rs
index 2ebb384..303a451 100644
index 2ebb384d8..4a7bfffdd 100644
--- a/boards/nordic/nrf52840dk/src/main.rs
+++ b/boards/nordic/nrf52840dk/src/main.rs
@@ -72,6 +72,7 @@ use kernel::common::dynamic_deferred_call::{DynamicDeferredCall, DynamicDeferred
use kernel::component::Component;
#[allow(unused_imports)]
use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init};
+use kernel::hil::usb::UsbController;
use nrf52840::gpio::Pin;
use nrf52_components::{self, UartChannel, UartPins};
@@ -113,6 +114,17 @@ pub mod io;
@@ -113,6 +113,17 @@ pub mod io;
// - Set to true to use Segger RTT over USB.
const USB_DEBUGGING: bool = false;
@@ -136,7 +195,7 @@ index 2ebb384..303a451 100644
// State for loading and holding applications.
// How should the kernel respond when a process faults.
const FAULT_RESPONSE: kernel::procs::FaultResponse = kernel::procs::FaultResponse::Panic;
@@ -164,6 +176,11 @@ pub struct Platform {
@@ -164,6 +175,11 @@ pub struct Platform {
>,
nonvolatile_storage: &'static capsules::nonvolatile_storage_driver::NonvolatileStorage<'static>,
nvmc: &'static nrf52840::nvmc::SyscallDriver,
@@ -148,7 +207,7 @@ index 2ebb384..303a451 100644
}
impl kernel::Platform for Platform {
@@ -184,6 +201,7 @@ impl kernel::Platform for Platform {
@@ -184,6 +200,7 @@ impl kernel::Platform for Platform {
capsules::analog_comparator::DRIVER_NUM => f(Some(self.analog_comparator)),
capsules::nonvolatile_storage_driver::DRIVER_NUM => f(Some(self.nonvolatile_storage)),
nrf52840::nvmc::DRIVER_NUM => f(Some(self.nvmc)),
@@ -156,57 +215,29 @@ index 2ebb384..303a451 100644
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
_ => f(None),
}
@@ -448,6 +466,49 @@ pub unsafe fn reset_handler() {
@@ -448,6 +465,21 @@ pub unsafe fn reset_handler() {
)
);
+ // Enable power events to be sent to USB controller
+ nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD);
+ nrf52840::power::POWER.enable_interrupts();
+
+ // Configure USB controller
+ let usb:
+ &'static capsules::usb::usb_ctap::CtapUsbSyscallDriver<
+ 'static,
+ 'static,
+ nrf52840::usbd::Usbd<'static>,
+ > = {
+ let usb_ctap = static_init!(
+ capsules::usb::usbc_ctap_hid::ClientCtapHID<
+ 'static,
+ 'static,
+ nrf52840::usbd::Usbd<'static>,
+ >,
+ capsules::usb::usbc_ctap_hid::ClientCtapHID::new(
+ &nrf52840::usbd::USBD,
+ capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840,
+ VENDOR_ID,
+ PRODUCT_ID,
+ STRINGS,
+ )
+ );
+ nrf52840::usbd::USBD.set_client(usb_ctap);
+
+ // Enable power events to be sent to USB controller
+ nrf52840::power::POWER.set_usb_client(&nrf52840::usbd::USBD);
+ nrf52840::power::POWER.enable_interrupts();
+
+ // Configure the USB userspace driver
+ let usb_driver = static_init!(
+ capsules::usb::usb_ctap::CtapUsbSyscallDriver<
+ 'static,
+ 'static,
+ nrf52840::usbd::Usbd<'static>,
+ >,
+ capsules::usb::usb_ctap::CtapUsbSyscallDriver::new(
+ usb_ctap,
+ board_kernel.create_grant(&memory_allocation_capability)
+ )
+ );
+ usb_ctap.set_client(usb_driver);
+ usb_driver as &'static _
+ };
+ let usb = components::usb_ctap::UsbCtapComponent::new(
+ board_kernel,
+ &nrf52840::usbd::USBD,
+ capsules::usb::usbc_client::MAX_CTRL_PACKET_SIZE_NRF52840,
+ VENDOR_ID,
+ PRODUCT_ID,
+ STRINGS,
+ )
+ .finalize(components::usb_ctap_component_buf!(nrf52840::usbd::Usbd));
+
nrf52_components::NrfClockComponent::new().finalize(());
let platform = Platform {
@@ -464,6 +525,7 @@ pub unsafe fn reset_handler() {
@@ -464,6 +496,7 @@ pub unsafe fn reset_handler() {
analog_comparator,
nonvolatile_storage,
nvmc,
@@ -215,7 +246,7 @@ index 2ebb384..303a451 100644
};
diff --git a/capsules/src/driver.rs b/capsules/src/driver.rs
index 256fc0e..ae458b3 100644
index 256fc0e9d..ae458b309 100644
--- a/capsules/src/driver.rs
+++ b/capsules/src/driver.rs
@@ -26,6 +26,7 @@ pub enum NUM {
@@ -227,7 +258,7 @@ index 256fc0e..ae458b3 100644
// Radio
BleAdvertising = 0x30000,
diff --git a/capsules/src/usb/mod.rs b/capsules/src/usb/mod.rs
index 767f5de..3f3a4f6 100644
index 767f5de83..3f3a4f646 100644
--- a/capsules/src/usb/mod.rs
+++ b/capsules/src/usb/mod.rs
@@ -1,5 +1,7 @@
@@ -240,7 +271,7 @@ index 767f5de..3f3a4f6 100644
+pub mod usbc_ctap_hid;
diff --git a/capsules/src/usb/usb_ctap.rs b/capsules/src/usb/usb_ctap.rs
new file mode 100644
index 0000000..da3d16d
index 000000000..da3d16d85
--- /dev/null
+++ b/capsules/src/usb/usb_ctap.rs
@@ -0,0 +1,355 @@
@@ -601,10 +632,10 @@ index 0000000..da3d16d
+}
diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs
new file mode 100644
index 0000000..d97b72d
index 000000000..642039120
--- /dev/null
+++ b/capsules/src/usb/usbc_ctap_hid.rs
@@ -0,0 +1,363 @@
@@ -0,0 +1,369 @@
+//! A USB HID client of the USB hardware interface
+
+use super::descriptors;
@@ -687,7 +718,7 @@ index 0000000..d97b72d
+ max_ctrl_packet_size: u8,
+ vendor_id: u16,
+ product_id: u16,
+ strings: &'static [&'static str]
+ strings: &'static [&'static str],
+ ) -> Self {
+ let interfaces: &mut [InterfaceDescriptor] = &mut [
+ // Interface declared in the FIDO2 specification, section 8.1.8.1
@@ -701,13 +732,19 @@ index 0000000..d97b72d
+
+ let endpoints: &[&[EndpointDescriptor]] = &[&[
+ EndpointDescriptor {
+ endpoint_address: EndpointAddress::new_const(ENDPOINT_NUM, TransferDirection::HostToDevice),
+ endpoint_address: EndpointAddress::new_const(
+ ENDPOINT_NUM,
+ TransferDirection::HostToDevice,
+ ),
+ transfer_type: TransferType::Interrupt,
+ max_packet_size: 64,
+ interval: 5,
+ },
+ EndpointDescriptor {
+ endpoint_address: EndpointAddress::new_const(ENDPOINT_NUM, TransferDirection::DeviceToHost),
+ endpoint_address: EndpointAddress::new_const(
+ ENDPOINT_NUM,
+ TransferDirection::DeviceToHost,
+ ),
+ transfer_type: TransferType::Interrupt,
+ max_packet_size: 64,
+ interval: 5,
@@ -717,8 +754,8 @@ index 0000000..d97b72d
+ let (device_descriptor_buffer, other_descriptor_buffer) =
+ descriptors::create_descriptor_buffers(
+ descriptors::DeviceDescriptor {
+ vendor_id: vendor_id,
+ product_id: product_id,
+ vendor_id,
+ product_id,
+ manufacturer_string: 1,
+ product_string: 2,
+ serial_number_string: 3,
@@ -969,7 +1006,7 @@ index 0000000..d97b72d
+ }
+}
diff --git a/chips/nrf52840/src/lib.rs b/chips/nrf52840/src/lib.rs
index 942d028..ce73e1f 100644
index 942d0288f..ce73e1f82 100644
--- a/chips/nrf52840/src/lib.rs
+++ b/chips/nrf52840/src/lib.rs
@@ -2,7 +2,7 @@

View File

@@ -1,9 +1,9 @@
c242b0237b93328eea0213411916f84e3ce631c3eea3bf56d6769ae5aa0b8d06 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
634e51405bad750c942773632c99a4d62860ef01dee1ba08e7899fdcded8e175 target/nrf52840dk_merged.hex
259a54fae11cb8f1306051354825d19223ba4c33f3adfdb2d3e9d9efc7229302 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
ba73e815c4ae55f49fb0e4275941903930893daebe70800bc39f24a34d0a8adb target/nrf52840_dongle_merged.hex
49d647374a1448c9c3107758b6e0a1cabdf008c3e53524a3b047a16c27b8af29 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
9d6b24b67dcd588c6572b491bae673e309bcbe8962497946232a554b5dc08ba5 target/nrf52840_dongle_dfu_merged.hex
dd5920dfb172d9371b29d019b6a37fae1a995bf9d814000944d9ef36bad31513 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
e1b147fefa75befe6f280e8aec41fa62b02e5c01bb1c940736b1903b597afe13 target/nrf52840dk_merged.hex
e4acfa602a5cc5d7c61d465f873918e8e0858628d0e5f8e0db26a7b7dd0b94d4 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
99b69a33320a4c5218b9e5084f2ad56957e04465dbbb53b0ab1051a176ba73a0 target/nrf52840_dongle_merged.hex
c0ace9f13ef3fd18c576a735ae23b3956bf8dd346f20c6217086e748d6bad8a2 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
3bde950d855ffa68eb334033388b292e98cdbf97993a57eca4524de101166f8b target/nrf52840_dongle_dfu_merged.hex
06a38a0d6d356145467a73c765e28a945878f663664016f888393207097bfe10 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
f3ed663311204ac709ed05dfb3d09ff283c3df7dbc5480ad3ec050523b0a2ed2 target/nrf52840_mdk_dfu_merged.hex
a2ee6798d20da62ed2c3ea7164620253d4b2319a3ed2f2dbc2973c1a5dd838a9 target/tab/ctap2.tab

View File

@@ -1,9 +1,9 @@
dab66677002854f6abfb1745d24d1c9e4e93c9bba286b14024e42cb8f2b99b9a third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
0bf90b63f0bbd8f8615735bb938dea256911bf68758bce3417f96a241e6462fe target/nrf52840dk_merged.hex
70cf9f6c1d6b2149c1ca88664073a92e092215faaf551310f8bfd8e171d3d3a1 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
1acdc5f11e88b48d0fdb3b61f935be0627217fc4b6c688f43c05cdb11385579e target/nrf52840_dongle_merged.hex
f550b6493c8cd401d191306510de50ddd6d4c709dcf90ea1bd3a9f1bcffd11b5 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
3b16c7d025c27530df5eb9c1c200e3d832c1531351e7601634c5dac6bd144935 target/nrf52840_dongle_dfu_merged.hex
2426ee9a6c75e325537818081d45445d95468a4c0a77feacdc6133d7d9aa227a third_party/tock/target/thumbv7em-none-eabi/release/nrf52840dk.bin
0038c7256f2bb8406364ca2deb8b228363e524a076263e23625fa2a3b4b35df6 target/nrf52840dk_merged.hex
c53d1e1db72df25950fa6d28699a2d38757def0dcbeb0d09d2366481cf0149a6 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle.bin
183365121eab69bb15746e7907bb0d66b9cc766d26a6a0dab301583c4bb8c4c3 target/nrf52840_dongle_merged.hex
233b5ba4459523759e3171cee83cdb3a383bbe65727c8ece64dfe5321d6ebe34 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_dongle_dfu.bin
95be6da19f67a9a85e83d97bdaaf5f062c82da00b9a767dd0bc49eaa2c74bb26 target/nrf52840_dongle_dfu_merged.hex
1baaf518a74c6077cb936d9cf178b6dd0232e7562fa56174886b05b77886cc32 third_party/tock/target/thumbv7em-none-eabi/release/nrf52840_mdk_dfu.bin
39c94b1dd8e65438d481835663c4ec2cda99311011031403c9244ed5095230c7 target/nrf52840_mdk_dfu_merged.hex
b02eb9439df1f8a3c21eb29f39c3b72c0f709b05a4e8a968441e73678cfb55df target/tab/ctap2.tab