usb: Add missing wMaxPacketSize endian conversions

wMaxPacketSize in endpoint descriptor is stored in little-endian order,
but the mps parameter passed to functions is in host order.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
This commit is contained in:
Tomasz Moń 2024-07-19 08:09:22 +02:00 committed by Fabio Baltieri
commit 60835aa393
7 changed files with 35 additions and 27 deletions

View file

@ -6,6 +6,7 @@
#include <zephyr/ztest.h>
#include <zephyr/drivers/usb/udc.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/usb/usb_ch9.h>
#include <zephyr/logging/log.h>
@ -95,7 +96,7 @@ static void test_udc_thread(void *p1, void *p2, void *p3)
static void test_udc_ep_try_config(const struct device *dev,
struct usb_ep_descriptor *ed)
{
uint16_t mps = ed->wMaxPacketSize;
uint16_t mps = sys_le16_to_cpu(ed->wMaxPacketSize);
int err;
err = udc_ep_try_config(dev, ed->bEndpointAddress,
@ -129,13 +130,17 @@ static void test_udc_ep_enable(const struct device *dev,
int err1, err2, err3, err4;
err1 = udc_ep_enable(dev, ed->bEndpointAddress, ed->bmAttributes,
ed->wMaxPacketSize, ed->bInterval);
sys_le16_to_cpu(ed->wMaxPacketSize),
ed->bInterval);
err2 = udc_ep_enable(dev, ed->bEndpointAddress, ed->bmAttributes,
ed->wMaxPacketSize, ed->bInterval);
sys_le16_to_cpu(ed->wMaxPacketSize),
ed->bInterval);
err3 = udc_ep_enable(dev, FALSE_EP_ADDR, ed->bmAttributes,
ed->wMaxPacketSize, ed->bInterval);
sys_le16_to_cpu(ed->wMaxPacketSize),
ed->bInterval);
err4 = udc_ep_enable(dev, ctrl_ep, ed->bmAttributes,
ed->wMaxPacketSize, ed->bInterval);
sys_le16_to_cpu(ed->wMaxPacketSize),
ed->bInterval);
if (!udc_is_initialized(dev) && !udc_is_enabled(dev)) {
zassert_equal(err1, -EPERM, "Not failed to enable endpoint");
@ -192,7 +197,7 @@ static struct net_buf *test_udc_ep_buf_alloc(const struct device *dev,
struct net_buf *buf;
buf = udc_ep_buf_alloc(dev, ed->bEndpointAddress,
ed->wMaxPacketSize);
sys_le16_to_cpu(ed->wMaxPacketSize));
zassert_not_null(buf, "Failed to allocate request");
@ -326,13 +331,14 @@ static void test_udc_ep_api(const struct device *dev,
for (int i = 0; i < num_of_iterations; i++) {
err = udc_ep_enable(dev, ed->bEndpointAddress, ed->bmAttributes,
ed->wMaxPacketSize, ed->bInterval);
sys_le16_to_cpu(ed->wMaxPacketSize),
ed->bInterval);
zassert_ok(err, "Failed to enable endpoint");
/* It needs a little reserve for memory management overhead. */
for (int n = 0; n < (CONFIG_UDC_BUF_COUNT - 4); n++) {
buf = udc_ep_buf_alloc(dev, ed->bEndpointAddress,
ed->wMaxPacketSize);
sys_le16_to_cpu(ed->wMaxPacketSize));
zassert_not_null(buf,
"Failed to allocate request (%d) for 0x%02x",
n, ed->bEndpointAddress);
@ -362,7 +368,7 @@ static void test_udc_ep_mps(uint8_t type)
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = 0x01,
.bmAttributes = type,
.wMaxPacketSize = 0,
.wMaxPacketSize = sys_cpu_to_le16(0),
.bInterval = 0,
};
const struct device *dev;
@ -399,7 +405,7 @@ static void test_udc_ep_mps(uint8_t type)
continue;
}
ed.wMaxPacketSize = mps[i];
ed.wMaxPacketSize = sys_cpu_to_le16(mps[i]);
test_udc_ep_api(dev, &ed);
ed.bEndpointAddress |= USB_EP_DIR_IN;
@ -440,7 +446,7 @@ static struct usb_ep_descriptor ed_ctrl_out = {
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = USB_CONTROL_EP_OUT,
.bmAttributes = USB_EP_TYPE_CONTROL,
.wMaxPacketSize = 64,
.wMaxPacketSize = sys_cpu_to_le16(64),
.bInterval = 0,
};
@ -449,7 +455,7 @@ static struct usb_ep_descriptor ed_ctrl_in = {
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = USB_CONTROL_EP_IN,
.bmAttributes = USB_EP_TYPE_CONTROL,
.wMaxPacketSize = 64,
.wMaxPacketSize = sys_cpu_to_le16(64),
.bInterval = 0,
};
@ -458,7 +464,7 @@ static struct usb_ep_descriptor ed_bulk_out = {
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = 0x01,
.bmAttributes = USB_EP_TYPE_BULK,
.wMaxPacketSize = 64,
.wMaxPacketSize = sys_cpu_to_le16(64),
.bInterval = 0,
};
@ -467,7 +473,7 @@ static struct usb_ep_descriptor ed_bulk_in = {
.bDescriptorType = USB_DESC_ENDPOINT,
.bEndpointAddress = 0x81,
.bmAttributes = USB_EP_TYPE_BULK,
.wMaxPacketSize = 64,
.wMaxPacketSize = sys_cpu_to_le16(64),
.bInterval = 0,
};