From 1e127de5173e3b8fb62efc79f97651ca22694441 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Tue, 19 Feb 2019 22:09:04 +0000 Subject: Validate CRC of incoming data The data sent with Set_Report requests contains a CRC which we so far ignored. This patch adds a Crc struct that uses the CRC peripheral to calculate the CRC for some data and uses it to validate the CRC of the received data. --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index caf7fdf..7e364ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ extern crate panic_halt; mod util; mod commands; +mod crc; mod device; mod hid; @@ -18,6 +19,7 @@ use hal::prelude::*; use stm32f103xx_usb::UsbBus; use usb_device::class::UsbClass; +use crate::crc::Crc; use crate::device::Nitrokey; use crate::hid::HidClass; @@ -25,6 +27,9 @@ use crate::hid::HidClass; fn main() -> ! { let p = hal::stm32::Peripherals::take().unwrap(); + p.RCC.ahbenr.modify(|_, w| w.crcen().set_bit()); + let crc = Crc::new(p.CRC); + let mut flash = p.FLASH.constrain(); let mut rcc = p.RCC.constrain(); @@ -40,7 +45,7 @@ fn main() -> ! { let mut gpioa = p.GPIOA.split(&mut rcc.apb2); let usb_bus = UsbBus::usb_with_reset(p.USB, &mut rcc.apb1, &clocks, &mut gpioa.crh, gpioa.pa12); - let mut usb_class = HidClass::new(Nitrokey::new(), &usb_bus); + let mut usb_class = HidClass::new(Nitrokey::new(crc), &usb_bus); let mut usb_dev = device::create_usb_device(&usb_bus); usb_dev.force_reset().expect("USB reset failed"); -- cgit v1.2.1