Block the USB devices

I want to block some USB devices based on some condition when they are plugged in. For e.g., I might want to block mass storage device1 but allow mass storage device2. I took WDM 7.1 Toaster filter driver code as the base but facing some roadblocks. I am giving below the things that I tried.

I took upper class filter driver code from Toaster example and modified it. I wrote a completion callback (CatchIrpRoutine) for IRP_MN_QUERY_DEVICE_RELATIONS and that gets hit when I plugin a USB device. I am able to identify the new device by adding a variable in the DeviceExtension member in Device Object structure (in FilterAddDevice function). I deleted the new device in the completion callback by calling IoDeleteDevice and that resulted in BSOD.

I have 2 inter-related questions:

  1. Can I block/detach a device during the handling of IRP_MN_QUERY_DEVICE_RELATIONS or during the completion callback?
  2. Is there any other hook point other than IRP_MN_QUERY_DEVICE_RELATIONS that can be used for blocking/detaching?

//filter.h
typedef struct _DEVICE_EXTENSION
{

BOOLEAN isNew;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;

//filter.c
NTSTATUS FilterDispatchPnp (PDEVICE_OBJECT DeviceObject, PIRP Irp) {

switch (irpStack->MinorFunction) {
case IRP_MN_QUERY_DEVICE_RELATIONS:
KeInitializeEvent(&event, NotificationEvent, FALSE);
IoCopyCurrentIrpStackLocationToNext(Irp);
IoSetCompletionRoutine(Irp, CatchIrpRoutine, &event, TRUE, TRUE, TRUE);

break;

}
}

NTSTATUS CatchIrpRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,IN PKEVENT Event) {
if (Irp->PendingReturned)
KeSetEvent(Event, IO_NO_INCREMENT, FALSE);

PDEVICE_OBJECT tmpObject = DeviceObject;
while (tmpObject) {
PDEVICE_EXTENSION deviceExtension = (PDEVICE_EXTENSION)tmpObject->DeviceExtension;
if (deviceExtension->isNew)
deviceExtension->isNew = FALSE;

tmpObject = tmpObject->NextDevice;
}
return STATUS_MORE_PROCESSING_REQUIRED;
}

NTSTATUS FilterAddDevice(__in PDRIVER_OBJECT DriverObject, __in PDEVICE_OBJECT PhysicalDeviceObject) {

deviceExtension->isNew = TRUE;
deviceExtension->Common.Type = DEVICE_TYPE_FIDO;

}