From d2272c1c4c686f55053c7ed701ba6388065e35df Mon Sep 17 00:00:00 2001 From: arighi Date: Thu, 23 Sep 2010 08:45:27 +0000 Subject: [PATCH] STM32: USB: always check host expected size Always check the host expected size before sending device, interface or endpoint status and properly set zero-packet flag when the size of the packet to transmit is less than the host expected size. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4265 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/usb_stm32.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index bbd02d21..e625cdfa 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -1178,12 +1178,15 @@ static uint32_t InData; /* Get device status */ static int UsbDevStatus(uint16_t index) { + size_t size; + if (index) return -USB_NODEV_ERROR; InData = ((uint32_t)udc.feature) & 0xff; + size = usb_size(sizeof(InData), usb_le16_to_cpu(setup_packet.wLength)); __usb_ep_write(CTRL_ENP_IN, - (uint8_t *)&InData, sizeof(InData), USB_StatusHandler); + (uint8_t *)&InData, size, USB_StatusHandler); return 0; } @@ -1191,9 +1194,12 @@ static int UsbDevStatus(uint16_t index) /* Get interface status */ static int UsbInterfaceStatus(UNUSED_ARG(uint16_t, index)) { + size_t size; + InData = 0; + size = usb_size(sizeof(InData), usb_le16_to_cpu(setup_packet.wLength)); __usb_ep_write(CTRL_ENP_IN, - (uint8_t *)&InData, sizeof(InData), USB_StatusHandler); + (uint8_t *)&InData, size, USB_StatusHandler); return 0; } @@ -1201,13 +1207,16 @@ static int UsbInterfaceStatus(UNUSED_ARG(uint16_t, index)) /* Get endpoint status */ static int UsbEpStatus(uint16_t index) { + size_t size; + if ((index & 0x7F) > 16) return -USB_NODEV_ERROR; InData = 0; USB_GetStallEP(USB_EpLogToPhysAdd(index), (bool *)&InData); + size = usb_size(sizeof(InData), usb_le16_to_cpu(setup_packet.wLength)); __usb_ep_write(CTRL_ENP_IN, - (uint8_t *)&InData, sizeof(InData), USB_StatusHandler); + (uint8_t *)&InData, size, USB_StatusHandler); return 0; } -- 2.25.1