Mark Shnaider wrote:
I am writing a USB upper filter driver.
Upper filter driver to what, specifically? To USB hubs?
In IRP_MN_QUERY_DEVICE_RELATIONS
I use IoSetCompletionRoutine and in competion routine
get pointer (PDEVICE_OBJECT) to new object device(pNewDev)
Now, do you understand that the response to a BusRelations request
includes ALL of the child devices of that bus? It doesn’t just include
new devices. PnP figures out which devices are new and which are
dropped by comparing this list to the previous answer.
In IRP_MJ_POWER
By using function IoGetDeviceAttachmentBaseRef(pNewDev),
IoGetDeviceProperty ()
I can get PID and VID of the inserted device.
You shouldn’t need IoGetDeviceAttachmentBaseRef. What you are receiving
here is a PDO – it already is the bottom of the stack. It’s a little
dangerous to extract the VID and PID from the hardware ID; it’s true
that the rules for forming user Hardware IDs have never changed, but the
format is not guaranteed. Also, some of the USB emulators (like
USB-over-Ethernet) don’t follow the rules exactly. It may be more
reliable to go read the Device Descriptor.
Now I want to disable the device (or remove) for predefined VID and
PID.
I did not succeeded doing it.
I tried to do it in three different ways:
- IoDeleteDevice.
This will cause a blue screen, because you don’t own the device object.
The device object is owned by the hub, and he still thinks the object is
alive.
- InvalidateDeviceRelations.,
This won’t do any good, because the hub still thinks the device is alive
and working.
- IoBuildSynchronousFsdReques(IRP_MJ_PNP ) MinorFunction =
IRP_MN_REMOVE_DEVICE
IoCallDriver(pNewDev, irp );
IoCallDriver return STATUS_SUCCESS.
You can’t do that because you are not PnP. PnP requests have to be fed
in from the top of the stack and managed properly. Plus, as soon as you
remove the device, the bus is going to notice that it’s back again, and
will recreate it.
But device is not removed and I can still see the smart card reader in
the device manager.
The Device manger can disable device.
How can I disable (remove) device in filter driver?
You can’t. You just aren’t in the right position to force that kind of
a change. It is the responsibility of the driver to expose a device’s
functions, not to establish policy about what’s allowed and what is not.
The disable/enable status is a user-mode thing. You could write a
Windows service that uses RegisterDeviceNotification to watch for new
USB devices to arrive. When you see one arrive, you can use the SetupDi
APIs to disable that device.
By the way, this is exactly the kind of thing that can be controlled by
Windows group policy. There are tens of thousands of options with very
fine-grained control over what operations are allowed and what are not.
You might pick up one of the books on group policy.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.