I’m working on a lower level filter driver for test purposes which requires communication with a test app. So I create a device object that is named/indexed. All good so far.
One of the functionality that the lower level filter driver provides is to issue a request to the parent port to reset it. Now this causes an issue as I load the the lower level filter driver on the hub driver and the children (this is a compound device). The application resets the hub which causes the downstream devices to be removed/added.
So the application has handles to these “side” device objects, and when the hardware is re-enumerated, the filter driver needs to restore a connection the corresponding side device object via an index and using IoGetDeviceObjectPointer, which returns STATUS_INVALID_DEVICE_STATE.
I’m baffled by this. This is the first time I’ve used IoGetDeviceObjectPointer. I request FILE_READ_ATTRIBUTES as all I want is the device object pointer, from which I can get the WDFDEVICE for the side device object and then the context.
status = IoGetDeviceObjectPointer(&deviceName, FILE_READ_ATTRIBUTES, &controlFileObject, &controlDeviceObject);
The side device object is created as below(this might look familiar to some of you).
If I can’t use this, I’ll just use PnP notification, but I figured this would be a simple way to manage hardware coming and going when a handle is open to the side device objects. Any hints/tips/suggestions would be greatly appreciated.
deviceInit = WdfControlDeviceInitAllocate(
Driver,
&SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RWX_RES_RWX);
if (!deviceInit) {
}
WdfDeviceInitSetExclusive(deviceInit, FALSE);
status = WdfDeviceInitAssignName(deviceInit, &deviceName);
if (!NT_SUCCESS(status))
{
}
WDF_FILEOBJECT_CONFIG_INIT(&fileObjectConfig,
WdfFltrControlCreate,
WdfFltrControlClose,
WDF_NO_EVENT_CALLBACK);
WdfDeviceInitSetFileObjectConfig(deviceInit,
&fileObjectConfig,
NULL);
status = WdfDeviceCreate(&deviceInit,
&wdfObjectAttr,
&DeviceContext->WdfFltrControlDevice);
if (!NT_SUCCESS(status))
{
}
status = WdfDeviceCreateSymbolicLink(DeviceContext->WdfFltrControlDevice,
&linkName);
if (!NT_SUCCESS(status)) {
}
controlDeviceContext = GetControlDeviceContext(DeviceContext->WdfFltrControlDevice);
controlDeviceContext->DeviceContext = DeviceContext;
controlDeviceContext->Index = i;
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQueueConfig,
WdfIoQueueDispatchSequential);
ioQueueConfig.EvtIoDeviceControl = WdfFltrAppIntDeviceControl;
status = WdfIoQueueCreate(DeviceContext->WdfFltrControlDevice,
&ioQueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
NULL);
if (!NT_SUCCESS(status))
{
}
WdfControlFinishInitializing(DeviceContext->WdfFltrControlDevice);