UMDF function and KMDF Bus driver

Hi,
I have a design where i have a Multifunction driver which creates 2 PDOs and is a function driver for USB device(Parents FDO). I have 2 fucntion driver(child FDO) which sits on top of these PDOs created. One is a UMDF Driver and another is KMDF function driver.

The requirment is requests should flow from both the child FDO and should come to parent FDO and then should be sent to device.

I have 2 approach to do this.

  1. I have created a queue and associated it with PDO
    status = WdfFdoAddStaticChild(Device, hChild);
    if (!NT_SUCCESS(status))
    {
    goto Cleanup;
    }
    WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE( &ioQueueConfig,
    WdfIoQueueDispatchParallel);
    ioQueueConfig.EvtIoDeviceControl = Someother1;

ioQueueConfig.DefaultQueue = TRUE;
ioQueueConfig.AllowZeroLengthRequests = TRUE;
status = WdfIoQueueCreate( hChild,
&ioQueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
WDF_NO_HANDLE);
if (!NT_SUCCESS(status))
{
KdPrint((“WdfIoQueueCreate failed %!STATUS!\n”, status));
return status;
}
2. I have created a io target and have stored it in PDO’s extension so that Fucntion driver can retrieve it andcan send the data. This is working fine.

parentWdmDeviceObject =
WdfDeviceWdmGetDeviceObject(WdfPdoGetParent(hChild));
WdfDeviceWdmGetDeviceObject(hChild)->StackSize +=
parentWdmDeviceObject->StackSize;

status =
WdfIoTargetCreate(hChild,
WDF_NO_OBJECT_ATTRIBUTES,
&pdoData->IoTargetForParentFdo);
if (!NT_SUCCESS (status))
{
goto Cleanup;
}

WDF_IO_TARGET_OPEN_PARAMS_INIT_EXISTING_DEVICE(&openParams,
parentWdmDeviceObject );
status =
WdfIoTargetOpen(pdoData->IoTargetForParentFdo, &openParams);
if (!NT_SUCCESS (status))
{
goto Cleanup;
}

The UMDF Driver is written in such a way that it gets the default io target (IWDFDevice::GetDefaultIoTarget) and creates and

its sends the IOCTL request (IWDFIoRequest::Send). The send function crashes saying (CWudfDeviceStack::Forward):pHostFileObj

should not be NULL.

Now i have the following questions

  1. Is this approach correct, I should get the request to my PDO if i do the send and my “Someother1( )” should be called.

  2. Which of the above two approach is correct and do we have any API to convert IOTarget object created in KMDF to UMDF IOtarget.

  3. Is there any other setting ,may be in INF or anything that i should do to make this work.

Regards,
Sup

Your UMDF problem is because UMDF enforces a file object for every
request. KMDF doesn’t have any such restriction.

You need to ensure that you provide a non-NULL file object to the format
function of I/O target. If you are issuing I/O in response to
application I/O whose lifetime will be contained within the lifetime of
application I/O you can use the file object that comes with application
I/O (IWDFIoRequest::GetFileObject).

If you are issuing a request that your driver creates which is unrelated
to application I/O, you can create your own file by calling
IWDFDevice::CreateWdfFile and use this file while formatting I/O for I/O
target. This file represents your session to the lower portion of the
stack.

You can even create such a file during start (OnPrepareHardware) and
close it (IWDFDriverCreatedFile::Close) in OnReleaseHardware if you want
to keep it around for all of your started state - this implies that your
driver keeps a session open to the lower portion of the stack for all of
its started state. Or you can use narrower scope for the file if that’s
what would make more sense.

Another thing to note is that unlike ZwCreateFile,
IWDFDriver::CreateWdfFile sends a Create IRP down to the next device in
the stack (and not to the top of the stack).

Hope this helps,

Praveen

Hi Praveen,

Thanks for the help. The problem was exactly the same as you told. As soon as file object was created, request started flowing into KMDF bus driver.

Once again,Thanks for the support.

Regards,
Sup