There is a past thread
(https://www.osronline.com/showthread.cfm?link=252223) which talks
about using USB DFU where the user wishes to cycle a USB device in
software. The participants of the last thread found the same libusb
and WinUSB code that I did, which stated that WinUSB does not support
IOCTL_USB_HUB_CYCLE_PORT. However, looking at the documentation
(https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/usbioctl/ni-usbioctl-ioctl_usb_hub_cycle_port)
it appears this was removed for Vista and 7 but later reintroduced due
to its utility.
I think I have the workflow of what I need to do:
- Get all USB host controllers.
- To each host controller send IOCTL_USB_GET_ROOT_HUB_NAME to get the
root hub names to pass to CreateFile. - To each root hub send USB_HUB_INFORMATION_EX to get the number of ports.
- To each port send IOCTL_USB_GET_NODE_INFORMATION to determine if it
is attached to a hub, and repeat the above for each hub. - To each hub, for each port, send
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, looking for my device.
Is this procedure complete? How do I accomplish #1? I am not clear on
#4, as I can’t (re-)find the structure in which you specify a root hub
and/or hub and port.
It feels as if I confused myself halfway through that, I was
originally typing something slightly different. In any case the gist
of it is that I need to recursively iterate through all hubs on a host
controller to find a specific VID/PID.
I would like to watch for WM_DEVICECHANGED messages for the device to
search for. How do I turn the name of the device given with
DBT_DEVICEATTACHED into the arguments I pass to the IOCTL? Is there a
way to more directly open that path with CreateFile? Is there a way to
parse that name into a series of structures for the IOCTL call I wish
to do, and would that be a stable solution?
Thanks in advance,
R0b0t1