Filtering USB

I’ve tried modifying the toaster filter inf that you pointed out Tim, but I still can’t get my driver to install. Should I be right-clicking the inf file and clicking ‘Install’, as with other filter drivers?

Alternatively, you can write a simple user-mode application to install
this without an INF, using the SetupDi APIs to write the UpperFilters
key. Our friends at Microsoft don’t like that solution, because among
other things it means you can’t play with the “Rollback” option, but it
is simple.

  • I quite like the sound of this option, as I will eventually be writing an application to install the driver, when I get round to it. I’m not too concerned about not being able to use the rollback option, as my driver is going to primarily be installed on a VMWare machine, so I can just revert to a previous system snapshot if things go pear-shaped :slight_smile:

I’ve had a look at the msdn docs on device installation funcs. (at http://msdn.microsoft.com/en-us/library/ms791137.aspx), and there looks to be a huge number of different functions. Could you please advise me as to which one(s) to use to write the UpperFilters key?

Thanks,

Al

xxxxx@live.co.uk wrote:

I’ve tried modifying the toaster filter inf that you pointed out Tim, but I still can’t get my driver to install. Should I be right-clicking the inf file and clicking ‘Install’, as with other filter drivers?

What other filter drivers are installed by clicking “Install”?

  • I quite like the sound of this option, as I will eventually be writing an application to install the driver, when I get round to it. I’m not too concerned about not being able to use the rollback option, as my driver is going to primarily be installed on a VMWare machine, so I can just revert to a previous system snapshot if things go pear-shaped :slight_smile:

I’ve had a look at the msdn docs on device installation funcs. (at http://msdn.microsoft.com/en-us/library/ms791137.aspx), and there looks to be a huge number of different functions. Could you please advise me as to which one(s) to use to write the UpperFilters key?

The greatest resource in understanding the SetupDi APIs is the source
code for the “devcon” utility in the WDK.

As a hint, you’ll use the SetupDiGet* and SetupDiEnum* functions to get
an SP_DEVINFO_DATA for the device you want to modify. The exact Get and
Enum functions you need depends on how you’ll find your device. Once
you have an SP_DEVINFO_DATA, you can use
SetupDiGetDeviceRegistryProperty and SetupDiSetDeviceRegistryProperty to
modify the UpperFilters value.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Class filter drivers can be installed by right clicking the inf file and
clicking 'Install". The WDK has an example of this in
src\setup\infs\clasfilt.

I have a class filter driver that can be installed this way.

Bill Wandel

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com]
On Behalf Of Tim Roberts
Sent: Friday, October 17, 2008 1:13 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Filtering USB

xxxxx@live.co.uk wrote:

I’ve tried modifying the toaster filter inf that you pointed out Tim, but
I still can’t get my driver to install. Should I be right-clicking the inf
file and clicking ‘Install’, as with other filter drivers?

What other filter drivers are installed by clicking “Install”?

  • I quite like the sound of this option, as I will eventually be
    writing an application to install the driver, when I get round to it.
    I’m not too concerned about not being able to use the rollback option,
    as my driver is going to primarily be installed on a VMWare machine,
    so I can just revert to a previous system snapshot if things go
    pear-shaped :slight_smile:

I’ve had a look at the msdn docs on device installation funcs. (at
http://msdn.microsoft.com/en-us/library/ms791137.aspx), and there looks to
be a huge number of different functions. Could you please advise me as to
which one(s) to use to write the UpperFilters key?

The greatest resource in understanding the SetupDi APIs is the source code
for the “devcon” utility in the WDK.

As a hint, you’ll use the SetupDiGet* and SetupDiEnum* functions to get an
SP_DEVINFO_DATA for the device you want to modify. The exact Get and Enum
functions you need depends on how you’ll find your device. Once you have an
SP_DEVINFO_DATA, you can use SetupDiGetDeviceRegistryProperty and
SetupDiSetDeviceRegistryProperty to modify the UpperFilters value.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


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

Hi guys,

I’ve had a go at getting the USB devices and then enumerating them. I’ve used SetupDiGetClassDevs() to get the USB class devices, and then SetupDiEnumDeviceInfo() to enumerate them. While SetupDiGetClassDevs() completes fine (doesn’t return INVALID_HANDLE_VALUE), the following call to SetupDiEnumDeviceInfo() doesn’t find any devices, as ERROR_NO_MORE_ITEMS is returned from a GetLastError() call. I firstly tried getting the class dev’s for the USB controllers class (GUID_DEVCLASS_USB), but now I’ve also tried GUID_DEVCLASS_DISKDRIVE and GUID_DEVCLASS_VOLUME (seeing as I’m trying to find my USB mass storage device) with the same result of no devices being returned. I’ve done quite a bit of reading around this, and followed what I’ve seen in the devcon source, and also this article at MS: http://support.microsoft.com/kb/259695. I’m pretty sure I’m close to what’s needed to achieve this, but I can’t understand why there are no devices being found with the SetupDiEnumDeviceInfo() call. Could anyone help point out which class is the correct one for me to be trying to get the class devices? I’ve included my source for what I’m trying below.

Al

SP_DEVINFO_DATA rdxdevinfo;

HDEVINFO hDevInfo = SetupDiGetClassDevs(
&GUID_DEVCLASS_USB, /* CONST GUID * ClassGuid - USB class GUID */
NULL, /* PCTSTR Enumerator */
NULL, /* HWND hwndParent */
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE /* DWORD Flags */
);

if (hDevInfo == INVALID_HANDLE_VALUE)
{
MessageBox(“INVALID_HANDLE_VALUE”);
return;
}

DWORD devIndex = 0;
rdxdevinfo.cbSize = sizeof(rdxdevinfo);

for(devIndex=0;SetupDiEnumDeviceInfo(hDevInfo,devIndex,&rdxdevinfo);devIndex++) {
MessageBox(“Found something.”);
}

if (devIndex == 0)
{
DWORD errnum = GetLastError();

if(errnum = ERROR_NO_MORE_ITEMS)
{
MessageBox(“No more items found.”);
} else {
char msg[32];
sprintf(msg,“Error: %X”,errnum);
MessageBox(msg);
}
}

SetupDiDestroyDeviceInfoList(hDevInfo);

A device class guid != device interface class guid. Device class guids are used in the INF, this is the class of the device as displayed in device manager. A device interface guid is the io contract to the device. remove DIGCF_INTERFACEDEVICE from the call and you will get the instances of the device class

d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@live.co.uk
Sent: Monday, October 20, 2008 11:34 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Filtering USB

Hi guys,

I’ve had a go at getting the USB devices and then enumerating them. I’ve used SetupDiGetClassDevs() to get the USB class devices, and then SetupDiEnumDeviceInfo() to enumerate them. While SetupDiGetClassDevs() completes fine (doesn’t return INVALID_HANDLE_VALUE), the following call to SetupDiEnumDeviceInfo() doesn’t find any devices, as ERROR_NO_MORE_ITEMS is returned from a GetLastError() call. I firstly tried getting the class dev’s for the USB controllers class (GUID_DEVCLASS_USB), but now I’ve also tried GUID_DEVCLASS_DISKDRIVE and GUID_DEVCLASS_VOLUME (seeing as I’m trying to find my USB mass storage device) with the same result of no devices being returned. I’ve done quite a bit of reading around this, and followed what I’ve seen in the devcon source, and also this article at MS: http://support.microsoft.com/kb/259695. I’m pretty sure I’m close to what’s needed to achieve this, but I can’t understand why there are no devices being found with the SetupDiEnumDeviceInfo() call. Could anyone help point out which class is the correct one for me to be trying to get the class devices? I’ve included my source for what I’m trying below.

Al

SP_DEVINFO_DATA rdxdevinfo;

HDEVINFO hDevInfo = SetupDiGetClassDevs(
&GUID_DEVCLASS_USB, /* CONST GUID * ClassGuid - USB class GUID */
NULL, /* PCTSTR Enumerator */
NULL, /* HWND hwndParent */
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE /* DWORD Flags */
);

if (hDevInfo == INVALID_HANDLE_VALUE)
{
MessageBox(“INVALID_HANDLE_VALUE”);
return;
}

DWORD devIndex = 0;
rdxdevinfo.cbSize = sizeof(rdxdevinfo);

for(devIndex=0;SetupDiEnumDeviceInfo(hDevInfo,devIndex,&rdxdevinfo);devIndex++) {
MessageBox(“Found something.”);
}

if (devIndex == 0)
{
DWORD errnum = GetLastError();

if(errnum = ERROR_NO_MORE_ITEMS)
{
MessageBox(“No more items found.”);
} else {
char msg[32];
sprintf(msg,“Error: %X”,errnum);
MessageBox(msg);
}
}

SetupDiDestroyDeviceInfoList(hDevInfo);


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

Ah ha! Excellent, thanks Doron :slight_smile: I understand that now, thought it would be something pretty simple.

Al

I’ve got one last small issue; I’ve set up the driver to be a lowerfilter on the USB device being enumerated by USBSTOR, so I can see SRB’s being sent to the device. When you plug the device in, I know that there is an inquiry command sent to the device to fetch standard inquiry data, but I’m not able to see this command. I can however see all other traffic (TUR’s, writes, reads etc) through my dispatch point for IRP_MJ_SCSI’s. Is there a reason why I can’t see the request for inquiry data being sent? I also thought I would be able to see inquiry data requests with the IOCTL_SCSI_GET_INQUIRY_DATA io control code, but no luck there either.

Al

Are you filtering a device which is enumerated by USBSTOR (e.g. the instance id is USBSTOR.….…) or a device controlled by usbstor as an FDO (e.g. USB.….…). you can find the instance path by breaking into the debugger and running !devstack .

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@live.co.uk
Sent: Tuesday, October 21, 2008 1:33 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Filtering USB

I’ve got one last small issue; I’ve set up the driver to be a lowerfilter on the USB device being enumerated by USBSTOR, so I can see SRB’s being sent to the device. When you plug the device in, I know that there is an inquiry command sent to the device to fetch standard inquiry data, but I’m not able to see this command. I can however see all other traffic (TUR’s, writes, reads etc) through my dispatch point for IRP_MJ_SCSI’s. Is there a reason why I can’t see the request for inquiry data being sent? I also thought I would be able to see inquiry data requests with the IOCTL_SCSI_GET_INQUIRY_DATA io control code, but no luck there either.

Al


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’m filtering the device enumerated by USBSTOR, apologies for not making that clear.

Al

My guess is that the inquiry data you want to filter is used to give the USBSTOR PDO an identity (hw IDs, instance ID, etc). this is most likely sent by the USBSTOR FDO during its init. by the time you are attached to the usbstor PDO, it is too late

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@live.co.uk
Sent: Wednesday, October 22, 2008 3:03 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Filtering USB

I’m filtering the device enumerated by USBSTOR, apologies for not making that clear.

Al


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