From 61651e89f3771aa2dfd683f198f593793e053b61 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Thu, 3 Nov 2022 14:32:59 -0500 Subject: [PATCH] stall ep0 instead of timing out When a request isn't supported, make sure to stall endpoint 0 instead of timing out. Discovered by experimenting with a KeyboardioHID change for rejecting Get/Set Protocol requests on non-boot keyboards. Signed-off-by: Taylor Yu --- cores/arduino/USBCore.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cores/arduino/USBCore.cpp b/cores/arduino/USBCore.cpp index c289f69a..948c01c3 100644 --- a/cores/arduino/USBCore.cpp +++ b/cores/arduino/USBCore.cpp @@ -761,9 +761,12 @@ void USBCore_::transcSetup(usb_dev* usbd, uint8_t ep) return; } else if ((usbd->control.req.bmRequestType & USB_RECPTYPE_MASK) == USB_RECPTYPE_ITF) { reqstat = (usb_reqsta)ClassCore::reqProcess(usbd, &usbd->control.req); - if (reqstat == REQ_SUPP - && (usbd->control.req.bmRequestType & USB_TRX_IN) != USB_TRX_IN) { - this->sendZLP(usbd, 0); + if (reqstat == REQ_SUPP) { + if ((usbd->control.req.bmRequestType & USB_TRX_IN) != USB_TRX_IN) { + this->sendZLP(usbd, 0); + } + } else { + usbd_ep_stall(usbd, 0); } return; } else { @@ -778,10 +781,15 @@ void USBCore_::transcSetup(usb_dev* usbd, uint8_t ep) // Respond with a ZLP if the host has sent data, // because we’ve already handled in in the class request. - if (reqstat == REQ_SUPP - && ((usbd->control.req.bmRequestType & USB_TRX_IN) != USB_TRX_IN)) { - this->sendZLP(usbd, 0); + if (reqstat == REQ_SUPP) { + if ((usbd->control.req.bmRequestType & USB_TRX_IN) != USB_TRX_IN) { + this->sendZLP(usbd, 0); + } + } else { + usbd_ep_stall(usbd, 0); } + // Return early, because the usbd_ep_send() call below is for + // processing transmissions from the original low-level code. return; /* vendor defined request */