Re: Build Connection in ClientEventConnect in TDI Cli- ent

Hi,
I did not go through this code in complete. But looks like
you are missing something. ConnectionContext is the one which you
passed when you created your connectionObject. But looks like
you are allocating a connectionContext, instead of using a
connectioncontext which you passed while creating a connection
object. Remember this connection object needs to be associated
with the address object on which you received this ClientEventConnect.

Hope this Helps,
Srin.

-----Original Message-----
From: Ivaylo Todorov [mailto:xxxxx@atia.com]
Sent: Tuesday, June 26, 2001 4:54 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Build Connection in ClientEventConnect in TDI
Client

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: xxxxx@nai.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