1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 23:08:14 +00:00

core/usb: call wait_random just before returning the data

This commit is contained in:
Pavol Rusnak 2019-06-24 15:44:11 +02:00 committed by Tomas Susanka
parent 0daf2bf6b6
commit 1ec5d091fd

View File

@ -343,7 +343,6 @@ static uint8_t usb_class_deinit(USBD_HandleTypeDef *dev, uint8_t cfg_idx) {
static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
USBD_SetupReqTypedef *req) {
wait_random();
if (((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_CLASS) &&
((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD) &&
((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_VENDOR)) {
@ -375,10 +374,12 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
'r',
't', // char URL[]
};
wait_random();
USBD_CtlSendData(dev, UNCONST(webusb_url),
MIN_8bits(req->wLength, sizeof(webusb_url)));
return USBD_OK;
} else {
wait_random();
USBD_CtlError(dev, req);
return USBD_FAIL;
}
@ -402,10 +403,12 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
0x00, // subCompatibleId
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved
};
wait_random();
USBD_CtlSendData(dev, UNCONST(winusb_wcid),
MIN_8bits(req->wLength, sizeof(winusb_wcid)));
return USBD_OK;
} else {
wait_random();
USBD_CtlError(dev, req);
return USBD_FAIL;
}
@ -440,10 +443,12 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
'c', 0x00, 'e', 0x00, 'a', 0x00, '5', 0x00, '0', 0x00, '3', 0x00,
'd', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00, // propertyData
};
wait_random();
USBD_CtlSendData(dev, UNCONST(winusb_guid),
MIN_8bits(req->wLength, sizeof(winusb_guid)));
return USBD_OK;
} else {
wait_random();
USBD_CtlError(dev, req);
return USBD_FAIL;
}
@ -452,18 +457,23 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
} else if ((req->bmRequest & USB_REQ_RECIPIENT_MASK) ==
USB_REQ_RECIPIENT_INTERFACE) {
if (req->wIndex >= USBD_MAX_NUM_INTERFACES) {
wait_random();
USBD_CtlError(dev, req);
return USBD_FAIL;
}
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:
wait_random();
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:
wait_random();
USBD_CtlError(dev, req);
return USBD_FAIL;
}
@ -472,16 +482,18 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev,
}
static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) {
wait_random();
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:
wait_random();
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:
@ -492,16 +504,18 @@ static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) {
}
static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) {
wait_random();
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:
wait_random();
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:
@ -512,10 +526,10 @@ static uint8_t usb_class_data_out(USBD_HandleTypeDef *dev, uint8_t ep_num) {
}
static uint8_t usb_class_sof(USBD_HandleTypeDef *dev) {
wait_random();
for (int i = 0; i < USBD_MAX_NUM_INTERFACES; i++) {
switch (usb_ifaces[i].type) {
case USB_IFACE_TYPE_VCP:
wait_random();
usb_vcp_class_sof(dev, &usb_ifaces[i].vcp);
break;
default: