1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 17:38:39 +00:00

embed/trezorhal/usb: correct handling of interface messages in usb_class_setup

This commit is contained in:
Pavol Rusnak 2018-02-12 18:23:46 +01:00
parent 7b2fd6ae4c
commit c115faf2cd
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 33 additions and 41 deletions

View File

@ -373,21 +373,25 @@ static uint8_t usb_class_setup(USBD_HandleTypeDef *dev, USBD_SetupReqTypedef *re
}
}
}
} else if (req->wIndex >= USBD_MAX_NUM_INTERFACES) {
USBD_CtlError(dev, req);
return USBD_FAIL;
}
switch (usb_ifaces[req->wIndex].type) {
case USB_IFACE_TYPE_HID:
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:
return usb_webusb_class_setup(dev, &usb_ifaces[req->wIndex].webusb, req);
default:
} else
if ((req->bmRequest & USB_REQ_RECIPIENT_MASK) == USB_REQ_RECIPIENT_INTERFACE) {
if (req->wIndex >= USBD_MAX_NUM_INTERFACES) {
USBD_CtlError(dev, req);
return USBD_FAIL;
}
switch (usb_ifaces[req->wIndex].type) {
case USB_IFACE_TYPE_HID:
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:
return usb_webusb_class_setup(dev, &usb_ifaces[req->wIndex].webusb, req);
default:
USBD_CtlError(dev, req);
return USBD_FAIL;
}
}
return USBD_OK;
}
static uint8_t usb_class_data_in(USBD_HandleTypeDef *dev, uint8_t ep_num) {

View File

@ -217,37 +217,25 @@ static void usb_webusb_class_deinit(USBD_HandleTypeDef *dev, usb_webusb_state_t
static int usb_webusb_class_setup(USBD_HandleTypeDef *dev, usb_webusb_state_t *state, USBD_SetupReqTypedef *req) {
switch (req->bmRequest & USB_REQ_TYPE_MASK) {
// Class request
case USB_REQ_TYPE_CLASS:
switch (req->bRequest) {
default:
USBD_CtlError(dev, req);
return USBD_FAIL;
}
break;
// Interface & Endpoint request
case USB_REQ_TYPE_STANDARD:
switch (req->bRequest) {
case USB_REQ_SET_INTERFACE:
state->alt_setting = req->wValue;
USBD_CtlSendStatus(dev);
return USBD_OK;
case USB_REQ_GET_INTERFACE:
USBD_CtlSendData(dev, &state->alt_setting, sizeof(state->alt_setting));
return USBD_OK;
default:
USBD_CtlError(dev, req);
return USBD_FAIL;
}
break;
if ((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_STANDARD) {
return USBD_OK;
}
return USBD_OK;
switch (req->bRequest) {
case USB_REQ_SET_INTERFACE:
state->alt_setting = req->wValue;
USBD_CtlSendStatus(dev);
return USBD_OK;
case USB_REQ_GET_INTERFACE:
USBD_CtlSendData(dev, &state->alt_setting, sizeof(state->alt_setting));
return USBD_OK;
default:
USBD_CtlError(dev, req);
return USBD_FAIL;
}
}
static void usb_webusb_class_data_in(USBD_HandleTypeDef *dev, usb_webusb_state_t *state, uint8_t ep_num) {