Skip to content

Commit f2d7b52

Browse files
committed
[HID] Improved checks in getDescriptor() method
1 parent abd6b79 commit f2d7b52

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

cores/arduino/USBCore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@
4949
#define REQUEST_OTHER 0x03
5050
#define REQUEST_RECIPIENT 0x03
5151

52-
#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
53-
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
52+
#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE)
53+
#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE)
54+
#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_STANDARD + REQUEST_INTERFACE)
5455

5556
// Class requests
5657

libraries/HID/HID.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ int HID_::getInterface(uint8_t* interfaceCount)
4040

4141
int HID_::getDescriptor(USBSetup& setup)
4242
{
43-
if (pluggedInterface != setup.wIndex) {
44-
return 0;
45-
}
43+
// Check if this is a HID Class Descriptor request
44+
if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0; }
45+
if (setup.wValueH != HID_REPORT_DESCRIPTOR_TYPE) { return 0; }
46+
47+
// In a HID Class Descriptor wIndex cointains the interface number
48+
if (setup.wIndex != pluggedInterface) { return 0; }
4649

4750
int total = 0;
4851
HIDDescriptorListNode* node;

0 commit comments

Comments
 (0)