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