From ccbbf657743eb656f4e49b0204092b4450ffa7ba Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 18 Feb 2019 12:07:26 +0000 Subject: Add HidDevice trait for device-specific information MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The HID USB class needs device-specific information – currently, the subclass and the protocol of the device, but also the report descriptors and request handlers once we support these functions. Therefore, this patch introduces the HidDevice trait that provides this data. It also adds a Nitrokey struct that implements this trait for the Nitrokey Pro device. --- src/device.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/device.rs') diff --git a/src/device.rs b/src/device.rs index ea732e6..31f4293 100644 --- a/src/device.rs +++ b/src/device.rs @@ -4,9 +4,29 @@ use usb_device::bus::{UsbBus, UsbBusAllocator}; use usb_device::device::{UsbDevice, UsbDeviceBuilder, UsbVidPid}; +use crate::hid::{HidDevice, Protocol, Subclass}; + const VID_CLAY_LOGIC: u16 = 0x20a0; const PID_NITROKEY_PRO: u16 = 0x4108; +pub struct Nitrokey {} + +impl Nitrokey { + pub fn new() -> Self { + Nitrokey {} + } +} + +impl HidDevice for Nitrokey { + fn subclass(&self) -> Subclass { + Subclass::BootInterface + } + + fn protocol(&self) -> Protocol { + Protocol::Keyboard + } +} + pub fn create_usb_device(alloc: &UsbBusAllocator) -> UsbDevice<'_, B> { UsbDeviceBuilder::new(alloc, UsbVidPid(VID_CLAY_LOGIC, PID_NITROKEY_PRO)) .manufacturer("Nitrokey/ntw") -- cgit v1.2.1