From f42b37ca8e688c98727aa3daf4f9f4dd9675a104 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Tue, 22 Sep 2015 21:07:04 +0200 Subject: [PATCH] Fixed report out length --- src/PluggableHID/HID.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/PluggableHID/HID.cpp b/src/PluggableHID/HID.cpp index 97a9292..c9d3854 100644 --- a/src/PluggableHID/HID.cpp +++ b/src/PluggableHID/HID.cpp @@ -167,24 +167,28 @@ bool HID_::HID_Setup(USBSetup& setup, u8 i) if(current->reportID == ID) { // Get the data length information and the corresponding bytes - // Assuming the host will never send more than 255 bytes - uint8_t length = setup.wLength; - void* data = malloc(length); - if(data){ - uint8_t recvLength = length; - //TODO loop can be improved maybe? Or does the compiler do this already? - while(recvLength > USB_EP_SIZE){ - USB_RecvControl(data + (length - recvLength), USB_EP_SIZE); - recvLength -= USB_EP_SIZE; + uint16_t length = (setup.wValueH << 8) | setup.wLength; + + // Ensure that there IS some data TODO needed? + if(length) + { + void* data = malloc(length); + if(data){ + uint16_t recvLength = length; + //TODO loop can be improved maybe? Or does the compiler do this already? + while(recvLength > USB_EP_SIZE){ + USB_RecvControl(data + (length - recvLength), USB_EP_SIZE); + recvLength -= USB_EP_SIZE; + } + USB_RecvControl(data + (length - recvLength), recvLength); + + // Data may contain the report ID again (Keyboard), maybe not (RawHID) + current->setReportData(data, length); } - USB_RecvControl(data + (length - recvLength), recvLength); - - // Data may contain the report ID again (Keyboard), maybe not (RawHID) - current->setReportData(data, length); + + // Release data if the pointer still exists + free(data); } - - // Release data if the pointer still exists - free(data); // Dont search any further break;