Fixed memory corruption HID report parser when too many COLLECTION or PUSH items were processed.
Make RNDIS device class driver include the CDC device class driver header, so that it can inherrit the required CDC functional descriptor macro.
Make HID host class driver include the HID report parser.
#define _DESCRIPTORS_H_\r
\r
/* Includes: */\r
#define _DESCRIPTORS_H_\r
\r
/* Includes: */\r
- #include <avr/pgmspace.h>\r
-\r
#include <LUFA/Drivers/USB/USB.h>\r
#include <LUFA/Drivers/USB/Class/HID.h>\r
\r
#include <LUFA/Drivers/USB/USB.h>\r
#include <LUFA/Drivers/USB/Class/HID.h>\r
\r
+ #include <avr/pgmspace.h>\r
+\r
/* Type Defines: */\r
/** Type define for the device configuration descriptor structure. This must be defined in the\r
* application code, as the configuration descriptor contains several sub-descriptors which\r
/* Type Defines: */\r
/** Type define for the device configuration descriptor structure. This must be defined in the\r
* application code, as the configuration descriptor contains several sub-descriptors which\r
\r
/* Includes: */\r
#include <LUFA/Drivers/USB/USB.h>\r
\r
/* Includes: */\r
#include <LUFA/Drivers/USB/USB.h>\r
+ #include <LUFA/Drivers/USB/Class/RNDIS.h>\r
+ \r
#include <avr/pgmspace.h>\r
\r
/* Macros: */\r
#include <avr/pgmspace.h>\r
\r
/* Macros: */\r
- /** Macro to define a CDC class-specific functional descriptor. CDC functional descriptors have a\r
- * uniform structure but variable sized data payloads, thus cannot be represented accurately by\r
- * a single typedef struct. A macro is used instead so that functional descriptors can be created\r
- * easily by specifying the size of the payload. This allows sizeof() to work correctly.\r
- *\r
- * \param[in] DataSize Size in bytes of the CDC functional descriptor's data payload\r
- */ \r
- #define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \\r
- struct \\r
- { \\r
- USB_Descriptor_Header_t Header; \\r
- uint8_t SubType; \\r
- uint8_t Data[DataSize]; \\r
- }\r
-\r
/** Endpoint number of the CDC device-to-host notification IN endpoint. */\r
#define CDC_NOTIFICATION_EPNUM 3\r
\r
/** Endpoint number of the CDC device-to-host notification IN endpoint. */\r
#define CDC_NOTIFICATION_EPNUM 3\r
\r
#include <LUFA/Drivers/Misc/TerminalCodes.h>\r
#include <LUFA/Drivers/Peripheral/SerialStream.h>\r
#include <LUFA/Drivers/Board/LEDs.h>\r
#include <LUFA/Drivers/Misc/TerminalCodes.h>\r
#include <LUFA/Drivers/Peripheral/SerialStream.h>\r
#include <LUFA/Drivers/Board/LEDs.h>\r
- #include <LUFA/Drivers/USB/USB.h>\r
- #include <LUFA/Drivers/USB/Class/Host/CDC.h>\r
+ #include <LUFA/Drivers/USB/USB.h>\\r
\r
/* Macros: */\r
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
\r
/* Macros: */\r
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */\r
USB_HostState = HOST_STATE_Configured;\r
break;\r
case HOST_STATE_Configured:\r
USB_HostState = HOST_STATE_Configured;\r
break;\r
case HOST_STATE_Configured:\r
- if (HID_Host_ReportReceived(&Mouse_HID_Interface))\r
+ if (HID_Host_IsReportReceived(&Mouse_HID_Interface))\r
-# make -C ClassDriver/ $@ <TODO: Re-enable after Host class drivers complete>
+ make -C ClassDriver/ $@
\r
/* Includes: */\r
#include "../../USB.h"\r
\r
/* Includes: */\r
#include "../../USB.h"\r
\r
#include <string.h>\r
\r
\r
#include <string.h>\r
\r
-void HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)\r
+bool HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)\r
+ bool ReportReceived;\r
+\r
+ if ((USB_HostState != HOST_STATE_Configured) || !(HIDInterfaceInfo->State.Active))\r
+ return false;\r
+\r
Pipe_SelectPipe(HIDInterfaceInfo->Config.DataINPipeNumber);\r
Pipe_SelectPipe(HIDInterfaceInfo->Config.DataINPipeNumber);\r
+ Pipe_Unfreeze();\r
+ \r
+ ReportReceived = Pipe_IsReadWriteAllowed();\r
+ \r
+ Pipe_Freeze();\r
- return Pipe_IsReadWriteAllowed();\r
+ return ReportReceived;\r
/* Includes: */\r
#include "../../USB.h"\r
#include "../Common/HID.h"\r
/* Includes: */\r
#include "../../USB.h"\r
#include "../Common/HID.h"\r
+ #include "HIDParser.h"\r
\r
/* Enable C linkage for C++ Compilers: */\r
#if defined(__cplusplus)\r
\r
/* Enable C linkage for C++ Compilers: */\r
#if defined(__cplusplus)\r
HID_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor */\r
HID_ENUMERROR_NoHIDInterfaceFound = 2, /**< A compatible HID interface was not found in the device's Configuration Descriptor */\r
HID_ENUMERROR_EndpointsNotFound = 3, /**< Compatible HID endpoints were not found in the device's CDC interface */\r
HID_ENUMERROR_InvalidConfigDescriptor = 1, /**< The device returned an invalid Configuration Descriptor */\r
HID_ENUMERROR_NoHIDInterfaceFound = 2, /**< A compatible HID interface was not found in the device's Configuration Descriptor */\r
HID_ENUMERROR_EndpointsNotFound = 3, /**< Compatible HID endpoints were not found in the device's CDC interface */\r
- } CDCHost_EnumerationFailure_ErrorCodes_t;\r
+ } HIDHost_EnumerationFailure_ErrorCodes_t;\r
\r
/* Function Prototypes: */\r
void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo);\r
uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint16_t ConfigDescriptorLength,\r
uint8_t* DeviceConfigDescriptor);\r
\r
\r
/* Function Prototypes: */\r
void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo);\r
uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint16_t ConfigDescriptorLength,\r
uint8_t* DeviceConfigDescriptor);\r
\r
- void HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo);\r
+ bool HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo);\r
\r
/* Private Interface - For use in library only: */\r
#if !defined(__DOXYGEN__)\r
\r
/* Private Interface - For use in library only: */\r
#if !defined(__DOXYGEN__)\r
uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData)\r
{\r
HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];\r
uint8_t USB_ProcessHIDReport(const uint8_t* ReportData, uint16_t ReportSize, HID_ReportInfo_t* const ParserData)\r
{\r
HID_StateTable_t StateTable[HID_STATETABLE_STACK_DEPTH];\r
- HID_StateTable_t* CurrStateTable = &StateTable[0];\r
+ HID_StateTable_t* CurrStateTable = &StateTable[0];\r
uint16_t UsageStack[HID_USAGE_STACK_DEPTH];\r
uint16_t UsageStack[HID_USAGE_STACK_DEPTH];\r
- uint8_t UsageStackSize = 0;\r
- uint16_t BitOffsetIn = 0;\r
- uint16_t BitOffsetOut = 0;\r
+ uint8_t UsageStackSize = 0;\r
+ uint16_t BitOffsetIn = 0;\r
+ uint16_t BitOffsetOut = 0;\r
#if defined(HID_ENABLE_FEATURE_PROCESSING)\r
#if defined(HID_ENABLE_FEATURE_PROCESSING)\r
- uint16_t BitOffsetFeature = 0;\r
+ uint16_t BitOffsetFeature = 0;\r
- HID_CollectionPath_t* CurrCollectionPath = NULL;\r
+ HID_CollectionPath_t* CurrCollectionPath = NULL;\r
- memset((void*)ParserData, 0x00, sizeof(HID_ReportInfo_t));\r
- memset((void*)StateTable, 0x00, sizeof(StateTable));\r
+ memset(ParserData, 0x00, sizeof(HID_ReportInfo_t));\r
+ memset(StateTable, 0x00, sizeof(StateTable));\r
\r
while (ReportSize)\r
{\r
\r
while (ReportSize)\r
{\r
+ uint8_t HIDReportItem = *(ReportData++);\r
uint32_t ReportItemData = 0;\r
\r
uint32_t ReportItemData = 0;\r
\r
- switch (*ReportData & DATA_SIZE_MASK)\r
+ ReportSize--;\r
+ \r
+ switch (HIDReportItem & DATA_SIZE_MASK)\r
- ReportItemData = *((uint32_t*)(ReportData + 1));\r
+ ReportItemData = *((uint32_t*)ReportData);\r
+ ReportSize -= 4;\r
+ ReportData += 4;\r
break;\r
case DATA_SIZE_2:\r
break;\r
case DATA_SIZE_2:\r
- ReportItemData = *((uint16_t*)(ReportData + 1));\r
+ ReportItemData = *((uint16_t*)ReportData);\r
+ ReportSize -= 2;\r
+ ReportData += 2;\r
break;\r
case DATA_SIZE_1:\r
break;\r
case DATA_SIZE_1:\r
- ReportItemData = *((uint8_t*)(ReportData + 1));\r
+ ReportItemData = *((uint8_t*)ReportData);\r
+ ReportSize -= 1;\r
+ ReportData += 1;\r
- switch (*ReportData & (TYPE_MASK | TAG_MASK))\r
+ switch (HIDReportItem & (TYPE_MASK | TAG_MASK))\r
{\r
case (TYPE_GLOBAL | TAG_GLOBAL_PUSH):\r
{\r
case (TYPE_GLOBAL | TAG_GLOBAL_PUSH):\r
- if (CurrStateTable == &StateTable[HID_STATETABLE_STACK_DEPTH])\r
+ if (CurrStateTable == &StateTable[HID_STATETABLE_STACK_DEPTH - 1])\r
return HID_PARSE_HIDStackOverflow;\r
\r
return HID_PARSE_HIDStackOverflow;\r
\r
- memcpy((CurrStateTable - 1),\r
- CurrStateTable,\r
+ memcpy(CurrStateTable,\r
+ (CurrStateTable + 1),\r
sizeof(HID_ReportItem_t));\r
\r
CurrStateTable++;\r
sizeof(HID_ReportItem_t));\r
\r
CurrStateTable++;\r
break;\r
case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID):\r
CurrStateTable->ReportID = ReportItemData;\r
break;\r
case (TYPE_GLOBAL | TAG_GLOBAL_REPORTID):\r
CurrStateTable->ReportID = ReportItemData;\r
BitOffsetOut = 0;\r
break;\r
case (TYPE_LOCAL | TAG_LOCAL_USAGE):\r
BitOffsetOut = 0;\r
break;\r
case (TYPE_LOCAL | TAG_LOCAL_USAGE):\r
\r
while (CurrCollectionPath->Parent != NULL);\r
{\r
\r
while (CurrCollectionPath->Parent != NULL);\r
{\r
- if (CurrCollectionPath == &ParserData->CollectionPaths[HID_MAX_COLLECTIONS])\r
+ if (CurrCollectionPath == &ParserData->CollectionPaths[HID_MAX_COLLECTIONS - 1])\r
return HID_PARSE_InsufficientCollectionPaths;\r
\r
CurrCollectionPath++;\r
return HID_PARSE_InsufficientCollectionPaths;\r
\r
CurrCollectionPath++;\r
CurrReportItem->Attributes.Usage.Usage = 0;\r
}\r
\r
CurrReportItem->Attributes.Usage.Usage = 0;\r
}\r
\r
- switch (*ReportData & TAG_MASK)\r
+ switch (HIDReportItem & TAG_MASK)\r
{\r
case TAG_MAIN_INPUT:\r
CurrReportItem->ItemType = REPORT_ITEM_TYPE_In;\r
{\r
case TAG_MAIN_INPUT:\r
CurrReportItem->ItemType = REPORT_ITEM_TYPE_In;\r
-#if !defined(HID_INCLUDE_CONSTANT_DATA_ITEMS)\r
+#if defined(HID_INCLUDE_CONSTANT_DATA_ITEMS)\r
+ ParserData->TotalReportItems++;\r
+#else\r
if (!(ReportItemData & IOF_CONSTANT))\r
ParserData->TotalReportItems++;\r
if (!(ReportItemData & IOF_CONSTANT))\r
ParserData->TotalReportItems++;\r
-#else\r
- ParserData->TotalReportItems++;\r
- if ((*ReportData & TYPE_MASK) == TYPE_MAIN)\r
+ if ((HIDReportItem & TYPE_MASK) == TYPE_MAIN)\r
{\r
CurrStateTable->Attributes.Usage.MinMax.Minimum = 0;\r
CurrStateTable->Attributes.Usage.MinMax.Maximum = 0;\r
UsageStackSize = 0;\r
}\r
{\r
CurrStateTable->Attributes.Usage.MinMax.Minimum = 0;\r
CurrStateTable->Attributes.Usage.MinMax.Maximum = 0;\r
UsageStackSize = 0;\r
}\r
- \r
- switch (*ReportData & DATA_SIZE_MASK)\r
- {\r
- case DATA_SIZE_4:\r
- ReportSize -= 5;\r
- ReportData += 5;\r
- break;\r
- case DATA_SIZE_2:\r
- ReportSize -= 3;\r
- ReportData += 3;\r
- break;\r
- case DATA_SIZE_1:\r
- ReportSize -= 2;\r
- ReportData += 2;\r
- break;\r
- case DATA_SIZE_0:\r
- ReportSize -= 1;\r
- ReportData += 1;\r
- break;\r
- }\r
}\r
\r
return HID_PARSE_Successful;\r
}\r
\r
return HID_PARSE_Successful;\r
* <b>Fixed:</b>\r
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the\r
* endpoint's bank\r
* <b>Fixed:</b>\r
* - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the\r
* endpoint's bank\r
+ * - Fixed swapped paremeters in the HID state memory copy call while processing a HID PUSH item in the HID report parser\r
+ * - Fixed memory corruption HID report parser when too many COLLECTION or PUSH items were processed\r
*\r
*\r
* \section Sec_ChangeLog090810 Version 090810\r
*\r
*\r
* \section Sec_ChangeLog090810 Version 090810\r
*\r
* - Bicycle POV: http://www.code.google.com/p/bicycleledpov/\r
* - CAMTRIG, a remote Camera Trigger device: http://code.astraw.com/projects/motmot/camtrig\r
*\r
* - Bicycle POV: http://www.code.google.com/p/bicycleledpov/\r
* - CAMTRIG, a remote Camera Trigger device: http://code.astraw.com/projects/motmot/camtrig\r
+ * - "Fingerlicking Wingdinger" (WARNING: Bad Language if no Javascript), a MIDI controller - http://noisybox.net/electronics/wingdinger/\r
* - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/\r
* - Openkubus, an open source hardware-based authentication dongle: http://code.google.com/p/openkubus/\r
* - Orbee, a USB connected RGB Orb for notifications: http://www.franksworkshop.com.au/Electronics/Orbee/Orbee.htm\r
* - Opendous-JTAG, an open source JTAG device: http://code.google.com/p/opendous-jtag/\r
* - Openkubus, an open source hardware-based authentication dongle: http://code.google.com/p/openkubus/\r
* - Orbee, a USB connected RGB Orb for notifications: http://www.franksworkshop.com.au/Electronics/Orbee/Orbee.htm\r