diff --git a/core/embed/trezorhal/stm32f4/usb.c b/core/embed/trezorhal/stm32f4/usb.c index 8efc0f5fef..9249c4b9e8 100644 --- a/core/embed/trezorhal/stm32f4/usb.c +++ b/core/embed/trezorhal/stm32f4/usb.c @@ -487,12 +487,10 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, } switch (usb_ifaces[req->wIndex].type) { case USB_IFACE_TYPE_HID: - wait_random(); return usb_hid_class_setup(dev, &usb_ifaces[req->wIndex].hid, req); case USB_IFACE_TYPE_VCP: return usb_vcp_class_setup(dev, &usb_ifaces[req->wIndex].vcp, req); case USB_IFACE_TYPE_WEBUSB: - wait_random(); return usb_webusb_class_setup(dev, &usb_ifaces[req->wIndex].webusb, req); default: @@ -511,14 +509,12 @@ static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) { for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { switch (usb_ifaces[i].type) { case USB_IFACE_TYPE_HID: - wait_random(); usb_hid_class_data_in(dev, &usb_ifaces[i].hid, ep_num); break; case USB_IFACE_TYPE_VCP: usb_vcp_class_data_in(dev, &usb_ifaces[i].vcp, ep_num); break; case USB_IFACE_TYPE_WEBUSB: - wait_random(); usb_webusb_class_data_in(dev, &usb_ifaces[i].webusb, ep_num); break; default: @@ -535,14 +531,12 @@ static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) { for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) { switch (usb_ifaces[i].type) { case USB_IFACE_TYPE_HID: - wait_random(); usb_hid_class_data_out(dev, &usb_ifaces[i].hid, ep_num); break; case USB_IFACE_TYPE_VCP: usb_vcp_class_data_out(dev, &usb_ifaces[i].vcp, ep_num); break; case USB_IFACE_TYPE_WEBUSB: - wait_random(); usb_webusb_class_data_out(dev, &usb_ifaces[i].webusb, ep_num); break; default: diff --git a/core/embed/trezorhal/stm32f4/usb_hid-impl.h b/core/embed/trezorhal/stm32f4/usb_hid-impl.h index d08be2a78d..349822287f 100644 --- a/core/embed/trezorhal/stm32f4/usb_hid-impl.h +++ b/core/embed/trezorhal/stm32f4/usb_hid-impl.h @@ -267,6 +267,8 @@ static void usb_hid_class_deinit(USBD_HandleTypeDef *dev, static int usb_hid_class_setup(USBD_HandleTypeDef *dev, usb_hid_state_t *state, USBD_SetupReqTypedef *req) { + wait_random(); + switch (req->bmRequest & USB_REQ_TYPE_MASK) { // Class request case USB_REQ_TYPE_CLASS: @@ -340,6 +342,7 @@ static int usb_hid_class_setup(USBD_HandleTypeDef *dev, usb_hid_state_t *state, static void usb_hid_class_data_in(USBD_HandleTypeDef *dev, usb_hid_state_t *state, uint8_t ep_num) { if ((ep_num | USB_EP_DIR_IN) == state->ep_in) { + wait_random(); state->ep_in_is_idle = 1; } } @@ -347,6 +350,7 @@ static void usb_hid_class_data_in(USBD_HandleTypeDef *dev, static void usb_hid_class_data_out(USBD_HandleTypeDef *dev, usb_hid_state_t *state, uint8_t ep_num) { if (ep_num == state->ep_out) { + wait_random(); // Save the report length to indicate we have read something, but don't // schedule next reading until user reads this one state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num); diff --git a/core/embed/trezorhal/stm32f4/usb_webusb-impl.h b/core/embed/trezorhal/stm32f4/usb_webusb-impl.h index cfc08d4fa2..3ffe4589e8 100644 --- a/core/embed/trezorhal/stm32f4/usb_webusb-impl.h +++ b/core/embed/trezorhal/stm32f4/usb_webusb-impl.h @@ -243,6 +243,8 @@ static int usb_webusb_class_setup(USBD_HandleTypeDef *dev, return USBD_OK; } + wait_random(); + switch (req->bRequest) { case USB_REQ_SET_INTERFACE: state->alt_setting = req->wValue; @@ -263,6 +265,7 @@ static void usb_webusb_class_data_in(USBD_HandleTypeDef *dev, usb_webusb_state_t *state, uint8_t ep_num) { if ((ep_num | USB_EP_DIR_IN) == state->ep_in) { + wait_random(); state->ep_in_is_idle = 1; } } @@ -271,6 +274,7 @@ static void usb_webusb_class_data_out(USBD_HandleTypeDef *dev, usb_webusb_state_t *state, uint8_t ep_num) { if (ep_num == state->ep_out) { + wait_random(); // Save the report length to indicate we have read something, but don't // schedule next reading until user reads this one state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num);