Commit in reactos/drivers/net/afd on arty_afd_20040709
afd/bind.c+63added 1.1.2.1
   /connect.c+177added 1.1.2.1
   /context.c+68added 1.1.2.1
   /info.c+51added 1.1.2.1
   /listen.c+58added 1.1.2.1
   /lock.c+166added 1.1.2.1
   /main.c+333added 1.1.2.1
   /read.c+192added 1.1.2.1
   /select.c+236added 1.1.2.1
   /write.c+222added 1.1.2.1
   /tdi.c+188-1801.13 -> 1.13.4.1
   /tdiconn.c+90-1851.1 -> 1.1.16.1
   /afd.c-2191.14 removed
   /dispatch.c-10461.15 removed
   /opnclose.c-2851.10 removed
   /rdwr.c-1181.5 removed
   /routines.c-3161.8 removed
include/afd.h+243added 1.18.10.1
       /tdiconn.h+14-111.1 -> 1.1.16.1
+2101-2360
11 added + 5 removed + 3 modified, total 19 files
New afd.  WIP but mostly working.  

The whole design is based on tdi requests and io completion.  We rely heavily
on the io manager.

Packet oriented sockets need to be reintroduced.  Some ioctls are not
implemented.  Some notifications from tdi are not in place yet.

The good news is that data will actually flow to and from userland using
it.

reactos/drivers/net/afd/afd
bind.c added at 1.1.2.1
diff -N bind.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bind.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,63 @@
+/* $Id: bind.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/bind.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS WarmSocketForBind( PAFD_FCB FCB ) {
+    NTSTATUS Status = STATUS_UNSUCCESSFUL;
+
+    AFD_DbgPrint(MID_TRACE,("Called\n"));
+
+    if( FCB->LocalAddress ) {
+	Status = TdiOpenAddressFile
+	    ( &FCB->TdiDeviceName,
+	      FCB->LocalAddress,
+	      &FCB->AddressFile.Handle, 
+	      &FCB->AddressFile.Object );
+    }
+
+    if( !NT_SUCCESS(Status) ) {
+	TdiCloseDevice( &FCB->AddressFile.Handle,
+			FCB->AddressFile.Object );
+	RtlZeroMemory( &FCB->AddressFile, sizeof( FCB->AddressFile ) );
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+
+    return Status;
+}
+
+NTSTATUS STDCALL
+AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+	      PIO_STACK_LOCATION IrpSp) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    PAFD_BIND_REQ BindReq = Irp->AssociatedIrp.SystemBuffer;
+    
+    AFD_DbgPrint(MID_TRACE,("Called\n"));
+    
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+    
+    FCB->LocalAddress = TaCopyTransportAddress( &BindReq->Address );
+
+    if( FCB->LocalAddress ) 
+	Status = WarmSocketForBind( FCB );
+    else Status = STATUS_NO_MEMORY;
+
+    if( NT_SUCCESS(Status) ) 
+	FCB->State = SOCKET_STATE_BOUND;
+
+    return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+}
+

reactos/drivers/net/afd/afd
connect.c added at 1.1.2.1
diff -N connect.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ connect.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,177 @@
+/* $Id: connect.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/connect.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS WarmSocketForConnection( PAFD_FCB FCB ) {
+    NTSTATUS Status = TdiOpenConnectionEndpointFile
+	( &FCB->TdiDeviceName,
+	  &FCB->Connection.Handle,
+	  &FCB->Connection.Object );
+    
+    if( NT_SUCCESS(Status) ) {
+	Status = TdiAssociateAddressFile
+	    ( FCB->AddressFile.Handle,
+	      FCB->Connection.Object );
+    }
+
+    if( !NT_SUCCESS(Status) ) {
+	TdiCloseDevice( &FCB->Connection.Handle,
+			FCB->Connection.Object );
+	RtlZeroMemory( &FCB->Connection, sizeof(FCB->Connection) );
+    }
+
+    return Status;
+}
+
+NTSTATUS DDKAPI StreamSocketConnectComplete
+( PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context ) {
+    NTSTATUS Status = Irp->IoStatus.Status;
+    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
+    PAFD_FCB FCB = (PAFD_FCB)Context;
+    PLIST_ENTRY NextIrpEntry;
+    PIRP NextIrp;
+
+    AFD_DbgPrint(MID_TRACE,("Called: FCB %x, FO %x\n", 
+			    Context, FCB->FileObject));
+
+    /* Check the result of the connect operation */
+    /* Since the previous does not return until we come through here, we do
+     * not need to relock. */
+    /* if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp ); */
+
+    if( NT_SUCCESS(Irp->IoStatus.Status) ) {
+	FCB->PollState |= AFD_EVENT_CONNECT;
+	FCB->State = SOCKET_STATE_CONNECTED;
+	PollReeval( FCB->DeviceExt, FCB->FileObject );
+    } else {
+	FCB->PollState |= AFD_EVENT_CONNECT_FAIL;
+	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 = 0;
+	IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
+    }
+
+    if( NT_SUCCESS(Status) ) {
+	/* Allocate the receive area and start receiving */
+	FCB->Recv.Window = 
+	    ExAllocatePool( NonPagedPool, FCB->Recv.Size );
+	FCB->Send.Window = 
+	    ExAllocatePool( NonPagedPool, FCB->Send.Size );
+
+	if( FCB->Recv.Window ) {
+	    Status = TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
+				 IrpSp->FileObject,
+				 TDI_RECEIVE_NORMAL,
+				 FCB->Recv.Window,
+				 FCB->Recv.Size,
+				 &FCB->ReceiveIrp.Iosb,
+				 ReceiveComplete,
+				 FCB );
+	}
+
+	if( Status == STATUS_PENDING )
+	    Status = STATUS_SUCCESS;
+    }
+
+    /* SocketStateUnlock( FCB ); */
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+    
+    return Status;
+}
+
+/* Return the socket object for ths request only if it is a connected or
+   stream type. */
+NTSTATUS STDCALL
+AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+		       PIO_STACK_LOCATION IrpSp) {
+    NTSTATUS Status = STATUS_INVALID_PARAMETER;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    PAFD_CONNECT_REQ ConnectReq = Irp->AssociatedIrp.SystemBuffer;
+    AFD_DbgPrint(MID_TRACE,("Called on %x\n", FCB));
+
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    AFD_DbgPrint(MID_TRACE,("Connect request:\n"));
+    OskitDumpBuffer
+	( (PCHAR)ConnectReq, 
+	  IrpSp->Parameters.DeviceIoControl.InputBufferLength );
+
+    switch( FCB->State ) {
+    case SOCKET_STATE_CONNECTED:
+	Status = STATUS_SUCCESS;
+	break;
+
+    case SOCKET_STATE_CONNECTING:
+	return LeaveIrpUntilLater( FCB, Irp, FUNCTION_CONNECT );
+
+    case SOCKET_STATE_CREATED: {
+	FCB->LocalAddress = TaCopyTransportAddress( &ConnectReq->Address );
+
+	if( FCB->LocalAddress ) {
+	    RtlZeroMemory( FCB->LocalAddress, 
+			   TaLengthOfTransportAddress
+			   ( &ConnectReq->Address ) );
+	    
+	    FCB->LocalAddress->TAAddressCount = 1;
+	    FCB->LocalAddress->Address[0].AddressType = 
+		ConnectReq->Address.Address[0].AddressType;
+	    FCB->LocalAddress->Address[0].AddressLength = 
+		ConnectReq->Address.Address[0].AddressLength;
+	    
+	    Status = WarmSocketForBind( FCB );
+	    
+	    if( NT_SUCCESS(Status) ) 
+		FCB->State = SOCKET_STATE_BOUND;
+	    else
+		return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+	} else
+	    return UnlockAndMaybeComplete
+		( FCB, STATUS_NO_MEMORY, Irp, 0, NULL ); 
+    } /* Drop through to SOCKET_STATE_BOUND */
+	
+    case SOCKET_STATE_BOUND:
+	FCB->RemoteAddress = TaCopyTransportAddress( &ConnectReq->Address );
+	
+	Status = WarmSocketForConnection( FCB );
+	
+	if( NT_SUCCESS(Status) ) {
+	    Status = TdiConnect( &FCB->PendingTdiIrp, 
+				 FCB->Connection.Object,
+				 FCB->RemoteAddress,
+				 StreamSocketConnectComplete,
+				 FCB );
+	}
+	
+	FCB->State = SOCKET_STATE_CONNECTING;
+	break;
+
+    default:
+	AFD_DbgPrint(MID_TRACE,("Inappropriate socket state %d for connect\n",
+				FCB->State));
+	break;
+    }
+    
+    return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+}

reactos/drivers/net/afd/afd
context.c added at 1.1.2.1
diff -N context.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ context.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,68 @@
+/* $Id: context.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/context.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS STDCALL
+AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	       PIO_STACK_LOCATION IrpSp ) {
+    NTSTATUS Status = STATUS_INVALID_PARAMETER;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    UINT ContextSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
+
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    if( FCB->ContextSize < ContextSize ) ContextSize = FCB->ContextSize;
+    
+    if( FCB->Context ) {
+	RtlCopyMemory( Irp->AssociatedIrp.SystemBuffer,
+		       FCB->Context,
+		       ContextSize );
+	Status = STATUS_SUCCESS;
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+
+    return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+}
+
+NTSTATUS STDCALL
+AfdSetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	       PIO_STACK_LOCATION IrpSp ) {
+    NTSTATUS Status = STATUS_NO_MEMORY;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    if( FCB->ContextSize < 
+	IrpSp->Parameters.DeviceIoControl.InputBufferLength ) {
+	if( FCB->Context )
+	    ExFreePool( FCB->Context );
+	FCB->Context = 
+	    ExAllocatePool
+	    ( PagedPool, 
+	      IrpSp->Parameters.DeviceIoControl.InputBufferLength );
+    }
+    
+    if( FCB->Context ) {
+	Status = STATUS_SUCCESS;
+	RtlCopyMemory( FCB->Context, 
+		       Irp->AssociatedIrp.SystemBuffer,
+		       IrpSp->Parameters.DeviceIoControl.InputBufferLength );
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+
+    return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+}

reactos/drivers/net/afd/afd
info.c added at 1.1.2.1
diff -N info.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ info.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,51 @@
+/* $Id: info.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/info.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS STDCALL
+AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	    PIO_STACK_LOCATION IrpSp ) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    PAFD_INFO InfoReq = Irp->AssociatedIrp.SystemBuffer;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+
+    AFD_DbgPrint(MID_TRACE,("Called %x %x\n", InfoReq, InfoReq ? InfoReq->InfoClass : 0));
+    
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    switch( InfoReq->InfoClass ) {
+    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_GROUP_ID_TYPE:
+	InfoReq->Information.Ulong = 0; /* What is group id */
+	break;
+
+    default:
+	AFD_DbgPrint(MID_TRACE,("Unknown info id %x\n", InfoReq->InfoClass));
+	Status = STATUS_INVALID_PARAMETER;
+	break;
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+
+    return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+}
+

reactos/drivers/net/afd/afd
listen.c added at 1.1.2.1
diff -N listen.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ listen.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,58 @@
+/* $Id: listen.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/listen.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS DDKAPI ListenComplete
+( PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context ) {
+    PAFD_FCB FCB = (PAFD_FCB)Context;
+    AFD_DbgPrint(MID_TRACE,("Completing listen request.\n"));
+    AFD_DbgPrint(MID_TRACE,("IoStatus was %x\n", FCB->ListenIrp.Iosb.Status));
+    AFD_DbgPrint(MID_TRACE,("Doing nothing as yet.\n"));
+    return STATUS_SUCCESS;
+}
+
+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;
+    PAFD_LISTEN_REQ ListenReq = Irp->AssociatedIrp.SystemBuffer;
+
+    AFD_DbgPrint(MID_TRACE,("Called\n"));
+
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    if( FCB->State != SOCKET_STATE_BOUND ) {
+	Status = STATUS_UNSUCCESSFUL;
+	AFD_DbgPrint(MID_TRACE,("Could not listen an unbound socket\n"));
+	return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+    }
+    
+    FCB->DelayedAccept = ListenReq->DelayedAccept;
+
+    Status = WarmSocketForConnection( FCB );
+
+    FCB->State = SOCKET_STATE_LISTENING;
+
+    Status = TdiListen( &FCB->ListenIrp.InFlightRequest,
+			FCB->Connection.Object, 
+			&FCB->ListenIrp.ConnectionInfo,
+			&FCB->ListenIrp.Iosb,
+			ListenComplete,
+			FCB );
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+    return UnlockAndMaybeComplete( FCB, Status, Irp, 0, NULL );
+}

reactos/drivers/net/afd/afd
lock.c added at 1.1.2.1
diff -N lock.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lock.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,166 @@
+/* $Id: lock.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/lock.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count, BOOLEAN Write ) {
+    UINT i;
+    /* Copy the buffer array so we don't lose it */
+    UINT Size = sizeof(AFD_WSABUF) * Count;
+    PAFD_WSABUF NewBuf = ExAllocatePool( PagedPool, Size * 2 );
+
+    if( NewBuf ) {
+	PAFD_MAPBUF MapBuf = (PAFD_MAPBUF)(NewBuf + Count);
+	RtlCopyMemory( NewBuf, Buf, Size );
+	
+	for( i = 0; i < Count; i++ ) {
+	    AFD_DbgPrint(MID_TRACE,("Locking buffer %d (%x:%d)\n",
+				    i, NewBuf[i].buf, NewBuf[i].len));
+
+	    MapBuf[i].Mdl = IoAllocateMdl( NewBuf[i].buf, 
+					   NewBuf[i].len,
+					   FALSE,
+					   FALSE,
+					   NULL );
+	    if( MapBuf[i].Mdl ) {
+		MmProbeAndLockPages( MapBuf[i].Mdl, KernelMode, 
+				     Write ? IoModifyAccess : IoReadAccess );
+	    }
+	}
+    }
+
+    return NewBuf;
+}
+
+VOID UnlockBuffers( PAFD_WSABUF Buf, UINT Count ) {
+    PAFD_MAPBUF Map = (PAFD_MAPBUF)(Buf + Count);
+    UINT i;
+
+    for( i = 0; i < Count; i++ ) {
+	if( Map[i].Mdl ) {
+	    MmUnlockPages( Map[i].Mdl );
+	    IoFreeMdl( Map[i].Mdl );
+	}
+    }
+
+    ExFreePool( Buf );
+}
+
+/* Returns transitioned state or SOCKET_STATE_INVALID_TRANSITION */
+UINT SocketAcquireStateLock( PAFD_FCB FCB ) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    PVOID CurrentThread = KeGetCurrentThread();
+
+    AFD_DbgPrint(MAX_TRACE,("Called on %x, attempting to lock\n", FCB));
+
+    /* Wait for the previous user to unlock the FCB state.  There might be
+     * multiple waiters waiting to change the state.  We need to check each
+     * time we get the event whether somebody still has the state locked */
+
+    if( !FCB ) return FALSE;
+
+    if( CurrentThread == FCB->CurrentThread ) {
+	FCB->LockCount++;
+	AFD_DbgPrint(MID_TRACE,
+		     ("Same thread, lock count %d\n", FCB->LockCount));
+	return TRUE;
+    } else {
+	AFD_DbgPrint(MID_TRACE,
+		     ("Thread %x opposes lock thread %x\n",
+		      CurrentThread, FCB->CurrentThread));
+    }
+
+    if( KeGetCurrentIrql() == PASSIVE_LEVEL ) {
+	ExAcquireFastMutex( &FCB->Mutex );
+	while( FCB->Locked ) {
+	    AFD_DbgPrint
+		(MID_TRACE,("FCB %x is locked, waiting for notification\n",
+			    FCB));
+	    ExReleaseFastMutex( &FCB->Mutex );
+	    Status = KeWaitForSingleObject( &FCB->StateLockedEvent,
+					    UserRequest,
+					    KernelMode,
+					    FALSE,
+					    NULL );
+	    ExAcquireFastMutex( &FCB->Mutex );
+	    if( Status == STATUS_SUCCESS ) break;
+	}
+	FCB->Locked = TRUE;
+	FCB->CurrentThread = CurrentThread;
+	FCB->LockCount++;
+	ExReleaseFastMutex( &FCB->Mutex );
+    } else {
+	KeAcquireSpinLock( &FCB->SpinLock, &FCB->OldIrql );
+	FCB->Locked = TRUE;
+	FCB->CurrentThread = CurrentThread;
+	FCB->LockCount++;
+    }
+    AFD_DbgPrint(MAX_TRACE,("Got lock (%d).\n", FCB->LockCount));
+
+    return TRUE;
+}
+
+VOID SocketStateUnlock( PAFD_FCB FCB ) {
+    FCB->LockCount--;
+
+    if( !FCB->LockCount ) {
+	FCB->CurrentThread = NULL;
+	if( KeGetCurrentIrql() == PASSIVE_LEVEL ) {
+	    ExAcquireFastMutex( &FCB->Mutex );
+	    FCB->Locked = FALSE;
+	    ExReleaseFastMutex( &FCB->Mutex );
+	} else {
+	    FCB->Locked = FALSE;
+	    KeReleaseSpinLock( &FCB->SpinLock, FCB->OldIrql );
+	}
+
+	AFD_DbgPrint(MAX_TRACE,("Unlocked.\n"));
+	KePulseEvent( &FCB->StateLockedEvent, IO_NETWORK_INCREMENT, FALSE );
+    } else {
+	AFD_DbgPrint(MID_TRACE,("Lock count %d\n", FCB->LockCount));
+    }
+}
+
+NTSTATUS DDKAPI UnlockAndMaybeComplete
+( PAFD_FCB FCB, NTSTATUS Status, PIRP Irp,
+  UINT Information, 
+  PIO_COMPLETION_ROUTINE Completion ) {
+    SocketStateUnlock( FCB );
+    if( Status == STATUS_PENDING ) {
+	IoMarkIrpPending( Irp );
+    } else {
+	Irp->IoStatus.Status = Status;
+	Irp->IoStatus.Information = Information;
+	if( Completion ) 
+	    Completion( FCB->DeviceExt->DeviceObject, Irp, FCB );
+	else IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
+    }
+    return Status;
+}
+
+
+NTSTATUS LostSocket( PIRP Irp ) {
+    NTSTATUS Status = STATUS_INVALID_PARAMETER;
+    AFD_DbgPrint(MIN_TRACE,("Called.\n"));
+    Irp->IoStatus.Information = 0;
+    Irp->IoStatus.Status = Status;
+    IoCompleteRequest( Irp, IO_NO_INCREMENT );
+    return Status;	
+}
+
+NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function ) {
+    InsertTailList( &FCB->PendingIrpList[Function], 
+		    &Irp->Tail.Overlay.ListEntry );
+    return UnlockAndMaybeComplete( FCB, STATUS_PENDING, Irp, 0,
+				   NULL );
+}
+

reactos/drivers/net/afd/afd
main.c added at 1.1.2.1
diff -N main.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ main.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,333 @@
+/* $Id: main.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/main.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040630 Created
+ *
+ * Suggestions: Uniform naming (AfdXxx)
+ */
+
+/* INCLUDES */
+
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+#ifdef DBG
+
+extern NTSTATUS DDKAPI MmCopyFromCaller( PVOID Dst, PVOID Src, UINT Size );
+
+/* See debug.h for debug/trace constants */
+DWORD DebugTraceLevel = DEBUG_ULTRA;
+
+#endif /* DBG */
+
+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 );
+    }
+    DbgPrint("\n");
+}
+
+/* FUNCTIONS */
+
+NTSTATUS STDCALL
+AfdCreateSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+		PIO_STACK_LOCATION IrpSp) {
+    PAFD_FCB FCB;
+    PFILE_OBJECT FileObject;
+    PAFD_DEVICE_EXTENSION DeviceExt;
+    PFILE_FULL_EA_INFORMATION EaInfo;
+    PAFD_SGID ConnectInfo;
+    ULONG EaLength;
+    PWCHAR EaInfoValue;
+    UINT Disposition, i;
+
+    AFD_DbgPrint(MID_TRACE,
+		 ("AfdCreate(DeviceObject %p Irp %p)\n", DeviceObject, Irp));
+
+    DeviceExt = DeviceObject->DeviceExtension;
+    FileObject = IrpSp->FileObject;
+    Disposition = (IrpSp->Parameters.Create.Options >> 24) & 0xff;
+    
+    Irp->IoStatus.Information = 0;
+    
+    EaInfo = Irp->AssociatedIrp.SystemBuffer;
+    ConnectInfo = (PAFD_SGID)(EaInfo->EaName + EaInfo->EaNameLength + 1);
+    EaInfoValue = (PWCHAR)(((PCHAR)ConnectInfo) + sizeof(AFD_SGID));
+
+    if(!EaInfo) {
+	AFD_DbgPrint(MIN_TRACE, ("No EA Info in IRP.\n"));
+	Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
+	IoCompleteRequest( Irp, IO_NO_INCREMENT );
+	return STATUS_INVALID_PARAMETER;
+    }
+
+    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,("About to allocate the new FCB\n"));
+
+    FCB = ExAllocatePool(NonPagedPool, sizeof(PAFD_FCB));
+    if( FCB == NULL ) {
+	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)\n", FCB, FileObject));
+
+    FCB->Locked = FALSE;
+    FCB->PollState = 0;
+    FCB->State = SOCKET_STATE_CREATED;
+    FCB->FileObject = FileObject;
+    FCB->DeviceExt = DeviceExt;
+    FCB->CurrentThread = NULL;
+    FCB->LockCount = 0;
+    FCB->DelayedAccept = FALSE;
+    FCB->LocalAddress = FCB->RemoteAddress = NULL;
+    FCB->Recv.Size = DEFAULT_RECEIVE_WINDOW_SIZE;
+    FCB->Recv.BytesUsed = 0;
+    FCB->Recv.Content = 0;
+    FCB->Recv.Window = NULL;
+    FCB->Send.Size = DEFAULT_SEND_WINDOW_SIZE;
+    FCB->Send.BytesUsed = 0;
+    FCB->Send.Content = 0;
+    FCB->Send.Window = NULL;
+    FCB->Context = 0;
+    FCB->ContextSize = 0;
+
+    RtlZeroMemory( &FCB->Connection, sizeof(FCB->Connection) );
+    RtlZeroMemory( &FCB->AddressFile, sizeof(FCB->AddressFile) );
+
+    KeInitializeSpinLock( &FCB->SpinLock );
+    ExInitializeFastMutex( &FCB->Mutex );
+    KeInitializeEvent( &FCB->StateLockedEvent, NotificationEvent, FALSE );
+
+    for( i = 0; i < MAX_FUNCTIONS; i++ ) {
+	InitializeListHead( &FCB->PendingIrpList[i] );
+    }
+
+    AFD_DbgPrint(MID_TRACE,("%x: Checking command channel\n", FCB));
+
+    FCB->TdiDeviceName.Length = ConnectInfo->TDNameLength;
+    FCB->TdiDeviceName.MaximumLength = FCB->TdiDeviceName.Length;
+    FCB->TdiDeviceName.Buffer = 
+      ExAllocatePool( NonPagedPool, FCB->TdiDeviceName.Length );
+    RtlCopyMemory( FCB->TdiDeviceName.Buffer,
+		   EaInfoValue,
+		   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;
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Success: %s %wZ\n", 
+			    EaInfo->EaName, &FCB->TdiDeviceName));
+    FileObject->FsContext = FCB;
+    Irp->IoStatus.Status = STATUS_SUCCESS;
+    IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS STDCALL
+AfdCloseSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+	       PIO_STACK_LOCATION IrpSp)
+{
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );    
+
+    AFD_DbgPrint(MID_TRACE,
+		 ("AfdClose(DeviceObject %p Irp %p)\n", DeviceObject, Irp));
+    
+    AFD_DbgPrint(MID_TRACE,("FCB %x\n", FCB));
+
+    FCB->PollState |= AFD_EVENT_CLOSE;
+    FCB->State = SOCKET_STATE_CLOSED;
+    PollReeval( FCB->DeviceExt, FCB->FileObject );
+
+    FileObject->FsContext = NULL;
+    
+    SocketStateUnlock( FCB );
+    
+    ExFreePool(FCB->TdiDeviceName.Buffer);
+    ExFreePool(FCB);
+    
+    Irp->IoStatus.Status = STATUS_SUCCESS;
+    Irp->IoStatus.Information = 0;
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    
+    AFD_DbgPrint(MID_TRACE, ("Returning success.\n"));
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS STDCALL
+AfdDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+{
+    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
+    NTSTATUS Status = STATUS_SUCCESS;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+
+    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);
+    }
+
+    switch(IrpSp->MajorFunction)
+    {
+	/* opening and closing handles to the device */
+    case IRP_MJ_CREATE:
+	/* 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);
+
+    /* write data */
+    case IRP_MJ_WRITE:
+	return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp, TRUE );
+    
+    /* read data */
+    case IRP_MJ_READ:
+	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 );
+
+	case IOCTL_AFD_CONNECT:
+	    return AfdStreamSocketConnect( DeviceObject, Irp, IrpSp );
+
+	case IOCTL_AFD_LISTEN:
+	    return AfdListenSocket( DeviceObject, Irp, IrpSp );
+
+	case IOCTL_AFD_RECV:
+	    return AfdConnectedSocketReadData( DeviceObject, Irp, IrpSp, 
+					       FALSE );
+
+	case IOCTL_AFD_SELECT:
+	    return AfdSelect( DeviceObject, Irp, IrpSp );
+
+	case IOCTL_AFD_RECVFROM:
+	    return AfdPacketSocketReadData( DeviceObject, Irp );
+
+	case IOCTL_AFD_SEND:
+	    return AfdConnectedSocketWriteData( DeviceObject, Irp, IrpSp, 
+						FALSE );
+
+	case IOCTL_AFD_SENDTO:
+	    return AfdPacketSocketWriteData( DeviceObject, Irp );
+
+	case IOCTL_AFD_GET_INFO:
+	    return AfdGetInfo( DeviceObject, Irp, IrpSp );
+
+	case IOCTL_AFD_GET_CONTEXT:
+	    return AfdGetContext( DeviceObject, Irp, IrpSp );
+
+	case IOCTL_AFD_SET_CONTEXT:
+	    return AfdSetContext( DeviceObject, Irp, IrpSp );
+
+	default:
+	    Status = STATUS_NOT_IMPLEMENTED;
+	    Irp->IoStatus.Information = 0;
+	    AFD_DbgPrint(MIN_TRACE, ("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;
+    }
+    }
+    
+    AFD_DbgPrint(MID_TRACE, ("Returning %x\n", Status));
+    Irp->IoStatus.Status = Status;
+    IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    
+    return (Status);
+}
+
+VOID STDCALL
+AfdUnload(PDRIVER_OBJECT DriverObject)
+{
+}
+
+NTSTATUS STDCALL 
+DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
+{
+    PDEVICE_OBJECT DeviceObject;
+    UNICODE_STRING wstrDeviceName;
+    PAFD_DEVICE_EXTENSION DeviceExt;
+    NTSTATUS Status;
+
+    /* register driver routines */
+    DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdDispatch;
+    DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdDispatch;
+    DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdDispatch;
+    DriverObject->MajorFunction[IRP_MJ_READ] = AfdDispatch;
+    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;
+    DriverObject->DriverUnload = AfdUnload;
+
+    /* create afd device */
+    RtlRosInitUnicodeStringFromLiteral(&wstrDeviceName, L"\\Device\\Afd");
+
+    Status = IoCreateDevice
+	( DriverObject,
+	  sizeof(AFD_DEVICE_EXTENSION),
+	  &wstrDeviceName,
+	  FILE_DEVICE_NAMED_PIPE,
+	  0,
+	  FALSE,
+	  &DeviceObject );
+
+    /* failure */
+    if(!NT_SUCCESS(Status))
+    {
+	return (Status);
+    }
+
+    DeviceExt = DeviceObject->DeviceExtension;
+    KeInitializeSpinLock( &DeviceExt->Lock );
+    InitializeListHead( &DeviceExt->Polls );
+
+    AFD_DbgPrint(MID_TRACE,("Device created: object %x ext %x\n",
+			    DeviceObject, DeviceExt));
+
+    return (Status);
+}
+
+/* EOF */

reactos/drivers/net/afd/afd
read.c added at 1.1.2.1
diff -N read.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ read.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,192 @@
+/* $Id: read.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/read.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS TryToSatisfyRecvRequestFromBuffer( PAFD_FCB FCB,
+					    PAFD_RECV_REQ RecvReq,
+					    PUINT TotalBytesCopied ) {
+    UINT i, BytesToCopy = 0,
+	BytesAvailable = 
+	FCB->Recv.Content - FCB->Recv.BytesUsed;
+    *TotalBytesCopied = 0;
+    PAFD_MAPBUF Map;
+
+    if( !BytesAvailable ) return STATUS_PENDING;
+
+    Map = (PAFD_MAPBUF)(RecvReq->BufferArray + RecvReq->BufferCount);
+
+    AFD_DbgPrint(MID_TRACE,("Buffer Count: %d @ %x\n", 
+			    RecvReq->BufferCount,
+			    RecvReq->BufferArray));
+    for( i = 0; 
+	 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 );
+	    
+	    AFD_DbgPrint(MID_TRACE,("Buffer %d: %x:%d\n", 
+				    i, 
+				    Map[i].BufferAddress,
+				    BytesToCopy));
+	    RtlCopyMemory( Map[i].BufferAddress,
+			   FCB->Recv.Window + FCB->Recv.BytesUsed,
+			   BytesToCopy );
+	    
+	    MmUnmapLockedPages( Map[i].BufferAddress, Map[i].Mdl );
+	    
+	    FCB->Recv.BytesUsed += BytesToCopy;
+	    *TotalBytesCopied += BytesToCopy;
+	    BytesAvailable -= BytesToCopy;
+	}
+    }
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS DDKAPI ReceiveComplete
+( PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context ) {
+    NTSTATUS Status = Irp->IoStatus.Status;
+    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
+    PAFD_FCB FCB = (PAFD_FCB)Context;
+    PLIST_ENTRY NextIrpEntry;
+    PIRP NextIrp;
+    PAFD_RECV_REQ RecvReq;
+    UINT TotalBytesCopied = 0;
+
+    AFD_DbgPrint(MID_TRACE,("Called\n"));
+    
+    if( !SocketAcquireStateLock( FCB ) ) return Status;
+    
+    if( NT_SUCCESS(Irp->IoStatus.Status) ) {
+	/* Update the receive window */
+	FCB->Recv.Content = Irp->IoStatus.Information;
+	FCB->Recv.BytesUsed = 0;
+	/* 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 );
+
+	Status = STATUS_SUCCESS;
+
+	/* Try to clear some requests */
+	while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) &&
+	       NT_SUCCESS(Status) ) {
+	    NextIrpEntry = 
+		RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
+	    NextIrp = 
+		CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
+	    RecvReq = NextIrp->AssociatedIrp.SystemBuffer;
+
+	    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\n", NextIrp));
+		UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount );
+		NextIrp->IoStatus.Status = Status;
+		NextIrp->IoStatus.Information = TotalBytesCopied;
+		IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
+	    }
+	}
+
+	if( FCB->Recv.Window && !FCB->Recv.Content ) {
+	    AFD_DbgPrint(MID_TRACE,
+			 ("Exhausted our buffer.  Requesting new: %x\n", FCB));
+	    Status = TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
+				 IrpSp->FileObject,
+				 TDI_RECEIVE_NORMAL,
+				 FCB->Recv.Window,
+				 FCB->Recv.Size,
+				 &FCB->ReceiveIrp.Iosb,
+				 ReceiveComplete,
+				 FCB );
+	}
+    } else {
+	while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_RECV] ) ) {
+	    NextIrpEntry = 
+		RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
+	    NextIrp = 
+		CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
+	    AFD_DbgPrint(MID_TRACE,("Completing recv %x (%x)\n", 
+				    NextIrp, Status));
+	    Irp->IoStatus.Status = Status;
+	    Irp->IoStatus.Information = 0;
+	    IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
+	}
+    }
+
+    if( FCB->Recv.Content ) {
+	FCB->PollState |= AFD_EVENT_RECEIVE;
+	PollReeval( FCB->DeviceExt, FCB->FileObject );
+    } else
+	FCB->PollState &= ~AFD_EVENT_RECEIVE;
+    
+
+    SocketStateUnlock( FCB );
+
+    AFD_DbgPrint(MID_TRACE,("Returned %x\n", Status));
+
+    return Status;
+}
+
+NTSTATUS STDCALL
+AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+			   PIO_STACK_LOCATION IrpSp, BOOLEAN Short) {
+    NTSTATUS Status = STATUS_INVALID_PARAMETER;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    PAFD_RECV_REQ RecvReq = Irp->AssociatedIrp.SystemBuffer;
+    UINT TotalBytesCopied = 0;
+
+    AFD_DbgPrint(MID_TRACE,("Called on %x\n", FCB));
+
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    RecvReq->BufferArray = LockBuffers( RecvReq->BufferArray, 
+					RecvReq->BufferCount,
+					TRUE );
+
+    Status = TryToSatisfyRecvRequestFromBuffer
+	( FCB, RecvReq, &TotalBytesCopied );
+
+    if( Status != STATUS_PENDING ) {
+	UnlockBuffers( RecvReq->BufferArray, RecvReq->BufferCount );
+	return UnlockAndMaybeComplete( FCB, Status, Irp, 
+				       TotalBytesCopied, NULL );
+    } else {
+	return LeaveIrpUntilLater( FCB, Irp, FUNCTION_RECV );
+    }
+}
+
+NTSTATUS STDCALL
+AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp ) {
+    Irp->IoStatus.Information = 0;
+    return STATUS_END_OF_FILE;
+}
+

reactos/drivers/net/afd/afd
select.c added at 1.1.2.1
diff -N select.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ select.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,236 @@
+/* $Id: select.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/select.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+VOID CopyBackStatus( PAFD_POLL_HANDLE HandleArray,
+		     UINT HandleCount ) {
+    UINT i;
+    
+    for( i = 0; i < HandleCount; i++ ) {
+	HandleArray[i].Events = HandleArray[i].Status;
+	HandleArray[i].Status = 0;
+    }
+}
+
+VOID ZeroEvents( PAFD_POLL_HANDLE HandleArray,
+		 UINT HandleCount ) {
+    UINT i;
+    
+    for( i = 0; i < HandleCount; i++ ) {
+	HandleArray[i].Events = 0;
+	HandleArray[i].Status = 0;
+    }
+}
+
+NTSTATUS STDCALL
+ScanForImmediateTrigger( PAFD_POLL_HANDLE HandleArray,
+			 UINT HandleCount,
+			 PUINT HandlesSet ) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    PFILE_OBJECT FileObject;
+    PAFD_FCB FCB;
+    UINT i;
+    BOOLEAN ShouldReturnNow = FALSE;
+
+    for( i = 0; i < HandleCount && NT_SUCCESS(Status); i++ ) {
+        HandleArray[i].Status = 0;
+	Status = 
+	    ObReferenceObjectByHandle
+	    ( HandleArray[i].Handle,
+	      FILE_ALL_ACCESS,
+	      NULL,
+	      KernelMode,
+	      (PVOID*)&FileObject,
+	      NULL );
+	if( NT_SUCCESS(Status) ) {
+	    FCB = FileObject->FsContext;
+	    /* Check select bits */
+	    if( !SocketAcquireStateLock( FCB ) ) 
+		Status = STATUS_UNSUCCESSFUL;
+	    if( NT_SUCCESS(Status) )
+		HandleArray[i].Status = 
+		    FCB->PollState & HandleArray[i].Events;
+	    if( HandleArray[i].Status ) ShouldReturnNow = TRUE;
+	    ObDereferenceObject( HandleArray[i].Handle );
+	}
+    }
+
+    if( !NT_SUCCESS(Status) || ShouldReturnNow ) return Status; 
+    else return STATUS_PENDING;
+}
+
+VOID SelectTimeout( PKDPC Dpc,
+		    PVOID DeferredContext,
+		    PVOID SystemArgument1,
+		    PVOID SystemArgument2 ) {
+    PAFD_ACTIVE_POLL Poll = DeferredContext;
+    PAFD_POLL_REQ PollReq;
+    PAFD_DEVICE_EXTENSION DeviceExt;
+    PIRP Irp;
+    KIRQL OldIrql;
+
+    Irp = Poll->Irp;
+    DeviceExt = Poll->DeviceExt;
+
+    PollReq = Irp->AssociatedIrp.SystemBuffer;
+
+    KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
+    RemoveEntryList( &Poll->ListEntry );
+    KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
+
+    ExFreePool( Poll );
+
+    ZeroEvents( PollReq->Handles, PollReq->HandleCount );
+
+    Irp->IoStatus.Status = STATUS_TIMEOUT;
+    Irp->IoStatus.Information = -1;
+
+    IoCompleteRequest( Irp, IO_NO_INCREMENT );
+}
+
+NTSTATUS STDCALL
+AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	   PIO_STACK_LOCATION IrpSp ) {
+    NTSTATUS Status = STATUS_NO_MEMORY;
+    PAFD_POLL_REQ PollReq = Irp->AssociatedIrp.SystemBuffer;
+    PAFD_DEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
+    PAFD_ACTIVE_POLL Poll = NULL;
+    UINT CopySize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
+    UINT AllocSize = 
+	CopySize + sizeof(AFD_ACTIVE_POLL) - sizeof(AFD_POLL_REQ);
+    KIRQL OldIrql;
+    UINT HandlesSignalled; 
+
+    AFD_DbgPrint(MID_TRACE,("Called\n"));
+
+    Status = ScanForImmediateTrigger( PollReq->Handles,
+				      PollReq->HandleCount,
+				      &HandlesSignalled );
+    
+    if( Status == STATUS_PENDING ) {
+	Poll = ExAllocatePool( NonPagedPool, AllocSize );
+	
+	if( Poll ) {
+	    KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
+	    
+	    KeInitializeDpc( (PRKDPC)&Poll->TimeoutDpc, 
+			     (PKDEFERRED_ROUTINE)SelectTimeout,
+			     Poll );
+	    PollReq->Timeout.QuadPart *= -1;
+	    /* Negative values are relative */
+	    KeInitializeTimerEx( &Poll->Timer, NotificationTimer );
+	    KeSetTimer( &Poll->Timer, PollReq->Timeout, &Poll->TimeoutDpc );
+	    
+	    Poll->Irp = Irp;
+	    Poll->DeviceExt = DeviceExt;
+
+	    InsertTailList( &DeviceExt->Polls, &Poll->ListEntry );
+	    Status = STATUS_PENDING;
+
+	    KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
+	} else Status = STATUS_NO_MEMORY;
+    } else if( Status == STATUS_SUCCESS ) {
+	CopyBackStatus( PollReq->Handles,
+			PollReq->HandleCount );
+    } else {
+	ZeroEvents( PollReq->Handles,
+		    PollReq->HandleCount );
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
+
+    if( Status == STATUS_PENDING )
+	IoMarkIrpPending( Irp );
+    else {
+	Irp->IoStatus.Status = Status;
+	Irp->IoStatus.Information = HandlesSignalled;
+	IoCompleteRequest( Irp, IO_NETWORK_INCREMENT );
+    }
+
+    return Status;
+}
+
+VOID SignalSocket( PAFD_ACTIVE_POLL Poll, PAFD_POLL_REQ PollReq, UINT i ) {
+    /* One of the files was destroyed.  We return now with error. */
+    Poll->Irp->IoStatus.Status = STATUS_SUCCESS; /* XXX REVISIT */
+    Poll->Irp->IoStatus.Information = 1;
+    CopyBackStatus( PollReq->Handles,
+		    PollReq->HandleCount );
+    IoCompleteRequest( Poll->Irp, IO_NETWORK_INCREMENT );
+}
+
+BOOLEAN UpdatePollWithFCB( PAFD_ACTIVE_POLL Poll, PFILE_OBJECT FileObject ) {
+    UINT i;
+    NTSTATUS Status;
+    PFILE_OBJECT TargetFile;
+    PAFD_FCB FCB;
+    PAFD_POLL_REQ PollReq = Poll->Irp->AssociatedIrp.SystemBuffer;
+
+    for( i = 0; i < PollReq->HandleCount; i++ ) {
+	Status = 
+	    ObReferenceObjectByHandle
+	    ( PollReq->Handles[i].Handle,
+	      FILE_ALL_ACCESS,
+	      NULL,
+	      KernelMode,
+	      (PVOID*)&TargetFile,
+	      NULL );
+	
+	if( !NT_SUCCESS(Status) ) { 
+	    PollReq->Handles[i].Status = AFD_EVENT_CLOSE;
+	    SignalSocket( Poll, PollReq, i );
+	    return TRUE;
+	} else {
+	    FCB = FileObject->FsContext;
+
+	    if( !SocketAcquireStateLock( FCB ) ) {
+		PollReq->Handles[i].Status = AFD_EVENT_CLOSE;
+		SignalSocket( Poll, PollReq, i );
+	    } else {
+		PollReq->Handles[i].Status = 
+		    PollReq->Handles[i].Events & FCB->PollState;
+		if( PollReq->Handles[i].Status )
+		    SignalSocket( Poll, PollReq, i );
+	    }
+	    return TRUE;
+	}
+    }
+
+    return FALSE;
+}
+
+VOID PollReeval( PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject ) {
+    PAFD_ACTIVE_POLL Poll = NULL;
+    PLIST_ENTRY ThePollEnt = NULL;
+    KIRQL OldIrql;
+
+    AFD_DbgPrint(MID_TRACE,("Called: DeviceExt %x FileObject %x\n", 
+			    DeviceExt, FileObject));
+
+    KeAcquireSpinLock( &DeviceExt->Lock, &OldIrql );
+
+    ThePollEnt = DeviceExt->Polls.Flink;
+
+    while( ThePollEnt != &DeviceExt->Polls ) {
+	Poll = CONTAINING_RECORD( ThePollEnt, AFD_ACTIVE_POLL, ListEntry );
+	if( UpdatePollWithFCB( Poll, FileObject ) ) {
+	    ThePollEnt = ThePollEnt->Flink;
+	    RemoveEntryList( &Poll->ListEntry );
+	} else 
+	    ThePollEnt = ThePollEnt->Flink;
+    }
+
+    KeReleaseSpinLock( &DeviceExt->Lock, OldIrql );
+
+    AFD_DbgPrint(MID_TRACE,("Leaving"));
+}

reactos/drivers/net/afd/afd
write.c added at 1.1.2.1
diff -N write.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ write.c	9 Jul 2004 04:41:18 -0000	1.1.2.1
@@ -0,0 +1,222 @@
+/* $Id: write.c,v 1.1.2.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/write.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
+#include "afd.h"
+#include "tdi_proto.h"
+#include "tdiconn.h"
+#include "debug.h"
+
+NTSTATUS DDKAPI SendComplete
+( PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context ) {
+    NTSTATUS Status = Irp->IoStatus.Status;
+    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
+    PAFD_FCB FCB = (PAFD_FCB)Context;
+    PLIST_ENTRY NextIrpEntry;
+    PIRP NextIrp = NULL;
+    PAFD_SEND_REQ SendReq;
+    PAFD_MAPBUF Map;
+    UINT TotalBytesCopied = 0, SpaceAvail, i, CopySize = 0;
+
+    AFD_DbgPrint(MID_TRACE,("Called, status %x, %d bytes used\n",
+			    Irp->IoStatus.Status,
+			    Irp->IoStatus.Information));
+
+    if( !SocketAcquireStateLock( FCB ) ) return Status;
+
+    if( !NT_SUCCESS(Status) ) {
+	/* Complete all following send IRPs with error */
+	
+	while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
+	    NextIrpEntry = 
+		RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
+	    NextIrp = 
+		CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
+	    SendReq = NextIrp->AssociatedIrp.SystemBuffer;
+
+	    UnlockBuffers( SendReq->BufferArray,
+			   SendReq->BufferCount );
+
+	    NextIrp->IoStatus.Status = Status;
+	    NextIrp->IoStatus.Information = 0;
+
+	    IoCompleteRequest( NextIrp, IO_NETWORK_INCREMENT );
+	}
+	
+	SocketStateUnlock( FCB );
+	return STATUS_SUCCESS;
+    }
+
+    RtlMoveMemory( FCB->Send.Window,
+		   FCB->Send.Window + FCB->Send.BytesUsed,
+		   FCB->Send.BytesUsed - Irp->IoStatus.Information );
+    FCB->Send.BytesUsed -= Irp->IoStatus.Information;
+
+    if( !FCB->Send.BytesUsed &&
+	!IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) &&
+	NT_SUCCESS(Status) ) {
+	NextIrpEntry = 
+	    RemoveHeadList(&FCB->PendingIrpList[FUNCTION_RECV]);
+	NextIrp = 
+	    CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
+	SendReq = NextIrp->AssociatedIrp.SystemBuffer;
+	Map = (PAFD_MAPBUF)(SendReq->BufferArray + SendReq->BufferCount);
+
+	AFD_DbgPrint(MID_TRACE,("SendReq @ %x\n", SendReq));
+	    
+	SpaceAvail = FCB->Send.Size - FCB->Send.BytesUsed;
+	    
+	for( i = 0; FCB->Send.BytesUsed < FCB->Send.Content && 
+		 i < SendReq->BufferCount; i++ ) {
+	    Map[i].BufferAddress = 
+		MmMapLockedPages( Map[i].Mdl, KernelMode );
+
+	    CopySize = MIN( SpaceAvail, SendReq->BufferArray[i].len );
+
+	    RtlCopyMemory( FCB->Send.Window + FCB->Send.BytesUsed,
+			   Map[i].BufferAddress,
+			   CopySize );
+	    
+	    MmUnmapLockedPages( Map[i].Mdl, KernelMode );
+	    
+	    FCB->Send.BytesUsed += CopySize;
+	    TotalBytesCopied += CopySize;
+	    SpaceAvail -= CopySize;
+	}
+    }
+	
+    /* Some data is still waiting */
+    if( FCB->Send.BytesUsed ) {
+	FCB->PollState &= ~AFD_EVENT_SEND;
+	Status = TdiSend( &FCB->SendIrp.InFlightRequest,
+			  IrpSp->FileObject,
+			  0,
+			  FCB->Send.Window,
+			  FCB->Send.BytesUsed,
+			  &FCB->SendIrp.Iosb,
+			  SendComplete,
+			  FCB );
+    } else {
+	FCB->PollState |= AFD_EVENT_SEND;
+	PollReeval( FCB->DeviceExt, FCB->FileObject );
+    }
+
+    if( TotalBytesCopied > 0 ) {
+	UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount );
+
+	if( Status == STATUS_PENDING )
+	    Status = STATUS_SUCCESS;
+
+	AFD_DbgPrint(MID_TRACE,("Dismissing request: %x\n", Status));
+	
+	return UnlockAndMaybeComplete( FCB, Status, Irp, TotalBytesCopied, 
+				       NULL );
+    } else if( NextIrp ) {
+	AFD_DbgPrint(MID_TRACE,("Could not do any more with Irp %x\n",
+				NextIrp));
+	InsertHeadList( &FCB->PendingIrpList[FUNCTION_SEND],
+			&Irp->Tail.Overlay.ListEntry );
+
+	SocketStateUnlock( FCB );
+    }
+	
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS STDCALL
+AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+			    PIO_STACK_LOCATION IrpSp, BOOLEAN Short) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    PFILE_OBJECT FileObject = IrpSp->FileObject;
+    PAFD_FCB FCB = FileObject->FsContext;
+    PAFD_SEND_REQ SendReq = Irp->AssociatedIrp.SystemBuffer;
+    UINT TotalBytesCopied = 0, i, CopySize = 0, 
+	SpaceAvail = 0, TotalBytesEncountered = 0;
+
+    AFD_DbgPrint(MID_TRACE,("Called on %x\n", FCB));
+
+    if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
+
+    AFD_DbgPrint(MID_TRACE,("We already have %d bytes waiting.\n", 
+			    FCB->Send.BytesUsed));
+
+    SendReq->BufferArray = LockBuffers( SendReq->BufferArray,
+					SendReq->BufferCount,
+					FALSE );
+    
+    if( !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++ ) {
+	    CopySize = MIN( SpaceAvail, SendReq->BufferArray[i].len );
+
+	    TotalBytesEncountered += SendReq->BufferArray[i].len;
+
+	    AFD_DbgPrint(MID_TRACE,("Copying Buffer %d, %x:%d to %x\n",
+				    i, 
+				    SendReq->BufferArray[i].buf,
+				    CopySize,
+				    FCB->Send.Window + FCB->Send.BytesUsed));
+	    
+	    RtlCopyMemory( FCB->Send.Window + FCB->Send.BytesUsed,
+			   SendReq->BufferArray[i].buf,
+			   CopySize );
+	    
+	    FCB->Send.BytesUsed += CopySize;
+	    TotalBytesCopied += CopySize;
+	    SpaceAvail -= CopySize;
+	}
+	
+	if( TotalBytesEncountered == 0 ) {
+	    UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount );
+	    
+	    AFD_DbgPrint(MID_TRACE,("Empty send\n"));
+	    return UnlockAndMaybeComplete
+		( FCB, Status, Irp, TotalBytesCopied, NULL );
+	}
+	
+	AFD_DbgPrint(MID_TRACE,("Completed %d bytes\n", TotalBytesCopied));
+	
+	if( TotalBytesCopied > 0 ) {
+	    UnlockBuffers( SendReq->BufferArray, SendReq->BufferCount );
+
+	    Status = TdiSend( &FCB->SendIrp.InFlightRequest,
+			      FCB->Connection.Object,
+			      0,
+			      FCB->Send.Window,
+			      FCB->Send.BytesUsed,
+			      &FCB->SendIrp.Iosb,
+			      SendComplete,
+			      FCB );
+	    
+	    if( Status == STATUS_PENDING )
+		Status = STATUS_SUCCESS;
+	    
+	    AFD_DbgPrint(MID_TRACE,("Dismissing request: %x\n", Status));
+	    
+	    return UnlockAndMaybeComplete
+		( FCB, Status, Irp, TotalBytesCopied, NULL );
+	}
+    }
+
+    AFD_DbgPrint(MID_TRACE,("Queuing request\n"));
+    return LeaveIrpUntilLater( FCB, Irp, FUNCTION_SEND );
+}
+
+NTSTATUS STDCALL
+AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp) {
+    Irp->IoStatus.Information = 0;
+    return STATUS_SUCCESS;
+}
+

reactos/drivers/net/afd/afd
tdi.c 1.13 -> 1.13.4.1
diff -u -r1.13 -r1.13.4.1
--- tdi.c	3 Jul 2004 17:40:20 -0000	1.13
+++ tdi.c	9 Jul 2004 04:41:18 -0000	1.13.4.1
@@ -8,6 +8,7 @@
  *   CSH 01/09-2000 Created
  */
 #include <afd.h>
+#include "debug.h"
 #include "tdiconn.h"
 
 #ifdef DBG
@@ -57,10 +58,10 @@
 {
     NTSTATUS Status;
 
-    AFD_DbgPrint(MAX_TRACE, ("Called\n"));
+    AFD_DbgPrint(MID_TRACE, ("Called\n"));
     
     Status = IoCallDriver(DeviceObject, Irp);
-    AFD_DbgPrint(MAX_TRACE, ("IoCallDriver: %08x\n", Status));
+    AFD_DbgPrint(MID_TRACE, ("IoCallDriver: %08x\n", Status));
 
     if ((Status == STATUS_PENDING) && (Event != NULL)) {
         AFD_DbgPrint(MAX_TRACE, ("Waiting on transport.\n"));
@@ -110,7 +111,7 @@
                                NULL);                   /* Security descriptor */
 
     Status = ZwCreateFile(Handle,                               /* Return file handle */
-                          GENERIC_READ | GENERIC_WRITE,         /* Desired access */
+                          GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,         /* Desired access */
                           &Attr,                                /* Object attributes */
                           &Iosb,                                /* IO status */
                           0,                                    /* Initial allocation size */
@@ -122,7 +123,7 @@
                           EaLength);                            /* EA length */
     if (NT_SUCCESS(Status)) {
         Status = ObReferenceObjectByHandle(*Handle,                       /* Handle to open file */
-                                           GENERIC_READ | GENERIC_WRITE,  /* Access mode */
+                                           GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE,  /* Access mode */
                                            NULL,                          /* Object type */
                                            KernelMode,                    /* Access mode */
                                            (PVOID*)Object,                /* Pointer to object */
@@ -158,9 +159,9 @@
 }
 
 
-NTSTATUS TdiOpenAddressFileIPv4(
+NTSTATUS TdiOpenAddressFile(
     PUNICODE_STRING DeviceName,
-    LPSOCKADDR Name,
+    PTRANSPORT_ADDRESS Name,
     PHANDLE AddressHandle,
     PFILE_OBJECT *AddressObject)
 /*
@@ -175,21 +176,21 @@
  */
 {
   PFILE_FULL_EA_INFORMATION EaInfo;
-  PTA_IP_ADDRESS Address;
   NTSTATUS Status;
   ULONG EaLength;
-
+  PTRANSPORT_ADDRESS Address;
+  
   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 */
+			   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 +
-             sizeof(TA_IP_ADDRESS) + 1;
+      TDI_TRANSPORT_ADDRESS_LENGTH +
+      TaLengthOfTransportAddress( Name ) + 1;
   EaInfo = (PFILE_FULL_EA_INFORMATION)ExAllocatePool(NonPagedPool, EaLength);
   if (!EaInfo)
-    return STATUS_INSUFFICIENT_RESOURCES;
-
+      return STATUS_INSUFFICIENT_RESOURCES;
+  
   RtlZeroMemory(EaInfo, EaLength);
   EaInfo->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH;
   /* Don't copy the terminating 0; we have already zeroed it */
@@ -197,9 +198,9 @@
                 TdiTransportAddress,
                 TDI_TRANSPORT_ADDRESS_LENGTH);
   EaInfo->EaValueLength = sizeof(TA_IP_ADDRESS);
-  Address = (PTA_IP_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); /* 0-terminated */
-  TdiBuildAddressIPv4(Address, Name);
-
+  Address = 
+      (PTRANSPORT_ADDRESS)(EaInfo->EaName + TDI_TRANSPORT_ADDRESS_LENGTH + 1); /* 0-terminated */
+  TaCopyTransportAddressInPlace( Address, Name );
   Status = TdiOpenDevice(DeviceName,
                          EaLength,
                          EaInfo,
@@ -210,43 +211,6 @@
 }
 
 
-NTSTATUS TdiOpenAddressFile(
-  PUNICODE_STRING DeviceName,
-  LPSOCKADDR Name,
-  PHANDLE AddressHandle,
-  PFILE_OBJECT *AddressObject)
-/*
- * FUNCTION: Opens an address file object
- * ARGUMENTS:
- *     DeviceName    = Pointer to counted string with name of device
- *     Name          = Pointer to socket name
- *     AddressHandle = Address of buffer to place address file handle
- *     AddressObject = Address of buffer to place address file object
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-
-  switch (Name->sa_family) {
-  case AF_INET:
-    Status = TdiOpenAddressFileIPv4(
-      DeviceName,
-      Name,
-      AddressHandle,
-      AddressObject);
-    break;
-
-  default:
-    AFD_DbgPrint(MAX_TRACE, ("Unknown socket address family (0x%X)\n",
-      Name->sa_family));
-    Status = STATUS_INVALID_PARAMETER;
-  }
-
-  return Status;
-}
-
-
 NTSTATUS TdiOpenConnectionEndpointFile(
   PUNICODE_STRING DeviceName,
   PHANDLE ConnectionHandle,
@@ -298,8 +262,11 @@
 
 
 NTSTATUS TdiConnect(
-  PFILE_OBJECT ConnectionObject,
-  LPSOCKADDR RemoteAddress)
+    PIRP *Irp,
+    PFILE_OBJECT ConnectionObject,
+    PTRANSPORT_ADDRESS RemoteAddress,
+    PIO_COMPLETION_ROUTINE CompletionRoutine,
+    PVOID CompletionContext)
 /*
  * FUNCTION: Connect a connection endpoint to a remote peer
  * ARGUMENTS:
@@ -315,7 +282,6 @@
   IO_STATUS_BLOCK Iosb;
   NTSTATUS Status;
   KEVENT Event;
-  PIRP Irp;
 
   AFD_DbgPrint(MAX_TRACE, ("Called\n"));
 
@@ -323,12 +289,17 @@
 
   DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
 
-  Status = TdiBuildConnectionInfo(&RequestConnectionInfo, RemoteAddress);
-  if (!NT_SUCCESS(Status))
+  /* Use same TDI address type for return connection information */
+  Status = TdiBuildConnectionInfo(&RequestConnectionInfo, 
+				  &RemoteAddress->Address[0]);
+  if (!NT_SUCCESS(Status)) {
+    ExFreePool(RequestConnectionInfo);
     return Status;
+  }
 
   /* Use same TDI address type for return connection information */
-  Status = TdiBuildConnectionInfo(&ReturnConnectionInfo, RemoteAddress);
+  Status = TdiBuildConnectionInfo(&ReturnConnectionInfo, 
+				  &RemoteAddress->Address[0]);
   if (!NT_SUCCESS(Status)) {
     ExFreePool(RequestConnectionInfo);
     ExFreePool(ReturnConnectionInfo);
@@ -337,29 +308,27 @@
 
   KeInitializeEvent(&Event, NotificationEvent, FALSE);
 
-  Irp = TdiBuildInternalDeviceControlIrp(TDI_CONNECT,             /* Sub function */
-                                         DeviceObject,            /* Device object */
-                                         ConnectionObject,        /* File object */
-                                         &Event,                  /* Event */
-                                         &Iosb);                  /* Status */
-  if (!Irp) {
-    ExFreePool(RequestConnectionInfo);
+  *Irp = TdiBuildInternalDeviceControlIrp(TDI_CONNECT,             /* Sub function */
+					  DeviceObject,            /* Device object */
+					  ConnectionObject,        /* File object */
+					  &Event,                  /* Event */
+					  &Iosb);                  /* Status */
+  if (!*Irp) {
     ExFreePool(ReturnConnectionInfo);
     return STATUS_INSUFFICIENT_RESOURCES;
   }
 
-  TdiBuildConnect(Irp,                    /* IRP */
+  TdiBuildConnect(*Irp,                   /* IRP */
                   DeviceObject,           /* Device object */
                   ConnectionObject,       /* File object */
-                  NULL,                   /* Completion routine */
-                  NULL,                   /* Completion routine context */
+                  CompletionRoutine,      /* Completion routine */
+                  CompletionContext,      /* Completion routine context */
                   NULL,                   /* Time */
                   RequestConnectionInfo,  /* Request connection information */
                   ReturnConnectionInfo);  /* Return connection information */
 
-  Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
+  Status = TdiCall(*Irp, DeviceObject, &Event, &Iosb);
 
-  ExFreePool(RequestConnectionInfo);
   ExFreePool(ReturnConnectionInfo);
 
   return Status;
@@ -414,14 +383,16 @@
 }
 
 
-NTSTATUS TdiListen(
-  PAFD_LISTEN_REQUEST ListenRequest,
+NTSTATUS TdiListen
+( PIRP *Irp,
+  PFILE_OBJECT ConnectionObject,
+  PTDI_CONNECTION_INFORMATION *RequestConnectionInfo,
+  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:
- *     ListenRequest     = Pointer to listen request object
  *     CompletionRoutine = Routine to be called when IRP is completed
  *     CompletionContext = Context for CompletionRoutine
  * RETURNS:
@@ -429,46 +400,40 @@
  *     May return STATUS_PENDING
  */
 {
-  PFILE_OBJECT ConnectionObject;
   PDEVICE_OBJECT DeviceObject;
   NTSTATUS Status;
-  PIRP Irp;
 
   AFD_DbgPrint(MAX_TRACE, ("Called\n"));
 
-  ConnectionObject = ListenRequest->Fcb->TdiConnectionObject;
-  assert(ConnectionObject);
-
   DeviceObject = IoGetRelatedDeviceObject(ConnectionObject);
 
-  Status = TdiBuildNullConnectionInfo(&ListenRequest->RequestConnectionInfo,
-    TDI_ADDRESS_TYPE_IP);
+  Status = TdiBuildNullConnectionInfo(RequestConnectionInfo,
+				      TDI_ADDRESS_TYPE_IP);
   if (!NT_SUCCESS(Status))
     return Status;
 
-  Irp = TdiBuildInternalDeviceControlIrp(TDI_LISTEN,              /* Sub function */
-                                         DeviceObject,            /* Device object */
-                                         ConnectionObject,        /* File object */
-                                         NULL,                    /* Event */
-                                         &ListenRequest->Iosb);   /* Status */
-  if (Irp == NULL)
+  *Irp = TdiBuildInternalDeviceControlIrp(TDI_LISTEN,              /* Sub function */
+					  DeviceObject,            /* Device object */
+					  ConnectionObject,        /* File object */
+					  NULL,                    /* Event */
+					  Iosb);                   /* Status */
+  if (*Irp == NULL)
     {
-      ExFreePool(ListenRequest->RequestConnectionInfo);
-	  ListenRequest->RequestConnectionInfo = NULL;
-      return STATUS_INSUFFICIENT_RESOURCES;
+	ExFreePool(*RequestConnectionInfo);
+	return STATUS_INSUFFICIENT_RESOURCES;
     }
-
-  TdiBuildListen(Irp,                    /* IRP */
+  
+  TdiBuildListen(*Irp,                   /* IRP */
                  DeviceObject,           /* Device object */
                  ConnectionObject,       /* File object */
                  CompletionRoutine,      /* Completion routine */
                  CompletionContext,      /* Completion routine context */
                  0,                      /* Flags */
-                 ListenRequest->RequestConnectionInfo,  /* Request connection information */
+                 *RequestConnectionInfo, /* Request connection information */
                  NULL /* ReturnConnectionInfo */);  /* Return connection information */
 
-  Status = TdiCall(Irp, DeviceObject, NULL /* Don't wait for completion */, &ListenRequest->Iosb);
-
+  Status = TdiCall(*Irp, DeviceObject, NULL /* Don't wait for completion */, Iosb);
+  
   return Status;
 }
 
@@ -629,7 +594,7 @@
     return Status;
 }
 
-
+#if 0
 NTSTATUS TdiQueryInformationEx(
     PFILE_OBJECT FileObject,
     ULONG Entity,
@@ -672,7 +637,6 @@
                                  OutputLength);                             /* Return information */
 }
 
-
 NTSTATUS TdiQueryAddress(
     PFILE_OBJECT FileObject,
     PULONG Address)
@@ -806,31 +770,20 @@
 
     return Status;
 }
+#endif
 
-
-NTSTATUS TdiSend(
-    PFILE_OBJECT TransportObject,
-    PVOID Buffer,
-    ULONG BufferSize)
-/*
- * FUNCTION: Sends a block of data
- * ARGUMENTS:
- *     TransportObject = Pointer to transport object
- *     Buffer          = Pointer to buffer with data to send
- *     BufferSize      = Length of Buffer
- * RETURNS:
- *     Status of operation
- */
+NTSTATUS TdiSend
+( PIRP *Irp,
+  PFILE_OBJECT TransportObject,
+  USHORT Flags,
+  PCHAR Buffer,
+  UINT BufferLength,
+  PIO_STATUS_BLOCK Iosb,
+  PIO_COMPLETION_ROUTINE CompletionRoutine,
+  PVOID CompletionContext )
 {
-#if 0
-    PTDI_CONNECTION_INFORMATION ConnectInfo;
     PDEVICE_OBJECT DeviceObject;
-    IO_STATUS_BLOCK Iosb;
-    DWORD TdiAddressSize;
-    PVOID BaseAddress;
     NTSTATUS Status;
-    KEVENT Event;
-    PIRP Irp;
     PMDL Mdl;
 
     DeviceObject = IoGetRelatedDeviceObject(TransportObject);
@@ -839,38 +792,28 @@
         return STATUS_INVALID_PARAMETER;
     }
 
-    Status = TdiBuildConnectionInfo( &ConnectInfo, Address );
-    if (!NT_SUCCESS(Status))
-	return STATUS_INSUFFICIENT_RESOURCES;
-
-    KeInitializeEvent(&Event, NotificationEvent, FALSE);
+    *Irp = TdiBuildInternalDeviceControlIrp
+	( TDI_SEND,                /* 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 */
-                                           &Event,              /* Event */
-                                           &Iosb);              /* Status */
-    if (!Irp) {
-        AFD_DbgPrint(MIN_TRACE, ("TdiBuildInternalDeviceControlIrp() failed.\n"));
-        ExFreePool(ConnectInfo);
+    if (!*Irp) {
+        AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-DisplayBuffer(Request->Buffers->buf, Request->Buffers->len);
-
+    AFD_DbgPrint(MID_TRACE, ("Allocating irp for %x:%d\n", Buffer,BufferLength));
 
-    /* FIXME: There may be more than one buffer */
-    BufferSize = Request->Buffers->len;
-    Mdl = IoAllocateMdl(
-        Request->Buffers->buf,  /* Virtual address of buffer */
-        Request->Buffers->len,  /* Length of buffer */
-        FALSE,                  /* Not secondary */
-        FALSE,                  /* Don't charge quota */
-        NULL);                  /* Don't use IRP */
+    Mdl = IoAllocateMdl(Buffer,         /* Virtual address */
+                        BufferLength,   /* Length of buffer */
+                        FALSE,          /* Not secondary */
+                        FALSE,          /* Don't charge quota */
+                        *Irp);          /* use IRP */
     if (!Mdl) {
-        AFD_DbgPrint(MIN_TRACE, ("IoAllocateMdl() failed.\n"));
-        IoFreeIrp(Irp);
-        ExFreePool(ConnectInfo);
+        AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+        IoFreeIrp(*Irp);
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
@@ -879,47 +822,35 @@
 #endif
         MmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess);
 #ifdef _MSC_VER
-    } except(EXCEPTION_EXECUTE_HANDLER) {
+    } except (EXCEPTION_EXECUTE_HANDLER) {
         AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
-        IoFreeMdl(Mdl);
-        IoFreeIrp(Irp);
-        ExFreePool(ConnectInfo);
-        return STATUS_UNSUCCESSFUL;
+        IoFreeIrp(*Irp);
+        return STATUS_INSUFFICIENT_RESOURCES;
     }
 #endif
 
-    BaseAddress = MmMapLockedPages(Mdl, KernelMode);
-
-    AFD_DbgPrint(MAX_TRACE, ("Mapped user mode buffer at 0x%X.\n", BaseAddress));
-
-    TdiBuildSendDatagram(Irp,               /* I/O Request Packet */
-                         DeviceObject,      /* Device object */
-                         TransportObject,   /* File object */
-                         NULL,              /* Completion routine */
-                         NULL,              /* Completion context */
-                         Mdl,               /* Descriptor for data buffer */
-                         BufferSize,        /* Size of data to send */
-                         ConnectInfo);      /* Connection information */
-
-    Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
-
-    MmUnmapLockedPages(BaseAddress, Mdl);
-
-    MmUnlockPages(Mdl);
+    AFD_DbgPrint(MID_TRACE,("AFD>>> Got an MDL: %x\n", Mdl));
 
-    IoFreeMdl(Mdl);
-
-    ExFreePool(ConnectInfo);
+    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 */
+
+    Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
+    /* Does not block...  The MDL is deleted in the receive completion
+       routine. */
 
     return Status;
-#endif
-    return STATUS_SUCCESS;
 }
 
 
 NTSTATUS TdiSendDatagram(
     PFILE_OBJECT TransportObject,
-    LPSOCKADDR Address,
+    PTA_ADDRESS Address,
     PMDL Mdl,
     ULONG BufferSize)
 /*
@@ -1025,10 +956,87 @@
 }
 
 
+NTSTATUS TdiReceive(
+    PIRP *Irp,
+    PFILE_OBJECT TransportObject,
+    USHORT Flags,
+    PCHAR Buffer,
+    UINT BufferLength,
+    PIO_STATUS_BLOCK Iosb,
+    PIO_COMPLETION_ROUTINE CompletionRoutine,
+    PVOID CompletionContext)
+{
+    PDEVICE_OBJECT DeviceObject;
+    NTSTATUS Status;
+    PMDL Mdl;
+
+    DeviceObject = IoGetRelatedDeviceObject(TransportObject);
+    if (!DeviceObject) {
+        AFD_DbgPrint(MIN_TRACE, ("Bad device object.\n"));
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    *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"));
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    AFD_DbgPrint(MID_TRACE, ("Allocating irp for %x:%d\n", Buffer,BufferLength));
+
+    Mdl = IoAllocateMdl(Buffer,         /* Virtual address */
+                        BufferLength,   /* Length of buffer */
+                        FALSE,          /* Not secondary */
+                        FALSE,          /* Don't charge quota */
+                        *Irp);          /* Don't use IRP */
+    if (!Mdl) {
+        AFD_DbgPrint(MIN_TRACE, ("Insufficient resources.\n"));
+        IoFreeIrp(*Irp);
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+#ifdef _MSC_VER
+    try {
+#endif
+        MmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess);
+#ifdef _MSC_VER
+    } except (EXCEPTION_EXECUTE_HANDLER) {
+        AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
+        IoFreeMdl(Mdl);
+        IoFreeIrp(*Irp);
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+#endif
+
+    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 */
+
+    Status = TdiCall(*Irp, DeviceObject, NULL, Iosb);
+    /* Does not block...  The MDL is deleted in the receive completion
+       routine. */
+
+    return Status;
+}
+
+
 NTSTATUS TdiReceiveDatagram(
     PFILE_OBJECT TransportObject,
-    LPSOCKADDR From,
-    LPSOCKADDR Address,
+    PTA_ADDRESS From,
+    PTA_ADDRESS Address,
     PUCHAR Buffer,
     PULONG BufferSize)
 /*
@@ -1044,7 +1052,7 @@
  */
 {
     PTDI_CONNECTION_INFORMATION ReceiveInfo;
-    TDI_CONNECTION_INFORMATION ReturnInfo;
+    PTDI_CONNECTION_INFORMATION ReturnInfo = NULL;
     PDEVICE_OBJECT DeviceObject;
     IO_STATUS_BLOCK Iosb;
     NTSTATUS Status;
@@ -1111,12 +1119,12 @@
                             Mdl,                    /* Data buffer */
                             *BufferSize,            /* Size of data buffer */
                             ReceiveInfo,            /* Connection information */
-                            &ReturnInfo,            /* Connection information */
+                            ReturnInfo,             /* Connection information */
                             TDI_RECEIVE_NORMAL);    /* Flags */
     Status = TdiCall(Irp, DeviceObject, &Event, &Iosb);
     if (NT_SUCCESS(Status)) {
         *BufferSize = Iosb.Information;
-        TdiBuildName(Address, TdiGetRemoteAddress(&ReturnInfo));
+	TaCopyAddressInPlace( Address, TdiGetRemoteAddress(ReturnInfo) );
     }
 
     MmUnlockPages(Mdl);

reactos/drivers/net/afd/afd
tdiconn.c 1.1 -> 1.1.16.1
diff -u -r1.1 -r1.1.16.1
--- tdiconn.c	7 Feb 2004 04:50:44 -0000	1.1
+++ tdiconn.c	9 Jul 2004 04:41:18 -0000	1.1.16.1
@@ -1,192 +1,64 @@
+/* $Id: tdiconn.c,v 1.1.16.1 2004/07/09 04:41:18 arty Exp $
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/afd/tdiconn.c
+ * PURPOSE:          Ancillary functions driver
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040708 Created
+ */
 #include <afd.h>
+#include "debug.h"
 #include "tdiconn.h"
 
-DWORD TdiAddressSizeFromType(
-  ULONG Type)
-/*
- * FUNCTION: Returns the size of a TDI style address of given address type
- * ARGUMENTS:
- *     Type = TDI style address type
- * RETURNS:
- *     Size of TDI style address, 0 if Type is not valid
- */
-{
-  switch (Type) {
-  case TDI_ADDRESS_TYPE_IP:
-    return sizeof(TA_IP_ADDRESS);
-  /* FIXME: More to come */
-  }
-  AFD_DbgPrint(MIN_TRACE, ("Unknown TDI address type (%d).\n", Type));
-  return 0;
-}
-
-DWORD TdiAddressSizeFromName(
-  LPSOCKADDR Name)
-/*
- * FUNCTION: Returns the size of a TDI style address equivalent to a
- *           WinSock style name
- * ARGUMENTS:
- *     Name = WinSock style name
- * RETURNS:
- *     Size of TDI style address, 0 if Name is not valid
- */
-{
-  switch (Name->sa_family) {
-  case AF_INET:
-    return sizeof(TA_IP_ADDRESS);
-  /* FIXME: More to come */
-  }
-  AFD_DbgPrint(MIN_TRACE, ("Unknown address family (%d).\n", Name->sa_family));
-  return 0;
+UINT TdiAddressSizeFromType( UINT AddressType ) {
+    switch( AddressType ) {
+    case TDI_ADDRESS_TYPE_IP:
+	return sizeof(TA_IP_ADDRESS);
+    default:
+	KeBugCheck( 0 );
+    }
+    return 0;
 }
 
-
-VOID TdiBuildAddressIPv4(
-  PTA_IP_ADDRESS Address,
-  LPSOCKADDR Name)
-/*
- * FUNCTION: Builds an IPv4 TDI style address
- * ARGUMENTS:
- *     Address = Address of buffer to place TDI style IPv4 address
- *     Name    = Pointer to WinSock style IPv4 name
- */
-{
-    Address->TAAddressCount                 = 1;
-    Address->Address[0].AddressLength       = TDI_ADDRESS_LENGTH_IP;
-    Address->Address[0].AddressType         = TDI_ADDRESS_TYPE_IP;
-    Address->Address[0].Address[0].sin_port = ((LPSOCKADDR_IN)Name)->sin_port;
-    Address->Address[0].Address[0].in_addr  = ((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr;
+UINT TaLengthOfAddress( PTA_ADDRESS Addr ) {
+    UINT AddrLen = 2 * sizeof( USHORT ) + Addr->AddressLength;
+    AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen));
+    return AddrLen;
 }
 
-
-NTSTATUS TdiBuildAddress(
-  PTA_ADDRESS Address,
-  LPSOCKADDR Name)
-/*
- * FUNCTION: Builds a TDI style address
- * ARGUMENTS:
- *     Address = Address of buffer to place TDI style address
- *     Name    = Pointer to WinSock style name
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  switch (Name->sa_family) {
-  case AF_INET:
-      TdiBuildAddressIPv4((PTA_IP_ADDRESS)Address,Name);
-      break;
-      /* FIXME: More to come */
-  default:
-      AFD_DbgPrint(MID_TRACE, ("Unknown address family (%d).\n", Name->sa_family));
-      Status = STATUS_INVALID_PARAMETER;
-  }
-  
-  return Status;
+UINT TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr ) {
+    UINT AddrLen = 2 * sizeof( ULONG ) + Addr->Address[0].AddressLength;
+    AFD_DbgPrint(MID_TRACE,("AddrLen %x\n", AddrLen));
+    return AddrLen;
 }
 
-
-NTSTATUS TdiBuildName(
-  LPSOCKADDR Name,
-  PTA_ADDRESS Address)
-/*
- * FUNCTION: Builds a WinSock style address
- * ARGUMENTS:
- *     Name    = Address of buffer to place WinSock style name
- *     Address = Pointer to TDI style address
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status = STATUS_SUCCESS;
-
-  switch (Address->AddressType) {
-  case TDI_ADDRESS_TYPE_IP:
-    Name->sa_family = AF_INET;
-    ((LPSOCKADDR_IN)Name)->sin_port = 
-      ((PTDI_ADDRESS_IP)&Address->Address[0])->sin_port;
-    ((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr = 
-      ((PTDI_ADDRESS_IP)&Address->Address[0])->in_addr;
-    break;
-  /* FIXME: More to come */
-  default:
-    AFD_DbgPrint(MID_TRACE, ("Unknown TDI address type (%d).\n", Address->AddressType));
-    Status = STATUS_INVALID_PARAMETER;
-  }
-
-  return Status;
-
+VOID TaCopyAddressInPlace( PTA_ADDRESS Target,
+			   PTA_ADDRESS Source ) {
+    UINT AddrLen = TaLengthOfAddress( Source );
+    RtlCopyMemory( Target, Source, AddrLen );
 }
 
-NTSTATUS TdiBuildConnectionInfoInPlace
-( PTDI_CONNECTION_INFORMATION ConnInfo,
-  LPSOCKADDR Name ) 
-/*
- * FUNCTION: Builds a TDI connection information structure
- * ARGUMENTS:
- *     ConnectionInfo = Address of buffer to place connection information
- *     Name           = Pointer to WinSock style name
- * RETURNS:
- *     Status of operation
- */
-{
-    ULONG TdiAddressSize;
-    
-    TdiAddressSize = TdiAddressSizeFromName(Name);
-
-    RtlZeroMemory(ConnInfo,
-		  sizeof(TDI_CONNECTION_INFORMATION) +
-		  TdiAddressSize);
-    
-    ConnInfo->OptionsLength = sizeof(ULONG);
-    ConnInfo->RemoteAddressLength = TdiAddressSize;
-    ConnInfo->RemoteAddress = (PVOID)
-	(((PCHAR)ConnInfo) + sizeof(TDI_CONNECTION_INFORMATION));
-    
-    TdiBuildAddress(ConnInfo->RemoteAddress, Name);
-    
-    return STATUS_SUCCESS;
+VOID TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target, 
+				    PTRANSPORT_ADDRESS Source ) {
+    UINT AddrLen = TaLengthOfTransportAddress( Source );
+    RtlCopyMemory( Target, Source, AddrLen );
 }
-    
 
-NTSTATUS TdiBuildConnectionInfo(
-  PTDI_CONNECTION_INFORMATION *ConnectionInfo,
-  LPSOCKADDR Name)
-/*
- * FUNCTION: Builds a TDI connection information structure
- * ARGUMENTS:
- *     ConnectionInfo = Address of buffer pointer to allocate connection 
- *                      information on
- *     Name           = Pointer to WinSock style name
- * RETURNS:
- *     Status of operation
- */
-{
-    PTDI_CONNECTION_INFORMATION ConnInfo;
-    ULONG TdiAddressSize;
-    NTSTATUS Status;
-    
-    TdiAddressSize = TdiAddressSizeFromName(Name);
-    
-    ConnInfo = (PTDI_CONNECTION_INFORMATION)
-	ExAllocatePool(NonPagedPool,
-		       sizeof(TDI_CONNECTION_INFORMATION) +
-		       TdiAddressSize);
-    if (!ConnInfo)
-	return STATUS_INSUFFICIENT_RESOURCES;
+PTRANSPORT_ADDRESS TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress ) {
+    UINT AddrLen;
+    PTRANSPORT_ADDRESS A;
     
-    Status = TdiBuildConnectionInfoInPlace( ConnInfo, Name );
+    ASSERT(OtherAddress->TAAddressCount == 1);
+    AddrLen = TaLengthOfTransportAddress( OtherAddress );
+    A = ExAllocatePool( NonPagedPool, AddrLen );
 
-    if( !NT_SUCCESS(Status) )
-	ExFreePool( ConnInfo );
-    else 
-	*ConnectionInfo = ConnInfo;
+    if( A ) 
+	TaCopyTransportAddressInPlace( A, OtherAddress );
     
-    return Status;
+  return A;
 }
 
-
 NTSTATUS TdiBuildNullConnectionInfoInPlace
 ( PTDI_CONNECTION_INFORMATION ConnInfo,
   ULONG Type ) 
@@ -204,8 +76,8 @@
   TdiAddressSize = TdiAddressSizeFromType(Type);
 
   RtlZeroMemory(ConnInfo,
-    sizeof(TDI_CONNECTION_INFORMATION) +
-    TdiAddressSize);
+		sizeof(TDI_CONNECTION_INFORMATION) +
+		TdiAddressSize);
 
   ConnInfo->OptionsLength = sizeof(ULONG);
   ConnInfo->RemoteAddressLength = 0;
@@ -235,8 +107,8 @@
 
   ConnInfo = (PTDI_CONNECTION_INFORMATION)
     ExAllocatePool(NonPagedPool,
-    sizeof(TDI_CONNECTION_INFORMATION) +
-    TdiAddressSize);
+		   sizeof(TDI_CONNECTION_INFORMATION) +
+		   TdiAddressSize);
   if (!ConnInfo)
     return STATUS_INSUFFICIENT_RESOURCES;
 
@@ -247,13 +119,44 @@
   else
       *ConnectionInfo = ConnInfo;
 
+  ConnInfo->RemoteAddress = (PTA_ADDRESS)&ConnInfo[1];
+  ConnInfo->RemoteAddressLength = TdiAddressSize;
+
+  return Status;
+}
+
+
+NTSTATUS
+TdiBuildConnectionInfoInPlace
+( PTDI_CONNECTION_INFORMATION ConnectionInfo,
+  PTA_ADDRESS Address ) {
+    NTSTATUS Status = STATUS_SUCCESS;
+    
+    RtlCopyMemory( ConnectionInfo->RemoteAddress,
+		   Address, 
+		   ConnectionInfo->RemoteAddressLength );
+    
+    return Status;
+}
+
+
+NTSTATUS
+TdiBuildConnectionInfo
+( PTDI_CONNECTION_INFORMATION *ConnectionInfo,
+  PTA_ADDRESS Address ) {
+  NTSTATUS Status = TdiBuildNullConnectionInfo( ConnectionInfo,
+						Address->AddressType );
+  
+  if( NT_SUCCESS(Status) )
+    TdiBuildConnectionInfoInPlace( *ConnectionInfo, Address );
+  
   return Status;
 }
 
 NTSTATUS 
 TdiBuildConnectionInfoPair
 ( PTDI_CONNECTION_INFO_PAIR ConnectionInfo,
-  LPSOCKADDR From, LPSOCKADDR To ) 
+  PTA_ADDRESS From, PTA_ADDRESS To ) 
     /*
      * FUNCTION: Fill a TDI_CONNECTION_INFO_PAIR struct will the two addresses
      *           given.
@@ -266,11 +169,11 @@
      */
 {
     PCHAR LayoutFrame;
-    DWORD SizeOfEntry;
+    UINT SizeOfEntry;
     ULONG TdiAddressSize;
 
     /* FIXME: Get from socket information */
-    TdiAddressSize = TdiAddressSizeFromName(From);
+    TdiAddressSize = TdiAddressSizeFromType(From->AddressType);
     SizeOfEntry = TdiAddressSize + sizeof(TDI_CONNECTION_INFORMATION);
 
     LayoutFrame = (PCHAR)ExAllocatePool(NonPagedPool, 2 * SizeOfEntry);
@@ -282,18 +185,20 @@
 
     RtlZeroMemory( LayoutFrame, 2 * SizeOfEntry );
 
-    PTDI_CONNECTION_INFORMATION 
+    { 
+      PTDI_CONNECTION_INFORMATION 
 	FromTdiConn = (PTDI_CONNECTION_INFORMATION)LayoutFrame, 
 	ToTdiConn = (PTDI_CONNECTION_INFORMATION)LayoutFrame + SizeOfEntry;
-
-    if (From != NULL) {
+      
+      if (From != NULL) {
 	TdiBuildConnectionInfoInPlace( FromTdiConn, From );
-    } else {
+      } else {
 	TdiBuildNullConnectionInfoInPlace( FromTdiConn, 
-					   From->sa_family );
-    }
+					   From->AddressType );
+      }
 
-    TdiBuildConnectionInfoInPlace( ToTdiConn, To );
+      TdiBuildConnectionInfoInPlace( ToTdiConn, To );
+    }
 
     return STATUS_SUCCESS;
 }

reactos/drivers/net/afd/afd
afd.c removed after 1.14
diff -N afd.c
--- afd.c	15 Jun 2004 02:56:13 -0000	1.14
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,219 +0,0 @@
-/*
- * COPYRIGHT:   See COPYING in the top level directory
- * PROJECT:     ReactOS Ancillary Function Driver
- * FILE:        afd/afd.c
- * PURPOSE:     MSAFD kernel mode module
- * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
- * REVISIONS:
- *   CSH 01/09-2000 Created
- */
-#include <afd.h>
-#include <rosrtl/string.h>
-
-#ifdef DBG
-
-/* See debug.h for debug/trace constants */
-//DWORD DebugTraceLevel = MID_TRACE;
-DWORD DebugTraceLevel = DEBUG_ULTRA;
-
-#endif /* DBG */
-
-
-NPAGED_LOOKASIDE_LIST BufferLookasideList;
-NPAGED_LOOKASIDE_LIST ReadRequestLookasideList;
-NPAGED_LOOKASIDE_LIST ListenRequestLookasideList;
-
-
-NTSTATUS
-STDCALL
-AfdFileSystemControl(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-{
-    UNIMPLEMENTED
-
-    Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
-    Irp->IoStatus.Information = 0;
-    return STATUS_UNSUCCESSFUL;
-}
-
-
-NTSTATUS
-STDCALL
-AfdDispatch(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-/*
- * FUNCTION: IOCTL dispatch routine
- * ARGUMENTS:
- *     DeviceObject = Pointer to a device object for this driver
- *     Irp          = Pointer to a I/O request packet
- * RETURNS:
- *     Status of the operation
- */
-{
-    NTSTATUS Status;
-    PIO_STACK_LOCATION IrpSp;
-    BOOL DoComplete = TRUE;
-
-    IrpSp = IoGetCurrentIrpStackLocation(Irp);
-
-    AFD_DbgPrint(MAX_TRACE, ("Called. DeviceObject is at (0x%X), IRP is at (0x%X), IrpSp->FileObject (0x%X).\n",
-        DeviceObject, Irp, IrpSp->FileObject));
-
-    Irp->IoStatus.Information = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-    switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
-    case IOCTL_AFD_BIND:
-        Status = AfdDispBind(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_LISTEN:
-        Status = AfdDispListen(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_SENDTO:
-        Status = AfdDispSendTo(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_RECVFROM:
-        Status = AfdDispRecvFrom(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_SELECT:
-        Status = AfdDispSelect(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_EVENTSELECT:
-        Status = AfdDispEventSelect(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_ENUMNETWORKEVENTS:
-        Status = AfdDispEnumNetworkEvents(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_RECV:
-        Status = AfdDispRecv(Irp, IrpSp);
-	DoComplete = FALSE;
-        break;
-
-    case IOCTL_AFD_SEND:
-        Status = AfdDispSend(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_CONNECT:
-        Status = AfdDispConnect(Irp, IrpSp);
-        break;
-
-    case IOCTL_AFD_GETNAME:
-        Status = AfdDispGetName(Irp, IrpSp);
-        break;
-
-    default:
-        Irp->IoStatus.Information = 0;
-        AFD_DbgPrint(MIN_TRACE, ("Unknown IOCTL (0x%X).\n",
-            IrpSp->Parameters.DeviceIoControl.IoControlCode));
-        Status = STATUS_NOT_IMPLEMENTED;
-        break;
-    }
-
-    if (Status != STATUS_PENDING && DoComplete) {
-        Irp->IoStatus.Status = Status;
-        IoCompleteRequest(Irp, IO_NETWORK_INCREMENT);
-    }
-
-    AFD_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
-
-    return Status;
-}
-
-
-VOID STDCALL AfdUnload(
-    PDRIVER_OBJECT DriverObject)
-/*
- * FUNCTION: Unloads the driver
- * ARGUMENTS:
- *     DriverObject = Pointer to driver object created by the system
- */
-{
-}
-
-
-NTSTATUS
-STDCALL
-DriverEntry(
-    PDRIVER_OBJECT DriverObject,
-	PUNICODE_STRING RegistryPath)
-/*
- * FUNCTION: Called by the system to initialize the driver
- * ARGUMENTS:
- *     DriverObject = object describing this driver
- *     RegistryPath = path to our configuration entries
- * RETURNS:
- *     Status of operation
- */
-{
-    PDEVICE_EXTENSION DeviceExt;
-    PDEVICE_OBJECT DeviceObject;
-    UNICODE_STRING DeviceName = ROS_STRING_INITIALIZER(L"\\Device\\Afd");
-    NTSTATUS Status;
-
-    Status = IoCreateDevice(DriverObject,
-                            sizeof(DEVICE_EXTENSION),
-                            &DeviceName,
-                            FILE_DEVICE_NAMED_PIPE,
-                            0,
-                            FALSE,
-                            &DeviceObject);
-    if (!NT_SUCCESS(Status)) {
-      AFD_DbgPrint(MIN_TRACE, ("Could not create device (0x%X).\n", Status));
-	    return Status;
-    }
-
-    DeviceObject->Flags |= DO_DIRECT_IO;
-
-    DeviceExt = DeviceObject->DeviceExtension;
-    KeInitializeSpinLock(&DeviceExt->FCBListLock);
-    InitializeListHead(&DeviceExt->FCBListHead);
-
-    DriverObject->MajorFunction[IRP_MJ_CREATE] = AfdCreate;
-    DriverObject->MajorFunction[IRP_MJ_CLOSE] = AfdClose;
-    DriverObject->MajorFunction[IRP_MJ_READ] = AfdRead;
-    DriverObject->MajorFunction[IRP_MJ_WRITE] = AfdWrite;
-    DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = AfdFileSystemControl;
-    DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AfdDispatch;
-    DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AfdClose;
-
-    DriverObject->DriverUnload = AfdUnload;
-
-/*    ExInitializeNPagedLookasideList(
-      &BufferLookasideList,
-      NULL,
-      NULL,
-      0,
-      sizeof(AFD_BUFFER),
-      TAG('A', 'F', 'D', 'B'),
-      0);*/
-
-/*    ExInitializeNPagedLookasideList(
-      &ReadRequestLookasideList,
-      NULL,
-      NULL,
-      0,
-      sizeof(AFD_READ_REQUEST),
-      TAG('A', 'F', 'D', 'R'),
-      0);*/
-
-	ExInitializeNPagedLookasideList(
-      &ListenRequestLookasideList,
-      NULL,
-      NULL,
-      0,
-      sizeof(AFD_LISTEN_REQUEST),
-      TAG('A', 'F', 'D', 'L'),
-      0);
-
-    return STATUS_SUCCESS;
-}
-
-/* EOF */

reactos/drivers/net/afd/afd
dispatch.c removed after 1.15
diff -N dispatch.c
--- dispatch.c	3 Jul 2004 17:40:20 -0000	1.15
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,1046 +0,0 @@
-/*
- * COPYRIGHT:   See COPYING in the top level directory
- * PROJECT:     ReactOS Ancillary Function Driver
- * FILE:        afd/dispatch.c
- * PURPOSE:     File object dispatch functions
- * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
- * REVISIONS:
- *   CSH 01/09-2000 Created
- */
-#include <afd.h>
-
-NTSTATUS AfdpDispRecv(
-    PIRP Irp,
-    PAFDFCB FCB,
-    PFILE_REQUEST_RECVFROM Request,
-    PFILE_REPLY_RECVFROM Reply,
-    BOOL Continuous)
-/*
- * FUNCTION: Receives data
- * ARGUMENTS:
- *     Irp     = Pointer to I/O request packet
- *     FCB     = Pointer to file control block
- *     Request = Address of request buffer
- *     Reply   = Address of reply buffer (same as request buffer)
- * RETURNS:
- *     Status of operation
- */
-{
-  PAFD_READ_REQUEST ReadRequest;
-  NTSTATUS Status;
-  KIRQL OldIrql;
-  PMDL Mdl;
-  UINT i;
-
-  KeAcquireSpinLock(&FCB->ReceiveQueueLock, &OldIrql);
-  /* Queue a read request and return STATUS_PENDING */
-  
-  AFD_DbgPrint(MAX_TRACE, ("Queueing read request.\n"));
-  
-  /*ReadRequest = (PAFD_READ_REQUEST)ExAllocateFromNPagedLookasideList(
-    &ReadRequestLookasideList);*/
-  ReadRequest = (PAFD_READ_REQUEST)ExAllocatePool(
-      NonPagedPool,
-      sizeof(AFD_READ_REQUEST));
-  if (ReadRequest) {
-      ReadRequest->Irp = Irp;
-      ReadRequest->RecvFromRequest = Request;
-      ReadRequest->RecvFromReply = Reply;
-      AFD_DbgPrint(MAX_TRACE,("Reply to %x (%x)\n", Reply, 
-			      ReadRequest->RecvFromReply));
-      
-      for( i = 0; 
-	   i < ReadRequest->RecvFromRequest->BufferCount; 
-	   i++ ) {
-	  /* These will be cleaned up in routines.c:FillWSABuffers */
-	  Mdl = IoAllocateMdl( ReadRequest->RecvFromRequest->Buffers[i].buf,
-			       ReadRequest->RecvFromRequest->Buffers[i].len,
-			       FALSE,
-			       FALSE,
-			       Irp );
-	  MmProbeAndLockPages( Mdl, KernelMode, IoWriteAccess );
-	  ReadRequest->RecvFromRequest->Buffers[i].buf = (PCHAR)Mdl;
-      }
-
-      InsertTailList( &FCB->ReadRequestQueue, &ReadRequest->ListEntry );
-
-      Status = STATUS_PENDING;
-  } else {
-      Status = STATUS_INSUFFICIENT_RESOURCES;
-  }
-
-  TryToSatisfyRecvRequest( FCB, Continuous );
-
-  if (IsListEmpty(&FCB->ReadRequestQueue)) /* All recv requests handled */
-      Status = STATUS_SUCCESS;
-  else
-      IoMarkIrpPending( Irp );
-  
-  KeReleaseSpinLock(&FCB->ReceiveQueueLock, OldIrql);
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispBind(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Binds to an address
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_BIND Request;
-  PFILE_REPLY_BIND Reply;
-  PAFDFCB FCB;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_BIND)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_BIND))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_BIND)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_BIND)Irp->AssociatedIrp.SystemBuffer;
-
-    Status = TdiOpenAddressFile(
-      &FCB->TdiDeviceName,
-      &Request->Name,
-      &FCB->TdiAddressObjectHandle,
-      &FCB->TdiAddressObject);
-
-    if (NT_SUCCESS(Status)) {
-      AfdRegisterEventHandlers(FCB);
-      FCB->State = SOCKET_STATE_BOUND;
-      Reply->Status = NO_ERROR;
-    } else {
-      //FIXME: WSAEADDRNOTAVAIL
-      Reply->Status = WSAEINVAL;
-    }
-  } else
-      Status = STATUS_INVALID_PARAMETER;
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS
-STDCALL
-AfdDispCompleteListen(
-  PDEVICE_OBJECT DeviceObject,
-  PIRP Irp,
-  PVOID Context)
-{
-  PAFD_LISTEN_REQUEST ListenRequest = (PAFD_LISTEN_REQUEST) Context;
-
-  /* FIXME: Protect ListenRequest->Fcb->ListenRequestQueue */
-  RemoveEntryList(&ListenRequest->ListEntry);
-
-  AFD_DbgPrint(MAX_TRACE, ("Completed ListenRequest at (0x%X).\n", ListenRequest));
-
-  if (NT_SUCCESS(ListenRequest->Iosb.Status))
-    {
-	  if (ListenRequest->Fcb->EventObject != NULL)
-	    {
-          /* FIXME: Protect ListenRequest->Fcb */
-          ListenRequest->Fcb->NetworkEvents.lNetworkEvents |= FD_ACCEPT;
-          ListenRequest->Fcb->NetworkEvents.iErrorCode[FD_ACCEPT_BIT] = NO_ERROR;
-	      KeSetEvent(ListenRequest->Fcb->EventObject, EVENT_INCREMENT, FALSE);
-	    }
-    }
-
-  ExFreePool(ListenRequest->RequestConnectionInfo);
-  ListenRequest->RequestConnectionInfo = NULL;
-  ExFreePool(ListenRequest);
-
-  return STATUS_SUCCESS;
-}
-
-
-NTSTATUS AfdDispListen(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Starts listening for connections
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_LISTEN Request;
-  PFILE_REPLY_LISTEN Reply;
-  PAFDFCB FCB;
-  PAFD_LISTEN_REQUEST ListenRequest;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  Status = STATUS_INVALID_PARAMETER;
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_LISTEN)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_LISTEN))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_LISTEN)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_LISTEN)Irp->AssociatedIrp.SystemBuffer;
-
-    if (FCB->State == SOCKET_STATE_BOUND)
-      {
-        /* We have a bound socket so go ahead and create a connection endpoint
-           and associate it with the address file object */
-
-        Status = TdiOpenConnectionEndpointFile(
-          &FCB->TdiDeviceName,
-          &FCB->TdiConnectionObjectHandle,
-          &FCB->TdiConnectionObject);
-
-        if (NT_SUCCESS(Status))
-          {
-            Status = TdiAssociateAddressFile(
-              FCB->TdiAddressObjectHandle,
-              FCB->TdiConnectionObject);
-
-            if (NT_SUCCESS(Status))
-              {
-                ListenRequest = ExAllocateFromNPagedLookasideList(&ListenRequestLookasideList);
-                if (ListenRequest != NULL)
-                  {
-                    ListenRequest->Fcb = FCB;
-                    /* FIXME: Protect ListenRequestQueue */
-                    InsertTailList(&FCB->ListenRequestQueue, &ListenRequest->ListEntry);
-
-                    Status = TdiListen(ListenRequest, AfdDispCompleteListen, ListenRequest);
-                    if ((Status == STATUS_PENDING) || NT_SUCCESS(Status))
-                      {
-                        if (Status != STATUS_PENDING)
-                          {
-                            AFD_DbgPrint(MIN_TRACE, ("FIXME: Status (0x%X).\n", Status));
-                          }
-                        Status = STATUS_SUCCESS;
-                      }
-		                else
-		                  {
-                        /* FIXME: Cleanup ListenRequest */
-                        /* FIXME: Cleanup from TdiOpenConnectionEndpointFile */
-		                  }
-                  }
-		            else
-		              {
-                    /* FIXME: Cleanup from TdiOpenConnectionEndpointFile */
-                    Status = STATUS_NO_MEMORY;
-		              }
-              }
-		        else
-		          {
-                /* FIXME: Cleanup from TdiOpenConnectionEndpointFile */
-		          }
-          }
-
-        if (NT_SUCCESS(Status)) {
-          Reply->Status = NO_ERROR;
-        } else {
-          Reply->Status = WSAEINVAL;
-        }
-      }
-    else if (FCB->State == SOCKET_STATE_CONNECTED)
-      {
-        Reply->Status = WSAEISCONN;
-      }
-    else
-      {
-        Reply->Status = WSAEINVAL;
-      }
-  }
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispSendTo(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Sends data to an address
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_SENDTO Request;
-  PFILE_REPLY_SENDTO Reply;
-  PAFDFCB FCB;
-  PVOID SystemVirtualAddress;
-  PVOID DataBufferAddress;
-  ULONG BufferSize;
-  ULONG BytesCopied;
-  PMDL Mdl;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_SENDTO)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_SENDTO))) {
-
-    AFD_DbgPrint(MAX_TRACE, ("FileObject at (0x%X).\n", IrpSp->FileObject));
-    AFD_DbgPrint(MAX_TRACE, ("FCB at (0x%X).\n", IrpSp->FileObject->FsContext));
-    AFD_DbgPrint(MAX_TRACE, ("CCB at (0x%X).\n", IrpSp->FileObject->FsContext2));
-
-    FCB = IrpSp->FileObject->FsContext;
-    Request = (PFILE_REQUEST_SENDTO)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_SENDTO)Irp->AssociatedIrp.SystemBuffer;
-
-    /* Since we're using bufferred I/O */
-    Request->Buffers = (LPWSABUF)(Request + 1);
-    BufferSize = WSABufferSize(Request->Buffers, Request->BufferCount);
-
-
-    /* FIXME: Should we handle special cases here? */
-    if ((FCB->SocketType == SOCK_RAW) && (FCB->AddressFamily == AF_INET)) {
-      BufferSize += sizeof(IPv4_HEADER);
-    }
-
-
-    if (BufferSize != 0) {
-      AFD_DbgPrint(MAX_TRACE, ("Allocating %d bytes for send buffer.\n", BufferSize));
-      SystemVirtualAddress = ExAllocatePool(NonPagedPool, BufferSize);
-      if (!SystemVirtualAddress) {
-          return STATUS_INSUFFICIENT_RESOURCES;
-      }
-
-      /* FIXME: Should we handle special cases here? */
-      if ((FCB->SocketType == SOCK_RAW) && (FCB->AddressFamily == AF_INET)) {
-        DataBufferAddress = ((PCHAR)SystemVirtualAddress) + sizeof(IPv4_HEADER);
-
-        /* FIXME: Should TCP/IP driver assign source address for raw sockets? */
-        ((PSOCKADDR_IN)&FCB->SocketName)->sin_addr.S_un.S_addr = 0x0100007F;
-
-        BuildIPv4Header(
-            (PIPv4_HEADER)SystemVirtualAddress,
-            BufferSize,
-            FCB->Protocol,
-            &FCB->SocketName,
-            &Request->To);
-      } else {
-        DataBufferAddress = SystemVirtualAddress;
-      }
-
-      Status = MergeWSABuffers(
-        Request->Buffers,
-        Request->BufferCount,
-        DataBufferAddress,
-        BufferSize,
-        &BytesCopied);
-      if (!NT_SUCCESS(Status)) {
-        AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-        return Status;
-      }
-    } else {
-      SystemVirtualAddress = NULL;
-      BytesCopied = 0;
-    }
-
-    Mdl = IoAllocateMdl(
-      SystemVirtualAddress,   /* Virtual address of buffer */
-      BufferSize,             /* Length of buffer */
-      FALSE,                  /* Not secondary */
-      FALSE,                  /* Don't charge quota */
-      NULL);                  /* Don't use IRP */
-    if (!Mdl) {
-      ExFreePool(SystemVirtualAddress);
-      return STATUS_INSUFFICIENT_RESOURCES;
-    }
-
-    MmBuildMdlForNonPagedPool(Mdl);
-
-    AFD_DbgPrint(MAX_TRACE, ("System virtual address is (0x%X).\n", SystemVirtualAddress));
-    AFD_DbgPrint(MAX_TRACE, ("MDL for data buffer is at (0x%X).\n", Mdl));
-
-    AFD_DbgPrint(MAX_TRACE, ("AFD.SYS: NDIS data buffer is at (0x%X).\n", Mdl));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer MdlFlags is (0x%X).\n", Mdl->MdlFlags));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer Next is at (0x%X).\n", Mdl->Next));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer Size is (0x%X).\n", Mdl->Size));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer MappedSystemVa is (0x%X).\n", Mdl->MappedSystemVa));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer StartVa is (0x%X).\n", Mdl->StartVa));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer ByteCount is (0x%X).\n", Mdl->ByteCount));
-    AFD_DbgPrint(MAX_TRACE, ("NDIS data buffer ByteOffset is (0x%X).\n", Mdl->ByteOffset));
-
-#if 0
-#ifdef _MSC_VER
-    try {
-#endif
-	MmProbeAndLockPages(Mdl, KernelMode, IoModifyAccess);
-#ifdef _MSC_VER
-    } except(EXCEPTION_EXECUTE_HANDLER) {
-	AFD_DbgPrint(MIN_TRACE, ("MmProbeAndLockPages() failed.\n"));
-	IoFreeMdl(Mdl);
-	if (BufferSize != 0) {
-	    ExFreePool(SystemVirtualAddress);
-	}
-	return STATUS_UNSUCCESSFUL;
-    }
-#endif
-#endif
-    
-    if (!FCB->TdiAddressObject) {
-	struct sockaddr_in BindName;
-
-	RtlZeroMemory(&BindName,sizeof(BindName));
-	BindName.sin_family = AF_INET;
-
-	Status = TdiOpenAddressFile
-	    (&FCB->TdiDeviceName,
-	     (SOCKADDR *)&BindName,
-	     &FCB->TdiAddressObjectHandle,
-	     &FCB->TdiAddressObject);
-
-	if (NT_SUCCESS(Status)) {
-	    AfdRegisterEventHandlers(FCB);
-	    FCB->State = SOCKET_STATE_BOUND;
-	    Reply->Status = NO_ERROR;
-	} else {
-	    //FIXME: WSAEADDRNOTAVAIL
-	    Reply->Status = WSAEINVAL;
-	    MmUnlockPages(Mdl);
-	    IoFreeMdl(Mdl);
-	    return Status;
-	}
-    }
-    
-    Status = TdiSendDatagram(FCB->TdiAddressObject,
-        &Request->To,
-        Mdl,
-        BufferSize);
-
-    /* FIXME: Assumes synchronous operation */
-#if 0
-    MmUnlockPages(Mdl);
-#endif
-
-    IoFreeMdl(Mdl);
-
-    if (BufferSize != 0) {
-        ExFreePool(SystemVirtualAddress);
-    }
-
-    Reply->NumberOfBytesSent = BufferSize;
-    Reply->Status = NO_ERROR;
-  } else
-    Status = STATUS_INVALID_PARAMETER;
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispRecvFrom(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Receives data from an address
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_RECVFROM Request;
-  PFILE_REPLY_RECVFROM Reply;
-  PAFDFCB FCB;
-
-  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_RECVFROM)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_RECVFROM))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_RECVFROM)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_RECVFROM)Irp->AssociatedIrp.SystemBuffer;
-    /* Since we're using bufferred I/O */
-    Request->Buffers = (LPWSABUF)(Request + 1);
-
-    Status = AfdpDispRecv(
-      Irp,
-      FCB,
-      Request,
-      Reply,
-      FALSE);
-  } else {
-    Status = STATUS_INVALID_PARAMETER;
-  }
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-typedef enum {
-  soRead,
-  soWrite,
-  soExcept
-} SelectOperation;
-
-
-DWORD AfdpDispSelectEx(
-    LPFD_SET FDSet,
-    SelectOperation Operation)
-{
-  PFILE_OBJECT FileObject;
-  NTSTATUS Status;
-  PAFDFCB Current;
-  KIRQL OldIrql;
-  DWORD Count;
-  ULONG i;
-
-  AFD_DbgPrint(MAX_TRACE, ("FDSet (0x%X)  Operation (0x%X).\n",
-    FDSet, Operation));
-
-  AFD_DbgPrint(MAX_TRACE, ("FDSet->fd_count (0x%X).\n", FDSet->fd_count));
-
-  Count = 0;
-  for (i = 0; i < FDSet->fd_count; i++) {
-
-    AFD_DbgPrint(MAX_TRACE, ("Handle (0x%X).\n", FDSet->fd_array[i]));
-
-    Status = ObReferenceObjectByHandle(
-      (HANDLE)FDSet->fd_array[i],
-      0,
-      IoFileObjectType,
-      KernelMode,
-      (PVOID*)&FileObject,
-      NULL);
-    if (NT_SUCCESS(Status)) {
-      AFD_DbgPrint(MAX_TRACE, ("File object is at (0x%X).\n", FileObject));
-
-      Current = FileObject->FsContext;
-
-      switch (Operation) {
-      case soRead:
-        KeAcquireSpinLock(&Current->ReceiveQueueLock, &OldIrql);
-        if (!IsListEmpty(&Current->ReceiveQueue)) {
-          AFD_DbgPrint(MAX_TRACE, ("Socket is readable.\n"));
-          Count++;
-        }
-        KeReleaseSpinLock(&Current->ReceiveQueueLock, OldIrql);
-        break;
-      case soWrite:
-        /* FIXME: How can we check for writability? */
-        Count++;
-        break;
-      case soExcept:
-        /* FIXME: What is this? */
-        Count++;
-        break;
-      }
-
-      ObDereferenceObject(FileObject);
-    }
-  }
-
-  return Count;
-}
-
-NTSTATUS AfdDispSelect(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Checks if sockets have data in the receive buffers
- *           and/or if client can send data
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_SELECT Request;
-  PFILE_REPLY_SELECT Reply;
-  DWORD SocketCount;
-  PAFDFCB FCB;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_SELECT)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_SELECT))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_SELECT)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_SELECT)Irp->AssociatedIrp.SystemBuffer;
-
-    AFD_DbgPrint(MAX_TRACE, ("R (0x%X)  W (0x%X).\n",
-      Request->ReadFDSet, Request->WriteFDSet));
-
-    SocketCount = 0;
-
-    if (Request->WriteFDSet) {
-      AFD_DbgPrint(MAX_TRACE, ("Write.\n"));
-      SocketCount += AfdpDispSelectEx(Request->WriteFDSet, soWrite);
-    }
-    if (Request->ReadFDSet) {
-      AFD_DbgPrint(MAX_TRACE, ("Read.\n"));
-      SocketCount += AfdpDispSelectEx(Request->ReadFDSet, soRead);
-    }
-    if (Request->ExceptFDSet) {
-      SocketCount += AfdpDispSelectEx(Request->ExceptFDSet, soExcept);
-    }
-
-    AFD_DbgPrint(MAX_TRACE, ("Sockets selected (0x%X).\n", SocketCount));
-
-    Reply->Status = NO_ERROR;
-    Reply->SocketCount = SocketCount;
-    Status = STATUS_SUCCESS;
-  } else
-    Status = STATUS_INVALID_PARAMETER;
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-NTSTATUS AfdDispEventSelect(
-  PIRP Irp,
-  PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Associate an event object with one or more network events
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_EVENTSELECT Request;
-  PFILE_REPLY_EVENTSELECT Reply;
-  PKEVENT Event;
-  PAFDFCB FCB;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_EVENTSELECT)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_EVENTSELECT))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_EVENTSELECT)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_EVENTSELECT)Irp->AssociatedIrp.SystemBuffer;
-
-	/* FIXME: Need to ObDereferenceObject(FCB->EventObject) this somewhere */
-	Status = ObReferenceObjectByHandle(
-      Request->hEventObject,
-      0,
-      ExEventObjectType,
-      UserMode,
-      (PVOID*)&Event,
-      NULL);
-    if (NT_SUCCESS(Status)) {
-      FCB->NetworkEvents.lNetworkEvents = Request->lNetworkEvents;
-	  FCB->EventObject = Event;
-      Reply->Status = NO_ERROR;
-      Status = STATUS_SUCCESS;
-	}
-	else
-	{
-	  AFD_DbgPrint(MID_TRACE, ("Bad event handle (0x%X).\n", Status));
-
-	  Reply->Status = WSAEINVAL;
-      Status = STATUS_SUCCESS;
-    }
-  }
-  else
-  {
-    Status = STATUS_INVALID_PARAMETER;
-  }
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-NTSTATUS AfdDispEnumNetworkEvents(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Reports network events
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_ENUMNETWORKEVENTS Request;
-  PFILE_REPLY_ENUMNETWORKEVENTS Reply;
-  HANDLE EventObject;
-  PAFDFCB FCB;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_ENUMNETWORKEVENTS)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_ENUMNETWORKEVENTS))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_ENUMNETWORKEVENTS)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_ENUMNETWORKEVENTS)Irp->AssociatedIrp.SystemBuffer;
-
-    EventObject = (HANDLE)Request->hEventObject;
-
-    RtlCopyMemory(
-      &Reply->NetworkEvents,
-      &FCB->NetworkEvents,
-      sizeof(WSANETWORKEVENTS));
-
-    RtlZeroMemory(
-      &FCB->NetworkEvents,
-      sizeof(WSANETWORKEVENTS));
-
-    if (EventObject != NULL) {
-      ZwClearEvent(EventObject);
-    }
-
-    Reply->Status = NO_ERROR;
-    Status = STATUS_SUCCESS;
-  } else
-    Status = STATUS_INVALID_PARAMETER;
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispRecv(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Receives data from an address
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_RECVFROM Request;
-  PFILE_REPLY_RECVFROM Reply;
-  PAFDFCB FCB;
-
-  AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_RECV)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_RECV))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_RECVFROM)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_RECVFROM)Irp->AssociatedIrp.SystemBuffer;
-
-    Status = AfdpDispRecv(
-      Irp,
-      FCB,
-      Request,
-      Reply,
-      TRUE);
-    Reply->NumberOfBytesRecvd = 0; /* FIXME */
-    Reply->Status = NO_ERROR;
-  } else {
-    Status = STATUS_INVALID_PARAMETER;
-  }
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispSend(
-    PIRP Irp,
-    PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Sends data
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status = STATUS_SUCCESS;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_SEND Request;
-  PFILE_REPLY_SEND Reply;
-  PAFDFCB FCB;
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_SEND)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_SEND))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_SEND)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_SEND)Irp->AssociatedIrp.SystemBuffer;
-
-    Reply->NumberOfBytesSent = 0;
-    Reply->Status = NO_ERROR;
-  } else
-    Status = STATUS_INVALID_PARAMETER;
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispConnect(
-  PIRP Irp,
-  PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Connect to a remote peer
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_CONNECT Request;
-  PFILE_REPLY_CONNECT Reply;
-  PAFDFCB FCB;
-  SOCKADDR_IN LocalAddress;
-
-  AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  Status = STATUS_INVALID_PARAMETER;
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_CONNECT)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_CONNECT))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_CONNECT)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_CONNECT)Irp->AssociatedIrp.SystemBuffer;
-
-    AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-    if (FCB->State == SOCKET_STATE_BOUND) {
-      Reply->Status = WSAEADDRINUSE;
-    } else if (FCB->State == SOCKET_STATE_CONNECTED) {
-      Reply->Status = WSAEISCONN;
-    } else {
-      /* We have an unbound socket so go ahead and create an address
-         file object and a connection endpoint and associate the two */
-
-      AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-      /* FIXME: Get from client */
-      LocalAddress.sin_family = AF_INET;
-      LocalAddress.sin_port = 1700;
-      LocalAddress.sin_addr.S_un.S_addr = 0x0; /* Dynamically allocate */
-
-      Status = TdiOpenAddressFile(
-        &FCB->TdiDeviceName,
-        (LPSOCKADDR)&LocalAddress,
-        &FCB->TdiAddressObjectHandle,
-        &FCB->TdiAddressObject);
-
-      if (NT_SUCCESS(Status)) {
-        AfdRegisterEventHandlers(FCB);
-        FCB->State = SOCKET_STATE_BOUND;
-      }
-
-      AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-      if (NT_SUCCESS(Status)) {
-        Status = TdiOpenConnectionEndpointFile(
-          &FCB->TdiDeviceName,
-          &FCB->TdiConnectionObjectHandle,
-          &FCB->TdiConnectionObject);
-      }
-
-      AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-      if (NT_SUCCESS(Status)) {
-        Status = TdiAssociateAddressFile(
-          FCB->TdiAddressObjectHandle,
-          FCB->TdiConnectionObject);
-      }
-
-      AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-      if (NT_SUCCESS(Status)) {
-        /* Now attempt to connect to the remote peer */
-        Status = TdiConnect(
-          FCB->TdiConnectionObject,
-          Request->name);
-      }
-
-      AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-      if (NT_SUCCESS(Status)) {
-        FCB->State = SOCKET_STATE_CONNECTED;
-        Reply->Status = NO_ERROR;
-      } else {
-        Reply->Status = WSAEINVAL;
-      }
-    }
-  }
-
-  AFD_DbgPrint(MAX_TRACE, ("Status (0x%X).\n", Status));
-
-  return Status;
-}
-
-
-NTSTATUS AfdDispGetName(
-  PIRP Irp,
-  PIO_STACK_LOCATION IrpSp)
-/*
- * FUNCTION: Get socket name
- * ARGUMENTS:
- *     Irp   = Pointer to I/O request packet
- *     IrpSp = Pointer to current stack location of Irp
- * RETURNS:
- *     Status of operation
- */
-{
-  NTSTATUS Status;
-  UINT InputBufferLength;
-  UINT OutputBufferLength;
-  PFILE_REQUEST_GETNAME Request;
-  PFILE_REPLY_GETNAME Reply;
-  PAFDFCB FCB;
-  PFILE_OBJECT FileObject;
-  PMDL Mdl;
-  PTDI_ADDRESS_INFO AddressInfoBuffer;
-  ULONG AddressInfoSize;
-
-  AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-  InputBufferLength  = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
-  OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
-
-  /* Validate parameters */
-  Status = STATUS_INVALID_PARAMETER;
-  if ((InputBufferLength >= sizeof(FILE_REQUEST_GETNAME)) &&
-    (OutputBufferLength >= sizeof(FILE_REPLY_GETNAME))) {
-    FCB = IrpSp->FileObject->FsContext;
-
-    Request = (PFILE_REQUEST_GETNAME)Irp->AssociatedIrp.SystemBuffer;
-    Reply   = (PFILE_REPLY_GETNAME)Irp->AssociatedIrp.SystemBuffer;
-
-    AFD_DbgPrint(MIN_TRACE, ("\n"));
-
-    if (Request->Peer) {
-      if (FCB->State != SOCKET_STATE_CONNECTED) {
-        Reply->Status = WSAENOTCONN;
-        return STATUS_UNSUCCESSFUL;
[truncated at 1000 lines; 50 more skipped]

reactos/drivers/net/afd/afd
opnclose.c removed after 1.10
diff -N opnclose.c
--- opnclose.c	15 Jun 2004 02:56:13 -0000	1.10
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,285 +0,0 @@
-/*
- * COPYRIGHT:   See COPYING in the top level directory
- * PROJECT:     ReactOS Ancillary Function Driver
- * FILE:        afd/opnclose.c
- * PURPOSE:     File object creation and destruction
- * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
- * REVISIONS:
- *   CSH 01/09-2000 Created
- */
-#include <afd.h>
-
-PAFDFCB AfdInitializeFCB(
-    PDEVICE_EXTENSION   DeviceExt,
-    PFILE_OBJECT        FileObject  OPTIONAL)
-/*
- * FUNCTION: Allocates and initializes a File Control Block structure
- */
-{
-  PAFDFCB NewFCB;
-
-  NewFCB = ExAllocatePool(NonPagedPool, sizeof(AFDFCB));
-  if (!NewFCB)
-    return NULL;
-
-  RtlZeroMemory(NewFCB, sizeof(AFDFCB));
-
-	ExInitializeResourceLite(&NewFCB->NTRequiredFCB.MainResource);
-	ExInitializeResourceLite(&NewFCB->NTRequiredFCB.PagingIoResource);
-
-	NewFCB->DeviceExt       = DeviceExt;
-	NewFCB->ReferenceCount  = 1;
-	NewFCB->OpenHandleCount = 1;
-
-  NewFCB->TdiAddressObjectHandle    = INVALID_HANDLE_VALUE;
-  NewFCB->TdiConnectionObjectHandle = INVALID_HANDLE_VALUE;
-
-  InitializeListHead(&NewFCB->CCBListHead);
-
-  InsertTailList(&DeviceExt->FCBListHead, &NewFCB->ListEntry);
-
-  InitializeListHead(&NewFCB->ReceiveQueue);
-  KeInitializeSpinLock(&NewFCB->ReceiveQueueLock);
-
-  InitializeListHead(&NewFCB->ReadRequestQueue);
-
-  InitializeListHead(&NewFCB->ListenRequestQueue);
-
-	if (FileObject)
-		FileObject->FsContext = (PVOID)NewFCB;
-
-  AFD_DbgPrint(MAX_TRACE, ("FCB created for file object (0x%X) at (0x%X).\n", FileObject, NewFCB));
-
-  return NewFCB;
-}
-
-
-PAFDCCB AfdInitializeCCB(
-    PAFDFCB         FCB,
-    PFILE_OBJECT    FileObject)
-/*
- * FUNCTION: Allocates and initializes a Context Control Block structure
- */
-{
-    PAFDCCB NewCCB;
-
-    NewCCB = ExAllocatePool(NonPagedPool, sizeof(AFDCCB));
-    if (!NewCCB)
-        return NULL;
-
-    RtlZeroMemory(NewCCB, sizeof(AFDCCB));
-
-    NewCCB->FileObject = FileObject;
-
-    FileObject->FsContext2 = (PVOID)NewCCB;
-
-    InsertTailList(&FCB->CCBListHead, &NewCCB->ListEntry);
-
-    AFD_DbgPrint(MAX_TRACE, ("CCB created for file object (0x%X) at (0x%X).\n", FileObject, NewCCB));
-
-    return NewCCB;
-}
-
-
-NTSTATUS
-STDCALL
-AfdCreate(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-{
-    PAFD_SOCKET_INFORMATION SocketInfo;
-    PFILE_FULL_EA_INFORMATION EaInfo;
-    PDEVICE_EXTENSION DeviceExt;
-    NTSTATUS Status;
-    ULONG EaLength;
-    PAFDFCB FCB;
-    PAFDCCB CCB;
-    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
-    PFILE_OBJECT FileObject  = IrpSp->FileObject;
-
-    AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
-
-    assert(DeviceObject);
-
-    DeviceExt = DeviceObject->DeviceExtension;
-
-    EaInfo = Irp->AssociatedIrp.SystemBuffer;
-
-    /* Parameter check */
-    if (!EaInfo) {
-        AFD_DbgPrint(MIN_TRACE, ("No EA information in IRP.\n"));
-        return STATUS_INVALID_PARAMETER;
-    }
-
-    SocketInfo = (PAFD_SOCKET_INFORMATION)(EaInfo->EaName + EaInfo->EaNameLength);
-
-    EaLength = sizeof(FILE_FULL_EA_INFORMATION) +
-               EaInfo->EaNameLength +
-               EaInfo->EaValueLength;
-
-    if (EaLength < sizeof(FILE_FULL_EA_INFORMATION) +
-        AFD_SOCKET_LENGTH + sizeof(AFD_SOCKET_INFORMATION)) {
-        AFD_DbgPrint(MIN_TRACE, ("EA information has invalid length.\n"));
-        return STATUS_INVALID_PARAMETER;
-    }
-
-    AFD_DbgPrint(MAX_TRACE, ("EaInfo at (0x%X)  length is (%d).\n", EaInfo, EaLength));
-
-    /* FIXME: File/socket could already be open, do a search for it */
-
-    FCB = AfdInitializeFCB(DeviceExt, FileObject);
-
-    CCB = AfdInitializeCCB(FCB, FileObject);
-
-    if (CCB && FCB) {
-        FCB->CommandChannel = SocketInfo->CommandChannel;
-
-        if (!FCB->CommandChannel) {
-            FCB->AddressFamily      = SocketInfo->AddressFamily;
-            FCB->SocketType         = SocketInfo->SocketType;
-            FCB->Protocol           = SocketInfo->Protocol;
-            FCB->SocketName         = SocketInfo->Name;
-            FCB->HelperContext      = SocketInfo->HelperContext;
-            FCB->NotificationEvents = SocketInfo->NotificationEvents;
-
-            FCB->TdiDeviceName.Length = 0;
-            FCB->TdiDeviceName.MaximumLength = SocketInfo->TdiDeviceName.MaximumLength;
-            FCB->TdiDeviceName.Buffer = ExAllocatePool(
-                NonPagedPool, 
-                FCB->TdiDeviceName.MaximumLength);
-
-            if (FCB->TdiDeviceName.Buffer) {
-                RtlCopyUnicodeString(&FCB->TdiDeviceName, &SocketInfo->TdiDeviceName);
-
-                AFD_DbgPrint(MAX_TRACE, ("TDI device name is (%wZ).\n", &FCB->TdiDeviceName));
-
-                /* Open address file now for raw sockets */
-                if (FCB->SocketType == SOCK_RAW) {
-                    AFD_DbgPrint(MAX_TRACE, ("Opening raw socket.\n"));
-
-                    Status = TdiOpenAddressFile(
-                        &FCB->TdiDeviceName,
-                        &SocketInfo->Name,
-                        &FCB->TdiAddressObjectHandle,
-                        &FCB->TdiAddressObject);
-                    if (NT_SUCCESS(Status)) {
-                        Status = AfdRegisterEventHandlers(FCB);
-                        if (NT_SUCCESS(Status)) {
-                          FCB->State = SOCKET_STATE_BOUND;
-                        } else {
-                          AFD_DbgPrint(MAX_TRACE, ("AfdRegisterEventHandlers() failed (0x%X).\n", Status));
-                        }
-                    } else {
-                      AFD_DbgPrint(MAX_TRACE, ("TdiOpenAddressFile() failed (0x%X).\n", Status));
-                    }
-                } else
-                    Status = STATUS_SUCCESS;
-            } else
-                Status = STATUS_INSUFFICIENT_RESOURCES;
-        } else
-            Status = STATUS_SUCCESS;
-    } else
-        Status = STATUS_INSUFFICIENT_RESOURCES;
-
-    if (!NT_SUCCESS(Status)) {
-      /* FIXME: Cleanup */
-      AFD_DbgPrint(MAX_TRACE, ("FIXME: Cleanup.\n"));
-    }
-
-    Irp->IoStatus.Status = Status;
-    Irp->IoStatus.Information = 0;
-
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    AFD_DbgPrint(MAX_TRACE, ("Leaving. Status (0x%X).\n", Status));
-
-    return Status;
-}
-
-
-VOID
-AfdKillListenRequests(PAFDFCB FCB)
-{
-  /* FIXME: Implement */
-  AFD_DbgPrint(MIN_TRACE, ("Unimplemented.\n"));
-
-  /*ExFreeToNPagedLookasideList(&ListenRequestLookasideList,
-		(PVOID)ListenRequest);*/
-}
-
-
-NTSTATUS
-STDCALL
-AfdClose(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-{
-    PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
-    PFILE_OBJECT FileObject  = IrpSp->FileObject;
-    NTSTATUS Status;
-    PAFDFCB FCB;
-    PAFDCCB CCB;
-
-    AFD_DbgPrint(MAX_TRACE, ("Called.\n"));
-
-    assert(DeviceObject);
-    assert(FileObject);
-
-    FCB = FileObject->FsContext;
-    CCB = FileObject->FsContext2;
-
-    switch (IrpSp->MajorFunction) {
-    /* Close a file object */
-    case IRP_MJ_CLOSE:
-        FCB->ReferenceCount--;
-        if (FCB->ReferenceCount < 1) {
-            if (!FCB->CommandChannel) {
-                /* Kill outstanding listen requests */
-                AfdKillListenRequests(FCB);
-
-                /* Close TDI connection file object */
-                if (FCB->TdiConnectionObjectHandle != INVALID_HANDLE_VALUE) {
-                    TdiCloseDevice(FCB->TdiConnectionObjectHandle, FCB->TdiConnectionObject);
-                    FCB->TdiConnectionObjectHandle = INVALID_HANDLE_VALUE;
-                }
-
-                /* Close TDI address file object */
-                if (FCB->TdiAddressObjectHandle != INVALID_HANDLE_VALUE) {
-                    AfdDeregisterEventHandlers(FCB);
-                    TdiCloseDevice(FCB->TdiAddressObjectHandle, FCB->TdiAddressObject);
-                    FCB->TdiAddressObjectHandle = INVALID_HANDLE_VALUE;
-                }
-            }
-
-            ExFreePool(FCB);
-        }
-
-        Status = STATUS_SUCCESS;
-        break;
-
-    /* Release resources bound to a file object */
-    case IRP_MJ_CLEANUP:
-        FCB->OpenHandleCount--;
-        Status = STATUS_SUCCESS;
-
-        ExFreePool(CCB);
-
-        break;
-
-	default:
-        Status = STATUS_INVALID_DEVICE_REQUEST;
-    }
-
-//    ExFreePool(CCB);
-
-    Irp->IoStatus.Status = Status;
-    Irp->IoStatus.Information = 0;
-
-    AFD_DbgPrint(MAX_TRACE, ("Completing IRP at (0x%X).\n", Irp));
-
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    return Status;
-}
-
-/* EOF */

reactos/drivers/net/afd/afd
rdwr.c removed after 1.5
diff -N rdwr.c
--- rdwr.c	3 Jul 2004 17:40:20 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,118 +0,0 @@
-/*
- * COPYRIGHT:   See COPYING in the top level directory
- * PROJECT:     ReactOS Ancillary Function Driver
- * FILE:        afd/rdwr.c
- * PURPOSE:     File object read/write functions
- * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
- * REVISIONS:
- *   CSH 01/09-2000 Created
- */
-#include <afd.h>
-
-NTSTATUS AfdReadFile(
-    PDEVICE_EXTENSION DeviceExt,
-    PFILE_OBJECT FileObject,
-    PVOID Buffer,
-    ULONG Length,
-    ULONG Offset)
-/*
- * FUNCTION: Reads data from a file
- */
-{
-    UNIMPLEMENTED
-
-    return STATUS_UNSUCCESSFUL;
-}
-
-
-NTSTATUS
-STDCALL
-AfdRead(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-{
-#if 1
-    UNIMPLEMENTED
-
-    Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
-    Irp->IoStatus.Information = 0;
-    return STATUS_UNSUCCESSFUL;
-#else
-    PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension;
-    PIO_STACK_LOCATION IoSp = IoGetCurrentIrpStackLocation(Irp);
-    PFILE_OBJECT FileObject = IoSp->FileObject;
-    NTSTATUS Status;
-    ULONG Length;
-    PVOID Buffer;
-    ULONG Offset;
-
-    Length = IoSp->Parameters.Read.Length;
-    Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
-    Offset = IoSp->Parameters.Read.ByteOffset.u.LowPart;
-   
-    Status = AfdReadFile(DeviceExt, FileObject, Buffer, Length, Offset);
-   
-    Irp->IoStatus.Status = Status;
-    Irp->IoStatus.Information = Length;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-    return Status;
-#endif
-}
-
-
-NTSTATUS
-STDCALL
-AfdWrite(
-    PDEVICE_OBJECT DeviceObject,
-    PIRP Irp)
-{
-    PIO_STACK_LOCATION IoSp = IoGetCurrentIrpStackLocation(Irp);
-    PFILE_OBJECT FileObject = IoSp->FileObject;
-    NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
-    ULONG Length;
-    PVOID Buffer;
-    ULONG Offset;
-    PAFDFCB FCB;
-    PAFDCCB CCB;
-
-    FCB = FileObject->FsContext;
-    CCB = FileObject->FsContext2;
-
-    assert(FCB);
-    assert(CCB);
-
-    Length = IoSp->Parameters.Write.Length;
-    Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
-    Offset = IoSp->Parameters.Write.ByteOffset.u.LowPart;
-
-    AFD_DbgPrint(MAX_TRACE, ("Called. Length (%d)  Buffer (0x%X)  Offset (0x%X)\n",
-        Length, Buffer, Offset));
-
-    assert((FCB->SocketType == SOCK_STREAM) || (FCB->SocketType == SOCK_DGRAM));
-
-    switch (FCB->SocketType) {
-      case SOCK_STREAM:
-        /* FIXME: Support connectionful communication */
-        break;
-      case SOCK_DGRAM:
-        /* Connectionless communication */
-        //Status = TdiSendDatagram(FCB->TdiAddressObject, WH2N(2000), 0x7F000001, Buffer, Length);
-        //if (!NT_SUCCESS(Status)) {
-          Length = 0;
-        //}
-        break;
-      case SOCK_RAW:
-        /* FIXME: Support raw communication */
-        break;
-    }
-
-    Irp->IoStatus.Status = Status;
-    Irp->IoStatus.Information = Length;
-    IoCompleteRequest(Irp, IO_NO_INCREMENT);
-
-    AFD_DbgPrint(MAX_TRACE, ("Leaving.\n"));
-
-    return Status;
-}
-
-/* EOF */

reactos/drivers/net/afd/afd
routines.c removed after 1.8
diff -N routines.c
--- routines.c	15 Jun 2004 02:56:13 -0000	1.8
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,316 +0,0 @@
-/*
- * COPYRIGHT:   See COPYING in the top level directory
- * PROJECT:     ReactOS Ancillary Function Driver
- * FILE:        afd/routines.c
- * PURPOSE:     Support routines
- * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
- * REVISIONS:
- *   CSH 01/02-2001 Created
- */
-#include <afd.h>
-#include <debug.h>
-
-#ifndef DONT_USE_ME_THIS_WAY_IM_LIFTED_FROM_NTOSKRNL_XXX_DO_THIS_THE_RIGHT_WAY
-LONG FASTCALL
-XxInterlockedExchange(PLONG Target,
-		    LONG Value);
-
-__asm__("\n\t.global @XxInterlockedExchange@8\n\t"
-	"@XxInterlockedExchange@8:\n\t"
-	"xchgl %edx,(%ecx)\n\t"
-	"movl  %edx,%eax\n\t"
-	"ret\n\t");
-
-#define InterlockedExchange XxInterlockedExchange
-#endif
-
-VOID DumpName(
-  LPSOCKADDR Name)
-{
-  AFD_DbgPrint(MIN_TRACE, ("DumpName:\n"));
-  AFD_DbgPrint(MIN_TRACE, ("  sa_family: %d\n", Name->sa_family));
-  AFD_DbgPrint(MIN_TRACE, ("  sin_port: %d\n", WN2H(((LPSOCKADDR_IN)Name)->sin_port)));
-  AFD_DbgPrint(MIN_TRACE, ("  in_addr: 0x%x\n", WN2H(((LPSOCKADDR_IN)Name)->sin_addr.S_un.S_addr)));
-}
-
-
-ULONG WSABufferSize(
-  LPWSABUF Buffers,
-  DWORD BufferCount)
-{
-  ULONG i;
-  LPWSABUF p;
-  ULONG Count = 0;
-
-  p = Buffers;
-  for (i = 0; i < BufferCount; i++) {
-    Count += p->len;
-    p++;
-  }
-
-  AFD_DbgPrint(MAX_TRACE, ("Buffer is %d bytes.\n", Count));
-
-  return Count;
-}
-
-
-NTSTATUS MergeWSABuffers(
-  LPWSABUF Buffers,
-  DWORD BufferCount,
-  PVOID Destination,
-  ULONG MaxLength,
-  PULONG BytesCopied)
-{
-  ULONG Length;
-  LPWSABUF p;
-  ULONG i;
-
-  *BytesCopied = 0;
-  if (BufferCount == 0)
-    return STATUS_SUCCESS;
-
-  p = Buffers;
-
-  AFD_DbgPrint(MAX_TRACE, ("Destination is 0x%X\n", Destination));
-  AFD_DbgPrint(MAX_TRACE, ("p is 0x%X\n", p));
-
-  for (i = 0; i < BufferCount; i++) {
-    Length = p->len;
-    if (Length > MaxLength)
-      /* Don't copy out of bounds */
-      Length = MaxLength;
-
-    RtlCopyMemory(Destination, p->buf, Length);
-    Destination += Length;
-    AFD_DbgPrint(MAX_TRACE, ("Destination is 0x%X\n", Destination));
-    p++;
-    AFD_DbgPrint(MAX_TRACE, ("p is 0x%X\n", p));
-
-    *BytesCopied += Length;
-
-    MaxLength -= Length;
-    if (MaxLength == 0)
-      /* Destination buffer is full */
-      break;
-  }
-
-  return STATUS_SUCCESS;
-}
-
-VOID TryToSatisfyRecvRequest( PAFDFCB FCB, BOOL Continuous ) {
-    PAFD_READ_REQUEST ReadRequest;
-    PLIST_ENTRY Entry;
-    NTSTATUS Status;
-    ULONG Count = 0;
-    
-    AFD_DbgPrint(MAX_TRACE, ("Satisfying read request.\n"));
-    
-    while (!IsListEmpty(&FCB->ReadRequestQueue) && 
-	   !IsListEmpty(&FCB->ReceiveQueue)) {
-	AFD_DbgPrint(MAX_TRACE, ("Satisfying read request.\n"));
-	
-	Entry = RemoveHeadList(&FCB->ReadRequestQueue);
-	ReadRequest = CONTAINING_RECORD(Entry, AFD_READ_REQUEST, ListEntry);
-	
-	AFD_DbgPrint(MAX_TRACE,("ReadRequest: (li) %x %x %x\n",
-				ReadRequest->Irp,
-				ReadRequest->RecvFromRequest,
-				ReadRequest->RecvFromReply));
-
-	Status = FillWSABuffers(
-	    FCB,
-	    ReadRequest->RecvFromRequest->Buffers,
-	    ReadRequest->RecvFromRequest->BufferCount,
-	    &Count,
-	    Continuous );
-	
-	ReadRequest->RecvFromReply->NumberOfBytesRecvd = Count;
-	ReadRequest->RecvFromReply->Status = NO_ERROR;
-	
-	ReadRequest->Irp->IoStatus.Information =
-	    sizeof(*ReadRequest->RecvFromReply);
-	ReadRequest->Irp->IoStatus.Status = Status;
-	
-	AFD_DbgPrint(MAX_TRACE, ("Completing IRP at (0x%X).\n", ReadRequest->Irp));
-	
-	IoSetCancelRoutine(ReadRequest->Irp, NULL);
-	IoCompleteRequest(ReadRequest->Irp, IO_NETWORK_INCREMENT);
-    }
-
-    AFD_DbgPrint(MAX_TRACE, ("Bytes received (0x%X).\n", Count));
-}
-
-/*
- * NOTES: ReceiveQueueLock must be acquired for the FCB when called
- */
-NTSTATUS FillWSABuffers(
-    PAFDFCB FCB,
-    LPWSABUF Buffers,
-    DWORD BufferCount,
-    PULONG BytesCopied,
-    BOOL Continuous)
-{
-  PUCHAR DstData, SrcData;
-  UINT DstSize, SrcSize;
-  UINT Count, Total;
-  PAFD_BUFFER SrcBuffer;
-  PMDL Mdl;
-  PLIST_ENTRY Entry;
-
-  *BytesCopied = 0;
-  if (BufferCount == 0)
-    return STATUS_SUCCESS;
-
-  if (IsListEmpty(&FCB->ReceiveQueue))
-    return STATUS_SUCCESS;
-
-  Entry = RemoveHeadList(&FCB->ReceiveQueue);
-  SrcBuffer = CONTAINING_RECORD(Entry, AFD_BUFFER, ListEntry);
-  SrcData = SrcBuffer->Buffer.buf + SrcBuffer->Offset;
-  SrcSize = SrcBuffer->Buffer.len - SrcBuffer->Offset;
-
-  /* First buffer: map the pages so we can access them */
-  Mdl = (PMDL)Buffers->buf;
-  DstData = MmMapLockedPages( Mdl, KernelMode );
-  DstSize = Buffers->len;
-
-  /* Copy the data */
-  for (Total = 0;;) {
-    /* Find out how many bytes we can copy at one time */
-    if (DstSize < SrcSize)
-      Count = DstSize;
-    else
-      Count = SrcSize;
-
-    AFD_DbgPrint(MAX_TRACE, ("DstData (0x%X) SrcData (0x%X) Count (0x%X).\n",
-      DstData, SrcData, Count));
-
-    RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
-
-    Total += Count;
-
-    SrcSize -= Count;
-    if (SrcSize == 0) {
-      ExFreePool(SrcBuffer->Buffer.buf);
-      ExFreePool(SrcBuffer);
-
-      /* No more bytes in source buffer. Proceed to the next buffer
-         in the source buffer chain if there is one */
-      if (IsListEmpty(&FCB->ReceiveQueue)) {
-        SrcBuffer = NULL;
-        SrcData = 0;
-        SrcSize = 0;
-        break;
-      }
-
-      Entry = RemoveHeadList(&FCB->ReceiveQueue);
-      SrcBuffer = CONTAINING_RECORD(Entry, AFD_BUFFER, ListEntry);
-      SrcData = SrcBuffer->Buffer.buf;
-      SrcSize = SrcBuffer->Buffer.len;
-    }
-
-    DstSize -= Count;
-    if (DstSize == 0) {
-      /* No more bytes in destination buffer. Proceed to
-         the next buffer in the destination buffer chain */
-      BufferCount--;
-      if (BufferCount < 1)
-        break;
-
-      /* And cleanup the pages. */
-      MmUnmapLockedPages( DstData, Mdl );
-      MmUnlockPages( Mdl );
-      IoFreeMdl( Mdl );
-
-      Buffers++;
-      Mdl = (PMDL)Buffers->buf;
-      DstData = MmMapLockedPages( Mdl, KernelMode );
-      DstSize = Buffers->len;
-    }
-  }
-
-  if (SrcSize > 0) {
-    SrcBuffer->Offset += Total;
-    InsertHeadList(&FCB->ReceiveQueue, Entry);
-  } else if (SrcBuffer != NULL) {
-    ExFreePool(SrcBuffer->Buffer.buf);
-    ExFreePool(SrcBuffer);
-  }
-
-  *BytesCopied = Total;
-
-  return STATUS_SUCCESS;
-}
-
-ULONG ChecksumCompute(
-    PVOID Data,
-    UINT Count,
-    ULONG Seed)
-/*
- * FUNCTION: Calculate checksum of a buffer
- * ARGUMENTS:
- *     Data  = Pointer to buffer with data
- *     Count = Number of bytes in buffer
- *     Seed  = Previously calculated checksum (if any)
- * RETURNS:
- *     Checksum of buffer
- */
-{
-  /* FIXME: This should be done in assembler */
-
-  register ULONG Sum = Seed;
-
-  while (Count > 1) {
-    Sum   += *(PUSHORT)Data;
-    Count -= 2;
-    Data   = (PVOID) ((ULONG_PTR) Data + 2);
-  }
-
-  /* Add left-over byte, if any */
-  if (Count > 0)
-    Sum += *(PUCHAR)Data;
-
-  /* Fold 32-bit sum to 16 bits */
-  while (Sum >> 16)
-    Sum = (Sum & 0xFFFF) + (Sum >> 16);
-
-  return ~Sum;
-}
-
-VOID BuildIPv4Header(
-  PIPv4_HEADER IPHeader,
-  ULONG TotalSize,
-  ULONG Protocol,
-  PSOCKADDR SourceAddress,
-  PSOCKADDR DestinationAddress)
-{
-  PSOCKADDR_IN SrcNameIn = (PSOCKADDR_IN)SourceAddress;
-  PSOCKADDR_IN DstNameIn = (PSOCKADDR_IN)DestinationAddress;
-
-  /* Version = 4, Length = 5 DWORDs */
-  IPHeader->VerIHL = 0x45;
-  /* Normal Type-of-Service */
-  IPHeader->Tos = 0;
-  /* Length of header and data */
-  IPHeader->TotalLength = WH2N((USHORT)TotalSize);
-  /* Identification */
-  IPHeader->Id = 0;
-  /* One fragment at offset 0 */
-  IPHeader->FlagsFragOfs = 0;
-  /* Time-to-Live is 128 */
-  IPHeader->Ttl = 128;
-  /* Protocol number */
-  IPHeader->Protocol = Protocol;
-  /* Checksum is 0 (calculated later) */
-  IPHeader->Checksum = 0;
-  /* Source address */
-  IPHeader->SrcAddr = SrcNameIn->sin_addr.S_un.S_addr;
-  /* Destination address */
-  IPHeader->DstAddr = DstNameIn->sin_addr.S_un.S_addr;
-
-  /* Calculate checksum of IP header */
-  IPHeader->Checksum = (USHORT)
-    ChecksumCompute(IPHeader, sizeof(IPv4_HEADER), 0);
-}
-
-/* EOF */

reactos/drivers/net/afd/include
afd.h added at 1.18.10.1
diff -N afd.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ afd.h	9 Jul 2004 04:41:18 -0000	1.18.10.1
@@ -0,0 +1,243 @@
+/* $Id: afd.h,v 1.18.10.1 2004/07/09 04:41:18 arty Exp $
+ *
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             drivers/net/afd/include/afd.h
+ * PURPOSE:          Ancillary functions driver -- constants and structures
+ * PROGRAMMER:       Art Yerkes (ayerkes@speakeasy.net)
+ * UPDATE HISTORY:
+ * 20040630 Created
+ */
+
+#ifndef _AFD_H
+#define _AFD_H
+
+#include <ntddk.h>
+#include <tdi.h>
+#include <tdikrnl.h>
+#include <tdiinfo.h>
+#include <string.h>
+#include <ndis.h>
+#include <shared.h>
+
+#ifndef _MSC_VER
+#include <rosrtl/string.h>
+#include <winsock2.h>
+#include <ddk/tdi.h>
+#include <ddk/ndis.h>
+#include <tcpmisc.h>
+#include <tcpioctl.h>
+#else
+#include <ntdef.h>
+#define STDCALL
+#endif
+
+#ifndef MIN
+#define MIN(x,y) (((x)<(y))?(x):(y))
+#endif
+
+#define SOCKET_STATE_INVALID_TRANSITION ((DWORD)-1)
+#define SOCKET_STATE_CREATED            0
+#define SOCKET_STATE_BOUND              1
+#define SOCKET_STATE_CONNECTING         2
+#define SOCKET_STATE_CONNECTED          3
+#define SOCKET_STATE_LISTENING          4
+#define SOCKET_STATE_MASK               0x0000ffff
+#define SOCKET_STATE_LOCKED             0x40000000
+#define SOCKET_STATE_NEW                0x80000000
+#define SOCKET_STATE_CLOSED             0x00000100
+
+#define FUNCTION_CONNECT                0
+#define FUNCTION_RECV                   1
+#define FUNCTION_SEND                   2
+#define FUNCTION_CLOSE                  3
+#define MAX_FUNCTIONS                   4
+
+#define DEFAULT_SEND_WINDOW_SIZE        16384
+#define DEFAULT_RECEIVE_WINDOW_SIZE     16384
+
+typedef struct _AFD_MAPBUF {
+    PVOID BufferAddress;
+    PMDL  Mdl;
+} AFD_MAPBUF, *PAFD_MAPBUF;
+
+typedef struct _AFD_DEVICE_EXTENSION {
+    PDEVICE_OBJECT DeviceObject;
+    LIST_ENTRY Polls;
+    KSPIN_LOCK Lock;
+} AFD_DEVICE_EXTENSION, *PAFD_DEVICE_EXTENSION;
+
+typedef struct _AFD_ACTIVE_POLL {
+    LIST_ENTRY ListEntry;
+    PIRP Irp;
+    PAFD_DEVICE_EXTENSION DeviceExt;
+    KDPC TimeoutDpc;
+    KTIMER Timer;
+} AFD_ACTIVE_POLL, *PAFD_ACTIVE_POLL;
+
+typedef struct _IRP_LIST {
+    LIST_ENTRY ListEntry;
+    PIRP Irp;
+} IRP_LIST, *PIRP_LIST;
+
+typedef struct _AFD_TDI_OBJECT {
+    PFILE_OBJECT Object;
+    HANDLE Handle;
+} AFD_TDI_OBJECT, *PAFD_TDI_OBJECT;
+
+typedef struct _AFD_IN_FLIGHT_REQUEST {
+    PIRP InFlightRequest;
+    IO_STATUS_BLOCK Iosb;    
+    PTDI_CONNECTION_INFORMATION ConnectionInfo;
+} AFD_IN_FLIGHT_REQUEST, *PAFD_IN_FLIGHT_REQUEST;
+
+typedef struct _AFD_DATA_WINDOW {
+    PCHAR Window;
+    UINT BytesUsed, Size, Content;
+} AFD_DATA_WINDOW, *PAFD_DATA_WINDOW;
+
+typedef struct _AFD_FCB {
+    BOOLEAN Locked;
+    UINT State;
+    KIRQL OldIrql;
+    UINT LockCount;
+    PVOID CurrentThread;
+    KSPIN_LOCK SpinLock;
+    PFILE_OBJECT FileObject;
+    PAFD_DEVICE_EXTENSION DeviceExt;
+    BOOLEAN DelayedAccept;
+    PTRANSPORT_ADDRESS LocalAddress;
+    PTRANSPORT_ADDRESS RemoteAddress;
+    IO_STATUS_BLOCK ReceiveIosb;
+    AFD_TDI_OBJECT AddressFile, Connection;
+    AFD_IN_FLIGHT_REQUEST ListenIrp, ReceiveIrp, SendIrp;
+    AFD_DATA_WINDOW Send, Recv;
+    FAST_MUTEX Mutex;
+    KEVENT StateLockedEvent;
+    UNICODE_STRING TdiDeviceName;
+    PVOID Context;
+    DWORD PollState;
+    UINT ContextSize;
+    PIRP PendingTdiIrp;
+    LIST_ENTRY PendingIrpList[MAX_FUNCTIONS];
+} AFD_FCB, *PAFD_FCB;
+
+/* bind.c */
+
+NTSTATUS WarmSocketForBind( PAFD_FCB FCB );
+NTSTATUS STDCALL
+AfdBindSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+	      PIO_STACK_LOCATION IrpSp);
+
+/* connect.c */
+
+NTSTATUS WarmSocketForConnection( PAFD_FCB FCB );
+NTSTATUS STDCALL
+AfdStreamSocketConnect(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+		       PIO_STACK_LOCATION IrpSp);
+
+/* context.c */
+
+NTSTATUS STDCALL
+AfdGetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	       PIO_STACK_LOCATION IrpSp );
+NTSTATUS STDCALL
+AfdSetContext( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	       PIO_STACK_LOCATION IrpSp );
+
+/* info.c */
+
+NTSTATUS STDCALL
+AfdGetInfo( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	    PIO_STACK_LOCATION IrpSp );
+
+/* listen.c */
+
+NTSTATUS AfdListenSocket(PDEVICE_OBJECT DeviceObject, PIRP Irp,
+			 PIO_STACK_LOCATION IrpSp);
+
+/* lock.c */
+
+PAFD_WSABUF LockBuffers( PAFD_WSABUF Buf, UINT Count, BOOLEAN Write );
+VOID UnlockBuffers( PAFD_WSABUF Buf, UINT Count );
+UINT SocketAcquireStateLock( PAFD_FCB FCB );
+NTSTATUS DDKAPI UnlockAndMaybeComplete
+( PAFD_FCB FCB, NTSTATUS Status, PIRP Irp,
+  UINT Information, 
+  PIO_COMPLETION_ROUTINE Completion );
+VOID SocketStateUnlock( PAFD_FCB FCB );
+NTSTATUS LostSocket( PIRP Irp );
+
+/* main.c */
+
+VOID OskitDumpBuffer( PCHAR Buffer, UINT Len );
+NTSTATUS LeaveIrpUntilLater( PAFD_FCB FCB, PIRP Irp, UINT Function );
+
+/* read.c */
+
+NTSTATUS DDKAPI ReceiveComplete
+( PDEVICE_OBJECT DeviceObject,
+  PIRP Irp,
+  PVOID Context );
+NTSTATUS STDCALL
+AfdConnectedSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+			   PIO_STACK_LOCATION IrpSp, BOOLEAN Short);
+NTSTATUS STDCALL
+AfdPacketSocketReadData(PDEVICE_OBJECT DeviceObject, PIRP Irp );
+
+/* select.c */
+
+NTSTATUS STDCALL
+AfdSelect( PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+	   PIO_STACK_LOCATION IrpSp );
+VOID PollReeval( PAFD_DEVICE_EXTENSION DeviceObject, PFILE_OBJECT FileObject );
+
+/* tdi.c */
+
+NTSTATUS TdiOpenAddressFile(
+    PUNICODE_STRING DeviceName,
+    PTRANSPORT_ADDRESS Name,
+    PHANDLE AddressHandle,
+    PFILE_OBJECT *AddressObject);
+
+NTSTATUS TdiAssociateAddressFile(
+  HANDLE AddressHandle,
+  PFILE_OBJECT ConnectionObject);
+
+NTSTATUS TdiListen
+( PIRP *Irp,
+  PFILE_OBJECT ConnectionObject,
+  PTDI_CONNECTION_INFORMATION *RequestConnectionInfo,
+  PIO_STATUS_BLOCK Iosb,
+  PIO_COMPLETION_ROUTINE  CompletionRoutine,
+  PVOID CompletionContext);
+
+NTSTATUS TdiReceive
+( PIRP *Irp,
+  PFILE_OBJECT ConnectionObject,
+  USHORT Flags,
+  PCHAR Buffer,
+  UINT BufferLength,
+  PIO_STATUS_BLOCK Iosb,
+  PIO_COMPLETION_ROUTINE  CompletionRoutine,
+  PVOID CompletionContext);
+
+NTSTATUS TdiSend
+( PIRP *Irp,
+  PFILE_OBJECT ConnectionObject,
+  USHORT Flags,
+  PCHAR Buffer,
+  UINT BufferLength,
+  PIO_STATUS_BLOCK Iosb,
+  PIO_COMPLETION_ROUTINE  CompletionRoutine,
+  PVOID CompletionContext);
+
+/* write.c */
+
+NTSTATUS STDCALL
+AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, 
+			    PIO_STACK_LOCATION IrpSp, BOOLEAN Short);
+NTSTATUS STDCALL
+AfdPacketSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp);
+
+#endif/*_AFD_H*/

reactos/drivers/net/afd/include
tdiconn.h 1.1 -> 1.1.16.1
diff -u -r1.1 -r1.1.16.1
--- tdiconn.h	7 Feb 2004 04:50:44 -0000	1.1
+++ tdiconn.h	9 Jul 2004 04:41:18 -0000	1.1.16.1
@@ -2,27 +2,30 @@
 #define _TDICONN_H
 
 #include <afd.h>
+#ifdef _MSC_VER
+#include <ntddtdi.h>
+#endif
 
 typedef VOID *PTDI_CONNECTION_INFO_PAIR;
 
-DWORD TdiAddressSizeFromType( ULONG Type );
-DWORD TdiAddressSizeFromName( LPSOCKADDR Name );
-VOID TdiBuildAddressIPv4( PTA_IP_ADDRESS Address,
-			  LPSOCKADDR Name );
-NTSTATUS TdiBuildAddress( PTA_ADDRESS Address,
-			  LPSOCKADDR Name );
-NTSTATUS TdiBuildName( LPSOCKADDR Name,
-		       PTA_ADDRESS Address );
+PTRANSPORT_ADDRESS TaCopyTransportAddress( PTRANSPORT_ADDRESS OtherAddress );
+UINT TaLengthOfAddress( PTA_ADDRESS Addr );
+UINT TaLengthOfTransportAddress( PTRANSPORT_ADDRESS Addr );
+VOID TaCopyAddressInPlace( PTA_ADDRESS Target, PTA_ADDRESS Source );
+VOID TaCopyTransportAddressInPlace( PTRANSPORT_ADDRESS Target, 
+				    PTRANSPORT_ADDRESS Source );
+UINT TdiAddressSizeFromType( UINT Type );
+UINT TdiAddressSizeFromName( PTRANSPORT_ADDRESS Name );
 NTSTATUS TdiBuildConnectionInfoInPlace
-( PTDI_CONNECTION_INFORMATION ConnInfo, LPSOCKADDR Name );
+( PTDI_CONNECTION_INFORMATION ConnInfo, PTA_ADDRESS Name );
 NTSTATUS TdiBuildConnectionInfo
-( PTDI_CONNECTION_INFORMATION *ConnectionInfo, LPSOCKADDR Name );
+( PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTA_ADDRESS Name );
 NTSTATUS TdiBuildNullConnectionInfoToPlace
 ( PTDI_CONNECTION_INFORMATION ConnInfo, ULONG Type );
 NTSTATUS TdiBuildNullConnectionInfo
 ( PTDI_CONNECTION_INFORMATION *ConnectionInfo, ULONG Type );
 NTSTATUS TdiBuildConnectionInfoPair
-( PTDI_CONNECTION_INFO_PAIR ConnectionInfo, LPSOCKADDR From, LPSOCKADDR To );
+( PTDI_CONNECTION_INFO_PAIR ConnectionInfo, PTA_ADDRESS From, PTA_ADDRESS To );
 PTA_ADDRESS TdiGetRemoteAddress( PTDI_CONNECTION_INFORMATION TdiConn );
 
 #endif/*_TDICONN_H*/
CVSspam 0.2.8