diff --git a/native/probes/ks_camera_cadence/ks_camera_cadence.cpp b/native/probes/ks_camera_cadence/ks_camera_cadence.cpp index 96c0f22..e1690bd 100644 --- a/native/probes/ks_camera_cadence/ks_camera_cadence.cpp +++ b/native/probes/ks_camera_cadence/ks_camera_cadence.cpp @@ -832,6 +832,101 @@ void printUsbVideoDescriptors(USHORT vendorId, USHORT productId) } } +void printUsbHubInventory() +{ + const auto hubPaths = enumerateInterfacePaths(UsbHubInterfaceGuid, "GUID_DEVINTERFACE_USB_HUB"); + std::printf("USB hub interfaces: %zu\n", hubPaths.size()); + ULONG totalPorts = 0; + ULONG usb3AdvertisedPorts = 0; + + for (const auto& hubPath : hubPaths) + { + Handle hub(CreateFileA( + hubPath.c_str(), + GENERIC_WRITE, + FILE_SHARE_WRITE, + nullptr, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + nullptr)); + if (!hub) + { + std::printf(" hub=%s open=failed %s\n", hubPath.c_str(), lastErrorText().c_str()); + continue; + } + + USB_NODE_INFORMATION nodeInfo{}; + nodeInfo.NodeType = UsbHub; + DWORD returned = 0; + if (!DeviceIoControl( + hub.value, + IOCTL_USB_GET_NODE_INFORMATION, + &nodeInfo, + sizeof(nodeInfo), + &nodeInfo, + sizeof(nodeInfo), + &returned, + nullptr)) + { + std::printf(" hub=%s info=failed %s\n", hubPath.c_str(), lastErrorText().c_str()); + continue; + } + + const ULONG ports = nodeInfo.u.HubInformation.HubDescriptor.bNumberOfPorts; + const bool advertisedUsb3 = + hubPath.find("root_hub30") != std::string::npos || + hubPath.find("pid_0626") != std::string::npos; + totalPorts += ports; + if (advertisedUsb3) + { + usb3AdvertisedPorts += ports; + } + + ULONG occupiedPorts = 0; + ULONG superSpeedDevices = 0; + for (ULONG port = 1; port <= ports; ++port) + { + std::vector connectionStorage(sizeof(USB_NODE_CONNECTION_INFORMATION_EX)); + auto* connection = reinterpret_cast(connectionStorage.data()); + connection->ConnectionIndex = port; + if (!DeviceIoControl( + hub.value, + IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, + connection, + static_cast(connectionStorage.size()), + connection, + static_cast(connectionStorage.size()), + &returned, + nullptr)) + { + continue; + } + + if (connection->DeviceDescriptor.idVendor != 0 || connection->DeviceDescriptor.idProduct != 0) + { + ++occupiedPorts; + } + if (connection->Speed == UsbSuperSpeed) + { + ++superSpeedDevices; + } + } + + std::printf( + " hub=%s ports=%lu advertisedUsb3=%s occupied=%lu superSpeedDevices=%lu\n", + hubPath.c_str(), + static_cast(ports), + advertisedUsb3 ? "yes" : "no", + static_cast(occupiedPorts), + static_cast(superSpeedDevices)); + } + + std::printf( + "USB hub port totals: all=%lu advertisedUsb3=%lu\n", + static_cast(totalPorts), + static_cast(usb3AdvertisedPorts)); +} + std::vector saveControls(HANDLE filter, const ControlScenario& scenario) { std::vector saved; @@ -1393,6 +1488,12 @@ int main(int argc, char** argv) { std::setvbuf(stdout, nullptr, _IONBF, 0); const std::string targetVid = argc > 1 ? argv[1] : "vid_f182"; + if (targetVid == "--usb-hubs") + { + printUsbHubInventory(); + return 0; + } + bool controlsOnly = false; bool baselineOnly = false; bool allWebcamFormats = false;