Bus filter drivers have been discussed here frequently, and the basic design
can be found.You implement a function filter driver for usb controllers and
hubs and attach pdo filters to enumerated child devices of those function
drivers. You can then look at the USB descriptors for the pdos in order to
find the iso endpoints you are interested in.
Unfortunately KMDF still does not support bus filters and there are no WDM
samples either.
Mark Roddy
On Fri, Jan 9, 2009 at 4:33 AM, wrote:
> Some more additional details about the issue.
>
> Our goal is scan all USB devices for ISO end point.
> We thought of writing Upper USB class filter, it was not able to detect all
> USB devices as these USB devices did not have any function driver under USB
> class. For ex USB TV Tuner card. This device has function driver only in
> Media class. Our filter was not loading on this and thus failed to scan the
> end points.
>
> Later we decided to modify our filter as bus filter. Now this driver acts
> as Bus filter for USB bus and thus sits on USBHUB.sys. We are using the PNP
> ID as USB\ROOT_HUB, USB\ROOT_HUB20, USB\Class_09. We used INCLUDE and NEEDS
> section from USPPort.inf. We achived some success except that this failed to
> detect the devices which are connected through the external hub.
>
> If the external hub is present during the installation of USB bus filter
> driver then it is able to detect the USB devices which are connected thorugh
> External hub. It fails to detect once plug in the external hub after
> installation of USB bus filter.
>
>
> —
> 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
>
Thanks Mark for qick reply
My question is not about the implementation of the bus filter. The issue is with installation of USB bus filter over USBHUB.sys of external hub.
I have a working USB bus filter and using INF file I could able to install it over USBHUB.sys.
I am using the PNPID as USB\ROOT_HUB, USB\ROOT_HUB20 and USB\Class_09 in the INF file.
WIth this INF file the USB bus filter installs properly on ROOT_HUB’s USBHUB.sys and Could bale to check the endpoints properly.
For external HUB it has the following behaviour.
- If the External hub is present during the USB bus filter driver installation.
- In this case USB bus filter driver instals over USBHUB.sys of external hub and it could able to see the USB device’s endpoints which is connected to the external hub.
- If the External HUB is plugged in after USB bus filter driver installation.
- In this case USB bus filter driver does not get installed over USBHUB.sys of external hub and hence it is unable to see the USB device’s endpoints which is connected to the external hub.
My problem is with case 2. I want my filter driver to be loaded on USBHUB.sys of external hub also with out doing a driver update on the external HUB.
Thanks
-Harsha
One way, which may be way over the top, would be to subscribe to USB hardware events, such as device arrived/removed events via RegisterDeviceNotification function, and if you get an event, using devcon as a source reference (sample in the WDK), ennumerate all USB devices, and any Class 9 devices found, add your driver as an upper filter to the new device.
The device will need to be restarted for the upper filter to be loaded. This should only need to be done once per hub per usb port.
Again as i said, it may be way over the top for what your trying to accomplish.
From your description you are not implement a bus pdo filter driver
correctly, otherwise you would detect the arrival of new hub devices and
attach pdo filters to them.
Mark Roddy
On Fri, Jan 9, 2009 at 8:09 AM, wrote:
> Thanks Mark for qick reply
>
> My question is not about the implementation of the bus filter. The issue is
> with installation of USB bus filter over USBHUB.sys of external hub.
>
> I have a working USB bus filter and using INF file I could able to install
> it over USBHUB.sys.
> I am using the PNPID as USB\ROOT_HUB, USB\ROOT_HUB20 and USB\Class_09 in
> the INF file.
> WIth this INF file the USB bus filter installs properly on ROOT_HUB’s
> USBHUB.sys and Could bale to check the endpoints properly.
> For external HUB it has the following behaviour.
> 1) If the External hub is present during the USB bus filter driver
> installation.
> - In this case USB bus filter driver instals over USBHUB.sys of external
> hub and it could able to see the USB device’s endpoints which is
> connected to the external hub.
>
>
> 2) If the External HUB is plugged in after USB bus filter driver
> installation.
> - In this case USB bus filter driver does not get installed over
> USBHUB.sys of external hub and hence it is unable to see the USB device’s
> endpoints which is connected to the external hub.
>
> My problem is with case 2. I want my filter driver to be loaded on
> USBHUB.sys of external hub also with out doing a driver update on the
> external HUB.
>
> Thanks
> -Harsha
>
>
>
> —
> 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 Mark
I can detect the arrival and removal of new hub devices at bus relations, but I can not detect the arrrival/removal of USB devices connected to that hubas there is no filter driver loaded for that HUB’s USBHUB.sys.
HI Ciaran,
I did not understand much from your explanation, however I will explore that option and will come back with few more questions.
Thanks
-Harhsa
Basically, for all external hubs (which load USBHUB.sys) you need to specify your driver as an upper filter. So by creating a windows service, you can register for hardware events in the service, which will notify the service upon a device being inserted/removed etc.
When you receive DBT_DEVICEARRIVAL, you will enumerate all USB devices, using the SetupDixxxx functions. For any Class 9 (Hubs) devices you find, if it does not have your driver defined as an upper filter, use SetupDiSetDeviceRegistryProperty to set the upper filter value for the device. Finally, for the change to take effect, you will need to restart the device. You will need administrator privileges to restart the device.
The Devcon sample in the WDK illustrates much of this, such as enumerating devices, stopping, starting and restarting devices.
HI Ciaran,
Can’t we do it from the kernel mode?
I think you are asking us to crate an exe and register a device arrival/removal notification event.
For our requirement I have to do it from kernel mode. my filter driver should also watch the USB devices connected through external hub along with USB devices connected to ROOT HUB.
Thanks
-Harsha
You need to be a bus filter for hubs as well as usb ports. The usb bus
filter is a bit complicated because of the topology.
Mark Roddy
On Mon, Jan 12, 2009 at 1:09 AM, wrote:
> Hi Mark
>
> I can detect the arrival and removal of new hub devices at bus relations,
> but I can not detect the arrrival/removal of USB devices connected to that
> hubas there is no filter driver loaded for that HUB’s USBHUB.sys.
>
> HI Ciaran,
>
> I did not understand much from your explanation, however I will explore
> that option and will come back with few more questions.
>
>
> Thanks
> -Harhsa
>
> —
> 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
>
While it may be possible to do it from kernel mode, a user mode service would be in my opinion much easier. The big problem you face is being able to add the relevant upper filter entry to the correct device key in the registry, and then restarting it.
It may be possible to cycle the port with the external hub attached using IOCTL_INTERNAL_USB_CYCLE_PORT.
However the user mode SetupDixxx api make enumerating and stop/starting/restarting USB devices relatively simple.
Hi Mark,
I have a working USB bus filter and using INF file I could able to install it
over USBHUB.sys.
I am using the PNPID as USB\ROOT_HUB, USB\ROOT_HUB20 and USB\Class_09 in the INF
file.
WIth this INF file the USB bus filter installs properly on ROOT_HUB’s USBHUB.sys
and Could able to check the endpoints of the USB devices properly.
For external HUB it has the following behaviour.
- If the External hub is present during the USB bus filter driver installation.
- In this case USB bus filter driver instals over USBHUB.sys of external hub
and it could able to see the USB device’s endpoints which is connected to the
external hub.
- If the External HUB is plugged in after USB bus filter driver installation.
- In this case USB bus filter driver does not get installed over USBHUB.sys of
external hub and hence it is unable to see the USB device’s endpoints which is
connected to the external hub.
My problem is with case 2. I want my filter driver to be loaded on USBHUB.sys of
external hub also with out doing a driver update on the external HUB.
Thanks
-Harsha
xxxxx@yahoo.com wrote:
Hi Mark,
I have a working USB bus filter and using INF file I could able to install it
over USBHUB.sys.
I am using the PNPID as USB\ROOT_HUB, USB\ROOT_HUB20 and USB\Class_09 in the INF
file.
This is wrong. You are installing DEVICE filters. As you have noticed,
such filters only glom on to the devices that are present when you do
the installation.
You need a CLASS filter. Such a filter will attached to any device of
the desired class right now, and any device that attaches in the
future. You should filter the USB class (GUID_DEVCLASS_USB,
36fc9e60…). Note, however, that because of poor understanding, there
are devices other than controllers and hubs that install in the USB
class. You should be able to identify hubs from the descriptors.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Tim Roberts wrote:
Note, however, that because of poor understanding, there are devices
other than controllers and hubs that install in the USB class.
Poor understanding? On whose part 
Poor docs and if I recall correctly failed examples that misused usb.
Tim’s point is correct though - the design of a functional usb bus filter
driver has to be a class filter and has to account for random usb devices
claiming to be in the USB class.
Mark Roddy
On Tue, Jan 13, 2009 at 4:19 PM, wrote:
> Tim Roberts wrote:
>
> > Note, however, that because of poor understanding, there are devices
> > other than controllers and hubs that install in the USB class.
>
> Poor understanding? On whose part 
>
> —
> 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
>
xxxxx@gmail.com wrote:
Tim Roberts wrote:
> Note, however, that because of poor understanding, there are devices
> other than controllers and hubs that install in the USB class.
>
Poor understanding? On whose part 
Poor understanding on the part of driver writers. When we first started
looking at the Device Manager layout, we thought “well, I’m making a USB
device, so I belong in the USB device class!” It wasn’t clear until
later that the USB device class was intended for “USB framework
devices”, like controllers and hubs.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Tim Roberts wrote:
It wasn’t clear until later that the USB device class was intended for
“USB framework devices”, like controllers and hubs.
So do you think the instances of usbstor and usbprint belong in there? Or not?
They should not have been placed there.
d
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Tuesday, January 13, 2009 3:34 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Re: Loading USB BUS upper filter on USBHUB.sys
Tim Roberts wrote:
It wasn’t clear until later that the USB device class was intended for
“USB framework devices”, like controllers and hubs.
So do you think the instances of usbstor and usbprint belong in there? Or not?
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
xxxxx@gmail.com wrote:
Tim Roberts wrote:
> It wasn’t clear until later that the USB device class was intended for
> “USB framework devices”, like controllers and hubs.
>
So do you think the instances of usbstor and usbprint belong in there? Or not?
I think it’s pretty clear they do not, but Microsoft made the rules…
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
HI Tim,
I atsrted off with Upper Class filter for USB class
It had follwoing issues.
1)The FIlter driver was loading on USBOHCI.sys, USBEHCI.sys, USBHub.sys, Any USB function drivers(ex:Mass storage device). I could able to check End points of mass stoarage device perfectly by loading Mass sotorage driver.However loading on USBIOhc.sys, USBEhci, USBHub.sys was unneccessary.
- It was unable scan endpoints the certain USB devices which come under Keyboard, Image, Mouse class(Ex: Keyboard, Mouse, Web ca, etc).
Because of above two we thought of implementing BUS filter which sits on USBHub.sys monitors all the USB devices. To some extenet we succeeded in this. WIth this we could able restrict our filter driver getting loaded on USBhub.sys only and we are able scan all the USB Devices for endpoint.
But we got stuck at below issue.
a) If the External hub is present during the USB bus filter driver installation.
- In this case USB bus filter driver instals over USBHUB.sys of external hub
and it could able to see the USB device’s endpoints which is connected to the
external hub.
b) If the External HUB is plugged in after USB bus filter driver installation.
- In this case USB bus filter driver does not get installed over USBHUB.sys of
external hub and hence it is unable to see the USB device’s endpoints which is
connected to the external hub.
Thanks
-Harsha
xxxxx@yahoo.com wrote:
I atsrted off with Upper Class filter for USB class
It had follwoing issues.
1)The FIlter driver was loading on USBOHCI.sys, USBEHCI.sys, USBHub.sys, Any USB function drivers(ex:Mass storage device). I could able to check End points of mass stoarage device perfectly by loading Mass sotorage driver.However loading on USBIOhc.sys, USBEhci, USBHub.sys was unneccessary.
- It was unable scan endpoints the certain USB devices which come under Keyboard, Image, Mouse class(Ex: Keyboard, Mouse, Web ca, etc).
Based on your description, I’m not surprised. If you are an UPPER
filter to usbstor.sys or usbhid.sys, then of course you can’t send
URBs. You are sitting on the function side of the driver; for
usbstor.sys, you’re on the storage side. You would need to use storage
commands. For usbhid.sys, you’re on the HID side, not the USB side.
You need to be BELOW usbhid.sys and usbstor.sys, and ABOVE usbhub.sys.
Thus, you want to be an upper filter to usbhub.sys. That puts you on
the USB side of the functional drivers, where you can send URBs.
a) If the External hub is present during the USB bus filter driver installation.
- In this case USB bus filter driver instals over USBHUB.sys of external hub
and it could able to see the USB device’s endpoints which is connected to the
external hub.
b) If the External HUB is plugged in after USB bus filter driver installation.
- In this case USB bus filter driver does not get installed over USBHUB.sys of
external hub and hence it is unable to see the USB device’s endpoints which is
connected to the external hub.
This sounds like you have made a DEVICE upper filter for usbhub.sys, not
a CLASS upper filter for USB-class devices.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Yes you would load on the usbport devices - and then you need to understand
that they are port devices and not bother with actively filtering at that
level. Instead, actively filter at the usbhub level. UsbStor does load,
unfortunately, as a usb class device, so you will, as mentioned perviously,
have to work around these sorts of USB devices that put themselves in the
usb class as well. Only actively filter at the hub level. As I have
mentioned, a functional usb bus filter driver that can dynamically attach to
all usbports and hubs is complicated.
Your original problem statement was your inability to act as a bus filter
for dynamically inserted usb hub devices. The solution that has been put
forward here that works is to be a usb class filter driver. That doesn’t
mean that it is trivial to implement, it means that it can be implemented
and it works and it resolves the problem you started with here.
Mark Roddy
On Thu, Jan 15, 2009 at 3:44 AM, wrote:
> HI Tim,
>
> I atsrted off with Upper Class filter for USB class
> It had follwoing issues.
>
> 1)The FIlter driver was loading on USBOHCI.sys, USBEHCI.sys, USBHub.sys,
> Any USB function drivers(ex:Mass storage device). I could able to check End
> points of mass stoarage device perfectly by loading Mass sotorage
> driver.However loading on USBIOhc.sys, USBEhci, USBHub.sys was unneccessary.
>
> 2) It was unable scan endpoints the certain USB devices which come under
> Keyboard, Image, Mouse class(Ex: Keyboard, Mouse, Web ca, etc).
>
> Because of above two we thought of implementing BUS filter which sits on
> USBHub.sys monitors all the USB devices. To some extenet we succeeded in
> this. WIth this we could able restrict our filter driver getting loaded on
> USBhub.sys only and we are able scan all the USB Devices for endpoint.
> But we got stuck at below issue.
>
> a) If the External hub is present during the USB bus filter
> driver installation.
> - In this case USB bus filter driver instals over USBHUB.sys
> of external hub
> and it could able to see the USB device’s endpoints which is
> connected to the
> external hub.
>
>
> b) If the External HUB is plugged in after USB bus filter
> driver installation.
> - In this case USB bus filter driver does not get installed
> over USBHUB.sys of
> external hub and hence it is unable to see the USB device’s
> endpoints which is
> connected to the external hub.
>
> Thanks
> -Harsha
>
> —
> 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
>