diff options
| author | Wei Mao <[email protected]> | 2023-03-20 17:12:34 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-03-20 17:12:34 -0700 |
| commit | 0250f5db3ef51843d27570c83dc59acd1c1b14b8 (patch) | |
| tree | 9386a87d0c40fe8a0c1bb5f94b5833e90da5c4f2 | |
| parent | 5ccdeee0a0ee3bafb9a6d2920e0e2fabfef24286 (diff) | |
[usb/usbview] Enumerate HostController with multiple DeviceInterfaces (#938)
| -rw-r--r-- | usb/usbview/enum.c | 117 |
1 files changed, 57 insertions, 60 deletions
diff --git a/usb/usbview/enum.c b/usb/usbview/enum.c index fd427f68..297e0d32 100644 --- a/usb/usbview/enum.c +++ b/usb/usbview/enum.c @@ -296,77 +296,74 @@ EnumerateHostControllers ( { deviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - success = SetupDiEnumDeviceInterfaces(deviceInfo, - 0, - (LPGUID)&GUID_CLASS_USB_HOST_CONTROLLER, - index, - &deviceInterfaceData); - - if (!success) + for (int devInterfaceIndex = 0; + SetupDiEnumDeviceInterfaces(deviceInfo, + &deviceInfoData, + (LPGUID)&GUID_CLASS_USB_HOST_CONTROLLER, + devInterfaceIndex, + &deviceInterfaceData); + devInterfaceIndex++) { - OOPS(); - break; - } + success = SetupDiGetDeviceInterfaceDetail(deviceInfo, + &deviceInterfaceData, + NULL, + 0, + &requiredLength, + NULL); - success = SetupDiGetDeviceInterfaceDetail(deviceInfo, - &deviceInterfaceData, - NULL, - 0, - &requiredLength, - NULL); + if (!success && GetLastError() != ERROR_INSUFFICIENT_BUFFER) + { + OOPS(); + break; + } - if (!success && GetLastError() != ERROR_INSUFFICIENT_BUFFER) - { - OOPS(); - break; - } + deviceDetailData = ALLOC(requiredLength); + if (deviceDetailData == NULL) + { + OOPS(); + break; + } - deviceDetailData = ALLOC(requiredLength); - if (deviceDetailData == NULL) - { - OOPS(); - break; - } + deviceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - deviceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + success = SetupDiGetDeviceInterfaceDetail(deviceInfo, + &deviceInterfaceData, + deviceDetailData, + requiredLength, + &requiredLength, + NULL); - success = SetupDiGetDeviceInterfaceDetail(deviceInfo, - &deviceInterfaceData, - deviceDetailData, - requiredLength, - &requiredLength, - NULL); + if (!success) + { + OOPS(); + break; + } - if (!success) - { - OOPS(); - break; - } + hHCDev = CreateFile(deviceDetailData->DevicePath, + GENERIC_WRITE, + FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + 0, + NULL); - hHCDev = CreateFile(deviceDetailData->DevicePath, - GENERIC_WRITE, - FILE_SHARE_WRITE, - NULL, - OPEN_EXISTING, - 0, - NULL); + // If the handle is valid, then we've successfully opened a Host + // Controller. Display some info about the Host Controller itself, + // then enumerate the Root Hub attached to the Host Controller. + // + if (hHCDev != INVALID_HANDLE_VALUE) + { + EnumerateHostController(hTreeParent, + hHCDev, + deviceDetailData->DevicePath, + deviceInfo, + &deviceInfoData); - // If the handle is valid, then we've successfully opened a Host - // Controller. Display some info about the Host Controller itself, - // then enumerate the Root Hub attached to the Host Controller. - // - if (hHCDev != INVALID_HANDLE_VALUE) - { - EnumerateHostController(hTreeParent, - hHCDev, - deviceDetailData->DevicePath, - deviceInfo, - &deviceInfoData); + CloseHandle(hHCDev); + } - CloseHandle(hHCDev); + FREE(deviceDetailData); } - - FREE(deviceDetailData); } SetupDiDestroyDeviceInfoList(deviceInfo); |
