Skip to content

Commit

Permalink
Merge branch 'bugfix/usb/host/urb_compliance_verification_add_v5.1' i…
Browse files Browse the repository at this point in the history
…nto 'release/v5.1'

[USB Host] added URB check args and transfer check compliance for regular EP transfer submit (v5.1)

See merge request espressif/esp-idf!25467
  • Loading branch information
suda-morris committed Aug 25, 2023
2 parents 06a4943 + 29a38ce commit cd979e2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions components/usb/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,12 +1077,16 @@ esp_err_t usbh_ep_get_handle(usb_device_handle_t dev_hdl, uint8_t bEndpointAddre
esp_err_t usbh_ep_enqueue_urb(usbh_ep_handle_t ep_hdl, urb_t *urb)
{
USBH_CHECK(ep_hdl != NULL && urb != NULL, ESP_ERR_INVALID_ARG);
/*
Todo: Here would be a good place to check that the URB is filled correctly according to the USB 2.0 specification.
This is currently done by the USB host library layer, but is more appropriate here.
*/
USBH_CHECK(urb_check_args(urb), ESP_ERR_INVALID_ARG);
bool xfer_is_in = ((usb_setup_packet_t *)urb->transfer.data_buffer)->bmRequestType & USB_BM_REQUEST_TYPE_DIR_IN;

endpoint_t *ep_obj = (endpoint_t *)ep_hdl;

USBH_CHECK( transfer_check_usb_compliance(&(urb->transfer),
USB_EP_DESC_GET_XFERTYPE(ep_obj->constant.ep_desc),
USB_EP_DESC_GET_MPS(ep_obj->constant.ep_desc),
xfer_is_in),
ESP_ERR_INVALID_ARG);
// Check that the EP's underlying pipe is in the active state before submitting the URB
if (hcd_pipe_get_state(ep_obj->constant.pipe_hdl) != HCD_PIPE_STATE_ACTIVE) {
return ESP_ERR_INVALID_STATE;
Expand Down

0 comments on commit cd979e2

Please sign in to comment.