From 9b878bfeb957bee2f4d69babff6bb8131126944a Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Mon, 9 Mar 2009 09:40:43 +0000 Subject: [PATCH] - Fix an incorrect assumption that endpoint descriptors must immediately follow an interface descriptor (there may be generic descriptors in between too, as it is for e.g. USB HID devices). Thanks to Michael Lotz from Haiku for his help with this issue. - Fix incorrect handling of alternate interface settings, which resulted in reading uninitialized memory. svn path=/trunk/; revision=39912 --- .../drivers/usb/nt4compat/usbdriver/devmgr.c | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/reactos/drivers/usb/nt4compat/usbdriver/devmgr.c b/reactos/drivers/usb/nt4compat/usbdriver/devmgr.c index ed917cd027f..ec5cc940f10 100644 --- a/reactos/drivers/usb/nt4compat/usbdriver/devmgr.c +++ b/reactos/drivers/usb/nt4compat/usbdriver/devmgr.c @@ -1200,6 +1200,7 @@ dev_mgr_build_usb_if(PUSB_CONFIGURATION pcfg, PUSB_INTERFACE pif, PUSB_INTERFACE { LONG i; PUSB_ENDPOINT_DESC pendp_desc; + PBYTE pbuf; if (pcfg == NULL || pif == NULL || pif_desc == NULL) return FALSE; @@ -1218,11 +1219,23 @@ dev_mgr_build_usb_if(PUSB_CONFIGURATION pcfg, PUSB_INTERFACE pif, PUSB_INTERFACE InitializeListHead(&pif->altif_list); pif->altif_count = 0; - pendp_desc = (PUSB_ENDPOINT_DESC) (&((PBYTE) pif_desc)[sizeof(USB_INTERFACE_DESC)]); + pbuf = &((PBYTE) pif_desc)[sizeof(USB_INTERFACE_DESC)]; - for(i = 0; i < pif->endp_count; i++, pendp_desc++) + i = 0; + while (i < pif->endp_count) { - dev_mgr_build_usb_endp(pif, &pif->endp[i], pendp_desc); + pendp_desc = (PUSB_ENDPOINT_DESC)pbuf; + + // check if it's an endpoint descriptor + if (pendp_desc->bDescriptorType == USB_DT_ENDPOINT) + { + // add it + dev_mgr_build_usb_endp(pif, &pif->endp[i], pendp_desc); + i++; + } + + // skip to the next one + pbuf += pendp_desc->bLength; } } else @@ -1299,8 +1312,7 @@ dev_mgr_build_usb_config(PUSB_DEV pdev, PBYTE pbuf, ULONG config_val, LONG confi } else { - i--; - pif = &pcfg->interf[i]; + pif = &pcfg->interf[i-1]; dev_mgr_build_usb_if(pcfg, pif, pif_desc, TRUE); } }