From 93e489704413f2b58baba08a6e1c0823606e4cc5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 30 Sep 2018 15:14:30 -0400 Subject: [PATCH] usb_cdc: Add usb_read_ep0_setup() interface function Use new usb_read_ep0_setup() function when reading a setup packet - this allows the low-level usb hardware code to better handle errors. Signed-off-by: Kevin O'Connor --- src/generic/usb_cdc.c | 3 +-- src/generic/usb_cdc.h | 1 + src/lpc176x/usbserial.c | 6 ++++++ src/samd21/usbserial.c | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c index 3899d7c3..a87ab810 100644 --- a/src/generic/usb_cdc.c +++ b/src/generic/usb_cdc.c @@ -412,9 +412,8 @@ static void usb_state_ready(void) { struct usb_ctrlrequest req; - int_fast8_t ret = usb_read_ep0(&req, sizeof(req)); + int_fast8_t ret = usb_read_ep0_setup(&req, sizeof(req)); if (ret != sizeof(req)) - // XXX - should verify that packet was sent with a setup token return; switch (req.bRequest) { case USB_REQ_GET_DESCRIPTOR: usb_req_get_descriptor(&req); break; diff --git a/src/generic/usb_cdc.h b/src/generic/usb_cdc.h index 21646900..4771d08c 100644 --- a/src/generic/usb_cdc.h +++ b/src/generic/usb_cdc.h @@ -15,6 +15,7 @@ enum { int_fast8_t usb_read_bulk_out(void *data, uint_fast8_t max_len); int_fast8_t usb_send_bulk_in(void *data, uint_fast8_t len); int_fast8_t usb_read_ep0(void *data, uint_fast8_t max_len); +int_fast8_t usb_read_ep0_setup(void *data, uint_fast8_t max_len); int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len); int_fast8_t usb_send_ep0_progmem(const void *data, uint_fast8_t len); void usb_stall_ep0(void); diff --git a/src/lpc176x/usbserial.c b/src/lpc176x/usbserial.c index 1dc3836c..fba2fd0b 100644 --- a/src/lpc176x/usbserial.c +++ b/src/lpc176x/usbserial.c @@ -189,6 +189,12 @@ usb_read_ep0(void *data, uint_fast8_t max_len) return usb_read_packet(EP0OUT, data, max_len); } +int_fast8_t +usb_read_ep0_setup(void *data, uint_fast8_t max_len) +{ + return usb_read_ep0(data, max_len); +} + int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len) { diff --git a/src/samd21/usbserial.c b/src/samd21/usbserial.c index 0d8f3155..bac75853 100644 --- a/src/samd21/usbserial.c +++ b/src/samd21/usbserial.c @@ -127,6 +127,12 @@ usb_read_ep0(void *data, uint_fast8_t max_len) return usb_read_packet(0, 0, data, max_len); } +int_fast8_t +usb_read_ep0_setup(void *data, uint_fast8_t max_len) +{ + return usb_read_ep0(data, max_len); +} + int_fast8_t usb_send_ep0(const void *data, uint_fast8_t len) {