TDI Filter

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

I didn’t look at the code, but…

However, performing the operation at the point you are mentioning (before
associate address and before the address is actually used for anything…)
isn’t likely to be valuable.

At that point I doubt that you could find anything more then was already
passed in when the address object was created. For example, if a wildcard
port or IP address was specified, then they certainly haven’t been selected
yet. You won’t be able to fetch additional information until the address
object is actually used in an active connection.

Good luck,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From:
To: “NT Developers Interest List”
Sent: Thursday, June 14, 2001 7:19 PM
Subject: [ntdev] TDI Filter

> 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???
>


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</http:></http:>

> passed in when the address object was created. For example, if a wildcard

port or IP address was specified, then they certainly haven’t been
selected
yet. You won’t be able to fetch additional information until the address
object is actually used in an active connection.

Then to what TDI call the Berkeley bind() is mapped?
bind() is enough to retrieve the local address - even the wildcard bind.
connect() is not necessary for this.

Am I right that bind() is mapped to address object creation?

Max


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

Well,as per my observation when app calls socket() and
bind(),Windows socket emulator(Driver) sends
IRP_MJ_CREATE request to tansport driver which creates
address object and assigns the port if wildcard port.
It also installs some of the event handlers like
error,disconnect,receive etc… Then when app calls
listen(),emulator sends TDI_ASSOCIATE_ADDRESS request
to transport driver and installs connect event handler
to listen for incoming request. When local or remote
offers the connection then emulator actually calls
TDI_ACCEPT. But since app has already called
accept()…

All this I observed on W2K…

  • Sunil

— “Maxim S. Shatskih”
wrote:
> > passed in when the address object was created. For
> example, if a wildcard
> > port or IP address was specified, then they
> certainly haven’t been
> selected
> > yet. You won’t be able to fetch additional
> information until the address
> > object is actually used in an active connection.
>
> Then to what TDI call the Berkeley bind() is mapped?
> bind() is enough to retrieve the local address -
> even the wildcard bind.
> connect() is not necessary for this.
>
> Am I right that bind() is mapped to address object
> creation?
>
> Max
>
>
> —
> You are currently subscribed to ntdev as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/


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