From 7f323f62b9dd4a0ee509d7e6e71d4bc2b4d10348 Mon Sep 17 00:00:00 2001 From: tantricity Date: Fri, 17 Jun 2011 02:27:01 +0000 Subject: [PATCH] usb patches (tueidj) git-svn-id: https://devkitpro.svn.sourceforge.net/svnroot/devkitpro/trunk/libogc@4660 258c5a1a-4f63-435d-9564-e8f6d34ab52c --- libogc/usb.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/libogc/usb.c b/libogc/usb.c index f3aee07..caa8831 100644 --- a/libogc/usb.c +++ b/libogc/usb.c @@ -539,7 +539,7 @@ done: return ret; } -static inline s32 __usb_getdesc(s32 fd, u8 *buffer, u8 valuehi, u8 valuelo, u16 index, u8 size) +static inline s32 __usb_getdesc(s32 fd, u8 *buffer, u8 valuehi, u8 valuelo, u16 index, u16 size) { u8 requestType = USB_CTRLTYPE_DIR_DEVICE2HOST; @@ -923,6 +923,9 @@ s32 USB_GetDescriptors(s32 fd, usb_devdesc *udd) } retval = __usb_getdesc(fd, buffer, USB_DT_CONFIG, iConf, 0, USB_DT_CONFIG_SIZE); + if (retval < 0) + goto free_and_error; + ucd = &udd->configurations[iConf]; memcpy(ucd, buffer, USB_DT_CONFIG_SIZE); iosFree(hId, buffer); @@ -951,6 +954,13 @@ s32 USB_GetDescriptors(s32 fd, usb_devdesc *udd) goto free_and_error; for(iInterface = 0; iInterface < ucd->bNumInterfaces; iInterface++) { + retval = __find_next_endpoint(ptr, size, 0); + if (retval>0) { + // FIXME: do something with this data + } + ptr += retval; + size -= retval; + uid = ucd->interfaces+iInterface; memcpy(uid, ptr, USB_DT_INTERFACE_SIZE); ptr += uid->bLength; @@ -983,16 +993,20 @@ s32 USB_GetDescriptors(s32 fd, usb_devdesc *udd) } } - if (iInterface==(ucd->bNumInterfaces-1) && size>2 && ptr[0]==USB_DT_INTERFACE_SIZE && ptr[1]==USB_DT_INTERFACE) { - // looks like there's interfaces with alternate settings on this device. - // grab them and make them look like separate interfaces - usb_interfacedesc *interfaces = realloc(ucd->interfaces, (iInterface+2)*sizeof(*interfaces)); - if (interfaces == NULL) - goto free_and_error; - interfaces[iInterface+1].endpoints = NULL; - interfaces[iInterface+1].extra = NULL; - ucd->bNumInterfaces++; - ucd->interfaces = interfaces; + if (iInterface==(ucd->bNumInterfaces-1) && size>2) { + // we've read all the interfaces but there's data left (probably alternate setting interfaces) + // see if we can find another interface descriptor + retval = __find_next_endpoint(ptr, size, 0); + if (size-retval >= USB_DT_INTERFACE_SIZE && ptr[retval+1] == USB_DT_INTERFACE) { + // found alternates, make room and loop + usb_interfacedesc *interfaces = realloc(ucd->interfaces, (iInterface+2)*sizeof(*interfaces)); + if (interfaces == NULL) + goto free_and_error; + interfaces[iInterface+1].endpoints = NULL; + interfaces[iInterface+1].extra = NULL; + ucd->bNumInterfaces++; + ucd->interfaces = interfaces; + } } } iosFree(hId, buffer); -- 2.11.4.GIT