how to get port number in USB function driver

Hi,

I have multiple identical USB 2.0 devices, which are simultaneously connected
to my PC. My driver needs to name each of those devices based on their physical
location; i.e. I need a uniform way of distinguishing between different
instances of my device that does not change so long as the user does not plug
the device into a different port.

I was thinking of using the port number for that, but I haven’t yet found a way
to figure it out. I know there is an interface exposed by the port driver that
allows me to get the port number but for that I need to create the device
manually (using the same interface).

Is that really the only way?`

Are there alternatives to achieve what I need?

Thanks,

Burk.

Dipl.-Ing. Burkhard Daniel Professional System Software Engineering
xxxxx@system-software.net http://system-software.net
fon/fax: +49-30-55153591 mobile: +49-179-5319489

Get the instance id of the device by sending an IRP_MN_QUERY_ID with
BusQueryInstanceID. Note that this won’t be helpful if your device has a
serial number since the instance ID will be the serial number in that case
no matter where the device is plugged.

Shahar

“Burkhard Daniel” wrote in message
news:xxxxx@ntdev…
> Hi,
>
> I have multiple identical USB 2.0 devices, which are simultaneously
> connected to my PC. My driver needs to name each of those devices based on
> their physical location; i.e. I need a uniform way of distinguishing
> between different instances of my device that does not change so long as
> the user does not plug the device into a different port.
>
> I was thinking of using the port number for that, but I haven’t yet found
> a way to figure it out. I know there is an interface exposed by the port
> driver that allows me to get the port number but for that I need to create
> the device manually (using the same interface).
>
> Is that really the only way?`
>
> Are there alternatives to achieve what I need?
>
>
> Thanks,
>
> Burk.
> –
> Dipl.-Ing. Burkhard Daniel Professional System Software Engineering
> xxxxx@system-software.net http://system-software.net
> fon/fax: +49-30-55153591 mobile: +49-179-5319489
>

Normal USB devices have unique ID burned into them. PnP will automatically
use this ID to point to device registry key, so, just use
IoOpenDeviceRegistryKey and the corresponding SetupDixxx user-mode function to
access this location.

If the device has no unique ID - you’re hosed, the user can re-plug it to
another port and render all your identification invalid.

So, no need in digging into the port numbers.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Burkhard Daniel”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, July 11, 2005 1:28 PM
Subject: [ntdev] how to get port number in USB function driver

> Hi,
>
> I have multiple identical USB 2.0 devices, which are simultaneously connected
> to my PC. My driver needs to name each of those devices based on their
physical
> location; i.e. I need a uniform way of distinguishing between different
> instances of my device that does not change so long as the user does not plug
> the device into a different port.
>
> I was thinking of using the port number for that, but I haven’t yet found a
way
> to figure it out. I know there is an interface exposed by the port driver
that
> allows me to get the port number but for that I need to create the device
> manually (using the same interface).
>
> Is that really the only way?`
>
> Are there alternatives to achieve what I need?
>
>
> Thanks,
>
> Burk.
> –
> Dipl.-Ing. Burkhard Daniel Professional System Software Engineering
> xxxxx@system-software.net http://system-software.net
> fon/fax: +49-30-55153591 mobile: +49-179-5319489
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

If your device does not have a serial number and you want unique IDs, I
would suggest a device coinstaller DLL that runs in user mode that
assigns the unique ID. It is much easier to manage from user mode. The
idea of a port number does not make much sense in USB unless you take
into account all of the downlevel hubs and ports that your device’s hub
is plugged into.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Monday, July 11, 2005 4:02 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] how to get port number in USB function driver

Normal USB devices have unique ID burned into them. PnP will
automatically
use this ID to point to device registry key, so, just use
IoOpenDeviceRegistryKey and the corresponding SetupDixxx user-mode
function to
access this location.

If the device has no unique ID - you’re hosed, the user can re-plug
it to
another port and render all your identification invalid.

So, no need in digging into the port numbers.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Burkhard Daniel”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, July 11, 2005 1:28 PM
Subject: [ntdev] how to get port number in USB function driver

> Hi,
>
> I have multiple identical USB 2.0 devices, which are simultaneously
connected
> to my PC. My driver needs to name each of those devices based on their
physical
> location; i.e. I need a uniform way of distinguishing between
different
> instances of my device that does not change so long as the user does
not plug
> the device into a different port.
>
> I was thinking of using the port number for that, but I haven’t yet
found a
way
> to figure it out. I know there is an interface exposed by the port
driver
that
> allows me to get the port number but for that I need to create the
device
> manually (using the same interface).
>
> Is that really the only way?`
>
> Are there alternatives to achieve what I need?
>
>
> Thanks,
>
> Burk.
> –
> Dipl.-Ing. Burkhard Daniel Professional System Software
Engineering
> xxxxx@system-software.net
http://system-software.net
> fon/fax: +49-30-55153591 mobile:
+49-179-5319489
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Actually we have a circumstance where we need to do something similar.
We have a set of hubs that are being used to configure devices in our
manufacturing process. It’s crucial that we display a status for each
device during this process and notify line personel when a device is
finished. We currently build the whole tree and then use knowledge of
the system to pick the parts we’re interested in. This has a few bad
implications, particularly when the devices are reset as we reflash
them.

If we have a preconfigured serial number in the device, this can cause
an unacceptable delay in connecting the devices during enumeration, so
we’re currently setting
HKLM\SYSTEM\Curr-entControlSet\Control\UsbFlags-\IgnoreHWSerNumVVVVPPPP
with our vid and pid. In our case, usually the serial number isn’t set
at this point in the manufacturing process anyway. We do however have
used devices coming through the line from time to time which will have a
valid serial number.

In the system that handles this, it’s required that we deal pretty much
only with the port. If you take a look at the WDM USBView sample you can
get an idea of how this works in user mode. This is essentially what
we’re doing, but there are complications based on slight differences
between USB 1.1 and 2.0. If you look at the example in one of the more
recent DDks, you will see what has to be done to accommodate this.

I’m not advocating the approach my predecessors have taken, but I
certainly understand the use case that drove them There. It certainly
seems to be a useful thing to be able to identify the location in the
USB tree that a given device is plugged into. In addition, I know a bit
about how this works from the user mode side, but I’m still figuring
things out from a driver perspective.

Any clarification would be useful for me also. Given the amount of
trouble we’ve had with this, I’m probably going to have to have a user
mode layer to hide this complexity from our automation programming guys.
It will need to provide port and hub information so that the end user
software can display what’s plugged in where.

Sam Robinson

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Doron Holan
Sent: Monday, July 11, 2005 1:07 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] how to get port number in USB function driver

If your device does not have a serial number and you want unique IDs, I
would suggest a device coinstaller DLL that runs in user mode that
assigns the unique ID. It is much easier to manage from user mode. The
idea of a port number does not make much sense in USB unless you take
into account all of the downlevel hubs and ports that your device’s hub
is plugged into.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Monday, July 11, 2005 4:02 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] how to get port number in USB function driver

Normal USB devices have unique ID burned into them. PnP will
Automatically use this ID to point to device registry key, so, just use
IoOpenDeviceRegistryKey and the corresponding SetupDixxx user-mode
function to access this location.

If the device has no unique ID - you’re hosed, the user can re-plug
it to another port and render all your identification invalid.

So, no need in digging into the port numbers.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Burkhard Daniel”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, July 11, 2005 1:28 PM
Subject: [ntdev] how to get port number in USB function driver

> Hi,
>
> I have multiple identical USB 2.0 devices, which are
> simultaneously connected to my PC. My driver needs to
> name each of those devices based on their physical
> location; i.e. I need a uniform way of distinguishing
> between different instances of my device that does not
> change so long as the user does not plug the device
> into a different port.
>
> I was thinking of using the port number for that, but
> I haven’t yet found a way to figure it out. I know
> there is an interface exposed by the port driver that
> allows me to get the port number but for that I need
> to create the Device manually (using the same interface).
>
> Is that really the only way?`
>
> Are there alternatives to achieve what I need?
>
>

–Appended by Panasonic Mobile Communications
Development Corporation of U.S.A.-----This e-mail
and any attachments may contain information that is
confidential, proprietary, privileged or otherwise
protected by law. The information is solely intended
for the named addressee (or a person responsible for
delivering it to the addressee). If you are not the
intended recipient of this message, you are not
authorized to read, print, retain, copy or
disseminate this message or any part of it. If you
have received this e-mail in error, please notify
the sender immediately by return e-mail and delete
it from your computer.

Ports under each hub are numbered from 0 to count-1. And all ports are mapped to an alias port under EHCI with most possible a different no. A typical picture looks as below for a system with six ports supporting USB 2.0.
UHCI 0:
Root Hub
Port 0
Port 1
UHCI 1:
Root Hub
Port 0
Port 1
UHCI 2
Root Hub
Port 0
Port 1
EHCI
Root Hub
Port 0
Port 1

Port 5

Best Regards
Raymond Zhang

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Burkhard Daniel
Sent: 2005??7??11?? 17:29
To: Windows System Software Devs Interest List
Subject: [ntdev] how to get port number in USB function driver

Hi,

I have multiple identical USB 2.0 devices, which are simultaneously connected
to my PC. My driver needs to name each of those devices based on their physical
location; i.e. I need a uniform way of distinguishing between different
instances of my device that does not change so long as the user does not plug
the device into a different port.

I was thinking of using the port number for that, but I haven’t yet found a way
to figure it out. I know there is an interface exposed by the port driver that
allows me to get the port number but for that I need to create the device
manually (using the same interface).

Is that really the only way?`

Are there alternatives to achieve what I need?

Thanks,

Burk.

Dipl.-Ing. Burkhard Daniel Professional System Software Engineering
xxxxx@system-software.net http://system-software.net
fon/fax: +49-30-55153591 mobile: +49-179-5319489


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@intel.com
To unsubscribe send a blank email to xxxxx@lists.osr.com