All,
I am developing a TDI Client filter drvier using KMDF. The driver loads as a
legacy driver. In the driver entry routine (code is below), I am trying to
create an IO Target using TCPIP.sys and then layering a control device on
top of it. It seems like I can attach to the device stack but I don’t get
any IO in the default event handler. Can someone tell me what I am doing
wrong?
TIA,
Dale
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT pDriver,
IN PUNICODE_STRING pRegPath)
{
NTSTATUS status;
DBGPRINT(5, (“TDI Filter Driver Entry. Driver built on: %s\n”,
TIMESTAMP));
#if DBG
DbgBreakPoint();
#endif
// Create the KMDF driver object
WDF_DRIVER_CONFIG configParms;
WDFDRIVER hDriver;
WDF_DRIVER_CONFIG_INIT(&configParms, WDF_NO_EVENT_CALLBACK);
configParms.DriverInitFlags |= WdfDriverInitNonPnpDriver;
configParms.EvtDriverUnload = ISTDriverUnload;
status = WdfDriverCreate(pDriver,
pRegPath,
WDF_NO_OBJECT_ATTRIBUTES,
&configParms,
&hDriver);
if (!NT_SUCCESS(status))
{
DBGPRINT(5, (“DriverEntry: Failed to create the KMDF driver object\n”));
}
// Create a control device object
//
//
PWDFDEVICE_INIT pDevInit;
pDevInit = WdfControlDeviceInitAllocate(
hDriver,
&SDDL_DEVOBJ_SYS_ALL);
if (pDevInit == NULL)
{
DBGPRINT(5, (“DriverEntry: Failed to create DEVICE_INIT for the CDO. Status:
0x%x.\n”,
status));
return STATUS_INSUFFICIENT_RESOURCES;
}
// Init the attributes for the device object
WDF_OBJECT_ATTRIBUTES attribs;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attribs, IST_TDI_EXT);
// Create the CDO device
WDFDEVICE hCDODevice;
status = WdfDeviceCreate(&pDevInit, &attribs, &hCDODevice);
if (!NT_SUCCESS(status))
{
DBGPRINT(5, (“Driver Entry: WdfDeviceCreate failed to create CDO. Status:
0x%x\n”, status));
WdfDeviceInitFree(pDevInit);
return status;
}
PIST_TDI_EXT pDevExt = GetDevExt(hCDODevice);
// Store the device handle
pDevExt->hDevice = hCDODevice;
// Configure the default IO qeue
WDF_IO_QUEUE_CONFIG ioQConfig;
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQConfig,
WdfIoQueueDispatchParallel);
ioQConfig.EvtIoDefault = ISTEvtIoDefault;
status = WdfIoQueueCreate(hCDODevice,
&ioQConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&pDevExt->hDeviceDefaultIoQueue);
if (!NT_SUCCESS (status))
{
DBGPRINT(5, (“DriverEntry: Failed to create the Default IO queue. Status:
0x%x\n”,
status));
return status;
}
WdfControlFinishInitializing(hCDODevice);
// Create the TCP/IP Io Target
//
// Init the attributes for the device object
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attribs, IST_TDI_EXT);
// Create the CDO device
WDFDEVICE hTCPDevice;
PWDFDEVICE_INIT pTCPDevInit;
pTCPDevInit = WdfControlDeviceInitAllocate(
hDriver,
&SDDL_DEVOBJ_SYS_ALL);
if (pTCPDevInit == NULL)
{
DBGPRINT(5, (“DriverEntry: Failed to create DEVICE_INIT for the CDO. Status:
0x%x.\n”,
status));
return STATUS_INSUFFICIENT_RESOURCES;
}
status = WdfDeviceCreate(&pTCPDevInit, &attribs, &hTCPDevice);
if (!NT_SUCCESS(status))
{
DBGPRINT(5, (“Driver Entry: WdfDeviceCreate failed to create TCPDevice.
Status: 0x%x\n”, status));
WdfDeviceInitFree(pDevInit);
return status;
}
WdfControlFinishInitializing(hTCPDevice);
// Get the TCP device object
UNICODE_STRING uniDevName;
RtlInitUnicodeString(&uniDevName, L"\Device\Tcp");
// Create the TCP/IP Io Device
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attribs, IST_TDI_EXT);
status = WdfIoTargetCreate(hTCPDevice, &attribs, &pDevExt->hTcpIpTarget);
if (!NT_SUCCESS(status))
{
DBGPRINT(5, (“DriverEntry: Failed to create the TCP/IP target. Status:
0x%x.\n”,
status));
return status;
}
// Open a handle to the device
WDF_IO_TARGET_OPEN_PARAMS openParms;
WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME(
&openParms,
&uniDevName,
FILE_WRITE_ACCESS | FILE_READ_ACCESS);
openParms.ShareAccess = FILE_SHARE_WRITE | FILE_SHARE_READ;
status = WdfIoTargetOpen(pDevExt->hTcpIpTarget, &openParms);
if (!NT_SUCCESS(status))
{
DBGPRINT(5, (“DriverEntry: Failed to open the TCP/IP target. Status:
0x%x.\n”,
status));
// Delete the IO Target
WdfObjectDelete(pDevExt->hTcpIpTarget);
pDevExt->hTcpIpTarget = 0;
return status;
}
// Attach the CDO to the Tcp/Ip Target
PDEVICE_OBJECT pCDODevice = WdfDeviceWdmGetDeviceObject(hCDODevice);
PDEVICE_OBJECT pTcpIpDevice = WdfDeviceWdmGetDeviceObject(hTCPDevice);
pDevExt->pLowerDevice = IoAttachDeviceToDeviceStack(pCDODevice,
pTcpIpDevice);
if (pDevExt->pLowerDevice == NULL)
{
DBGPRINT(5, (“DriverEntry: Failed to attach to the TCP/IP target.\n”));
return STATUS_UNSUCCESSFUL;
}
return STATUS_SUCCESS;
}