mirror of
https://github.com/reactos/reactos.git
synced 2024-06-30 09:50:07 +00:00
[AFD/FORMATTING]
- Try to fix indentation nightmare svn path=/trunk/; revision=56389
This commit is contained in:
parent
85b693d42d
commit
5258184b49
|
@ -46,7 +46,7 @@ NTSTATUS WarmSocketForBind( PAFD_FCB FCB ) {
|
|||
if (!FCB->Recv.Window)
|
||||
Status = STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = TdiReceiveDatagram(&FCB->ReceiveIrp.InFlightRequest,
|
||||
|
@ -58,7 +58,7 @@ NTSTATUS WarmSocketForBind( PAFD_FCB FCB ) {
|
|||
&FCB->ReceiveIrp.Iosb,
|
||||
PacketSocketRecvComplete,
|
||||
FCB);
|
||||
|
||||
|
||||
/* We don't want to wait for this read to complete. */
|
||||
if( Status == STATUS_PENDING ) Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ NTSTATUS WarmSocketForBind( PAFD_FCB FCB ) {
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -81,24 +81,25 @@ AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
if( !(BindReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
|
||||
Irp, 0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
|
||||
Irp, 0 );
|
||||
|
||||
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
|
||||
FCB->LocalAddress = TaCopyTransportAddress( &BindReq->Address );
|
||||
|
||||
if( FCB->LocalAddress )
|
||||
Status = TdiBuildConnectionInfo( &FCB->AddressFrom,
|
||||
FCB->LocalAddress );
|
||||
Status = TdiBuildConnectionInfo( &FCB->AddressFrom,
|
||||
FCB->LocalAddress );
|
||||
|
||||
if( NT_SUCCESS(Status) )
|
||||
Status = WarmSocketForBind( FCB );
|
||||
Status = WarmSocketForBind( FCB );
|
||||
AFD_DbgPrint(MID_TRACE,("FCB->Flags %x\n", FCB->Flags));
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
|
||||
/* MSAFD relies on us returning the address file handle in the IOSB */
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, (ULONG_PTR)FCB->AddressFile.Handle );
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp,
|
||||
(ULONG_PTR)FCB->AddressFile.Handle );
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,10 @@
|
|||
*/
|
||||
#include "afd.h"
|
||||
|
||||
NTSTATUS NTAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
AfdGetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -39,7 +40,7 @@ AfdGetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
NTSTATUS
|
||||
NTAPI
|
||||
AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -47,7 +48,7 @@ AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT ConnectOptionsSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!ConnectOptions)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -75,7 +76,7 @@ AfdSetConnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
NTSTATUS
|
||||
NTAPI
|
||||
AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -83,7 +84,7 @@ AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!ConnectOptionsSize)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -108,9 +109,10 @@ AfdSetConnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
return UnlockAndMaybeComplete(FCB, STATUS_SUCCESS, Irp, 0);
|
||||
}
|
||||
|
||||
NTSTATUS NTAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
AfdGetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -146,7 +148,7 @@ AfdSetConnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT ConnectDataSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!ConnectData)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -184,7 +186,7 @@ AfdSetConnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
if (!ConnectDataSize)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
||||
if (BufferSize < sizeof(UINT))
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
|
||||
|
@ -207,7 +209,8 @@ AfdSetConnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
|
||||
NTSTATUS WarmSocketForConnection( PAFD_FCB FCB ) {
|
||||
NTSTATUS
|
||||
WarmSocketForConnection(PAFD_FCB FCB) {
|
||||
NTSTATUS Status;
|
||||
|
||||
if( !FCB->TdiDeviceName.Length || !FCB->TdiDeviceName.Buffer ) {
|
||||
|
@ -227,7 +230,8 @@ NTSTATUS WarmSocketForConnection( PAFD_FCB FCB ) {
|
|||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS MakeSocketIntoConnection( PAFD_FCB FCB ) {
|
||||
NTSTATUS
|
||||
MakeSocketIntoConnection(PAFD_FCB FCB) {
|
||||
NTSTATUS Status;
|
||||
|
||||
ASSERT(!FCB->Recv.Window);
|
||||
|
@ -265,13 +269,13 @@ NTSTATUS MakeSocketIntoConnection( PAFD_FCB FCB ) {
|
|||
FCB->State = SOCKET_STATE_CONNECTED;
|
||||
|
||||
Status = TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
|
||||
FCB->Connection.Object,
|
||||
TDI_RECEIVE_NORMAL,
|
||||
FCB->Recv.Window,
|
||||
FCB->Recv.Size,
|
||||
&FCB->ReceiveIrp.Iosb,
|
||||
ReceiveComplete,
|
||||
FCB );
|
||||
FCB->Connection.Object,
|
||||
TDI_RECEIVE_NORMAL,
|
||||
FCB->Recv.Window,
|
||||
FCB->Recv.Size,
|
||||
&FCB->ReceiveIrp.Iosb,
|
||||
ReceiveComplete,
|
||||
FCB );
|
||||
|
||||
if( Status == STATUS_PENDING ) Status = STATUS_SUCCESS;
|
||||
|
||||
|
@ -283,17 +287,18 @@ NTSTATUS MakeSocketIntoConnection( PAFD_FCB FCB ) {
|
|||
return Status;
|
||||
}
|
||||
|
||||
static NTSTATUS NTAPI StreamSocketConnectComplete
|
||||
( PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp,
|
||||
PVOID Context ) {
|
||||
static
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
StreamSocketConnectComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PVOID Context) {
|
||||
NTSTATUS Status = Irp->IoStatus.Status;
|
||||
PAFD_FCB FCB = (PAFD_FCB)Context;
|
||||
PLIST_ENTRY NextIrpEntry;
|
||||
PIRP NextIrp;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called: FCB %x, FO %x\n",
|
||||
Context, FCB->FileObject));
|
||||
Context, FCB->FileObject));
|
||||
|
||||
/* I was wrong about this before as we can have pending writes to a not
|
||||
* yet connected socket */
|
||||
|
@ -301,7 +306,7 @@ static NTSTATUS NTAPI StreamSocketConnectComplete
|
|||
return STATUS_FILE_CLOSED;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Irp->IoStatus.Status = %x\n",
|
||||
Irp->IoStatus.Status));
|
||||
Irp->IoStatus.Status));
|
||||
|
||||
ASSERT(FCB->ConnectIrp.InFlightRequest == Irp);
|
||||
FCB->ConnectIrp.InFlightRequest = NULL;
|
||||
|
@ -309,45 +314,45 @@ static NTSTATUS NTAPI StreamSocketConnectComplete
|
|||
if( FCB->State == SOCKET_STATE_CLOSED ) {
|
||||
/* Cleanup our IRP queue because the FCB is being destroyed */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_CONNECT] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_CONNECT]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_CONNECT]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
}
|
||||
|
||||
if( !NT_SUCCESS(Irp->IoStatus.Status) ) {
|
||||
FCB->PollState |= AFD_EVENT_CONNECT_FAIL;
|
||||
FCB->PollState |= AFD_EVENT_CONNECT_FAIL;
|
||||
FCB->PollStatus[FD_CONNECT_BIT] = Irp->IoStatus.Status;
|
||||
AFD_DbgPrint(MID_TRACE,("Going to bound state\n"));
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
AFD_DbgPrint(MID_TRACE,("Going to bound state\n"));
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
|
||||
/* Succeed pending irps on the FUNCTION_CONNECT list */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_CONNECT] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_CONNECT]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
AFD_DbgPrint(MID_TRACE,("Completing connect %x\n", NextIrp));
|
||||
NextIrp->IoStatus.Status = Status;
|
||||
NextIrp->IoStatus.Information = NT_SUCCESS(Status) ? ((ULONG_PTR)FCB->Connection.Handle) : 0;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_CONNECT]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
AFD_DbgPrint(MID_TRACE,("Completing connect %x\n", NextIrp));
|
||||
NextIrp->IoStatus.Status = Status;
|
||||
NextIrp->IoStatus.Information = NT_SUCCESS(Status) ? ((ULONG_PTR)FCB->Connection.Handle) : 0;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
Status = MakeSocketIntoConnection( FCB );
|
||||
Status = MakeSocketIntoConnection( FCB );
|
||||
|
||||
if( !NT_SUCCESS(Status) ) {
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
}
|
||||
if( !NT_SUCCESS(Status) ) {
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
}
|
||||
|
||||
FCB->FilledConnectData = MIN(FCB->ConnectReturnInfo->UserDataLength, FCB->ConnectDataSize);
|
||||
if (FCB->FilledConnectData)
|
||||
|
@ -365,20 +370,20 @@ static NTSTATUS NTAPI StreamSocketConnectComplete
|
|||
FCB->FilledConnectOptions);
|
||||
}
|
||||
|
||||
if( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP,
|
||||
Tail.Overlay.ListEntry);
|
||||
AFD_DbgPrint(MID_TRACE,("Launching send request %x\n", NextIrp));
|
||||
Status = AfdConnectedSocketWriteData
|
||||
( DeviceObject,
|
||||
NextIrp,
|
||||
IoGetCurrentIrpStackLocation( NextIrp ),
|
||||
FALSE );
|
||||
}
|
||||
if( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP,
|
||||
Tail.Overlay.ListEntry);
|
||||
AFD_DbgPrint(MID_TRACE,("Launching send request %x\n", NextIrp));
|
||||
Status = AfdConnectedSocketWriteData
|
||||
( DeviceObject,
|
||||
NextIrp,
|
||||
IoGetCurrentIrpStackLocation( NextIrp ),
|
||||
FALSE );
|
||||
}
|
||||
|
||||
if( Status == STATUS_PENDING )
|
||||
Status = STATUS_SUCCESS;
|
||||
if( Status == STATUS_PENDING )
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
|
@ -390,9 +395,10 @@ static NTSTATUS NTAPI StreamSocketConnectComplete
|
|||
|
||||
/* Return the socket object for ths request only if it is a connected or
|
||||
stream type. */
|
||||
NTSTATUS NTAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
NTSTATUS Status = STATUS_INVALID_PARAMETER;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -401,93 +407,93 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
if( !(ConnectReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp,
|
||||
0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp,
|
||||
0 );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Connect request:\n"));
|
||||
#if 0
|
||||
OskitDumpBuffer
|
||||
( (PCHAR)ConnectReq,
|
||||
IrpSp->Parameters.DeviceIoControl.InputBufferLength );
|
||||
( (PCHAR)ConnectReq,
|
||||
IrpSp->Parameters.DeviceIoControl.InputBufferLength );
|
||||
#endif
|
||||
|
||||
if( FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS )
|
||||
{
|
||||
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
|
||||
FCB->RemoteAddress =
|
||||
TaCopyTransportAddress( &ConnectReq->RemoteAddress );
|
||||
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
|
||||
FCB->RemoteAddress =
|
||||
TaCopyTransportAddress( &ConnectReq->RemoteAddress );
|
||||
|
||||
if( !FCB->RemoteAddress )
|
||||
Status = STATUS_NO_MEMORY;
|
||||
else
|
||||
Status = STATUS_SUCCESS;
|
||||
if( !FCB->RemoteAddress )
|
||||
Status = STATUS_NO_MEMORY;
|
||||
else
|
||||
Status = STATUS_SUCCESS;
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
}
|
||||
|
||||
switch( FCB->State ) {
|
||||
case SOCKET_STATE_CONNECTED:
|
||||
Status = STATUS_SUCCESS;
|
||||
break;
|
||||
Status = STATUS_SUCCESS;
|
||||
break;
|
||||
|
||||
case SOCKET_STATE_CONNECTING:
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_CONNECT );
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_CONNECT );
|
||||
|
||||
case SOCKET_STATE_CREATED:
|
||||
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
|
||||
FCB->LocalAddress =
|
||||
TaBuildNullTransportAddress( ConnectReq->RemoteAddress.Address[0].AddressType );
|
||||
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
|
||||
FCB->LocalAddress =
|
||||
TaBuildNullTransportAddress( ConnectReq->RemoteAddress.Address[0].AddressType );
|
||||
|
||||
if( FCB->LocalAddress ) {
|
||||
Status = WarmSocketForBind( FCB );
|
||||
if( FCB->LocalAddress ) {
|
||||
Status = WarmSocketForBind( FCB );
|
||||
|
||||
if( NT_SUCCESS(Status) )
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
else
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
} else
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_NO_MEMORY, Irp, 0 );
|
||||
|
||||
if( NT_SUCCESS(Status) )
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
else
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
} else
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_NO_MEMORY, Irp, 0 );
|
||||
|
||||
/* Drop through to SOCKET_STATE_BOUND */
|
||||
|
||||
case SOCKET_STATE_BOUND:
|
||||
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
|
||||
FCB->RemoteAddress =
|
||||
TaCopyTransportAddress( &ConnectReq->RemoteAddress );
|
||||
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
|
||||
FCB->RemoteAddress =
|
||||
TaCopyTransportAddress( &ConnectReq->RemoteAddress );
|
||||
|
||||
if( !FCB->RemoteAddress ) {
|
||||
Status = STATUS_NO_MEMORY;
|
||||
break;
|
||||
}
|
||||
if( !FCB->RemoteAddress ) {
|
||||
Status = STATUS_NO_MEMORY;
|
||||
break;
|
||||
}
|
||||
|
||||
Status = WarmSocketForConnection( FCB );
|
||||
Status = WarmSocketForConnection( FCB );
|
||||
|
||||
if( !NT_SUCCESS(Status) )
|
||||
break;
|
||||
if( !NT_SUCCESS(Status) )
|
||||
break;
|
||||
|
||||
if (FCB->ConnectReturnInfo) ExFreePool(FCB->ConnectReturnInfo);
|
||||
Status = TdiBuildConnectionInfo
|
||||
( &FCB->ConnectReturnInfo,
|
||||
&ConnectReq->RemoteAddress );
|
||||
Status = TdiBuildConnectionInfo
|
||||
( &FCB->ConnectReturnInfo,
|
||||
&ConnectReq->RemoteAddress );
|
||||
|
||||
if( NT_SUCCESS(Status) )
|
||||
{
|
||||
if (FCB->ConnectCallInfo) ExFreePool(FCB->ConnectCallInfo);
|
||||
Status = TdiBuildConnectionInfo(&FCB->ConnectCallInfo,
|
||||
&ConnectReq->RemoteAddress);
|
||||
&ConnectReq->RemoteAddress);
|
||||
}
|
||||
else break;
|
||||
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
FCB->ConnectCallInfo->UserData = FCB->ConnectData;
|
||||
FCB->ConnectCallInfo->UserDataLength = FCB->ConnectDataSize;
|
||||
FCB->ConnectCallInfo->Options = FCB->ConnectOptions;
|
||||
FCB->ConnectCallInfo->OptionsLength = FCB->ConnectOptionsSize;
|
||||
|
||||
|
||||
FCB->State = SOCKET_STATE_CONNECTING;
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Queueing IRP %x\n", Irp));
|
||||
Status = QueueUserModeIrp( FCB, Irp, FUNCTION_CONNECT );
|
||||
if (Status == STATUS_PENDING)
|
||||
|
@ -500,20 +506,20 @@ AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
StreamSocketConnectComplete,
|
||||
FCB );
|
||||
}
|
||||
|
||||
|
||||
if (Status != STATUS_PENDING)
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
return Status;
|
||||
}
|
||||
break;
|
||||
return Status;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
AFD_DbgPrint(MIN_TRACE,("Inappropriate socket state %d for connect\n",
|
||||
FCB->State));
|
||||
break;
|
||||
AFD_DbgPrint(MIN_TRACE,("Inappropriate socket state %d for connect\n",
|
||||
FCB->State));
|
||||
break;
|
||||
}
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_INVALID_PARAMETER;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -22,10 +22,10 @@ AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( FCB->ContextSize < ContextSize ) ContextSize = FCB->ContextSize;
|
||||
|
||||
if( FCB->Context ) {
|
||||
RtlCopyMemory( Irp->UserBuffer,
|
||||
FCB->Context,
|
||||
ContextSize );
|
||||
Status = STATUS_SUCCESS;
|
||||
RtlCopyMemory( Irp->UserBuffer,
|
||||
FCB->Context,
|
||||
ContextSize );
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
|
@ -35,7 +35,7 @@ AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetContextSize( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp )
|
||||
PIO_STACK_LOCATION IrpSp )
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -57,31 +57,31 @@ AfdGetContextSize( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdSetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
PVOID Context = LockRequest(Irp, IrpSp);
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
|
||||
|
||||
if (!Context)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
if( FCB->Context ) {
|
||||
ExFreePool( FCB->Context );
|
||||
FCB->ContextSize = 0;
|
||||
ExFreePool( FCB->Context );
|
||||
FCB->ContextSize = 0;
|
||||
}
|
||||
|
||||
FCB->Context = ExAllocatePool( PagedPool,
|
||||
IrpSp->Parameters.DeviceIoControl.InputBufferLength );
|
||||
IrpSp->Parameters.DeviceIoControl.InputBufferLength );
|
||||
|
||||
if( !FCB->Context ) return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );
|
||||
|
||||
FCB->ContextSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
RtlCopyMemory( FCB->Context,
|
||||
Context,
|
||||
FCB->ContextSize );
|
||||
Context,
|
||||
FCB->ContextSize );
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp, 0 );
|
||||
}
|
||||
|
|
|
@ -44,48 +44,48 @@ NTSTATUS AfdEventReceive(
|
|||
IN PVOID Tsdu,
|
||||
OUT PIRP *IoRequestPacket)
|
||||
{
|
||||
PAFDFCB FCB = (PAFDFCB)TdiEventContext;
|
||||
PVOID ReceiveBuffer;
|
||||
PAFD_BUFFER Buffer;
|
||||
KIRQL OldIrql;
|
||||
PAFDFCB FCB = (PAFDFCB)TdiEventContext;
|
||||
PVOID ReceiveBuffer;
|
||||
PAFD_BUFFER Buffer;
|
||||
KIRQL OldIrql;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
|
||||
AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes on socket\n",
|
||||
BytesAvailable));
|
||||
AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes on socket\n",
|
||||
BytesAvailable));
|
||||
|
||||
ReceiveBuffer = ExAllocatePool(NonPagedPool, BytesAvailable);
|
||||
if (!ReceiveBuffer)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
ReceiveBuffer = ExAllocatePool(NonPagedPool, BytesAvailable);
|
||||
if (!ReceiveBuffer)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
/*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
|
||||
&BufferLookasideList);*/
|
||||
Buffer = (PAFD_BUFFER)ExAllocatePool(NonPagedPool, sizeof(AFD_BUFFER));
|
||||
if (!Buffer) {
|
||||
ExFreePool(ReceiveBuffer);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
/*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
|
||||
&BufferLookasideList);*/
|
||||
Buffer = (PAFD_BUFFER)ExAllocatePool(NonPagedPool, sizeof(AFD_BUFFER));
|
||||
if (!Buffer) {
|
||||
ExFreePool(ReceiveBuffer);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
/* Copy the data to a local buffer */
|
||||
RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
|
||||
/* Copy the data to a local buffer */
|
||||
RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
|
||||
|
||||
Buffer->Buffer.len = BytesAvailable;
|
||||
Buffer->Buffer.buf = ReceiveBuffer;
|
||||
Buffer->Offset = 0;
|
||||
Buffer->Buffer.len = BytesAvailable;
|
||||
Buffer->Buffer.buf = ReceiveBuffer;
|
||||
Buffer->Offset = 0;
|
||||
|
||||
KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
|
||||
KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
|
||||
|
||||
InsertTailList( &FCB->ReceiveQueue, &Buffer->ListEntry );
|
||||
InsertTailList( &FCB->ReceiveQueue, &Buffer->ListEntry );
|
||||
|
||||
TryToSatisfyRecvRequest( FCB, TRUE );
|
||||
TryToSatisfyRecvRequest( FCB, TRUE );
|
||||
|
||||
KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
|
||||
KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
|
||||
|
||||
*BytesTaken = BytesAvailable;
|
||||
*BytesTaken = BytesAvailable;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,89 +121,87 @@ NTSTATUS ClientEventChainedReceive(
|
|||
|
||||
|
||||
NTSTATUS AfdEventReceiveDatagramHandler(
|
||||
IN PVOID TdiEventContext,
|
||||
IN LONG SourceAddressLength,
|
||||
IN PVOID SourceAddress,
|
||||
IN LONG OptionsLength,
|
||||
IN PVOID Options,
|
||||
IN ULONG ReceiveDatagramFlags,
|
||||
IN ULONG BytesIndicated,
|
||||
IN ULONG BytesAvailable,
|
||||
OUT ULONG *BytesTaken,
|
||||
IN PVOID Tsdu,
|
||||
OUT PIRP *IoRequestPacket)
|
||||
IN PVOID TdiEventContext,
|
||||
IN LONG SourceAddressLength,
|
||||
IN PVOID SourceAddress,
|
||||
IN LONG OptionsLength,
|
||||
IN PVOID Options,
|
||||
IN ULONG ReceiveDatagramFlags,
|
||||
IN ULONG BytesIndicated,
|
||||
IN ULONG BytesAvailable,
|
||||
OUT ULONG *BytesTaken,
|
||||
IN PVOID Tsdu,
|
||||
OUT PIRP *IoRequestPacket)
|
||||
{
|
||||
PAFDFCB FCB = (PAFDFCB)TdiEventContext;
|
||||
PAFD_READ_REQUEST ReadRequest;
|
||||
PVOID ReceiveBuffer;
|
||||
PAFD_BUFFER Buffer;
|
||||
PLIST_ENTRY Entry;
|
||||
NTSTATUS Status;
|
||||
KIRQL OldIrql;
|
||||
ULONG Count;
|
||||
BOOLEAN CompleteIrp;
|
||||
PAFDFCB FCB = (PAFDFCB)TdiEventContext;
|
||||
PAFD_READ_REQUEST ReadRequest;
|
||||
PVOID ReceiveBuffer;
|
||||
PAFD_BUFFER Buffer;
|
||||
PLIST_ENTRY Entry;
|
||||
NTSTATUS Status;
|
||||
KIRQL OldIrql;
|
||||
ULONG Count;
|
||||
BOOLEAN CompleteIrp;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
|
||||
|
||||
AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes from (0x%X).\n",
|
||||
BytesAvailable, *(PULONG)SourceAddress));
|
||||
AFD_DbgPrint(MID_TRACE, ("Receiving (%d) bytes from (0x%X).\n",
|
||||
BytesAvailable, *(PULONG)SourceAddress));
|
||||
|
||||
ReceiveBuffer = ExAllocatePool(NonPagedPool, BytesAvailable);
|
||||
if (!ReceiveBuffer)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
ReceiveBuffer = ExAllocatePool(NonPagedPool, BytesAvailable);
|
||||
if (!ReceiveBuffer)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
/*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
|
||||
&BufferLookasideList);*/
|
||||
Buffer = (PAFD_BUFFER)ExAllocatePool(NonPagedPool, sizeof(AFD_BUFFER));
|
||||
if (!Buffer) {
|
||||
ExFreePool(ReceiveBuffer);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
/*Buffer = (PAFD_BUFFER)ExAllocateFromNPagedLookasideList(
|
||||
&BufferLookasideList);*/
|
||||
Buffer = (PAFD_BUFFER)ExAllocatePool(NonPagedPool, sizeof(AFD_BUFFER));
|
||||
if (!Buffer) {
|
||||
ExFreePool(ReceiveBuffer);
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
/* Copy the data to a local buffer */
|
||||
RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
|
||||
/* Copy the data to a local buffer */
|
||||
RtlCopyMemory(ReceiveBuffer, Tsdu, BytesAvailable);
|
||||
|
||||
Buffer->Buffer.len = BytesAvailable;
|
||||
Buffer->Buffer.buf = ReceiveBuffer;
|
||||
Buffer->Offset = 0;
|
||||
Buffer->Buffer.len = BytesAvailable;
|
||||
Buffer->Buffer.buf = ReceiveBuffer;
|
||||
Buffer->Offset = 0;
|
||||
|
||||
ExInterlockedInsertTailList(
|
||||
&FCB->ReceiveQueue,
|
||||
&Buffer->ListEntry,
|
||||
&FCB->ReceiveQueueLock);
|
||||
ExInterlockedInsertTailList(&FCB->ReceiveQueue,
|
||||
&Buffer->ListEntry,
|
||||
&FCB->ReceiveQueueLock);
|
||||
|
||||
KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
|
||||
KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
|
||||
|
||||
if (CompleteIrp = !IsListEmpty(&FCB->ReadRequestQueue)) {
|
||||
AFD_DbgPrint(MAX_TRACE, ("Satisfying read request.\n"));
|
||||
if (CompleteIrp = !IsListEmpty(&FCB->ReadRequestQueue)) {
|
||||
AFD_DbgPrint(MAX_TRACE, ("Satisfying read request.\n"));
|
||||
|
||||
Entry = RemoveHeadList(&FCB->ReceiveQueue);
|
||||
ReadRequest = CONTAINING_RECORD(Entry, AFD_READ_REQUEST, ListEntry);
|
||||
Entry = RemoveHeadList(&FCB->ReceiveQueue);
|
||||
ReadRequest = CONTAINING_RECORD(Entry, AFD_READ_REQUEST, ListEntry);
|
||||
|
||||
Status = FillWSABuffers(
|
||||
FCB,
|
||||
ReadRequest->RecvFromRequest->Buffers,
|
||||
ReadRequest->RecvFromRequest->BufferCount,
|
||||
&Count,
|
||||
FALSE ); /* Packet oriented */
|
||||
ReadRequest->RecvFromReply->NumberOfBytesRecvd = Count;
|
||||
ReadRequest->RecvFromReply->Status = NO_ERROR;
|
||||
Status = FillWSABuffers(FCB,
|
||||
ReadRequest->RecvFromRequest->Buffers,
|
||||
ReadRequest->RecvFromRequest->BufferCount,
|
||||
&Count,
|
||||
FALSE); /* Packet oriented */
|
||||
ReadRequest->RecvFromReply->NumberOfBytesRecvd = Count;
|
||||
ReadRequest->RecvFromReply->Status = NO_ERROR;
|
||||
|
||||
ReadRequest->Irp->IoStatus.Information = 0;
|
||||
ReadRequest->Irp->IoStatus.Status = Status;
|
||||
}
|
||||
ReadRequest->Irp->IoStatus.Information = 0;
|
||||
ReadRequest->Irp->IoStatus.Status = Status;
|
||||
}
|
||||
|
||||
KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
|
||||
KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
|
||||
|
||||
if (CompleteIrp) {
|
||||
AFD_DbgPrint(MAX_TRACE, ("Completing IRP at (0x%X).\n", ReadRequest->Irp));
|
||||
IoCompleteRequest(ReadRequest->Irp, IO_NETWORK_INCREMENT);
|
||||
*BytesTaken = BytesAvailable;
|
||||
}
|
||||
if (CompleteIrp) {
|
||||
AFD_DbgPrint(MAX_TRACE, ("Completing IRP at (0x%X).\n", ReadRequest->Irp));
|
||||
IoCompleteRequest(ReadRequest->Irp, IO_NETWORK_INCREMENT);
|
||||
*BytesTaken = BytesAvailable;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PAFD_INFO InfoReq = LockRequest(Irp, IrpSp);
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
|
@ -19,34 +19,34 @@ AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
PLIST_ENTRY CurrentEntry;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called %x %x\n", InfoReq,
|
||||
InfoReq ? InfoReq->InformationClass : 0));
|
||||
InfoReq ? InfoReq->InformationClass : 0));
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
|
||||
|
||||
if (!InfoReq)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
_SEH2_TRY {
|
||||
switch( InfoReq->InformationClass ) {
|
||||
case AFD_INFO_RECEIVE_WINDOW_SIZE:
|
||||
InfoReq->Information.Ulong = FCB->Recv.Size;
|
||||
break;
|
||||
switch( InfoReq->InformationClass ) {
|
||||
case AFD_INFO_RECEIVE_WINDOW_SIZE:
|
||||
InfoReq->Information.Ulong = FCB->Recv.Size;
|
||||
break;
|
||||
|
||||
case AFD_INFO_SEND_WINDOW_SIZE:
|
||||
InfoReq->Information.Ulong = FCB->Send.Size;
|
||||
AFD_DbgPrint(MID_TRACE,("Send window size %d\n", FCB->Send.Size));
|
||||
break;
|
||||
case AFD_INFO_SEND_WINDOW_SIZE:
|
||||
InfoReq->Information.Ulong = FCB->Send.Size;
|
||||
AFD_DbgPrint(MID_TRACE,("Send window size %d\n", FCB->Send.Size));
|
||||
break;
|
||||
|
||||
case AFD_INFO_GROUP_ID_TYPE:
|
||||
InfoReq->Information.LargeInteger.u.HighPart = FCB->GroupType;
|
||||
InfoReq->Information.LargeInteger.u.LowPart = FCB->GroupID;
|
||||
AFD_DbgPrint(MID_TRACE, ("Group ID: %d Group Type: %d\n", FCB->GroupID, FCB->GroupType));
|
||||
break;
|
||||
case AFD_INFO_GROUP_ID_TYPE:
|
||||
InfoReq->Information.LargeInteger.u.HighPart = FCB->GroupType;
|
||||
InfoReq->Information.LargeInteger.u.LowPart = FCB->GroupID;
|
||||
AFD_DbgPrint(MID_TRACE, ("Group ID: %d Group Type: %d\n", FCB->GroupID, FCB->GroupType));
|
||||
break;
|
||||
|
||||
case AFD_INFO_BLOCKING_MODE:
|
||||
InfoReq->Information.Boolean = FCB->NonBlocking;
|
||||
break;
|
||||
|
||||
case AFD_INFO_BLOCKING_MODE:
|
||||
InfoReq->Information.Boolean = FCB->NonBlocking;
|
||||
break;
|
||||
|
||||
case AFD_INFO_INLINING_MODE:
|
||||
InfoReq->Information.Boolean = FCB->OobInline;
|
||||
break;
|
||||
|
@ -59,16 +59,16 @@ AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
break;
|
||||
|
||||
case AFD_INFO_SENDS_IN_PROGRESS:
|
||||
case AFD_INFO_SENDS_IN_PROGRESS:
|
||||
InfoReq->Information.Ulong = 0;
|
||||
|
||||
/* Count the queued sends */
|
||||
CurrentEntry = FCB->PendingIrpList[FUNCTION_SEND].Flink;
|
||||
while (CurrentEntry != &FCB->PendingIrpList[FUNCTION_SEND])
|
||||
{
|
||||
InfoReq->Information.Ulong++;
|
||||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
/* Count the queued sends */
|
||||
CurrentEntry = FCB->PendingIrpList[FUNCTION_SEND].Flink;
|
||||
while (CurrentEntry != &FCB->PendingIrpList[FUNCTION_SEND])
|
||||
{
|
||||
InfoReq->Information.Ulong++;
|
||||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
|
||||
/* This needs to count too because when this is dispatched
|
||||
* the user-mode IRP has already been completed and therefore
|
||||
|
@ -83,15 +83,15 @@ AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
InfoReq->Information.Ulong++;
|
||||
break;
|
||||
|
||||
default:
|
||||
AFD_DbgPrint(MIN_TRACE,("Unknown info id %x\n",
|
||||
InfoReq->InformationClass));
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
AFD_DbgPrint(MIN_TRACE,("Unknown info id %x\n",
|
||||
InfoReq->InformationClass));
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
break;
|
||||
}
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE,("Exception executing GetInfo\n"));
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE,("Exception executing GetInfo\n"));
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
} _SEH2_END;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
|
@ -109,78 +109,78 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
PCHAR NewBuffer;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!InfoReq)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
_SEH2_TRY {
|
||||
switch (InfoReq->InformationClass) {
|
||||
case AFD_INFO_BLOCKING_MODE:
|
||||
AFD_DbgPrint(MID_TRACE,("Blocking mode set to %d\n", InfoReq->Information.Boolean));
|
||||
FCB->NonBlocking = InfoReq->Information.Boolean;
|
||||
break;
|
||||
case AFD_INFO_INLINING_MODE:
|
||||
FCB->OobInline = InfoReq->Information.Boolean;
|
||||
break;
|
||||
case AFD_INFO_RECEIVE_WINDOW_SIZE:
|
||||
NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong);
|
||||
if (NewBuffer)
|
||||
{
|
||||
if (FCB->Recv.Content > InfoReq->Information.Ulong)
|
||||
FCB->Recv.Content = InfoReq->Information.Ulong;
|
||||
|
||||
if (FCB->Recv.Window)
|
||||
{
|
||||
RtlCopyMemory(NewBuffer,
|
||||
FCB->Recv.Window,
|
||||
FCB->Recv.Content);
|
||||
|
||||
ExFreePool(FCB->Recv.Window);
|
||||
}
|
||||
|
||||
FCB->Recv.Size = InfoReq->Information.Ulong;
|
||||
FCB->Recv.Window = NewBuffer;
|
||||
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = STATUS_NO_MEMORY;
|
||||
}
|
||||
break;
|
||||
case AFD_INFO_SEND_WINDOW_SIZE:
|
||||
NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong);
|
||||
if (NewBuffer)
|
||||
{
|
||||
if (FCB->Send.BytesUsed > InfoReq->Information.Ulong)
|
||||
FCB->Send.BytesUsed = InfoReq->Information.Ulong;
|
||||
|
||||
if (FCB->Send.Window)
|
||||
{
|
||||
RtlCopyMemory(NewBuffer,
|
||||
FCB->Send.Window,
|
||||
FCB->Send.BytesUsed);
|
||||
|
||||
ExFreePool(FCB->Send.Window);
|
||||
}
|
||||
|
||||
FCB->Send.Size = InfoReq->Information.Ulong;
|
||||
FCB->Send.Window = NewBuffer;
|
||||
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = STATUS_NO_MEMORY;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
AFD_DbgPrint(MIN_TRACE,("Unknown request %d\n", InfoReq->InformationClass));
|
||||
break;
|
||||
}
|
||||
switch (InfoReq->InformationClass) {
|
||||
case AFD_INFO_BLOCKING_MODE:
|
||||
AFD_DbgPrint(MID_TRACE,("Blocking mode set to %d\n", InfoReq->Information.Boolean));
|
||||
FCB->NonBlocking = InfoReq->Information.Boolean;
|
||||
break;
|
||||
case AFD_INFO_INLINING_MODE:
|
||||
FCB->OobInline = InfoReq->Information.Boolean;
|
||||
break;
|
||||
case AFD_INFO_RECEIVE_WINDOW_SIZE:
|
||||
NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong);
|
||||
if (NewBuffer)
|
||||
{
|
||||
if (FCB->Recv.Content > InfoReq->Information.Ulong)
|
||||
FCB->Recv.Content = InfoReq->Information.Ulong;
|
||||
|
||||
if (FCB->Recv.Window)
|
||||
{
|
||||
RtlCopyMemory(NewBuffer,
|
||||
FCB->Recv.Window,
|
||||
FCB->Recv.Content);
|
||||
|
||||
ExFreePool(FCB->Recv.Window);
|
||||
}
|
||||
|
||||
FCB->Recv.Size = InfoReq->Information.Ulong;
|
||||
FCB->Recv.Window = NewBuffer;
|
||||
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = STATUS_NO_MEMORY;
|
||||
}
|
||||
break;
|
||||
case AFD_INFO_SEND_WINDOW_SIZE:
|
||||
NewBuffer = ExAllocatePool(PagedPool, InfoReq->Information.Ulong);
|
||||
if (NewBuffer)
|
||||
{
|
||||
if (FCB->Send.BytesUsed > InfoReq->Information.Ulong)
|
||||
FCB->Send.BytesUsed = InfoReq->Information.Ulong;
|
||||
|
||||
if (FCB->Send.Window)
|
||||
{
|
||||
RtlCopyMemory(NewBuffer,
|
||||
FCB->Send.Window,
|
||||
FCB->Send.BytesUsed);
|
||||
|
||||
ExFreePool(FCB->Send.Window);
|
||||
}
|
||||
|
||||
FCB->Send.Size = InfoReq->Information.Ulong;
|
||||
FCB->Send.Window = NewBuffer;
|
||||
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = STATUS_NO_MEMORY;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
AFD_DbgPrint(MIN_TRACE,("Unknown request %d\n", InfoReq->InformationClass));
|
||||
break;
|
||||
}
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE,("Exception executing SetInfo\n"));
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE,("Exception executing SetInfo\n"));
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
} _SEH2_END;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
|
@ -190,7 +190,7 @@ AfdSetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -199,29 +199,29 @@ AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
|
||||
if( FCB->AddressFile.Object == NULL && FCB->Connection.Object == NULL ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER, Irp, 0 );
|
||||
}
|
||||
|
||||
Mdl = IoAllocateMdl
|
||||
( Irp->UserBuffer,
|
||||
IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL );
|
||||
Mdl = IoAllocateMdl( Irp->UserBuffer,
|
||||
IrpSp->Parameters.DeviceIoControl.OutputBufferLength,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL );
|
||||
|
||||
if( Mdl != NULL ) {
|
||||
_SEH2_TRY {
|
||||
MmProbeAndLockPages( Mdl, Irp->RequestorMode, IoModifyAccess );
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||
Status = _SEH2_GetExceptionCode();
|
||||
} _SEH2_END;
|
||||
_SEH2_TRY {
|
||||
MmProbeAndLockPages( Mdl, Irp->RequestorMode, IoModifyAccess );
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||
Status = _SEH2_GetExceptionCode();
|
||||
} _SEH2_END;
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
Status = TdiQueryInformation
|
||||
( FCB->Connection.Object ? FCB->Connection.Object : FCB->AddressFile.Object,
|
||||
TDI_QUERY_ADDRESS_INFO,
|
||||
Mdl );
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
Status = TdiQueryInformation( FCB->Connection.Object
|
||||
? FCB->Connection.Object
|
||||
: FCB->AddressFile.Object,
|
||||
TDI_QUERY_ADDRESS_INFO,
|
||||
Mdl );
|
||||
}
|
||||
} else
|
||||
Status = STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
@ -231,7 +231,7 @@ AfdGetSockName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetPeerName( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include "afd.h"
|
||||
|
||||
static NTSTATUS SatisfyAccept( PAFD_DEVICE_EXTENSION DeviceExt,
|
||||
PIRP Irp,
|
||||
PFILE_OBJECT NewFileObject,
|
||||
PAFD_TDI_OBJECT_QELT Qelt ) {
|
||||
PIRP Irp,
|
||||
PFILE_OBJECT NewFileObject,
|
||||
PAFD_TDI_OBJECT_QELT Qelt ) {
|
||||
PAFD_FCB FCB = NewFileObject->FsContext;
|
||||
NTSTATUS Status;
|
||||
|
||||
|
@ -26,16 +26,16 @@ static NTSTATUS SatisfyAccept( PAFD_DEVICE_EXTENSION DeviceExt,
|
|||
|
||||
if( FCB->RemoteAddress ) ExFreePool( FCB->RemoteAddress );
|
||||
FCB->RemoteAddress =
|
||||
TaCopyTransportAddress( Qelt->ConnInfo->RemoteAddress );
|
||||
TaCopyTransportAddress( Qelt->ConnInfo->RemoteAddress );
|
||||
|
||||
if( !FCB->RemoteAddress )
|
||||
Status = STATUS_NO_MEMORY;
|
||||
if( !FCB->RemoteAddress )
|
||||
Status = STATUS_NO_MEMORY;
|
||||
else
|
||||
Status = MakeSocketIntoConnection( FCB );
|
||||
Status = MakeSocketIntoConnection( FCB );
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
Status = TdiBuildConnectionInfo(&FCB->ConnectCallInfo, FCB->RemoteAddress);
|
||||
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
Status = TdiBuildConnectionInfo(&FCB->ConnectReturnInfo, FCB->RemoteAddress);
|
||||
|
||||
|
@ -44,7 +44,7 @@ static NTSTATUS SatisfyAccept( PAFD_DEVICE_EXTENSION DeviceExt,
|
|||
|
||||
static NTSTATUS SatisfyPreAccept( PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt ) {
|
||||
PAFD_RECEIVED_ACCEPT_DATA ListenReceive =
|
||||
(PAFD_RECEIVED_ACCEPT_DATA)Irp->AssociatedIrp.SystemBuffer;
|
||||
(PAFD_RECEIVED_ACCEPT_DATA)Irp->AssociatedIrp.SystemBuffer;
|
||||
PTA_IP_ADDRESS IPAddr;
|
||||
|
||||
ListenReceive->SequenceNumber = Qelt->Seq;
|
||||
|
@ -55,7 +55,7 @@ static NTSTATUS SatisfyPreAccept( PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt ) {
|
|||
Qelt->ConnInfo->RemoteAddress));
|
||||
|
||||
TaCopyTransportAddressInPlace( &ListenReceive->Address,
|
||||
Qelt->ConnInfo->RemoteAddress );
|
||||
Qelt->ConnInfo->RemoteAddress );
|
||||
|
||||
IPAddr = (PTA_IP_ADDRESS)&ListenReceive->Address;
|
||||
|
||||
|
@ -79,10 +79,9 @@ static NTSTATUS SatisfyPreAccept( PIRP Irp, PAFD_TDI_OBJECT_QELT Qelt ) {
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static NTSTATUS NTAPI ListenComplete
|
||||
( PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp,
|
||||
PVOID Context ) {
|
||||
static NTSTATUS NTAPI ListenComplete( PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp,
|
||||
PVOID Context ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PAFD_FCB FCB = (PAFD_FCB)Context;
|
||||
PAFD_TDI_OBJECT_QELT Qelt;
|
||||
|
@ -98,13 +97,13 @@ static NTSTATUS NTAPI ListenComplete
|
|||
if( FCB->State == SOCKET_STATE_CLOSED ) {
|
||||
/* Cleanup our IRP queue because the FCB is being destroyed */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_PREACCEPT] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_PREACCEPT]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_PREACCEPT]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
/* Free ConnectionReturnInfo and ConnectionCallInfo */
|
||||
|
@ -120,13 +119,13 @@ static NTSTATUS NTAPI ListenComplete
|
|||
FCB->ListenIrp.ConnectionCallInfo = NULL;
|
||||
}
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Completing listen request.\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("IoStatus was %x\n", Irp->IoStatus.Status));
|
||||
|
||||
|
||||
if (Irp->IoStatus.Status != STATUS_SUCCESS)
|
||||
{
|
||||
SocketStateUnlock(FCB);
|
||||
|
@ -135,13 +134,13 @@ static NTSTATUS NTAPI ListenComplete
|
|||
|
||||
Qelt = ExAllocatePool( NonPagedPool, sizeof(*Qelt) );
|
||||
if( !Qelt ) {
|
||||
Status = STATUS_NO_MEMORY;
|
||||
Status = STATUS_NO_MEMORY;
|
||||
} else {
|
||||
UINT AddressType =
|
||||
FCB->LocalAddress->Address[0].AddressType;
|
||||
|
||||
Qelt->Object = FCB->Connection;
|
||||
Qelt->Seq = FCB->ConnSeq++;
|
||||
Qelt->Object = FCB->Connection;
|
||||
Qelt->Seq = FCB->ConnSeq++;
|
||||
AFD_DbgPrint(MID_TRACE,("Address Type: %d (RA %x)\n",
|
||||
AddressType,
|
||||
FCB->ListenIrp.
|
||||
|
@ -158,30 +157,30 @@ static NTSTATUS NTAPI ListenComplete
|
|||
|
||||
/* Satisfy a pre-accept request if one is available */
|
||||
if( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_PREACCEPT] ) &&
|
||||
!IsListEmpty( &FCB->PendingConnections ) ) {
|
||||
PLIST_ENTRY PendingIrp =
|
||||
RemoveHeadList( &FCB->PendingIrpList[FUNCTION_PREACCEPT] );
|
||||
PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
|
||||
SatisfyPreAccept
|
||||
( CONTAINING_RECORD( PendingIrp, IRP,
|
||||
Tail.Overlay.ListEntry ),
|
||||
CONTAINING_RECORD( PendingConn, AFD_TDI_OBJECT_QELT,
|
||||
ListEntry ) );
|
||||
!IsListEmpty( &FCB->PendingConnections ) ) {
|
||||
PLIST_ENTRY PendingIrp =
|
||||
RemoveHeadList( &FCB->PendingIrpList[FUNCTION_PREACCEPT] );
|
||||
PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
|
||||
SatisfyPreAccept
|
||||
( CONTAINING_RECORD( PendingIrp, IRP,
|
||||
Tail.Overlay.ListEntry ),
|
||||
CONTAINING_RECORD( PendingConn, AFD_TDI_OBJECT_QELT,
|
||||
ListEntry ) );
|
||||
}
|
||||
|
||||
/* Launch new accept socket */
|
||||
Status = WarmSocketForConnection( FCB );
|
||||
|
||||
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
Status = TdiBuildNullConnectionInfoInPlace(FCB->ListenIrp.ConnectionCallInfo,
|
||||
FCB->LocalAddress->Address[0].AddressType);
|
||||
ASSERT(Status == STATUS_SUCCESS);
|
||||
|
||||
|
||||
Status = TdiBuildNullConnectionInfoInPlace(FCB->ListenIrp.ConnectionReturnInfo,
|
||||
FCB->LocalAddress->Address[0].AddressType);
|
||||
ASSERT(Status == STATUS_SUCCESS);
|
||||
|
||||
|
||||
Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
|
||||
FCB->Connection.Object,
|
||||
&FCB->ListenIrp.ConnectionCallInfo,
|
||||
|
@ -196,7 +195,7 @@ static NTSTATUS NTAPI ListenComplete
|
|||
|
||||
/* Trigger a select return if appropriate */
|
||||
if( !IsListEmpty( &FCB->PendingConnections ) ) {
|
||||
FCB->PollState |= AFD_EVENT_ACCEPT;
|
||||
FCB->PollState |= AFD_EVENT_ACCEPT;
|
||||
FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
} else
|
||||
|
@ -207,8 +206,8 @@ static NTSTATUS NTAPI ListenComplete
|
|||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
NTSTATUS AfdListenSocket( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -219,13 +218,13 @@ NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
|
||||
if( !(ListenReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp,
|
||||
0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp,
|
||||
0 );
|
||||
|
||||
if( FCB->State != SOCKET_STATE_BOUND ) {
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE,("Could not listen an unbound socket\n"));
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
Status = STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE,("Could not listen an unbound socket\n"));
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
}
|
||||
|
||||
FCB->DelayedAccept = ListenReq->UseDelayedAcceptance;
|
||||
|
@ -239,14 +238,14 @@ NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
|
||||
Status = TdiBuildNullConnectionInfo
|
||||
( &FCB->ListenIrp.ConnectionCallInfo,
|
||||
FCB->LocalAddress->Address[0].AddressType );
|
||||
( &FCB->ListenIrp.ConnectionCallInfo,
|
||||
FCB->LocalAddress->Address[0].AddressType );
|
||||
|
||||
if (!NT_SUCCESS(Status)) return UnlockAndMaybeComplete(FCB, Status, Irp, 0);
|
||||
|
||||
Status = TdiBuildNullConnectionInfo
|
||||
( &FCB->ListenIrp.ConnectionReturnInfo,
|
||||
FCB->LocalAddress->Address[0].AddressType );
|
||||
( &FCB->ListenIrp.ConnectionReturnInfo,
|
||||
FCB->LocalAddress->Address[0].AddressType );
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
|
@ -258,22 +257,22 @@ NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
FCB->State = SOCKET_STATE_LISTENING;
|
||||
|
||||
Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
|
||||
FCB->Connection.Object,
|
||||
&FCB->ListenIrp.ConnectionCallInfo,
|
||||
&FCB->ListenIrp.ConnectionReturnInfo,
|
||||
&FCB->ListenIrp.Iosb,
|
||||
ListenComplete,
|
||||
FCB );
|
||||
FCB->Connection.Object,
|
||||
&FCB->ListenIrp.ConnectionCallInfo,
|
||||
&FCB->ListenIrp.ConnectionReturnInfo,
|
||||
&FCB->ListenIrp.Iosb,
|
||||
ListenComplete,
|
||||
FCB );
|
||||
|
||||
if( Status == STATUS_PENDING )
|
||||
Status = STATUS_SUCCESS;
|
||||
Status = STATUS_SUCCESS;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
}
|
||||
|
||||
NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
NTSTATUS Status;
|
||||
|
@ -283,15 +282,15 @@ NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
|
||||
if( !IsListEmpty( &FCB->PendingConnections ) ) {
|
||||
PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
|
||||
PLIST_ENTRY PendingConn = FCB->PendingConnections.Flink;
|
||||
|
||||
/* We have a pending connection ... complete this irp right away */
|
||||
Status = SatisfyPreAccept
|
||||
( Irp,
|
||||
CONTAINING_RECORD
|
||||
( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry ) );
|
||||
/* We have a pending connection ... complete this irp right away */
|
||||
Status = SatisfyPreAccept
|
||||
( Irp,
|
||||
CONTAINING_RECORD
|
||||
( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry ) );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
|
||||
|
||||
if ( !IsListEmpty( &FCB->PendingConnections ) )
|
||||
{
|
||||
|
@ -301,21 +300,21 @@ NTSTATUS AfdWaitForListen( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
} else
|
||||
FCB->PollState &= ~AFD_EVENT_ACCEPT;
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
} else if (FCB->NonBlocking) {
|
||||
AFD_DbgPrint(MIN_TRACE,("No connection ready on a non-blocking socket\n"));
|
||||
|
||||
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_CANT_WAIT, Irp, 0);
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Holding\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("Holding\n"));
|
||||
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_PREACCEPT );
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_PREACCEPT );
|
||||
}
|
||||
}
|
||||
|
||||
NTSTATUS AfdAccept( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_DEVICE_EXTENSION DeviceExt =
|
||||
|
@ -329,57 +328,57 @@ NTSTATUS AfdAccept( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
|
||||
for( PendingConn = FCB->PendingConnections.Flink;
|
||||
PendingConn != &FCB->PendingConnections;
|
||||
PendingConn = PendingConn->Flink ) {
|
||||
PAFD_TDI_OBJECT_QELT PendingConnObj =
|
||||
CONTAINING_RECORD( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry );
|
||||
PendingConn != &FCB->PendingConnections;
|
||||
PendingConn = PendingConn->Flink ) {
|
||||
PAFD_TDI_OBJECT_QELT PendingConnObj =
|
||||
CONTAINING_RECORD( PendingConn, AFD_TDI_OBJECT_QELT, ListEntry );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Comparing Seq %d to Q %d\n",
|
||||
AcceptData->SequenceNumber,
|
||||
PendingConnObj->Seq));
|
||||
AFD_DbgPrint(MID_TRACE,("Comparing Seq %d to Q %d\n",
|
||||
AcceptData->SequenceNumber,
|
||||
PendingConnObj->Seq));
|
||||
|
||||
if( PendingConnObj->Seq == AcceptData->SequenceNumber ) {
|
||||
PFILE_OBJECT NewFileObject = NULL;
|
||||
if( PendingConnObj->Seq == AcceptData->SequenceNumber ) {
|
||||
PFILE_OBJECT NewFileObject = NULL;
|
||||
|
||||
RemoveEntryList( PendingConn );
|
||||
RemoveEntryList( PendingConn );
|
||||
|
||||
Status = ObReferenceObjectByHandle
|
||||
( AcceptData->ListenHandle,
|
||||
FILE_ALL_ACCESS,
|
||||
NULL,
|
||||
KernelMode,
|
||||
(PVOID *)&NewFileObject,
|
||||
NULL );
|
||||
Status = ObReferenceObjectByHandle
|
||||
( AcceptData->ListenHandle,
|
||||
FILE_ALL_ACCESS,
|
||||
NULL,
|
||||
KernelMode,
|
||||
(PVOID *)&NewFileObject,
|
||||
NULL );
|
||||
|
||||
if( !NT_SUCCESS(Status) ) return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
|
||||
ASSERT(NewFileObject != FileObject);
|
||||
ASSERT(NewFileObject->FsContext != FCB);
|
||||
|
||||
/* We have a pending connection ... complete this irp right away */
|
||||
Status = SatisfyAccept( DeviceExt, Irp, NewFileObject, PendingConnObj );
|
||||
/* We have a pending connection ... complete this irp right away */
|
||||
Status = SatisfyAccept( DeviceExt, Irp, NewFileObject, PendingConnObj );
|
||||
|
||||
ObDereferenceObject( NewFileObject );
|
||||
ObDereferenceObject( NewFileObject );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("Completed a wait for accept\n"));
|
||||
|
||||
ExFreePool( PendingConnObj );
|
||||
|
||||
FCB->EventSelectDisabled &= ~AFD_EVENT_ACCEPT;
|
||||
ExFreePool( PendingConnObj );
|
||||
|
||||
if( !IsListEmpty( &FCB->PendingConnections ) )
|
||||
{
|
||||
FCB->PollState |= AFD_EVENT_ACCEPT;
|
||||
FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
} else
|
||||
FCB->PollState &= ~AFD_EVENT_ACCEPT;
|
||||
FCB->EventSelectDisabled &= ~AFD_EVENT_ACCEPT;
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
}
|
||||
if( !IsListEmpty( &FCB->PendingConnections ) )
|
||||
{
|
||||
FCB->PollState |= AFD_EVENT_ACCEPT;
|
||||
FCB->PollStatus[FD_ACCEPT_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
} else
|
||||
FCB->PollState &= ~AFD_EVENT_ACCEPT;
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AFD_DbgPrint(MIN_TRACE,("No connection waiting\n"));
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_UNSUCCESSFUL, Irp, 0 );
|
||||
|
|
|
@ -12,16 +12,16 @@
|
|||
PVOID GetLockedData(PIRP Irp, PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
ASSERT(Irp->MdlAddress);
|
||||
|
||||
|
||||
return MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
|
||||
}
|
||||
|
||||
/* Lock a method_neither request so it'll be available from DISPATCH_LEVEL */
|
||||
PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
||||
BOOLEAN LockFailed = FALSE;
|
||||
|
||||
|
||||
ASSERT(!Irp->MdlAddress);
|
||||
|
||||
|
||||
switch (IrpSp->MajorFunction)
|
||||
{
|
||||
case IRP_MJ_DEVICE_CONTROL:
|
||||
|
@ -29,7 +29,7 @@ PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
|||
ASSERT(IrpSp->Parameters.DeviceIoControl.Type3InputBuffer);
|
||||
ASSERT(IrpSp->Parameters.DeviceIoControl.InputBufferLength);
|
||||
|
||||
|
||||
|
||||
Irp->MdlAddress =
|
||||
IoAllocateMdl( IrpSp->Parameters.DeviceIoControl.Type3InputBuffer,
|
||||
IrpSp->Parameters.DeviceIoControl.InputBufferLength,
|
||||
|
@ -42,7 +42,7 @@ PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
|||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
LockFailed = TRUE;
|
||||
} _SEH2_END;
|
||||
|
||||
|
||||
if( LockFailed ) {
|
||||
AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
|
||||
IoFreeMdl( Irp->MdlAddress );
|
||||
|
@ -51,11 +51,11 @@ PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
|||
}
|
||||
} else return NULL;
|
||||
break;
|
||||
|
||||
|
||||
case IRP_MJ_READ:
|
||||
case IRP_MJ_WRITE:
|
||||
ASSERT(Irp->UserBuffer);
|
||||
|
||||
|
||||
Irp->MdlAddress =
|
||||
IoAllocateMdl(Irp->UserBuffer,
|
||||
(IrpSp->MajorFunction == IRP_MJ_READ) ?
|
||||
|
@ -69,7 +69,7 @@ PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
|||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
LockFailed = TRUE;
|
||||
} _SEH2_END;
|
||||
|
||||
|
||||
if( LockFailed ) {
|
||||
AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
|
||||
IoFreeMdl( Irp->MdlAddress );
|
||||
|
@ -78,12 +78,12 @@ PVOID LockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp ) {
|
|||
}
|
||||
} else return NULL;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
return GetLockedData(Irp, IrpSp);
|
||||
}
|
||||
|
||||
|
@ -100,8 +100,8 @@ VOID UnlockRequest( PIRP Irp, PIO_STACK_LOCATION IrpSp )
|
|||
* for datagrams. */
|
||||
|
||||
PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
|
||||
PVOID AddressBuf, PINT AddressLen,
|
||||
BOOLEAN Write, BOOLEAN LockAddress ) {
|
||||
PVOID AddressBuf, PINT AddressLen,
|
||||
BOOLEAN Write, BOOLEAN LockAddress ) {
|
||||
UINT i;
|
||||
/* Copy the buffer array so we don't lose it */
|
||||
UINT Lock = LockAddress ? 2 : 0;
|
||||
|
@ -115,7 +115,7 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
|
|||
if( NewBuf ) {
|
||||
RtlZeroMemory(NewBuf, Size * 2);
|
||||
|
||||
MapBuf = (PAFD_MAPBUF)(NewBuf + Count + Lock);
|
||||
MapBuf = (PAFD_MAPBUF)(NewBuf + Count + Lock);
|
||||
|
||||
_SEH2_TRY {
|
||||
RtlCopyMemory( NewBuf, Buf, sizeof(AFD_WSABUF) * Count );
|
||||
|
@ -136,45 +136,45 @@ PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count,
|
|||
_SEH2_YIELD(return NULL);
|
||||
} _SEH2_END;
|
||||
|
||||
for( i = 0; i < Count; i++ ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Locking buffer %d (%x:%d)\n",
|
||||
i, NewBuf[i].buf, NewBuf[i].len));
|
||||
for( i = 0; i < Count; i++ ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Locking buffer %d (%x:%d)\n",
|
||||
i, NewBuf[i].buf, NewBuf[i].len));
|
||||
|
||||
if( NewBuf[i].buf && NewBuf[i].len ) {
|
||||
MapBuf[i].Mdl = IoAllocateMdl( NewBuf[i].buf,
|
||||
NewBuf[i].len,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL );
|
||||
} else {
|
||||
MapBuf[i].Mdl = NULL;
|
||||
continue;
|
||||
}
|
||||
if( NewBuf[i].buf && NewBuf[i].len ) {
|
||||
MapBuf[i].Mdl = IoAllocateMdl( NewBuf[i].buf,
|
||||
NewBuf[i].len,
|
||||
FALSE,
|
||||
FALSE,
|
||||
NULL );
|
||||
} else {
|
||||
MapBuf[i].Mdl = NULL;
|
||||
continue;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("NewMdl @ %x\n", MapBuf[i].Mdl));
|
||||
AFD_DbgPrint(MID_TRACE,("NewMdl @ %x\n", MapBuf[i].Mdl));
|
||||
|
||||
if( MapBuf[i].Mdl ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n"));
|
||||
_SEH2_TRY {
|
||||
MmProbeAndLockPages( MapBuf[i].Mdl, UserMode,
|
||||
Write ? IoModifyAccess : IoReadAccess );
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
LockFailed = TRUE;
|
||||
} _SEH2_END;
|
||||
AFD_DbgPrint(MID_TRACE,("MmProbeAndLock finished\n"));
|
||||
if( MapBuf[i].Mdl ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Probe and lock pages\n"));
|
||||
_SEH2_TRY {
|
||||
MmProbeAndLockPages( MapBuf[i].Mdl, UserMode,
|
||||
Write ? IoModifyAccess : IoReadAccess );
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
LockFailed = TRUE;
|
||||
} _SEH2_END;
|
||||
AFD_DbgPrint(MID_TRACE,("MmProbeAndLock finished\n"));
|
||||
|
||||
if( LockFailed ) {
|
||||
if( LockFailed ) {
|
||||
AFD_DbgPrint(MIN_TRACE,("Failed to lock pages\n"));
|
||||
IoFreeMdl( MapBuf[i].Mdl );
|
||||
MapBuf[i].Mdl = NULL;
|
||||
ExFreePool( NewBuf );
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ExFreePool( NewBuf );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
IoFreeMdl( MapBuf[i].Mdl );
|
||||
MapBuf[i].Mdl = NULL;
|
||||
ExFreePool( NewBuf );
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ExFreePool( NewBuf );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Leaving %x\n", NewBuf));
|
||||
|
@ -190,11 +190,11 @@ VOID UnlockBuffers( PAFD_WSABUF Buf, UINT Count, BOOL Address ) {
|
|||
if( !Buf ) return;
|
||||
|
||||
for( i = 0; i < Count + Lock; i++ ) {
|
||||
if( Map[i].Mdl ) {
|
||||
MmUnlockPages( Map[i].Mdl );
|
||||
IoFreeMdl( Map[i].Mdl );
|
||||
Map[i].Mdl = NULL;
|
||||
}
|
||||
if( Map[i].Mdl ) {
|
||||
MmUnlockPages( Map[i].Mdl );
|
||||
IoFreeMdl( Map[i].Mdl );
|
||||
Map[i].Mdl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ExFreePool( Buf );
|
||||
|
@ -208,22 +208,22 @@ PAFD_HANDLE LockHandles( PAFD_HANDLE HandleArray, UINT HandleCount ) {
|
|||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
PAFD_HANDLE FileObjects = ExAllocatePool
|
||||
( NonPagedPool, HandleCount * sizeof(AFD_HANDLE) );
|
||||
( NonPagedPool, HandleCount * sizeof(AFD_HANDLE) );
|
||||
|
||||
for( i = 0; FileObjects && i < HandleCount; i++ ) {
|
||||
FileObjects[i].Status = 0;
|
||||
FileObjects[i].Events = HandleArray[i].Events;
|
||||
FileObjects[i].Status = 0;
|
||||
FileObjects[i].Events = HandleArray[i].Events;
|
||||
FileObjects[i].Handle = 0;
|
||||
if( !HandleArray[i].Handle ) continue;
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
Status = ObReferenceObjectByHandle
|
||||
( (PVOID)HandleArray[i].Handle,
|
||||
FILE_ALL_ACCESS,
|
||||
NULL,
|
||||
KernelMode,
|
||||
(PVOID*)&FileObjects[i].Handle,
|
||||
NULL );
|
||||
}
|
||||
if( !HandleArray[i].Handle ) continue;
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
Status = ObReferenceObjectByHandle
|
||||
( (PVOID)HandleArray[i].Handle,
|
||||
FILE_ALL_ACCESS,
|
||||
NULL,
|
||||
KernelMode,
|
||||
(PVOID*)&FileObjects[i].Handle,
|
||||
NULL );
|
||||
}
|
||||
|
||||
if( !NT_SUCCESS(Status) )
|
||||
{
|
||||
|
@ -233,8 +233,8 @@ PAFD_HANDLE LockHandles( PAFD_HANDLE HandleArray, UINT HandleCount ) {
|
|||
}
|
||||
|
||||
if( !NT_SUCCESS(Status) ) {
|
||||
UnlockHandles( FileObjects, HandleCount );
|
||||
return NULL;
|
||||
UnlockHandles( FileObjects, HandleCount );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return FileObjects;
|
||||
|
@ -244,8 +244,8 @@ VOID UnlockHandles( PAFD_HANDLE HandleArray, UINT HandleCount ) {
|
|||
UINT i;
|
||||
|
||||
for( i = 0; i < HandleCount; i++ ) {
|
||||
if( HandleArray[i].Handle )
|
||||
ObDereferenceObject( (PVOID)HandleArray[i].Handle );
|
||||
if( HandleArray[i].Handle )
|
||||
ObDereferenceObject( (PVOID)HandleArray[i].Handle );
|
||||
}
|
||||
|
||||
ExFreePool( HandleArray );
|
||||
|
@ -292,11 +292,11 @@ NTSTATUS LostSocket( PIRP Irp ) {
|
|||
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
|
||||
/* Add the IRP to the queue in all cases (so AfdCancelHandler will work properly) */
|
||||
InsertTailList( &FCB->PendingIrpList[Function],
|
||||
&Irp->Tail.Overlay.ListEntry );
|
||||
|
||||
|
||||
/* Acquire the cancel spin lock and check the cancel bit */
|
||||
IoAcquireCancelSpinLock(&Irp->CancelIrql);
|
||||
if (!Irp->Cancel)
|
||||
|
@ -321,15 +321,15 @@ NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
|
|||
Irp);
|
||||
Status = STATUS_CANCELLED;
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
|
||||
NTSTATUS Status;
|
||||
|
||||
|
||||
Status = QueueUserModeIrp(FCB, Irp, Function);
|
||||
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
|
||||
return Status;
|
||||
|
|
|
@ -26,9 +26,9 @@ void OskitDumpBuffer( PCHAR Data, UINT Len ) {
|
|||
unsigned int i;
|
||||
|
||||
for( i = 0; i < Len; i++ ) {
|
||||
if( i && !(i & 0xf) ) DbgPrint( "\n" );
|
||||
if( !(i & 0xf) ) DbgPrint( "%08x: ", (UINT)(Data + i) );
|
||||
DbgPrint( " %02x", Data[i] & 0xff );
|
||||
if( i && !(i & 0xf) ) DbgPrint( "\n" );
|
||||
if( !(i & 0xf) ) DbgPrint( "%08x: ", (UINT)(Data + i) );
|
||||
DbgPrint( " %02x", Data[i] & 0xff );
|
||||
}
|
||||
DbgPrint("\n");
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath);
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -68,7 +68,7 @@ AfdGetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
NTSTATUS
|
||||
NTAPI
|
||||
AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -76,7 +76,7 @@ AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT DisconnectOptionsSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!DisconnectOptions)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -89,7 +89,8 @@ AfdSetDisconnectOptions(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
FCB->DisconnectOptions = ExAllocatePool(PagedPool, DisconnectOptionsSize);
|
||||
if (!FCB->DisconnectOptions) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
if (!FCB->DisconnectOptions)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
RtlCopyMemory(FCB->DisconnectOptions,
|
||||
DisconnectOptions,
|
||||
|
@ -111,7 +112,7 @@ AfdSetDisconnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!DisconnectOptionsSize)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -138,7 +139,7 @@ AfdSetDisconnectOptionsSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdGetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -154,7 +155,8 @@ AfdGetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
ASSERT(FCB->DisconnectData);
|
||||
|
||||
if (FCB->FilledDisconnectData < BufferSize) BufferSize = FCB->FilledDisconnectData;
|
||||
if (FCB->FilledDisconnectData < BufferSize)
|
||||
BufferSize = FCB->FilledDisconnectData;
|
||||
|
||||
RtlCopyMemory(Irp->UserBuffer,
|
||||
FCB->DisconnectData,
|
||||
|
@ -166,7 +168,7 @@ AfdGetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
NTSTATUS
|
||||
NTAPI
|
||||
AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -174,7 +176,7 @@ AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT DisconnectDataSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!DisconnectData)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -187,7 +189,8 @@ AfdSetDisconnectData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
FCB->DisconnectData = ExAllocatePool(PagedPool, DisconnectDataSize);
|
||||
if (!FCB->DisconnectData) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
if (!FCB->DisconnectData)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
RtlCopyMemory(FCB->DisconnectData,
|
||||
DisconnectData,
|
||||
|
@ -209,7 +212,7 @@ AfdSetDisconnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!DisconnectDataSize)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -227,7 +230,8 @@ AfdSetDisconnectDataSize(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
FCB->DisconnectData = ExAllocatePool(PagedPool, *DisconnectDataSize);
|
||||
if (!FCB->DisconnectData) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
if (!FCB->DisconnectData)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
FCB->DisconnectDataSize = *DisconnectDataSize;
|
||||
|
||||
|
@ -244,7 +248,7 @@ AfdGetTdiHandles(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
PAFD_TDI_HANDLE_DATA HandleData = Irp->UserBuffer;
|
||||
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
|
||||
if (!HandleFlags)
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
|
@ -266,7 +270,7 @@ AfdGetTdiHandles(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
static NTSTATUS NTAPI
|
||||
AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PAFD_FCB FCB;
|
||||
PFILE_OBJECT FileObject;
|
||||
PAFD_DEVICE_EXTENSION DeviceExt;
|
||||
|
@ -278,8 +282,8 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
UINT i;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,
|
||||
("AfdCreate(DeviceObject %p Irp %p)\n", DeviceObject, Irp));
|
||||
AFD_DbgPrint(MID_TRACE,("AfdCreate(DeviceObject %p Irp %p)\n",
|
||||
DeviceObject, Irp));
|
||||
|
||||
DeviceExt = DeviceObject->DeviceExtension;
|
||||
FileObject = IrpSp->FileObject;
|
||||
|
@ -290,25 +294,26 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
EaInfo = Irp->AssociatedIrp.SystemBuffer;
|
||||
|
||||
if( EaInfo ) {
|
||||
ConnectInfo = (PAFD_CREATE_PACKET)(EaInfo->EaName + EaInfo->EaNameLength + 1);
|
||||
EaInfoValue = (PWCHAR)(((PCHAR)ConnectInfo) + sizeof(AFD_CREATE_PACKET));
|
||||
ConnectInfo = (PAFD_CREATE_PACKET)(EaInfo->EaName + EaInfo->EaNameLength + 1);
|
||||
EaInfoValue = (PWCHAR)(((PCHAR)ConnectInfo) + sizeof(AFD_CREATE_PACKET));
|
||||
|
||||
//EaLength = sizeof(FILE_FULL_EA_INFORMATION) + EaInfo->EaNameLength + EaInfo->EaValueLength;
|
||||
//EaLength = sizeof(FILE_FULL_EA_INFORMATION) + EaInfo->EaNameLength + EaInfo->EaValueLength;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("EaInfo: %x, EaInfoValue: %x\n",
|
||||
EaInfo, EaInfoValue));
|
||||
AFD_DbgPrint(MID_TRACE,("EaInfo: %x, EaInfoValue: %x\n",
|
||||
EaInfo, EaInfoValue));
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("About to allocate the new FCB\n"));
|
||||
|
||||
FCB = ExAllocatePool(NonPagedPool, sizeof(AFD_FCB));
|
||||
if( FCB == NULL ) {
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Initializing the new FCB @ %x (FileObject %x Flags %x)\n", FCB, FileObject, ConnectInfo ? ConnectInfo->EndpointFlags : 0));
|
||||
AFD_DbgPrint(MID_TRACE,("Initializing the new FCB @ %x (FileObject %x Flags %x)\n",
|
||||
FCB, FileObject, ConnectInfo ? ConnectInfo->EndpointFlags : 0));
|
||||
|
||||
RtlZeroMemory( FCB, sizeof( *FCB ) );
|
||||
|
||||
|
@ -324,7 +329,7 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
KeInitializeMutex( &FCB->Mutex, 0 );
|
||||
|
||||
for( i = 0; i < MAX_FUNCTIONS; i++ ) {
|
||||
InitializeListHead( &FCB->PendingIrpList[i] );
|
||||
InitializeListHead( &FCB->PendingIrpList[i] );
|
||||
}
|
||||
|
||||
InitializeListHead( &FCB->DatagramList );
|
||||
|
@ -333,27 +338,27 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
AFD_DbgPrint(MID_TRACE,("%x: Checking command channel\n", FCB));
|
||||
|
||||
if( ConnectInfo ) {
|
||||
FCB->TdiDeviceName.Length = ConnectInfo->SizeOfTransportName;
|
||||
FCB->TdiDeviceName.MaximumLength = FCB->TdiDeviceName.Length;
|
||||
FCB->TdiDeviceName.Buffer =
|
||||
ExAllocatePool( NonPagedPool, FCB->TdiDeviceName.Length );
|
||||
FCB->TdiDeviceName.Length = ConnectInfo->SizeOfTransportName;
|
||||
FCB->TdiDeviceName.MaximumLength = FCB->TdiDeviceName.Length;
|
||||
FCB->TdiDeviceName.Buffer =
|
||||
ExAllocatePool( NonPagedPool, FCB->TdiDeviceName.Length );
|
||||
|
||||
if( !FCB->TdiDeviceName.Buffer ) {
|
||||
ExFreePool(FCB);
|
||||
AFD_DbgPrint(MID_TRACE,("Could not copy target string\n"));
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
if( !FCB->TdiDeviceName.Buffer ) {
|
||||
ExFreePool(FCB);
|
||||
AFD_DbgPrint(MID_TRACE,("Could not copy target string\n"));
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
RtlCopyMemory( FCB->TdiDeviceName.Buffer,
|
||||
ConnectInfo->TransportName,
|
||||
FCB->TdiDeviceName.Length );
|
||||
RtlCopyMemory( FCB->TdiDeviceName.Buffer,
|
||||
ConnectInfo->TransportName,
|
||||
FCB->TdiDeviceName.Length );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Success: %s %wZ\n",
|
||||
EaInfo->EaName, &FCB->TdiDeviceName));
|
||||
AFD_DbgPrint(MID_TRACE,("Success: %s %wZ\n",
|
||||
EaInfo->EaName, &FCB->TdiDeviceName));
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Success: Control connection\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("Success: Control connection\n"));
|
||||
}
|
||||
|
||||
FileObject->FsContext = FCB;
|
||||
|
@ -361,17 +366,17 @@ AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
/* It seems that UDP sockets are writable from inception */
|
||||
if( FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Packet oriented socket\n"));
|
||||
|
||||
/* A datagram socket is always sendable */
|
||||
FCB->PollState |= AFD_EVENT_SEND;
|
||||
|
||||
/* A datagram socket is always sendable */
|
||||
FCB->PollState |= AFD_EVENT_SEND;
|
||||
FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
|
||||
if( !NT_SUCCESS(Status) ) {
|
||||
if( FCB->TdiDeviceName.Buffer ) ExFreePool( FCB->TdiDeviceName.Buffer );
|
||||
ExFreePool( FCB );
|
||||
FileObject->FsContext = NULL;
|
||||
if( FCB->TdiDeviceName.Buffer ) ExFreePool( FCB->TdiDeviceName.Buffer );
|
||||
ExFreePool( FCB );
|
||||
FileObject->FsContext = NULL;
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
|
@ -414,7 +419,7 @@ AfdCleanupSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
static NTSTATUS NTAPI
|
||||
AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
PIO_STACK_LOCATION IrpSp)
|
||||
{
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -422,10 +427,10 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
PAFD_IN_FLIGHT_REQUEST InFlightRequest[IN_FLIGHT_REQUESTS];
|
||||
PAFD_TDI_OBJECT_QELT Qelt;
|
||||
PLIST_ENTRY QeltEntry;
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,
|
||||
("AfdClose(DeviceObject %p Irp %p)\n", DeviceObject, Irp));
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("AfdClose(DeviceObject %p Irp %p)\n",
|
||||
DeviceObject, Irp));
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) ) return STATUS_FILE_CLOSED;
|
||||
|
||||
|
@ -439,11 +444,11 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
/* Cancel our pending requests */
|
||||
for( i = 0; i < IN_FLIGHT_REQUESTS; i++ ) {
|
||||
if( InFlightRequest[i]->InFlightRequest ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %d (%x)\n",
|
||||
i, InFlightRequest[i]->InFlightRequest));
|
||||
if( InFlightRequest[i]->InFlightRequest ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Cancelling in flight irp %d (%x)\n",
|
||||
i, InFlightRequest[i]->InFlightRequest));
|
||||
IoCancelIrp(InFlightRequest[i]->InFlightRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KillSelectsForFCB( FCB->DeviceExt, FileObject, FALSE );
|
||||
|
@ -476,17 +481,17 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
ExFreePool( FCB->Context );
|
||||
|
||||
if( FCB->Recv.Window )
|
||||
ExFreePool( FCB->Recv.Window );
|
||||
ExFreePool( FCB->Recv.Window );
|
||||
|
||||
if( FCB->Send.Window )
|
||||
ExFreePool( FCB->Send.Window );
|
||||
ExFreePool( FCB->Send.Window );
|
||||
|
||||
if( FCB->AddressFrom )
|
||||
ExFreePool( FCB->AddressFrom );
|
||||
ExFreePool( FCB->AddressFrom );
|
||||
|
||||
if( FCB->ConnectCallInfo )
|
||||
ExFreePool( FCB->ConnectCallInfo );
|
||||
|
||||
|
||||
if( FCB->ConnectReturnInfo )
|
||||
ExFreePool( FCB->ConnectReturnInfo );
|
||||
|
||||
|
@ -503,19 +508,19 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
ExFreePool( FCB->DisconnectOptions );
|
||||
|
||||
if( FCB->LocalAddress )
|
||||
ExFreePool( FCB->LocalAddress );
|
||||
ExFreePool( FCB->LocalAddress );
|
||||
|
||||
if( FCB->RemoteAddress )
|
||||
ExFreePool( FCB->RemoteAddress );
|
||||
ExFreePool( FCB->RemoteAddress );
|
||||
|
||||
if( FCB->Connection.Object )
|
||||
{
|
||||
TdiDisassociateAddressFile(FCB->Connection.Object);
|
||||
ObDereferenceObject(FCB->Connection.Object);
|
||||
ObDereferenceObject(FCB->Connection.Object);
|
||||
}
|
||||
|
||||
if( FCB->AddressFile.Object )
|
||||
ObDereferenceObject(FCB->AddressFile.Object);
|
||||
ObDereferenceObject(FCB->AddressFile.Object);
|
||||
|
||||
if( FCB->AddressFile.Handle != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
|
@ -534,7 +539,7 @@ AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
if( FCB->TdiDeviceName.Buffer )
|
||||
ExFreePool(FCB->TdiDeviceName.Buffer);
|
||||
ExFreePool(FCB->TdiDeviceName.Buffer);
|
||||
|
||||
ExFreePool(FCB);
|
||||
|
||||
|
@ -557,17 +562,17 @@ DisconnectComplete(PDEVICE_OBJECT DeviceObject,
|
|||
PAFD_FCB FCB = Context;
|
||||
PIRP CurrentIrp;
|
||||
PLIST_ENTRY CurrentEntry;
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) )
|
||||
|
||||
if (!SocketAcquireStateLock(FCB))
|
||||
return STATUS_FILE_CLOSED;
|
||||
|
||||
|
||||
ASSERT(FCB->DisconnectIrp.InFlightRequest == Irp);
|
||||
FCB->DisconnectIrp.InFlightRequest = NULL;
|
||||
|
||||
|
||||
ASSERT(FCB->DisconnectPending);
|
||||
ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
|
||||
(FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
|
||||
|
||||
|
||||
if (NT_SUCCESS(Irp->IoStatus.Status) && (FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE))
|
||||
{
|
||||
FCB->FilledDisconnectData = MIN(FCB->DisconnectDataSize, FCB->ConnectReturnInfo->UserDataLength);
|
||||
|
@ -577,7 +582,7 @@ DisconnectComplete(PDEVICE_OBJECT DeviceObject,
|
|||
FCB->ConnectReturnInfo->UserData,
|
||||
FCB->FilledDisconnectData);
|
||||
}
|
||||
|
||||
|
||||
FCB->FilledDisconnectOptions = MIN(FCB->DisconnectOptionsSize, FCB->ConnectReturnInfo->OptionsLength);
|
||||
if (FCB->FilledDisconnectOptions)
|
||||
{
|
||||
|
@ -586,9 +591,9 @@ DisconnectComplete(PDEVICE_OBJECT DeviceObject,
|
|||
FCB->FilledDisconnectOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FCB->DisconnectPending = FALSE;
|
||||
|
||||
|
||||
while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_DISCONNECT]))
|
||||
{
|
||||
CurrentEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_DISCONNECT]);
|
||||
|
@ -599,7 +604,7 @@ DisconnectComplete(PDEVICE_OBJECT DeviceObject,
|
|||
(void)IoSetCancelRoutine(CurrentIrp, NULL);
|
||||
IoCompleteRequest(CurrentIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
|
||||
if (!(FCB->DisconnectFlags & TDI_DISCONNECT_RELEASE))
|
||||
{
|
||||
/* Signal complete connection closure immediately */
|
||||
|
@ -607,9 +612,9 @@ DisconnectComplete(PDEVICE_OBJECT DeviceObject,
|
|||
FCB->PollStatus[FD_CLOSE_BIT] = Irp->IoStatus.Status;
|
||||
PollReeval(FCB->DeviceExt, FCB->FileObject);
|
||||
}
|
||||
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
|
||||
return Irp->IoStatus.Status;
|
||||
}
|
||||
|
||||
|
@ -618,11 +623,11 @@ NTSTATUS
|
|||
DoDisconnect(PAFD_FCB FCB)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
|
||||
ASSERT(FCB->DisconnectPending);
|
||||
ASSERT((IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) && !FCB->SendIrp.InFlightRequest) ||
|
||||
(FCB->DisconnectFlags & TDI_DISCONNECT_ABORT));
|
||||
|
||||
|
||||
if (FCB->DisconnectIrp.InFlightRequest)
|
||||
{
|
||||
return STATUS_PENDING;
|
||||
|
@ -646,7 +651,7 @@ DoDisconnect(PAFD_FCB FCB)
|
|||
{
|
||||
FCB->DisconnectPending = FALSE;
|
||||
}
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
@ -664,7 +669,7 @@ RetryDisconnectCompletion(PAFD_FCB FCB)
|
|||
|
||||
static NTSTATUS NTAPI
|
||||
AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
PAFD_DISCONNECT_INFO DisReq;
|
||||
|
@ -673,12 +678,12 @@ AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
PLIST_ENTRY CurrentEntry;
|
||||
PIRP CurrentIrp;
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
|
||||
if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
|
||||
|
||||
if (!(DisReq = LockRequest(Irp, IrpSp)))
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
|
||||
Irp, 0 );
|
||||
|
||||
if( !(DisReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
|
||||
Irp, 0 );
|
||||
|
||||
/* Send direction only */
|
||||
if ((DisReq->DisconnectType & AFD_DISCONNECT_SEND) &&
|
||||
!(DisReq->DisconnectType & AFD_DISCONNECT_RECV))
|
||||
|
@ -725,7 +730,7 @@ AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
if (!(FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS))
|
||||
{
|
||||
if( !FCB->ConnectCallInfo )
|
||||
if (!FCB->ConnectCallInfo)
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER,
|
||||
|
@ -753,13 +758,13 @@ AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FCB->DisconnectFlags = Flags;
|
||||
FCB->DisconnectTimeout = DisReq->Timeout;
|
||||
FCB->DisconnectPending = TRUE;
|
||||
FCB->SendClosed = TRUE;
|
||||
FCB->PollState &= ~AFD_EVENT_SEND;
|
||||
|
||||
|
||||
Status = QueueUserModeIrp(FCB, Irp, FUNCTION_DISCONNECT);
|
||||
if (Status == STATUS_PENDING)
|
||||
{
|
||||
|
@ -769,11 +774,11 @@ AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
/* Go ahead and execute the disconnect because we're ready for it */
|
||||
Status = DoDisconnect(FCB);
|
||||
}
|
||||
|
||||
|
||||
if (Status != STATUS_PENDING)
|
||||
RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
|
||||
}
|
||||
|
||||
|
||||
if (Status == STATUS_PENDING)
|
||||
{
|
||||
SocketStateUnlock(FCB);
|
||||
|
@ -790,12 +795,12 @@ AfdDisconnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_INVALID_PARAMETER, Irp, 0);
|
||||
}
|
||||
|
||||
|
||||
ExFreePool(FCB->RemoteAddress);
|
||||
|
||||
|
||||
FCB->RemoteAddress = NULL;
|
||||
}
|
||||
|
||||
|
||||
FCB->PollState &= ~AFD_EVENT_SEND;
|
||||
FCB->SendClosed = TRUE;
|
||||
}
|
||||
|
@ -814,168 +819,168 @@ AfdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
|||
|
||||
AFD_DbgPrint(MID_TRACE,("AfdDispatch: %d\n", IrpSp->MajorFunction));
|
||||
if( IrpSp->MajorFunction != IRP_MJ_CREATE) {
|
||||
AFD_DbgPrint(MID_TRACE,("FO %x, IrpSp->FO %x\n",
|
||||
FileObject, IrpSp->FileObject));
|
||||
ASSERT(FileObject == IrpSp->FileObject);
|
||||
AFD_DbgPrint(MID_TRACE,("FO %x, IrpSp->FO %x\n",
|
||||
FileObject, IrpSp->FileObject));
|
||||
ASSERT(FileObject == IrpSp->FileObject);
|
||||
}
|
||||
|
||||
Irp->IoStatus.Information = 0;
|
||||
|
||||
switch(IrpSp->MajorFunction)
|
||||
{
|
||||
/* opening and closing handles to the device */
|
||||
/* opening and closing handles to the device */
|
||||
case IRP_MJ_CREATE:
|
||||
/* Mostly borrowed from the named pipe file system */
|
||||
return AfdCreateSocket(DeviceObject, Irp, IrpSp);
|
||||
/* Mostly borrowed from the named pipe file system */
|
||||
return AfdCreateSocket(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IRP_MJ_CLOSE:
|
||||
/* Ditto the borrowing */
|
||||
return AfdCloseSocket(DeviceObject, Irp, IrpSp);
|
||||
/* Ditto the borrowing */
|
||||
return AfdCloseSocket(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IRP_MJ_CLEANUP:
|
||||
return AfdCleanupSocket(DeviceObject, Irp, IrpSp);
|
||||
|
||||
/* write data */
|
||||
case IRP_MJ_WRITE:
|
||||
return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp, TRUE );
|
||||
return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp, TRUE );
|
||||
|
||||
/* read data */
|
||||
case IRP_MJ_READ:
|
||||
return AfdConnectedSocketReadData( DeviceObject, Irp, IrpSp, TRUE );
|
||||
return AfdConnectedSocketReadData( DeviceObject, Irp, IrpSp, TRUE );
|
||||
|
||||
case IRP_MJ_DEVICE_CONTROL:
|
||||
{
|
||||
switch( IrpSp->Parameters.DeviceIoControl.IoControlCode ) {
|
||||
case IOCTL_AFD_BIND:
|
||||
return AfdBindSocket( DeviceObject, Irp, IrpSp );
|
||||
switch( IrpSp->Parameters.DeviceIoControl.IoControlCode ) {
|
||||
case IOCTL_AFD_BIND:
|
||||
return AfdBindSocket( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_CONNECT:
|
||||
return AfdStreamSocketConnect( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_CONNECT:
|
||||
return AfdStreamSocketConnect( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_START_LISTEN:
|
||||
return AfdListenSocket( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_START_LISTEN:
|
||||
return AfdListenSocket( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_RECV:
|
||||
return AfdConnectedSocketReadData( DeviceObject, Irp, IrpSp,
|
||||
FALSE );
|
||||
case IOCTL_AFD_RECV:
|
||||
return AfdConnectedSocketReadData( DeviceObject, Irp, IrpSp,
|
||||
FALSE );
|
||||
|
||||
case IOCTL_AFD_SELECT:
|
||||
return AfdSelect( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_SELECT:
|
||||
return AfdSelect( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_EVENT_SELECT:
|
||||
return AfdEventSelect( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_EVENT_SELECT:
|
||||
return AfdEventSelect( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_ENUM_NETWORK_EVENTS:
|
||||
return AfdEnumEvents( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_ENUM_NETWORK_EVENTS:
|
||||
return AfdEnumEvents( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_RECV_DATAGRAM:
|
||||
return AfdPacketSocketReadData( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_RECV_DATAGRAM:
|
||||
return AfdPacketSocketReadData( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_SEND:
|
||||
return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp,
|
||||
FALSE );
|
||||
case IOCTL_AFD_SEND:
|
||||
return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp,
|
||||
FALSE );
|
||||
|
||||
case IOCTL_AFD_SEND_DATAGRAM:
|
||||
return AfdPacketSocketWriteData( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_SEND_DATAGRAM:
|
||||
return AfdPacketSocketWriteData( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_GET_INFO:
|
||||
return AfdGetInfo( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_GET_INFO:
|
||||
return AfdGetInfo( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_SET_INFO:
|
||||
return AfdSetInfo( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_SET_INFO:
|
||||
return AfdSetInfo( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_GET_CONTEXT_SIZE:
|
||||
return AfdGetContextSize( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_GET_CONTEXT_SIZE:
|
||||
return AfdGetContextSize( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_GET_CONTEXT:
|
||||
return AfdGetContext( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_GET_CONTEXT:
|
||||
return AfdGetContext( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_SET_CONTEXT:
|
||||
return AfdSetContext( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_SET_CONTEXT:
|
||||
return AfdSetContext( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_WAIT_FOR_LISTEN:
|
||||
return AfdWaitForListen( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_WAIT_FOR_LISTEN:
|
||||
return AfdWaitForListen( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_ACCEPT:
|
||||
return AfdAccept( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_ACCEPT:
|
||||
return AfdAccept( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_DISCONNECT:
|
||||
return AfdDisconnect( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_DISCONNECT:
|
||||
return AfdDisconnect( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_GET_SOCK_NAME:
|
||||
return AfdGetSockName( DeviceObject, Irp, IrpSp );
|
||||
case IOCTL_AFD_GET_SOCK_NAME:
|
||||
return AfdGetSockName( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_GET_PEER_NAME:
|
||||
return AfdGetPeerName( DeviceObject, Irp, IrpSp );
|
||||
|
||||
case IOCTL_AFD_GET_CONNECT_DATA:
|
||||
return AfdGetConnectData(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_GET_CONNECT_DATA:
|
||||
return AfdGetConnectData(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_CONNECT_DATA:
|
||||
return AfdSetConnectData(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_CONNECT_DATA:
|
||||
return AfdSetConnectData(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_DISCONNECT_DATA:
|
||||
return AfdSetDisconnectData(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_DISCONNECT_DATA:
|
||||
return AfdSetDisconnectData(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_GET_DISCONNECT_DATA:
|
||||
return AfdGetDisconnectData(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_GET_DISCONNECT_DATA:
|
||||
return AfdGetDisconnectData(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_CONNECT_DATA_SIZE:
|
||||
return AfdSetConnectDataSize(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_CONNECT_DATA_SIZE:
|
||||
return AfdSetConnectDataSize(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_DISCONNECT_DATA_SIZE:
|
||||
return AfdSetDisconnectDataSize(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_DISCONNECT_DATA_SIZE:
|
||||
return AfdSetDisconnectDataSize(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_CONNECT_OPTIONS:
|
||||
return AfdSetConnectOptions(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_CONNECT_OPTIONS:
|
||||
return AfdSetConnectOptions(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_DISCONNECT_OPTIONS:
|
||||
return AfdSetDisconnectOptions(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_DISCONNECT_OPTIONS:
|
||||
return AfdSetDisconnectOptions(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_GET_CONNECT_OPTIONS:
|
||||
return AfdGetConnectOptions(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_GET_CONNECT_OPTIONS:
|
||||
return AfdGetConnectOptions(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_GET_DISCONNECT_OPTIONS:
|
||||
return AfdGetDisconnectOptions(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_GET_DISCONNECT_OPTIONS:
|
||||
return AfdGetDisconnectOptions(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_CONNECT_OPTIONS_SIZE:
|
||||
return AfdSetConnectOptionsSize(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_CONNECT_OPTIONS_SIZE:
|
||||
return AfdSetConnectOptionsSize(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_SET_DISCONNECT_OPTIONS_SIZE:
|
||||
return AfdSetDisconnectOptionsSize(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_SET_DISCONNECT_OPTIONS_SIZE:
|
||||
return AfdSetDisconnectOptionsSize(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_GET_TDI_HANDLES:
|
||||
return AfdGetTdiHandles(DeviceObject, Irp, IrpSp);
|
||||
case IOCTL_AFD_GET_TDI_HANDLES:
|
||||
return AfdGetTdiHandles(DeviceObject, Irp, IrpSp);
|
||||
|
||||
case IOCTL_AFD_DEFER_ACCEPT:
|
||||
DbgPrint("IOCTL_AFD_DEFER_ACCEPT is UNIMPLEMENTED!\n");
|
||||
break;
|
||||
case IOCTL_AFD_DEFER_ACCEPT:
|
||||
DbgPrint("IOCTL_AFD_DEFER_ACCEPT is UNIMPLEMENTED!\n");
|
||||
break;
|
||||
|
||||
case IOCTL_AFD_GET_PENDING_CONNECT_DATA:
|
||||
DbgPrint("IOCTL_AFD_GET_PENDING_CONNECT_DATA is UNIMPLEMENTED!\n");
|
||||
break;
|
||||
case IOCTL_AFD_GET_PENDING_CONNECT_DATA:
|
||||
DbgPrint("IOCTL_AFD_GET_PENDING_CONNECT_DATA is UNIMPLEMENTED!\n");
|
||||
break;
|
||||
|
||||
case IOCTL_AFD_VALIDATE_GROUP:
|
||||
DbgPrint("IOCTL_AFD_VALIDATE_GROUP is UNIMPLEMENTED!\n");
|
||||
break;
|
||||
case IOCTL_AFD_VALIDATE_GROUP:
|
||||
DbgPrint("IOCTL_AFD_VALIDATE_GROUP is UNIMPLEMENTED!\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = STATUS_NOT_SUPPORTED;
|
||||
DbgPrint("Unknown IOCTL (0x%x)\n",
|
||||
IrpSp->Parameters.DeviceIoControl.IoControlCode);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Status = STATUS_NOT_SUPPORTED;
|
||||
DbgPrint("Unknown IOCTL (0x%x)\n",
|
||||
IrpSp->Parameters.DeviceIoControl.IoControlCode);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* unsupported operations */
|
||||
default:
|
||||
{
|
||||
Status = STATUS_NOT_IMPLEMENTED;
|
||||
AFD_DbgPrint(MIN_TRACE,
|
||||
("Irp: Unknown Major code was %x\n",
|
||||
IrpSp->MajorFunction));
|
||||
break;
|
||||
Status = STATUS_NOT_IMPLEMENTED;
|
||||
AFD_DbgPrint(MIN_TRACE,
|
||||
("Irp: Unknown Major code was %x\n",
|
||||
IrpSp->MajorFunction));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -983,7 +988,7 @@ AfdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
|||
Irp->IoStatus.Status = Status;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
return (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
BOOLEAN CheckUnlockExtraBuffers(PAFD_FCB FCB, PIO_STACK_LOCATION IrpSp)
|
||||
|
@ -1040,15 +1045,15 @@ CleanupPendingIrp(PAFD_FCB FCB, PIRP Irp, PIO_STACK_LOCATION IrpSp, PAFD_ACTIVE_
|
|||
PAFD_RECV_INFO RecvReq;
|
||||
PAFD_SEND_INFO SendReq;
|
||||
PAFD_POLL_INFO PollReq;
|
||||
|
||||
|
||||
if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_RECV ||
|
||||
IrpSp->MajorFunction == IRP_MJ_READ)
|
||||
{
|
||||
RecvReq = GetLockedData(Irp, IrpSp);
|
||||
UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, CheckUnlockExtraBuffers(FCB, IrpSp));
|
||||
}
|
||||
else if ((IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND ||
|
||||
IrpSp->MajorFunction == IRP_MJ_WRITE))
|
||||
else if (IrpSp->Parameters.DeviceIoControl.IoControlCode == IOCTL_AFD_SEND ||
|
||||
IrpSp->MajorFunction == IRP_MJ_WRITE)
|
||||
{
|
||||
SendReq = GetLockedData(Irp, IrpSp);
|
||||
UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, CheckUnlockExtraBuffers(FCB, IrpSp));
|
||||
|
@ -1058,7 +1063,7 @@ CleanupPendingIrp(PAFD_FCB FCB, PIRP Irp, PIO_STACK_LOCATION IrpSp, PAFD_ACTIVE_
|
|||
PollReq = Irp->AssociatedIrp.SystemBuffer;
|
||||
ZeroEvents(PollReq->Handles, PollReq->HandleCount);
|
||||
SignalSocket(Poll, NULL, PollReq, STATUS_CANCELLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VOID NTAPI
|
||||
|
@ -1076,24 +1081,24 @@ AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
|
|||
PAFD_ACTIVE_POLL Poll;
|
||||
|
||||
IoReleaseCancelSpinLock(Irp->CancelIrql);
|
||||
|
||||
|
||||
if (!SocketAcquireStateLock(FCB))
|
||||
return;
|
||||
|
||||
|
||||
switch (IrpSp->MajorFunction)
|
||||
{
|
||||
case IRP_MJ_DEVICE_CONTROL:
|
||||
IoctlCode = IrpSp->Parameters.DeviceIoControl.IoControlCode;
|
||||
break;
|
||||
|
||||
|
||||
case IRP_MJ_READ:
|
||||
IoctlCode = IOCTL_AFD_RECV;
|
||||
break;
|
||||
|
||||
|
||||
case IRP_MJ_WRITE:
|
||||
IoctlCode = IOCTL_AFD_SEND;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
SocketStateUnlock(FCB);
|
||||
|
@ -1104,58 +1109,58 @@ AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
|
|||
{
|
||||
case IOCTL_AFD_RECV:
|
||||
case IOCTL_AFD_RECV_DATAGRAM:
|
||||
Function = FUNCTION_RECV;
|
||||
break;
|
||||
Function = FUNCTION_RECV;
|
||||
break;
|
||||
|
||||
case IOCTL_AFD_SEND:
|
||||
case IOCTL_AFD_SEND_DATAGRAM:
|
||||
Function = FUNCTION_SEND;
|
||||
break;
|
||||
Function = FUNCTION_SEND;
|
||||
break;
|
||||
|
||||
case IOCTL_AFD_CONNECT:
|
||||
Function = FUNCTION_CONNECT;
|
||||
break;
|
||||
Function = FUNCTION_CONNECT;
|
||||
break;
|
||||
|
||||
case IOCTL_AFD_WAIT_FOR_LISTEN:
|
||||
Function = FUNCTION_PREACCEPT;
|
||||
break;
|
||||
Function = FUNCTION_PREACCEPT;
|
||||
break;
|
||||
|
||||
case IOCTL_AFD_SELECT:
|
||||
KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
|
||||
KeAcquireSpinLock(&DeviceExt->Lock, &OldIrql);
|
||||
|
||||
CurrentEntry = DeviceExt->Polls.Flink;
|
||||
while (CurrentEntry != &DeviceExt->Polls)
|
||||
{
|
||||
Poll = CONTAINING_RECORD(CurrentEntry, AFD_ACTIVE_POLL, ListEntry);
|
||||
|
||||
if (Irp == Poll->Irp)
|
||||
CurrentEntry = DeviceExt->Polls.Flink;
|
||||
while (CurrentEntry != &DeviceExt->Polls)
|
||||
{
|
||||
CleanupPendingIrp(FCB, Irp, IrpSp, Poll);
|
||||
KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
|
||||
SocketStateUnlock(FCB);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
}
|
||||
Poll = CONTAINING_RECORD(CurrentEntry, AFD_ACTIVE_POLL, ListEntry);
|
||||
|
||||
KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
|
||||
if (Irp == Poll->Irp)
|
||||
{
|
||||
CleanupPendingIrp(FCB, Irp, IrpSp, Poll);
|
||||
KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
|
||||
SocketStateUnlock(FCB);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
}
|
||||
|
||||
KeReleaseSpinLock(&DeviceExt->Lock, OldIrql);
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (IOCTL_AFD_SELECT)\n");
|
||||
return;
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (IOCTL_AFD_SELECT)\n");
|
||||
return;
|
||||
|
||||
case IOCTL_AFD_DISCONNECT:
|
||||
Function = FUNCTION_DISCONNECT;
|
||||
break;
|
||||
|
||||
Function = FUNCTION_DISCONNECT;
|
||||
break;
|
||||
|
||||
default:
|
||||
ASSERT(FALSE);
|
||||
UnlockAndMaybeComplete(FCB, STATUS_CANCELLED, Irp, 0);
|
||||
return;
|
||||
ASSERT(FALSE);
|
||||
UnlockAndMaybeComplete(FCB, STATUS_CANCELLED, Irp, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentEntry = FCB->PendingIrpList[Function].Flink;
|
||||
|
@ -1175,9 +1180,9 @@ AfdCancelHandler(PDEVICE_OBJECT DeviceObject,
|
|||
CurrentEntry = CurrentEntry->Flink;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
|
||||
DbgPrint("WARNING!!! IRP cancellation race could lead to a process hang! (Function: %d)\n", Function);
|
||||
}
|
||||
|
||||
|
@ -1203,19 +1208,18 @@ DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
|||
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;
|
||||
DriverObject->DriverUnload = AfdUnload;
|
||||
|
||||
Status = IoCreateDevice
|
||||
( DriverObject,
|
||||
sizeof(AFD_DEVICE_EXTENSION),
|
||||
&wstrDeviceName,
|
||||
FILE_DEVICE_NAMED_PIPE,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject );
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
sizeof(AFD_DEVICE_EXTENSION),
|
||||
&wstrDeviceName,
|
||||
FILE_DEVICE_NAMED_PIPE,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject);
|
||||
|
||||
/* failure */
|
||||
if(!NT_SUCCESS(Status))
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
DeviceExt = DeviceObject->DeviceExtension;
|
||||
|
@ -1223,9 +1227,9 @@ DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
|||
InitializeListHead( &DeviceExt->Polls );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Device created: object %x ext %x\n",
|
||||
DeviceObject, DeviceExt));
|
||||
DeviceObject, DeviceExt));
|
||||
|
||||
return (Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -42,11 +42,11 @@ static VOID HandleReceiveComplete( PAFD_FCB FCB, NTSTATUS Status, ULONG_PTR Info
|
|||
{
|
||||
FCB->Recv.Content = 0;
|
||||
FCB->TdiReceiveClosed = TRUE;
|
||||
|
||||
|
||||
/* Signal graceful receive shutdown */
|
||||
FCB->PollState |= AFD_EVENT_DISCONNECT;
|
||||
FCB->PollStatus[FD_CLOSE_BIT] = Status;
|
||||
|
||||
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
/* Receive failed with no data (unexpected closure) */
|
||||
|
@ -54,27 +54,27 @@ static VOID HandleReceiveComplete( PAFD_FCB FCB, NTSTATUS Status, ULONG_PTR Info
|
|||
{
|
||||
FCB->Recv.Content = 0;
|
||||
FCB->TdiReceiveClosed = TRUE;
|
||||
|
||||
/* Signal complete connection failure immediately */
|
||||
FCB->PollState |= AFD_EVENT_CLOSE;
|
||||
FCB->PollStatus[FD_CLOSE_BIT] = Status;
|
||||
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
/* Signal complete connection failure immediately */
|
||||
FCB->PollState |= AFD_EVENT_CLOSE;
|
||||
FCB->PollStatus[FD_CLOSE_BIT] = Status;
|
||||
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
}
|
||||
|
||||
static BOOLEAN CantReadMore( PAFD_FCB FCB ) {
|
||||
UINT BytesAvailable = FCB->Recv.Content - FCB->Recv.BytesUsed;
|
||||
|
||||
|
||||
return !BytesAvailable && FCB->TdiReceiveClosed;
|
||||
}
|
||||
|
||||
static VOID RefillSocketBuffer( PAFD_FCB FCB ) {
|
||||
if( !FCB->ReceiveIrp.InFlightRequest &&
|
||||
if( !FCB->ReceiveIrp.InFlightRequest &&
|
||||
!FCB->TdiReceiveClosed ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Replenishing buffer\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("Replenishing buffer\n"));
|
||||
|
||||
TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
|
||||
TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
|
||||
FCB->Connection.Object,
|
||||
TDI_RECEIVE_NORMAL,
|
||||
FCB->Recv.Window,
|
||||
|
@ -82,21 +82,21 @@ static VOID RefillSocketBuffer( PAFD_FCB FCB ) {
|
|||
&FCB->ReceiveIrp.Iosb,
|
||||
ReceiveComplete,
|
||||
FCB );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NTSTATUS TryToSatisfyRecvRequestFromBuffer( PAFD_FCB FCB,
|
||||
PAFD_RECV_INFO RecvReq,
|
||||
PUINT TotalBytesCopied ) {
|
||||
PAFD_RECV_INFO RecvReq,
|
||||
PUINT TotalBytesCopied ) {
|
||||
UINT i, BytesToCopy = 0, FcbBytesCopied = FCB->Recv.BytesUsed,
|
||||
BytesAvailable =
|
||||
FCB->Recv.Content - FCB->Recv.BytesUsed;
|
||||
BytesAvailable =
|
||||
FCB->Recv.Content - FCB->Recv.BytesUsed;
|
||||
PAFD_MAPBUF Map;
|
||||
*TotalBytesCopied = 0;
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called, BytesAvailable = %d\n",
|
||||
BytesAvailable));
|
||||
BytesAvailable));
|
||||
|
||||
if( CantReadMore(FCB) ) return STATUS_SUCCESS;
|
||||
if( !BytesAvailable ) return STATUS_PENDING;
|
||||
|
@ -104,42 +104,42 @@ static NTSTATUS TryToSatisfyRecvRequestFromBuffer( PAFD_FCB FCB,
|
|||
Map = (PAFD_MAPBUF)(RecvReq->BufferArray + RecvReq->BufferCount);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Buffer Count: %d @ %x\n",
|
||||
RecvReq->BufferCount,
|
||||
RecvReq->BufferArray));
|
||||
RecvReq->BufferCount,
|
||||
RecvReq->BufferArray));
|
||||
for( i = 0;
|
||||
RecvReq->BufferArray &&
|
||||
BytesAvailable &&
|
||||
i < RecvReq->BufferCount;
|
||||
i++ ) {
|
||||
BytesToCopy =
|
||||
MIN( RecvReq->BufferArray[i].len, BytesAvailable );
|
||||
RecvReq->BufferArray &&
|
||||
BytesAvailable &&
|
||||
i < RecvReq->BufferCount;
|
||||
i++ ) {
|
||||
BytesToCopy =
|
||||
MIN( RecvReq->BufferArray[i].len, BytesAvailable );
|
||||
|
||||
if( Map[i].Mdl ) {
|
||||
Map[i].BufferAddress = MmMapLockedPages( Map[i].Mdl, KernelMode );
|
||||
if( Map[i].Mdl ) {
|
||||
Map[i].BufferAddress = MmMapLockedPages( Map[i].Mdl, KernelMode );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Buffer %d: %x:%d\n",
|
||||
i,
|
||||
Map[i].BufferAddress,
|
||||
BytesToCopy));
|
||||
AFD_DbgPrint(MID_TRACE,("Buffer %d: %x:%d\n",
|
||||
i,
|
||||
Map[i].BufferAddress,
|
||||
BytesToCopy));
|
||||
|
||||
RtlCopyMemory( Map[i].BufferAddress,
|
||||
FCB->Recv.Window + FcbBytesCopied,
|
||||
BytesToCopy );
|
||||
RtlCopyMemory( Map[i].BufferAddress,
|
||||
FCB->Recv.Window + FcbBytesCopied,
|
||||
BytesToCopy );
|
||||
|
||||
MmUnmapLockedPages( Map[i].BufferAddress, Map[i].Mdl );
|
||||
MmUnmapLockedPages( Map[i].BufferAddress, Map[i].Mdl );
|
||||
|
||||
*TotalBytesCopied += BytesToCopy;
|
||||
FcbBytesCopied += BytesToCopy;
|
||||
BytesAvailable -= BytesToCopy;
|
||||
FcbBytesCopied += BytesToCopy;
|
||||
BytesAvailable -= BytesToCopy;
|
||||
|
||||
if (!(RecvReq->TdiFlags & TDI_RECEIVE_PEEK))
|
||||
FCB->Recv.BytesUsed += BytesToCopy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If there's nothing left in our buffer start a new request */
|
||||
if( FCB->Recv.BytesUsed == FCB->Recv.Content ) {
|
||||
FCB->Recv.BytesUsed = FCB->Recv.Content = 0;
|
||||
FCB->Recv.BytesUsed = FCB->Recv.Content = 0;
|
||||
FCB->PollState &= ~AFD_EVENT_RECEIVE;
|
||||
|
||||
RefillSocketBuffer( FCB );
|
||||
|
@ -162,24 +162,22 @@ static NTSTATUS ReceiveActivity( PAFD_FCB FCB, PIRP Irp ) {
|
|||
/* XXX Not implemented yet */
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("FCB %x Receive data waiting %d\n",
|
||||
FCB, FCB->Recv.Content));
|
||||
FCB, FCB->Recv.Content));
|
||||
|
||||
if( CantReadMore( FCB ) ) {
|
||||
/* Success here means that we got an EOF. Complete a pending read
|
||||
* with zero bytes if we haven't yet overread, then kill the others.
|
||||
*/
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
NextIrpEntry =
|
||||
RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp =
|
||||
CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Completing recv %x (%d)\n", NextIrp,
|
||||
TotalBytesCopied));
|
||||
UnlockBuffers( RecvReq->BufferArray,
|
||||
RecvReq->BufferCount, FALSE );
|
||||
RecvReq->BufferCount, FALSE );
|
||||
if (FCB->Overread && FCB->PollStatus[FD_CLOSE_BIT] == STATUS_SUCCESS)
|
||||
{
|
||||
/* Overread after a graceful disconnect so complete with an error */
|
||||
|
@ -194,58 +192,56 @@ static NTSTATUS ReceiveActivity( PAFD_FCB FCB, PIRP Irp ) {
|
|||
NextIrp->IoStatus.Information = 0;
|
||||
if( NextIrp == Irp ) RetStatus = Status;
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
FCB->Overread = TRUE;
|
||||
}
|
||||
} else {
|
||||
/* Kick the user that receive would be possible now */
|
||||
/* XXX Not implemented yet */
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("FCB %x Receive data waiting %d\n",
|
||||
FCB, FCB->Recv.Content));
|
||||
/*OskitDumpBuffer( FCB->Recv.Window, FCB->Recv.Content );*/
|
||||
|
||||
/* Try to clear some requests */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
NextIrpEntry =
|
||||
RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp =
|
||||
CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("RecvReq @ %x\n", RecvReq));
|
||||
|
||||
Status = TryToSatisfyRecvRequestFromBuffer
|
||||
( FCB, RecvReq, &TotalBytesCopied );
|
||||
|
||||
if( Status == STATUS_PENDING ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Ran out of data for %x\n", NextIrp));
|
||||
InsertHeadList(&FCB->PendingIrpList[FUNCTION_RECV],
|
||||
&NextIrp->Tail.Overlay.ListEntry);
|
||||
break;
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Completing recv %x (%d)\n", NextIrp,
|
||||
TotalBytesCopied));
|
||||
UnlockBuffers( RecvReq->BufferArray,
|
||||
RecvReq->BufferCount, FALSE );
|
||||
NextIrp->IoStatus.Status = Status;
|
||||
NextIrp->IoStatus.Information = TotalBytesCopied;
|
||||
if( NextIrp == Irp ) {
|
||||
RetStatus = Status;
|
||||
RetBytesCopied = TotalBytesCopied;
|
||||
}
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
}
|
||||
/* Kick the user that receive would be possible now */
|
||||
/* XXX Not implemented yet */
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("FCB %x Receive data waiting %d\n",
|
||||
FCB, FCB->Recv.Content));
|
||||
/*OskitDumpBuffer( FCB->Recv.Window, FCB->Recv.Content );*/
|
||||
|
||||
/* Try to clear some requests */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("RecvReq @ %x\n", RecvReq));
|
||||
|
||||
Status = TryToSatisfyRecvRequestFromBuffer
|
||||
( FCB, RecvReq, &TotalBytesCopied );
|
||||
|
||||
if( Status == STATUS_PENDING ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Ran out of data for %x\n", NextIrp));
|
||||
InsertHeadList(&FCB->PendingIrpList[FUNCTION_RECV],
|
||||
&NextIrp->Tail.Overlay.ListEntry);
|
||||
break;
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Completing recv %x (%d)\n", NextIrp,
|
||||
TotalBytesCopied));
|
||||
UnlockBuffers( RecvReq->BufferArray,
|
||||
RecvReq->BufferCount, FALSE );
|
||||
NextIrp->IoStatus.Status = Status;
|
||||
NextIrp->IoStatus.Information = TotalBytesCopied;
|
||||
if( NextIrp == Irp ) {
|
||||
RetStatus = Status;
|
||||
RetBytesCopied = TotalBytesCopied;
|
||||
}
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( FCB->Recv.Content - FCB->Recv.BytesUsed &&
|
||||
IsListEmpty(&FCB->PendingIrpList[FUNCTION_RECV]) ) {
|
||||
FCB->PollState |= AFD_EVENT_RECEIVE;
|
||||
FCB->PollState |= AFD_EVENT_RECEIVE;
|
||||
FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
|
@ -286,29 +282,29 @@ NTSTATUS NTAPI ReceiveComplete
|
|||
if( FCB->State == SOCKET_STATE_CLOSED ) {
|
||||
/* Cleanup our IRP queue because the FCB is being destroyed */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation(NextIrp);
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation(NextIrp);
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, FALSE);
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
} else if( FCB->State == SOCKET_STATE_LISTENING ) {
|
||||
AFD_DbgPrint(MIN_TRACE,("!!! LISTENER GOT A RECEIVE COMPLETE !!!\n"));
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
HandleReceiveComplete( FCB, Irp->IoStatus.Status, Irp->IoStatus.Information );
|
||||
|
||||
ReceiveActivity( FCB, NULL );
|
||||
|
||||
HandleReceiveComplete( FCB, Irp->IoStatus.Status, Irp->IoStatus.Information );
|
||||
|
||||
ReceiveActivity( FCB, NULL );
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
@ -325,69 +321,68 @@ SatisfyPacketRecvRequest( PAFD_FCB FCB, PIRP Irp,
|
|||
UINT BytesToCopy = 0, BytesAvailable = DatagramRecv->Len, AddrLen = 0;
|
||||
PAFD_MAPBUF Map;
|
||||
BOOLEAN ExtraBuffers = CheckUnlockExtraBuffers(FCB, IrpSp);
|
||||
|
||||
|
||||
Map = (PAFD_MAPBUF)(RecvReq->BufferArray +
|
||||
RecvReq->BufferCount +
|
||||
(ExtraBuffers ? EXTRA_LOCK_BUFFERS : 0));
|
||||
|
||||
BytesToCopy =
|
||||
MIN( RecvReq->BufferArray[0].len, BytesAvailable );
|
||||
|
||||
RecvReq->BufferCount +
|
||||
(ExtraBuffers ? EXTRA_LOCK_BUFFERS : 0));
|
||||
|
||||
BytesToCopy = MIN( RecvReq->BufferArray[0].len, BytesAvailable );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("BytesToCopy: %d len %d\n", BytesToCopy,
|
||||
RecvReq->BufferArray[0].len));
|
||||
|
||||
RecvReq->BufferArray[0].len));
|
||||
|
||||
if( Map[0].Mdl ) {
|
||||
/* Copy the address */
|
||||
if( ExtraBuffers && Map[1].Mdl && Map[2].Mdl ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Checking TAAddressCount\n"));
|
||||
|
||||
if( DatagramRecv->Address->TAAddressCount != 1 ) {
|
||||
AFD_DbgPrint
|
||||
/* Copy the address */
|
||||
if( ExtraBuffers && Map[1].Mdl && Map[2].Mdl ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Checking TAAddressCount\n"));
|
||||
|
||||
if( DatagramRecv->Address->TAAddressCount != 1 ) {
|
||||
AFD_DbgPrint
|
||||
(MIN_TRACE,
|
||||
("Wierd address count %d\n",
|
||||
DatagramRecv->Address->TAAddressCount));
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Computing addr len\n"));
|
||||
|
||||
AddrLen = MIN(DatagramRecv->Address->Address->AddressLength +
|
||||
sizeof(USHORT),
|
||||
RecvReq->BufferArray[1].len);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Copying %d bytes of address\n", AddrLen));
|
||||
|
||||
Map[1].BufferAddress = MmMapLockedPages( Map[1].Mdl, KernelMode );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Done mapping, copying address\n"));
|
||||
|
||||
RtlCopyMemory( Map[1].BufferAddress,
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Computing addr len\n"));
|
||||
|
||||
AddrLen = MIN(DatagramRecv->Address->Address->AddressLength +
|
||||
sizeof(USHORT),
|
||||
RecvReq->BufferArray[1].len);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Copying %d bytes of address\n", AddrLen));
|
||||
|
||||
Map[1].BufferAddress = MmMapLockedPages( Map[1].Mdl, KernelMode );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Done mapping, copying address\n"));
|
||||
|
||||
RtlCopyMemory( Map[1].BufferAddress,
|
||||
&DatagramRecv->Address->Address->AddressType,
|
||||
AddrLen );
|
||||
|
||||
MmUnmapLockedPages( Map[1].BufferAddress, Map[1].Mdl );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Copying address len\n"));
|
||||
|
||||
Map[2].BufferAddress = MmMapLockedPages( Map[2].Mdl, KernelMode );
|
||||
*((PINT)Map[2].BufferAddress) = AddrLen;
|
||||
MmUnmapLockedPages( Map[2].BufferAddress, Map[2].Mdl );
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Mapping data buffer pages\n"));
|
||||
|
||||
Map[0].BufferAddress = MmMapLockedPages( Map[0].Mdl, KernelMode );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Buffer %d: %x:%d\n",
|
||||
0,
|
||||
Map[0].BufferAddress,
|
||||
BytesToCopy));
|
||||
|
||||
RtlCopyMemory( Map[0].BufferAddress,
|
||||
|
||||
MmUnmapLockedPages( Map[1].BufferAddress, Map[1].Mdl );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Copying address len\n"));
|
||||
|
||||
Map[2].BufferAddress = MmMapLockedPages( Map[2].Mdl, KernelMode );
|
||||
*((PINT)Map[2].BufferAddress) = AddrLen;
|
||||
MmUnmapLockedPages( Map[2].BufferAddress, Map[2].Mdl );
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Mapping data buffer pages\n"));
|
||||
|
||||
Map[0].BufferAddress = MmMapLockedPages( Map[0].Mdl, KernelMode );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Buffer %d: %x:%d\n",
|
||||
0,
|
||||
Map[0].BufferAddress,
|
||||
BytesToCopy));
|
||||
|
||||
RtlCopyMemory( Map[0].BufferAddress,
|
||||
DatagramRecv->Buffer,
|
||||
BytesToCopy );
|
||||
|
||||
MmUnmapLockedPages( Map[0].BufferAddress, Map[0].Mdl );
|
||||
|
||||
|
||||
MmUnmapLockedPages( Map[0].BufferAddress, Map[0].Mdl );
|
||||
|
||||
*TotalBytesCopied = BytesToCopy;
|
||||
}
|
||||
|
||||
|
@ -403,22 +398,22 @@ SatisfyPacketRecvRequest( PAFD_FCB FCB, PIRP Irp,
|
|||
}
|
||||
|
||||
Irp->IoStatus.Information = *TotalBytesCopied;
|
||||
|
||||
|
||||
if (!(RecvReq->TdiFlags & TDI_RECEIVE_PEEK))
|
||||
{
|
||||
FCB->Recv.Content -= *TotalBytesCopied;
|
||||
ExFreePool( DatagramRecv->Address );
|
||||
ExFreePool( DatagramRecv );
|
||||
}
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Done\n"));
|
||||
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS NTAPI
|
||||
AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp, BOOLEAN Short) {
|
||||
PIO_STACK_LOCATION IrpSp, BOOLEAN Short) {
|
||||
NTSTATUS Status = STATUS_INVALID_PARAMETER;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -437,20 +432,20 @@ AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
AFD_DbgPrint(MIN_TRACE,("Called recv on wrong kind of socket (s%x)\n",
|
||||
FCB->State));
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_INVALID_PARAMETER,
|
||||
Irp, 0 );
|
||||
Irp, 0 );
|
||||
}
|
||||
|
||||
|
||||
if( !(RecvReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
|
||||
Irp, 0 );
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY,
|
||||
Irp, 0 );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Recv flags %x\n", RecvReq->AfdFlags));
|
||||
|
||||
|
||||
RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray,
|
||||
RecvReq->BufferCount,
|
||||
NULL, NULL,
|
||||
TRUE, FALSE );
|
||||
|
||||
|
||||
if( !RecvReq->BufferArray ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_ACCESS_VIOLATION,
|
||||
Irp, 0 );
|
||||
|
@ -460,11 +455,11 @@ AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
if( FCB->Flags & AFD_ENDPOINT_CONNECTIONLESS )
|
||||
{
|
||||
if (!IsListEmpty(&FCB->DatagramList))
|
||||
if (!IsListEmpty(&FCB->DatagramList))
|
||||
{
|
||||
ListEntry = RemoveHeadList(&FCB->DatagramList);
|
||||
DatagramRecv = CONTAINING_RECORD(ListEntry, AFD_STORED_DATAGRAM, ListEntry);
|
||||
Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
|
||||
Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
|
||||
(PUINT)&Irp->IoStatus.Information);
|
||||
|
||||
if (RecvReq->TdiFlags & TDI_RECEIVE_PEEK)
|
||||
|
@ -534,9 +529,9 @@ AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
PacketSocketRecvComplete(
|
||||
PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp,
|
||||
PVOID Context ) {
|
||||
PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp,
|
||||
PVOID Context ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PAFD_FCB FCB = Context;
|
||||
PIRP NextIrp;
|
||||
|
@ -558,16 +553,16 @@ PacketSocketRecvComplete(
|
|||
if( FCB->State == SOCKET_STATE_CLOSED ) {
|
||||
/* Cleanup our IRP queue because the FCB is being destroyed */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, CheckUnlockExtraBuffers(FCB, NextIrpSp));
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, CheckUnlockExtraBuffers(FCB, NextIrpSp));
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
/* Free all items on the datagram list */
|
||||
|
@ -578,10 +573,10 @@ PacketSocketRecvComplete(
|
|||
ExFreePool( DatagramRecv );
|
||||
}
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
}
|
||||
|
||||
|
||||
if (Irp->IoStatus.Status != STATUS_SUCCESS)
|
||||
{
|
||||
SocketStateUnlock(FCB);
|
||||
|
@ -597,44 +592,44 @@ PacketSocketRecvComplete(
|
|||
DatagramRecv = ExAllocatePool( NonPagedPool, DGSize );
|
||||
|
||||
if( DatagramRecv ) {
|
||||
DatagramRecv->Len = Irp->IoStatus.Information;
|
||||
RtlCopyMemory( DatagramRecv->Buffer, FCB->Recv.Window,
|
||||
DatagramRecv->Len );
|
||||
AFD_DbgPrint(MID_TRACE,("Received (A %x)\n",
|
||||
FCB->AddressFrom->RemoteAddress));
|
||||
DatagramRecv->Address =
|
||||
TaCopyTransportAddress( FCB->AddressFrom->RemoteAddress );
|
||||
DatagramRecv->Len = Irp->IoStatus.Information;
|
||||
RtlCopyMemory( DatagramRecv->Buffer, FCB->Recv.Window,
|
||||
DatagramRecv->Len );
|
||||
AFD_DbgPrint(MID_TRACE,("Received (A %x)\n",
|
||||
FCB->AddressFrom->RemoteAddress));
|
||||
DatagramRecv->Address =
|
||||
TaCopyTransportAddress( FCB->AddressFrom->RemoteAddress );
|
||||
|
||||
if( !DatagramRecv->Address ) Status = STATUS_NO_MEMORY;
|
||||
if( !DatagramRecv->Address ) Status = STATUS_NO_MEMORY;
|
||||
|
||||
} else Status = STATUS_NO_MEMORY;
|
||||
|
||||
if( !NT_SUCCESS( Status ) ) {
|
||||
if( DatagramRecv ) ExFreePool( DatagramRecv );
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
if( DatagramRecv ) ExFreePool( DatagramRecv );
|
||||
SocketStateUnlock( FCB );
|
||||
return Status;
|
||||
} else {
|
||||
FCB->Recv.Content += DatagramRecv->Len;
|
||||
InsertTailList( &FCB->DatagramList, &DatagramRecv->ListEntry );
|
||||
InsertTailList( &FCB->DatagramList, &DatagramRecv->ListEntry );
|
||||
}
|
||||
|
||||
/* Satisfy as many requests as we can */
|
||||
|
||||
while( !IsListEmpty( &FCB->DatagramList ) &&
|
||||
!IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Looping trying to satisfy request\n"));
|
||||
ListEntry = RemoveHeadList( &FCB->DatagramList );
|
||||
DatagramRecv = CONTAINING_RECORD( ListEntry, AFD_STORED_DATAGRAM,
|
||||
ListEntry );
|
||||
ListEntry = RemoveHeadList( &FCB->PendingIrpList[FUNCTION_RECV] );
|
||||
NextIrp = CONTAINING_RECORD( ListEntry, IRP, Tail.Overlay.ListEntry );
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
!IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Looping trying to satisfy request\n"));
|
||||
ListEntry = RemoveHeadList( &FCB->DatagramList );
|
||||
DatagramRecv = CONTAINING_RECORD( ListEntry, AFD_STORED_DATAGRAM,
|
||||
ListEntry );
|
||||
ListEntry = RemoveHeadList( &FCB->PendingIrpList[FUNCTION_RECV] );
|
||||
NextIrp = CONTAINING_RECORD( ListEntry, IRP, Tail.Overlay.ListEntry );
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
RecvReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("RecvReq: %x, DatagramRecv: %x\n",
|
||||
RecvReq, DatagramRecv));
|
||||
AFD_DbgPrint(MID_TRACE,("RecvReq: %x, DatagramRecv: %x\n",
|
||||
RecvReq, DatagramRecv));
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Satisfying\n"));
|
||||
AFD_DbgPrint(MID_TRACE,("Satisfying\n"));
|
||||
Status = SatisfyPacketRecvRequest
|
||||
( FCB, NextIrp, DatagramRecv,
|
||||
(PUINT)&NextIrp->IoStatus.Information );
|
||||
|
@ -647,7 +642,7 @@ PacketSocketRecvComplete(
|
|||
|
||||
AFD_DbgPrint(MID_TRACE,("Unlocking\n"));
|
||||
UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount, CheckUnlockExtraBuffers(FCB, NextIrpSp) );
|
||||
if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Completing\n"));
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
|
@ -657,25 +652,25 @@ PacketSocketRecvComplete(
|
|||
}
|
||||
|
||||
if( !IsListEmpty( &FCB->DatagramList ) && IsListEmpty(&FCB->PendingIrpList[FUNCTION_RECV]) ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling\n"));
|
||||
FCB->PollState |= AFD_EVENT_RECEIVE;
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling\n"));
|
||||
FCB->PollState |= AFD_EVENT_RECEIVE;
|
||||
FCB->PollStatus[FD_READ_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
} else
|
||||
FCB->PollState &= ~AFD_EVENT_RECEIVE;
|
||||
|
||||
if( NT_SUCCESS(Irp->IoStatus.Status) ) {
|
||||
/* Now relaunch the datagram request */
|
||||
Status = TdiReceiveDatagram
|
||||
( &FCB->ReceiveIrp.InFlightRequest,
|
||||
FCB->AddressFile.Object,
|
||||
0,
|
||||
FCB->Recv.Window,
|
||||
FCB->Recv.Size,
|
||||
FCB->AddressFrom,
|
||||
&FCB->ReceiveIrp.Iosb,
|
||||
PacketSocketRecvComplete,
|
||||
FCB );
|
||||
/* Now relaunch the datagram request */
|
||||
Status = TdiReceiveDatagram
|
||||
( &FCB->ReceiveIrp.InFlightRequest,
|
||||
FCB->AddressFile.Object,
|
||||
0,
|
||||
FCB->Recv.Window,
|
||||
FCB->Recv.Size,
|
||||
FCB->AddressFrom,
|
||||
&FCB->ReceiveIrp.Iosb,
|
||||
PacketSocketRecvComplete,
|
||||
FCB );
|
||||
}
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
|
@ -685,7 +680,7 @@ PacketSocketRecvComplete(
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -701,8 +696,7 @@ AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( FCB->State != SOCKET_STATE_BOUND )
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Invalid socket state\n"));
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_INVALID_PARAMETER, Irp, 0 );
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_INVALID_PARAMETER, Irp, 0);
|
||||
}
|
||||
|
||||
if (FCB->TdiReceiveClosed)
|
||||
|
@ -712,20 +706,18 @@ AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
if( !(RecvReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_NO_MEMORY, Irp, 0 );
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Recv flags %x\n", RecvReq->AfdFlags));
|
||||
|
||||
RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray,
|
||||
RecvReq->BufferCount,
|
||||
RecvReq->Address,
|
||||
RecvReq->AddressLength,
|
||||
TRUE, TRUE );
|
||||
RecvReq->BufferCount,
|
||||
RecvReq->Address,
|
||||
RecvReq->AddressLength,
|
||||
TRUE, TRUE );
|
||||
|
||||
if( !RecvReq->BufferArray ) { /* access violation in userspace */
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_ACCESS_VIOLATION, Irp, 0 );
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_ACCESS_VIOLATION, Irp, 0);
|
||||
}
|
||||
|
||||
FCB->EventSelectDisabled &= ~AFD_EVENT_RECEIVE;
|
||||
|
@ -734,15 +726,15 @@ AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
{
|
||||
ListEntry = RemoveHeadList(&FCB->DatagramList);
|
||||
DatagramRecv = CONTAINING_RECORD(ListEntry, AFD_STORED_DATAGRAM, ListEntry);
|
||||
Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
|
||||
Status = SatisfyPacketRecvRequest(FCB, Irp, DatagramRecv,
|
||||
(PUINT)&Irp->IoStatus.Information);
|
||||
|
||||
|
||||
if (RecvReq->TdiFlags & TDI_RECEIVE_PEEK)
|
||||
{
|
||||
InsertHeadList(&FCB->DatagramList,
|
||||
&DatagramRecv->ListEntry);
|
||||
}
|
||||
|
||||
|
||||
if (!IsListEmpty(&FCB->DatagramList))
|
||||
{
|
||||
FCB->PollState |= AFD_EVENT_RECEIVE;
|
||||
|
@ -751,9 +743,9 @@ AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
else
|
||||
FCB->PollState &= ~AFD_EVENT_RECEIVE;
|
||||
|
||||
|
||||
UnlockBuffers(RecvReq->BufferArray, RecvReq->BufferCount, TRUE);
|
||||
|
||||
|
||||
return UnlockAndMaybeComplete(FCB, Status, Irp, Irp->IoStatus.Information);
|
||||
}
|
||||
else if( (RecvReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) )
|
||||
|
|
|
@ -31,22 +31,22 @@ static VOID PrintEvents( ULONG Events ) {
|
|||
}
|
||||
|
||||
static VOID CopyBackStatus( PAFD_HANDLE HandleArray,
|
||||
UINT HandleCount ) {
|
||||
UINT HandleCount ) {
|
||||
UINT i;
|
||||
|
||||
for( i = 0; i < HandleCount; i++ ) {
|
||||
HandleArray[i].Events = HandleArray[i].Status;
|
||||
HandleArray[i].Status = 0;
|
||||
HandleArray[i].Events = HandleArray[i].Status;
|
||||
HandleArray[i].Status = 0;
|
||||
}
|
||||
}
|
||||
|
||||
VOID ZeroEvents( PAFD_HANDLE HandleArray,
|
||||
UINT HandleCount ) {
|
||||
UINT HandleCount ) {
|
||||
UINT i;
|
||||
|
||||
for( i = 0; i < HandleCount; i++ ) {
|
||||
HandleArray[i].Status = 0;
|
||||
HandleArray[i].Events = 0;
|
||||
HandleArray[i].Status = 0;
|
||||
HandleArray[i].Events = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ VOID SignalSocket(
|
|||
PAFD_ACTIVE_POLL Poll OPTIONAL,
|
||||
PIRP _Irp OPTIONAL,
|
||||
PAFD_POLL_INFO PollReq,
|
||||
NTSTATUS Status
|
||||
NTSTATUS Status
|
||||
)
|
||||
{
|
||||
UINT i;
|
||||
|
@ -65,16 +65,16 @@ VOID SignalSocket(
|
|||
|
||||
if (Poll)
|
||||
{
|
||||
KeCancelTimer( &Poll->Timer );
|
||||
RemoveEntryList( &Poll->ListEntry );
|
||||
ExFreePool( Poll );
|
||||
}
|
||||
KeCancelTimer( &Poll->Timer );
|
||||
RemoveEntryList( &Poll->ListEntry );
|
||||
ExFreePool( Poll );
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information =
|
||||
FIELD_OFFSET(AFD_POLL_INFO, Handles) + sizeof(AFD_HANDLE) * PollReq->HandleCount;
|
||||
CopyBackStatus( PollReq->Handles,
|
||||
PollReq->HandleCount );
|
||||
PollReq->HandleCount );
|
||||
for( i = 0; i < PollReq->HandleCount; i++ ) {
|
||||
AFD_DbgPrint
|
||||
(MAX_TRACE,
|
||||
|
@ -92,9 +92,9 @@ VOID SignalSocket(
|
|||
}
|
||||
|
||||
static VOID SelectTimeout( PKDPC Dpc,
|
||||
PVOID DeferredContext,
|
||||
PVOID SystemArgument1,
|
||||
PVOID SystemArgument2 ) {
|
||||
PVOID DeferredContext,
|
||||
PVOID SystemArgument1,
|
||||
PVOID SystemArgument2 ) {
|
||||
PAFD_ACTIVE_POLL Poll = DeferredContext;
|
||||
PAFD_POLL_INFO PollReq;
|
||||
PIRP Irp;
|
||||
|
@ -133,8 +133,8 @@ VOID KillSelectsForFCB( PAFD_DEVICE_EXTENSION DeviceExt,
|
|||
|
||||
ListEntry = DeviceExt->Polls.Flink;
|
||||
while ( ListEntry != &DeviceExt->Polls ) {
|
||||
Poll = CONTAINING_RECORD(ListEntry, AFD_ACTIVE_POLL, ListEntry);
|
||||
ListEntry = ListEntry->Flink;
|
||||
Poll = CONTAINING_RECORD(ListEntry, AFD_ACTIVE_POLL, ListEntry);
|
||||
ListEntry = ListEntry->Flink;
|
||||
Irp = Poll->Irp;
|
||||
PollReq = Irp->AssociatedIrp.SystemBuffer;
|
||||
HandleArray = AFD_HANDLES(PollReq);
|
||||
|
@ -147,7 +147,7 @@ VOID KillSelectsForFCB( PAFD_DEVICE_EXTENSION DeviceExt,
|
|||
ZeroEvents( PollReq->Handles, PollReq->HandleCount );
|
||||
SignalSocket( Poll, NULL, PollReq, STATUS_CANCELLED );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
|
||||
|
@ -157,7 +157,7 @@ VOID KillSelectsForFCB( PAFD_DEVICE_EXTENSION DeviceExt,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
NTSTATUS Status = STATUS_NO_MEMORY;
|
||||
PAFD_FCB FCB;
|
||||
PFILE_OBJECT FileObject;
|
||||
|
@ -168,17 +168,17 @@ AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
ULONG Exclusive = PollReq->Exclusive;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called (HandleCount %d Timeout %d)\n",
|
||||
PollReq->HandleCount,
|
||||
(INT)(PollReq->Timeout.QuadPart)));
|
||||
PollReq->HandleCount,
|
||||
(INT)(PollReq->Timeout.QuadPart)));
|
||||
|
||||
SET_AFD_HANDLES(PollReq,
|
||||
LockHandles( PollReq->Handles, PollReq->HandleCount ));
|
||||
LockHandles( PollReq->Handles, PollReq->HandleCount ));
|
||||
|
||||
if( !AFD_HANDLES(PollReq) ) {
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
|
||||
return STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Status = STATUS_NO_MEMORY;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
if( Exclusive ) {
|
||||
|
@ -191,32 +191,32 @@ AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
}
|
||||
|
||||
KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
|
||||
KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
|
||||
|
||||
for( i = 0; i < PollReq->HandleCount; i++ ) {
|
||||
if( !AFD_HANDLES(PollReq)[i].Handle ) continue;
|
||||
for( i = 0; i < PollReq->HandleCount; i++ ) {
|
||||
if( !AFD_HANDLES(PollReq)[i].Handle ) continue;
|
||||
|
||||
FileObject = (PFILE_OBJECT)AFD_HANDLES(PollReq)[i].Handle;
|
||||
FCB = FileObject->FsContext;
|
||||
FileObject = (PFILE_OBJECT)AFD_HANDLES(PollReq)[i].Handle;
|
||||
FCB = FileObject->FsContext;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE, ("AFD: Select Events: "));
|
||||
PrintEvents( PollReq->Handles[i].Events );
|
||||
AFD_DbgPrint(MID_TRACE,("\n"));
|
||||
AFD_DbgPrint(MID_TRACE, ("AFD: Select Events: "));
|
||||
PrintEvents( PollReq->Handles[i].Events );
|
||||
AFD_DbgPrint(MID_TRACE,("\n"));
|
||||
|
||||
PollReq->Handles[i].Status =
|
||||
PollReq->Handles[i].Events & FCB->PollState;
|
||||
if( PollReq->Handles[i].Status ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling %x with %x\n",
|
||||
FCB, FCB->PollState));
|
||||
Signalled++;
|
||||
}
|
||||
}
|
||||
PollReq->Handles[i].Status =
|
||||
PollReq->Handles[i].Events & FCB->PollState;
|
||||
if( PollReq->Handles[i].Status ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling %x with %x\n",
|
||||
FCB, FCB->PollState));
|
||||
Signalled++;
|
||||
}
|
||||
}
|
||||
|
||||
if( Signalled ) {
|
||||
Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Status = Status;
|
||||
SignalSocket( NULL, Irp, PollReq, Status );
|
||||
} else {
|
||||
if( Signalled ) {
|
||||
Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Status = Status;
|
||||
SignalSocket( NULL, Irp, PollReq, Status );
|
||||
} else {
|
||||
|
||||
PAFD_ACTIVE_POLL Poll = NULL;
|
||||
|
||||
|
@ -244,9 +244,9 @@ AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
AFD_DbgPrint(MAX_TRACE, ("FIXME: do something with the IRP!\n"));
|
||||
Status = STATUS_NO_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
|
||||
KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
|
||||
|
@ -255,55 +255,55 @@ AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdEventSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
NTSTATUS Status = STATUS_NO_MEMORY;
|
||||
PAFD_EVENT_SELECT_INFO EventSelectInfo =
|
||||
(PAFD_EVENT_SELECT_INFO)LockRequest( Irp, IrpSp );
|
||||
(PAFD_EVENT_SELECT_INFO)LockRequest( Irp, IrpSp );
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) ) {
|
||||
return LostSocket( Irp );
|
||||
return LostSocket( Irp );
|
||||
}
|
||||
|
||||
if ( !EventSelectInfo ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp,
|
||||
0 );
|
||||
0 );
|
||||
}
|
||||
AFD_DbgPrint(MID_TRACE,("Called (Event %x Triggers %x)\n",
|
||||
EventSelectInfo->EventObject,
|
||||
EventSelectInfo->Events));
|
||||
EventSelectInfo->EventObject,
|
||||
EventSelectInfo->Events));
|
||||
|
||||
if( FCB->EventSelect ) ObDereferenceObject( FCB->EventSelect );
|
||||
FCB->EventSelect = NULL;
|
||||
|
||||
if( EventSelectInfo->EventObject && EventSelectInfo->Events ) {
|
||||
Status = ObReferenceObjectByHandle( (PVOID)EventSelectInfo->
|
||||
EventObject,
|
||||
EVENT_ALL_ACCESS,
|
||||
ExEventObjectType,
|
||||
UserMode,
|
||||
(PVOID *)&FCB->EventSelect,
|
||||
NULL );
|
||||
Status = ObReferenceObjectByHandle( (PVOID)EventSelectInfo->
|
||||
EventObject,
|
||||
EVENT_ALL_ACCESS,
|
||||
ExEventObjectType,
|
||||
UserMode,
|
||||
(PVOID *)&FCB->EventSelect,
|
||||
NULL );
|
||||
|
||||
if( !NT_SUCCESS(Status) )
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Failed reference event (0x%x)\n", Status));
|
||||
FCB->EventSelect = NULL;
|
||||
}
|
||||
else
|
||||
FCB->EventSelectTriggers = EventSelectInfo->Events;
|
||||
if( !NT_SUCCESS(Status) )
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Failed reference event (0x%x)\n", Status));
|
||||
FCB->EventSelect = NULL;
|
||||
}
|
||||
else
|
||||
FCB->EventSelectTriggers = EventSelectInfo->Events;
|
||||
} else {
|
||||
FCB->EventSelect = NULL;
|
||||
FCB->EventSelectTriggers = 0;
|
||||
Status = STATUS_SUCCESS;
|
||||
Status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if((FCB->EventSelect) &&
|
||||
(FCB->PollState & (FCB->EventSelectTriggers & ~FCB->EventSelectDisabled)))
|
||||
{
|
||||
AFD_DbgPrint(MID_TRACE,("Setting event %x\n", FCB->EventSelect));
|
||||
|
||||
|
||||
/* Disable the events that triggered the select until the reenabling function is called */
|
||||
FCB->EventSelectDisabled |= (FCB->PollState & (FCB->EventSelectTriggers & ~FCB->EventSelectDisabled));
|
||||
|
||||
|
@ -314,26 +314,25 @@ AfdEventSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, Status, Irp,
|
||||
0 );
|
||||
0 );
|
||||
}
|
||||
|
||||
NTSTATUS NTAPI
|
||||
AfdEnumEvents( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PIO_STACK_LOCATION IrpSp ) {
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_ENUM_NETWORK_EVENTS_INFO EnumReq =
|
||||
(PAFD_ENUM_NETWORK_EVENTS_INFO)LockRequest( Irp, IrpSp );
|
||||
(PAFD_ENUM_NETWORK_EVENTS_INFO)LockRequest( Irp, IrpSp );
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called (FCB %x)\n", FCB));
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) ) {
|
||||
return LostSocket( Irp );
|
||||
return LostSocket( Irp );
|
||||
}
|
||||
|
||||
if ( !EnumReq ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp,
|
||||
0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_NO_MEMORY, Irp, 0 );
|
||||
}
|
||||
|
||||
EnumReq->PollEvents = FCB->PollState;
|
||||
|
@ -341,8 +340,7 @@ AfdEnumEvents( PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
FCB->PollStatus,
|
||||
sizeof(EnumReq->EventStatus) );
|
||||
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp,
|
||||
0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_SUCCESS, Irp, 0 );
|
||||
}
|
||||
|
||||
/* * * NOTE ALWAYS CALLED AT DISPATCH_LEVEL * * */
|
||||
|
@ -355,17 +353,17 @@ static BOOLEAN UpdatePollWithFCB( PAFD_ACTIVE_POLL Poll, PFILE_OBJECT FileObject
|
|||
ASSERT( KeGetCurrentIrql() == DISPATCH_LEVEL );
|
||||
|
||||
for( i = 0; i < PollReq->HandleCount; i++ ) {
|
||||
if( !AFD_HANDLES(PollReq)[i].Handle ) continue;
|
||||
if( !AFD_HANDLES(PollReq)[i].Handle ) continue;
|
||||
|
||||
FileObject = (PFILE_OBJECT)AFD_HANDLES(PollReq)[i].Handle;
|
||||
FCB = FileObject->FsContext;
|
||||
FileObject = (PFILE_OBJECT)AFD_HANDLES(PollReq)[i].Handle;
|
||||
FCB = FileObject->FsContext;
|
||||
|
||||
PollReq->Handles[i].Status = PollReq->Handles[i].Events & FCB->PollState;
|
||||
if( PollReq->Handles[i].Status ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling %x with %x\n",
|
||||
FCB, FCB->PollState));
|
||||
Signalled++;
|
||||
}
|
||||
PollReq->Handles[i].Status = PollReq->Handles[i].Events & FCB->PollState;
|
||||
if( PollReq->Handles[i].Status ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling %x with %x\n",
|
||||
FCB, FCB->PollState));
|
||||
Signalled++;
|
||||
}
|
||||
}
|
||||
|
||||
return Signalled ? 1 : 0;
|
||||
|
@ -379,7 +377,7 @@ VOID PollReeval( PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject ) {
|
|||
PAFD_POLL_INFO PollReq;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called: DeviceExt %x FileObject %x\n",
|
||||
DeviceExt, FileObject));
|
||||
DeviceExt, FileObject));
|
||||
|
||||
KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
|
||||
|
||||
|
@ -387,24 +385,24 @@ VOID PollReeval( PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject ) {
|
|||
FCB = (PAFD_FCB)FileObject->FsContext;
|
||||
|
||||
if( !FCB ) {
|
||||
KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
|
||||
return;
|
||||
KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now signal normal select irps */
|
||||
ThePollEnt = DeviceExt->Polls.Flink;
|
||||
|
||||
while( ThePollEnt != &DeviceExt->Polls ) {
|
||||
Poll = CONTAINING_RECORD( ThePollEnt, AFD_ACTIVE_POLL, ListEntry );
|
||||
PollReq = Poll->Irp->AssociatedIrp.SystemBuffer;
|
||||
AFD_DbgPrint(MID_TRACE,("Checking poll %x\n", Poll));
|
||||
Poll = CONTAINING_RECORD( ThePollEnt, AFD_ACTIVE_POLL, ListEntry );
|
||||
PollReq = Poll->Irp->AssociatedIrp.SystemBuffer;
|
||||
AFD_DbgPrint(MID_TRACE,("Checking poll %x\n", Poll));
|
||||
|
||||
if( UpdatePollWithFCB( Poll, FileObject ) ) {
|
||||
ThePollEnt = ThePollEnt->Flink;
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling socket\n"));
|
||||
SignalSocket( Poll, NULL, PollReq, STATUS_SUCCESS );
|
||||
} else
|
||||
ThePollEnt = ThePollEnt->Flink;
|
||||
if( UpdatePollWithFCB( Poll, FileObject ) ) {
|
||||
ThePollEnt = ThePollEnt->Flink;
|
||||
AFD_DbgPrint(MID_TRACE,("Signalling socket\n"));
|
||||
SignalSocket( Poll, NULL, PollReq, STATUS_SUCCESS );
|
||||
} else
|
||||
ThePollEnt = ThePollEnt->Flink;
|
||||
}
|
||||
|
||||
KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
|
||||
|
@ -413,10 +411,10 @@ VOID PollReeval( PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject ) {
|
|||
(FCB->PollState & (FCB->EventSelectTriggers & ~FCB->EventSelectDisabled)))
|
||||
{
|
||||
AFD_DbgPrint(MID_TRACE,("Setting event %x\n", FCB->EventSelect));
|
||||
|
||||
|
||||
/* Disable the events that triggered the select until the reenabling function is called */
|
||||
FCB->EventSelectDisabled |= (FCB->PollState & (FCB->EventSelectTriggers & ~FCB->EventSelectDisabled));
|
||||
|
||||
|
||||
/* Set the application's event */
|
||||
KeSetEvent( FCB->EventSelect, IO_NETWORK_INCREMENT, FALSE );
|
||||
}
|
||||
|
|
|
@ -71,12 +71,11 @@ static NTSTATUS TdiCall(
|
|||
|
||||
if ((Status == STATUS_PENDING) && (Event != NULL)) {
|
||||
AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
|
||||
KeWaitForSingleObject(
|
||||
Event,
|
||||
Executive,
|
||||
KernelMode,
|
||||
FALSE,
|
||||
NULL);
|
||||
KeWaitForSingleObject(Event,
|
||||
Executive,
|
||||
KernelMode,
|
||||
FALSE,
|
||||
NULL);
|
||||
Status = Iosb->Status;
|
||||
}
|
||||
|
||||
|
@ -136,11 +135,11 @@ static NTSTATUS TdiOpenDevice(
|
|||
(PVOID*)Object, /* Pointer to object */
|
||||
NULL); /* Handle information */
|
||||
if (!NT_SUCCESS(Status)) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("ObReferenceObjectByHandle() failed with status (0x%X).\n", Status));
|
||||
ZwClose(*Handle);
|
||||
AFD_DbgPrint(MIN_TRACE, ("ObReferenceObjectByHandle() failed with status (0x%X).\n", Status));
|
||||
ZwClose(*Handle);
|
||||
} else {
|
||||
AFD_DbgPrint(MAX_TRACE, ("Got handle (0x%X) Object (0x%X)\n",
|
||||
*Handle, *Object));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Got handle (0x%X) Object (0x%X)\n",
|
||||
*Handle, *Object));
|
||||
}
|
||||
} else {
|
||||
AFD_DbgPrint(MIN_TRACE, ("ZwCreateFile() failed with status (0x%X)\n", Status));
|
||||
|
@ -170,45 +169,45 @@ NTSTATUS TdiOpenAddressFile(
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PFILE_FULL_EA_INFORMATION EaInfo;
|
||||
NTSTATUS Status;
|
||||
ULONG EaLength;
|
||||
PTRANSPORT_ADDRESS Address;
|
||||
PFILE_FULL_EA_INFORMATION EaInfo;
|
||||
NTSTATUS Status;
|
||||
ULONG EaLength;
|
||||
PTRANSPORT_ADDRESS Address;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ) Name (0x%X)\n",
|
||||
DeviceName, Name));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ) Name (0x%X)\n",
|
||||
DeviceName, Name));
|
||||
|
||||
/* EaName must be 0-terminated, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
|
||||
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
|
||||
TDI_TRANSPORT_ADDRESS_LENGTH +
|
||||
TaLengthOfTransportAddress( Name ) + 1;
|
||||
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
|
||||
if (!EaInfo)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
/* EaName must be 0-terminated, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
|
||||
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
|
||||
TDI_TRANSPORT_ADDRESS_LENGTH +
|
||||
TaLengthOfTransportAddress( Name ) + 1;
|
||||
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
|
||||
if (!EaInfo)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
RtlZeroMemory(EaInfo, EaLength);
|
||||
EaInfo->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
|
||||
/* Don't copy the terminating 0; we have already zeroed it */
|
||||
RtlCopyMemory(EaInfo->EaName,
|
||||
TdiTransportAddress,
|
||||
TDI_TRANSPORT_ADDRESS_LENGTH);
|
||||
EaInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
|
||||
Address =
|
||||
(PTRANSPORT_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); /* 0-terminated */
|
||||
TaCopyTransportAddressInPlace( Address, Name );
|
||||
RtlZeroMemory(EaInfo, EaLength);
|
||||
EaInfo->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
|
||||
/* Don't copy the terminating 0; we have already zeroed it */
|
||||
RtlCopyMemory(EaInfo->EaName,
|
||||
TdiTransportAddress,
|
||||
TDI_TRANSPORT_ADDRESS_LENGTH);
|
||||
EaInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
|
||||
Address =
|
||||
(PTRANSPORT_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); /* 0-terminated */
|
||||
TaCopyTransportAddressInPlace( Address, Name );
|
||||
|
||||
Status = TdiOpenDevice(DeviceName,
|
||||
EaLength,
|
||||
EaInfo,
|
||||
AddressHandle,
|
||||
AddressObject);
|
||||
ExFreePool(EaInfo);
|
||||
return Status;
|
||||
Status = TdiOpenDevice(DeviceName,
|
||||
EaLength,
|
||||
EaInfo,
|
||||
AddressHandle,
|
||||
AddressObject);
|
||||
ExFreePool(EaInfo);
|
||||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS TdiQueryMaxDatagramLength(
|
||||
PFILE_OBJECT FileObject,
|
||||
PUINT MaxDatagramLength)
|
||||
PFILE_OBJECT FileObject,
|
||||
PUINT MaxDatagramLength)
|
||||
{
|
||||
PMDL Mdl;
|
||||
PTDI_MAX_DATAGRAM_INFO Buffer;
|
||||
|
@ -259,9 +258,9 @@ NTSTATUS TdiQueryMaxDatagramLength(
|
|||
}
|
||||
|
||||
NTSTATUS TdiOpenConnectionEndpointFile(
|
||||
PUNICODE_STRING DeviceName,
|
||||
PHANDLE ConnectionHandle,
|
||||
PFILE_OBJECT *ConnectionObject)
|
||||
PUNICODE_STRING DeviceName,
|
||||
PHANDLE ConnectionHandle,
|
||||
PFILE_OBJECT *ConnectionObject)
|
||||
/*
|
||||
* FUNCTION: Opens a connection endpoint file object
|
||||
* ARGUMENTS:
|
||||
|
@ -272,39 +271,39 @@ NTSTATUS TdiOpenConnectionEndpointFile(
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PFILE_FULL_EA_INFORMATION EaInfo;
|
||||
PVOID *ContextArea;
|
||||
NTSTATUS Status;
|
||||
ULONG EaLength;
|
||||
PFILE_FULL_EA_INFORMATION EaInfo;
|
||||
PVOID *ContextArea;
|
||||
NTSTATUS Status;
|
||||
ULONG EaLength;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ)\n", DeviceName));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. DeviceName (%wZ)\n", DeviceName));
|
||||
|
||||
/* EaName must be 0-terminated, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
|
||||
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
|
||||
TDI_CONNECTION_CONTEXT_LENGTH +
|
||||
sizeof(PVOID) + 1;
|
||||
/* EaName must be 0-terminated, even though TDI_TRANSPORT_ADDRESS_LENGTH does *not* include the 0 */
|
||||
EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
|
||||
TDI_CONNECTION_CONTEXT_LENGTH +
|
||||
sizeof(PVOID) + 1;
|
||||
|
||||
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
|
||||
if (!EaInfo)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
|
||||
if (!EaInfo)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
RtlZeroMemory(EaInfo, EaLength);
|
||||
EaInfo->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
|
||||
/* Don't copy the terminating 0; we have already zeroed it */
|
||||
RtlCopyMemory(EaInfo->EaName,
|
||||
TdiConnectionContext,
|
||||
TDI_CONNECTION_CONTEXT_LENGTH);
|
||||
EaInfo->EaValueLength = sizeof(PVOID);
|
||||
ContextArea = (PVOID*)(EaInfo->EaName + TDI_CONNECTION_CONTEXT_LENGTH + 1); /* 0-terminated */
|
||||
/* FIXME: Allocate context area */
|
||||
*ContextArea = NULL;
|
||||
Status = TdiOpenDevice(DeviceName,
|
||||
EaLength,
|
||||
EaInfo,
|
||||
ConnectionHandle,
|
||||
ConnectionObject);
|
||||
ExFreePool(EaInfo);
|
||||
return Status;
|
||||
RtlZeroMemory(EaInfo, EaLength);
|
||||
EaInfo->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
|
||||
/* Don't copy the terminating 0; we have already zeroed it */
|
||||
RtlCopyMemory(EaInfo->EaName,
|
||||
TdiConnectionContext,
|
||||
TDI_CONNECTION_CONTEXT_LENGTH);
|
||||
EaInfo->EaValueLength = sizeof(PVOID);
|
||||
ContextArea = (PVOID*)(EaInfo->EaName + TDI_CONNECTION_CONTEXT_LENGTH + 1); /* 0-terminated */
|
||||
/* FIXME: Allocate context area */
|
||||
*ContextArea = NULL;
|
||||
Status = TdiOpenDevice(DeviceName,
|
||||
EaLength,
|
||||
EaInfo,
|
||||
ConnectionHandle,
|
||||
ConnectionObject);
|
||||
ExFreePool(EaInfo);
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -325,50 +324,50 @@ NTSTATUS TdiConnect(
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||
|
||||
ASSERT(*Irp == NULL);
|
||||
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_CONNECT, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
if (!*Irp) {
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_CONNECT, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
if (!*Irp) {
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
TdiBuildConnect(*Irp, /* IRP */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion routine context */
|
||||
NULL, /* Time */
|
||||
ConnectionCallInfo, /* Request connection information */
|
||||
ConnectionReturnInfo); /* Return connection information */
|
||||
TdiBuildConnect(*Irp, /* IRP */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion routine context */
|
||||
NULL, /* Time */
|
||||
ConnectionCallInfo, /* Request connection information */
|
||||
ConnectionReturnInfo); /* Return connection information */
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
|
||||
return STATUS_PENDING;
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS TdiAssociateAddressFile(
|
||||
HANDLE AddressHandle,
|
||||
PFILE_OBJECT ConnectionObject)
|
||||
HANDLE AddressHandle,
|
||||
PFILE_OBJECT ConnectionObject)
|
||||
/*
|
||||
* FUNCTION: Associates a connection endpoint to an address file object
|
||||
* ARGUMENTS:
|
||||
|
@ -378,47 +377,47 @@ NTSTATUS TdiAssociateAddressFile(
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
KEVENT Event;
|
||||
PIRP Irp;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
KEVENT Event;
|
||||
PIRP Irp;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. AddressHandle (0x%X) ConnectionObject (0x%X)\n",
|
||||
AddressHandle, ConnectionObject));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. AddressHandle (0x%X) ConnectionObject (0x%X)\n",
|
||||
AddressHandle, ConnectionObject));
|
||||
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
Irp = TdiBuildInternalDeviceControlIrp(TDI_ASSOCIATE_ADDRESS, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
Irp = TdiBuildInternalDeviceControlIrp(TDI_ASSOCIATE_ADDRESS, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
TdiBuildAssociateAddress(Irp,
|
||||
DeviceObject,
|
||||
ConnectionObject,
|
||||
NULL,
|
||||
NULL,
|
||||
AddressHandle);
|
||||
TdiBuildAssociateAddress(Irp,
|
||||
DeviceObject,
|
||||
ConnectionObject,
|
||||
NULL,
|
||||
NULL,
|
||||
AddressHandle);
|
||||
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
}
|
||||
|
||||
NTSTATUS TdiDisassociateAddressFile(
|
||||
PFILE_OBJECT ConnectionObject)
|
||||
PFILE_OBJECT ConnectionObject)
|
||||
/*
|
||||
* FUNCTION: Disassociates a connection endpoint from an address file object
|
||||
* ARGUMENTS:
|
||||
|
@ -427,51 +426,51 @@ NTSTATUS TdiDisassociateAddressFile(
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
KEVENT Event;
|
||||
PIRP Irp;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
KEVENT Event;
|
||||
PIRP Irp;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. ConnectionObject (0x%X)\n", ConnectionObject));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called. ConnectionObject (0x%X)\n", ConnectionObject));
|
||||
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
Irp = TdiBuildInternalDeviceControlIrp(TDI_DISASSOCIATE_ADDRESS, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
Irp = TdiBuildInternalDeviceControlIrp(TDI_DISASSOCIATE_ADDRESS, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
TdiBuildDisassociateAddress(Irp,
|
||||
DeviceObject,
|
||||
ConnectionObject,
|
||||
NULL,
|
||||
NULL);
|
||||
TdiBuildDisassociateAddress(Irp,
|
||||
DeviceObject,
|
||||
ConnectionObject,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
}
|
||||
|
||||
NTSTATUS TdiListen
|
||||
( PIRP *Irp,
|
||||
PFILE_OBJECT ConnectionObject,
|
||||
PTDI_CONNECTION_INFORMATION *RequestConnectionInfo,
|
||||
PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo,
|
||||
PIO_STATUS_BLOCK Iosb,
|
||||
PIO_COMPLETION_ROUTINE CompletionRoutine,
|
||||
PVOID CompletionContext)
|
||||
NTSTATUS TdiListen(
|
||||
PIRP *Irp,
|
||||
PFILE_OBJECT ConnectionObject,
|
||||
PTDI_CONNECTION_INFORMATION *RequestConnectionInfo,
|
||||
PTDI_CONNECTION_INFORMATION *ReturnConnectionInfo,
|
||||
PIO_STATUS_BLOCK Iosb,
|
||||
PIO_COMPLETION_ROUTINE CompletionRoutine,
|
||||
PVOID CompletionContext)
|
||||
/*
|
||||
* FUNCTION: Listen on a connection endpoint for a connection request from a remote peer
|
||||
* ARGUMENTS:
|
||||
|
@ -482,41 +481,41 @@ NTSTATUS TdiListen
|
|||
* May return STATUS_PENDING
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||
|
||||
ASSERT(*Irp == NULL);
|
||||
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
if (!ConnectionObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad connection object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
|
||||
if (!DeviceObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_LISTEN, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
if (*Irp == NULL)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_LISTEN, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
if (*Irp == NULL)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
TdiBuildListen(*Irp, /* IRP */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion routine context */
|
||||
0, /* Flags */
|
||||
*RequestConnectionInfo, /* Request connection information */
|
||||
*ReturnConnectionInfo); /* Return connection information */
|
||||
TdiBuildListen(*Irp, /* IRP */
|
||||
DeviceObject, /* Device object */
|
||||
ConnectionObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion routine context */
|
||||
0, /* Flags */
|
||||
*RequestConnectionInfo, /* Request connection information */
|
||||
*ReturnConnectionInfo); /* Return connection information */
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL /* Don't wait for completion */, Iosb);
|
||||
TdiCall(*Irp, DeviceObject, NULL /* Don't wait for completion */, Iosb);
|
||||
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
|
@ -540,46 +539,46 @@ NTSTATUS TdiSetEventHandler(
|
|||
* Specify NULL for Handler to stop calling event handler
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
KEVENT Event;
|
||||
PIRP Irp;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
KEVENT Event;
|
||||
PIRP Irp;
|
||||
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||
AFD_DbgPrint(MAX_TRACE, ("Called\n"));
|
||||
|
||||
if (!FileObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
if (!FileObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
||||
if (!DeviceObject) {
|
||||
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
||||
if (!DeviceObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
Irp = TdiBuildInternalDeviceControlIrp(TDI_SET_EVENT_HANDLER, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
FileObject, /* File object */
|
||||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
Irp = TdiBuildInternalDeviceControlIrp(TDI_SET_EVENT_HANDLER, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
FileObject, /* File object */
|
||||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
|
||||
|
||||
TdiBuildSetEventHandler(Irp,
|
||||
DeviceObject,
|
||||
FileObject,
|
||||
NULL,
|
||||
NULL,
|
||||
EventType,
|
||||
Handler,
|
||||
Context);
|
||||
TdiBuildSetEventHandler(Irp,
|
||||
DeviceObject,
|
||||
FileObject,
|
||||
NULL,
|
||||
NULL,
|
||||
EventType,
|
||||
Handler,
|
||||
Context);
|
||||
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
}
|
||||
|
||||
|
||||
|
@ -611,8 +610,8 @@ NTSTATUS TdiQueryDeviceControl(
|
|||
PIRP Irp;
|
||||
|
||||
if (!FileObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
||||
|
@ -664,8 +663,8 @@ NTSTATUS TdiQueryInformation(
|
|||
PIRP Irp;
|
||||
|
||||
if (!FileObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad file object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(FileObject);
|
||||
|
@ -682,17 +681,16 @@ NTSTATUS TdiQueryInformation(
|
|||
&Event, /* Event */
|
||||
&Iosb); /* Status */
|
||||
if (!Irp) {
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
TdiBuildQueryInformation(
|
||||
Irp,
|
||||
DeviceObject,
|
||||
FileObject,
|
||||
NULL,
|
||||
NULL,
|
||||
QueryType,
|
||||
MdlBuffer);
|
||||
TdiBuildQueryInformation(Irp,
|
||||
DeviceObject,
|
||||
FileObject,
|
||||
NULL,
|
||||
NULL,
|
||||
QueryType,
|
||||
MdlBuffer);
|
||||
|
||||
return TdiCall(Irp, DeviceObject, &Event, &Iosb);
|
||||
}
|
||||
|
@ -850,8 +848,8 @@ NTSTATUS TdiQueryAddress(
|
|||
|
||||
if (SnmpInfo.NumAddr != 1) {
|
||||
/* Skip loopback address */
|
||||
PIPADDR_ENTRY IpAddressEntry = (PIPADDR_ENTRY)
|
||||
((PCHAR)IpAddress) + sizeof(IPADDR_ENTRY);
|
||||
PIPADDR_ENTRY IpAddressEntry = (PIPADDR_ENTRY)
|
||||
((PCHAR)IpAddress) + sizeof(IPADDR_ENTRY);
|
||||
*Address = DN2H(IpAddressEntry->Addr);
|
||||
} else {
|
||||
/* Select the first address returned */
|
||||
|
@ -873,24 +871,24 @@ NTSTATUS TdiQueryAddress(
|
|||
return Status;
|
||||
}
|
||||
|
||||
NTSTATUS TdiSend
|
||||
( PIRP *Irp,
|
||||
PFILE_OBJECT TransportObject,
|
||||
USHORT Flags,
|
||||
PCHAR Buffer,
|
||||
UINT BufferLength,
|
||||
PIO_STATUS_BLOCK Iosb,
|
||||
PIO_COMPLETION_ROUTINE CompletionRoutine,
|
||||
PVOID CompletionContext )
|
||||
NTSTATUS TdiSend(
|
||||
PIRP *Irp,
|
||||
PFILE_OBJECT TransportObject,
|
||||
USHORT Flags,
|
||||
PCHAR Buffer,
|
||||
UINT BufferLength,
|
||||
PIO_STATUS_BLOCK Iosb,
|
||||
PIO_COMPLETION_ROUTINE CompletionRoutine,
|
||||
PVOID CompletionContext)
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PMDL Mdl;
|
||||
|
||||
|
||||
ASSERT(*Irp == NULL);
|
||||
|
||||
if (!TransportObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(TransportObject);
|
||||
|
@ -899,12 +897,11 @@ NTSTATUS TdiSend
|
|||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp
|
||||
( TDI_SEND, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb ); /* Status */
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_SEND, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
|
||||
if (!*Irp) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
|
||||
|
@ -929,7 +926,7 @@ NTSTATUS TdiSend
|
|||
MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoModifyAccess);
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||
IoFreeMdl(Mdl);
|
||||
IoFreeMdl(Mdl);
|
||||
IoCompleteRequest(*Irp, IO_NO_INCREMENT);
|
||||
*Irp = NULL;
|
||||
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
||||
|
@ -938,13 +935,13 @@ NTSTATUS TdiSend
|
|||
AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %x\n", Mdl));
|
||||
|
||||
TdiBuildSend(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
Flags, /* Flags */
|
||||
BufferLength); /* Length of data */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
Flags, /* Flags */
|
||||
BufferLength); /* Length of data */
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
/* Does not block... The MDL is deleted in the receive completion
|
||||
|
@ -965,12 +962,12 @@ NTSTATUS TdiReceive(
|
|||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PMDL Mdl;
|
||||
|
||||
|
||||
ASSERT(*Irp == NULL);
|
||||
|
||||
if (!TransportObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(TransportObject);
|
||||
|
@ -979,12 +976,11 @@ NTSTATUS TdiReceive(
|
|||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp
|
||||
( TDI_RECEIVE, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb ); /* Status */
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
|
||||
if (!*Irp) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
|
||||
|
@ -1011,22 +1007,22 @@ NTSTATUS TdiReceive(
|
|||
AFD_DbgPrint(MID_TRACE, ("probe and lock done\n"));
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||
IoFreeMdl(Mdl);
|
||||
IoFreeMdl(Mdl);
|
||||
IoCompleteRequest(*Irp, IO_NO_INCREMENT);
|
||||
*Irp = NULL;
|
||||
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
||||
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
||||
} _SEH2_END;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %x\n", Mdl));
|
||||
|
||||
TdiBuildReceive(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
Flags, /* Flags */
|
||||
BufferLength); /* Length of data */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
Flags, /* Flags */
|
||||
BufferLength); /* Length of data */
|
||||
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
|
@ -1061,12 +1057,12 @@ NTSTATUS TdiReceiveDatagram(
|
|||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PMDL Mdl;
|
||||
|
||||
|
||||
ASSERT(*Irp == NULL);
|
||||
|
||||
if (!TransportObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad tranport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad tranport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
DeviceObject = IoGetRelatedDeviceObject(TransportObject);
|
||||
|
@ -1075,12 +1071,11 @@ NTSTATUS TdiReceiveDatagram(
|
|||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp
|
||||
( TDI_RECEIVE_DATAGRAM, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb ); /* Status */
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_RECEIVE_DATAGRAM, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
|
||||
if (!*Irp) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
|
||||
|
@ -1105,7 +1100,7 @@ NTSTATUS TdiReceiveDatagram(
|
|||
MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoModifyAccess);
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||
IoFreeMdl(Mdl);
|
||||
IoFreeMdl(Mdl);
|
||||
IoCompleteRequest(*Irp, IO_NO_INCREMENT);
|
||||
*Irp = NULL;
|
||||
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
||||
|
@ -1113,17 +1108,16 @@ NTSTATUS TdiReceiveDatagram(
|
|||
|
||||
AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %x\n", Mdl));
|
||||
|
||||
TdiBuildReceiveDatagram
|
||||
(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
BufferLength,
|
||||
Addr,
|
||||
Addr,
|
||||
Flags); /* Length of data */
|
||||
TdiBuildReceiveDatagram(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
BufferLength,
|
||||
Addr,
|
||||
Addr,
|
||||
Flags); /* Length of data */
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
/* Does not block... The MDL is deleted in the receive completion
|
||||
|
@ -1156,12 +1150,12 @@ NTSTATUS TdiSendDatagram(
|
|||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PMDL Mdl;
|
||||
|
||||
|
||||
ASSERT(*Irp == NULL);
|
||||
|
||||
if (!TransportObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called(TransportObject %x)\n", TransportObject));
|
||||
|
@ -1172,12 +1166,11 @@ NTSTATUS TdiSendDatagram(
|
|||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp
|
||||
( TDI_SEND_DATAGRAM, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb ); /* Status */
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_SEND_DATAGRAM, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
|
||||
if (!*Irp) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
|
||||
|
@ -1203,7 +1196,7 @@ NTSTATUS TdiSendDatagram(
|
|||
MmProbeAndLockPages(Mdl, (*Irp)->RequestorMode, IoModifyAccess);
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
|
||||
IoFreeMdl(Mdl);
|
||||
IoFreeMdl(Mdl);
|
||||
IoCompleteRequest(*Irp, IO_NO_INCREMENT);
|
||||
*Irp = NULL;
|
||||
_SEH2_YIELD(return STATUS_INSUFFICIENT_RESOURCES);
|
||||
|
@ -1211,15 +1204,14 @@ NTSTATUS TdiSendDatagram(
|
|||
|
||||
AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %x\n", Mdl));
|
||||
|
||||
TdiBuildSendDatagram
|
||||
(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
BufferLength, /* Bytes to send */
|
||||
Addr); /* Address */
|
||||
TdiBuildSendDatagram(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Mdl, /* Data buffer */
|
||||
BufferLength, /* Bytes to send */
|
||||
Addr); /* Address */
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
/* Does not block... The MDL is deleted in the send completion
|
||||
|
@ -1241,8 +1233,8 @@ NTSTATUS TdiDisconnect(
|
|||
PDEVICE_OBJECT DeviceObject;
|
||||
|
||||
if (!TransportObject) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
AFD_DbgPrint(MIN_TRACE, ("Bad transport object.\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called(TransportObject %x)\n", TransportObject));
|
||||
|
@ -1253,31 +1245,29 @@ NTSTATUS TdiDisconnect(
|
|||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
*Irp = TdiBuildInternalDeviceControlIrp
|
||||
( TDI_DISCONNECT, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb ); /* Status */
|
||||
*Irp = TdiBuildInternalDeviceControlIrp(TDI_DISCONNECT, /* Sub function */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
NULL, /* Event */
|
||||
Iosb); /* Status */
|
||||
|
||||
if (!*Irp) {
|
||||
AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
TdiBuildDisconnect
|
||||
(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Time, /* Time */
|
||||
Flags, /* Disconnect flags */
|
||||
RequestConnectionInfo, /* Indication of who to disconnect */
|
||||
ReturnConnectionInfo); /* Indication of who disconnected */
|
||||
TdiBuildDisconnect(*Irp, /* I/O Request Packet */
|
||||
DeviceObject, /* Device object */
|
||||
TransportObject, /* File object */
|
||||
CompletionRoutine, /* Completion routine */
|
||||
CompletionContext, /* Completion context */
|
||||
Time, /* Time */
|
||||
Flags, /* Disconnect flags */
|
||||
RequestConnectionInfo, /* Indication of who to disconnect */
|
||||
ReturnConnectionInfo); /* Indication of who disconnected */
|
||||
|
||||
TdiCall(*Irp, DeviceObject, NULL, Iosb);
|
||||
|
||||
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,19 +12,19 @@
|
|||
UINT TdiAddressSizeFromType( UINT AddressType ) {
|
||||
switch( AddressType ) {
|
||||
case TDI_ADDRESS_TYPE_IP:
|
||||
return TDI_ADDRESS_LENGTH_IP;
|
||||
return TDI_ADDRESS_LENGTH_IP;
|
||||
case TDI_ADDRESS_TYPE_APPLETALK:
|
||||
return TDI_ADDRESS_LENGTH_APPLETALK;
|
||||
return TDI_ADDRESS_LENGTH_APPLETALK;
|
||||
case TDI_ADDRESS_TYPE_NETBIOS:
|
||||
return TDI_ADDRESS_LENGTH_NETBIOS;
|
||||
return TDI_ADDRESS_LENGTH_NETBIOS;
|
||||
/* case TDI_ADDRESS_TYPE_NS: */
|
||||
case TDI_ADDRESS_TYPE_IPX:
|
||||
return TDI_ADDRESS_LENGTH_IPX;
|
||||
return TDI_ADDRESS_LENGTH_IPX;
|
||||
case TDI_ADDRESS_TYPE_VNS:
|
||||
return TDI_ADDRESS_LENGTH_VNS;
|
||||
return TDI_ADDRESS_LENGTH_VNS;
|
||||
default:
|
||||
DbgPrint("TdiAddressSizeFromType - invalid type: %x\n", AddressType);
|
||||
return 0;
|
||||
DbgPrint("TdiAddressSizeFromType - invalid type: %x\n", AddressType);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ UINT TaLengthOfTransportAddressByType(UINT AddressType)
|
|||
}
|
||||
|
||||
VOID TaCopyAddressInPlace( PTA_ADDRESS Target,
|
||||
PTA_ADDRESS Source ) {
|
||||
PTA_ADDRESS Source ) {
|
||||
UINT AddrLen = TaLengthOfAddress( Source );
|
||||
RtlCopyMemory( Target, Source, AddrLen );
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ PTA_ADDRESS TaCopyAddress( PTA_ADDRESS Source ) {
|
|||
PVOID Buffer;
|
||||
if (!AddrLen)
|
||||
return NULL;
|
||||
|
||||
|
||||
Buffer = ExAllocatePool( NonPagedPool, AddrLen );
|
||||
|
||||
if (Buffer)
|
||||
|
@ -91,7 +91,7 @@ PTA_ADDRESS TaCopyAddress( PTA_ADDRESS Source ) {
|
|||
}
|
||||
|
||||
VOID TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target,
|
||||
PTRANSPORT_ADDRESS Source ) {
|
||||
PTRANSPORT_ADDRESS Source ) {
|
||||
UINT AddrLen = TaLengthOfTransportAddress( Source );
|
||||
RtlCopyMemory( Target, Source, AddrLen );
|
||||
}
|
||||
|
@ -103,13 +103,13 @@ PTRANSPORT_ADDRESS TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress ) {
|
|||
AddrLen = TaLengthOfTransportAddress( OtherAddress );
|
||||
if (!AddrLen)
|
||||
return NULL;
|
||||
|
||||
|
||||
A = ExAllocatePool( NonPagedPool, AddrLen );
|
||||
|
||||
if( A )
|
||||
TaCopyTransportAddressInPlace( A, OtherAddress );
|
||||
TaCopyTransportAddressInPlace( A, OtherAddress );
|
||||
|
||||
return A;
|
||||
return A;
|
||||
}
|
||||
|
||||
NTSTATUS TdiBuildNullTransportAddressInPlace(PTRANSPORT_ADDRESS A, UINT AddressType)
|
||||
|
@ -135,7 +135,7 @@ PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType)
|
|||
AddrLen = TaLengthOfTransportAddressByType(AddressType);
|
||||
if (!AddrLen)
|
||||
return NULL;
|
||||
|
||||
|
||||
A = ExAllocatePool(NonPagedPool, AddrLen);
|
||||
|
||||
if (A)
|
||||
|
@ -162,26 +162,26 @@ NTSTATUS TdiBuildNullConnectionInfoInPlace
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
ULONG TdiAddressSize;
|
||||
PTRANSPORT_ADDRESS TransportAddress;
|
||||
ULONG TdiAddressSize;
|
||||
PTRANSPORT_ADDRESS TransportAddress;
|
||||
|
||||
TdiAddressSize = TaLengthOfTransportAddressByType(Type);
|
||||
if (!TdiAddressSize)
|
||||
TdiAddressSize = TaLengthOfTransportAddressByType(Type);
|
||||
if (!TdiAddressSize)
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
RtlZeroMemory(ConnInfo,
|
||||
sizeof(TDI_CONNECTION_INFORMATION) +
|
||||
TdiAddressSize);
|
||||
RtlZeroMemory(ConnInfo,
|
||||
sizeof(TDI_CONNECTION_INFORMATION) +
|
||||
TdiAddressSize);
|
||||
|
||||
ConnInfo->OptionsLength = sizeof(ULONG);
|
||||
ConnInfo->RemoteAddressLength = TdiAddressSize;
|
||||
ConnInfo->RemoteAddress = TransportAddress =
|
||||
(PTRANSPORT_ADDRESS)&ConnInfo[1];
|
||||
ConnInfo->OptionsLength = sizeof(ULONG);
|
||||
ConnInfo->RemoteAddressLength = TdiAddressSize;
|
||||
ConnInfo->RemoteAddress = TransportAddress =
|
||||
(PTRANSPORT_ADDRESS)&ConnInfo[1];
|
||||
|
||||
return TdiBuildNullTransportAddressInPlace(TransportAddress, Type);
|
||||
return TdiBuildNullTransportAddressInPlace(TransportAddress, Type);
|
||||
}
|
||||
|
||||
NTSTATUS TdiBuildNullConnectionInfo
|
||||
|
@ -197,37 +197,37 @@ NTSTATUS TdiBuildNullConnectionInfo
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo;
|
||||
ULONG TdiAddressSize;
|
||||
NTSTATUS Status;
|
||||
PTDI_CONNECTION_INFORMATION ConnInfo;
|
||||
ULONG TdiAddressSize;
|
||||
NTSTATUS Status;
|
||||
|
||||
TdiAddressSize = TaLengthOfTransportAddressByType(Type);
|
||||
if (!TdiAddressSize) {
|
||||
TdiAddressSize = TaLengthOfTransportAddressByType(Type);
|
||||
if (!TdiAddressSize) {
|
||||
AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
|
||||
*ConnectionInfo = NULL;
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
*ConnectionInfo = NULL;
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
ConnInfo = (PTDI_CONNECTION_INFORMATION)
|
||||
ExAllocatePool(NonPagedPool,
|
||||
sizeof(TDI_CONNECTION_INFORMATION) +
|
||||
TdiAddressSize);
|
||||
if (!ConnInfo) {
|
||||
*ConnectionInfo = NULL;
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
ConnInfo = (PTDI_CONNECTION_INFORMATION)
|
||||
ExAllocatePool(NonPagedPool,
|
||||
sizeof(TDI_CONNECTION_INFORMATION) +
|
||||
TdiAddressSize);
|
||||
if (!ConnInfo) {
|
||||
*ConnectionInfo = NULL;
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
Status = TdiBuildNullConnectionInfoInPlace( ConnInfo, Type );
|
||||
Status = TdiBuildNullConnectionInfoInPlace( ConnInfo, Type );
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
ExFreePool( ConnInfo );
|
||||
ConnInfo = NULL;
|
||||
}
|
||||
ExFreePool( ConnInfo );
|
||||
ConnInfo = NULL;
|
||||
}
|
||||
|
||||
*ConnectionInfo = ConnInfo;
|
||||
|
||||
return Status;
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
|
@ -238,11 +238,11 @@ TdiBuildConnectionInfoInPlace
|
|||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
|
||||
_SEH2_TRY {
|
||||
RtlCopyMemory( ConnectionInfo->RemoteAddress,
|
||||
Address,
|
||||
ConnectionInfo->RemoteAddressLength );
|
||||
RtlCopyMemory( ConnectionInfo->RemoteAddress,
|
||||
Address,
|
||||
ConnectionInfo->RemoteAddressLength );
|
||||
} _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
|
||||
Status = _SEH2_GetExceptionCode();
|
||||
Status = _SEH2_GetExceptionCode();
|
||||
} _SEH2_END;
|
||||
|
||||
return Status;
|
||||
|
@ -254,10 +254,10 @@ TdiBuildConnectionInfo
|
|||
( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
|
||||
PTRANSPORT_ADDRESS Address ) {
|
||||
NTSTATUS Status = TdiBuildNullConnectionInfo
|
||||
( ConnectionInfo, Address->Address[0].AddressType );
|
||||
( ConnectionInfo, Address->Address[0].AddressType );
|
||||
|
||||
if( NT_SUCCESS(Status) )
|
||||
TdiBuildConnectionInfoInPlace( *ConnectionInfo, Address );
|
||||
TdiBuildConnectionInfoInPlace( *ConnectionInfo, Address );
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,8 @@ static NTSTATUS NTAPI SendComplete
|
|||
*/
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called, status %x, %d bytes used\n",
|
||||
Irp->IoStatus.Status,
|
||||
Irp->IoStatus.Information));
|
||||
Irp->IoStatus.Status,
|
||||
Irp->IoStatus.Information));
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) )
|
||||
return STATUS_FILE_CLOSED;
|
||||
|
@ -45,109 +45,105 @@ static NTSTATUS NTAPI SendComplete
|
|||
if( FCB->State == SOCKET_STATE_CLOSED ) {
|
||||
/* Cleanup our IRP queue because the FCB is being destroyed */
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
|
||||
if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
|
||||
RetryDisconnectCompletion(FCB);
|
||||
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
}
|
||||
|
||||
if( !NT_SUCCESS(Status) ) {
|
||||
/* Complete all following send IRPs with error */
|
||||
/* Complete all following send IRPs with error */
|
||||
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
|
||||
NextIrpEntry =
|
||||
RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp =
|
||||
CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
|
||||
NextIrpEntry =
|
||||
RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp =
|
||||
CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
|
||||
UnlockBuffers( SendReq->BufferArray,
|
||||
SendReq->BufferCount,
|
||||
FALSE );
|
||||
UnlockBuffers( SendReq->BufferArray,
|
||||
SendReq->BufferCount,
|
||||
FALSE );
|
||||
|
||||
NextIrp->IoStatus.Status = Status;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
NextIrp->IoStatus.Status = Status;
|
||||
NextIrp->IoStatus.Information = 0;
|
||||
|
||||
if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
if ( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
|
||||
}
|
||||
|
||||
RetryDisconnectCompletion(FCB);
|
||||
|
||||
SocketStateUnlock( FCB );
|
||||
SocketStateUnlock( FCB );
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
RtlMoveMemory( FCB->Send.Window,
|
||||
FCB->Send.Window + FCB->Send.BytesUsed,
|
||||
FCB->Send.BytesUsed - Irp->IoStatus.Information );
|
||||
FCB->Send.Window + FCB->Send.BytesUsed,
|
||||
FCB->Send.BytesUsed - Irp->IoStatus.Information );
|
||||
|
||||
TotalBytesProcessed = 0;
|
||||
while (!IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]) &&
|
||||
TotalBytesProcessed != Irp->IoStatus.Information) {
|
||||
NextIrpEntry =
|
||||
RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp =
|
||||
CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
Map = (PAFD_MAPBUF)(SendReq->BufferArray + SendReq->BufferCount);
|
||||
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
Map = (PAFD_MAPBUF)(SendReq->BufferArray + SendReq->BufferCount);
|
||||
|
||||
TotalBytesCopied = 0;
|
||||
|
||||
for( i = 0; i < SendReq->BufferCount; i++ )
|
||||
TotalBytesCopied += SendReq->BufferArray[i].len;
|
||||
|
||||
|
||||
for( i = 0; i < SendReq->BufferCount; i++ )
|
||||
TotalBytesCopied += SendReq->BufferArray[i].len;
|
||||
|
||||
NextIrp->IoStatus.Status = Irp->IoStatus.Status;
|
||||
NextIrp->IoStatus.Information = TotalBytesCopied;
|
||||
|
||||
|
||||
TotalBytesProcessed += TotalBytesCopied;
|
||||
|
||||
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
|
||||
|
||||
UnlockBuffers( SendReq->BufferArray,
|
||||
SendReq->BufferCount,
|
||||
FALSE );
|
||||
|
||||
|
||||
if (NextIrp->MdlAddress) UnlockRequest(NextIrp, NextIrpSp);
|
||||
|
||||
|
||||
IoCompleteRequest(NextIrp, IO_NETWORK_INCREMENT);
|
||||
}
|
||||
|
||||
ASSERT(TotalBytesProcessed == Irp->IoStatus.Information);
|
||||
|
||||
|
||||
FCB->Send.BytesUsed -= TotalBytesProcessed;
|
||||
|
||||
while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
|
||||
NextIrpEntry =
|
||||
RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp =
|
||||
CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
Map = (PAFD_MAPBUF)(SendReq->BufferArray + SendReq->BufferCount);
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
NextIrpSp = IoGetCurrentIrpStackLocation( NextIrp );
|
||||
SendReq = GetLockedData(NextIrp, NextIrpSp);
|
||||
Map = (PAFD_MAPBUF)(SendReq->BufferArray + SendReq->BufferCount);
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("SendReq @ %x\n", SendReq));
|
||||
AFD_DbgPrint(MID_TRACE,("SendReq @ %x\n", SendReq));
|
||||
|
||||
SpaceAvail = FCB->Send.Size - FCB->Send.BytesUsed;
|
||||
SpaceAvail = FCB->Send.Size - FCB->Send.BytesUsed;
|
||||
TotalBytesCopied = 0;
|
||||
|
||||
for( i = 0; i < SendReq->BufferCount; i++ ) {
|
||||
for( i = 0; i < SendReq->BufferCount; i++ ) {
|
||||
if (SpaceAvail < SendReq->BufferArray[i].len)
|
||||
{
|
||||
InsertHeadList(&FCB->PendingIrpList[FUNCTION_SEND],
|
||||
|
@ -155,18 +151,18 @@ static NTSTATUS NTAPI SendComplete
|
|||
NextIrp = NULL;
|
||||
break;
|
||||
}
|
||||
Map[i].BufferAddress =
|
||||
MmMapLockedPages( Map[i].Mdl, KernelMode );
|
||||
Map[i].BufferAddress =
|
||||
MmMapLockedPages( Map[i].Mdl, KernelMode );
|
||||
|
||||
RtlCopyMemory( FCB->Send.Window + FCB->Send.BytesUsed,
|
||||
Map[i].BufferAddress,
|
||||
SendReq->BufferArray[i].len );
|
||||
RtlCopyMemory( FCB->Send.Window + FCB->Send.BytesUsed,
|
||||
Map[i].BufferAddress,
|
||||
SendReq->BufferArray[i].len );
|
||||
|
||||
MmUnmapLockedPages( Map[i].BufferAddress, Map[i].Mdl );
|
||||
MmUnmapLockedPages( Map[i].BufferAddress, Map[i].Mdl );
|
||||
|
||||
TotalBytesCopied += SendReq->BufferArray[i].len;
|
||||
SpaceAvail -= SendReq->BufferArray[i].len;
|
||||
}
|
||||
TotalBytesCopied += SendReq->BufferArray[i].len;
|
||||
SpaceAvail -= SendReq->BufferArray[i].len;
|
||||
}
|
||||
|
||||
if (NextIrp != NULL)
|
||||
{
|
||||
|
@ -175,13 +171,13 @@ static NTSTATUS NTAPI SendComplete
|
|||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (FCB->Send.Size - FCB->Send.BytesUsed != 0 &&
|
||||
!FCB->SendClosed)
|
||||
{
|
||||
FCB->PollState |= AFD_EVENT_SEND;
|
||||
FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
FCB->PollState |= AFD_EVENT_SEND;
|
||||
FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -191,14 +187,14 @@ static NTSTATUS NTAPI SendComplete
|
|||
/* Some data is still waiting */
|
||||
if( FCB->Send.BytesUsed )
|
||||
{
|
||||
Status = TdiSend( &FCB->SendIrp.InFlightRequest,
|
||||
FCB->Connection.Object,
|
||||
0,
|
||||
FCB->Send.Window,
|
||||
FCB->Send.BytesUsed,
|
||||
&FCB->SendIrp.Iosb,
|
||||
SendComplete,
|
||||
FCB );
|
||||
Status = TdiSend( &FCB->SendIrp.InFlightRequest,
|
||||
FCB->Connection.Object,
|
||||
0,
|
||||
FCB->Send.Window,
|
||||
FCB->Send.BytesUsed,
|
||||
&FCB->SendIrp.Iosb,
|
||||
SendComplete,
|
||||
FCB );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -221,8 +217,8 @@ static NTSTATUS NTAPI PacketSocketSendComplete
|
|||
PAFD_SEND_INFO SendReq;
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Called, status %x, %d bytes used\n",
|
||||
Irp->IoStatus.Status,
|
||||
Irp->IoStatus.Information));
|
||||
Irp->IoStatus.Status,
|
||||
Irp->IoStatus.Information));
|
||||
|
||||
if( !SocketAcquireStateLock( FCB ) )
|
||||
return STATUS_FILE_CLOSED;
|
||||
|
@ -247,24 +243,24 @@ static NTSTATUS NTAPI PacketSocketSendComplete
|
|||
SocketStateUnlock( FCB );
|
||||
return STATUS_FILE_CLOSED;
|
||||
}
|
||||
|
||||
|
||||
ASSERT(!IsListEmpty(&FCB->PendingIrpList[FUNCTION_SEND]));
|
||||
|
||||
|
||||
/* TDI spec guarantees FIFO ordering on IRPs */
|
||||
NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
|
||||
NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
|
||||
|
||||
|
||||
SendReq = GetLockedData(NextIrp, IoGetCurrentIrpStackLocation(NextIrp));
|
||||
|
||||
|
||||
NextIrp->IoStatus.Status = Irp->IoStatus.Status;
|
||||
NextIrp->IoStatus.Information = Irp->IoStatus.Information;
|
||||
|
||||
|
||||
(void)IoSetCancelRoutine(NextIrp, NULL);
|
||||
|
||||
|
||||
UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
|
||||
|
||||
|
||||
UnlockRequest(NextIrp, IoGetCurrentIrpStackLocation(NextIrp));
|
||||
|
||||
|
||||
IoCompleteRequest(NextIrp, IO_NETWORK_INCREMENT);
|
||||
|
||||
FCB->PollState |= AFD_EVENT_SEND;
|
||||
|
@ -278,7 +274,7 @@ static NTSTATUS NTAPI PacketSocketSendComplete
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp, BOOLEAN Short) {
|
||||
PIO_STACK_LOCATION IrpSp, BOOLEAN Short) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
PAFD_FCB FCB = FileObject->FsContext;
|
||||
|
@ -312,17 +308,17 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
NULL, NULL,
|
||||
FALSE, FALSE );
|
||||
|
||||
if( !SendReq->BufferArray ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_ACCESS_VIOLATION,
|
||||
if( !SendReq->BufferArray ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_ACCESS_VIOLATION,
|
||||
Irp, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
Status = TdiBuildConnectionInfo( &TargetAddress, FCB->RemoteAddress );
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
FCB->EventSelectDisabled &= ~AFD_EVENT_SEND;
|
||||
FCB->PollState &= ~AFD_EVENT_SEND;
|
||||
|
||||
|
||||
Status = QueueUserModeIrp(FCB, Irp, FUNCTION_SEND);
|
||||
if (Status == STATUS_PENDING)
|
||||
{
|
||||
|
@ -335,11 +331,11 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
PacketSocketSendComplete,
|
||||
FCB);
|
||||
}
|
||||
|
||||
|
||||
ExFreePool( TargetAddress );
|
||||
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
else
|
||||
|
@ -348,7 +344,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (FCB->PollState & AFD_EVENT_CLOSE)
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Connection reset by remote peer\n"));
|
||||
|
@ -356,15 +352,15 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
/* This is an unexpected remote disconnect */
|
||||
return UnlockAndMaybeComplete(FCB, FCB->PollStatus[FD_CLOSE_BIT], Irp, 0);
|
||||
}
|
||||
|
||||
|
||||
if (FCB->PollState & AFD_EVENT_ABORT)
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Connection aborted\n"));
|
||||
|
||||
|
||||
/* This is an abortive socket closure on our side */
|
||||
return UnlockAndMaybeComplete(FCB, FCB->PollStatus[FD_CLOSE_BIT], Irp, 0);
|
||||
}
|
||||
|
||||
|
||||
if (FCB->SendClosed)
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("No more sends\n"));
|
||||
|
@ -374,13 +370,13 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
if( !(SendReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_NO_MEMORY, Irp, TotalBytesCopied );
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_NO_MEMORY, Irp, TotalBytesCopied );
|
||||
|
||||
SendReq->BufferArray = LockBuffers( SendReq->BufferArray,
|
||||
SendReq->BufferCount,
|
||||
NULL, NULL,
|
||||
FALSE, FALSE );
|
||||
SendReq->BufferCount,
|
||||
NULL, NULL,
|
||||
FALSE, FALSE );
|
||||
|
||||
if( !SendReq->BufferArray ) {
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_ACCESS_VIOLATION,
|
||||
|
@ -390,57 +386,56 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
AFD_DbgPrint(MID_TRACE,("Socket state %d\n", FCB->State));
|
||||
|
||||
if( FCB->State != SOCKET_STATE_CONNECTED ) {
|
||||
if( (SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
|
||||
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_CANT_WAIT, Irp, 0 );
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Queuing request\n"));
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_SEND );
|
||||
}
|
||||
if( (SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
|
||||
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_CANT_WAIT, Irp, 0 );
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Queuing request\n"));
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_SEND );
|
||||
}
|
||||
}
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("FCB->Send.BytesUsed = %d\n",
|
||||
FCB->Send.BytesUsed));
|
||||
FCB->Send.BytesUsed));
|
||||
|
||||
SpaceAvail = FCB->Send.Size - FCB->Send.BytesUsed;
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("We can accept %d bytes\n",
|
||||
SpaceAvail));
|
||||
|
||||
|
||||
for( i = 0; FCB->Send.BytesUsed < FCB->Send.Size &&
|
||||
i < SendReq->BufferCount; i++ ) {
|
||||
|
||||
|
||||
if (SpaceAvail < SendReq->BufferArray[i].len)
|
||||
{
|
||||
if (TotalBytesCopied + SendReq->BufferArray[i].len > FCB->Send.Size)
|
||||
{
|
||||
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
|
||||
|
||||
UnlockBuffers(SendReq->BufferArray, SendReq->BufferCount, FALSE);
|
||||
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_BUFFER_OVERFLOW, Irp, 0);
|
||||
}
|
||||
SpaceAvail += TotalBytesCopied;
|
||||
NoSpace = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
AFD_DbgPrint(MID_TRACE,("Copying Buffer %d, %x:%d to %x\n",
|
||||
i,
|
||||
SendReq->BufferArray[i].buf,
|
||||
SendReq->BufferArray[i].len,
|
||||
FCB->Send.Window + FCB->Send.BytesUsed));
|
||||
|
||||
|
||||
RtlCopyMemory( FCB->Send.Window + FCB->Send.BytesUsed,
|
||||
SendReq->BufferArray[i].buf,
|
||||
SendReq->BufferArray[i].len );
|
||||
|
||||
|
||||
TotalBytesCopied += SendReq->BufferArray[i].len;
|
||||
SpaceAvail -= SendReq->BufferArray[i].len;
|
||||
}
|
||||
|
||||
|
||||
FCB->EventSelectDisabled &= ~AFD_EVENT_SEND;
|
||||
|
||||
|
||||
if( TotalBytesCopied == 0 ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Empty send\n"));
|
||||
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
|
||||
|
@ -451,8 +446,8 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if (SpaceAvail)
|
||||
{
|
||||
FCB->PollState |= AFD_EVENT_SEND;
|
||||
FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
|
||||
PollReeval( FCB->DeviceExt, FCB->FileObject );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -463,7 +458,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
{
|
||||
FCB->Send.BytesUsed += TotalBytesCopied;
|
||||
AFD_DbgPrint(MID_TRACE,("Copied %d bytes\n", TotalBytesCopied));
|
||||
|
||||
|
||||
Status = QueueUserModeIrp(FCB, Irp, FUNCTION_SEND);
|
||||
if (Status == STATUS_PENDING && !FCB->SendIrp.InFlightRequest)
|
||||
{
|
||||
|
@ -477,7 +472,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
FCB);
|
||||
}
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
else
|
||||
|
@ -486,8 +481,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
if( (SendReq->AfdFlags & AFD_IMMEDIATE) || (FCB->NonBlocking) ) {
|
||||
AFD_DbgPrint(MID_TRACE,("Nonblocking\n"));
|
||||
UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount, FALSE );
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_CANT_WAIT, Irp, 0 );
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_CANT_WAIT, Irp, 0 );
|
||||
} else {
|
||||
AFD_DbgPrint(MID_TRACE,("Queuing request\n"));
|
||||
return LeaveIrpUntilLater( FCB, Irp, FUNCTION_SEND );
|
||||
|
@ -497,7 +491,7 @@ AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
|
||||
NTSTATUS NTAPI
|
||||
AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
PIO_STACK_LOCATION IrpSp) {
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PTDI_CONNECTION_INFORMATION TargetAddress;
|
||||
PFILE_OBJECT FileObject = IrpSp->FileObject;
|
||||
|
@ -513,8 +507,7 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
FCB->State != SOCKET_STATE_CREATED)
|
||||
{
|
||||
AFD_DbgPrint(MIN_TRACE,("Invalid socket state\n"));
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_INVALID_PARAMETER, Irp, 0 );
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_INVALID_PARAMETER, Irp, 0);
|
||||
}
|
||||
|
||||
if (FCB->SendClosed)
|
||||
|
@ -524,19 +517,18 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
}
|
||||
|
||||
if( !(SendReq = LockRequest( Irp, IrpSp )) )
|
||||
return UnlockAndMaybeComplete
|
||||
( FCB, STATUS_NO_MEMORY, Irp, 0 );
|
||||
|
||||
return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
|
||||
|
||||
if (FCB->State == SOCKET_STATE_CREATED)
|
||||
{
|
||||
if( FCB->LocalAddress ) ExFreePool( FCB->LocalAddress );
|
||||
FCB->LocalAddress =
|
||||
TaBuildNullTransportAddress( ((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
|
||||
Address[0].AddressType );
|
||||
|
||||
|
||||
if( FCB->LocalAddress ) {
|
||||
Status = WarmSocketForBind( FCB );
|
||||
|
||||
|
||||
if( NT_SUCCESS(Status) )
|
||||
FCB->State = SOCKET_STATE_BOUND;
|
||||
else
|
||||
|
@ -552,24 +544,24 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
FALSE, FALSE );
|
||||
|
||||
if( !SendReq->BufferArray )
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_ACCESS_VIOLATION,
|
||||
return UnlockAndMaybeComplete( FCB, STATUS_ACCESS_VIOLATION,
|
||||
Irp, 0 );
|
||||
|
||||
AFD_DbgPrint
|
||||
(MID_TRACE,("RemoteAddress #%d Type %d\n",
|
||||
((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
|
||||
TAAddressCount,
|
||||
((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
|
||||
Address[0].AddressType));
|
||||
(MID_TRACE,("RemoteAddress #%d Type %d\n",
|
||||
((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
|
||||
TAAddressCount,
|
||||
((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress)->
|
||||
Address[0].AddressType));
|
||||
|
||||
Status = TdiBuildConnectionInfo( &TargetAddress,
|
||||
((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress) );
|
||||
((PTRANSPORT_ADDRESS)SendReq->TdiConnection.RemoteAddress) );
|
||||
|
||||
/* Check the size of the Address given ... */
|
||||
|
||||
if( NT_SUCCESS(Status) ) {
|
||||
FCB->EventSelectDisabled &= ~AFD_EVENT_SEND;
|
||||
FCB->PollState &= ~AFD_EVENT_SEND;
|
||||
FCB->PollState &= ~AFD_EVENT_SEND;
|
||||
|
||||
Status = QueueUserModeIrp(FCB, Irp, FUNCTION_SEND);
|
||||
if (Status == STATUS_PENDING)
|
||||
|
@ -584,10 +576,10 @@ AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp,
|
|||
FCB);
|
||||
}
|
||||
|
||||
ExFreePool( TargetAddress );
|
||||
|
||||
ExFreePool(TargetAddress);
|
||||
|
||||
SocketStateUnlock(FCB);
|
||||
|
||||
|
||||
return STATUS_PENDING;
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue