Build Connection in ClientEventConnect in TDI Client

Hi

I have build two NT kernel-mode TDI Client Drivers; one acts as “server”
and another acts as “client”.

In “server”, I register ClientEventConnect routine to receive connection
request. I preallocate IRP (TdiBuildAccept), in ClientEventConnect I
return this IRP, for TDI will use this IRP to accept the connection
request. In the IRP I set the “client”'s IP address and port.

The “server” do receive the connection request, but after
ClientEventConnect return, the “client” report that the remote refused
the connection.

NTSTATUS
ClientEventConnect (
IN PVOID TdiEventContext,
IN LONG RemoteAddressLength,
IN PVOID RemoteAddress,
IN LONG UserDataLength,
IN PVOID UserData,
IN LONG OptionsLength,
IN PVOID Options,
OUT CONNECTION_CONTEXT *ConnectionContext,
OUT PIRP *AcceptIrp
)
{
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
CONNECTION_CONTEXT connectContext;
PDEVICE_OBJECT deviceObject;

IO_STATUS_BLOCK IoStatusBlock;
PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
TDI_CONNECTION_INFORMATION connectInfo;

KdPrint(( “Server: ClientEventConnect: Start! \n” ));
KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));

connectContext = ExAllocatePool( NonPagedPool, sizeof(
TdiConnectionContext ) );

RtlCopyMemory ( connectContext, // copy transport name
TdiConnectionContext,
sizeof ( TdiConnectionContext ) );

ConnectionContext = &connectContext;

AcceptIrp = &pGlobalIrp;

pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
buffer
NonPagedPool,
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

if ( pConnectInfo ) // validate
pointer
{
RtlZeroMemory ( pConnectInfo, // clear
buffer
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

pConnectInfo->RemoteAddressLength = RemoteAddressLength;

// pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof (
TDI_CONNECTION_INFORMATION );

pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;

connectInfo.RemoteAddressLength = RemoteAddressLength;
connectInfo.RemoteAddress = RemoteAddress;

deviceObject = IoGetRelatedDeviceObject( connectObject );

TdiBuildAccept(
pGlobalIrp,
deviceObject,
connectObject,
NULL,
NULL,
&connectInfo,
NULL //pReturnConnectInfo
);

ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );

if ( pConnectInfo )
ExFreePool( pConnectInfo );
}

if ( NT_SUCCESS( ntStatus ) )
ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
else
ntStatus = STATUS_CONNECTION_REFUSED;

KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”, ntStatus
));

return ( ntStatus );
}

NTSTATUS
ClientEventConnect (
IN PVOID TdiEventContext,
IN LONG RemoteAddressLength,
IN PVOID RemoteAddress,
IN LONG UserDataLength,
IN PVOID UserData,
IN LONG OptionsLength,
IN PVOID Options,
OUT CONNECTION_CONTEXT *ConnectionContext,
OUT PIRP *AcceptIrp
)
{
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
// WORK_QUEUE_ITEM WorkItem;
// CONNECT_INFO ConnectInfo;
CONNECTION_CONTEXT connectContext;
PDEVICE_OBJECT deviceObject;

IO_STATUS_BLOCK IoStatusBlock;
PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
TDI_CONNECTION_INFORMATION connectInfo;

KdPrint(( “Server: ClientEventConnect: Start! \n” ));
KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));

connectContext = ExAllocatePool( NonPagedPool, sizeof(
TdiConnectionContext ) );

RtlCopyMemory ( connectContext, // copy transport name
TdiConnectionContext,
sizeof ( TdiConnectionContext ) );

ConnectionContext = &connectContext;

AcceptIrp = &pGlobalIrp;

pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
buffer
NonPagedPool,
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

if ( pConnectInfo ) // validate
pointer
{
RtlZeroMemory ( pConnectInfo, // clear
buffer
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

pConnectInfo->RemoteAddressLength = RemoteAddressLength;

// pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof (
TDI_CONNECTION_INFORMATION );

pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;

connectInfo.RemoteAddressLength = RemoteAddressLength;
connectInfo.RemoteAddress = RemoteAddress;

//
// Get deviceObject from connectObject
//
deviceObject = IoGetRelatedDeviceObject( connectObject );

TdiBuildAccept(
pGlobalIrp,
deviceObject,
connectObject,
NULL,
NULL,
&connectInfo,
NULL //pReturnConnectInfo
);

ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );

if ( pConnectInfo )
ExFreePool( pConnectInfo );
}

if ( NT_SUCCESS( ntStatus ) )
ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
else
ntStatus = STATUS_CONNECTION_REFUSED;

KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”, ntStatus
));

return ( STATUS_INSUFFICIENT_RESOURCES );
}

Please, send my sample!
Any suggestions are appreciated.

Best Regards,
Ivaylo Todorov


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 haven’t looked thoroughly but your problem could be in the
way you deal with the accept IRP.
Try to build the IRP using TdiBuildAccept and pass the pointer
to the irp to AcceptIrp output parameter, ie do NOT submit it
to TDI using your TdiCall(). The transport driver will process
this irp as “accept” when your return STATUS_MORE_PROCESSING_REQUIRED.
Something like:

TdiBuildAccept(pGlobalIrp,…);
IoSetNextIrpStackLocation(pGlobalIrp)
*AcceptIrp = pGlobalIrp;
return STATUS_MORE_PROCESSING_REQUIRED;

Good luck,

  • Vitaly

On 06/15/01, “xxxxx@atia.com” wrote:

Hi

I have build two NT kernel-mode TDI Client Drivers; one acts as “server”
and another acts as “client”.

In “server”, I register ClientEventConnect routine to receive connection
request. I preallocate IRP (TdiBuildAccept), in ClientEventConnect I
return this IRP, for TDI will use this IRP to accept the connection
request. In the IRP I set the “client”'s IP address and port.

The “server” do receive the connection request, but after
ClientEventConnect return, the “client” report that the remote refused
the connection.

NTSTATUS
ClientEventConnect (
IN PVOID TdiEventContext,
IN LONG RemoteAddressLength,
IN PVOID RemoteAddress,
IN LONG UserDataLength,
IN PVOID UserData,
IN LONG OptionsLength,
IN PVOID Options,
OUT CONNECTION_CONTEXT *ConnectionContext,
OUT PIRP *AcceptIrp
)
{
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
CONNECTION_CONTEXT connectContext;
PDEVICE_OBJECT deviceObject;

IO_STATUS_BLOCK IoStatusBlock;
PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
TDI_CONNECTION_INFORMATION connectInfo;

KdPrint(( “Server: ClientEventConnect: Start! \n” ));
KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));

connectContext = ExAllocatePool( NonPagedPool, sizeof(
TdiConnectionContext ) );

RtlCopyMemory ( connectContext, // copy transport name
TdiConnectionContext,
sizeof ( TdiConnectionContext ) );

ConnectionContext = &connectContext;

AcceptIrp = &pGlobalIrp;

pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
buffer
NonPagedPool,
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

if ( pConnectInfo ) // validate
pointer
{
RtlZeroMemory ( pConnectInfo, // clear
buffer
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

pConnectInfo->RemoteAddressLength = RemoteAddressLength;

// pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof (
TDI_CONNECTION_INFORMATION );

pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;

connectInfo.RemoteAddressLength = RemoteAddressLength;
connectInfo.RemoteAddress = RemoteAddress;

deviceObject = IoGetRelatedDeviceObject( connectObject );

TdiBuildAccept(
pGlobalIrp,
deviceObject,
connectObject,
NULL,
NULL,
&connectInfo,
NULL //pReturnConnectInfo
);

ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );

if ( pConnectInfo )
ExFreePool( pConnectInfo );
}

if ( NT_SUCCESS( ntStatus ) )
ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
else
ntStatus = STATUS_CONNECTION_REFUSED;

KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”, ntStatus
));

return ( ntStatus );
}

NTSTATUS
ClientEventConnect (
IN PVOID TdiEventContext,
IN LONG RemoteAddressLength,
IN PVOID RemoteAddress,
IN LONG UserDataLength,
IN PVOID UserData,
IN LONG OptionsLength,
IN PVOID Options,
OUT CONNECTION_CONTEXT *ConnectionContext,
OUT PIRP *AcceptIrp
)
{
NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
// WORK_QUEUE_ITEM WorkItem;
// CONNECT_INFO ConnectInfo;
CONNECTION_CONTEXT connectContext;
PDEVICE_OBJECT deviceObject;

IO_STATUS_BLOCK IoStatusBlock;
PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
TDI_CONNECTION_INFORMATION connectInfo;

KdPrint(( “Server: ClientEventConnect: Start! \n” ));
KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));

connectContext = ExAllocatePool( NonPagedPool, sizeof(
TdiConnectionContext ) );

RtlCopyMemory ( connectContext, // copy transport name
TdiConnectionContext,
sizeof ( TdiConnectionContext ) );

ConnectionContext = &connectContext;

AcceptIrp = &pGlobalIrp;

pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
buffer
NonPagedPool,
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

if ( pConnectInfo ) // validate
pointer
{
RtlZeroMemory ( pConnectInfo, // clear
buffer
sizeof ( TDI_CONNECTION_INFORMATION ) +
RemoteAddressLength );

pConnectInfo->RemoteAddressLength = RemoteAddressLength;

// pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof (
TDI_CONNECTION_INFORMATION );

pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;

connectInfo.RemoteAddressLength = RemoteAddressLength;
connectInfo.RemoteAddress = RemoteAddress;

//
// Get deviceObject from connectObject
//
deviceObject = IoGetRelatedDeviceObject( connectObject );

TdiBuildAccept(
pGlobalIrp,
deviceObject,
connectObject,
NULL,
NULL,
&connectInfo,
NULL //pReturnConnectInfo
);

ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );

if ( pConnectInfo )
ExFreePool( pConnectInfo );
}

if ( NT_SUCCESS( ntStatus ) )
ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
else
ntStatus = STATUS_CONNECTION_REFUSED;

KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”, ntStatus
));

return ( STATUS_INSUFFICIENT_RESOURCES );
}

Please, send my sample!
Any suggestions are appreciated.

Best Regards,
Ivaylo Todorov


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


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

Hi,
my problem really is in call to TdiCall.
I write my source as you show.
I make connection only when TdiMon is sarted.
If remove TDI_BUILD_THREADCONTEXT i can’t build connection
betwen server and client.

NTSTATUS
ClientEventConnect (
IN PVOID TdiEventContext,
IN LONG RemoteAddressLength,
IN PVOID RemoteAddress,
IN LONG UserDataLength,
IN PVOID UserData,
IN LONG OptionsLength,
IN PVOID Options,
OUT CONNECTION_CONTEXT *ConnectionContext,
OUT PIRP *AcceptIrp
)
{
// NTSTATUS ntStatus = STATUS_SUCCESS;
WORK_QUEUE_ITEM WorkItem;
PDEVICE_OBJECT deviceObject;
IO_STACK_LOCATION

CONNECTION_CONTEXT connectContext;
BUILD_THREAD_CONTEXT BuildThreadContext;
PCLIENT_OBJECT_INFO pClientObjectInfo;

PIRP pIrp;
TDI_CONNECTION_INFORMATION connectInfo;

KdPrint(( “Server: ClientEventConnect: Start! \n” ));

DbgPrintTimeStamp( “BEGIN” );

pClientObjectInfo = ( PCLIENT_OBJECT_INFO )TdiEventContext;

pClientObjectInfo->pClientInfo->Address =
((PTA_IP_ADDRESS)RemoteAddress)->Address[0].Address[0].in_addr;
pClientObjectInfo->pClientInfo->Port =
((PTA_IP_ADDRESS)RemoteAddress)->Address[0].Address[0].sin_port;

connectContext = ExAllocatePool( NonPagedPool,
sizeof( TdiConnectionContext ) );

RtlCopyMemory ( connectContext, // copy connect name
TdiConnectionContext,
sizeof ( TdiConnectionContext ) );

*ConnectionContext = connectContext;

connectInfo.RemoteAddressLength = RemoteAddressLength;
connectInfo.RemoteAddress = RemoteAddress;

//
// Allocate a Irp to accept connection
//

pClientObjectInfo->ppIrp = &pIrp;

KeInitializeEvent( &( pClientObjectInfo->intEvent ), SynchronizationEvent,
FALSE );
ExInitializeWorkItem( &WorkItem, TdiBuildIrpThread, pClientObjectInfo );
ExQueueWorkItem( &WorkItem, DelayedWorkQueue );

( void )KeWaitForSingleObject( &( pClientObjectInfo->intEvent ),
Executive,
KernelMode,
TRUE,
NULL
);

if ( pIrp == NULL ) {

KdPrint(( “ClientEventConnect: ERROR allocate AcceptIrp! \n” ));
return STATUS_INSUFFICIENT_RESOURCES;
}

deviceObject = IoGetRelatedDeviceObject( pTdiTransportObject );

TdiBuildAccept(
pIrp,
deviceObject,
( PFILE_OBJECT )pClientObjectInfo->ConnectObject,
NULL,
NULL,
&connectInfo,
NULL
);

IoSetNextIrpStackLocation( pIrp );

*AcceptIrp = pIrp;

return ( STATUS_MORE_PROCESSING_REQUIRED );
}

----- Original Message -----
From:
To: “NT Developers Interest List”
Sent: Monday, June 18, 2001 12:00 PM
Subject: [ntdev] Re: Build Connection in ClientEventConnect in TDI Client

> I haven’t looked thoroughly but your problem could be in the
> way you deal with the accept IRP.
> Try to build the IRP using TdiBuildAccept and pass the pointer
> to the irp to AcceptIrp output parameter, ie do NOT submit it
> to TDI using your TdiCall(). The transport driver will process
> this irp as “accept” when your return STATUS_MORE_PROCESSING_REQUIRED.
> Something like:
>
> TdiBuildAccept(pGlobalIrp,…);
> IoSetNextIrpStackLocation(pGlobalIrp)
> *AcceptIrp = pGlobalIrp;
> return STATUS_MORE_PROCESSING_REQUIRED;
>
> Good luck,
>
> - Vitaly
>
>
> On 06/15/01, “xxxxx@atia.com” wrote:
> > Hi
> >
> > I have build two NT kernel-mode TDI Client Drivers; one acts as “server”
> > and another acts as “client”.
> >
> > In “server”, I register ClientEventConnect routine to receive connection
> > request. I preallocate IRP (TdiBuildAccept), in ClientEventConnect I
> > return this IRP, for TDI will use this IRP to accept the connection
> > request. In the IRP I set the “client”'s IP address and port.
> >
> > The “server” do receive the connection request, but after
> > ClientEventConnect return, the “client” report that the remote refused
> > the connection.
> >
> >
> > NTSTATUS
> > ClientEventConnect (
> > IN PVOID TdiEventContext,
> > IN LONG RemoteAddressLength,
> > IN PVOID RemoteAddress,
> > IN LONG UserDataLength,
> > IN PVOID UserData,
> > IN LONG OptionsLength,
> > IN PVOID Options,
> > OUT CONNECTION_CONTEXT *ConnectionContext,
> > OUT PIRP *AcceptIrp
> > )
> > {
> > NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
> > CONNECTION_CONTEXT connectContext;
> > PDEVICE_OBJECT deviceObject;
> >
> > IO_STATUS_BLOCK IoStatusBlock;
> > PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
> > TDI_CONNECTION_INFORMATION connectInfo;
> >
> >
> > KdPrint(( “Server: ClientEventConnect: Start! \n” ));
> > KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));
> >
> >
> > connectContext = ExAllocatePool( NonPagedPool,
eof(
> > TdiConnectionContext ) );
> >
> > RtlCopyMemory ( connectContext, // copy transport name
> > TdiConnectionContext,
> > sizeof ( TdiConnectionContext ) );
> >
> > ConnectionContext = &connectContext;
> >
> > AcceptIrp = &pGlobalIrp;
> >
> >
> >
> > pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
> > buffer
> > NonPagedPool,
> > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > RemoteAddressLength );
> >
> > if ( pConnectInfo ) // validate
> > pointer
> > {
> > RtlZeroMemory ( pConnectInfo, // clear
> > buffer
> > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > RemoteAddressLength );
> >
> > pConnectInfo->RemoteAddressLength = RemoteAddressLength;
> >
> > // pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof (
> > TDI_CONNECTION_INFORMATION );
> >
> > pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;
> >
> >
> > connectInfo.RemoteAddressLength = RemoteAddressLength;
> > connectInfo.RemoteAddress = RemoteAddress;
> >
> > deviceObject = IoGetRelatedDeviceObject( connectObject );
> >
> >
> > TdiBuildAccept(
> > pGlobalIrp,
> > deviceObject,
> > connectObject,
> > NULL,
> > NULL,
> > &c
onnectInfo,
> > NULL file://pReturnConnectInfo
> > );
> >
> >
> > ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );
> >
> >
> >
> > if ( pConnectInfo )
> > ExFreePool( pConnectInfo );
> > }
> >
> > if ( NT_SUCCESS( ntStatus ) )
> > ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
> > else
> > ntStatus = STATUS_CONNECTION_REFUSED;
> >
> >
> > KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”,
ntStatus
> > ));
> >
> > return ( ntStatus );
> > }
> >
> >
> > NTSTATUS
> > ClientEventConnect (
> > IN PVOID TdiEventContext,
> > IN LONG RemoteAddressLength,
> > IN PVOID RemoteAddress,
> > IN LONG UserDataLength,
> > IN PVOID UserData,
> > IN LONG OptionsLength,
> > IN PVOID Options,
> > OUT CONNECTION_CONTEXT *ConnectionContext,
> > OUT PIRP *AcceptIrp
> > )
> > {
> > NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
> > // WORK_QUEUE_ITEM WorkItem;
> > // CONNECT_INFO ConnectInfo;
> > CONNECTION_CONTEXT connectContext;
> > PDEVICE_OBJECT deviceObject;
> >
> > IO_STATUS_BLOCK IoStatusBlock;
> > PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
> > TDI_CONNECTION_INFORMATION connectInfo;
> >
> >
> > KdPrint(( “Server: ClientEventConnect: Start! \n” ));
> > KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));
> >
> >
> > connectContext = ExAllocatePool( NonPagedPool,
eof(
> > TdiConnectionContext ) );
> >
> > RtlCopyMemory ( connectContext, // copy transport name
> > TdiConnectionContext,
> > sizeof ( TdiConnectionContext ) );
> >
> > ConnectionContext = &connectContext;
> >
> > AcceptIrp = &pGlobalIrp;
> >
> >
> >
> > pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
> > buffer
> > NonPagedPool,
> > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > RemoteAddressLength );
> >
> > if ( pConnectInfo ) // validate
> > pointer
> > {
> > RtlZeroMemory ( pConnectInfo,
// clear
> > buffer
> > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > RemoteAddressLength );
> >
> > pConnectInfo->RemoteAddressLength = RemoteAddressLength;
> >
> > // pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof

> > TDI_CONNECTION_INFORMATION );
> >
> > pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;
> >
> >
> > connectInfo.RemoteAddressLength = RemoteAddressLength;
> > connectInfo.RemoteAddress = RemoteAddress;
> >
> > //
> > // Get deviceObject from connectObject
> > //
> > deviceObject = IoGetRelatedDeviceObject( connectObject );
> >
> >
> > TdiBuildAccept(
> > pGlobalIrp,
> > deviceObject,
> > connectObject,
> > NULL,
> > NULL,
> > &connectInfo,
> > NULL file://pReturnConnectInfo
> > );
> >
> >
> > ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );
> >
> >
> >
> > if ( pConnectInfo )
> > ExFreePool( pConnectInfo );
> > }
> >
> > if ( NT_SUCCESS( ntStatus ) )
> > ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
> > else
> > ntStatus = STATUS_CONNECTION_REFUSED;
> >
> >
> > KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”,
ntStatus
> > ));
> >
> > return ( STATUS_INSUFFICIENT_RESOURCES );
> > }
> >
> >
> >
> > Please, send my sample!
> > Any suggestions are appreciated.
> >
> > Best Regards,
> > Ivaylo Todorov
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@atia.com
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
> —
> You are currently subscribed to ntdev as: xxxxx@atia.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.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

Hi Ivaylo -

It is pretty hard for me to diagnose your problem
since I don’t know the context of your app, what it has to do with TdiMon,
etc.

Just few suggestions on debugging:

Try to simplify & isolate the problem: remove all the WorkItem stuff
from the routine and preallocate the IRP beforehand.

Just make sure you get all the accept IRP parameters right.
Set up the completion routine for the IRP and set a breakpoint
on the completion routine. When it hits check the NTSTATUS
and go from there.

Hope this helps,

Vitaly

On 06/26/01, ““Ivaylo Todorov” ” wrote:
> Hi,
> my problem really is in call to TdiCall.
> I write my source as you show.
> I make connection only when TdiMon is sarted.
> If remove TDI_BUILD_THREADCONTEXT i can’t build connection
> betwen server and client.
>
>
> NTSTATUS
> ClientEventConnect (
> IN PVOID TdiEventContext,
> IN LONG RemoteAddressLength,
> IN PVOID RemoteAddress,
> IN LONG UserDataLength,
> IN PVOID UserData,
> IN LONG OptionsLength,
> IN PVOID Options,
> OUT CONNECTION_CONTEXT *ConnectionContext,
> OUT PIRP *AcceptIrp
> )
> {
> // NTSTATUS ntStatus = STATUS_SUCCESS;
> WORK_QUEUE_ITEM WorkItem;
> PDEVICE_OBJECT deviceObject;
> IO_STACK_LOCATION
>
> CONNECTION_CONTEXT connectContext;
> BUILD_THREAD_CONTEXT BuildThreadContext;
> PCLIENT_OBJECT_INFO pClientObjectInfo;
>
> PIRP pIrp;
> TDI_CONNECTION_INFORMATION connectInfo;
>
>
>
> KdPrint(( “Server: ClientEventConnect: Start! \n” ));
>
>
>
> DbgPrintTimeStamp( “BEGIN” );
>
> pClientObjectInfo = ( PCLIENT_OBJECT_INFO )TdiEventContext;
>
>
> pClientObjectInfo->pClientInfo->Address =
> ((PTA_IP_ADDRESS)RemoteAddress)->Address[0].Address[0].in_addr;
> pClientObjectInfo->pClientInfo->Port =
> ((PTA_IP_ADDRESS)RemoteAddress)->Address[0].Address[0].sin_port;
>
>
> connectContext = ExAllocatePool( NonPagedPool,
> sizeof( TdiConnectionContext ) );
>
> RtlCopyMemory ( connectContext, // copy connect name
> TdiConnectionContext,
> sizeof ( TdiConnectionContext ) );
>
> *ConnectionContext = connectContext;
>
>
>
> connectInfo.RemoteAddressLength = RemoteAddressLength;
> connectInfo.RemoteAddress = RemoteAddress;
>
>
> //
> // Allocate a Irp to accept connection
> //
>
> pClientObjectInfo->ppIrp = &pIrp;
>
>
> KeInitializeEvent( &( pClientObjectInfo->intEvent ), SynchronizationEvent,
> FALSE );
> ExInitializeWorkItem( &WorkItem, TdiBuildIrpThread, pClientObjectInfo );
> ExQueueWorkItem( &WorkItem, DelayedWorkQueue );
>
> ( void )KeWaitForSingleObject( &( pClientObjectInfo->intEvent ),
> Executive,
> KernelMode,
> TRUE,
> NULL
> );
>
>
> if ( pIrp == NULL ) {
>
> KdPrint(( “ClientEventConnect: ERROR allocate AcceptIrp! \n” ));
> return STATUS_INSUFFICIENT_RESOURCES;
> }
>
>
>
> deviceObject = IoGetRelatedDeviceObject( pTdiTransportObject );
>
>
> TdiBuildAccept(
> pIrp,
> deviceObject,
> ( PFILE_OBJECT )pClientObjectInfo->ConnectObject,
> NULL,
> NULL,
> &connectInfo,
> NULL
> );
>
>
>
> IoSetNextIrpStackLocation( pIrp );
>
> *AcceptIrp = pIrp;
>
>
>
> return ( STATUS_MORE_PROCESSING_REQUIRED );
> }
>
> ----- Original Message -----
> From:
> To: “NT Developers Interest List”
> Sent: Monday, June 18, 2001 12:00 PM
> Subject: [ntdev] Re: Build Connection in ClientEventConnect in TDI Client
>
>
> > I haven’t looked thoroughly but your problem could be in the
> > way you deal with the accept IRP.
> > Try to build the IRP using TdiBuildAccept and pass the pointer
> > to the irp to AcceptIrp output parameter, ie do NOT submit it
> > to TDI using your TdiCall(). The transport driver will process
> > this irp as “accept” when your return STATUS_MORE_PROCESSING_REQUIRED.
> > Something like:
> >
> > TdiBuildAccept(pGlobalIrp,…);
> > IoSetNextIrpStackLocation(pGlobalIrp)
> > *AcceptIrp = pGlobalIrp;
> > return STATUS_MORE_PROCESSING_REQUIRED;
> >
> > Good luck,
> >
> > - Vitaly
> >
> >
> > On 06/15/01, “xxxxx@atia.com” wrote:
> > > Hi
> > >
> > > I have build two NT kernel-mode TDI Client Drivers; one acts as “server”
> > > and another acts as “client”.
> > >
> > > In “server”, I register ClientEventConnect routine to receive connection
> > > request. I preallocate IRP (TdiBuildAccept), in ClientEventConnect I
> > > return this IRP, for TDI will use this IRP to accept the connection
> > > request. In the IRP I set the “client”'s IP address and port.
> > >
> > > The “server” do receive the connection request, but after
> > > ClientEventConnect return, the “client” report that the remote refused
> > > the connection.
> > >
> > >
> > > NTSTATUS
> > > ClientEventConnect (
> > > IN PVOID TdiEventContext,
> > > IN LONG RemoteAddressLength,
> > > IN PVOID RemoteAddress,
> > > IN LONG UserDataLength,
> > > IN PVOID UserData,
> > > IN LONG OptionsLength,
> > > IN PVOID Options,
> > > OUT CONNECTION_CONTEXT *ConnectionContext,
> > > OUT PIRP *AcceptIrp
> > > )
> > > {
> > > NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
> > > CONNECTION_CONTEXT connectContext;
> > > PDEVICE_OBJECT deviceObject;
> > >
> > > IO_STATUS_BLOCK IoStatusBlock;
> > > PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
> > > TDI_CONNECTION_INFORMATION connectInfo;
> > >
> > >
> > > KdPrint(( “Server: ClientEventConnect: Start! \n” ));
> > > KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));
> > >
> > >
> > > connectContext = ExAllocatePool( NonPagedPool,
> eof(
> > > TdiConnectionContext ) );
> > >
> > > RtlCopyMemory ( connectContext, // copy transport name
> > > TdiConnectionContext,
> > > sizeof ( TdiConnectionContext ) );
> > >
> > > ConnectionContext = &connectContext;
> > >
> > > AcceptIrp = &pGlobalIrp;
> > >
> > >
> > >
> > > pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
> > > buffer
> > > NonPagedPool,
> > > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > > RemoteAddressLength );
> > >
> > > if ( pConnectInfo ) // validate
> > > pointer
> > > {
> > > RtlZeroMemory ( pConnectInfo, // clear
> > > buffer
> > > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > > RemoteAddressLength );
> > >
> > > pConnectInfo->RemoteAddressLength = RemoteAddressLength;
> > >
> > > // pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof (
> > > TDI_CONNECTION_INFORMATION );
> > >
> > > pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;
> > >
> > >
> > > connectInfo.RemoteAddressLength = RemoteAddressLength;
> > > connectInfo.RemoteAddress = RemoteAddress;
> > >
> > > deviceObject = IoGetRelatedDeviceObject( connectObject );
> > >
> > >
> > > TdiBuildAccept(
> > > pGlobalIrp,
> > > deviceObject,
> > > connectObject,
> > > NULL,
> > > NULL,
> > > &c
> onnectInfo,
> > > NULL file://pReturnConnectInfo
> > > );
> > >
> > >
> > > ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );
> > >
> > >
> > >
> > > if ( pConnectInfo )
> > > ExFreePool( pConnectInfo );
> > > }
> > >
> > > if ( NT_SUCCESS( ntStatus ) )
> > > ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
> > > else
> > > ntStatus = STATUS_CONNECTION_REFUSED;
> > >
> > >
> > > KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”,
> ntStatus
> > > ));
> > >
> > > return ( ntStatus );
> > > }
> > >
> > >
> > > NTSTATUS
> > > ClientEventConnect (
> > > IN PVOID TdiEventContext,
> > > IN LONG RemoteAddressLength,
> > > IN PVOID RemoteAddress,
> > > IN LONG UserDataLength,
> > > IN PVOID UserData,
> > > IN LONG OptionsLength,
> > > IN PVOID Options,
> > > OUT CONNECTION_CONTEXT *ConnectionContext,
> > > OUT PIRP *AcceptIrp
> > > )
> > > {
> > > NTSTATUS ntStatus = STATUS_UNSUCCESSFUL;
> > > // WORK_QUEUE_ITEM WorkItem;
> > > // CONNECT_INFO ConnectInfo;
> > > CONNECTION_CONTEXT connectContext;
> > > PDEVICE_OBJECT deviceObject;
> > >
> > > IO_STATUS_BLOCK IoStatusBlock;
> > > PTDI_CONNECTION_INFORMATION pConnectInfo = NULL;
> > > TDI_CONNECTION_INFORMATION connectInfo;
> > >
> > >
> > > KdPrint(( “Server: ClientEventConnect: Start! \n” ));
> > > KdPrint(( “Server: remoteAddressLength = %u \n”, RemoteAddressLength ));
> > >
> > >
> > > connectContext = ExAllocatePool( NonPagedPool,
> eof(
> > > TdiConnectionContext ) );
> > >
> > > RtlCopyMemory ( connectContext, // copy transport name
> > > TdiConnectionContext,
> > > sizeof ( TdiConnectionContext ) );
> > >
> > > ConnectionContext = &connectContext;
> > >
> > > AcceptIrp = &pGlobalIrp;
> > >
> > >
> > >
> > > pConnectInfo = (PTDI_CONNECTION_INFORMATION)ExAllocatePool ( // allocate
> > > buffer
> > > NonPagedPool,
> > > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > > RemoteAddressLength );
> > >
> > > if ( pConnectInfo ) // validate
> > > pointer
> > > {
> > > RtlZeroMemory ( pConnectInfo,
> // clear
> > > buffer
> > > sizeof ( TDI_CONNECTION_INFORMATION ) +
> > > RemoteAddressLength );
> > >
> > > pConnectInfo->RemoteAddressLength = RemoteAddressLength;
> > >
> > > // pConnectInfo->RemoteAddress = (PUCHAR)pConnectInfo + sizeof
>
> > > TDI_CONNECTION_INFORMATION );
> > >
> > > pConnectInfo->RemoteAddress = (PTA_IP_ADDRESS)RemoteAddress;
> > >
> > >
> > > connectInfo.RemoteAddressLength = RemoteAddressLength;
> > > connectInfo.RemoteAddress = RemoteAddress;
> > >
> > > //
> > > // Get deviceObject from connectObject
> > > //
> > > deviceObject = IoGetRelatedDeviceObject( connectObject );
> > >
> > >
> > > TdiBuildAccept(
> > > pGlobalIrp,
> > > deviceObject,
> > > connectObject,
> > > NULL,
> > > NULL,
> > > &connectInfo,
> > > NULL file://pReturnConnectInfo
> > > );
> > >
> > >
> > > ntStatus = TdiCall( pGlobalIrp, deviceObject, &IoStatusBlock );
> > >
> > >
> > >
> > > if ( pConnectInfo )
> > > ExFreePool( pConnectInfo );
> > > }
> > >
> > > if ( NT_SUCCESS( ntStatus ) )
> > > ntStatus = STATUS_MORE_PROCESSING_REQUIRED;
> > > else
> > > ntStatus = STATUS_CONNECTION_REFUSED;
> > >
> > >
> > > KdPrint(( “TdiClient: ClientEventConnect: exit Status = 0x%X \n”,
> ntStatus
> > > ));
> > >
> > > return ( STATUS_INSUFFICIENT_RESOURCES );
> > > }
> > >
> > >
> > >
> > > Please, send my sample!
> > > Any suggestions are appreciated.
> > >
> > > Best Regards,
> > > Ivaylo Todorov
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@atia.com
> > > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@atia.com
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.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


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

> Hi,

my problem really is in call to TdiCall.
I write my source as you show.

ClientEventConnect runs on DISPATCH_LEVEL, and you try to use
KeWaitForSingleObject there. It’s wrong.

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