Filter Drivers – part2


In a previous post I introduced the stream interface filter driver. How do you implement it?
The driver you want to filter must have a registry entry which tells the Device Manager which filter to use.
Let’s say you want to filter the serial driver, you’ll have a registry which looks like (notice the GUID):

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Serial2]
 "Filter"= "{CC5195AA-BA49-48a0-BE17-DF6D1B0173FF}"

[HKEY_LOCAL_MACHINE\Drivers\Filters\{CC5195AA-BA49-48a0-BE17-DF6D1B0173FF}\MyFilter]
 "Dll"="MyFilter.dll"
 "InitEntry"="MyFilterInit"
 "Order"=dword:0

The filter is a DLL that must export a ‘init’ function with the same name as declared in the registry. The function prototype is

typedef PDRIVER_FILTER  (*pInitEntry) (LPCTSTR lpcFilterRegistryPath,
LPCTSTR pDeviceRegistryPath, PDRIVER_FILTER pNextFilter );

 

  • lpcFilterRegistryPath is the registry key of the filter
  • lpDeviceRegistryPath is the registry key of the filtered driver
  • pNextFilter is a pointer to a structure which contains the filtered driver entry points

The function returns a a pointer to a structure (DRIVER_FILTER) which contains the filter driver entry points: once you have setup the filter the device manager will call the filter driver entry points instead of the driver ones.

You have to fill the returned structure appropriately so that every entry point of the filtered driver has a correspondent not NULL entry in the filter, otherwise the device manager won’t load neither the filter nor the driver.
Those entry points have a prototype which is similar to the stream interface ones (XXX_Open, etc.) with an additional parameter which is a pointer to the
DRIVER_FILTER returned by the filter driver in its init function.

You can have more than one filter driver in the same stack, loaded by the device manager according to the “Order” registry value (similarly to
‘normal’ drivers); if you add, as an example:

[HKEY_LOCAL_MACHINE\Drivers\Filters\{CC5195AA-BA49-48a0-BE17-DF6D1B0173FF}\MyFilter2]
 "Dll"="MyFilter2.dll"
 "InitEntry"="MyFilterInit"
 "Order"=dword:1

the stack will look like: Device Manager -> MyFilter2.dll -> MyFilter.dll -> com16550.dll
The pNextFilter argument to the init function of MyFilter2 will represent the entry points of the lower filter (MyFilter) rather than those belonging to com16550.dll.

Advertisements
This entry was posted in Windows Embedded Compact and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s