Skip to content

Commit

Permalink
Fix USB enumeration on OS X (#640)
Browse files Browse the repository at this point in the history
Hopefully without breaking the others.

Summary of the changes:
- Device descriptor reports the device is bus powered and requires
  100mA max.
- HID descriptor version bumped to 1.11 (was 1.10)
- Added string index for Interface and HID descriptors (which seems to
  make OS X happy)
  • Loading branch information
jmichelp authored Jul 26, 2023
1 parent 8868752 commit e3d2e7d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
4 changes: 4 additions & 0 deletions boards/nordic/nrf52840_dongle_opensk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ static STRINGS: &'static [&'static str] = &[
"OpenSK",
// Serial number
"v1.0",
// Interface description + main HID string
"FIDO2",
// vendor HID string
"Vendor HID",
];

// State for loading and holding applications.
Expand Down
4 changes: 4 additions & 0 deletions boards/nordic/nrf52840_mdk_dfu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ static STRINGS: &'static [&'static str] = &[
"OpenSK",
// Serial number
"v1.0",
// Interface description + main HID string
"FIDO2",
// vendor HID string
"Vendor HID",
];

// State for loading and holding applications.
Expand Down
4 changes: 4 additions & 0 deletions boards/nordic/nrf52840dk_opensk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ static STRINGS: &'static [&'static str] = &[
"OpenSK",
// Serial number
"v1.0",
// Interface description + main HID string
"FIDO2",
// vendor HID string
"Vendor HID",
];

// State for loading and holding applications.
Expand Down
27 changes: 22 additions & 5 deletions patches/tock/03-add-ctap-modules.patch
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ index 000000000..f2e248bc9
+ self.side == Some(side)
+ }
+}
diff --git a/capsules/src/usb/descriptors.rs b/capsules/src/usb/descriptors.rs
index 67f708239..9c5bc9cd1 100644
--- a/capsules/src/usb/descriptors.rs
+++ b/capsules/src/usb/descriptors.rs
@@ -568,8 +568,8 @@ impl Default for ConfigurationDescriptor {
num_interfaces: 1,
configuration_value: 1,
string_index: 0,
- attributes: ConfigurationAttributes::new(true, false),
- max_power: 0, // in 2mA units
+ attributes: ConfigurationAttributes::new(false, false),
+ max_power: 50, // in 2mA units
related_descriptor_length: 0,
}
}
diff --git a/capsules/src/usb/mod.rs b/capsules/src/usb/mod.rs
index 767f5de83..cb5e0af97 100644
--- a/capsules/src/usb/mod.rs
Expand Down Expand Up @@ -544,10 +559,10 @@ index 000000000..30cac1323
+}
diff --git a/capsules/src/usb/usbc_ctap_hid.rs b/capsules/src/usb/usbc_ctap_hid.rs
new file mode 100644
index 000000000..e074eb7a6
index 000000000..5ad2c44b3
--- /dev/null
+++ b/capsules/src/usb/usbc_ctap_hid.rs
@@ -0,0 +1,552 @@
@@ -0,0 +1,554 @@
+//! A USB HID client of the USB hardware interface
+
+use super::app::App;
Expand Down Expand Up @@ -652,14 +667,14 @@ index 000000000..e074eb7a6
+ }];
+
+static HID: HIDDescriptor<'static> = HIDDescriptor {
+ hid_class: 0x0110,
+ hid_class: 0x0111,
+ country_code: HIDCountryCode::NotSupported,
+ sub_descriptors: HID_SUB_DESCRIPTORS,
+};
+
+#[cfg(feature = "vendor_hid")]
+static VENDOR_HID: HIDDescriptor<'static> = HIDDescriptor {
+ hid_class: 0x0110,
+ hid_class: 0x0111,
+ country_code: HIDCountryCode::NotSupported,
+ sub_descriptors: VENDOR_HID_SUB_DESCRIPTORS,
+};
Expand Down Expand Up @@ -719,6 +734,7 @@ index 000000000..e074eb7a6
+ interface_class: 0x03, // HID
+ interface_subclass: 0x00, // no subcall
+ interface_protocol: 0x00, // no protocol
+ string_index: 4,
+ ..InterfaceDescriptor::default()
+ },
+ // Vendor HID interface.
Expand All @@ -728,6 +744,7 @@ index 000000000..e074eb7a6
+ interface_class: 0x03, // HID
+ interface_subclass: 0x00,
+ interface_protocol: 0x00,
+ string_index: 5,
+ ..InterfaceDescriptor::default()
+ },
+ ];
Expand Down Expand Up @@ -786,7 +803,7 @@ index 000000000..e074eb7a6
+ manufacturer_string: 1,
+ product_string: 2,
+ serial_number_string: 3,
+ class: 0x03, // HID class for all interfaces
+ class: 0x00, // Class is specified at the interface level
+ max_packet_size_ep0: max_ctrl_packet_size,
+ ..descriptors::DeviceDescriptor::default()
+ },
Expand Down
2 changes: 1 addition & 1 deletion patches/tock/04-vendor-hid.patch
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ index 65301bcf1..dc70e98b1 100644
+[features]
+vendor_hid = []
diff --git a/capsules/src/usb/descriptors.rs b/capsules/src/usb/descriptors.rs
index 67f708239..c2556d3a2 100644
index 9c5bc9cd1..c3ed71c44 100644
--- a/capsules/src/usb/descriptors.rs
+++ b/capsules/src/usb/descriptors.rs
@@ -415,13 +415,14 @@ impl DescriptorBuffer {
Expand Down
4 changes: 2 additions & 2 deletions patches/tock/06-persistent-storage.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chips/nrf52/src/nvmc.rs b/chips/nrf52/src/nvmc.rs
index 61e94260e..b7c3be3f6 100644
index 61e94260e..e115e1851 100644
--- a/chips/nrf52/src/nvmc.rs
+++ b/chips/nrf52/src/nvmc.rs
@@ -5,7 +5,14 @@
Expand Down Expand Up @@ -393,7 +393,7 @@ index 028f30220..8880bc000 100644
pub use crate::process::ProcessId;
pub use crate::scheduler::Scheduler;
diff --git a/kernel/src/memop.rs b/kernel/src/memop.rs
index 51d89f37c..45ab3856b 100644
index 51d89f37c..c4f7cef92 100644
--- a/kernel/src/memop.rs
+++ b/kernel/src/memop.rs
@@ -107,6 +107,37 @@ pub(crate) fn memop(process: &dyn Process, op_type: usize, r1: usize) -> Syscall
Expand Down

0 comments on commit e3d2e7d

Please sign in to comment.