From: sam d sam on
My application needs to know to which motherboard USB port a USB drive is
connected. Is it correct that each motherboard USB port is always assigned
the same Enhanced USB Controller port number?
If so, how to get the Enhanced USB Controller port number for a plugged USB
high speed device?
I was hoping to get a child device for each connection index from the
Usbview example, but so far do not know how to do it.
Is there a Windows (XP) API allowing to do this?
If no APIs in user mode, how can it be done in kernel mode from a filter
driver?
From: Tim Roberts on
sam d <sam d(a)discussions.microsoft.com> wrote:
>
>My application needs to know to which motherboard USB port a USB drive is
>connected.

I doubt that. Why do you think you need this info?

Personally, I've never seen an OEM computer that had its motherboard USB
ports numbered where I could see them. Without that, what good does the
port number do you?

>Is it correct that each motherboard USB port is always assigned
>the same Enhanced USB Controller port number?

Usually.

>If so, how to get the Enhanced USB Controller port number for a plugged USB
>high speed device?
>I was hoping to get a child device for each connection index from the
>Usbview example, but so far do not know how to do it.
>Is there a Windows (XP) API allowing to do this?
>If no APIs in user mode, how can it be done in kernel mode from a filter
>driver?

Usbview is the only example you're going to find for this. A kernel driver
really has no way to learn this information about it device, because it
isn't useful.
--
Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: Maxim S. Shatskih on
> My application needs to know to which motherboard USB port a USB drive is
> connected.

Usually, there is no need in this (unless for a very specific requirements like emulating the XBox's USB port numbering on a Windows PC).

USB port numbering is too volatile a thing. First, you usually cannot match the number to the actual plug on the motherboard/case. Second, MS's USB stack does not expose USB port numbers (except some side IOCTLs), and using these numbers is not a recommended way of USB use in Windows.

One of the reasons is that MS is going away from the scheme of device numbering by consecutive integers, like Disk1 Disk2 Disk3 etc. The reasons are, for instance, that these numbers can hardly be invented without holes in them, and also can hardly be persistent in a PnP environment where devices do often plugged in and out.

For instance, the "storage device number" for a disk (which is in \\.\PhysicalDrive%d) is _no more persistent across boots_.

No wonder if any USB numbering is also non-persistent across boots.

>Is it correct that each motherboard USB port is always assigned
> the same Enhanced USB Controller port number?

I will not be surprised if this is not so, especially given the companion UHCI controller to each EHCI.

Also note that the mobo can have several HC instances in the south bridge. My Asus P5KC (1-year-old mobo with Intel P35 chipset) has 6 UHCI controllers and 2 EHCI ones.

Each controller has its own root hub, and thus its own port numbering.

> If no APIs in user mode, how can it be done in kernel mode from a filter
> driver?

Yes, and the filter should be very, very complex.

You can look at IOCTL_USB_xxx calls though. Probably they will be able to return you the downstream port number to which the device is attached.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: Maxim S. Shatskih on
> Personally, I've never seen an OEM computer that had its motherboard USB
> ports numbered where I could see them. Without that, what good does the
> port number do you?

+1

(to continue the speech on "USB port numbers are evil" started in my previous post)

If one has some unique device, it is absolutely a bad idea if the functionality of this device _will depend upon the particular USB plug_ where it is plugged in. This will disturb the user experience a lot. All USB plugs on the computer do behave for the users as if they are electrically parallel.

Even if one has 2 identical devices, using port numbers is evil, since this will require to actually know what plug on the computer's or laptop's case corresponds to what number. With 2 identical devices, the trial-and-error way of initiating some operation on one of them and then on another one is the best way. The "operation" can be as simple as the LED blinking.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: Uwe Sieber on
sam d wrote:
> My application needs to know to which motherboard USB port a USB drive is
> connected. Is it correct that each motherboard USB port is always assigned
> the same Enhanced USB Controller port number?
> If so, how to get the Enhanced USB Controller port number for a plugged USB
> high speed device?
> I was hoping to get a child device for each connection index from the
> Usbview example, but so far do not know how to do it.
> Is there a Windows (XP) API allowing to do this?

All USB devices have full parent/child realations up
to their USB root hub (and further up to the root
but we don't need this here). If you enumerate with
GUID_DEVINTERFACE_USB_DEVICE for the devices and
with GUID_DEVINTERFACE_USB_HUB for the hubs and
root hubs, analyze their parent and child devices
for builing a device tree and getting hub's and
device's dwAddress (SPDRP_ADDRESS or CM_DRP_ADDRESS),
then you can put together a "port number". I've done
this in my "USB Drive Letter Manager" beause many
users asked for drive letters depending on the used
USB port. The included ListUsbDrives shows the "USB
port name" in X-Y-Z style.
In the beta version there is and old and a new
number which is usually equal. Old is USBview
style, new is CM_DRP_ADDRESS style as pointed
out by Philip Ries [MSFT] in the thread "How
to use devices found with Usbview" (25 Aug 2009).
This is much faster and simpler than the USB API.
http://www.uwe-sieber.de/files/usbdlm_beta.zip

But USB root hubs have no fixed number, it may
change when USB controllers are added or removed.


Uwe