Determining the chain of parent devices connected to a USB mass storage device

335 views Asked by At

I'm developing a WDM filter driver that attaches to USB Mass Storage devices. I need to be able to navigate the chain of parent and grandparent devices (i.e. hubs) and check the vendor and product IDs.

Using IoGetDeviceAttachmentBaseRef(), I can access the PDO of the mass storage device, but I've hit the bottom of the USB Mass Storage device stack. So now I need to access the parent USB hub stack, but I'm not sure how that can be done.

If you loop through the NextDevice list in the PDO of the mass storage device, you can see the PDO of the hub listed, but doing it that way doesn't tell me the hub is a parent/grandparent of the mass storage device.

1

There are 1 answers

0
Martin Drab On

You should be able to easily attach as a filter to all USB devices since they all belong to a single device setup class (USB). Then, watch for IRP_MJ_PNP:IRP_MN_QUERY_DEVICE_RELATIONS with RelationType set to BusRelations to be informed about parent-child relationships between the devices.

If you loop through the NextDevice list in the PDO of the mass storage device, you can see the PDO of the hub listed, but doing it that way doesn't tell me the hub is a parent/grandparent of the mass storage device.

It is safer to use IoEnumerateDeviceObjectList to walk the NextDevice list.