Skip to content

Commit

Permalink
usb: loopback: use class internal buffer to store request data
Browse files Browse the repository at this point in the history
Use internal buffer to store request data and not
the data OUT stage buffer.

Signed-off-by: Johann Fischer <[email protected]>
  • Loading branch information
jfischer-no authored and nashif committed Aug 3, 2021
1 parent 5698e17 commit e9f9138
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions subsys/usb/class/loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(usb_loopback);
#define LOOPBACK_IN_EP_IDX 1

static uint8_t loopback_buf[1024];
BUILD_ASSERT(sizeof(loopback_buf) == CONFIG_USB_REQUEST_BUFFER_SIZE);

/* usb.rst config structure start */
struct usb_loopback_config {
Expand Down Expand Up @@ -135,13 +136,21 @@ static int loopback_vendor_handler(struct usb_setup_packet *setup,
if (usb_reqtype_is_to_device(setup) &&
setup->bRequest == 0x5b) {
LOG_DBG("Host-to-Device, data %p", *data);
/*
* Copy request data in loopback_buf buffer and reuse
* it later in control device-to-host transfer.
*/
memcpy(loopback_buf, *data,
MIN(sizeof(loopback_buf), setup->wLength));
return 0;
}

if ((usb_reqtype_is_to_host(setup)) &&
(setup->bRequest == 0x5c)) {
LOG_DBG("Device-to-Host, wLength %d, data %p",
setup->wLength, *data);
*data = loopback_buf;
*len = MIN(sizeof(loopback_buf), setup->wLength);
return 0;
}

Expand Down

0 comments on commit e9f9138

Please sign in to comment.