mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-21 13:58:08 +00:00
fix(core/embed): fix random delays in usb driver
[no changelog]
This commit is contained in:
parent
799a78525f
commit
f5d35da635
@ -487,12 +487,10 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
|
|||||||
}
|
}
|
||||||
switch (usb_ifaces[req->wIndex].type) {
|
switch (usb_ifaces[req->wIndex].type) {
|
||||||
case USB_IFACE_TYPE_HID:
|
case USB_IFACE_TYPE_HID:
|
||||||
wait_random();
|
|
||||||
return usb_hid_class_setup(dev, &usb_ifaces[req->wIndex].hid, req);
|
return usb_hid_class_setup(dev, &usb_ifaces[req->wIndex].hid, req);
|
||||||
case USB_IFACE_TYPE_VCP:
|
case USB_IFACE_TYPE_VCP:
|
||||||
return usb_vcp_class_setup(dev, &usb_ifaces[req->wIndex].vcp, req);
|
return usb_vcp_class_setup(dev, &usb_ifaces[req->wIndex].vcp, req);
|
||||||
case USB_IFACE_TYPE_WEBUSB:
|
case USB_IFACE_TYPE_WEBUSB:
|
||||||
wait_random();
|
|
||||||
return usb_webusb_class_setup(dev, &usb_ifaces[req->wIndex].webusb,
|
return usb_webusb_class_setup(dev, &usb_ifaces[req->wIndex].webusb,
|
||||||
req);
|
req);
|
||||||
default:
|
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++) {
|
for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) {
|
||||||
switch (usb_ifaces[i].type) {
|
switch (usb_ifaces[i].type) {
|
||||||
case USB_IFACE_TYPE_HID:
|
case USB_IFACE_TYPE_HID:
|
||||||
wait_random();
|
|
||||||
usb_hid_class_data_in(dev, &usb_ifaces[i].hid, ep_num);
|
usb_hid_class_data_in(dev, &usb_ifaces[i].hid, ep_num);
|
||||||
break;
|
break;
|
||||||
case USB_IFACE_TYPE_VCP:
|
case USB_IFACE_TYPE_VCP:
|
||||||
usb_vcp_class_data_in(dev, &usb_ifaces[i].vcp, ep_num);
|
usb_vcp_class_data_in(dev, &usb_ifaces[i].vcp, ep_num);
|
||||||
break;
|
break;
|
||||||
case USB_IFACE_TYPE_WEBUSB:
|
case USB_IFACE_TYPE_WEBUSB:
|
||||||
wait_random();
|
|
||||||
usb_webusb_class_data_in(dev, &usb_ifaces[i].webusb, ep_num);
|
usb_webusb_class_data_in(dev, &usb_ifaces[i].webusb, ep_num);
|
||||||
break;
|
break;
|
||||||
default:
|
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++) {
|
for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) {
|
||||||
switch (usb_ifaces[i].type) {
|
switch (usb_ifaces[i].type) {
|
||||||
case USB_IFACE_TYPE_HID:
|
case USB_IFACE_TYPE_HID:
|
||||||
wait_random();
|
|
||||||
usb_hid_class_data_out(dev, &usb_ifaces[i].hid, ep_num);
|
usb_hid_class_data_out(dev, &usb_ifaces[i].hid, ep_num);
|
||||||
break;
|
break;
|
||||||
case USB_IFACE_TYPE_VCP:
|
case USB_IFACE_TYPE_VCP:
|
||||||
usb_vcp_class_data_out(dev, &usb_ifaces[i].vcp, ep_num);
|
usb_vcp_class_data_out(dev, &usb_ifaces[i].vcp, ep_num);
|
||||||
break;
|
break;
|
||||||
case USB_IFACE_TYPE_WEBUSB:
|
case USB_IFACE_TYPE_WEBUSB:
|
||||||
wait_random();
|
|
||||||
usb_webusb_class_data_out(dev, &usb_ifaces[i].webusb, ep_num);
|
usb_webusb_class_data_out(dev, &usb_ifaces[i].webusb, ep_num);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -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,
|
static int usb_hid_class_setup(USBD_HandleTypeDef *dev, usb_hid_state_t *state,
|
||||||
USBD_SetupReqTypedef *req) {
|
USBD_SetupReqTypedef *req) {
|
||||||
|
wait_random();
|
||||||
|
|
||||||
switch (req->bmRequest & USB_REQ_TYPE_MASK) {
|
switch (req->bmRequest & USB_REQ_TYPE_MASK) {
|
||||||
// Class request
|
// Class request
|
||||||
case USB_REQ_TYPE_CLASS:
|
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,
|
static void usb_hid_class_data_in(USBD_HandleTypeDef *dev,
|
||||||
usb_hid_state_t *state, uint8_t ep_num) {
|
usb_hid_state_t *state, uint8_t ep_num) {
|
||||||
if ((ep_num | USB_EP_DIR_IN) == state->ep_in) {
|
if ((ep_num | USB_EP_DIR_IN) == state->ep_in) {
|
||||||
|
wait_random();
|
||||||
state->ep_in_is_idle = 1;
|
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,
|
static void usb_hid_class_data_out(USBD_HandleTypeDef *dev,
|
||||||
usb_hid_state_t *state, uint8_t ep_num) {
|
usb_hid_state_t *state, uint8_t ep_num) {
|
||||||
if (ep_num == state->ep_out) {
|
if (ep_num == state->ep_out) {
|
||||||
|
wait_random();
|
||||||
// Save the report length to indicate we have read something, but don't
|
// Save the report length to indicate we have read something, but don't
|
||||||
// schedule next reading until user reads this one
|
// schedule next reading until user reads this one
|
||||||
state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num);
|
state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num);
|
||||||
|
@ -243,6 +243,8 @@ static int usb_webusb_class_setup(USBD_HandleTypeDef *dev,
|
|||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wait_random();
|
||||||
|
|
||||||
switch (req->bRequest) {
|
switch (req->bRequest) {
|
||||||
case USB_REQ_SET_INTERFACE:
|
case USB_REQ_SET_INTERFACE:
|
||||||
state->alt_setting = req->wValue;
|
state->alt_setting = req->wValue;
|
||||||
@ -263,6 +265,7 @@ static void usb_webusb_class_data_in(USBD_HandleTypeDef *dev,
|
|||||||
usb_webusb_state_t *state,
|
usb_webusb_state_t *state,
|
||||||
uint8_t ep_num) {
|
uint8_t ep_num) {
|
||||||
if ((ep_num | USB_EP_DIR_IN) == state->ep_in) {
|
if ((ep_num | USB_EP_DIR_IN) == state->ep_in) {
|
||||||
|
wait_random();
|
||||||
state->ep_in_is_idle = 1;
|
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,
|
usb_webusb_state_t *state,
|
||||||
uint8_t ep_num) {
|
uint8_t ep_num) {
|
||||||
if (ep_num == state->ep_out) {
|
if (ep_num == state->ep_out) {
|
||||||
|
wait_random();
|
||||||
// Save the report length to indicate we have read something, but don't
|
// Save the report length to indicate we have read something, but don't
|
||||||
// schedule next reading until user reads this one
|
// schedule next reading until user reads this one
|
||||||
state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num);
|
state->last_read_len = USBD_LL_GetRxDataSize(dev, ep_num);
|
||||||
|
Loading…
Reference in New Issue
Block a user