1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-16 04:29:08 +00:00

trezorhal: small fixes to USB stack

This commit is contained in:
Pavol Rusnak 2018-01-21 02:37:02 +01:00
parent aa8c192040
commit 5ef0967857
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
5 changed files with 34 additions and 20 deletions

View File

@ -175,7 +175,7 @@ static uint8_t *usb_get_langid_str_descriptor(USBD_SpeedTypeDef speed, uint16_t
.wData = USB_LANGID_ENGLISH_US,
};
*length = sizeof(usb_langid_str_desc);
return (uint8_t *)(&usb_langid_str_desc);
return UNCONST(&usb_langid_str_desc);
}
static uint8_t *usb_get_manufacturer_str_descriptor(USBD_SpeedTypeDef speed, uint16_t *length) {
@ -281,7 +281,8 @@ 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) {
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_STANDARD) &&
((req->bmRequest & USB_REQ_TYPE_MASK) != USB_REQ_TYPE_VENDOR)) {
return USBD_OK;
}
if (req->wIndex >= USBD_MAX_NUM_INTERFACES) {

View File

@ -286,7 +286,7 @@ static int usb_hid_class_setup(USBD_HandleTypeDef *dev, usb_hid_state_t *state,
switch (req->wValue >> 8) {
case USB_DESC_TYPE_HID:
USBD_CtlSendData(dev, (uint8_t *)&state->desc_block->hid, MIN(req->wLength, sizeof(state->desc_block->hid)));
USBD_CtlSendData(dev, UNCONST(&state->desc_block->hid), MIN(req->wLength, sizeof(state->desc_block->hid)));
break;
case USB_DESC_TYPE_REPORT:

View File

@ -360,7 +360,7 @@ static int usb_vcp_class_setup(USBD_HandleTypeDef *dev, usb_vcp_state_t *state,
case USB_D2H:
switch (req->bRequest) {
case USB_CDC_GET_LINE_CODING:
USBD_CtlSendData(dev, (uint8_t *)(&line_coding), MIN(req->wLength, sizeof(line_coding)));
USBD_CtlSendData(dev, UNCONST(&line_coding), MIN(req->wLength, sizeof(line_coding)));
break;
default:
USBD_CtlSendData(dev, cmd_buffer, MIN(req->wLength, sizeof(cmd_buffer)));

View File

@ -244,7 +244,7 @@ static int usb_webusb_class_setup(USBD_HandleTypeDef *dev, usb_webusb_state_t *s
case USB_WEBUSB_REQ_GET_URL:
// we should check whether req->wValue == USB_WEBUSB_LANDING_PAGE,
// but let's return always the same url for all indexes
USBD_CtlSendData(dev, (uint8_t *)url, sizeof(url));
USBD_CtlSendData(dev, UNCONST(url), sizeof(url));
break;
default:
USBD_CtlError(dev, req);

View File

@ -268,24 +268,37 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
pdev->ep0_state = USBD_EP0_SETUP;
pdev->ep0_data_len = pdev->request.wLength;
switch (pdev->request.bmRequest & 0x1F)
switch (pdev->request.bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_RECIPIENT_DEVICE:
USBD_StdDevReq (pdev, &pdev->request);
break;
case USB_REQ_TYPE_STANDARD:
switch (pdev->request.bmRequest & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_DEVICE:
USBD_StdDevReq(pdev, &pdev->request);
break;
case USB_REQ_RECIPIENT_INTERFACE:
USBD_StdItfReq(pdev, &pdev->request);
break;
case USB_REQ_RECIPIENT_ENDPOINT:
USBD_StdEPReq(pdev, &pdev->request);
break;
default:
USBD_LL_StallEP(pdev, pdev->request.bmRequest & 0x80);
break;
}
break;
case USB_REQ_RECIPIENT_INTERFACE:
USBD_StdItfReq(pdev, &pdev->request);
break;
case USB_REQ_RECIPIENT_ENDPOINT:
USBD_StdEPReq(pdev, &pdev->request);
break;
default:
USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80);
break;
case USB_REQ_TYPE_CLASS:
case USB_REQ_TYPE_VENDOR:
if (pdev->dev_state == USBD_STATE_CONFIGURED) {
if (pdev->pClass->Setup != NULL)
pdev->pClass->Setup(pdev, &pdev->request);
} else {
USBD_CtlError(pdev, &pdev->request);
}
break;
}
return USBD_OK;
}