drivers: usb: check maximum packet size

Check maximum packet size (MPS) of an endpoint in usb_dc_kinetis
and usb_dc_native_posix drivers.

resolves #14957
resolves #14954

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This commit is contained in:
Johann Fischer 2019-04-05 17:52:57 +02:00 committed by Anas Nashif
parent 65fd5859a4
commit d2c6869e30
2 changed files with 31 additions and 9 deletions

View file

@ -276,14 +276,35 @@ int usb_dc_ep_check_cap(const struct usb_dc_ep_cfg_data * const cfg)
{
u8_t ep_idx = EP_ADDR2IDX(cfg->ep_addr);
if ((cfg->ep_type == USB_DC_EP_CONTROL) && ep_idx) {
LOG_ERR("invalid endpoint configuration");
return -1;
}
if (ep_idx > (NUM_OF_EP_MAX - 1)) {
LOG_ERR("endpoint index/address out of range");
return -1;
return -EINVAL;
}
switch (cfg->ep_type) {
case USB_DC_EP_CONTROL:
if (cfg->ep_mps > USB_MAX_CTRL_MPS) {
return -EINVAL;
}
return 0;
case USB_DC_EP_BULK:
if (cfg->ep_mps > USB_MAX_FS_BULK_MPS) {
return -EINVAL;
}
break;
case USB_DC_EP_INTERRUPT:
if (cfg->ep_mps > USB_MAX_FS_INT_MPS) {
return -EINVAL;
}
break;
case USB_DC_EP_ISOCHRONOUS:
if (cfg->ep_mps > USB_MAX_FS_ISO_MPS) {
return -EINVAL;
}
break;
default:
LOG_ERR("Unknown endpoint type!");
return -EINVAL;
}
if (ep_idx & BIT(0)) {
@ -309,8 +330,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const cfg)
struct k_mem_block *block;
struct usb_ep_ctrl_data *ep_ctrl = &dev_data.ep_ctrl[ep_idx];
if (ep_idx > (NUM_OF_EP_MAX - 1)) {
LOG_ERR("Wrong endpoint index/address");
if (usb_dc_ep_check_cap(cfg)) {
return -EINVAL;
}

View file

@ -192,7 +192,9 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const cfg)
u8_t ep = cfg->ep_addr;
u8_t ep_idx = USBIP_EP_ADDR2IDX(ep);
LOG_DBG("ep %x, mps %d, type %d", ep, ep_mps, cfg->ep_type);
if (usb_dc_ep_check_cap(cfg)) {
return -EINVAL;
}
if (!usbip_ctrl.attached && !usbip_ep_is_valid(ep)) {
return -EINVAL;