Question about Device Instance ID and upper filter

Hello guys,

During the AddDevice phase, my upper filter uses IRP_MN_QUERY_ID with “BusQueryInstanceID” and “BusQueryDeviceID” to get the device and device instance id. This usually works, but sometimes the string differs from the one that I can see with device manager UI (devmgmt.msc).

For example, for a Bluetooth radio my filter shows the string “USB\Vid_0a12&Pid_0001” for device ID and “2” for instance ID, but devmgmt shows “USB\VID0a12&PID_001\6&22194588&0&2”.

I know that there are differences depending on whether the device has an UniqueID or not, but this is not the case. I don’t think that “2” it’s the right string. When this thing happens, the device can’t start and devmgmt show the yellow mark on the device.

It doesn’t happen with disk drives, so maybe it’s something to do with querying the device during the AddDevice phase? I believe that it’s safe to do QUERY_ID at that stage, isn’t it?

Thanks guys.

> During the AddDevice phase, my upper filter uses IRP_MN_QUERY_ID with “BusQueryInstanceID”

and “BusQueryDeviceID” to get the device and device instance id.

Use IoGetDeviceProperty instead for device ID, and why do you need the instance ID?


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Because a need to uniquely identify the device to avoid mistakes when, for example, someone plugs two identical USB pen drives. Is the InstanceID the way to go?

Once you unique identify the device, what are you going to do? Don’t worry about identity, let the OS take care of that. If you need to store per instance data, use the device’s devnode and store something under it

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.es
Sent: Sunday, August 22, 2010 11:11 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Question about Device Instance ID and upper filter

Because a need to uniquely identify the device to avoid mistakes when, for example, someone plugs two identical USB pen drives. Is the InstanceID the way to go?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I think it’s enough to get device ID. Instance ID is not used to distinguish different devices, but differenct port in host machine.

Because a need to uniquely identify the device to avoid mistakes when, for example, someone plugs two identical USB pen drives. Is the InstanceID the way to go?


NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

I have two USB pen drives, same brand, same capacity.
I plug both of them, and devmgmt.msc shows the same properties for both, except for the device instance ID. I want to apply different access policies to them, so I need some way to make a difference.

So, I guess that instance id is the best way, for an upper class filter, to differentiate between devices, isn’t it?

I think you also can use device serial number as well

On Mon, Aug 23, 2010 at 12:05 PM, wrote:

> I have two USB pen drives, same brand, same capacity.
> I plug both of them, and devmgmt.msc shows the same properties for both,
> except for the device instance ID. I want to apply different access policies
> to them, so I need some way to make a difference.
>
> So, I guess that instance id is the best way, for an upper class filter, to
> differentiate between devices, isn’t it?
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Prageeth Madhushanka
Sri Lanka

You can’t get the whole instance id path in the kernel. Store your policy in the devnode. If you have a helper app, it can open the same devnode key.

d

dent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@yahoo.es
Sent: August 22, 2010 11:35 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Question about Device Instance ID and upper filter

I have two USB pen drives, same brand, same capacity.
I plug both of them, and devmgmt.msc shows the same properties for both, except for the device instance ID. I want to apply different access policies to them, so I need some way to make a difference.

So, I guess that instance id is the best way, for an upper class filter, to differentiate between devices, isn’t it?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Doron: By storing something in the devnode, you mean the registry key for the device?

Prageeth: I don’t know of a safe way of getting the device serial number, do you?

yes

d

dent from a phpne with no keynoard

-----Original Message-----
From: xxxxx@yahoo.es
Sent: August 22, 2010 11:58 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Question about Device Instance ID and upper filter

Doron: By storing something in the devnode, you mean the registry key for the device?

Prageeth: I don’t know of a safe way of getting the device serial number, do you?


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Ok guys, will try. Wish me luck :slight_smile:

You can get the serial number by using IOCTL code,
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION with USB_STRING_DESCRIPTOR
structure.

For this you need to follow several steps to find the port of
a connected usb device.

On Mon, Aug 23, 2010 at 12:28 PM, wrote:

> Doron: By storing something in the devnode, you mean the registry key for
> the device?
>
> Prageeth: I don’t know of a safe way of getting the device serial number,
> do you?

>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Prageeth Madhushanka
Sri Lanka

> Because a need to uniquely identify the device to avoid mistakes when, for example, someone plugs

two identical USB pen drives. Is the InstanceID the way to go?

It is already unique identified by your PDO and your device registry key.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

But Maxim can it be changed when you plug the same device next time. I read
some where that pnp device instance ids can be changed.
I am asking this to clarify my doubts.

Thanks.

On Mon, Aug 23, 2010 at 6:36 PM, Maxim S. Shatskih
wrote:

> > Because a need to uniquely identify the device to avoid mistakes when,
> for example, someone plugs
> >two identical USB pen drives. Is the InstanceID the way to go?
>
> It is already unique identified by your PDO and your device registry key.
>
> –
> Maxim S. Shatskih
> Windows DDK MVP
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Prageeth Madhushanka
Sri Lanka

>But Maxim can it be changed when you plug the same device next time.

Only for USB devices without the unique ID in them.

For such devices, instance ID denotes the port to which the device connected, not the actual device hardware piece.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

You may also be able to use IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
http://msdn.microsoft.com/en-us/library/aa363411(VS.85).aspx

Prageeth Madhushanka wrote:

You can get the serial number by using IOCTL code,
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION with USB_STRING_DESCRIPTOR
structure.

For this you need to follow several steps to find the port of
a connected usb device.

On Mon, Aug 23, 2010 at 12:28 PM, > mailto:xxxxx> wrote:
>
> Doron: By storing something in the devnode, you mean the registry
> key for the device?
>
> Prageeth: I don’t know of a safe way of getting the device serial
> number, do you?

>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
>
>
> –
> Prageeth Madhushanka
> Sri Lanka
></mailto:xxxxx>