Hi all,
I had written a TDI filter driver for Tcp/Udp devices. I would like to make
a TDI_QUERY_INFORMATION request for getting a IP address and Port no.
before TDI_ASSOCIATE_ADDRESS goes down to transport driver.
My code fragment is given below… Can anybody tell me what’s wrong with
my code. This call goes into loop as if transport driver taking a long time
to complete… I don’t know what’s going wrong with this I/O packet???
//----------------------------------------------------------------------
//
// TcpmonQueryAddress
//
// This function retrieves the local address information from the
// underlying transport, asking for the address in particular.
//
//----------------------------------------------------------------------
BOOLEAN TcpmonQueryAddress(
PDEVICE_OBJECT DeviceObject,
PFILE_OBJECT FileObject,
PVOID LocalAddress,
ULONG LocalAddrLen
)
{
PIRP Irp;
KEVENT Event;
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION IoStackLocation;
PMDL MdlAddress;
PVOID SysMdlAddress;
NTSTATUS ntStatus;
// Validate input parameters
if ( (DeviceObject == NULL)
|| (FileObject == NULL)
|| (LocalAddress == NULL))
{
DbgPrint((“TcpmonQueryAddress: Invalid input parameters… \
DeviceObject,FileObject or LocalAddress.\n”));
return (FALSE);
}
// Initialize the event
KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
MdlAddress = IoAllocateMdl(LocalAddress,LocalAddrLen,FALSE,FALSE,NULL);
if (MdlAddress == NULL)
{
DbgPrint((“TcpmonQueryAddress: Failed to allocate MDL buffer.\n”));
return (FALSE);
}
MmBuildMdlForNonPagedPool(MdlAddress);
// Allocate an IRP for this request.
Irp = TdiBuildInternalDeviceControlIrp (
TDI_QUERY_INFORMATION,
DeviceObject,
FileObject,
&Event,
&IoStatusBlock );
if(Irp == NULL)
{
IoFreeMdl(MdlAddress);
DbgPrint((“TcpmonQueryAddress: Failed to allocate IRP.\n”));
return (FALSE);
}
//MdlAddress = IoAllocateMdl(LocalAddress,LocalAddrLen,FALSE,TRUE,Irp);
TdiBuildQueryInformation(
Irp,
DeviceObject,
FileObject,
TcpmonQueryAddressComplete,
NULL,
TDI_QUERY_ADDRESS_INFO,
MdlAddress
);
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->Tail.Overlay.OriginalFileObject = FileObject;
// Send it to the transport
DbgPrint((“TcpmonQueryAddress: Before calling IoCallDriver()
Irp=0x%x…\n”,Irp));
ntStatus = IoCallDriver(DeviceObject, Irp);
if (!NT_SUCCESS(ntStatus))
{
DbgPrint((“TcpmonQueryAddress: IoCallDriver() returned
%x…\n”,ntStatus));
}
// Wait for the I/O
KeWaitForSingleObject(&Event, Executive, KernelMode, TRUE, 0);
// Done! Note that since our completion routine frees
// the IRP we cannot touch the IRP now.
return NT_SUCCESS( IoStatusBlock.Status );
}
//----------------------------------------------------------------------
//
// TcpmonQueryAddressComplete
//
// This routine is used to handle I/O completion for our self-generated
// IRP that is used to query a transport address.
//
//----------------------------------------------------------------------
NTSTATUS TcpmonQueryAddressComplete(
PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context
)
{
// Copy the status information back into the “user” IOSB.
*Irp->UserIosb = Irp->IoStatus;
if(!NT_SUCCESS(Irp->IoStatus.Status))
{
DbgBreakPoint();
DbgPrint((“TcpmonQueryAddressComplete: ERROR ON IRP:
%x\n”,Irp->IoStatus.Status));
}
// Set the user event - wakes up the mainline code doing
// this.
KeSetEvent(Irp->UserEvent, 0, FALSE);
// Free the IRP now that we are done with it.
IoFreeMdl(Irp->MdlAddress);
IoFreeIrp(Irp);
// We return STATUS_MORE_PROCESSING_REQUIRED because this “magic”
return
// value tells the I/O Manager that additional processing will be done by
// this driver to the IRP - in fact, it might (as it is in this case)
// already BE done - and the IRP cannot be completed.
return STATUS_MORE_PROCESSING_REQUIRED;
}
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com