ReactOS  0.4.13-dev-1165-gd2976ca
connect.c File Reference
#include "afd.h"
Include dependency graph for connect.c:

Go to the source code of this file.

Functions

NTSTATUS NTAPI AfdGetConnectOptions (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetConnectOptions (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetConnectOptionsSize (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdGetConnectData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetConnectData (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS NTAPI AfdSetConnectDataSize (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 
NTSTATUS WarmSocketForConnection (PAFD_FCB FCB)
 
NTSTATUS MakeSocketIntoConnection (PAFD_FCB FCB)
 
static NTSTATUS NTAPI StreamSocketConnectComplete (PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
 
NTSTATUS NTAPI AfdStreamSocketConnect (PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp)
 

Variables

static IO_COMPLETION_ROUTINE StreamSocketConnectComplete
 

Function Documentation

◆ AfdGetConnectData()

NTSTATUS NTAPI AfdGetConnectData ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 127 of file connect.c.

129 {
131  PAFD_FCB FCB = FileObject->FsContext;
132  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
133 
135 
136  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
137 
138  if (FCB->ConnectDataSize == 0)
139  {
140  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
142  }
143 
144  ASSERT(FCB->ConnectData);
145 
146  if (FCB->FilledConnectData < BufferSize) BufferSize = FCB->FilledConnectData;
147 
148  RtlCopyMemory(Irp->UserBuffer,
149  FCB->ConnectData,
150  BufferSize);
151 
153 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
#define BufferSize
Definition: classpnp.h:419
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int UINT
Definition: ndis.h:50
#define MIN_TRACE
Definition: debug.h:14
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdGetConnectOptions()

NTSTATUS NTAPI AfdGetConnectOptions ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 15 of file connect.c.

17 {
19  PAFD_FCB FCB = FileObject->FsContext;
20  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.OutputBufferLength;
21 
23 
25 
26  if (FCB->ConnectOptionsSize == 0)
27  {
28  AFD_DbgPrint(MIN_TRACE,("Invalid parameter\n"));
30  }
31 
32  ASSERT(FCB->ConnectOptions);
33 
34  if (FCB->FilledConnectOptions < BufferSize) BufferSize = FCB->FilledConnectOptions;
35 
36  RtlCopyMemory(Irp->UserBuffer,
37  FCB->ConnectOptions,
38  BufferSize);
39 
41 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
#define BufferSize
Definition: classpnp.h:419
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
unsigned int UINT
Definition: ndis.h:50
#define MIN_TRACE
Definition: debug.h:14
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdSetConnectData()

NTSTATUS NTAPI AfdSetConnectData ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 157 of file connect.c.

159 {
161  PAFD_FCB FCB = FileObject->FsContext;
162  PVOID ConnectData = LockRequest(Irp, IrpSp, FALSE, NULL);
163  UINT ConnectDataSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
164 
166 
167  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
168 
169  if (!ConnectData)
171 
172  if (FCB->ConnectData)
173  {
175  FCB->ConnectData = NULL;
176  FCB->ConnectDataSize = 0;
177  FCB->FilledConnectData = 0;
178  }
179 
180  FCB->ConnectData = ExAllocatePoolWithTag(PagedPool,
181  ConnectDataSize,
183 
184  if (!FCB->ConnectData) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
185 
186  RtlCopyMemory(FCB->ConnectData,
187  ConnectData,
188  ConnectDataSize);
189 
190  FCB->ConnectDataSize = ConnectDataSize;
191 
193 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define TAG_AFD_CONNECT_DATA
Definition: afd.h:41
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
* PFILE_OBJECT
Definition: iotypes.h:1955
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdSetConnectDataSize()

NTSTATUS NTAPI AfdSetConnectDataSize ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 197 of file connect.c.

199 {
201  PAFD_FCB FCB = FileObject->FsContext;
202  PUINT ConnectDataSize = LockRequest(Irp, IrpSp, FALSE, NULL);
203  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
204 
206 
207  if (!SocketAcquireStateLock(FCB)) return LostSocket(Irp);
208 
209  if (!ConnectDataSize)
211 
212  if (BufferSize < sizeof(UINT))
213  {
214  AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
216  }
217 
218  if (FCB->ConnectData)
219  {
221  FCB->ConnectDataSize = 0;
222  FCB->FilledConnectData = 0;
223  }
224 
225  FCB->ConnectData = ExAllocatePoolWithTag(PagedPool,
226  *ConnectDataSize,
228 
229  if (!FCB->ConnectData) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
230 
231  FCB->ConnectDataSize = *ConnectDataSize;
232 
234 }
#define TAG_AFD_CONNECT_DATA
Definition: afd.h:41
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
#define BufferSize
Definition: classpnp.h:419
* PFILE_OBJECT
Definition: iotypes.h:1955
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
unsigned int * PUINT
Definition: ndis.h:50

Referenced by AfdDispatch().

◆ AfdSetConnectOptions()

NTSTATUS NTAPI AfdSetConnectOptions ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 45 of file connect.c.

47 {
49  PAFD_FCB FCB = FileObject->FsContext;
50  PVOID ConnectOptions = LockRequest(Irp, IrpSp, FALSE, NULL);
51  UINT ConnectOptionsSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
52 
54 
56 
57  if (!ConnectOptions)
59 
60  if (FCB->ConnectOptions)
61  {
63  FCB->ConnectOptions = NULL;
64  FCB->ConnectOptionsSize = 0;
65  FCB->FilledConnectOptions = 0;
66  }
67 
68  FCB->ConnectOptions = ExAllocatePoolWithTag(PagedPool,
69  ConnectOptionsSize,
71 
72  if (!FCB->ConnectOptions)
74 
75  RtlCopyMemory(FCB->ConnectOptions,
76  ConnectOptions,
77  ConnectOptionsSize);
78 
79  FCB->ConnectOptionsSize = ConnectOptionsSize;
80 
82 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TAG_AFD_CONNECT_OPTIONS
Definition: afd.h:44
Definition: afd.h:161
* PFILE_OBJECT
Definition: iotypes.h:1955
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ AfdSetConnectOptionsSize()

NTSTATUS NTAPI AfdSetConnectOptionsSize ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 86 of file connect.c.

88 {
90  PAFD_FCB FCB = FileObject->FsContext;
91  PUINT ConnectOptionsSize = LockRequest(Irp, IrpSp, FALSE, NULL);
92  UINT BufferSize = IrpSp->Parameters.DeviceIoControl.InputBufferLength;
93 
95 
97 
98  if (!ConnectOptionsSize)
100 
101  if (BufferSize < sizeof(UINT))
102  {
103  AFD_DbgPrint(MIN_TRACE,("Buffer too small\n"));
105  }
106 
107  if (FCB->ConnectOptions)
108  {
110  FCB->ConnectOptionsSize = 0;
111  FCB->FilledConnectOptions = 0;
112  }
113 
114  FCB->ConnectOptions = ExAllocatePoolWithTag(PagedPool,
115  *ConnectOptionsSize,
117 
118  if (!FCB->ConnectOptions) return UnlockAndMaybeComplete(FCB, STATUS_NO_MEMORY, Irp, 0);
119 
120  FCB->ConnectOptionsSize = *ConnectOptionsSize;
121 
123 }
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define TAG_AFD_CONNECT_OPTIONS
Definition: afd.h:44
Definition: afd.h:161
#define BufferSize
Definition: classpnp.h:419
* PFILE_OBJECT
Definition: iotypes.h:1955
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int UINT
Definition: ndis.h:50
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
unsigned int * PUINT
Definition: ndis.h:50

Referenced by AfdDispatch().

◆ AfdStreamSocketConnect()

NTSTATUS NTAPI AfdStreamSocketConnect ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PIO_STACK_LOCATION  IrpSp 
)

Definition at line 431 of file connect.c.

432  {
435  PAFD_FCB FCB = FileObject->FsContext;
436  PAFD_CONNECT_INFO ConnectReq;
437  AFD_DbgPrint(MID_TRACE,("Called on %p\n", FCB));
438 
440 
441  if( !SocketAcquireStateLock( FCB ) ) return LostSocket( Irp );
442  if( !(ConnectReq = LockRequest( Irp, IrpSp, FALSE, NULL )) )
444  0 );
445 
446  AFD_DbgPrint(MID_TRACE,("Connect request:\n"));
447 #if 0
449  ( (PCHAR)ConnectReq,
450  IrpSp->Parameters.DeviceIoControl.InputBufferLength );
451 #endif
452 
454  {
455  if (FCB->RemoteAddress)
456  {
458  }
459 
460  FCB->RemoteAddress =
461  TaCopyTransportAddress( &ConnectReq->RemoteAddress );
462 
463  if( !FCB->RemoteAddress )
465  else
467 
468  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
469  }
470 
471  switch( FCB->State ) {
474  break;
475 
478 
480  if (FCB->LocalAddress)
481  {
483  }
484 
485  FCB->LocalAddress =
487 
488  if( FCB->LocalAddress ) {
490 
491  if( NT_SUCCESS(Status) )
492  FCB->State = SOCKET_STATE_BOUND;
493  else
494  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
495  } else
497  ( FCB, STATUS_NO_MEMORY, Irp, 0 );
498 
499  /* Drop through to SOCKET_STATE_BOUND */
500 
501  case SOCKET_STATE_BOUND:
502  if (FCB->RemoteAddress)
503  {
505  }
506 
507  FCB->RemoteAddress =
508  TaCopyTransportAddress( &ConnectReq->RemoteAddress );
509 
510  if( !FCB->RemoteAddress ) {
512  break;
513  }
514 
516 
517  if( !NT_SUCCESS(Status) )
518  break;
519 
520  if (FCB->ConnectReturnInfo)
521  {
523  }
524 
526  ( &FCB->ConnectReturnInfo,
527  &ConnectReq->RemoteAddress );
528 
529  if( NT_SUCCESS(Status) )
530  {
531  if (FCB->ConnectCallInfo)
532  {
534  }
535 
536  Status = TdiBuildConnectionInfo(&FCB->ConnectCallInfo,
537  &ConnectReq->RemoteAddress);
538  }
539  else break;
540 
541 
542  if( NT_SUCCESS(Status) ) {
543  FCB->ConnectCallInfo->UserData = FCB->ConnectData;
544  FCB->ConnectCallInfo->UserDataLength = FCB->ConnectDataSize;
545  FCB->ConnectCallInfo->Options = FCB->ConnectOptions;
546  FCB->ConnectCallInfo->OptionsLength = FCB->ConnectOptionsSize;
547 
548  FCB->State = SOCKET_STATE_CONNECTING;
549 
550  AFD_DbgPrint(MID_TRACE,("Queueing IRP %p\n", Irp));
552  if (Status == STATUS_PENDING)
553  {
554  Status = TdiConnect( &FCB->ConnectIrp.InFlightRequest,
555  FCB->Connection.Object,
556  FCB->ConnectCallInfo,
557  FCB->ConnectReturnInfo,
559  FCB );
560  }
561 
562  if (Status != STATUS_PENDING)
563  FCB->State = SOCKET_STATE_BOUND;
564 
566 
567  return Status;
568  }
569  break;
570 
571  default:
572  AFD_DbgPrint(MIN_TRACE,("Inappropriate socket state %u for connect\n",
573  FCB->State));
574  break;
575  }
576 
577  return UnlockAndMaybeComplete( FCB, Status, Irp, 0 );
578 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
signed char * PCHAR
Definition: retypes.h:7
void OskitDumpBuffer(PCHAR Data, UINT Len)
Definition: main.c:29
PTRANSPORT_ADDRESS TaBuildNullTransportAddress(UINT AddressType)
Definition: tdiconn.c:113
#define MID_TRACE
Definition: debug.h:15
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
Definition: cdstruc.h:908
#define TAG_AFD_TDI_CONNECTION_INFORMATION
Definition: afd.h:53
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
PVOID LockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Output, KPROCESSOR_MODE *LockMode)
Definition: lock.c:24
LONG NTSTATUS
Definition: precomp.h:26
#define FUNCTION_CONNECT
Definition: afd.h:84
#define TAG_AFD_TRANSPORT_ADDRESS
Definition: afd.h:39
NTSTATUS WarmSocketForBind(PAFD_FCB FCB, ULONG ShareType)
Definition: bind.c:13
#define SOCKET_STATE_CREATED
Definition: afd.h:73
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
NTSTATUS NTAPI UnlockAndMaybeComplete(PAFD_FCB FCB, NTSTATUS Status, PIRP Irp, UINT Information)
Definition: lock.c:375
#define AFD_ENDPOINT_CONNECTIONLESS
Definition: shared.h:153
#define AFD_SHARE_WILDCARD
Definition: shared.h:193
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
TRANSPORT_ADDRESS RemoteAddress
Definition: shared.h:121
smooth NULL
Definition: ftsmooth.c:416
static IO_COMPLETION_ROUTINE StreamSocketConnectComplete
Definition: connect.c:320
NTSTATUS TdiConnect(PIRP *Irp, PFILE_OBJECT ConnectionObject, PTDI_CONNECTION_INFORMATION ConnectionCallInfo, PTDI_CONNECTION_INFORMATION ConnectionReturnInfo, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:334
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
Definition: afd.h:161
NTSTATUS LeaveIrpUntilLater(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:433
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
NTSTATUS WarmSocketForConnection(PAFD_FCB FCB)
Definition: connect.c:238
NTSTATUS QueueUserModeIrp(PAFD_FCB FCB, PIRP Irp, UINT Function)
Definition: lock.c:397
* PFILE_OBJECT
Definition: iotypes.h:1955
NTSTATUS TdiBuildConnectionInfo(PTDI_CONNECTION_INFORMATION *ConnectionInfo, PTRANSPORT_ADDRESS Address)
Definition: tdiconn.c:237
ULONG Flags
Definition: ntfs.h:532
USHORT AddressType
Definition: tdi.h:339
Status
Definition: gdiplustypes.h:24
TA_ADDRESS Address[1]
Definition: tdi.h:377
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
NTSTATUS LostSocket(PIRP Irp)
Definition: lock.c:387
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define SOCKET_STATE_BOUND
Definition: afd.h:74
#define SOCKET_STATE_CONNECTING
Definition: afd.h:75
PTRANSPORT_ADDRESS TaCopyTransportAddress(PTRANSPORT_ADDRESS OtherAddress)
Definition: tdiconn.c:80
#define MIN_TRACE
Definition: debug.h:14
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by AfdDispatch().

◆ MakeSocketIntoConnection()

NTSTATUS MakeSocketIntoConnection ( PAFD_FCB  FCB)

Definition at line 259 of file connect.c.

259  {
261 
262  ASSERT(!FCB->Recv.Window);
263  ASSERT(!FCB->Send.Window);
264 
265  if (!FCB->Recv.Size)
266  {
267  Status = TdiQueryMaxDatagramLength(FCB->Connection.Object,
268  &FCB->Recv.Size);
269  if (!NT_SUCCESS(Status))
270  return Status;
271  }
272 
273  if (!FCB->Send.Size)
274  {
275  Status = TdiQueryMaxDatagramLength(FCB->Connection.Object,
276  &FCB->Send.Size);
277  if (!NT_SUCCESS(Status))
278  return Status;
279  }
280 
281  /* Allocate the receive area and start receiving */
282  if (!FCB->Recv.Window)
283  {
284  FCB->Recv.Window = ExAllocatePoolWithTag(PagedPool,
285  FCB->Recv.Size,
287 
288  if( !FCB->Recv.Window ) return STATUS_NO_MEMORY;
289  }
290 
291  if (!FCB->Send.Window)
292  {
293  FCB->Send.Window = ExAllocatePoolWithTag(PagedPool,
294  FCB->Send.Size,
296 
297  if( !FCB->Send.Window ) return STATUS_NO_MEMORY;
298  }
299 
300  FCB->State = SOCKET_STATE_CONNECTED;
301 
302  Status = TdiReceive( &FCB->ReceiveIrp.InFlightRequest,
303  FCB->Connection.Object,
305  FCB->Recv.Window,
306  FCB->Recv.Size,
308  FCB );
309 
311 
312  FCB->PollState |= AFD_EVENT_CONNECT | AFD_EVENT_SEND;
313  FCB->PollStatus[FD_CONNECT_BIT] = STATUS_SUCCESS;
314  FCB->PollStatus[FD_WRITE_BIT] = STATUS_SUCCESS;
315  PollReeval( FCB->DeviceExt, FCB->FileObject );
316 
317  return Status;
318 }
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
PFILE_OBJECT FileObject
Definition: ntfs.h:516
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
#define FD_CONNECT_BIT
Definition: winsock2.h:301
IO_COMPLETION_ROUTINE ReceiveComplete
Definition: afd.h:310
#define TDI_RECEIVE_NORMAL
Definition: tdi.h:122
NTSTATUS TdiReceive(PIRP *Irp, PFILE_OBJECT TransportObject, USHORT Flags, PCHAR Buffer, UINT BufferLength, PIO_COMPLETION_ROUTINE CompletionRoutine, PVOID CompletionContext)
Definition: tdi.c:976
#define AFD_EVENT_CONNECT
Definition: shared.h:209
#define TAG_AFD_DATA_BUFFER
Definition: afd.h:38
#define AFD_EVENT_SEND
Definition: shared.h:205
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define SOCKET_STATE_CONNECTED
Definition: afd.h:76
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS TdiQueryMaxDatagramLength(PFILE_OBJECT FileObject, PUINT MaxDatagramLength)
Definition: tdi.c:226
Status
Definition: gdiplustypes.h:24
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define FD_WRITE_BIT
Definition: winsock2.h:295

Referenced by SatisfyAccept(), and StreamSocketConnectComplete().

◆ StreamSocketConnectComplete()

static NTSTATUS NTAPI StreamSocketConnectComplete ( PDEVICE_OBJECT  DeviceObject,
PIRP  Irp,
PVOID  Context 
)
static

Definition at line 324 of file connect.c.

325  {
326  NTSTATUS Status = Irp->IoStatus.Status;
328  PLIST_ENTRY NextIrpEntry;
329  PIRP NextIrp;
330 
331  AFD_DbgPrint(MID_TRACE,("Called: FCB %p, FO %p\n",
332  Context, FCB->FileObject));
333 
334  /* I was wrong about this before as we can have pending writes to a not
335  * yet connected socket */
336  if( !SocketAcquireStateLock( FCB ) )
337  return STATUS_FILE_CLOSED;
338 
339  AFD_DbgPrint(MID_TRACE,("Irp->IoStatus.Status = %x\n",
340  Irp->IoStatus.Status));
341 
342  ASSERT(FCB->ConnectIrp.InFlightRequest == Irp);
343  FCB->ConnectIrp.InFlightRequest = NULL;
344 
345  if( FCB->State == SOCKET_STATE_CLOSED ) {
346  /* Cleanup our IRP queue because the FCB is being destroyed */
347  while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_CONNECT] ) ) {
348  NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_CONNECT]);
349  NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
350  NextIrp->IoStatus.Status = STATUS_FILE_CLOSED;
351  NextIrp->IoStatus.Information = 0;
352  if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
353  (void)IoSetCancelRoutine(NextIrp, NULL);
355  }
357  return STATUS_FILE_CLOSED;
358  }
359 
360  if( !NT_SUCCESS(Irp->IoStatus.Status) ) {
361  FCB->PollState |= AFD_EVENT_CONNECT_FAIL;
362  FCB->PollStatus[FD_CONNECT_BIT] = Irp->IoStatus.Status;
363  AFD_DbgPrint(MID_TRACE,("Going to bound state\n"));
364  FCB->State = SOCKET_STATE_BOUND;
365  PollReeval( FCB->DeviceExt, FCB->FileObject );
366  }
367 
368  /* Succeed pending irps on the FUNCTION_CONNECT list */
369  while( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_CONNECT] ) ) {
370  NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_CONNECT]);
371  NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP, Tail.Overlay.ListEntry);
372  AFD_DbgPrint(MID_TRACE,("Completing connect %p\n", NextIrp));
373  NextIrp->IoStatus.Status = Status;
374  NextIrp->IoStatus.Information = NT_SUCCESS(Status) ? ((ULONG_PTR)FCB->Connection.Handle) : 0;
375  if( NextIrp->MdlAddress ) UnlockRequest( NextIrp, IoGetCurrentIrpStackLocation( NextIrp ) );
376  (void)IoSetCancelRoutine(NextIrp, NULL);
378  }
379 
380  if( NT_SUCCESS(Status) ) {
382 
383  if( !NT_SUCCESS(Status) ) {
385  return Status;
386  }
387 
388  FCB->FilledConnectData = MIN(FCB->ConnectReturnInfo->UserDataLength, FCB->ConnectDataSize);
389  if (FCB->FilledConnectData)
390  {
391  RtlCopyMemory(FCB->ConnectData,
392  FCB->ConnectReturnInfo->UserData,
393  FCB->FilledConnectData);
394  }
395 
396  FCB->FilledConnectOptions = MIN(FCB->ConnectReturnInfo->OptionsLength, FCB->ConnectOptionsSize);
397  if (FCB->FilledConnectOptions)
398  {
399  RtlCopyMemory(FCB->ConnectOptions,
400  FCB->ConnectReturnInfo->Options,
401  FCB->FilledConnectOptions);
402  }
403 
404  if( !IsListEmpty( &FCB->PendingIrpList[FUNCTION_SEND] ) ) {
405  NextIrpEntry = RemoveHeadList(&FCB->PendingIrpList[FUNCTION_SEND]);
406  NextIrp = CONTAINING_RECORD(NextIrpEntry, IRP,
407  Tail.Overlay.ListEntry);
408  AFD_DbgPrint(MID_TRACE,("Launching send request %p\n", NextIrp));
410  ( DeviceObject,
411  NextIrp,
412  IoGetCurrentIrpStackLocation( NextIrp ),
413  FALSE );
414  }
415 
416  if( Status == STATUS_PENDING )
418  }
419 
421 
422  AFD_DbgPrint(MID_TRACE,("Returning %x\n", Status));
423 
424  return Status;
425 }
VOID SocketStateUnlock(PAFD_FCB FCB)
Definition: lock.c:370
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MID_TRACE
Definition: debug.h:15
VOID PollReeval(PAFD_DEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
Definition: select.c:407
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define AFD_EVENT_CONNECT_FAIL
Definition: shared.h:211
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
#define FUNCTION_CONNECT
Definition: afd.h:84
BOOLEAN SocketAcquireStateLock(PAFD_FCB FCB)
Definition: lock.c:360
#define FD_CONNECT_BIT
Definition: winsock2.h:301
IRP
Definition: iotypes.h:2463
IoSetCancelRoutine(Irp, CancelRoutine)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
T MIN(T a, T b)
Definition: polytest.cpp:79
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define IO_NETWORK_INCREMENT
Definition: tcpip.h:43
Definition: afd.h:161
NTSTATUS NTAPI AfdConnectedSocketWriteData(PDEVICE_OBJECT DeviceObject, PIRP Irp, PIO_STACK_LOCATION IrpSp, BOOLEAN Short)
Definition: write.c:329
struct _AFD_FCB * PAFD_FCB
#define FUNCTION_SEND
Definition: afd.h:86
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
VOID UnlockRequest(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: lock.c:180
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: typedefs.h:117
NTSTATUS MakeSocketIntoConnection(PAFD_FCB FCB)
Definition: connect.c:259
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define SOCKET_STATE_BOUND
Definition: afd.h:74
#define SOCKET_STATE_CLOSED
Definition: afd.h:82
#define ULONG_PTR
Definition: config.h:101
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define STATUS_FILE_CLOSED
Definition: ntstatus.h:518

◆ WarmSocketForConnection()

NTSTATUS WarmSocketForConnection ( PAFD_FCB  FCB)

Definition at line 238 of file connect.c.

238  {
240 
241  if( !FCB->TdiDeviceName.Length || !FCB->TdiDeviceName.Buffer ) {
242  AFD_DbgPrint(MIN_TRACE,("Null Device\n"));
243  return STATUS_NO_SUCH_DEVICE;
244  }
245 
246  Status = TdiOpenConnectionEndpointFile(&FCB->TdiDeviceName,
247  &FCB->Connection.Handle,
248  &FCB->Connection.Object );
249 
250  if( NT_SUCCESS(Status) ) {
251  Status = TdiAssociateAddressFile( FCB->AddressFile.Handle,
252  FCB->Connection.Object );
253  }
254 
255  return Status;
256 }
Definition: cdstruc.h:908
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS TdiAssociateAddressFile(HANDLE AddressHandle, PFILE_OBJECT ConnectionObject)
Definition: tdi.c:391
NTSTATUS TdiOpenConnectionEndpointFile(PUNICODE_STRING DeviceName, PHANDLE ConnectionHandle, PFILE_OBJECT *ConnectionObject)
Definition: tdi.c:281
#define AFD_DbgPrint(_t_, _x_)
Definition: debug.h:60
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
Status
Definition: gdiplustypes.h:24
#define MIN_TRACE
Definition: debug.h:14

Referenced by AfdListenSocket(), AfdStreamSocketConnect(), and ListenComplete().

Variable Documentation

◆ StreamSocketConnectComplete

IO_COMPLETION_ROUTINE StreamSocketConnectComplete
static

Definition at line 320 of file connect.c.

Referenced by AfdStreamSocketConnect().