Fix buffer size and check maxPacketSize #646

This commit is contained in:
Jun Wako 2021-06-26 20:44:23 +09:00
parent b6511306f1
commit d3e306f5f9

View file

@ -582,14 +582,18 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
// To-do: optimize manually, using the for loop only if needed.
for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) {
const uint16_t const_buff_len = 16;
uint8_t buf[const_buff_len];
const uint16_t const_buff_len = 64;
USBTRACE3("(hidboot.h) i=", i, 0x81);
USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].epAddr=", epInfo[epInterruptInIndex + i].epAddr, 0x81);
USBTRACE3("(hidboot.h) epInfo[epInterruptInIndex + i].maxPktSize=", epInfo[epInterruptInIndex + i].maxPktSize, 0x81);
uint16_t read = (uint16_t)epInfo[epInterruptInIndex + i].maxPktSize;
if (read > const_buff_len)
read = const_buff_len;
uint8_t buf[read];
rcode = pUsb->inTransfer(bAddress, epInfo[epInterruptInIndex + i].epAddr, &read, buf);
// SOME buggy dongles report extra keys (like sleep) using a 2 byte packet on the wrong endpoint.
// Since keyboard and mice must report at least 3 bytes, we ignore the extra data.