From 64faa6948b68a8d655d4cbe255b0bfb5fc35e5bc Mon Sep 17 00:00:00 2001 From: ycwan9 Date: Wed, 7 Dec 2022 04:15:32 +0000 Subject: [PATCH] fix wrong BOS response length in Linux (#49) Linux first sends a get BOS request with wLength=5, and then request the full BOS in the next packet. Replying the whole BOS results a driver error. --- components/USBIP/usb_handle.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/USBIP/usb_handle.c b/components/USBIP/usb_handle.c index 0375b16..c1aebbc 100644 --- a/components/USBIP/usb_handle.c +++ b/components/USBIP/usb_handle.c @@ -315,7 +315,9 @@ static void handleGetDescriptor(usbip_stage2_header *header) #if (USE_WINUSB == 1) case USB_DT_BOS: os_printf("* GET 0x0F BOS DESCRIPTOR\r\n"); - send_stage2_submit_data(header, 0, bosDescriptor, sizeof(bosDescriptor)); + uint32_t bos_len = header->u.cmd_submit.request.wLength.u8lo | ((uint32_t) header->u.cmd_submit.request.wLength.u8hi << 8); + bos_len = (sizeof(bosDescriptor) < bos_len) ? sizeof(bosDescriptor) : bos_len; + send_stage2_submit_data(header, 0, bosDescriptor, bos_len); break; #else case USB_DT_HID_REPORT: